HEVC學習(九) —— 幀內預測系列之六

上次留下兩個幀內預測中最爲重要的兩個函數xPredIntraPlanar和xPredIntraAng,本文先介紹第一個函數。先看代碼及相應的註釋:

  1. /** Function for deriving planar intra prediction. 
  2.  * \param pSrc pointer to reconstructed sample array 
  3.  * \param srcStride the stride of the reconstructed sample array 
  4.  * \param rpDst reference to pointer for the prediction sample array 
  5.  * \param dstStride the stride of the prediction sample array 
  6.  * \param width the width of the block 
  7.  * \param height the height of the block 
  8.  * 
  9.  * This function derives the prediction samples for planar mode (intra coding). 
  10.  */  
  11. Void TComPrediction::xPredIntraPlanar( Int* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )  
  12. {  
  13.   assert(width == height);  
  14.   
  15.   Int k, l, bottomLeft, topRight;  
  16.   Int horPred;  
  17.   Int leftColumn[MAX_CU_SIZE], topRow[MAX_CU_SIZE], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];  
  18.   UInt blkSize = width;  
  19.   UInt offset2D = width;  
  20.   UInt shift1D = g_aucConvertToBit[ width ] + 2;  //!< 加2纔是得到實際的寬度取Log2的結果   
  21.   UInt shift2D = shift1D + 1;  
  22.   
  23.   // Get left and above reference column and row  
  24.   for(k=0;k<blkSize+1;k++)  
  25.   {  
  26.     topRow[k] = pSrc[k-srcStride];   //!< p[x][-1], x = 0, 1, 2, ..., nT,即上邊界  
  27.     leftColumn[k] = pSrc[k*srcStride-1]; //!< p[-1][y], y = -1, 0, 1, 2, ..., nT,即左邊界  
  28.   }  
  29.   
  30.   // Prepare intermediate variables used in interpolation  
  31.   bottomLeft = leftColumn[blkSize]; //!< 左下邊界  
  32.   topRight   = topRow[blkSize]; //!< 右上邊界  
  33.   for (k=0;k<blkSize;k++)  
  34.   {  
  35.     bottomRow[k]   = bottomLeft - topRow[k];  
  36.     rightColumn[k] = topRight   - leftColumn[k];  
  37.     topRow[k]      <<= shift1D;  
  38.     leftColumn[k]  <<= shift1D;  
  39.   }  
  40. <span style="color:#000000;"//! 上邊那個循環過程參考下圖</span>  

  1.  //! planar預測模式分析:首先,獲取待預測CU的上鄰塊的最後一行topRow以及右上點topRight,  
  2.  //!  待預測CU的左鄰塊的最右一列leftColumn以及左下點bottomLeft,  
  3.  //!  接着,根據以上獲得的樣點值計算用於求預測樣點值的中間變量---待預測CU的右鄰列和下鄰行,  
  4.  //!  右鄰列對應點的計算方法爲前面獲得的右上點topRight減去leftColumn對應點(右上-左),  
  5.  //!  下鄰行對應點的計算方法爲前面獲得的左下點bottomLeft減去topRow對應點(左下-上),  
  6.  //!  接下來,對於待預測CU中的每一個樣點值(x, y),它的預測值由(x, -1), (x, nT), (-1, y), (nT, y)  
  7.  //!  四個點取平均值獲得(其實不是直接地取平均,表達起來比較麻煩,姑且這麼說吧)  
  8.   
  9.  //! 對照着下面代碼參考下圖  
  10.   // Generate prediction signal  
  11.   for (k=0;k<blkSize;k++)  
  12.   {  
  13.     horPred = leftColumn[k] + offset2D; //!< leftColumn[k] * uiWidth + uiWidth,最後加上uiWidth應該是爲了取平均時進行四捨五入  
  14.     for (l=0;l<blkSize;l++)  
  15.     {  
  16.       horPred += rightColumn[k];  
  17.       topRow[l] += bottomRow[l]; //!< topRow[l] * uiWidth  
  18.       rpDst[k*dstStride+l] = ( (horPred + topRow[l]) >> shift2D );  // draft 8.4.4.2.4,公式(8-33)  
  19.     }  
  20.   }  
  21. }  

 

至此,還剩下最後一個函數尚未介紹,留待下一篇文章。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章