HEVC代码分析-xPredIntraPlanar

该函数实现帧内planar预测模式,由重建像素生成当前块的planar模式预测块。

Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
{
  // 参数分别为重建像素数组,参考像素stride,预测像素数组,预测像素stride,预测块宽,预测块高
  // pSrc和rpDst分别都指向当前块的左上角位置,即(0,0)处
  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;		// 计算需要用到的水平移位值,g_aucConvertToBit即计算log2(W)-2,再加2就为log2(W)
  UInt shift1Dver = g_aucConvertToBit[ height ] + 2;	// 计算需要用到的竖直移位值

  // Get left and above reference column and row
  for(Int k=0;k<width+1;k++)
  {
    topRow[k] = pSrc[k-srcStride]; // 提取重建像素到参考像素数组中,topRow保存当前块上方的参考像素,范围为(0,-1)到(W,-1)共W+1个值
  }

  for (Int k=0; k < height+1; k++)
  {
    leftColumn[k] = pSrc[k*srcStride-1]; // 提取当前块左侧的参考像素,范围为(-1,0)到(-1,H)共H+1个值
  }

  // Prepare intermediate variables used in interpolation
  Int bottomLeft = leftColumn[height];	// 坐标为(-1,H)处的参考像素值
  Int topRight   = topRow[width];	// 坐标为(W,-1)处的参考像素值

  for(Int k=0;k<width;k++)
  {
	// 遍历当前块每一列
    bottomRow[k]  = bottomLeft - topRow[k];	// 计算该列上下参考像素差值,即变化幅度,保存在bottomRow数组中
    topRow[k]     <<= shift1Dver; // 左移,即表示将topRow中的参考像素值乘以H,为了保持计算精度,最后还会除掉
  }

  for(Int k=0;k<height;k++)
  {
    rightColumn[k]  = topRight - leftColumn[k]; // rightColumn中保存水平变化幅度
    leftColumn[k]   <<= shift1Dhor; // leftColumn中参考像素值乘以W,为了保持计算精度,最后还会除掉
	// 按理说这里应该乘以W+1的,因为左右参考像素的距离其实是W+1,但是为了实现简单就认为两者间的距离为W
  }

  const UInt topRowShift = 0;

  // Generate prediction signal
  // 生成预测像素
  for (Int y=0;y<height;y++)
  {
	// 遍历每一行
    Int horPred = leftColumn[y] + width; // 加width是为了后面的四舍五入
    for (Int x=0;x<width;x++)
    {
	  // 遍历每一列
      horPred += rightColumn[y]; // 距离左边参考像素越远加更多的偏移值,加到最右一列horPred就是(W,-1)处重建值放大W倍的结果
								 // 简单来说就是由左右两点的参考像素根据距离加权得到horPred值
      topRow[x] += bottomRow[x]; // 同样的当前列上下两点参考像素根据加权得到竖直预测值

      Int vertPred = ((topRow[x] + topRowShift)>>topRowShift); // 没啥用
      rpDst[y*dstStride+x] = ( horPred + vertPred ) >> (shift1Dhor+1); // horPred和vertPred平均,并且消除之前的缩放
    }
  }
}

发布了25 篇原创文章 · 获赞 46 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/huster1446/article/details/103426049