Mercurial > libavcodec.hg
comparison snow.c @ 2600:2bcea6618a87 libavcodec
fix QROOT != 8
author | michael |
---|---|
date | Sat, 09 Apr 2005 19:48:59 +0000 |
parents | 3e90a8cfddc6 |
children | c31a28f27d9a |
comparison
equal
deleted
inserted
replaced
2599:3e36a706f5b7 | 2600:2bcea6618a87 |
---|---|
29 #include <assert.h> | 29 #include <assert.h> |
30 | 30 |
31 #define MAX_DECOMPOSITIONS 8 | 31 #define MAX_DECOMPOSITIONS 8 |
32 #define MAX_PLANES 4 | 32 #define MAX_PLANES 4 |
33 #define DWTELEM int | 33 #define DWTELEM int |
34 #define QROOT 8 | 34 #define QSHIFT 3 |
35 #define QROOT (1<<QSHIFT) | |
35 #define LOSSLESS_QLOG -128 | 36 #define LOSSLESS_QLOG -128 |
36 #define FRAC_BITS 8 | 37 #define FRAC_BITS 8 |
37 | 38 |
38 static const int8_t quant3[256]={ | 39 static const int8_t quant3[256]={ |
39 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, | 40 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
570 #ifdef __sgi | 571 #ifdef __sgi |
571 // Avoid a name clash on SGI IRIX | 572 // Avoid a name clash on SGI IRIX |
572 #undef qexp | 573 #undef qexp |
573 #endif | 574 #endif |
574 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 | 575 #define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 |
575 static const uint8_t qexp[8]={ | 576 static uint8_t qexp[QROOT]; |
576 128, 140, 152, 166, 181, 197, 215, 235 | |
577 // 64, 70, 76, 83, 91, 99, 108, 117 | |
578 // 32, 35, 38, 41, 45, 49, 54, 59 | |
579 // 16, 17, 19, 21, 23, 25, 27, 29 | |
580 // 8, 9, 10, 10, 11, 12, 13, 15 | |
581 }; | |
582 | 577 |
583 static inline int mirror(int v, int m){ | 578 static inline int mirror(int v, int m){ |
584 if (v<0) return -v; | 579 if (v<0) return -v; |
585 else if(v>m) return 2*m-v; | 580 else if(v>m) return 2*m-v; |
586 else return v; | 581 else return v; |
1834 } | 1829 } |
1835 | 1830 |
1836 static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ | 1831 static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ |
1837 const int w= b->width; | 1832 const int w= b->width; |
1838 int x,y; | 1833 int x,y; |
1839 const int qlog= clip(s->qlog + b->qlog, 0, 128); | 1834 const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); |
1840 int qmul= qexp[qlog&7]<<(qlog>>3); | 1835 int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
1841 int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; | 1836 int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
1842 int new_index = 0; | 1837 int new_index = 0; |
1843 | 1838 |
1844 START_TIMER | 1839 START_TIMER |
1845 | 1840 |
2841 | 2836 |
2842 static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){ | 2837 static void quantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride, int bias){ |
2843 const int level= b->level; | 2838 const int level= b->level; |
2844 const int w= b->width; | 2839 const int w= b->width; |
2845 const int h= b->height; | 2840 const int h= b->height; |
2846 const int qlog= clip(s->qlog + b->qlog, 0, 128); | 2841 const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); |
2847 const int qmul= qexp[qlog&7]<<(qlog>>3); | 2842 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
2848 int x,y, thres1, thres2; | 2843 int x,y, thres1, thres2; |
2849 START_TIMER | 2844 START_TIMER |
2850 | |
2851 assert(QROOT==8); | |
2852 | 2845 |
2853 if(s->qlog == LOSSLESS_QLOG) return; | 2846 if(s->qlog == LOSSLESS_QLOG) return; |
2854 | 2847 |
2855 bias= bias ? 0 : (3*qmul)>>3; | 2848 bias= bias ? 0 : (3*qmul)>>3; |
2856 thres1= ((qmul - bias)>>QEXPSHIFT) - 1; | 2849 thres1= ((qmul - bias)>>QEXPSHIFT) - 1; |
2903 } | 2896 } |
2904 | 2897 |
2905 static void dequantize_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride){ | 2898 static void dequantize_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, DWTELEM *src, int stride){ |
2906 const int w= b->width; | 2899 const int w= b->width; |
2907 const int h= b->height; | 2900 const int h= b->height; |
2908 const int qlog= clip(s->qlog + b->qlog, 0, 128); | 2901 const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); |
2909 const int qmul= qexp[qlog&7]<<(qlog>>3); | 2902 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
2910 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; | 2903 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
2911 int x,y; | 2904 int x,y; |
2912 START_TIMER | 2905 START_TIMER |
2913 | 2906 |
2914 if(s->qlog == LOSSLESS_QLOG) return; | 2907 if(s->qlog == LOSSLESS_QLOG) return; |
2915 | |
2916 assert(QROOT==8); | |
2917 | 2908 |
2918 for(y=0; y<h; y++){ | 2909 for(y=0; y<h; y++){ |
2919 // DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride)); | 2910 // DWTELEM * line = slice_buffer_get_line_from_address(sb, src + (y * stride)); |
2920 DWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; | 2911 DWTELEM * line = slice_buffer_get_line(sb, (y * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; |
2921 for(x=0; x<w; x++){ | 2912 for(x=0; x<w; x++){ |
2933 } | 2924 } |
2934 | 2925 |
2935 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ | 2926 static void dequantize(SnowContext *s, SubBand *b, DWTELEM *src, int stride){ |
2936 const int w= b->width; | 2927 const int w= b->width; |
2937 const int h= b->height; | 2928 const int h= b->height; |
2938 const int qlog= clip(s->qlog + b->qlog, 0, 128); | 2929 const int qlog= clip(s->qlog + b->qlog, 0, QROOT*16); |
2939 const int qmul= qexp[qlog&7]<<(qlog>>3); | 2930 const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); |
2940 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; | 2931 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; |
2941 int x,y; | 2932 int x,y; |
2942 START_TIMER | 2933 START_TIMER |
2943 | 2934 |
2944 if(s->qlog == LOSSLESS_QLOG) return; | 2935 if(s->qlog == LOSSLESS_QLOG) return; |
2945 | 2936 |
2946 assert(QROOT==8); | |
2947 | |
2948 for(y=0; y<h; y++){ | 2937 for(y=0; y<h; y++){ |
2949 for(x=0; x<w; x++){ | 2938 for(x=0; x<w; x++){ |
2950 int i= src[x + y*stride]; | 2939 int i= src[x + y*stride]; |
2951 if(i<0){ | 2940 if(i<0){ |
2952 src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias | 2941 src[x + y*stride]= -((-i*qmul + qadd)>>(QEXPSHIFT)); //FIXME try different bias |
3125 s->mv_scale= get_symbol(&s->c, s->header_state, 0); | 3114 s->mv_scale= get_symbol(&s->c, s->header_state, 0); |
3126 s->qbias= get_symbol(&s->c, s->header_state, 1); | 3115 s->qbias= get_symbol(&s->c, s->header_state, 1); |
3127 s->block_max_depth= get_symbol(&s->c, s->header_state, 0); | 3116 s->block_max_depth= get_symbol(&s->c, s->header_state, 0); |
3128 | 3117 |
3129 return 0; | 3118 return 0; |
3119 } | |
3120 | |
3121 static void init_qexp(){ | |
3122 int i; | |
3123 double v=128; | |
3124 | |
3125 for(i=0; i<QROOT; i++){ | |
3126 qexp[i]= lrintf(v); | |
3127 v *= pow(2, 1.0 / QROOT); | |
3128 } | |
3130 } | 3129 } |
3131 | 3130 |
3132 static int common_init(AVCodecContext *avctx){ | 3131 static int common_init(AVCodecContext *avctx){ |
3133 SnowContext *s = avctx->priv_data; | 3132 SnowContext *s = avctx->priv_data; |
3134 int width, height; | 3133 int width, height; |
3173 | 3172 |
3174 mcfh(0, 0) | 3173 mcfh(0, 0) |
3175 mcfh(8, 0) | 3174 mcfh(8, 0) |
3176 mcfh(0, 8) | 3175 mcfh(0, 8) |
3177 mcfh(8, 8) | 3176 mcfh(8, 8) |
3178 | 3177 |
3178 if(!qexp[0]) | |
3179 init_qexp(); | |
3180 | |
3179 dec= s->spatial_decomposition_count= 5; | 3181 dec= s->spatial_decomposition_count= 5; |
3180 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type | 3182 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type |
3181 | 3183 |
3182 s->chroma_h_shift= 1; //FIXME XXX | 3184 s->chroma_h_shift= 1; //FIXME XXX |
3183 s->chroma_v_shift= 1; | 3185 s->chroma_v_shift= 1; |
3365 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; | 3367 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; |
3366 | 3368 |
3367 if(pict->quality){ | 3369 if(pict->quality){ |
3368 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); | 3370 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); |
3369 //<64 >60 | 3371 //<64 >60 |
3370 s->qlog += 61; | 3372 s->qlog += 61*QROOT/8; |
3371 }else{ | 3373 }else{ |
3372 s->qlog= LOSSLESS_QLOG; | 3374 s->qlog= LOSSLESS_QLOG; |
3373 } | 3375 } |
3374 | 3376 |
3375 frame_start(s); | 3377 frame_start(s); |