34、hevc参考软件HM中Intra预测参考像素的获取与管理

继续上一个section所讨论的问题。在section 33中讨论了HEVC帧内预测的几种不同模式,代表这几种模式的函数xPredIntraPlanar、xPredIntraAng和xDCPredFiltering调用的位置位于Void TComPrediction::predIntraLumaAng()中,所以也可以说,在一个PU内,函数Void TComPrediction::predIntraLumaAng实现了亮度分量的帧内预测。该函数的实现方法如下:

  1. Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, 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;  
  14.   
  15.   // Create the prediction  
  16.   if ( uiDirMode == PLANAR_IDX )//Intra平面模式  
  17.   {  
  18.     xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );  
  19.   }  
  20.   else  
  21.   {  
  22.     if ( (iWidth > 16) || (iHeight > 16) )//Intra角度模式  
  23.     {  
  24.       xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );  
  25.     }  
  26.     else//对Intra16×16模式的特殊处理  
  27.     {  
  28.       xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );  
  29.   
  30.       if( (uiDirMode == DC_IDX ) && bAbove && bLeft )  
  31.       {  
  32.         xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);  
  33.       }  
  34.     }  
  35.   }  
  36. }  

该函数中存在一个非常关键的指针变量ptrSrc,指向的是当前块的参考数据。这个指针通过m_piYuvExt计算得来,方法是pcTComPattern->getPredictorPtr:
  1. Int* TComPattern::getPredictorPtr( UInt uiDirMode, UInt log2BlkSize, Int* piAdiBuf )  
  2. {  
  3.   Int* piSrc;  
  4.   assert(log2BlkSize >= 2 && log2BlkSize < 7);  
  5.   Int diff = min<Int>(abs((Int) uiDirMode - HOR_IDX), abs((Int)uiDirMode - VER_IDX));  
  6.   UChar ucFiltIdx = diff > m_aucIntraFilter[log2BlkSize - 2] ? 1 : 0;  
  7.   if (uiDirMode == DC_IDX)  
  8.   {  
  9.     ucFiltIdx = 0; //no smoothing for DC or LM chroma  
  10.   }  
  11.   
  12.   assert( ucFiltIdx <= 1 );  
  13.   
  14.   Int width  = 1 << log2BlkSize;  
  15.   Int height = 1 << log2BlkSize;  
  16.     
  17.   piSrc = getAdiOrgBuf( width, height, piAdiBuf );//该函数其实没有实际意义,直接返回<span style="font-family: Arial, Helvetica, sans-serif;">piAdiBuf </span>  
  18.   
  19.   if ( ucFiltIdx )  
  20.   {  
  21.     piSrc += (2 * width + 1) * (2 * height + 1);  
  22.   }  
  23.   
  24.   return piSrc;  
  25. }  

该函数首先判断当前的帧内预测方向同HOR_IDX、VER_IDX两个预设模式之绝对差的较小值,与某一个预定义的Filter指示标识(m_aucIntraFilter)进行比较。m_aucIntraFilter定义为:

  1. const UChar TComPattern::m_aucIntraFilter[5] =  
  2. {  
  3.   10, //4x4  
  4.   7, //8x8  
  5.   1, //16x16  
  6.   0, //32x32  
  7.   10, //64x64  
  8. };  

我们已经知道,HOR_IDX = 10,VER_IDX = 26,uiDirMode共有0~35这些取值。所以diff的取值范围只有[0, 10]这11个值,结合aucIntraFilter定义来看,可以认为是对于4×4和64×64的尺寸,ucFiltIdx始终为0;对于其他尺寸,块大小越大越需要滤波,对于32×32的块都需要滤波操作(至于如何进行滤波将在后面研究),而取滤波的数据就是讲指针piSrc向后移动一段距离,这段距离刚好是一组Intra参考数据的长度。


回到上一级函数之后,发现getPredictorPtr所操作的数据地址指针,其实就是m_piYuvExt。看来文章就在这个指针变量中了。m_piYuvExt定义在TComPrediction类中,在其构造函数中初始化,在析构函数中释放内存。分配响应的内存空间在函数Void TComPrediction::initTempBuff()中实现,这个函数在编码开始之前就会被调用。

实际的参考数据呢?实际上,在对当前PU的每一种模式进行遍历(TEncSearch::estIntraPredQT函数)之前,会有专门操作对m_piYuvExt进行数据填充操作,具体的操作在TComPattern::initAdiPattern中实现。该函数比较长就不贴在这里了,里面的核心部分是调用了fillReferenceSamples函数填充参考数据,随后生成Intra预测的滤波参考数据。


OK,本篇到此告一段落,下篇研究fillReferenceSamples的实现以及Intra参考数据滤波的原理。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值