xTZSearch函数

分析xTZSearch这个函数,xTZSearchHelp是当中最为重要的子函数之一。它实现最基本的功能:根据输入的搜索点坐标,参考图像首地址,原始图像首地址,以及当前PU大小等相关信息,计算出SAD,并与之前保存的最佳值进行比较,更新到目前为止的最佳值相关参数,如uiBestSad,搜索点坐标,搜索步长等。其他的函数如xTZ8PointSearch等搜索函数,最终都是调用xTZSearchHelp进行误差匹配的。因此,我们有必要先来了解xTZSearchHelp这个函数:

 

[cpp]  view plain  copy
  1. __inline Void TEncSearch::xTZSearchHelp( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, const Int iSearchX, const Int iSearchY, const UChar ucPointNr, const UInt uiDistance )  
  2. {  
  3.   UInt  uiSad;  
  4.     
  5.   Pel*  piRefSrch;  
  6.     
  7.   piRefSrch = rcStruct.piRefY + iSearchY * rcStruct.iYStride + iSearchX; //!< 参考图像Y分量的起始地址  
  8.     
  9.   //-- jclee for using the SAD function pointer  
  10.   m_pcRdCost->setDistParam( pcPatternKey, piRefSrch, rcStruct.iYStride,  m_cDistParam );//!< 该函数主要职能是设置计算SAD的函数指针,下面会更为详细地分析该函数  
  11.     
  12.   // fast encoder decision: use subsampled SAD when rows > 8 for integer ME  
  13.   if ( m_pcEncCfg->getUseFastEnc() )  
  14.   {  
  15.     if ( m_cDistParam.iRows > 8 )  
  16.     {  
  17.       m_cDistParam.iSubShift = 1;  
  18.     }  
  19.   }  
  20.   
  21.   setDistParamComp(0);  // Y component  
  22.   
  23.   // distortion  
  24.   m_cDistParam.bitDepth = g_bitDepthY; //!< 位深  
  25.   uiSad = m_cDistParam.DistFunc( &m_cDistParam ); //!< 计算SAD  
  26.     
  27.   // motion cost  
  28.   uiSad += m_pcRdCost->getCost( iSearchX, iSearchY ); //!< 考虑上mv本身带来的开销  
  29.     
  30.   if( uiSad < rcStruct.uiBestSad ) //!< 更新最佳值  
  31.   {  
  32.     rcStruct.uiBestSad      = uiSad; //!< SAD  
  33.     rcStruct.iBestX         = iSearchX; //!< mv_x  
  34.     rcStruct.iBestY         = iSearchY; //!< mv_y  
  35.     rcStruct.uiBestDistance = uiDistance; //!< 搜索步长  
  36.     rcStruct.uiBestRound    = 0; //!< 搜索次数  
  37.     rcStruct.ucPointNr      = ucPointNr;  //!< 搜索点序号  
  38.   }  
  39. }  


[cpp]  view plain  copy
  1. // Setting the Distortion Parameter for Inter (ME)  
  2. Void TComRdCost::setDistParam( TComPattern* pcPatternKey, Pel* piRefY, Int iRefStride, DistParam& rcDistParam )  
  3. {  
  4.   // set Original & Curr Pointer / Stride  
  5.   rcDistParam.pOrg = pcPatternKey->getROIY(); //!< 感兴趣区即待搜索的原始图像首地址  
  6.   rcDistParam.pCur = piRefY;    //!< 参考图像首地址  
  7.     
  8.   rcDistParam.iStrideOrg = pcPatternKey->getPatternLStride(); //!< 原始图像跨度  
  9.   rcDistParam.iStrideCur = iRefStride;  //!< 参考图像跨度  
  10.     
  11.   // set Block Width / Height  
  12.   rcDistParam.iCols    = pcPatternKey->getROIYWidth();   //!< PU宽度  
  13.   rcDistParam.iRows    = pcPatternKey->getROIYHeight();  //!< PU高度  
  14.   rcDistParam.DistFunc = m_afpDistortFunc[DF_SAD + g_aucConvertToBit[ rcDistParam.iCols ] + 1 ]; //!< 根据PU的大小选择相应的失真计算函数  
  15.     
  16. #if AMP_SAD //!< 为非对称分区AMP预测模式提供专用的失真函数  
  17.   if (rcDistParam.iCols == 12)  
  18.   {  
  19.       rcDistParam.DistFunc = m_afpDistortFunc[43 ]; //!< TComRdCost::xGetSAD12  
  20.   }  
  21.   else if (rcDistParam.iCols == 24)  
  22.   {  
  23.     rcDistParam.DistFunc = m_afpDistortFunc[44 ]; //!< TComRdCost::xGetSAD24  
  24.   }  
  25.   else if (rcDistParam.iCols == 48)  
  26.   {  
  27.     rcDistParam.DistFunc = m_afpDistortFunc[45 ]; //!< TComRdCost::xGetSAD48  
  28.   }  
  29. #endif  
  30.   
  31.   // initialize  
  32.   rcDistParam.iSubShift  = 0; //!< (vertical) subsampling shift (for reducing complexity)  
  33. }  
[cpp]  view plain  copy
  1. /// distortion parameter class  
  2. class DistParam  
  3. {  
  4. public:  
  5.   Pel*  pOrg;   //!< 原始图像首地址  
  6.   Pel*  pCur;   //!< 参考图像首地址  
  7.   Int   iStrideOrg;  //!< 原始图像跨度  
  8.   Int   iStrideCur;  //!< 参考图像跨度  
  9.   Int   iRows;  //!< PU的宽度  
  10.   Int   iCols;  //!< PU的高度  
  11.   Int   iStep;    
  12.   FpDistFunc DistFunc; //!< 计算失真的函数指针  
  13.   Int   bitDepth;   //!< 位深  
  14.   
  15.   Bool            bApplyWeight;     // whether weithed prediction is used or not  
  16.   wpScalingParam  *wpCur;           // weithed prediction scaling parameters for current ref  
  17.   UInt            uiComp;           // uiComp = 0 (luma Y), 1 (chroma U), 2 (chroma V)  
  18.   
  19. #if NS_HAD  
  20.   Bool            bUseNSHAD;  
  21. #endif  
  22.   
  23.   // (vertical) subsampling shift (for reducing complexity)  
  24.   // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.  
  25.   Int   iSubShift; //!< 下采样  
  26.     
  27.   DistParam()  
  28.   {  
  29.     pOrg = NULL;  
  30.     pCur = NULL;  
  31.     iStrideOrg = 0;  
  32.     iStrideCur = 0;  
  33.     iRows = 0;  
  34.     iCols = 0;  
  35.     iStep = 1;  
  36.     DistFunc = NULL;  
  37.     iSubShift = 0;  
  38.     bitDepth = 0;  
  39. #if NS_HAD  
  40.     bUseNSHAD = false;  
  41. #endif  
  42.   }  
  43. };  


具体的SAD计算函数这里不一一列举,功能其实很简单,就是根据PU所包含的总的像素数计算参考图像与原始图像的像素差的绝对值的总和。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值