diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-08-02 17:53:57 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-08-02 17:53:57 +0000 |
commit | 0635cbfc325dc59db5031d47f4f24a6bc66be712 (patch) | |
tree | 8e9a98cd74364c93fac75a016b1ba4b45673104c /libavcodec/snow.c | |
parent | 9b434875f1248119be417b4cf0c0773af4db5942 (diff) | |
download | ffmpeg-0635cbfc325dc59db5031d47f4f24a6bc66be712.tar.gz |
improved magnitude coding, 0.2% lower bitrate (foreman@352x288 qscale 1 and 8)
Originally committed as revision 3372 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/snow.c')
-rw-r--r-- | libavcodec/snow.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/libavcodec/snow.c b/libavcodec/snow.c index b8f37e7cc0..9534f3ef30 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -494,33 +494,35 @@ static inline int get_symbol(CABACContext *c, uint8_t *state, int is_signed){ static inline void put_symbol2(CABACContext *c, uint8_t *state, int v, int log2){ int i; - int e= av_log2(v<<1); + int r= log2>=0 ? 1<<log2 : 1; assert(v>=0); - if(v==0) assert(e==0); - - while(e > log2){ - put_cabac(c, state+log2, 1); - v -= 1<<log2; - assert(v>=0); - e= av_log2(v<<1); + assert(log2>=-4); + + while(v >= r){ + put_cabac(c, state+4+log2, 1); + v -= r; log2++; + if(log2>0) r+=r; } - put_cabac(c, state+log2, 0); + put_cabac(c, state+4+log2, 0); for(i=log2-1; i>=0; i--){ put_cabac(c, state+31-i, (v>>i)&1); } - assert(!((v>>i)&1)); } static inline int get_symbol2(CABACContext *c, uint8_t *state, int log2){ int i; + int r= log2>=0 ? 1<<log2 : 1; int v=0; - while(get_cabac(c, state+log2)){ - v+= 1<<log2; + assert(log2>=-4); + + while(get_cabac(c, state+4+log2)){ + v+= r; log2++; + if(log2>0) r+=r; } for(i=log2-1; i>=0; i--){ @@ -1839,7 +1841,7 @@ static void encode_subband_c0run(SnowContext *s, SubBand *b, DWTELEM *src, DWTEL if(v){ int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); - put_symbol(&s->c, b->state[context + 2], ABS(v)-1, 0); + put_symbol2(&s->c, b->state[context + 2], ABS(v)-1, context-4); put_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]], v<0); } } @@ -2255,7 +2257,7 @@ static inline void decode_subband(SnowContext *s, SubBand *b, DWTELEM *src, DWTE } if(v){ int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); - v= get_symbol(&s->c, b->state[context + 2], 0) + 1; + v= get_symbol2(&s->c, b->state[context + 2], context-4) + 1; if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) v= -v; src[x + y*stride]= v; |