⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snow.c

📁 ffmpeg源码分析
💻 C
📖 第 1 页 / 共 5 页
字号:
        r += r>>4;        r += r>>8;        dst[i*dst_step] = LIFT(src[i*src_step], ((r+add)>>shift), inverse);    }    if(mirror_right){        int r= 3*2*ref[w*ref_step];        r += r>>4;        r += r>>8;        dst[w*dst_step] = LIFT(src[w*src_step], ((r+add)>>shift), inverse);    }}#endif#ifndef liftSstatic always_inline void liftS(DWTELEM *dst, DWTELEM *src, DWTELEM *ref, int dst_step, int src_step, int ref_step, int width, int mul, int add, int shift, int highpass, int inverse){    const int mirror_left= !highpass;    const int mirror_right= (width&1) ^ highpass;    const int w= (width>>1) - 1 + (highpass & width);    int i;    assert(shift == 4);#define LIFTS(src, ref, inv) ((inv) ? (src) - (((ref) - 4*(src))>>shift): (16*4*(src) + 4*(ref) + 8 + (5<<27))/(5*16) - (1<<23))    if(mirror_left){        dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse);        dst += dst_step;        src += src_step;    }    for(i=0; i<w; i++){        dst[i*dst_step] = LIFTS(src[i*src_step], mul*(ref[i*ref_step] + ref[(i+1)*ref_step])+add, inverse);    }    if(mirror_right){        dst[w*dst_step] = LIFTS(src[w*src_step], mul*2*ref[w*ref_step]+add, inverse);    }}#endifstatic void inplace_lift(DWTELEM *dst, int width, int *coeffs, int n, int shift, int start, int inverse){    int x, i;    for(x=start; x<width; x+=2){        int64_t sum=0;        for(i=0; i<n; i++){            int x2= x + 2*i - n + 1;            if     (x2<     0) x2= -x2;            else if(x2>=width) x2= 2*width-x2-2;            sum += coeffs[i]*(int64_t)dst[x2];        }        if(inverse) dst[x] -= (sum + (1<<shift)/2)>>shift;        else        dst[x] += (sum + (1<<shift)/2)>>shift;    }}static void inplace_liftV(DWTELEM *dst, int width, int height, int stride, int *coeffs, int n, int shift, int start, int inverse){    int x, y, i;    for(y=start; y<height; y+=2){        for(x=0; x<width; x++){            int64_t sum=0;            for(i=0; i<n; i++){                int y2= y + 2*i - n + 1;                if     (y2<      0) y2= -y2;                else if(y2>=height) y2= 2*height-y2-2;                sum += coeffs[i]*(int64_t)dst[x + y2*stride];            }            if(inverse) dst[x + y*stride] -= (sum + (1<<shift)/2)>>shift;            else        dst[x + y*stride] += (sum + (1<<shift)/2)>>shift;        }    }}#define SCALEX 1#define LX0 0#define LX1 1#if 0 // more accurate 9/7#define N1 2#define SHIFT1 14#define COEFFS1 (int[]){-25987,-25987}#define N2 2#define SHIFT2 19#define COEFFS2 (int[]){-27777,-27777}#define N3 2#define SHIFT3 15#define COEFFS3 (int[]){28931,28931}#define N4 2#define SHIFT4 15#define COEFFS4 (int[]){14533,14533}#elif 1 // 13/7 CRF#define N1 4#define SHIFT1 4#define COEFFS1 (int[]){1,-9,-9,1}#define N2 4#define SHIFT2 4#define COEFFS2 (int[]){-1,5,5,-1}#define N3 0#define SHIFT3 1#define COEFFS3 NULL#define N4 0#define SHIFT4 1#define COEFFS4 NULL#elif 1 // 3/5#define LX0 1#define LX1 0#define SCALEX 0.5#define N1 2#define SHIFT1 1#define COEFFS1 (int[]){1,1}#define N2 2#define SHIFT2 2#define COEFFS2 (int[]){-1,-1}#define N3 0#define SHIFT3 0#define COEFFS3 NULL#define N4 0#define SHIFT4 0#define COEFFS4 NULL#elif 1 // 11/5#define N1 0#define SHIFT1 1#define COEFFS1 NULL#define N2 2#define SHIFT2 2#define COEFFS2 (int[]){-1,-1}#define N3 2#define SHIFT3 0#define COEFFS3 (int[]){-1,-1}#define N4 4#define SHIFT4 7#define COEFFS4 (int[]){-5,29,29,-5}#define SCALEX 4#elif 1 // 9/7 CDF#define N1 2#define SHIFT1 7#define COEFFS1 (int[]){-203,-203}#define N2 2#define SHIFT2 12#define COEFFS2 (int[]){-217,-217}#define N3 2#define SHIFT3 7#define COEFFS3 (int[]){113,113}#define N4 2#define SHIFT4 9#define COEFFS4 (int[]){227,227}#define SCALEX 1#elif 1 // 7/5 CDF#define N1 0#define SHIFT1 1#define COEFFS1 NULL#define N2 2#define SHIFT2 2#define COEFFS2 (int[]){-1,-1}#define N3 2#define SHIFT3 0#define COEFFS3 (int[]){-1,-1}#define N4 2#define SHIFT4 4#define COEFFS4 (int[]){3,3}#elif 1 // 9/7 MN#define N1 4#define SHIFT1 4#define COEFFS1 (int[]){1,-9,-9,1}#define N2 2#define SHIFT2 2#define COEFFS2 (int[]){1,1}#define N3 0#define SHIFT3 1#define COEFFS3 NULL#define N4 0#define SHIFT4 1#define COEFFS4 NULL#else // 13/7 CRF#define N1 4#define SHIFT1 4#define COEFFS1 (int[]){1,-9,-9,1}#define N2 4#define SHIFT2 4#define COEFFS2 (int[]){-1,5,5,-1}#define N3 0#define SHIFT3 1#define COEFFS3 NULL#define N4 0#define SHIFT4 1#define COEFFS4 NULL#endifstatic void horizontal_decomposeX(DWTELEM *b, int width){    DWTELEM temp[width];    const int width2= width>>1;    const int w2= (width+1)>>1;    int x;    inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 0);    inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 0);    inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 0);    inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 0);    for(x=0; x<width2; x++){        temp[x   ]= b[2*x    ];        temp[x+w2]= b[2*x + 1];    }    if(width&1)        temp[x   ]= b[2*x    ];    memcpy(b, temp, width*sizeof(int));}static void horizontal_composeX(DWTELEM *b, int width){    DWTELEM temp[width];    const int width2= width>>1;    int x;    const int w2= (width+1)>>1;    memcpy(temp, b, width*sizeof(int));    for(x=0; x<width2; x++){        b[2*x    ]= temp[x   ];        b[2*x + 1]= temp[x+w2];    }    if(width&1)        b[2*x    ]= temp[x   ];    inplace_lift(b, width, COEFFS4, N4, SHIFT4, LX0, 1);    inplace_lift(b, width, COEFFS3, N3, SHIFT3, LX1, 1);    inplace_lift(b, width, COEFFS2, N2, SHIFT2, LX0, 1);    inplace_lift(b, width, COEFFS1, N1, SHIFT1, LX1, 1);}static void spatial_decomposeX(DWTELEM *buffer, int width, int height, int stride){    int x, y;    for(y=0; y<height; y++){        for(x=0; x<width; x++){            buffer[y*stride + x] *= SCALEX;        }    }    for(y=0; y<height; y++){        horizontal_decomposeX(buffer + y*stride, width);    }    inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 0);    inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 0);    inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 0);    inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 0);}static void spatial_composeX(DWTELEM *buffer, int width, int height, int stride){    int x, y;    inplace_liftV(buffer, width, height, stride, COEFFS4, N4, SHIFT4, LX0, 1);    inplace_liftV(buffer, width, height, stride, COEFFS3, N3, SHIFT3, LX1, 1);    inplace_liftV(buffer, width, height, stride, COEFFS2, N2, SHIFT2, LX0, 1);    inplace_liftV(buffer, width, height, stride, COEFFS1, N1, SHIFT1, LX1, 1);    for(y=0; y<height; y++){        horizontal_composeX(buffer + y*stride, width);    }    for(y=0; y<height; y++){        for(x=0; x<width; x++){            buffer[y*stride + x] /= SCALEX;        }    }}static void horizontal_decompose53i(DWTELEM *b, int width){    DWTELEM temp[width];    const int width2= width>>1;    int x;    const int w2= (width+1)>>1;    for(x=0; x<width2; x++){        temp[x   ]= b[2*x    ];        temp[x+w2]= b[2*x + 1];    }    if(width&1)        temp[x   ]= b[2*x    ];#if 0    {    int A1,A2,A3,A4;    A2= temp[1       ];    A4= temp[0       ];    A1= temp[0+width2];    A1 -= (A2 + A4)>>1;    A4 += (A1 + 1)>>1;    b[0+width2] = A1;    b[0       ] = A4;    for(x=1; x+1<width2; x+=2){        A3= temp[x+width2];        A4= temp[x+1     ];        A3 -= (A2 + A4)>>1;        A2 += (A1 + A3 + 2)>>2;        b[x+width2] = A3;        b[x       ] = A2;        A1= temp[x+1+width2];        A2= temp[x+2       ];        A1 -= (A2 + A4)>>1;        A4 += (A1 + A3 + 2)>>2;        b[x+1+width2] = A1;        b[x+1       ] = A4;    }    A3= temp[width-1];    A3 -= A2;    A2 += (A1 + A3 + 2)>>2;    b[width -1] = A3;    b[width2-1] = A2;    }#else    lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0);    lift(b   , temp   , b+w2, 1, 1, 1, width,  1, 2, 2, 0, 0);#endif}static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){    int i;    for(i=0; i<width; i++){        b1[i] -= (b0[i] + b2[i])>>1;    }}static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){    int i;    for(i=0; i<width; i++){        b1[i] += (b0[i] + b2[i] + 2)>>2;    }}static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){    int y;    DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride;    DWTELEM *b1= buffer + mirror(-2  , height-1)*stride;    for(y=-2; y<height; y+=2){        DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;        DWTELEM *b3= buffer + mirror(y+2, height-1)*stride;{START_TIMER        if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);        if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);STOP_TIMER("horizontal_decompose53i")}{START_TIMER        if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);        if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);STOP_TIMER("vertical_decompose53i*")}        b0=b2;        b1=b3;    }}static void horizontal_decompose97i(DWTELEM *b, int width){    DWTELEM temp[width];    const int w2= (width+1)>>1;    lift (temp+w2, b    +1, b      , 1, 2, 2, width, -W_AM, W_AO, W_AS, 1, 0);    liftS(temp   , b      , temp+w2, 1, 2, 1, width, -W_BM, W_BO, W_BS, 0, 0);    lift5(b   +w2, temp+w2, temp   , 1, 1, 1, width,  W_CM, W_CO, W_CS, 1, 0);    lift (b      , temp   , b   +w2, 1, 1, 1, width,  W_DM, W_DO, W_DS, 0, 0);}static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){    int i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -