这篇博客写得不错,觉得对我对大家刚开始学习时会有帮助,于是转载之。
原文地址:http://blog.csdn.net/hevc_cjl/article/details/8242448
上次留下两个帧内预测中最为重要的两个函数xPredIntraPlanar和xPredIntraAng,本文先介绍第一个函数。先看代码及相应的注释:
- /** Function for deriving planar intra prediction.
- * \param pSrc pointer to reconstructed sample array
- * \param srcStride the stride of the reconstructed sample array
- * \param rpDst reference to pointer for the prediction sample array
- * \param dstStride the stride of the prediction sample array
- * \param width the width of the block
- * \param height the height of the block
- *
- * This function derives the prediction samples for planar mode (intra coding).
- */
- Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
- {
- assert(width == height);
- Int k, l, bottomLeft, topRight;
- Int horPred;
- Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];
- UInt blkSize = width;
- UInt offset2D = width;
- UInt shift1D = g_aucConvertToBit[ width ] + 2; //!< 加2才是得到实际的宽度取Log2的结果
- UInt shift2D = shift1D + 1;
- // Get left and above reference column and row
- for(k=0;k<blkSize+1;k++)
- {
- topRow[k] = pSrc[k-srcStride]; //!< p[x][-1], x = 0, 1, 2, ..., nT,即上边界
- leftColumn[k] = pSrc[k*srcStride-1]; //!< p[-1][y], y = -1, 0, 1, 2, ..., nT,即左边界
- }
- // Prepare intermediate variables used in interpolation
- bottomLeft = leftColumn[blkSize]; //!< 左下边界
- topRight = topRow[blkSize]; //!< 右上边界
- for (k=0;k<blkSize;k++)
- {
- bottomRow[k] = bottomLeft - topRow[k];
- rightColumn[k] = topRight - leftColumn[k];
- topRow[k] <<= shift1D;
- leftColumn[k] <<= shift1D;
- }
- <span style="color:#000000;"> //! 上边那个循环过程参考下图</span>
- //! planar预测模式分析:首先,获取待预测CU的上邻块的最后一行topRow以及右上点topRight,
- //! 待预测CU的左邻块的最右一列leftColumn以及左下点bottomLeft,
- //! 接着,根据以上获得的样点值计算用于求预测样点值的中间变量---待预测CU的右邻列和下邻行,
- //! 右邻列对应点的计算方法为前面获得的右上点topRight减去leftColumn对应点(右上-左),
- //! 下邻行对应点的计算方法为前面获得的左下点bottomLeft减去topRow对应点(左下-上),
- //! 接下来,对于待预测CU中的每一个样点值(x, y),它的预测值由(x, -1), (x, nT), (-1, y), (nT, y)
- //! 四个点取平均值获得(其实不是直接地取平均,表达起来比较麻烦,姑且这么说吧)
- //! 对照着下面代码参考下图
- // Generate prediction signal
- for (k=0;k<blkSize;k++)
- {
- horPred = leftColumn[k] + offset2D; //!< leftColumn[k] * uiWidth + uiWidth,最后加上uiWidth应该是为了取平均时进行四舍五入
- for (l=0;l<blkSize;l++)
- {
- horPred += rightColumn[k];
- topRow[l] += bottomRow[l]; //!< topRow[l] * uiWidth
- rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D ); // draft 8.4.4.2.4,公式(8-33)
- }
- }
- }
至此,还剩下最后一个函数尚未介绍,留待下一篇文章。
(转载请注明出处。)