diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-10-31 12:22:00 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-10-31 12:22:00 +0000 |
commit | d34a07466fdbaeb5e5775d312ab9c75bdf0ae550 (patch) | |
tree | 264aee6a0c7b12161eaac6da0abff41837916be7 | |
parent | 880eae9c50385aeaceda5728a16d8213560b2103 (diff) | |
download | ffmpeg-d34a07466fdbaeb5e5775d312ab9c75bdf0ae550.tar.gz |
switch ffv1 to the put/get_symbol() from snow
Originally committed as revision 3659 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/ffv1.c | 90 | ||||
-rw-r--r-- | tests/ffmpeg.regression.ref | 2 | ||||
-rw-r--r-- | tests/rotozoom.regression.ref | 2 |
3 files changed, 44 insertions, 50 deletions
diff --git a/libavcodec/ffv1.c b/libavcodec/ffv1.c index c7eb2281fa..991a8b3c05 100644 --- a/libavcodec/ffv1.c +++ b/libavcodec/ffv1.c @@ -218,57 +218,52 @@ static inline int get_context(FFV1Context *f, int_fast16_t *src, int_fast16_t *l return f->quant_table[0][(L-LT) & 0xFF] + f->quant_table[1][(LT-T) & 0xFF] + f->quant_table[2][(T-RT) & 0xFF]; } -/** - * put - */ -static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed, int max_exp){ +static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ int i; if(v){ const int a= ABS(v); const int e= av_log2(a); - put_rac(c, state+0, 0); + assert(e<=9); + for(i=0; i<e; i++){ - put_rac(c, state+1+i, 1); //1..8 + put_rac(c, state+1+i, 1); //1..10 } + put_rac(c, state+1+i, 0); - if(e<max_exp){ - put_rac(c, state+1+i, 0); //1..8 - - for(i=e-1; i>=0; i--){ - put_rac(c, state+16+e+i, (a>>i)&1); //17..29 - } - if(is_signed) - put_rac(c, state+9 + e, v < 0); //9..16 + for(i=e-1; i>=0; i--){ + put_rac(c, state+22+i, (a>>i)&1); //22..31 } + + if(is_signed) + put_rac(c, state+11 + e, v < 0); //11..21 }else{ put_rac(c, state+0, 1); } } -static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed, int max_exp){ +static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){ if(get_rac(c, state+0)) return 0; else{ - int i, e; - - for(e=0; e<max_exp; e++){ - int a= 1<<e; - - if(get_rac(c, state + 1 + e)==0){ // 1..8 - for(i=e-1; i>=0; i--){ - a += get_rac(c, state+16+e+i)<<i; //17..29 - } + int i, e, a; + e= 0; + while(get_rac(c, state+1 + e)){ //1..10 + e++; + } + assert(e<=9); - if(is_signed && get_rac(c, state+9 + e)) //9..16 - return -a; - else - return a; - } + a= 1; + for(i=e-1; i>=0; i--){ + a += a + get_rac(c, state+22 + i); //22..31 } - return -(1<<e); + + if(is_signed && get_rac(c, state+11 + e)) //11..21 + return -a; + else + return a; } } @@ -380,7 +375,7 @@ static inline void encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], i diff= fold(diff, bits); if(s->ac){ - put_symbol(c, p->state[context], diff, 1, bits-1); + put_symbol(c, p->state[context], diff, 1); }else{ if(context == 0) run_mode=1; @@ -492,11 +487,11 @@ static void write_quant_table(RangeCoder *c, int16_t *quant_table){ for(i=1; i<128 ; i++){ if(quant_table[i] != quant_table[i-1]){ - put_symbol(c, state, i-last-1, 0, 7); + put_symbol(c, state, i-last-1, 0); last= i; } } - put_symbol(c, state, i-last-1, 0, 7); + put_symbol(c, state, i-last-1, 0); } static void write_header(FFV1Context *f){ @@ -506,12 +501,12 @@ static void write_header(FFV1Context *f){ memset(state, 128, sizeof(state)); - put_symbol(c, state, f->version, 0, 7); - put_symbol(c, state, f->avctx->coder_type, 0, 7); - put_symbol(c, state, f->colorspace, 0, 7); //YUV cs type + put_symbol(c, state, f->version, 0); + put_symbol(c, state, f->avctx->coder_type, 0); + put_symbol(c, state, f->colorspace, 0); //YUV cs type put_rac(c, state, 1); //chroma planes - put_symbol(c, state, f->chroma_h_shift, 0, 7); - put_symbol(c, state, f->chroma_v_shift, 0, 7); + put_symbol(c, state, f->chroma_h_shift, 0); + put_symbol(c, state, f->chroma_v_shift, 0); put_rac(c, state, 0); //no transparency plane for(i=0; i<5; i++) @@ -618,7 +613,6 @@ static void clear_state(FFV1Context *f){ for(j=0; j<p->context_count; j++){ if(f->ac){ memset(p->state[j], 128, sizeof(uint8_t)*CONTEXT_SIZE); - p->state[j][7] = 256-8; }else{ p->vlc_state[j].drift= 0; p->vlc_state[j].error_sum= 4; //FFMAX((RANGE + 32)/64, 2); @@ -723,9 +717,9 @@ static inline void decode_line(FFV1Context *s, int w, int_fast16_t *sample[2], i sign=0; - if(s->ac) - diff= get_symbol(c, p->state[context], 1, bits-1); - else{ + if(s->ac){ + diff= get_symbol(c, p->state[context], 1); + }else{ if(context == 0 && run_mode==0) run_mode=1; if(run_mode){ @@ -838,7 +832,7 @@ static int read_quant_table(RangeCoder *c, int16_t *quant_table, int scale){ memset(state, 128, sizeof(state)); for(v=0; i<128 ; v++){ - int len= get_symbol(c, state, 0, 7) + 1; + int len= get_symbol(c, state, 0) + 1; if(len + i > 128) return -1; @@ -865,12 +859,12 @@ static int read_header(FFV1Context *f){ memset(state, 128, sizeof(state)); - f->version= get_symbol(c, state, 0, 7); - f->ac= f->avctx->coder_type= get_symbol(c, state, 0, 7); - f->colorspace= get_symbol(c, state, 0, 7); //YUV cs type + f->version= get_symbol(c, state, 0); + f->ac= f->avctx->coder_type= get_symbol(c, state, 0); + f->colorspace= get_symbol(c, state, 0); //YUV cs type get_rac(c, state); //no chroma = false - f->chroma_h_shift= get_symbol(c, state, 0, 7); - f->chroma_v_shift= get_symbol(c, state, 0, 7); + f->chroma_h_shift= get_symbol(c, state, 0); + f->chroma_v_shift= get_symbol(c, state, 0); get_rac(c, state); //transparency plane f->plane_count= 2; diff --git a/tests/ffmpeg.regression.ref b/tests/ffmpeg.regression.ref index 0ec4070405..472e49c1be 100644 --- a/tests/ffmpeg.regression.ref +++ b/tests/ffmpeg.regression.ref @@ -107,7 +107,7 @@ de42cb5a15bfa8e70cf60edda0b32355 *./data/a-flv.flv 657991 ./data/a-flv.flv 4d9c04e7017dc68da7891048c46c1c37 *./data/out.yuv stddev: 8.08 PSNR:29.97 bytes:7602176 -07cdb322dcf12b107e62a4140afd83ee *./data/a-ffv1.avi +255e21b18af133a5196551aac321b5eb *./data/a-ffv1.avi 2653642 ./data/a-ffv1.avi 799d3db687f6cdd7a837ec156efc171f *./data/out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 diff --git a/tests/rotozoom.regression.ref b/tests/rotozoom.regression.ref index 7ba54f953f..660af7181f 100644 --- a/tests/rotozoom.regression.ref +++ b/tests/rotozoom.regression.ref @@ -107,7 +107,7 @@ d847c144e7b72027531047ea4c441cbf *./data/a-flv.flv 131771 ./data/a-flv.flv e61cd1e7c5a292d396ae90f4d2fb3db7 *./data/out.yuv stddev: 5.33 PSNR:33.57 bytes:7602176 -9de6fde85d9ec1d533b0bdd07703067c *./data/a-ffv1.avi +35600c92a9e2067ee452816b863a5012 *./data/a-ffv1.avi 3524768 ./data/a-ffv1.avi dde5895817ad9d219f79a52d0bdfb001 *./data/out.yuv stddev: 0.00 PSNR:99.99 bytes:7602176 |