From c97de57c39418cb2186e37826576d0d29b2d01f2 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 9 Apr 2005 19:48:59 +0000 Subject: [PATCH] fix QROOT != 8 Originally committed as revision 4114 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/snow.c | 50 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/libavcodec/snow.c b/libavcodec/snow.c index faed630ad4..b355920553 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -31,7 +31,8 @@ #define MAX_DECOMPOSITIONS 8 #define MAX_PLANES 4 #define DWTELEM int -#define QROOT 8 +#define QSHIFT 3 +#define QROOT (1<width; int x,y; - const int qlog= clip(s->qlog + b->qlog, 0, 128); - int qmul= qexp[qlog&7]<<(qlog>>3); + const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); + int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int new_index = 0; @@ -2843,13 +2838,11 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b const int level= b->level; const int w= b->width; const int h= b->height; - const int qlog= clip(s->qlog + b->qlog, 0, 128); - const int qmul= qexp[qlog&7]<<(qlog>>3); + const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); + const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); int x,y, thres1, thres2; START_TIMER - assert(QROOT==8); - if(s->qlog == LOSSLESS_QLOG) return; bias= bias ? 0 : (3*qmul)>>3; @@ -2905,16 +2898,14 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b static void dequantize_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride){ const int w= b->width; const int h= b->height; - const int qlog= clip(s->qlog + b->qlog, 0, 128); - const int qmul= qexp[qlog&7]<<(qlog>>3); + const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); + const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int x,y; START_TIMER if(s->qlog == LOSSLESS_QLOG) return; - assert(QROOT==8); - for(y=0; ystride_line) + b->buf_y_offset) + b->buf_x_offset; @@ -2935,16 +2926,14 @@ static void dequantize_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, D static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ const int w= b->width; const int h= b->height; - const int qlog= clip(s->qlog + b->qlog, 0, 128); - const int qmul= qexp[qlog&7]<<(qlog>>3); + const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); + const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; int x,y; START_TIMER if(s->qlog == LOSSLESS_QLOG) return; - assert(QROOT==8); - for(y=0; ypriv_data; int width, height; @@ -3175,7 +3174,10 @@ static int common_init(AVCodecContext *avctx){ mcfh(8, 0) mcfh(0, 8) mcfh(8, 8) - + + if(!qexp[0]) + init_qexp(); + dec= s->spatial_decomposition_count= 5; s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type @@ -3367,7 +3369,7 @@ static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, if(pict->quality){ s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); //<64 >60 - s->qlog += 61; + s->qlog += 61*QROOT/8; }else{ s->qlog= LOSSLESS_QLOG; }