diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-07-27 17:38:53 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-07-27 17:38:53 +0000 |
commit | da66b6313e61a861321b7d62a3d12a38877784bb (patch) | |
tree | 1be63e046c0c10b0772cdb5d844c29803b6bfa05 /libavcodec/snow.c | |
parent | a8d73e56e6a0e883d203e044ea1e4b2189ef299f (diff) | |
download | ffmpeg-da66b6313e61a861321b7d62a3d12a38877784bb.tar.gz |
optimize quantizaton (about 3x faster)
further opt is easily possible but could lead to overflows depening upon coefficient range, so this wont be done yet as it would make the code somewhat less flexible
Originally committed as revision 3354 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/snow.c')
-rw-r--r-- | libavcodec/snow.c | 63 |
1 files changed, 35 insertions, 28 deletions
diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 74ed242d26..3150443804 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -1801,29 +1801,33 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b const int h= b->height; const int qlog= clip(s->qlog + b->qlog, 0, 128); const int qmul= qexp[qlog&7]<<(qlog>>3); - int x,y; + int x,y, thres1, thres2; + START_TIMER assert(QROOT==8); bias= bias ? 0 : (3*qmul)>>3; + thres1= ((qmul - bias)>>QEXPSHIFT) - 1; + thres2= 2*thres1; if(!bias){ for(y=0; y<h; y++){ for(x=0; x<w; x++){ - int i= src[x + y*stride]; - //FIXME use threshold - //FIXME optimize - //FIXME bias - if(i>=0){ - i<<= QEXPSHIFT; - i/= qmul; - src[x + y*stride]= i; - }else{ - i= -i; - i<<= QEXPSHIFT; - i/= qmul; - src[x + y*stride]= -i; - } + int i= src[x + y*stride]; + + if((unsigned)(i+thres1) > thres2){ + if(i>=0){ + i<<= QEXPSHIFT; + i/= qmul; //FIXME optimize + src[x + y*stride]= i; + }else{ + i= -i; + i<<= QEXPSHIFT; + i/= qmul; //FIXME optimize + src[x + y*stride]= -i; + } + }else + src[x + y*stride]= 0; } } }else{ @@ -1831,22 +1835,25 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b for(x=0; x<w; x++){ int i= src[x + y*stride]; - //FIXME use threshold - //FIXME optimize - //FIXME bias - if(i>=0){ - i<<= QEXPSHIFT; - i= (i + bias) / qmul; - src[x + y*stride]= i; - }else{ - i= -i; - i<<= QEXPSHIFT; - i= (i + bias) / qmul; - src[x + y*stride]= -i; - } + if((unsigned)(i+thres1) > thres2){ + if(i>=0){ + i<<= QEXPSHIFT; + i= (i + bias) / qmul; //FIXME optimize + src[x + y*stride]= i; + }else{ + i= -i; + i<<= QEXPSHIFT; + i= (i + bias) / qmul; //FIXME optimize + src[x + y*stride]= -i; + } + }else + src[x + y*stride]= 0; } } } + if(level+1 == s->spatial_decomposition_count){ +// STOP_TIMER("quantize") + } } static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ |