comparison snow.c @ 2150:8aff375a986b libavcodec

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
author michael
date Tue, 27 Jul 2004 17:38:53 +0000
parents 48dc4ec06e88
children 44c973bfec0f
comparison
equal deleted inserted replaced
2149:48dc4ec06e88 2150:8aff375a986b
1799 const int level= b->level; 1799 const int level= b->level;
1800 const int w= b->width; 1800 const int w= b->width;
1801 const int h= b->height; 1801 const int h= b->height;
1802 const int qlog= clip(s->qlog + b->qlog, 0, 128); 1802 const int qlog= clip(s->qlog + b->qlog, 0, 128);
1803 const int qmul= qexp[qlog&7]<<(qlog>>3); 1803 const int qmul= qexp[qlog&7]<<(qlog>>3);
1804 int x,y; 1804 int x,y, thres1, thres2;
1805 START_TIMER
1805 1806
1806 assert(QROOT==8); 1807 assert(QROOT==8);
1807 1808
1808 bias= bias ? 0 : (3*qmul)>>3; 1809 bias= bias ? 0 : (3*qmul)>>3;
1810 thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
1811 thres2= 2*thres1;
1809 1812
1810 if(!bias){ 1813 if(!bias){
1811 for(y=0; y<h; y++){ 1814 for(y=0; y<h; y++){
1812 for(x=0; x<w; x++){ 1815 for(x=0; x<w; x++){
1813 int i= src[x + y*stride]; 1816 int i= src[x + y*stride];
1814 //FIXME use threshold 1817
1815 //FIXME optimize 1818 if((unsigned)(i+thres1) > thres2){
1816 //FIXME bias 1819 if(i>=0){
1817 if(i>=0){ 1820 i<<= QEXPSHIFT;
1818 i<<= QEXPSHIFT; 1821 i/= qmul; //FIXME optimize
1819 i/= qmul; 1822 src[x + y*stride]= i;
1820 src[x + y*stride]= i; 1823 }else{
1821 }else{ 1824 i= -i;
1822 i= -i; 1825 i<<= QEXPSHIFT;
1823 i<<= QEXPSHIFT; 1826 i/= qmul; //FIXME optimize
1824 i/= qmul; 1827 src[x + y*stride]= -i;
1825 src[x + y*stride]= -i; 1828 }
1826 } 1829 }else
1830 src[x + y*stride]= 0;
1827 } 1831 }
1828 } 1832 }
1829 }else{ 1833 }else{
1830 for(y=0; y<h; y++){ 1834 for(y=0; y<h; y++){
1831 for(x=0; x<w; x++){ 1835 for(x=0; x<w; x++){
1832 int i= src[x + y*stride]; 1836 int i= src[x + y*stride];
1833 1837
1834 //FIXME use threshold 1838 if((unsigned)(i+thres1) > thres2){
1835 //FIXME optimize 1839 if(i>=0){
1836 //FIXME bias 1840 i<<= QEXPSHIFT;
1837 if(i>=0){ 1841 i= (i + bias) / qmul; //FIXME optimize
1838 i<<= QEXPSHIFT; 1842 src[x + y*stride]= i;
1839 i= (i + bias) / qmul; 1843 }else{
1840 src[x + y*stride]= i; 1844 i= -i;
1841 }else{ 1845 i<<= QEXPSHIFT;
1842 i= -i; 1846 i= (i + bias) / qmul; //FIXME optimize
1843 i<<= QEXPSHIFT; 1847 src[x + y*stride]= -i;
1844 i= (i + bias) / qmul; 1848 }
1845 src[x + y*stride]= -i; 1849 }else
1846 } 1850 src[x + y*stride]= 0;
1847 } 1851 }
1848 } 1852 }
1853 }
1854 if(level+1 == s->spatial_decomposition_count){
1855 // STOP_TIMER("quantize")
1849 } 1856 }
1850 } 1857 }
1851 1858
1852 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ 1859 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){
1853 const int level= b->level; 1860 const int level= b->level;