这篇博客写得不错,觉得对我对大家刚开始学习时会有帮助,于是转载之。
原文地址:http://blog.csdn.net/hevc_cjl/article/details/8216065
由于最近比较忙,所以博客的进度慢了,这几天争取把帧内系列完结了,而且,会渐渐随着对HM的理解的深入,把一些细节问题逐渐地给解释清楚了,前面有些地方仅仅只是泛泛介绍,还没真正地把所有地方都讲通。好了,废话少说,进入今天的正题,今天主要介绍实现帧内预测的最为重要的函数之一predIntraLumaAng。先贴代码和相关注释:
- Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, TComDataCU* pcCU, Bool bAbove, Bool bLeft )
- {
- Pel *pDst = piPred;
- Int *ptrSrc;
- assert( g_aucConvertToBit[ iWidth ] >= 0 ); // 4x 4
- assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128
- assert( iWidth == iHeight );
- //! 获取指向用于帧内预测的参考样点的指针,很有可能指向的是经过滤波的参考样点首地址
- ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
- // get starting pixel in block
- Int sw = 2 * iWidth + 1; //!< ptrSrc指向的是当前PU的左上邻点,故加上2*iWidth指向下一行即当前PU的左邻点,加1指向当前PU的首地址
- // Create the prediction
- if ( uiDirMode == PLANAR_IDX )
- {
- xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
- }
- else
- {
- xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );
- if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
- {// draft 8.4.4.2.5
- xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
- }
- }
- }
这段代码本身并不长,主要就是调用了getPredictorPtr获得指向参考样点首地址的指针,再根据帧内预测的模式调用xPredIntraPlanar进行Intra_Planar模式预测和调用xPredIntraAng进行Intra_DC、Intra_Angular模式预测,最后调用xDCPredFiltering对Intra_DC模式的边界进行平滑滤波处理。
先看看getPreditorPtr函数的实现:
- <span style="font-size:12px;">/*
- const UChar TComPattern::m_aucIntraFilter[5] =
- {
- 10, //4x4
- 7, //8x8
- 1, //16x16
- 0, //32x32
- 10, //64x64
- };
- */
- Int* TComPattern::getPredictorPtr( UInt uiDirMode, UInt log2BlkSize, Int* piAdiBuf )
- {//! 这边根据帧内预测模式来决定是否要将指针指向经过滤波后的样点值,判断规则可参见draft 8.4.4.2.3
- Int* piSrc;
- assert(log2BlkSize >= 2 && log2BlkSize < 7);
- Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX));
- UChar ucFiltIdx = diff > m_aucIntraFilter[log2BlkSize - 2] ? 1 : 0;
- #if REMOVE_LMCHROMA
- if (uiDirMode == DC_IDX)
- #else
- if (uiDirMode == DC_IDX || uiDirMode == LM_CHROMA_IDX)
- #endif
- {
- ucFiltIdx = 0; //no smoothing for DC or LM chroma
- }
- assert( ucFiltIdx <= 1 );
- Int width = 1 << log2BlkSize;
- Int height = 1 << log2BlkSize;
- piSrc = getAdiOrgBuf( width, height, piAdiBuf );
- if ( ucFiltIdx ) //!< 帧内预测模式满足滤波的条件
- {
- piSrc += (2 * width + 1) * (2 * height + 1); //!< 指针指向滤波后的样点值
- }
- return piSrc;
- }
- </span>
在函数的开始前,我注释了一个数组m_aucIntraFilter,这里面存放了不同PU尺寸下滤波的阈值,可参照draft8.4.4.2.3进行了解,具体的判断规则在draft里也详细介绍了,我就不重复了,有兴趣的朋友可以到官网上去下,或者可以到我的博客资源里下载。这里需要指出的是,在函数的最后,当满足滤波条件是,piSrc向后移动了(2*width +1)*(2*height+1),可能刚开始看这句话时会有所疑惑,关于这个的解释可以查看我前面的博客“HEVC学习(五) —— 帧内预测系列之三”中对几个buffer的解释,看完后大家应该就能清楚了。至此,这个函数的解释就结束了。
接下来介绍xDCPredFiltering函数,其实这个函数也没啥好讲的,参考draft 8.4.4.2.5就能看明白了应该,这里我就直接给出代码和注释,其它的应该没什么问题的了。
- /** Function for filtering intra DC predictor.
- * \param pSrc pointer to reconstructed sample array
- * \param iSrcStride the stride of the reconstructed sample array
- * \param rpDst reference to pointer for the prediction sample array
- * \param iDstStride the stride of the prediction sample array
- * \param iWidth the width of the block
- * \param iHeight the height of the block
- *
- * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding).
- */
- Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )
- {
- Pel* pDst = rpDst; //!< 实际上就是dcVal
- Int x, y, iDstStride2, iSrcStride2;
- // boundary pixels processing
- pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2); //!< 式子(8-35),左上角的点,利用其上邻点和左邻点与其加权平均
- //! predSamples[0][0] = ( p[0][-1] + p[-1][0] + 2 * dcVal + 2 ) >> 2);
- for ( x = 1; x < iWidth; x++ ) //!< 上边界
- {
- pDst[x] = (Pel)((pSrc[x - iSrcStride] + 3 * pDst[x] + 2) >> 2); //!< 式子(8-36),第一行的点,利用对应上邻点与其加权平均
- // predSamples[x][0] = ( p[x][-1] + 3 * dcVal + 2 ) >> 2);
- }
- //! 左边界
- for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
- {
- pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); //!< 式子(8-37),第一列的点,利用对应左邻点与其加权平均
- // predSamples[0][y] = ( p[-1][y] + 3 * dcVal + 2 ) >> 2);
- }
- return;
- }
最后还剩下两个实际进行帧内模式预测的函数,篇幅关系,留待下一篇文章吧
(转载请注明出处。)