comparison snow.c @ 2193:ea7715935e55 libavcodec

5% faster decode_subband() a little cleanup
author michael
date Fri, 27 Aug 2004 20:15:32 +0000
parents 77167ed8453f
children d29037435955
comparison
equal deleted inserted replaced
2192:77167ed8453f 2193:ea7715935e55
373 int width; 373 int width;
374 int height; 374 int height;
375 int qlog; ///< log(qscale)/log[2^(1/6)] 375 int qlog; ///< log(qscale)/log[2^(1/6)]
376 DWTELEM *buf; 376 DWTELEM *buf;
377 int16_t *x; 377 int16_t *x;
378 DWTELEM *coeff;
378 struct SubBand *parent; 379 struct SubBand *parent;
379 uint8_t state[/*7*2*/ 7 + 512][32]; 380 uint8_t state[/*7*2*/ 7 + 512][32];
380 }SubBand; 381 }SubBand;
381 382
382 typedef struct Plane{ 383 typedef struct Plane{
1901 const int w= b->width; 1902 const int w= b->width;
1902 const int h= b->height; 1903 const int h= b->height;
1903 int x,y; 1904 int x,y;
1904 1905
1905 START_TIMER 1906 START_TIMER
1906 #if 0 1907
1907 for(y=0; y<b->height; y++)
1908 memset(&src[y*stride], 0, b->width*sizeof(DWTELEM));
1909
1910 int plane;
1911 for(plane=24; plane>=0; plane--){
1912 int run;
1913
1914 run= get_symbol(&s->c, b->state[1], 0);
1915
1916 #define HIDE(c, plane) c= c>=0 ? c&((-1)<<(plane)) : -((-c)&((-1)<<(plane)));
1917
1918 for(y=0; y<h; y++){
1919 for(x=0; x<w; x++){
1920 int v, p=0, lv;
1921 int /*ll=0, */l=0, lt=0, t=0, rt=0;
1922 int d=0, r=0, rd=0, ld=0;
1923 lv= src[x + y*stride];
1924
1925 if(y){
1926 t= src[x + (y-1)*stride];
1927 if(x){
1928 lt= src[x - 1 + (y-1)*stride];
1929 }
1930 if(x + 1 < w){
1931 rt= src[x + 1 + (y-1)*stride];
1932 }
1933 }
1934 if(x){
1935 l= src[x - 1 + y*stride];
1936 /*if(x > 1){
1937 if(orientation==1) ll= src[y + (x-2)*stride];
1938 else ll= src[x - 2 + y*stride];
1939 }*/
1940 }
1941 if(y+1<h){
1942 d= src[x + (y+1)*stride];
1943 if(x) ld= src[x - 1 + (y+1)*stride];
1944 if(x + 1 < w) rd= src[x + 1 + (y+1)*stride];
1945 }
1946 if(x + 1 < w)
1947 r= src[x + 1 + y*stride];
1948
1949 if(parent){
1950 int px= x>>1;
1951 int py= y>>1;
1952 if(px<b->parent->width && py<b->parent->height)
1953 p= parent[px + py*2*stride];
1954 }
1955 HIDE( p, plane)
1956 if(/*ll|*/l|lt|t|rt|r|rd|ld|d|p|lv){
1957 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)
1958 +3*ABS(r) + ABS(rd) + 2*ABS(d) + ABS(ld));
1959
1960 if(lv){
1961 assert(context + 8*av_log2(ABS(lv)) < 512 - 100);
1962 if(get_cabac(&s->c, &b->state[99][context + 8*(av_log2(ABS(lv))-plane)])){
1963 if(lv<0) v= lv - (1<<plane);
1964 else v= lv + (1<<plane);
1965 }else
1966 v=lv;
1967 }else{
1968 v= get_cabac(&s->c, &b->state[ 0][context]) << plane;
1969 }
1970 }else{
1971 assert(!lv);
1972 if(!run){
1973 run= get_symbol(&s->c, b->state[1], 0);
1974 v= 1<<plane;
1975 }else{
1976 run--;
1977 v=0;
1978 }
1979 }
1980 if(v && !lv){
1981 int context= clip(quant3b[l&0xFF] + quant3b[r&0xFF], -1,1)
1982 + 3*clip(quant3b[t&0xFF] + quant3b[d&0xFF], -1,1);
1983 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + context]))
1984 v= -v;
1985 }
1986 src[x + y*stride]= v;
1987 }
1988 }
1989 }
1990 return;
1991 #endif
1992 if(1){ 1908 if(1){
1993 int run; 1909 int run;
1994 int index=0; 1910 int index=0;
1995 int prev_index=-1; 1911 int prev_index=-1;
1996 int prev2_index=0; 1912 int prev2_index=0;
2000 for(y=0; y<b->height; y++) 1916 for(y=0; y<b->height; y++)
2001 memset(&src[y*stride], 0, b->width*sizeof(DWTELEM)); 1917 memset(&src[y*stride], 0, b->width*sizeof(DWTELEM));
2002 1918
2003 run= get_symbol2(&s->c, b->state[1], 3); 1919 run= get_symbol2(&s->c, b->state[1], 3);
2004 for(y=0; y<h; y++){ 1920 for(y=0; y<h; y++){
1921 int v=0;
1922 int lt=0, t=0, rt=0;
1923
1924 if(y){
1925 rt= src[(y-1)*stride];
1926 }
2005 for(x=0; x<w; x++){ 1927 for(x=0; x<w; x++){
2006 int v, p=0; 1928 int p=0;
2007 int /*ll=0, */l=0, lt=0, t=0, rt=0; 1929 const int l= v;
2008 1930
2009 if(y){ 1931 lt= t; t= rt;
2010 t= src[x + (y-1)*stride]; 1932
2011 if(x){ 1933 if(y && x + 1 < w){
2012 lt= src[x - 1 + (y-1)*stride]; 1934 rt= src[x + 1 + (y-1)*stride];
2013 } 1935 }else
2014 if(x + 1 < w){ 1936 rt= 0;
2015 rt= src[x + 1 + (y-1)*stride];
2016 }
2017 }
2018 if(x){
2019 l= src[x - 1 + y*stride];
2020 /*if(x > 1){
2021 if(orientation==1) ll= src[y + (x-2)*stride];
2022 else ll= src[x - 2 + y*stride];
2023 }*/
2024 }
2025 if(parent){ 1937 if(parent){
2026 int px= x>>1; 1938 int px= x>>1;
2027 int py= y>>1; 1939 int py= y>>1;
2028 if(px<b->parent->width && py<b->parent->height) 1940 if(px<b->parent->width && py<b->parent->height)
2029 p= parent[px + py*2*stride]; 1941 p= parent[px + py*2*stride];
2060 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p)); 1972 int context= av_log2(/*ABS(ll) + */3*ABS(l) + ABS(lt) + 2*ABS(t) + ABS(rt) + ABS(p));
2061 v= get_symbol2(&s->c, b->state[context + 2], context-4) + 1; 1973 v= get_symbol2(&s->c, b->state[context + 2], context-4) + 1;
2062 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]])) 1974 if(get_cabac(&s->c, &b->state[0][16 + 1 + 3 + quant3b[l&0xFF] + 3*quant3b[t&0xFF]]))
2063 v= -v; 1975 v= -v;
2064 src[x + y*stride]= v; 1976 src[x + y*stride]= v;
2065 b->x[index++]=x; 1977 b->x[index++]=x; //FIXME interleave x/coeff
1978 // b->coeff[index++]= v;
2066 } 1979 }
2067 } 1980 }
2068 b->x[index++]= w+1; //end marker 1981 b->x[index++]= w+1; //end marker
2069 prev_index= prev2_index; 1982 prev_index= prev2_index;
2070 prev2_index= index; 1983 prev2_index= index;
2894 s->block_max_depth= get_symbol(&s->c, s->header_state, 0); 2807 s->block_max_depth= get_symbol(&s->c, s->header_state, 0);
2895 2808
2896 return 0; 2809 return 0;
2897 } 2810 }
2898 2811
2899 static int init_subband(SubBand *b, int w, int h, int stride){
2900 b->width= w;
2901 b->height= h;
2902 b->stride= stride;
2903 b->buf= av_mallocz(b->stride * b->height*sizeof(DWTELEM));
2904 b->x= av_mallocz(((b->width+1) * b->height+1)*sizeof(int16_t));
2905 return 0;
2906 }
2907
2908 static int common_init(AVCodecContext *avctx){ 2812 static int common_init(AVCodecContext *avctx){
2909 SnowContext *s = avctx->priv_data; 2813 SnowContext *s = avctx->priv_data;
2910 int width, height; 2814 int width, height;
2911 int level, orientation, plane_index, dec; 2815 int level, orientation, plane_index, dec;
2912 2816
2987 if(orientation&1) b->buf += (w+1)>>1; 2891 if(orientation&1) b->buf += (w+1)>>1;
2988 if(orientation>1) b->buf += b->stride>>1; 2892 if(orientation>1) b->buf += b->stride>>1;
2989 2893
2990 if(level) 2894 if(level)
2991 b->parent= &s->plane[plane_index].band[level-1][orientation]; 2895 b->parent= &s->plane[plane_index].band[level-1][orientation];
2992 b->x= av_mallocz(((b->width+1) * b->height+1)*sizeof(int16_t)); 2896 b->x = av_mallocz(((b->width+1) * b->height+1)*sizeof(int16_t));
2897 b->coeff= av_mallocz(((b->width+1) * b->height+1)*sizeof(DWTELEM));
2993 } 2898 }
2994 w= (w+1)>>1; 2899 w= (w+1)>>1;
2995 h= (h+1)>>1; 2900 h= (h+1)>>1;
2996 } 2901 }
2997 } 2902 }
3309 for(level=s->spatial_decomposition_count-1; level>=0; level--){ 3214 for(level=s->spatial_decomposition_count-1; level>=0; level--){
3310 for(orientation=level ? 1 : 0; orientation<4; orientation++){ 3215 for(orientation=level ? 1 : 0; orientation<4; orientation++){
3311 SubBand *b= &s->plane[plane_index].band[level][orientation]; 3216 SubBand *b= &s->plane[plane_index].band[level][orientation];
3312 3217
3313 av_freep(&b->x); 3218 av_freep(&b->x);
3219 av_freep(&b->coeff);
3314 } 3220 }
3315 } 3221 }
3316 } 3222 }
3317 } 3223 }
3318 3224