Revision 93fbdb5a

View differences:

libavcodec/snow.c
30 30
#define MAX_PLANES 4
31 31
#define DWTELEM int
32 32
#define QROOT 8 
33
#define LOSSLESS_QLOG -128
33 34

  
34 35
static const int8_t quant3[256]={
35 36
 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
......
2246 2247

  
2247 2248
    assert(QROOT==8);
2248 2249

  
2250
    if(s->qlog == LOSSLESS_QLOG) return;
2251
 
2249 2252
    bias= bias ? 0 : (3*qmul)>>3;
2250 2253
    thres1= ((qmul - bias)>>QEXPSHIFT) - 1;
2251 2254
    thres2= 2*thres1;
......
2305 2308
    const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT;
2306 2309
    int x,y;
2307 2310
    
2311
    if(s->qlog == LOSSLESS_QLOG) return;
2312
    
2308 2313
    assert(QROOT==8);
2309 2314

  
2310 2315
    for(y=0; y<h; y++){
......
2673 2678
    s->keyframe=avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0;
2674 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));
2677
    //<64 >60
2678
    s->qlog += 61;
2681
    if(pict->quality){
2682
        s->qlog= rint(QROOT*log(pict->quality / (float)FF_QP2LAMBDA)/log(2));
2683
        //<64 >60
2684
        s->qlog += 61;
2685
    }else{
2686
        s->qlog= LOSSLESS_QLOG;
2687
    }
2679 2688

  
2680 2689
    for(i=0; i<s->mb_band.stride * s->mb_band.height; i++){
2681 2690
        s->mb_band.buf[i]= s->keyframe;
......
2877 2886
            }
2878 2887
        }
2879 2888
        predict_plane(s, s->spatial_dwt_buffer, plane_index, 0);
2880
        spatial_dwt(s, s->spatial_dwt_buffer, w, h, w);
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
        }
2881 2896
 
2897
        spatial_dwt(s, s->spatial_dwt_buffer, w, h, w);
2898

  
2882 2899
        for(level=0; level<s->spatial_decomposition_count; level++){
2883 2900
            for(orientation=level ? 1 : 0; orientation<4; orientation++){
2884 2901
                SubBand *b= &p->band[level][orientation];
......
2901 2918
                dequantize(s, b, b->buf, b->stride);
2902 2919
            }
2903 2920
        }
2904
        
2921

  
2905 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 2930
        predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
2907 2931
        //FIXME optimize
2908 2932
        for(y=0; y<h; y++){
......
2918 2942
    if(pict->data[plane_index]) //FIXME gray hack
2919 2943
            for(y=0; y<h; y++){
2920 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 2946
                    error += d*d;
2923 2947
                }
2924 2948
            }
2925
            error= (error + 128*256)>>16;
2926 2949
            s->avctx->error[plane_index] += error;
2927 2950
            s->avctx->error[3] += error;
2928 2951
        }
......
3041 3064
        }
3042 3065

  
3043 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 3074
        predict_plane(s, s->spatial_dwt_buffer, plane_index, 1);
3045 3075

  
3046 3076
        //FIXME optimize

Also available in: Unified diff