Commit cf4e8380 authored by michael's avatar michael

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


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@3354 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent fc594447
...@@ -1801,29 +1801,33 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b ...@@ -1801,29 +1801,33 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b
const int h= b->height; const int h= b->height;
const int qlog= clip(s->qlog + b->qlog, 0, 128); const int qlog= clip(s->qlog + b->qlog, 0, 128);
const int qmul= qexp[qlog&7]<<(qlog>>3); const int qmul= qexp[qlog&7]<<(qlog>>3);
int x,y; int x,y, thres1, thres2;
START_TIMER
assert(QROOT==8); assert(QROOT==8);
bias= bias ? 0 : (3*qmul)>>3; bias= bias ? 0 : (3*qmul)>>3;
thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
thres2= 2*thres1;
if(!bias){ if(!bias){
for(y=0; y<h; y++){ for(y=0; y<h; y++){
for(x=0; x<w; x++){ for(x=0; x<w; x++){
int i= src[x + y*stride]; int i= src[x + y*stride];
//FIXME use threshold
//FIXME optimize if((unsigned)(i+thres1) > thres2){
//FIXME bias if(i>=0){
if(i>=0){ i<<= QEXPSHIFT;
i<<= QEXPSHIFT; i/= qmul; //FIXME optimize
i/= qmul; src[x + y*stride]= i;
src[x + y*stride]= i; }else{
}else{ i= -i;
i= -i; i<<= QEXPSHIFT;
i<<= QEXPSHIFT; i/= qmul; //FIXME optimize
i/= qmul; src[x + y*stride]= -i;
src[x + y*stride]= -i; }
} }else
src[x + y*stride]= 0;
} }
} }
}else{ }else{
...@@ -1831,22 +1835,25 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b ...@@ -1831,22 +1835,25 @@ static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int b
for(x=0; x<w; x++){ for(x=0; x<w; x++){
int i= src[x + y*stride]; int i= src[x + y*stride];
//FIXME use threshold if((unsigned)(i+thres1) > thres2){
//FIXME optimize if(i>=0){
//FIXME bias i<<= QEXPSHIFT;
if(i>=0){ i= (i + bias) / qmul; //FIXME optimize
i<<= QEXPSHIFT; src[x + y*stride]= i;
i= (i + bias) / qmul; }else{
src[x + y*stride]= i; i= -i;
}else{ i<<= QEXPSHIFT;
i= -i; i= (i + bias) / qmul; //FIXME optimize
i<<= QEXPSHIFT; src[x + y*stride]= -i;
i= (i + bias) / qmul; }
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){ static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment