提交 43efd19a 编写于 作者: L Loren Merritt

decode H.264 with 8x8 transform.

deblocking is still incorrect with 8x8+cavlc

Originally committed as revision 4339 to svn://svn.ffmpeg.org/ffmpeg/trunk
上级 20ffdcf9
......@@ -3685,6 +3685,7 @@ void dsputil_init(DSPContext* c, AVCodecContext *avctx)
}
c->h264_idct_add= ff_h264_idct_add_c;
c->h264_idct8_add= ff_h264_idct8_add_c;
c->get_pixels = get_pixels_c;
c->diff_pixels = diff_pixels_c;
......
......@@ -50,6 +50,7 @@ void ff_fdct_mmx(DCTELEM *block);
void ff_fdct_mmx2(DCTELEM *block);
void ff_fdct_sse2(DCTELEM *block);
void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride);
void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride);
void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block);
void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block);
......@@ -325,6 +326,7 @@ typedef struct DSPContext {
#define RECON_SHIFT 6
void (*h264_idct_add)(uint8_t *dst, DCTELEM *block, int stride);
void (*h264_idct8_add)(uint8_t *dst, DCTELEM *block, int stride);
} DSPContext;
void dsputil_static_init(void);
......
此差异已折叠。
......@@ -306,8 +306,50 @@ static const uint8_t chroma_dc_scan[4]={
(0+1*2)*16, (1+1*2)*16, //FIXME
};
static const uint8_t zigzag_scan8x8[64]={
0+0*8, 1+0*8, 0+1*8, 0+2*8,
1+1*8, 2+0*8, 3+0*8, 2+1*8,
1+2*8, 0+3*8, 0+4*8, 1+3*8,
2+2*8, 3+1*8, 4+0*8, 5+0*8,
4+1*8, 3+2*8, 2+3*8, 1+4*8,
0+5*8, 0+6*8, 1+5*8, 2+4*8,
3+3*8, 4+2*8, 5+1*8, 6+0*8,
7+0*8, 6+1*8, 5+2*8, 4+3*8,
3+4*8, 2+5*8, 1+6*8, 0+7*8,
1+7*8, 2+6*8, 3+5*8, 4+4*8,
5+3*8, 6+2*8, 7+1*8, 7+2*8,
6+3*8, 5+4*8, 4+5*8, 3+6*8,
2+7*8, 3+7*8, 4+6*8, 5+5*8,
6+4*8, 7+3*8, 7+4*8, 6+5*8,
5+6*8, 4+7*8, 5+7*8, 6+6*8,
7+5*8, 7+6*8, 6+7*8, 7+7*8,
};
// zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)]
static const uint8_t zigzag_scan8x8_cavlc[64]={
0+0*8, 1+1*8, 1+2*8, 2+2*8,
4+1*8, 0+5*8, 3+3*8, 7+0*8,
3+4*8, 1+7*8, 5+3*8, 6+3*8,
2+7*8, 6+4*8, 5+6*8, 7+5*8,
1+0*8, 2+0*8, 0+3*8, 3+1*8,
3+2*8, 0+6*8, 4+2*8, 6+1*8,
2+5*8, 2+6*8, 6+2*8, 5+4*8,
3+7*8, 7+3*8, 4+7*8, 7+6*8,
0+1*8, 3+0*8, 0+4*8, 4+0*8,
2+3*8, 1+5*8, 5+1*8, 5+2*8,
1+6*8, 3+5*8, 7+1*8, 4+5*8,
4+6*8, 7+4*8, 5+7*8, 6+7*8,
0+2*8, 2+1*8, 1+3*8, 5+0*8,
1+4*8, 2+4*8, 6+0*8, 4+3*8,
0+7*8, 4+4*8, 7+2*8, 3+6*8,
5+5*8, 6+5*8, 6+6*8, 7+7*8,
};
#define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16bit
#define MB_TYPE_8x8DCT 0x01000000
#define IS_REF0(a) ((a)&MB_TYPE_REF0)
#define IS_8x8DCT(a) ((a)&MB_TYPE_8x8DCT)
typedef struct IMbInfo{
uint16_t type;
......@@ -472,6 +514,18 @@ static const uint16_t dequant_coeff[52][16]={
//{4608,5888,4608,5888, 5888,7424,5888,7424, 4608,5888,4608,5888, 5888,7424,5888,7424, },
};
static const int dequant8_coeff_init_scan[16] = {
0,3,4,3, 3,1,5,1, 4,5,2,5, 3,1,5,1
};
static const int dequant8_coeff_init[6][6]={
{20,18,32,19,25,24},
{22,19,35,21,28,26},
{26,23,42,24,33,31},
{28,25,45,26,35,33},
{32,28,51,30,40,38},
{36,32,58,34,46,43},
};
#define QUANT_SHIFT 22
static const int quant_coeff[52][16]={
......@@ -561,7 +615,7 @@ static const int tc0_table[52][3] = {
/* Cabac pre state table */
static const int cabac_context_init_I[399][2] =
static const int cabac_context_init_I[460][2] =
{
/* 0 - 10 */
{ 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 },
......@@ -707,10 +761,30 @@ static const int cabac_context_init_I[399][2] =
{ 31, -7 }, { 35, -15 }, { 34, -3 }, { 34, 3 },
{ 36, -1 }, { 34, 5 }, { 32, 11 }, { 35, 5 },
{ 34, 12 }, { 39, 11 }, { 30, 29 }, { 34, 26 },
{ 29, 39 }, { 19, 66 }
{ 29, 39 }, { 19, 66 },
/* 399 -> 435 */
{ 31, 21 }, { 31, 31 }, { 25, 50 },
{ -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 },
{ -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 },
{ -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 },
{ -23, 68 }, { -24, 50 }, { -11, 74 }, { 23, -13 },
{ 26, -13 }, { 40, -15 }, { 49, -14 }, { 44, 3 },
{ 45, 6 }, { 44, 34 }, { 33, 54 }, { 19, 82 },
{ -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 },
{ 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 },
{ 0, 68 }, { -9, 92 },
/* 436 -> 459 */
{ -14, 106 }, { -13, 97 }, { -15, 90 }, { -12, 90 },
{ -18, 88 }, { -10, 73 }, { -9, 79 }, { -14, 86 },
{ -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 },
{ -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 },
{ 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 },
{ 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 }
};
static const int cabac_context_init_PB[3][399][2] =
static const int cabac_context_init_PB[3][460][2] =
{
/* i_cabac_init_idc == 0 */
{
......@@ -847,7 +921,25 @@ static const int cabac_context_init_PB[3][399][2] =
{ 23, 42 }, { 19, 57 }, { 22, 53 }, { 22, 61 },
{ 11, 86 },
/* 399 - 435 */
{ 12, 40 }, { 11, 51 }, { 14, 59 },
{ -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 },
{ -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 },
{ -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 },
{ -16, 66 }, { -22, 65 }, { -20, 63 }, { 9, -2 },
{ 26, -9 }, { 33, -9 }, { 39, -7 }, { 41, -2 },
{ 45, 3 }, { 49, 9 }, { 45, 27 }, { 36, 59 },
{ -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 },
{ -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 },
{ -8, 66 }, { -8, 76 },
/* 436 - 459 */
{ -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
{ -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 },
{ -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
{ -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 },
{ 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 },
{ 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 },
},
/* i_cabac_init_idc == 1 */
......@@ -985,6 +1077,25 @@ static const int cabac_context_init_PB[3][399][2] =
{ 18, 50 }, { 12, 70 }, { 21, 54 }, { 14, 71 },
{ 11, 83 },
/* 399 - 435 */
{ 24, 32 }, { 21, 49 }, { 21, 54 },
{ -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 },
{ -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 8 },
{ -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 },
{ -14, 66 }, { 0, 59 }, { 2, 59 }, { 17, -10 },
{ 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
{ 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
{ -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 },
{ -2, 52 }, { -9, 57 }, { -6, 53 }, { -4, 65 },
{ -4, 67 }, { -7, 82 },
/* 436 - 459 */
{ -3, 81 }, { -3, 76 }, { -7, 72 }, { -6, 78 },
{ -12, 72 }, { -14, 68 }, { -3, 70 }, { -6, 76 },
{ -5, 66 }, { -5, 62 }, { 0, 57 }, { -4, 61 },
{ -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 },
{ 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 },
{ 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 },
},
/* i_cabac_init_idc == 2 */
......@@ -1121,5 +1232,25 @@ static const int cabac_context_init_PB[3][399][2] =
{ 22, 42 }, { 16, 60 }, { 15, 52 }, { 14, 60 },
{ 3, 78 }, { -16, 123 }, { 21, 53 }, { 22, 56 },
{ 25, 61 },
/* 399 - 435 */
{ 21, 33 }, { 19, 50 }, { 17, 61 },
{ -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
{ -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
{ -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
{ -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
{ 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
{ 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
{ -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 },
{ -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 },
{ -6, 68 }, { -10, 79 },
/* 436 - 459 */
{ -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 },
{ -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 },
{ -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 },
{ -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 },
{ 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 },
{ 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 },
}
};
......@@ -68,3 +68,74 @@ void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){
void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block){
idct_internal(dst, block, stride, 8, 3, 0);
}
void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride){
int i;
DCTELEM (*src)[8] = (DCTELEM(*)[8])block;
uint8_t *cm = cropTbl + MAX_NEG_CROP;
block[0] += 32;
for( i = 0; i < 8; i++ )
{
const int a0 = src[i][0] + src[i][4];
const int a2 = src[i][0] - src[i][4];
const int a4 = (src[i][2]>>1) - src[i][6];
const int a6 = (src[i][6]>>1) + src[i][2];
const int b0 = a0 + a6;
const int b2 = a2 + a4;
const int b4 = a2 - a4;
const int b6 = a0 - a6;
const int a1 = -src[i][3] + src[i][5] - src[i][7] - (src[i][7]>>1);
const int a3 = src[i][1] + src[i][7] - src[i][3] - (src[i][3]>>1);
const int a5 = -src[i][1] + src[i][7] + src[i][5] + (src[i][5]>>1);
const int a7 = src[i][3] + src[i][5] + src[i][1] + (src[i][1]>>1);
const int b1 = (a7>>2) + a1;
const int b3 = a3 + (a5>>2);
const int b5 = (a3>>2) - a5;
const int b7 = a7 - (a1>>2);
src[i][0] = b0 + b7;
src[i][7] = b0 - b7;
src[i][1] = b2 + b5;
src[i][6] = b2 - b5;
src[i][2] = b4 + b3;
src[i][5] = b4 - b3;
src[i][3] = b6 + b1;
src[i][4] = b6 - b1;
}
for( i = 0; i < 8; i++ )
{
const int a0 = src[0][i] + src[4][i];
const int a2 = src[0][i] - src[4][i];
const int a4 = (src[2][i]>>1) - src[6][i];
const int a6 = (src[6][i]>>1) + src[2][i];
const int b0 = a0 + a6;
const int b2 = a2 + a4;
const int b4 = a2 - a4;
const int b6 = a0 - a6;
const int a1 = -src[3][i] + src[5][i] - src[7][i] - (src[7][i]>>1);
const int a3 = src[1][i] + src[7][i] - src[3][i] - (src[3][i]>>1);
const int a5 = -src[1][i] + src[7][i] + src[5][i] + (src[5][i]>>1);
const int a7 = src[3][i] + src[5][i] + src[1][i] + (src[1][i]>>1);
const int b1 = (a7>>2) + a1;
const int b3 = a3 + (a5>>2);
const int b5 = (a3>>2) - a5;
const int b7 = a7 - (a1>>2);
dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b7) >> 6) ];
dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b2 + b5) >> 6) ];
dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b4 + b3) >> 6) ];
dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b6 + b1) >> 6) ];
dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b6 - b1) >> 6) ];
dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b4 - b3) >> 6) ];
dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b2 - b5) >> 6) ];
dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b7) >> 6) ];
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册