运动估计/补偿之xTZSearchHelp转自http://blog.csdn.net/frd2009041510 https://blog.csdn.net/FRD2009041510/articl

 
 


  1. /* 
  2. 分析xTZSearch这个函数,xTZSearchHelp是当中最为重要的子函数之一。它实现最基本的功能:根据输入的搜索点坐标, 
  3. 参考图像首地址,原始图像首地址,以及当前PU大小等相关信息,计算出SAD,并与之前保存的最佳值进行比较,更新到 
  4. 目前为止的最佳值相关参数,如uiBestSad,搜索点坐标,搜索步长等。其他的函数如xTZ8PointSearch等搜索函数,最终 
  5. 都是调用xTZSearchHelp进行误差匹配的。 
  6. */  
  7. __inline Void TEncSearch::xTZSearchHelp( TComPattern* pcPatternKey, IntTZSearchStruct& rcStruct, const Int iSearchX, const Int iSearchY, const UChar ucPointNr, const UInt uiDistance )  
  8. {  
  9.   UInt  uiSad;  
  10.     
  11.   Pel*  piRefSrch;  
  12.     
  13.   piRefSrch = rcStruct.piRefY + iSearchY * rcStruct.iYStride + iSearchX;//!< 参考图像Y分量的起始地址    
  14.     
  15.   //-- jclee for using the SAD function pointer  
  16.   m_pcRdCost->setDistParam( pcPatternKey, piRefSrch, rcStruct.iYStride,  m_cDistParam );//!< 该函数主要职能是设置计算SAD的函数指针,下面会更为详细地分析该函数    
  17.     
  18.   // fast encoder decision: use subsampled SAD when rows > 8 for integer ME  
  19.   if ( m_pcEncCfg->getUseFastEnc() )  
  20.   {  
  21.     if ( m_cDistParam.iRows > 8 )  
  22.     {  
  23.       m_cDistParam.iSubShift = 1;  
  24.     }  
  25.   }  
  26.   
  27.   setDistParamComp(0);  // Y component  
  28.   
  29.   // distortion  
  30.   m_cDistParam.bitDepth = g_bitDepthY;//!< 位深  
  31.   uiSad = m_cDistParam.DistFunc( &m_cDistParam );//!< 计算SAD  
  32.     
  33.   // motion cost  
  34.   uiSad += m_pcRdCost->getCost( iSearchX, iSearchY );//!< 考虑上mv本身带来的开销  
  35.     
  36.   if( uiSad < rcStruct.uiBestSad )//!< 更新最佳值  
  37.   {  
  38.     rcStruct.uiBestSad      = uiSad;//!< SAD  
  39.     rcStruct.iBestX         = iSearchX; //!< mv_x  
  40.     rcStruct.iBestY         = iSearchY;//!< mv_y  
  41.     rcStruct.uiBestDistance = uiDistance;//!< 搜索步长  
  42.     rcStruct.uiBestRound    = 0;//!< 搜索次数  
  43.     rcStruct.ucPointNr      = ucPointNr;//!< 搜索点序号  
  44.   }  
  45. }  

[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  
  17.   if (rcDistParam.iCols == 12)  
  18.   {  
  19.     rcDistParam.DistFunc = m_afpDistortFunc[43 ];  
  20.   }  
  21.   else if (rcDistParam.iCols == 24)  
  22.   {  
  23.     rcDistParam.DistFunc = m_afpDistortFunc[44 ];  
  24.   }  
  25.   else if (rcDistParam.iCols == 48)  
  26.   {  
  27.     rcDistParam.DistFunc = m_afpDistortFunc[45 ];  
  28.   }  
  29. #endif  
  30.   
  31.   // initialize  
  32.   rcDistParam.iSubShift  = 0;  
  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.   // (vertical) subsampling shift (for reducing complexity)  
  20.   // - 0 = no subsampling, 1 = even rows, 2 = every 4th, etc.  
  21.   Int   iSubShift;//!< 下采样  
  22.     
  23.   DistParam()  
  24.   {  
  25.     pOrg = NULL;  
  26.     pCur = NULL;  
  27.     iStrideOrg = 0;  
  28.     iStrideCur = 0;  
  29.     iRows = 0;  
  30.     iCols = 0;  
  31.     iStep = 1;  
  32.     DistFunc = NULL;  
  33.     iSubShift = 0;  
  34.     bitDepth = 0;  
  35.   }  
  36. };  


猜你喜欢

转载自blog.csdn.net/sinat_39372048/article/details/80622373