您的位置:首页 > 其它

【HEVC学习与研究】34、HEVC参考软件HM中Intra预测参考像素的获取与管理

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

Void TComPrediction::predIntraLumaAng(TComPattern* pcTComPattern, UInt uiDirMode, Pel* piPred, UInt uiStride, Int iWidth, Int iHeight, 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;

  // Create the prediction
  if ( uiDirMode == PLANAR_IDX )//Intra平面模式
  {
    xPredIntraPlanar( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight );
  }
  else
  {
    if ( (iWidth > 16) || (iHeight > 16) )//Intra角度模式
    {
      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, false );
    }
    else//对Intra16×16模式的特殊处理
    {
      xPredIntraAng(g_bitDepthY, ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight, uiDirMode, bAbove, bLeft, true );

      if( (uiDirMode == DC_IDX ) && bAbove && bLeft )
      {
        xDCPredFiltering( ptrSrc+sw+1, sw, pDst, uiStride, iWidth, iHeight);
      }
    }
  }
}


该函数中存在一个非常关键的指针变量ptrSrc,指向的是当前块的参考数据。这个指针通过m_piYuvExt计算得来,方法是pcTComPattern->getPredictorPtr:

Int* TComPattern::getPredictorPtr( UInt uiDirMode, UInt log2BlkSize, Int* piAdiBuf )
{
  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 (uiDirMode == DC_IDX)
  {
    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 );//该函数其实没有实际意义,直接返回<span style="font-family: Arial, Helvetica, sans-serif;">piAdiBuf </span>

  if ( ucFiltIdx )
  {
    piSrc += (2 * width + 1) * (2 * height + 1);
  }

  return piSrc;
}


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

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


我们已经知道,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参考数据滤波的原理。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: