上次留下兩個幀內預測中最爲重要的兩個函數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)
- }
- }
- }
至此,還剩下最後一個函數尚未介紹,留待下一篇文章。