HEVC代码追踪(十一。七):运动估计/补偿之xTZ8PointDiamondSearch

简介: <p>xTZSearch调用了2个最为主要的函数:xTZ8PointDiamondSearch和xTZ2PointSearch,值得一提的是,HM中还提供了另外一个搜索函数xTZ8PointSquareSearch,但由于实际并没有使用这个函数,且它其实跟钻石搜索只是搜索点的选择略有不同,分析起来基本上也是一样的。</p> <p><br></p> <p></p><pre code_s

xTZSearch调用了2个最为主要的函数:xTZ8PointDiamondSearch和xTZ2PointSearch,值得一提的是,HM中还提供了另外一个搜索函数xTZ8PointSquareSearch,但由于实际并没有使用这个函数,且它其实跟钻石搜索只是搜索点的选择略有不同,分析起来基本上也是一样的。


__inline Void TEncSearch::xTZ8PointDiamondSearch( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, const Int iStartX, const Int iStartY, const Int iDist )
{
  Int   iSrchRngHorLeft   = pcMvSrchRngLT->getHor();
  Int   iSrchRngHorRight  = pcMvSrchRngRB->getHor();
  Int   iSrchRngVerTop    = pcMvSrchRngLT->getVer();
  Int   iSrchRngVerBottom = pcMvSrchRngRB->getVer();
  
  // 8 point search,                   //   1 2 3
  // search around the start point     //   4 0 5
  // with the required  distance       //   6 7 8
  assert ( iDist != 0 );
  const Int iTop        = iStartY - iDist;//!< 2
  const Int iBottom     = iStartY + iDist;//!< 7
  const Int iLeft       = iStartX - iDist;//!< 4
  const Int iRight      = iStartX + iDist;//!< 5
  rcStruct.uiBestRound += 1;//!< 每次调用xTZSearchHelp,一旦发现当前搜索点的sad小于存放的最佳值,则将uiBestRound清零  
  
  if ( iDist == 1 ) // iDist == 1
  {//!< 搜索步长等于1时,只搜索2,4,5,7这四个位置,这也就是在后面最佳步长为1时,仍然要进行2点钻石搜索的原因  
    if ( iTop >= iSrchRngVerTop ) // check top
    {
      xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
    }
    if ( iLeft >= iSrchRngHorLeft ) // check middle left
    {
      xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
    }
    if ( iRight <= iSrchRngHorRight ) // check middle right
    {
      xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
    }
    if ( iBottom <= iSrchRngVerBottom ) // check bottom
    {
      xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
    }
  }
  else // if (iDist != 1)
  {
    if ( iDist <= 8 )
    {
      const Int iTop_2      = iStartY - (iDist>>1);
      const Int iBottom_2   = iStartY + (iDist>>1);
      const Int iLeft_2     = iStartX - (iDist>>1);
      const Int iRight_2    = iStartX + (iDist>>1);
      
      if (  iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft &&
          iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom ) // check border,保证在搜索范围内  
      {
        xTZSearchHelp( pcPatternKey, rcStruct, iStartX,  iTop,      2, iDist    );
        xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2,  iTop_2,    1, iDist>>1 );
        xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2,    3, iDist>>1 );
        xTZSearchHelp( pcPatternKey, rcStruct, iLeft,    iStartY,   4, iDist    );
        xTZSearchHelp( pcPatternKey, rcStruct, iRight,   iStartY,   5, iDist    );
        xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2,  iBottom_2, 6, iDist>>1 );
        xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, iDist>>1 );
        xTZSearchHelp( pcPatternKey, rcStruct, iStartX,  iBottom,   7, iDist    );
      }
      else // check border,有部分越界,在确保不越界的情况下搜索对应点
      {
        if ( iTop >= iSrchRngVerTop ) // check top
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 2, iDist );
        }
        if ( iTop_2 >= iSrchRngVerTop ) // check half top
        {
          if ( iLeft_2 >= iSrchRngHorLeft ) // check half left
          {
            xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iTop_2, 1, (iDist>>1) );
          }
          if ( iRight_2 <= iSrchRngHorRight ) // check half right
          {
            xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iTop_2, 3, (iDist>>1) );
          }
        } // check half top
        if ( iLeft >= iSrchRngHorLeft ) // check left
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 4, iDist );
        }
        if ( iRight <= iSrchRngHorRight ) // check right
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 5, iDist );
        }
        if ( iBottom_2 <= iSrchRngVerBottom ) // check half bottom
        {
          if ( iLeft_2 >= iSrchRngHorLeft ) // check half left
          {
            xTZSearchHelp( pcPatternKey, rcStruct, iLeft_2, iBottom_2, 6, (iDist>>1) );
          }
          if ( iRight_2 <= iSrchRngHorRight ) // check half right
          {
            xTZSearchHelp( pcPatternKey, rcStruct, iRight_2, iBottom_2, 8, (iDist>>1) );
          }
        } // check half bottom
        if ( iBottom <= iSrchRngVerBottom ) // check bottom
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 7, iDist );
        }
      } // check border
    }
    else // iDist > 8,搜索步长大于8以后,ucPointNr统一设置为0
    {
      if ( iTop >= iSrchRngVerTop && iLeft >= iSrchRngHorLeft &&
          iRight <= iSrchRngHorRight && iBottom <= iSrchRngVerBottom ) // check border,在搜索范围内  
      {
        xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop,    0, iDist );//!< 2
        xTZSearchHelp( pcPatternKey, rcStruct, iLeft,   iStartY, 0, iDist );//!< 4
        xTZSearchHelp( pcPatternKey, rcStruct, iRight,  iStartY, 0, iDist );//!< 5
        xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist );//!< 7
        for ( Int index = 1; index < 4; index++ )//!< 不妨假设此时iDist = 16,搜索的点可以以(iStartX, iStartY)为原点进行描点,不难得出钻石扫描的pattern
        {
          Int iPosYT = iTop    + ((iDist>>2) * index);//!< iTop + 4 (8, 12)
          Int iPosYB = iBottom - ((iDist>>2) * index);//!< iBottom - 4 (8, 12)  
          Int iPosXL = iStartX - ((iDist>>2) * index);//!< iStartX - 4 (8, 12)
          Int iPosXR = iStartX + ((iDist>>2) * index); //!< iStartX + 4 (8, 12) 
          xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist );
          xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist );
          xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist );
          xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist );
        }
      }
      else // check border,有部分越界,在确保不越界的地方进行搜索
      {
        if ( iTop >= iSrchRngVerTop ) // check top
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iTop, 0, iDist );
        }
        if ( iLeft >= iSrchRngHorLeft ) // check left
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iLeft, iStartY, 0, iDist );
        }
        if ( iRight <= iSrchRngHorRight ) // check right
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iRight, iStartY, 0, iDist );
        }
        if ( iBottom <= iSrchRngVerBottom ) // check bottom
        {
          xTZSearchHelp( pcPatternKey, rcStruct, iStartX, iBottom, 0, iDist );
        }
        for ( Int index = 1; index < 4; index++ )
        {
          Int iPosYT = iTop    + ((iDist>>2) * index);
          Int iPosYB = iBottom - ((iDist>>2) * index);
          Int iPosXL = iStartX - ((iDist>>2) * index);
          Int iPosXR = iStartX + ((iDist>>2) * index);
          
          if ( iPosYT >= iSrchRngVerTop ) // check top
          {
            if ( iPosXL >= iSrchRngHorLeft ) // check left
            {
              xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYT, 0, iDist );
            }
            if ( iPosXR <= iSrchRngHorRight ) // check right
            {
              xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYT, 0, iDist );
            }
          } // check top
          if ( iPosYB <= iSrchRngVerBottom ) // check bottom
          {
            if ( iPosXL >= iSrchRngHorLeft ) // check left
            {
              xTZSearchHelp( pcPatternKey, rcStruct, iPosXL, iPosYB, 0, iDist );
            }
            if ( iPosXR <= iSrchRngHorRight ) // check right
            {
              xTZSearchHelp( pcPatternKey, rcStruct, iPosXR, iPosYB, 0, iDist );
            }
          } // check bottom
        } // for ...
      } // check border
    } // iDist <= 8
  } // iDist == 1
}




目录
相关文章
HEVC代码追踪(十一。九):运动估计/补偿之xTZ2PointSearch
<p><br></p> <p></p> <pre code_snippet_id="539592" snippet_file_name="blog_20141202_1_5458888" name="code" class="cpp">__inline Void TEncSearch::xTZ2PointSearch( TComPattern* pcPatternKey, IntTZSe
1088 0
HEVC代码追踪(十一。五):运动估计/补偿之xTZSearch
<p><br></p> <p></p> <pre name="code" class="cpp">Void TEncSearch::xTZSearch( TComDataCU* pcCU, TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngR
1791 0
HEVC代码追踪(十一。六):运动估计/补偿之xTZSearchHelp
<p><br></p> <p></p> <pre name="code" class="cpp">/* 分析xTZSearch这个函数,xTZSearchHelp是当中最为重要的子函数之一。它实现最基本的功能:根据输入的搜索点坐标, 参考图像首地址,原始图像首地址,以及当前PU大小等相关信息,计算出SAD,并与之前保存的最佳值进行比较,更新到 目前为止的最佳值相关参数,如uiBestSa
1855 0
HEVC代码追踪(十一。三):运动估计/补偿之xMotionEstimation
<p><br></p> <p></p> <pre name="code" class="cpp">//!&lt; 运动估计(基本思想就是用TZSearch算法先进行整像素搜索,确定一个局部的最佳值,然后以这个最佳点为中心再进行精度更高的分像素搜索。) Void TEncSearch::xMotionEstimation( TComDataCU* pcCU,
2217 0
HEVC代码追踪(十一。二):运动估计/补偿之predInterSearch
<p><br></p> <p></p> <pre name="code" class="cpp">/** search of the best candidate for inter prediction * \param pcCU * \param pcOrgYuv * \param rpcPredYuv * \param rpcResiYuv * \param rpcRec
1678 0
HEVC代码追踪(十一。八):运动估计/补偿之xTZ8PointSquareSearch
<p><br></p> <p></p> <pre code_snippet_id="539588" snippet_file_name="blog_20141202_1_7201235" name="code" class="cpp">__inline Void TEncSearch::xTZ8PointSquareSearch( TComPattern* pcPatternKey,
1129 0
HEVC代码追踪(十一。一):运动估计/补偿之xCheckRDCostInter
<p><br></p> <p></p> <pre code_snippet_id="539245" snippet_file_name="blog_20141202_1_7049848" name="code" class="cpp">#if AMP_MRG Void TEncCu::xCheckRDCostInter( TComDataCU*&amp; rpcBestCU, TComD
1639 0
HEVC代码追踪(十一。四):运动估计/补偿之xPatternSearch和xPatternSearchFast
<p><br></p> <p></p> <pre name="code" class="cpp">Void TEncSearch::xPatternSearch( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, TComMv* pcMvSrchRngLT, TComMv* pcMvSrchRngRB, TComMv&amp;
1826 0
|
编解码 缓存 存储
HEVC代码追踪(十一):运动估计/补偿之理论知识
<p>运动估计的英文名称是Motion Estimation,是视频编码和视频处理(例如去交织)中广泛使用的一种技术。</p> <p><br></p> <p>运动估计的<strong><span style="color:#ff0000">基本思想</span></strong>是将图像序列的每一帧分成许多互不重叠的宏块,并认为宏块内所有像素的位移量都相同,然后对每个宏块到参考帧某一给
2313 0
HEVC代码追踪(十五):解码之decompressSlice
<p><br></p> <p></p> <pre name="code" class="cpp">Void TDecGop::decompressSlice(TComInputBitstream* pcBitstream, TComPic*&amp; rpcPic) { TComSlice* pcSlice = rpcPic-&gt;getSlice(rpcPic-&gt;getC
1213 0