comparison snow.c @ 2161:ec7789e19e43 libavcodec

lossless support
author michael
date Mon, 02 Aug 2004 19:09:28 +0000
parents 11e1425b3a66
children cbac56a6244f
comparison
equal deleted inserted replaced
2160:11e1425b3a66 2161:ec7789e19e43
28 28
29 #define MAX_DECOMPOSITIONS 8 29 #define MAX_DECOMPOSITIONS 8
30 #define MAX_PLANES 4 30 #define MAX_PLANES 4
31 #define DWTELEM int 31 #define DWTELEM int
32 #define QROOT 8 32 #define QROOT 8
33 #define LOSSLESS_QLOG -128
33 34
34 static const int8_t quant3[256]={ 35 static const int8_t quant3[256]={
35 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 36 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
36 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
37 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2244 int x,y, thres1, thres2; 2245 int x,y, thres1, thres2;
2245 START_TIMER 2246 START_TIMER
2246 2247
2247 assert(QROOT==8); 2248 assert(QROOT==8);
2248 2249
2250 if(s->qlog == LOSSLESS_QLOG) return;
2251
2249 bias= bias ? 0 : (3*qmul)>>3; 2252 bias= bias ? 0 : (3*qmul)>>3;
2250 thres1= ((qmul - bias)>>QEXPSHIFT) - 1; 2253 thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
2251 thres2= 2*thres1; 2254 thres2= 2*thres1;
2252 2255
2253 if(!bias){ 2256 if(!bias){
2303 const int qlog= clip(s->qlog + b->qlog, 0, 128); 2306 const int qlog= clip(s->qlog + b->qlog, 0, 128);
2304 const int qmul= qexp[qlog&7]<<(qlog>>3); 2307 const int qmul= qexp[qlog&7]<<(qlog>>3);
2305 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; 2308 const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
2306 int x,y; 2309 int x,y;
2307 2310
2311 if(s->qlog == LOSSLESS_QLOG) return;
2312
2308 assert(QROOT==8); 2313 assert(QROOT==8);
2309 2314
2310 for(y=0; y<h; y++){ 2315 for(y=0; y<h; y++){
2311 for(x=0; x<w; x++){ 2316 for(x=0; x<w; x++){
2312 int i= src[x + y*stride]; 2317 int i= src[x + y*stride];
2671 memset(s->header_state, 0, sizeof(s->header_state)); 2676 memset(s->header_state, 0, sizeof(s->header_state));
2672 2677
2673 s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; 2678 s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
2674 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; 2679 pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE;
2675 2680
2676 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2)); 2681 if(pict->quality){
2677 //<64 >60 2682 s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2));
2678 s->qlog += 61; 2683 //<64 >60
2684 s->qlog += 61;
2685 }else{
2686 s->qlog= LOSSLESS_QLOG;
2687 }
2679 2688
2680 for(i=0; i<s->mb_band.stride * s->mb_band.height; i++){ 2689 for(i=0; i<s->mb_band.stride * s->mb_band.height; i++){
2681 s->mb_band.buf[i]= s->keyframe; 2690 s->mb_band.buf[i]= s->keyframe;
2682 } 2691 }
2683 2692
2875 for(x=0; x<w; x++){ 2884 for(x=0; x<w; x++){
2876 s->spatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<8; 2885 s->spatial_dwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<8;
2877 } 2886 }
2878 } 2887 }
2879 predict_plane(s, s->spatial_dwt_buffer, plane_index, 0); 2888 predict_plane(s, s->spatial_dwt_buffer, plane_index, 0);
2889 if(s->qlog == LOSSLESS_QLOG){
2890 for(y=0; y<h; y++){
2891 for(x=0; x<w; x++){
2892 s->spatial_dwt_buffer[y*w + x]= (s->spatial_dwt_buffer[y*w + x] + 127)>>8;
2893 }
2894 }
2895 }
2896
2880 spatial_dwt(s, s->spatial_dwt_buffer, w, h, w); 2897 spatial_dwt(s, s->spatial_dwt_buffer, w, h, w);
2881 2898
2882 for(level=0; level<s->spatial_decomposition_count; level++){ 2899 for(level=0; level<s->spatial_decomposition_count; level++){
2883 for(orientation=level ? 1 : 0; orientation<4; orientation++){ 2900 for(orientation=level ? 1 : 0; orientation<4; orientation++){
2884 SubBand *b= &p->band[level][orientation]; 2901 SubBand *b= &p->band[level][orientation];
2885 2902
2886 quantize(s, b, b->buf, b->stride, s->qbias); 2903 quantize(s, b, b->buf, b->stride, s->qbias);
2899 SubBand *b= &p->band[level][orientation]; 2916 SubBand *b= &p->band[level][orientation];
2900 2917
2901 dequantize(s, b, b->buf, b->stride); 2918 dequantize(s, b, b->buf, b->stride);
2902 } 2919 }
2903 } 2920 }
2904 2921
2905 spatial_idwt(s, s->spatial_dwt_buffer, w, h, w); 2922 spatial_idwt(s, s->spatial_dwt_buffer, w, h, w);
2923 if(s->qlog == LOSSLESS_QLOG){
2924 for(y=0; y<h; y++){
2925 for(x=0; x<w; x++){
2926 s->spatial_dwt_buffer[y*w + x]<<=8;
2927 }
2928 }
2929 }
2906 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); 2930 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
2907 //FIXME optimize 2931 //FIXME optimize
2908 for(y=0; y<h; y++){ 2932 for(y=0; y<h; y++){
2909 for(x=0; x<w; x++){ 2933 for(x=0; x<w; x++){
2910 int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8; 2934 int v= (s->spatial_dwt_buffer[y*w + x]+128)>>8;
2916 int64_t error= 0; 2940 int64_t error= 0;
2917 2941
2918 if(pict->data[plane_index]) //FIXME gray hack 2942 if(pict->data[plane_index]) //FIXME gray hack
2919 for(y=0; y<h; y++){ 2943 for(y=0; y<h; y++){
2920 for(x=0; x<w; x++){ 2944 for(x=0; x<w; x++){
2921 int d= s->spatial_dwt_buffer[y*w + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]*256; 2945 int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x];
2922 error += d*d; 2946 error += d*d;
2923 } 2947 }
2924 } 2948 }
2925 error= (error + 128*256)>>16;
2926 s->avctx->error[plane_index] += error; 2949 s->avctx->error[plane_index] += error;
2927 s->avctx->error[3] += error; 2950 s->avctx->error[3] += error;
2928 } 2951 }
2929 } 2952 }
2930 2953
3039 dequantize(s, b, b->buf, b->stride); 3062 dequantize(s, b, b->buf, b->stride);
3040 } 3063 }
3041 } 3064 }
3042 3065
3043 spatial_idwt(s, s->spatial_dwt_buffer, w, h, w); 3066 spatial_idwt(s, s->spatial_dwt_buffer, w, h, w);
3067 if(s->qlog == LOSSLESS_QLOG){
3068 for(y=0; y<h; y++){
3069 for(x=0; x<w; x++){
3070 s->spatial_dwt_buffer[y*w + x]<<=8;
3071 }
3072 }
3073 }
3044 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1); 3074 predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
3045 3075
3046 //FIXME optimize 3076 //FIXME optimize
3047 for(y=0; y<h; y++){ 3077 for(y=0; y<h; y++){
3048 for(x=0; x<w; x++){ 3078 for(x=0; x<w; x++){