[HEVC] HEVC学习(五) —— 帧内预测系列之三

时间:2022-03-14 20:13:45

[HEVC] HEVC学习(五) —— 帧内预测系列之三

今天主要介绍帧内预测一个很重要的函数initAdiPattern,它的主要功能有三个,(1)检测当前PU的相邻样点包括左上、上、右上、左、左下邻域样点值的可用性,或者说检查这些点是否存在;(2)参考样点的替换过程,主要实现的是JCTVC-J1003即draft 8.4.4.2.2的内容,主要由函数fillReferenceSamples来完成,这个在之前的文章已经讨论过了;(3)相邻样点即参考样点的平滑滤波,主要实现draft 8.4.4.2.3的内容。话不多说,下面给出initAdiPattern的实现和我个人的一些注释,供大家参考。
  1. Void TComPattern::initAdiPattern( TComDataCU* pcCU, UInt uiZorderIdxInPart, UInt uiPartDepth, Int* piAdiBuf, Int iOrgBufStride, Int iOrgBufHeight, Bool& bAbove, Bool& bLeft, Bool bLMmode )
  2. {//! bLMmode is usually false 
  3.   Pel*  piRoiOrigin;
  4.   Int*  piAdiTemp;
  5.   UInt  uiCuWidth   = pcCU->getWidth(0) >> uiPartDepth; //!< CU的宽度
  6.   UInt  uiCuHeight  = pcCU->getHeight(0)>> uiPartDepth; //!< CU的高度
  7.   UInt  uiCuWidth2  = uiCuWidth<<1;
  8.   UInt  uiCuHeight2 = uiCuHeight<<1;
  9.   UInt  uiWidth;
  10.   UInt  uiHeight;
  11.   Int   iPicStride = pcCU->getPic()->getStride();
  12.   Int   iUnitSize = 0;
  13.   Int   iNumUnitsInCu = 0;
  14.   Int   iTotalUnits = 0;
  15.   Bool  bNeighborFlags[4 * MAX_NUM_SPU_W + 1];  //!< 用于存放4个方向上的相邻样点值的可用性, 4 x 32 + 1
  16.   Int   iNumIntraNeighbor = 0; //!< 给可用邻块进行计数
  17.   
  18.   UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;

  19.   //! 获取当前PU左上角LT,右上角RT以及左下角LB 以4x4块为单位的Zorder
  20.   pcCU->deriveLeftRightTopIdxAdi( uiPartIdxLT, uiPartIdxRT, uiZorderIdxInPart, uiPartDepth );
  21.   pcCU->deriveLeftBottomIdxAdi  ( uiPartIdxLB,              uiZorderIdxInPart, uiPartDepth );
  22.   
  23.   iUnitSize      = g_uiMaxCUWidth >> g_uiMaxCUDepth;
  24.   iNumUnitsInCu  = uiCuWidth / iUnitSize;
  25.   iTotalUnits    = (iNumUnitsInCu << 2) + 1; // Top + RightTop + Left + LeftBottom + LeftTop = iNumUnitsInCu + iNumUnitsInCu + iNumUnitsInCu + iNumUnitsInCu + 1
  26.   //! 扫描顺序是从左下到左上,再从左上到右上
  27.   bNeighborFlags[iNumUnitsInCu*2] = isAboveLeftAvailable( pcCU, uiPartIdxLT );
  28.   iNumIntraNeighbor  += (Int)(bNeighborFlags[iNumUnitsInCu*2]);
  29.   iNumIntraNeighbor  += isAboveAvailable     ( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*2)+1 );
  30.   iNumIntraNeighbor  += isAboveRightAvailable( pcCU, uiPartIdxLT, uiPartIdxRT, bNeighborFlags+(iNumUnitsInCu*3)+1 );
  31.   iNumIntraNeighbor  += isLeftAvailable      ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+(iNumUnitsInCu*2)-1 );
  32.   iNumIntraNeighbor  += isBelowLeftAvailable ( pcCU, uiPartIdxLT, uiPartIdxLB, bNeighborFlags+ iNumUnitsInCu   -1 );
  33.   
  34.   bAbove = true;
  35.   bLeft  = true;

  36.   uiWidth=uiCuWidth2+1;
  37.   uiHeight=uiCuHeight2+1;
  38.   
  39.   if (((uiWidth<<2)>iOrgBufStride)||((uiHeight<<2)>iOrgBufHeight))
  40.   {
  41.     return;
  42.   }
  43.   //! piRoiOrigin指向当前PU左上角
  44.   piRoiOrigin = pcCU->getPic()->getPicYuvRec()->getLumaAddr(pcCU->getAddr(), pcCU->getZorderIdxInCU()+uiZorderIdxInPart);
  45.   piAdiTemp   = piAdiBuf;

  46.   fillReferenceSamples ( pcCU, piRoiOrigin, piAdiTemp, bNeighborFlags, iNumIntraNeighbor, iUnitSize, iNumUnitsInCu, iTotalUnits, uiCuWidth, uiCuHeight, uiWidth, uiHeight, iPicStride, bLMmode);
  47.   
  48.   Int   i;
  49.   // generate filtered intra prediction samples
  50.   Int iBufSize = uiCuHeight2 + uiCuWidth2 + 1;  // left and left above border + above and above right border + top left corner = length of 3. filter buffer

  51.   UInt uiWH = uiWidth * uiHeight;               // number of elements in one buffer

  52.   //! 下面所进行的工作主要是对参考样点进行3抽头的滤波。piAdiBuf指向滤波前的参考样点的首地址,在滤波前,先将所有参考样点
  53.   //! 拷贝到piFilterBuf指向的区域,经滤波后的样点值保存在piFilterBufN指向的区域,最终将滤波后的样点值拷贝到piFilterBuf1
  54.   //! 值得一提的是,最终的结果是,piAdiBuf指向的区域是未经滤波的样点值,而piFilterBuf1指向的区域是经过滤波的样点值,
  55.   //! 两者的地址相差uiWH = uiWidth * uiHeight = (uiCuWidth2 + 1) * (uiCuHeight2 + 1),这就解释了在进行真正的帧内预测时,
  56.   //! 在需要滤波时,指向piAdiBuf的指针需要加上uiWH的偏移量
  57.   Int* piFilteredBuf1 = piAdiBuf + uiWH;        // 1. filter buffer
  58.   Int* piFilteredBuf2 = piFilteredBuf1 + uiWH;  // 2. filter buffer
  59.   Int* piFilterBuf = piFilteredBuf2 + uiWH;     // buffer for 2. filtering (sequential)
  60.   Int* piFilterBufN = piFilterBuf + iBufSize;   // buffer for 1. filtering (sequential) //!<存放的是参考样点经3抽头滤波后的值

  61.   // draft 8.4.4.2.3 Filtering process of neighbouring samples
  62.   Int l = 0;
  63.   // left border from bottom to top
  64.   for (i = 0; i < uiCuHeight2; i++)
  65.   {
  66.     piFilterBuf[l++] = piAdiTemp[uiWidth * (uiCuHeight2 - i)]; //!< 左边界,存储顺序为从下往上
  67.   }
  68.   // top left corner
  69.   piFilterBuf[l++] = piAdiTemp[0];  //!< 左上边界
  70.   // above border from left to right
  71.   for (i=0; i < uiCuWidth2; i++)
  72.   {
  73.     piFilterBuf[l++] = piAdiTemp[1 + i];  //!<上边界,存储顺序为从左往右
  74.   }

  75.   // 1. filtering with [1 2 1]
  76.   piFilterBufN[0] = piFilterBuf[0]; //!< 第1个点直接保存,不滤波
  77.   piFilterBufN[iBufSize - 1] = piFilterBuf[iBufSize - 1]; //!< 最后一个点也直接保存,不滤波
  78.   for (i = 1; i < iBufSize - 1; i++) //!< 对中间样点值进行3抽头[1 2 1] / 4 的平滑滤波
  79.   {
  80.     piFilterBufN[i] = (piFilterBuf[i - 1] + 2 * piFilterBuf[i]+piFilterBuf[i + 1] + 2) >> 2;
  81.   }

  82.   // fill 1. filter buffer with filtered values
  83.   l=0;
  84.   for (i = 0; i < uiCuHeight2; i++)
  85.   {
  86.     piFilteredBuf1[uiWidth * (uiCuHeight2 - i)] = piFilterBufN[l++];  // left border from bottom to top //!< 左边界
  87.   }
  88.   piFilteredBuf1[0] = piFilterBufN[l++]; //!< 左上边界
  89.   for (i = 0; i < uiCuWidth2; i++)
  90.   {
  91.     piFilteredBuf1[1 + i] = piFilterBufN[l++]; // above border from left to right //!< 上边界
  92.   }
  93. }
复制代码
最后附上图,以帮助大家更好地理解代码,我就不对图多作解释了,相信大家对着代码能比较容易看明白的。
[img][/img]




(转载请注明出处。原文地址:http://blog.csdn.net/hevc_cjl/article/details/8184276

图片1.jpg (12.99 KB)

图1

[HEVC] HEVC学习(五) —— 帧内预测系列之三