motionCompensation运动补偿,在帧间各种模式中,根据之前获取到的亚像素精度的mv,就能在参考帧中得到pu的参考块,在pu的参考块位置处,通过亚像素插值来得到亚像素位置的pu的预测像素pred。
总之,MC运动补偿,就是根据运动向量mv,得到当前pu的预测像素。
motionCompensation调用了xPredInterUni函数进行单向预测的运动补偿,调用xPredInterBi函数进行双向预测的运动补偿。
VTM中,调用motionCompensation时,参数eRefPicList只有三种情况:REF_PIC_LIST_0、REF_PIC_LIST_1、REF_PIC_LIST_X,表示前向、后向、不确定。
相比VTM1,motionCompensation函数中多了CPR模式相关的一些代码。
对Affine模式的运动补偿,与Merge以及inter_ME模式的运动补偿过程是不同的:
Affine模式运动补偿时xPredAffineBlk函数
Merge及inter_ME模式运动补偿时xPredInterBlk函数
void InterPrediction::motionCompensation( PredictionUnit &pu, PelUnitBuf &predBuf, const RefPicList &eRefPicList
#if JVET_L0293_CPR
, const bool luma, const bool chroma
#endif
)
{
#if JVET_L0293_CPR
// dual tree handling for CPR as the only ref
if (!luma || !chroma) //CPR模式相关的一些代码
{
if (!luma && chroma)
{
xChromaMC(pu, predBuf);
return;
}
else // (luma && !chroma)
{
xPredInterUni(pu, eRefPicList, predBuf, false
#if JVET_L0256_BIO
, false
#endif
, luma, chroma);
return;
}
}
// else, go with regular MC below
#endif
CodingStructure &cs = *pu.cs;
const PPS &pps = *cs.pps;
const SliceType sliceType = cs.slice->getSliceType();
if( eRefPicList != REF_PIC_LIST_X ) //指明了pu的参考列表,单向预测
{
if( ( ( sliceType == P_SLICE && pps.getUseWP() ) || ( sliceType == B_SLICE && pps.getWPBiPred() ) ) )//使用加权预测
{
xPredInterUni ( pu, eRefPicList, predBuf, true ); //单向预测 最后一个参数为true表示之后还要进行加权预测
xWeightedPredictionUni( pu, predBuf, eRefPicList, predBuf, -1, m_maxCompIDToPred ); //单向加权预测
}
else //不使用加权预测
{
xPredInterUni( pu, eRefPicList, predBuf, false ); //单向预测
}
}
else //没有指明参考列表,当作Bi处理
{
#if JVET_L0293_CPR
if (pu.mergeType != MRG_TYPE_DEFAULT_N && pu.mergeType != MRG_TYPE_CPR)
#else
if( pu.mergeType != MRG_TYPE_DEFAULT_N )
#endif
{
xSubPuMC( pu, predBuf, eRefPicList );
}
else if( xCheckIdenticalMotion( pu ) ) //如果前后两个方向的参考poc相同,mv相同,则归为单向处理
{
xPredInterUni( pu, REF_PIC_LIST_0, predBuf, false ); //前向预测
}
else
{
xPredInterBi( pu, predBuf ); //双向预测 其中会进行双向预测的加权预测
}
}
return;
}
//单向预测的运动补偿算法
//xPredInterUni调用xPredInterBlk函数进行pu的每个通道的预测像素的获取
//相比VTM1,其中多了xPredAffineBlk函数进行Affine模式时pu的运动补偿,获取预测像素
void InterPrediction::xPredInterUni(const PredictionUnit