本文主要记录 x264 中使用到的帧内预测技术。
Intra_4x4 预测模式
x264 中对 4x4 的预测模式如下:
Intra4x4PredMode[luma4x4BlkIdx] | Name of Intra4x4PredMode[luma4x4BlkIdx] |
---|---|
0 | Intra_4x4_Vertical(prediction mode) |
1 | Intra_4x4_Horizontal(prediction mode) |
2 | Intra_4x4_DC(prediction mode) |
3 | Intra_4x4_Diagonal_Down_Left(prediction mode) |
4 | Intra_4x4_Diagonal_Down_Right(prediction mode) |
5 | Intra_4x4_Vertical_Right(prediction mode) |
6 | Intra_4x4_Horizontal_Down(prediction mode) |
7 | Intra_4x4_Vertical_Left(prediction mode) |
8 | Intra_4x4_Horizontal_Up(prediction mode) |
下面依次分析这几种预测模式:
Intra_4x4_Vertical 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 0.
This mode shall be used only when the samples p[ x, -1 ] with x = 0..3 are marked as "available for Intra_4x4 prediction".
The values of the prediction samples pred4x4L[ x, y ], with x, y = 0..3, are derived by
$pred4x4_L[x,y]=p[x,-1], with x,y=0..3$
x264 中关于模式 Intra_4x4_Vertical 的代码如下:
1 2 3 4 5 6 7 8 9 |
|
Intra_4x4_Horizontal 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 1.
This mode shall be used only when the samples p[ −1, y ], with y = 0..3, are marked as "available for Intra_4x4 prediction".
The values of the prediction samples pred4x4L[ x, y ], with x, y = 0..3, are derived by
$pred4x4_L[x,y]=p[-1, y], with x,y=0..3$
x264 中关于模式 Intra_4x4_Vertical 的代码如下:
1 2 3 4 5 6 7 |
|
Intra_4x4_DC 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 2.
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:If all samples p[ x, −1 ], with x = 0..3, and p[ −1, y ], with y = 0..3, are marked as "available for Intra_4x4 prediction", the values of the prediction samples $pred4x4_L$[ x, y ], with x, y = 0..3, are derived by
$pred4x4_L[x,y]$ = (p[0,-1]+p[1,-1]+p[2,-1]+p[3,-1]+p[-1,0]+p[-1,1]+p[-1,2]+p[-1,3]+4)>>3Otherwise, if any samples p[ x, .1 ], with x = 0..3, are marked as "not available for Intra_4x4 prediction" and all samples p[ .1, y ], with y = 0..3, are marked as "available for Intra_4x4 prediction", the values of the prediction samples $pred4x4_L$[ x, y ], with x, y = 0..3, are derived by
$pred4x4_L[x,y] = (p[-1,0]+p[-1,1]+p[-1,2]+p[-1,3]+2)>>2$Otherwise, if any samples p[ .1, y ], with y = 0..3, are marked as "not available for Intra_4x4 prediction" and all samples p[ x, .1 ], with x = 0 .. 3, are marked as "available for Intra_4x4 prediction", the values of the prediction samples $pred4x4_L$[ x, y ], with x, y = 0 .. 3, are derived by
$pred4x4_L[x,y] = (p[0,-1]+p[1,-1]+p[2,-1]+p[3,-1]+2)>>2$Otherwise (some samples p[ x, .1 ], with x = 0..3, and some samples p[ .1, y ], with y = 0..3, are marked as "not available for Intra_4x4 prediction"), the values of the prediction samples $pred4x4_L$[ x, y ], with x, y = 0..3, are derived by
$pred4x4_L[x,y]=(1<<(BitDepth_Y-1))$
x264 中关于模式 Intra_4x4_DC 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Intra_4x4_Diagonal_Down_Left 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 3.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..7 are marked as "available for Intra_4x4 prediction".
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:If x is equal to 3 and y is equal to 3,
$pred4x4_L[ x, y ] = ( p[ 6, .1 ] + 3 * p[ 7, .1 ] + 2 ) >> 2$Otherwise (x is not equal to 3 or y is not equal to 3),
$pred4x4_L[ x, y ] = ( p[ x + y, −1 ] + 2 * p[ x + y + 1, −1 ] + p[ x + y + 2, −1 ] + 2 ) >> 2$
x264 中关于模式 Intra_4x4_DC 的代码如下:
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 |
|
Intra_4x4_Diagonal_Down_Right 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 4.
This mode shall be used only when the samples p[ x, .1 ] with x = 0..3 and p[ .1, y ] with y = .1..3 are marked as "available for Intra_4x4 prediction".
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:
If x is greater than y,
$pred4x4_L[ x, y ] = ( p[ x − y − 2, −1] + 2 * p[ x − y − 1, −1 ] + p[ x − y, −1 ] + 2 ) >> 2$
Otherwise if x is less than y,
$pred4x4_L[ x, y ] = ( p[ −1, y − x − 2 ] + 2 * p[ −1, y − x − 1 ] + p[ −1, y − x ] + 2 ) >> 2$
Otherwise (x is equal to y),
$pred4x4_L[ x, y ] = ( p[ 0, .1 ] + 2 * p[ .1, .1 ] + p[ .1, 0 ] + 2 ) >> 2$
x264 中关于模式 Intra_4x4_Diagonal_Down_Right 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Intra_4x4_Vertical_Right 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 5.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..3 and p[ −1, y ] with y = −1..3 are marked as "available for Intra_4x4 prediction".
Let the variable zVR be set equal to 2 * x − y.
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:If zVR is equal to 0,2,4 or 6,
$pred_L[x,y]=(p[x-(y>>1)-1,-1]+p[x-(y>>1),-1]+1)>>1$
Otherwise, if zVR is equal to 1, 3, or 5,
$pred4x4_L[x,y]=(p[x-(y>>1)-2,-1]+2*p[x-(y>>1)-1,-1]+p[x-(y>>1),-1]+2)>>2$
Otherwise, if zVR is equal to −1,
$pred4x4_L[ x, y ] = (p[-1, 0 ] + 2 * p[ -1, -1 ] + p[ 0, -1 ] + 2 ) >> 2$
Otherwise (zVR is equal to -2 or -3),
$pred4x4_L[ x, y ] = ( p[ −1, y − 1 ] + 2 * p[ −1, y − 2 ] + p[ −1, y − 3 ] + 2 ) >> 2$
x264 中关于模式 Intra_4x4_Vertical_Right 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Intra_4x4_Horizontal_Down 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 6.
This mode shall be used only when the samples p[ x, -1 ] with x = 0..3 and p[ -1, y ] with y = .1..3 are marked as "available for Intra_4x4 prediction".
Let the variable zHD be set equal to 2 * y - x.
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:
x264 中关于模式 Intra_4x4_Horizontal_Down 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Intra_4x4_Vertical_Left 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 7.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..7 are marked as "available for Intra_4x4 prediction".
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:
x264 中关于模式 Intra_4x4_Vertical_Left 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Intra_4x4_Horizontal_Up 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_4x4 prediction mode is invoked when Intra4x4PredMode[ luma4x4BlkIdx ] is equal to 8.
This mode shall be used only when the samples p[ −1, y ] with y = 0..3 are marked as "available for Intra_4x4 prediction".
Let the variable zHU be set equal to x + 2 * y.
The values of the prediction samples $pred4x4_L[ x, y ]$, with x, y = 0..3, are derived as follows:
x264 中关于模式 Intra_4x4_Horizontal_Up 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Intra_8x8 预测模式
x264 中对 8x8 的预测模式如下:
intra8x8Predmodei[luma8x8BlkIdx] | Name of Intra8x8PredMode[luma8x8BlkIdx] |
---|---|
0 | Intra_8x8_Vertical(prediction mode) |
1 | Intra_8x8_Horizontal(prediction mode) |
2 | Intra_8x8_DC(prediction mode) |
3 | Intra_8x8_Diagonal_Down_Left(prediction mode) |
4 | Intra_8x8_Diagonal_Down_Right(prediction mode) |
5 | Intra_8x8_Vertical_Right(prediction mode) |
6 | Intra_8x8_Horizontal_Down(prediction mode) |
7 | Intra_8x8_Vertical_Left(prediction mode) |
8 | Intra_8x8_Horizontal_Up(prediction mode) |
下面依次分析这几种预测模式:
Intra_8x8_Vertical 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 0.
This mode shall be used only when the samples p[ x, -1 ] with x = 0..7 are marked as "available for Intra_8x8 prediction".
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived by
$pred8x8_L[x,y]=p'[x,-1],with x,y=0..7$
X264 中关于模式 Intra_8x8_Vertical 的代码如下:
1 2 3 4 5 6 7 8 9 10 |
|
Intra_8x8_Horizontal 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 1.
This mode shall be used only when the samples p[ −1, y ], with y = 0..7, are marked as "available for Intra_8x8 prediction".
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived by
$pred8x8_L[x,y]=p'[-1,y], with x,y=0..7$
x264 中对 Intra_8x8_Horizontal 的代码如下:
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 |
|
Intra_8x8_DC 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 2.
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
x264 中对 Intra_8x8_DC 模式的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Intra_8x8_Diagonal_Down_Left 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 3.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..15 are marked as "available for Intra_8x8 prediction".
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If x is equal to 7 and y is equal to 7,
$pred8xx_L[x,y]=( p′[ 14, −1 ] + 3 * p′[ 15, −1 ] + 2 ) >> 2$
Otherwise (x is not equal to 7 or y is not equal to 7)
$pred8x8_L[ x, y ] = ( p′[ x + y, −1 ] + 2 * p′[ x + y + 1, −1 ] + p′[ x + y + 2, −1 ] + 2 ) >> 2$
X264 中关于模式 Intra_8x8_Diagonal_Down_Left 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Intra_8x8_Diagonal_Down_Right 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 4.
This mode shall be used only when the samples p[ x, .1 ] with x = 0..7 and p[ .1, y ] with y = .1..7 are marked as
"available for Intra_8x8 prediction".
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If x is greater than y,
$pred8x8_L[ x, y ] = ( p′[ x − y − 2, −1] + 2 * p′[ x − y − 1, −1 ] + p′[ x − y, −1 ] + 2 ) >> 2$
Otherwise if x is less than y,
$pred8x8_L[ x, y ] = ( p′[ .1, y . x . 2 ] + 2 * p′[ .1, y . x . 1 ] + p′[ .1, y . x ] + 2 ) >> 2$
Otherwise (x is equal to y),
$pred8x8_L[ x, y ] = ( p′[ 0, −1 ] + 2 * p′[ −1, −1 ] + p′[ −1, 0 ] + 2 ) >> 2$
X264 中关于模式 Intra_8x8_Diagonal_Down_Right 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Intra_8x8_Vertical_Right 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 5.
This mode shall be used only when the samples p[ x, -1 ] with x = 0..7 and p[ -1, y ] with y = -1..7 are marked as "available for Intra_8x8 prediction".
Let the variable zVR be set equal to 2 * x . y.
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If zVR is equal to 0, 2, 4, 6, 8, 10, 12, or 14
$pred8x8_L[x,y] = (p'[x-y(y>>1)-1,-1] + p'[x-(y>>1),-1]+1)>>1$
Otherwise, if zVR is equal to 1, 3, 5, 7, 9, 11, or 13
$pred8x8_L[x,y]=(p'[x-(y>>1)-2,-1]+2*p'[x-(y>>1)-1,-1]+p'[x-(y>>1),-1]+2)>>2$
Otherwise, if zVR is equal to −1,
$pred8x8_L[ x, y ] = ( p′[ −1, 0 ] + 2 * p′[ −1, −1 ] + p′[ 0, −1 ] + 2 ) >> 2$
Otherwise (zVR is equal to .2, .3, .4, .5, .6, or .7),
$pred8x8_L[ x, y ] = ( p′[ -1, y . 2*x - 1 ] + 2 * p′[ -1, y - 2*x - 2 ] + p′[ -1, y - 2*x - 3 ] + 2 ) >> 2$
X264 中关于模式 Intra_8x8_Vertical_Right 的代码如下:
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 |
|
Intra_8x8_Horizontal_Down 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 6.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..7 and p[ −1, y ] with y = −1..7 are marked as "available for Intra_8x8 prediction".
Let the variable zHD be set equal to 2 * y − x.
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If zHD is equal to 0, 2, 4, 6, 8, 10, 12, or 14
$pred8x8_L[ x, y ] = ( p′[ −1, y − ( x >> 1 ) − 1 ] + p′[ −1, y − ( x >> 1 ) ] + 1 ) >> 1$
Otherwise, if zHD is equal to 1, 3, 5, 7, 9, 11, or 13
$pred8x8_L[x,y]=(p′[-1, y -(x>>1)-2]+2*p′[-1,y-(x>>1)-1]+p′[-1,y-(x>>1)]+2)>>2$
Otherwise, if zHD is equal to −1,
$pred8x8L[ x, y ] = ( p′[ −1, 0 ] + 2 * p′[ −1, −1 ] + p′[ 0, −1 ] + 2 ) >> 2$
Otherwise (zHD is equal to −2, −3, −4, −5, −6, −7),
$pred8x8L[ x, y ] = ( p′[ x − 2*y − 1, −1 ] + 2 * p′[ x − 2*y − 2, −1 ] + p′[ x − 2*y − 3, −1 ] + 2 ) >> 2$
X264 中关于模式 Intra_8x8_Horizontal_Down 的代码如下:
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 |
|
Intra_8x8_Vertical_Left 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 7.
This mode shall be used only when the samples p[ x, −1 ] with x = 0..15 are marked as "available for Intra_8x8 prediction".
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If y is equal to 0, 2, 4 or 6
$pred8x8_L[ x, y ] = ( p′[ x + ( y >> 1 ), .1 ] + p′[ x + ( y >> 1 ) + 1, .1 ] + 1) >> 1$
Otherwise (y is equal to 1, 3, 5, 7),
$pred8x8_L[ x, y ] = ( p′[ x + ( y >> 1 ), −1 ] + 2 * p′[ x + ( y >> 1 ) + 1, −1 ] + p′[ x + ( y >> 1 ) + 2, −1 ] + 2 ) >>2$
X264 中关于模式 Intra_8x8_Horizontal_Down 的代码如下:
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 |
|
Intra_8x8_Horizontal_Up 预测模式
在SPEC 中,关于该预测模式的定义如下:
This Intra_8x8 prediction mode is invoked when Intra8x8PredMode[ luma8x8BlkIdx ] is equal to 8.
This mode shall be used only when the samples p[ -1, y ] with y = 0..7 are marked as "available for Intra_8x8 prediction".
Let the variable zHU be set equal to x + 2 * y.
The values of the prediction samples $pred8x8_L[ x, y ]$, with x, y = 0..7, are derived as follows:
If zHU is equal to 0, 2, 4, 6, 8, 10, or 12
$pred8x8_L[ x, y ] = ( p′[ −1, y + ( x >> 1 ) ] + p′[ −1, y + ( x >> 1 ) + 1 ] + 1 ) >> 1$
Otherwise, if zHU is equal to 1, 3, 5, 7, 9, or 11
$pred8x8_L[ x, y ] = ( p′[ −1, y + ( x >> 1 ) ] + 2 * p′[ −1, y + ( x >> 1 ) + 1 ] + p′[ −1, y + ( x >> 1 ) + 2 ] + 2 ) >>2$
Otherwise, if zHU is equal to 13,
$pred8x8_L[ x, y ] = ( p′[ −1, 6 ] + 3 * p′[ −1, 7 ] + 2 ) >> 2$
Otherwise (zHU is greater than 13),
$pred8x8_L[x,y]=p'[-1,7]$
X264 中关于模式 Intra_8x8_Horizontal_Up 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Intra_16x16 预测模式
x264 中对 16x16 的预测模式如下:
intra16x16Predmode | Name of Intra16x16PredMode | Note |
---|---|---|
0 | Intra_16x16_Vertical(prediction mode) | 由上边像素推出相应像素值 |
1 | Intra_16x16_Horicontal(prdiction mode) | 由左边像素推出相应像素值 |
2 | Intra_16x16_DC(prediction mode) | 由上边和左边像素平均值推出相应像素值 |
3 | Intra_16x16_Plane(prediction mode) | 利用线性 plan 函数及左、上像素推出相应像素值,适用于亮度变化平缓区域 |
下面依次分析这几种预测模式:
Intra_16x16_Vertical 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_16x16 prediction mode shall be used only when the samples p[x, -1] with x=0...15 are marked as "available for Intra_16x16 prediction".The values of the prediction samples pred[x, y] with x,y=0...15, are derived by pred[x,y]=p[x,-1],with x,y=0...15
从 SPEC 中可以看出,只要16x16
宏块正上方的 16 个元素可用,就可以使用使用Intra_16x16_Vertical
预测模式,至于该宏块的左边像素是否可用,并不影响。示例如下:
x264 中关于模式 Vertical 的C 代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
注意,上面代码中的 pixel 为 uint8_t,而 pixel4 为 uint32_t,而 MPIXEL_X4 定义如下:
1 2 3 |
|
分析上面的代码结合上面的图,可以看出,每执行一次 for 循环,都对16x16
的每一行像素进行赋值,而赋值的最小单位是4byte,一行像素需要4次赋值完成,值得大小就是宏块的上一行像素值得大小。
执行完整个 for 循环后,16x16 宏块像素赋值结束。
针对AARCH64
平台,X264 做了汇编优化,其代码如下:
1 2 3 4 5 6 7 8 9 |
|
上面的汇编代码可以看出,同样是循环执行16次,因为是64位,所以每次赋值即可实现16字节的运算,相对于上面的C语言版,赋值语句是其1/4,实现了效率上的优化。
Intra_16x16_Horizontal 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_16x16 prediction mode shall be used only when the samples p[−1, y] with y = 0..15 are marked as "available
for Intra_16x16 prediction".
The values of the prediction samples predL[ x, y ], with x, y = 0..15, are derived by
predL[ x, y ] = p[ −1, y ], with x, y = 0..15
从 SPEC 中可以看出,只要16x16
宏块左方的 16 个元素可用,就可以使用使用Intra_16x16_Vertical
预测模式,至于该宏块的上边像素是否可用,并不影响。示例如下:
x264 中关于模式 Horizontal 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
其中PIXEL_SPLAT_X4
定义如下:
1
|
|
该宏的作用是将1字节的数据,扩展为4字节的数据,其中的每个字节大小与起始的第一个字节相等。
分析上面的代码结合上面的图,可以看出,每执行一次for循环,都对16x16
的每一行像素进行赋值,而赋值的最小单位是4byte,一行像素
需要4次赋值完成,值得大小就是宏块的左边像素值得大小。执行完整个for循环后,16x16宏块像素值结束。
针对AARCH64
平台,X264 做了汇编优化,其代码如下:
1 2 3 4 5 6 7 8 9 10 11 |
|
Intra_16x16_DC 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_16x16 prediction mode operates, depending on whether the neighbouring samples are marked as "available for Intra_16x16 prediction", as follows:
If all neighbouring samples p[x,-1] ], with x = 0..15, and p[ −1, y ], with y = 0..15, are marked as "available for Intra_16x16 prediction", the prediction for all luma samples in the macroblock is given by: $pred_L[x,y]=(\sum_{x'=0}^{15}p[x',-1]+\sum_{y'=0}^{15}p[-1,y']+16)>>5, with x,y=0..15$
Otherwise, if any of the neighbouring samples p[ x, .1 ], with x = 0..15, are marked as "not available for Intra_16x16 prediction" and all of the neighbouring samples p[ .1, y ], with y = 0..15, are marked as "available for Intra_16x16 prediction", the prediction for all luma samples in the macroblock is given by: $pred_L[x,y]=(\sum_{y'=0}^{15}p[-1,y']+8)>>4, with x,y=0..15$
Otherwise, if any of the neighbouring samples p[ −1, y ], with y = 0..15, are marked as "not available for Intra_16x16 prediction" and all of the neighbouring samples p[ x, −1 ], with x = 0..15, are marked as "available for Intra_16x16 prediction", the prediction for all luma samples in the macroblock is given by: $pred_L[x,y]=(\sum_{x'=0}^{15}p[x',-1]+8)>>4, with x,y=0..15$
Otherwise (some of the neighbouring samples p[ x, .1 ], with x = 0..15, and some of the neighbouring samples p[ .1, y ], with y = 0..15, are marked as "not available for Intra_16x16 prediction"), the prediction for all luma samples in the macroblock is given by: $pred_L[x,y]=(1<<(BitDepth_Y - 1)), with x,y=0..15$
通过 SPEC 描述可以看出来,DC 模式分为4种情况,一种是宏块的上方和左方宏块像素均可用时,此时宏块内的像素值为参考像素值得平均值;第二种是当左方像素不可用、上方像素可用时,宏块内的像素值为上方可用像素的平均值; 第三种是当上方像素不可用、左方像素可用时,宏块内的像素值为左方可用像素的平均值。最后一种,当上方和左方像素均不可用时,宏块内像素值与BitDepth有关。此处仅仅举例上方和左方像素均可用的例子。
x264 中关于模式 DC 的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Intra_16x16_Plane 预测模式
在 SPEC 中,关于该预测模式的定义如下:
This Intra_16x16 prediction mode shall be used only when the samples p[ x, .1 ] with x = .1..15 and p[ .1, y ] with y = 0..15 are marked as "available for Intra_16x16 prediction".
The values of the prediction samples $pred_L[x,y]$,with x,y=0...15, are derived by
$pred_L[x,y]=Clip1_Y((a+b*(x-7)+c*(y-7)+16)>>5)$,with x,y=0...15, where
$a = 16 * ( p[ .1, 15 ] + p[ 15, .1 ] )$
$b = ( 5 * H + 32 ) >> 6$
$c = ( 5 * V + 32 ) >> 6$
and H and V are specified as
$H=\sum_{x'=0}^{7}(x'+1)*(p[8+x',-1]-p[6-x',-1])$
$V=\sum_{y'=0}^{7}(y'+1)*(p[-1,8+y']-p[-1,6-y'])$
x264 中关于模式 Plane 的代码如下:
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 |
|