Hash search in SCC8.7

调用过程

TEncGOP::compressGOP -> TEncSlice::compressSlice -> TEncCu::compressCtu -> TEncCu::xCompressCU -> TEncCu::xCheckRDCostHashInter -> TEncSearch::predInterHashSearch -> TEncSearch::xHashInterEstimation

函数getBlockHashValue 获取hash value

Bool TComHash::getBlockHashValue( const TComPicYuv* const pPicYuv, Int width, Int height, Int xStart, Int yStart, const BitDepths bitDepths, UInt& hashValue1, UInt& hashValue2 )
{
  Int addValue = m_blockSizeToIndex[width][height];
  assert( addValue >= 0 );
  addValue <<= m_CRCBits;
  Int crcMask = 1<getChromaFormat() == CHROMA_444)
  {
    length *= 3;
    bIncludeChroma = true;
  }

  UChar* p = new UChar[length];
  UInt* toHash = new UInt[4];

  Int block2x2Num = (width*height) >> 2;

  UInt* hashValueBuffer[2][2];
  for (Int i = 0; i < 2; i++)
  {
    for (Int j = 0; j < 2; j++)
    {
      hashValueBuffer[i][j] = new UInt[block2x2Num];
    }
  }

  //2x2 subblock hash values in current CU
  Int subBlockInWidth = (width >> 1);
  for (Int yPos = 0; yPos < height; yPos += 2)
  {
    for (Int xPos = 0; xPos < width; xPos += 2)
    {
      Int pos = (yPos >> 1)*subBlockInWidth + (xPos >> 1);
      TComHash::getPixelsIn1DCharArrayByBlock2x2(pPicYuv, p, xStart + xPos, yStart + yPos, bitDepths, bIncludeChroma);

      hashValueBuffer[0][0][pos] = TComHash::getCRCValue1(p, length * sizeof(UChar));
      hashValueBuffer[1][0][pos] = TComHash::getCRCValue2(p, length * sizeof(UChar));
    }
  }

  Int srcSubBlockInWidth = subBlockInWidth;
  subBlockInWidth >>= 1;
  length = 4 * sizeof(UInt);

  Int srcIdx = 1;
  Int dstIdx = 0;

  //4x4 subblock hash values to current block hash values
  for (Int subWidth = 4; subWidth <= width; subWidth *= 2)
  {
    srcIdx = 1 - srcIdx;
    dstIdx = 1 - dstIdx;

    Int dstPos = 0;
    for (Int yPos = 0; yPos < subBlockInWidth; yPos++)
    {
      for (Int xPos = 0; xPos < subBlockInWidth; xPos++)
      {
        Int srcPos = (yPos << 1)*srcSubBlockInWidth + (xPos << 1);

        toHash[0] = hashValueBuffer[0][srcIdx][srcPos];
        toHash[1] = hashValueBuffer[0][srcIdx][srcPos + 1];
        toHash[2] = hashValueBuffer[0][srcIdx][srcPos + srcSubBlockInWidth];
        toHash[3] = hashValueBuffer[0][srcIdx][srcPos + srcSubBlockInWidth + 1];

        hashValueBuffer[0][dstIdx][dstPos] = TComHash::getCRCValue1((UChar*)toHash, length);

        toHash[0] = hashValueBuffer[1][srcIdx][srcPos];
        toHash[1] = hashValueBuffer[1][srcIdx][srcPos + 1];
        toHash[2] = hashValueBuffer[1][srcIdx][srcPos + srcSubBlockInWidth];
        toHash[3] = hashValueBuffer[1][srcIdx][srcPos + srcSubBlockInWidth + 1];
        hashValueBuffer[1][dstIdx][dstPos] = TComHash::getCRCValue2((UChar*)toHash, length);

        dstPos++;
      }
    }

    srcSubBlockInWidth = subBlockInWidth;
    subBlockInWidth >>= 1;
  }

  hashValue1 = (hashValueBuffer[0][dstIdx][0] & crcMask) + addValue;
  hashValue2 = hashValueBuffer[1][dstIdx][0];

  delete[] toHash;

  for (Int i = 0; i < 2; i++)
  {
    for (Int j = 0; j < 2; j++)
    {
      delete[] hashValueBuffer[i][j];
    }
  }

  delete[] p;

  return true;
}

你可能感兴趣的:(Hash search in SCC8.7)