您的位置:首页 > 编程语言

HTM-16.2代码(10)——xPatternSearch和xPatternSearchFast

2016-12-27 17:19 489 查看
xPatternSearch进行整像素搜索

Void TEncSearch::xPatternSearch( const TComPattern* const pcPatternKey,
const Pel*               piRefY,
const Int                iRefStride,
const TComMv* const      pcMvSrchRngLT,
const TComMv* const      pcMvSrchRngRB,
TComMv&      rcMv,
Distortion&  ruiSAD )
{//在pcMvSrchRngLT和pcMvSrchRngRB的范围内进行整像素搜索,其中最优的mv存入rcMv中,失真存入ruiSAD
Int   iSrchRngHorLeft   = pcMvSrchRngLT->getHor();
Int   iSrchRngHorRight  = pcMvSrchRngRB->getHor();
Int   iSrchRngVerTop    = pcMvSrchRngLT->getVer();
Int   iSrchRngVerBottom = pcMvSrchRngRB->getVer();

Distortion  uiSad;
Distortion  uiSadBest = std::numeric_limits<Distortion>::max();
Int         iBestX = 0;
Int         iBestY = 0;

//-- jclee for using the SAD function pointer
m_pcRdCost->setDistParam( pcPatternKey, piRefY, iRefStride,  m_cDistParam );

// fast encoder decision: use subsampled SAD for integer ME
if ( m_pcEncCfg->getFastInterSearchMode()==FASTINTERSEARCH_MODE1 || m_pcEncCfg->getFastInterSearchMode()==FASTINTERSEARCH_MODE3 )
{
if ( m_cDistParam.iRows > 8 )
{
m_cDistParam.iSubShift = 1;
}
}

piRefY += (iSrchRngVerTop * iRefStride);
for ( Int y = iSrchRngVerTop; y <= iSrchRngVerBottom; y++ )
{
for ( Int x = iSrchRngHorLeft; x <= iSrchRngHorRight; x++ )
{
//  find min. distortion position
m_cDistParam.pCur = piRefY + x;

setDistParamComp(COMPONENT_Y);

m_cDistParam.bitDepth = pcPatternKey->getBitDepthY();

#if NH_3D_IC
m_cDistParam.bUseIC = pcPatternKey->getICFlag();
#endif
#if NH_3D_SDC_INTER
m_cDistParam.bUseSDCMRSAD = pcPatternKey->getSDCMRSADFlag();
#endif

uiSad = m_cDistParam.DistFunc( &m_cDistParam );

// motion cost
uiSad += m_pcRdCost->getCostOfVectorWithPredictor( x, y );

if ( uiSad < uiSadBest )
{
uiSadBest = uiSad;
iBestX    = x;
iBestY    = y;
m_cDistParam.m_maximumDistortionForEarlyExit = uiSad;
}
}
piRefY += iRefStride;
}

rcMv.set( iBestX, iBestY );

ruiSAD = uiSadBest - m_pcRdCost->getCostOfVectorWithPredictor( iBestX, iBestY );
return;
}


xPatternSearchFast的主要部分见xTZSearch

Void TEncSearch::xPatternSearchFast( const TComDataCU* const  pcCU,
const TComPattern* const pcPatternKey,
const Pel* const         piRefY,
const Int                iRefStride,
const TComMv* const      pcMvSrchRngLT,
const TComMv* const      pcMvSrchRngRB,
TComMv       &rcMv,
Distortion   &ruiSAD,
const TComMv* const      pIntegerMv2Nx2NPred )
{
assert (MD_LEFT < NUM_MV_PREDICTORS);
pcCU->getMvPredLeft       ( m_acMvPredictors[MD_LEFT] );
assert (MD_ABOVE < NUM_MV_PREDICTORS);
pcCU->getMvPredAbove      ( m_acMvPredictors[MD_ABOVE] );
assert (MD_ABOVE_RIGHT < NUM_MV_PREDICTORS);
pcCU->getMvPredAboveRight ( m_acMvPredictors[MD_ABOVE_RIGHT] );

switch ( m_motionEstimationSearchMethod )
{
case MESEARCH_DIAMOND:
xTZSearch( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred, false );
break;

case MESEARCH_SELECTIVE:
xTZSearchSelective( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred );
break;

case MESEARCH_DIAMOND_ENHANCED:
xTZSearch( pcCU, pcPatternKey, piRefY, iRefStride, pcMvSrchRngLT, pcMvSrchRngRB, rcMv, ruiSAD, pIntegerMv2Nx2NPred, true );
break;

case MESEARCH_FULL: // shouldn't get here.
default:
break;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: