2021-03-09

这篇博客讲HM代码中xPredIntraPlanar、xPredIntraAng、xDCPredFiltering三个函数,有关帧内预测的理论知识看 https://blog.csdn.net/shayashi/article/details/82877875
xPredIntraPlanar函数是对Planar模式预测的函数,Planar模式对应0,该模式的预测采用同双线性差值方式,代码如下:

Void TComPrediction::xPredIntraPlanar( const Pel* pSrc, Int srcStride, Pel* rpDst, Int dstStride, UInt width, UInt height )
{
  assert(width <= height);

Int leftColumn[MAX_CU_SIZE+1], topRow[MAX_CU_SIZE+1], bottomRow[MAX_CU_SIZE], rightColumn[MAX_CU_SIZE];//参考像素
UInt shift1Dhor = g_aucConvertToBit[ width ] + 2;//水平移动位数
UInt shift1Dver = g_aucConvertToBit[ height ] + 2;//竖直移动位数
//g_aucConvertToBit是对应的bit数 [4]==0 [8]==1 [16]==2 [32]==3 [64]==4 other -1
// Get left and above reference column and row获取参考像素
for(Int k=0;k<width+1;k++)
{
topRow[k] = pSrc[k-srcStride];//srcStride == 2 * width + 1
}

for (Int k=0; k < height+1; k++)
{
leftColumn[k] = pSrc[k*srcStride-1];
}

// Prepare intermediate variables used in interpolation
Int bottomLeft = leftColumn[height];
Int topRight = topRow[width];
//bottomRow[k]= leftColumn[height]-topRow[k],且将topRow的数值乘height
for(Int k=0;k<width;k++)
{
bottomRow[k] = bottomLeft - topRow[k];
topRow[k] <<= shift1Dver;
}
//rightColumn[k]=topRow[width]-leftColumn[k],将leftColumn的数值乘width
for(Int k=0;k<height;k++)
{
rightColumn[k] = topRight - leftColumn[k];
leftColumn[k] <<= shift1Dhor;
}

const UInt topRowShift = 0;

// 生成预测信号
//双线性插值就是像素对应的上、下和左、右参考像素成比例的和。
//horPred(x,y) = (width - x) * leftColumn[y] + x * topRight
//vertPred(x,y) = (width - y) * topRight[y] + y * bottomLeft
//rpDst(x,y) = (horPred(x,y) + vertPred(x,y)) >> (shift1Dhor+1)
for (Int y=0;y<height;y++)
{
Int horPred = leftColumn[y] + width;
for (Int x=0;x<width;x++)
{
horPred += rightColumn[y];
topRow[x] += bottomRow[x];

  Int vertPred = ((topRow[x] + topRowShift)&gt;&gt;topRowShift);
  rpDst[y*dstStride+x] = ( horPred + vertPred ) &gt;&gt; (shift1Dhor+1);//dstStride == width
}

}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55

xPredIntraAng函数是对DC模式和角度模式进行预测的函数:

Void TComPrediction::xPredIntraAng(       Int bitDepth,
                                    const Pel* pSrc,     Int srcStride,
                                          Pel* pTrueDst, Int dstStrideTrue,
                                          UInt uiWidth, UInt uiHeight, ChannelType channelType,
                                          UInt dirMode, const Bool bEnableEdgeFilters
                                  )
{
  Int width=Int(uiWidth);
  Int height=Int(uiHeight);

// Map the mode index to main prediction direction and angle
assert( dirMode != PLANAR_IDX ); //no planar
const Bool modeDC = dirMode==DC_IDX;

// Do the DC prediction DC模式就是对块中的每一个像素设置为平均值
if (modeDC)
{
const Pel dcval = predIntraGetPredValDC(pSrc, srcStride, width, height);

for (Int y=height;y&gt;0;y--, pTrueDst+=dstStrideTrue)
{
  for (Int x=0; x&lt;width;) // width is always a multiple of 4.
  {
    pTrueDst[x++] = dcval;
  }
}

}
else // Do angular predictions
{
const Bool bIsModeVer = (dirMode >= 18);//是否是竖直模式
const Int intraPredAngleMode = (bIsModeVer) ? (Int)dirMode - VER_IDX : -((Int)dirMode - HOR_IDX);//竖直模式:mode - 26 ;水平模式:10-mode
const Int absAngMode = abs(intraPredAngleMode);
const Int signAng = intraPredAngleMode < 0 ? -1 : 1;//sin正负
const Bool edgeFilter = bEnableEdgeFilters && isLuma(channelType) && (width <= MAXIMUM_INTRA_FILTERED_WIDTH) && (height <= MAXIMUM_INTRA_FILTERED_HEIGHT);//当块大小小于等于16x16且是亮度预测且bEnableEdgeFilters ==true进行边缘滤波

// Set bitshifts and scale the angle parameter to block size
static const Int angTable[9]    = {0,    2,    5,   9,  13,  17,  21,  26,  32};//mode偏移量绝对值
static const Int invAngTable[9] = {0, 4096, 1638, 910, 630, 482, 390, 315, 256}; // (256 * 32) / Angle
Int invAngle                    = invAngTable[absAngMode];
Int absAng                      = angTable[absAngMode];
Int intraPredAngle              = signAng * absAng;

Pel* refMain;
Pel* refSide;

Pel  refAbove[2*MAX_CU_SIZE+1];
Pel  refLeft[2*MAX_CU_SIZE+1];

// Initialize the Main and Left reference array.映射
if (intraPredAngle &lt; 0)
{
  const Int refMainOffsetPreScale = (bIsModeVer ? height : width ) - 1;
  const Int refMainOffset         = height - 1;
  for (Int x=0;x&lt;width+1;x++)
  {
    refAbove[x+refMainOffset] = pSrc[x-srcStride-1];
  }
  for (Int y=0;y&lt;height+1;y++)
  {
    refLeft[y+refMainOffset] = pSrc[(y-1)*srcStride-1];
  }
  refMain = (bIsModeVer ? refAbove : refLeft)  + refMainOffset;
  refSide = (bIsModeVer ? refLeft  : refAbove) + refMainOffset;

  // Extend the Main reference to the left.
  Int invAngleSum    = 128;       // rounding for (shift by 8)
  for (Int k=-1; k&gt;(refMainOffsetPreScale+1)*intraPredAngle&gt;&gt;5; k--)
  {
    invAngleSum += invAngle;
    refMain[k] = refSide[invAngleSum&gt;&gt;8];
  }
}
else// (2 &lt;= mode &lt;= 10) || (26 &lt;= mode &lt;= 34)
{
  for (Int x=0;x&lt;2*width+1;x++)
  {
    refAbove[x] = pSrc[x-srcStride-1];//srcStride == 2*width+1
  }
  for (Int y=0;y&lt;2*height+1;y++)
  {
    refLeft[y] = pSrc[(y-1)*srcStride-1];
  }
  refMain = bIsModeVer ? refAbove : refLeft ;//主参考像素
  refSide = bIsModeVer ? refLeft  : refAbove;
}

// swap width/height if we are doing a horizontal mode:
Pel tempArray[MAX_CU_SIZE*MAX_CU_SIZE];
const Int dstStride = bIsModeVer ? dstStrideTrue : MAX_CU_SIZE;
Pel *pDst = bIsModeVer ? pTrueDst : tempArray;
if (!bIsModeVer)
{
  std::swap(width, height);
}

if (intraPredAngle == 0)  // pure vertical or pure horizontal
{
  for (Int y=0;y&lt;height;y++)
  {
    for (Int x=0;x&lt;width;x++)
    {
      pDst[y*dstStride+x] = refMain[x+1];
    }
  }

  if (edgeFilter)
  {
    for (Int y=0;y&lt;height;y++)
    {//边缘滤波 当前像素值+(对应参考像素值和左上角参考像素和的1/2)
      pDst[y*dstStride] = Clip3 (0, ((1 &lt;&lt; bitDepth) - 1), pDst[y*dstStride] + (( refSide[y+1] - refSide[0] ) &gt;&gt; 1) );
    }
  }
}
else
{
  Pel *pDsty=pDst;

  for (Int y=0, deltaPos=intraPredAngle; y&lt;height; y++, deltaPos+=intraPredAngle, pDsty+=dstStride)
  {
    const Int deltaInt   = deltaPos &gt;&gt; 5;//坐标整数部分
    const Int deltaFract = deltaPos &amp; (32 - 1);//坐标分数部分

//pDsty[x] = ((32 - deltaFract) * refMain[x + deltaInt+1] + deltaFract * refMain[x + deltaInt+2] + 16) >> 5
if (deltaFract)
{
// Do linear filtering
const Pel *pRM=refMain+deltaInt+1;
Int lastRefMainPel=*pRM++;
for (Int x=0;x<width;pRM++,x++)
{
Int thisRefMainPel=*pRM;
pDsty[x+0] = (Pel) ( ((32-deltaFract)lastRefMainPel + deltaFractthisRefMainPel +16) >> 5 );
lastRefMainPel=thisRefMainPel;
}
}
else
{
// Just copy the integer samples
for (Int x=0;x<width; x++)
{
pDsty[x] = refMain[x+deltaInt+1];
}
}
}
}

// Flip the block if this is the horizontal mode水平模式翻转
if (!bIsModeVer)
{
  for (Int y=0; y&lt;height; y++)
  {
    for (Int x=0; x&lt;width; x++)
    {
      pTrueDst[x*dstStrideTrue] = pDst[x];
    }
    pTrueDst++;
    pDst+=dstStride;
  }
}

}
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160

xDCPredFiltering函数是对DC模式进行边缘滤波的函数,对第一行和第一列进行滤波:

Void TComPrediction::xDCPredFiltering( const Pel* pSrc, Int iSrcStride, Pel* pDst, Int iDstStride, Int iWidth, Int iHeight, ChannelType channelType )
{
  Int x, y, iDstStride2, iSrcStride2;
//亮度模式且小于等于16x16才进行滤波
  if (isLuma(channelType) && (iWidth <= MAXIMUM_INTRA_FILTERED_WIDTH) && (iHeight <= MAXIMUM_INTRA_FILTERED_HEIGHT))
  {
    //top-left pDst[0] = 当前像素值和左边像素上边参考像素进行2 1 1滤波
    pDst[0] = (Pel)((pSrc[-iSrcStride] + pSrc[-1] + 2 * pDst[0] + 2) >> 2);
//top row (vertical filter)第一行像素值等于当前像素和上边参考像素进行3 1滤波
for ( x = 1; x &lt; iWidth; x++ )
{
  pDst[x] = (Pel)((pSrc[x - iSrcStride] +  3 * pDst[x] + 2) &gt;&gt; 2);
}

//left column (horizontal filter)第一列像素值等于当前像素和左边参考像素进行3 1滤波
for ( y = 1, iDstStride2 = iDstStride, iSrcStride2 = iSrcStride-1; y &lt; iHeight; y++, iDstStride2+=iDstStride, iSrcStride2+=iSrcStride )
{
  pDst[iDstStride2] = (Pel)((pSrc[iSrcStride2] + 3 * pDst[iDstStride2] + 2) &gt;&gt; 2);
}

}

return;
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值