diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2010-10-10 21:04:34 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2010-10-10 21:04:34 +0000 |
commit | 4f22b3bbbf886ab504a217ac470d543f710e89b7 (patch) | |
tree | ef91ce3671e270e1048fa4eca853556ac256b53f /libavcodec/ffv1.c | |
parent | 54ce8a4c8b3fa80f86e9c212cd3aa2654808e930 (diff) | |
download | ffmpeg-4f22b3bbbf886ab504a217ac470d543f710e89b7.tar.gz |
Factorize quant table read and write code in ffv1.c
Originally committed as revision 25436 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/ffv1.c')
-rw-r--r-- | libavcodec/ffv1.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index 0e3007fa81..b3f4ebcd19 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -591,6 +591,12 @@ static void write_quant_table(RangeCoder *c, int16_t *quant_table){ put_symbol(c, state, i-last-1, 0); } +static void write_quant_tables(RangeCoder *c, int16_t quant_table[5][256]){ + int i; + for(i=0; i<5; i++) + write_quant_table(c, quant_table[i]); +} + static void write_header(FFV1Context *f){ uint8_t state[CONTEXT_SIZE]; int i; @@ -614,8 +620,7 @@ static void write_header(FFV1Context *f){ put_symbol(c, state, f->chroma_v_shift, 0); put_rac(c, state, 0); //no transparency plane - for(i=0; i<5; i++) - write_quant_table(c, f->quant_table[i]); + write_quant_tables(c, f->quant_table); } #endif /* CONFIG_FFV1_ENCODER */ @@ -995,6 +1000,19 @@ static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){ return 2*v - 1; } +static int read_quant_tables(RangeCoder *c, int16_t quant_table[5][256]){ + int i; + int context_count=1; + + for(i=0; i<5; i++){ + context_count*= read_quant_table(c, quant_table[i], context_count); + if(context_count > 32768U){ + return -1; + } + } + return (context_count+1)/2; +} + static int read_header(FFV1Context *f){ uint8_t state[CONTEXT_SIZE]; int i, context_count; @@ -1052,16 +1070,11 @@ static int read_header(FFV1Context *f){ } //printf("%d %d %d\n", f->chroma_h_shift, f->chroma_v_shift,f->avctx->pix_fmt); - - context_count=1; - for(i=0; i<5; i++){ - context_count*= read_quant_table(c, f->quant_table[i], context_count); - if(context_count < 0 || context_count > 32768){ + context_count= read_quant_tables(c, f->quant_table); + if(context_count < 0){ av_log(f->avctx, AV_LOG_ERROR, "read_quant_table error\n"); return -1; } - } - context_count= (context_count+1)/2; for(i=0; i<f->plane_count; i++){ PlaneContext * const p= &f->plane[i]; |