这篇博客讲HM代码中xPredIntraPlanar、xPredIntraAng、xDCPredFiltering三个函数,有关帧内预测的理论知识看 https://blog.csdn.net/shayashi/article/details/82877875 。
xPredIntraPlanar函数是对Planar模式预测的函数,Planar模式对应0,该模式的预测采用同双线性差值方式,代码如下:
Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
{
assert(width <= height);
Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];//参考像素
UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;//水平移动位数
UInt shift1Dver = g_aucConvertToBit[ height ] + 2;//竖直移动位数
//g_aucConvertToBit是对应的bit数 [4]==0 [8]==1 [16]==2 [32]==3 [64]==4 other -1
// Get left and above reference column and row获取参考像素
for(Int k=0;k<width+1;k++)
{
topRow[k] = pSrc[k-srcStride];//srcStride == 2 * width + 1
}
for (Int k=0; k < height+1; k++)
{
leftColumn[k] = pSrc[k*srcStride-1];
}
// Prepare intermediate variables used in interpolation
Int bottomLeft = leftColumn[height];
Int topRight = topRow[width];
//bottomRow[k]= leftColumn[height]-topRow[k],且将topRow的数值乘height
for(Int k=0;k<width;k++)
{
bottomRow[k] = bottomLeft - topRow[k];
topRow[k] <<= shift1Dver;
}
//rightColumn[k]=topRow[width]-leftColumn[k],将leftColumn的数值乘width
for(Int k=0;k<height;k++)
{
rightColumn[k] = topRight - leftColumn[k];
leftColumn[k] <<= shift1Dhor;
}
const UInt topRowShift = 0;
// 生成预测信号
//双线性插值就是像素对应的上、下和左、右参考像素成比例的和。
//horPred(x,y) = (width - x) * leftColumn[y] + x * topRight
//vertPred(x,y) = (width - y) * topRight[y] + y * bottomLeft
//rpDst(x,y) = (horP