# HG changeset patch # User michael # Date 1090949933 0 # Node ID 8aff375a986b0a0fc9138141bc91cb2b8b364b77 # Parent 48dc4ec06e88954b818d969003db9fdfee5515ef 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 diff -r 48dc4ec06e88 -r 8aff375a986b snow.c --- a/snow.c Tue Jul 27 17:02:31 2004 +0000 +++ b/snow.c Tue Jul 27 17:38:53 2004 +0000 @@ -1801,29 +1801,33 @@ 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=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 @@ for(x=0; x=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){