Commit 45ccc61a authored by Michael Niedermayer's avatar Michael Niedermayer

Factorize quantization matrix loading code out.

Originally committed as revision 18723 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent da00b525
...@@ -1470,42 +1470,31 @@ static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) ...@@ -1470,42 +1470,31 @@ static void mpeg_decode_picture_display_extension(Mpeg1Context *s1)
); );
} }
static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra){
int i;
for(i=0; i<64; i++) {
int j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
int v = get_bits(&s->gb, 8);
if(v==0){
av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n");
return -1;
}
matrix0[j] = v;
if(matrix1)
matrix1[j] = v;
}
return 0;
}
static void mpeg_decode_quant_matrix_extension(MpegEncContext *s) static void mpeg_decode_quant_matrix_extension(MpegEncContext *s)
{ {
int i, v, j;
dprintf(s->avctx, "matrix extension\n"); dprintf(s->avctx, "matrix extension\n");
if (get_bits1(&s->gb)) { if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
for(i=0;i<64;i++) { if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
v = get_bits(&s->gb, 8); if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1);
j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0);
s->intra_matrix[j] = v;
s->chroma_intra_matrix[j] = v;
}
}
if (get_bits1(&s->gb)) {
for(i=0;i<64;i++) {
v = get_bits(&s->gb, 8);
j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->inter_matrix[j] = v;
s->chroma_inter_matrix[j] = v;
}
}
if (get_bits1(&s->gb)) {
for(i=0;i<64;i++) {
v = get_bits(&s->gb, 8);
j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->chroma_intra_matrix[j] = v;
}
}
if (get_bits1(&s->gb)) {
for(i=0;i<64;i++) {
v = get_bits(&s->gb, 8);
j= s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->chroma_inter_matrix[j] = v;
}
}
} }
static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1) static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
...@@ -2008,22 +1997,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, ...@@ -2008,22 +1997,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
/* get matrix */ /* get matrix */
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
for(i=0;i<64;i++) { load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1);
v = get_bits(&s->gb, 8);
if(v==0){
av_log(s->avctx, AV_LOG_ERROR, "intra matrix damaged\n");
return -1;
}
j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->intra_matrix[j] = v;
s->chroma_intra_matrix[j] = v;
}
#ifdef DEBUG
dprintf(s->avctx, "intra matrix present\n");
for(i=0;i<64;i++)
dprintf(s->avctx, " %d", s->intra_matrix[s->dsp.idct_permutation[i]]);
dprintf(s->avctx, "\n");
#endif
} else { } else {
for(i=0;i<64;i++) { for(i=0;i<64;i++) {
j = s->dsp.idct_permutation[i]; j = s->dsp.idct_permutation[i];
...@@ -2033,22 +2007,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, ...@@ -2033,22 +2007,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx,
} }
} }
if (get_bits1(&s->gb)) { if (get_bits1(&s->gb)) {
for(i=0;i<64;i++) { load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0);
v = get_bits(&s->gb, 8);
if(v==0){
av_log(s->avctx, AV_LOG_ERROR, "inter matrix damaged\n");
return -1;
}
j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ];
s->inter_matrix[j] = v;
s->chroma_inter_matrix[j] = v;
}
#ifdef DEBUG
dprintf(s->avctx, "non-intra matrix present\n");
for(i=0;i<64;i++)
dprintf(s->avctx, " %d", s->inter_matrix[s->dsp.idct_permutation[i]]);
dprintf(s->avctx, "\n");
#endif
} else { } else {
for(i=0;i<64;i++) { for(i=0;i<64;i++) {
int j= s->dsp.idct_permutation[i]; int j= s->dsp.idct_permutation[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment