(HEVC)帧内预测:predIntraLumaAng; getPreditorPtr; xDCPredFiltering

来源:互联网 发布:skate it 编辑:程序博客网 时间:2024/05/21 14:50

将自己看到的对我帮助很大的文章转载于此,方便下次查阅。

原文链接:http://blog.csdn.net/hevc_cjl/article/details/8216065。


由于最近比较忙,所以博客的进度慢了,这几天争取把帧内系列完结了,而且,会渐渐随着对HM的理解的深入,把一些细节问题逐渐地给解释清楚了,前面有些地方仅仅只是泛泛介绍,还没真正地把所有地方都讲通。好了,废话少说,进入今天的正题,今天主要介绍实现帧内预测的最为重要的函数之一predIntraLumaAng。先贴代码和相关注释:

 

[cpp] view plaincopy
  1. Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight,  TComDataCU* pcCU, Bool bAbove, Bool bLeft )  
  2. {  
  3.   Pel *pDst = piPred;  
  4.   Int *ptrSrc;  
  5.   
  6.   assert( g_aucConvertToBit[ iWidth ] >= 0 ); //   4x  4  
  7.   assert( g_aucConvertToBit[ iWidth ] <= 5 ); // 128x128  
  8.   assert( iWidth == iHeight  );  
  9.   //! 获取指向用于帧内预测的参考样点的指针,很有可能指向的是经过滤波的参考样点首地址  
  10.   ptrSrc = pcTComPattern->getPredictorPtr( uiDirMode, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );  
  11.   
  12.   // get starting pixel in block  
  13.   Int sw = 2 * iWidth + 1; //!< ptrSrc指向的是当前PU的左上邻点,故加上2*iWidth指向下一行即当前PU的左邻点,加1指向当前PU的首地址  
  14.   
  15.   // Create the prediction  
  16.   if ( uiDirMode == PLANAR_IDX )  
  17.   {  
  18.     xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );  
  19.   }  
  20.   else  
  21.   {  
  22.     xPredIntraAng( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );  
  23.   
  24.     if( (uiDirMode == DC_IDX ) && bAbove && bLeft )  
  25.     {// draft 8.4.4.2.5  
  26.       xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);  
  27.     }  
  28.   }  
  29. }  


这段代码本身并不长,主要就是调用了getPredictorPtr获得指向参考样点首地址的指针,再根据帧内预测的模式调用xPredIntraPlanar进行Intra_Planar模式预测和调用xPredIntraAng进行Intra_DC、Intra_Angular模式预测,最后调用xDCPredFiltering对Intra_DC模式的边界进行平滑滤波处理。

 

先看看getPreditorPtr函数的实现:

[cpp] view plaincopy
  1. <span style="font-size:12px;">/* 
  2.  
  3. const UChar TComPattern::m_aucIntraFilter[5] = 
  4. { 
  5. 10, //4x4 
  6. 7, //8x8 
  7. 1, //16x16 
  8. 0, //32x32 
  9. 10, //64x64 
  10. }; 
  11.  
  12. */  
  13. Int* TComPattern::getPredictorPtr( UInt uiDirMode, UInt log2BlkSize, Int* piAdiBuf )  
  14. {//! 这边根据帧内预测模式来决定是否要将指针指向经过滤波后的样点值,判断规则可参见draft 8.4.4.2.3  
  15.   Int* piSrc;  
  16.   assert(log2BlkSize >= 2 && log2BlkSize < 7);  
  17.   Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX));  
  18.   UChar ucFiltIdx = diff > m_aucIntraFilter[log2BlkSize - 2] ? 1 : 0;  
  19. #if REMOVE_LMCHROMA  
  20.   if (uiDirMode == DC_IDX)  
  21. #else  
  22.   if (uiDirMode == DC_IDX || uiDirMode == LM_CHROMA_IDX)  
  23. #endif  
  24.   {  
  25.     ucFiltIdx = 0; //no smoothing for DC or LM chroma  
  26.   }  
  27.   
  28.   assert( ucFiltIdx <= 1 );  
  29.   
  30.   Int width  = 1 << log2BlkSize;  
  31.   Int height = 1 << log2BlkSize;  
  32.     
  33.   piSrc = getAdiOrgBuf( width, height, piAdiBuf );  
  34.   
  35.   if ( ucFiltIdx ) //!< 帧内预测模式满足滤波的条件  
  36.   {  
  37.     piSrc += (2 * width + 1) * (2 * height + 1); //!< 指针指向滤波后的样点值  
  38.   }  
  39.   
  40.   return piSrc;  
  41. }  
  42.   
  43. </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就能看明白了应该,这里我就直接给出代码和注释,其它的应该没什么问题的了。

 

[cpp] view plaincopy
  1. /** Function for filtering intra DC predictor. 
  2.  * \param pSrc pointer to reconstructed sample array 
  3.  * \param iSrcStride the stride of the reconstructed sample array 
  4.  * \param rpDst reference to pointer for the prediction sample array 
  5.  * \param iDstStride the stride of the prediction sample array 
  6.  * \param iWidth the width of the block 
  7.  * \param iHeight the height of the block 
  8.  * 
  9.  * This function performs filtering left and top edges of the prediction samples for DC mode (intra coding). 
  10.  */  
  11. Void TComPrediction::xDCPredFiltering( Int* pSrc, Int iSrcStride, Pel*& rpDst, Int iDstStride, Int iWidth, Int iHeight )  
  12. {  
  13.   Pel* pDst = rpDst;  //!< 实际上就是dcVal  
  14.   Int x, y, iDstStride2, iSrcStride2;  
  15.   
  16.   // boundary pixels processing  
  17.   pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);  //!< 式子(8-35),左上角的点,利用其上邻点和左邻点与其加权平均  
  18. //! predSamples[0][0] = ( p[0][-1] + p[-1][0] + 2 * dcVal + 2 ) >> 2);   
  19.   for ( x = 1; x < iWidth; x++ ) //!< 上边界  
  20.   {  
  21.     pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) >> 2); //!< 式子(8-36),第一行的点,利用对应上邻点与其加权平均  
  22. // predSamples[x][0] = ( p[x][-1] + 3 * dcVal + 2 ) >> 2);  
  23.   }  
  24.   //! 左边界  
  25.   for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y < iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )  
  26.   {  
  27.     pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) >> 2); //!< 式子(8-37),第一列的点,利用对应左邻点与其加权平均  
  28. // predSamples[0][y] = ( p[-1][y] + 3 * dcVal + 2 ) >> 2);  
  29.   }  
  30.   
  31.   return;  
  32. }  

最后还剩下两个实际进行帧内模式预测的函数,篇幅关系,留待下一篇文章吧微笑

 

       周

       20130824


原创粉丝点击