📄 snow.c
字号:
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 inv_lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1); inv_lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1);#endif /* 0 */ 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 ];#ifdef __CW32__ av_free(temp);#endif}static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){ b1[i] += (b0[i] + b2[i])>>1; }}static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){ b1[i] -= (b0[i] + b2[i] + 2)>>2; }}static void spatial_compose53i_buffered_init(dwt_compose_t *cs, slice_buffer * sb, int height, int stride_line){ cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line); cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line); cs->y = -1;}static void spatial_compose53i_init(dwt_compose_t *cs, IDWTELEM *buffer, int height, int stride){ cs->b0 = buffer + mirror(-1-1, height-1)*stride; cs->b1 = buffer + mirror(-1 , height-1)*stride; cs->y = -1;}static void spatial_compose53i_dy_buffered(dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){ int y= cs->y; IDWTELEM *b0= cs->b0; IDWTELEM *b1= cs->b1; IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); if(y-1<(unsigned)height) horizontal_compose53i(b0, width); if(y+0<(unsigned)height) horizontal_compose53i(b1, width); cs->b0 = b2; cs->b1 = b3; cs->y += 2;}static void spatial_compose53i_dy(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride){ int y= cs->y; IDWTELEM *b0= cs->b0; IDWTELEM *b1= cs->b1; IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride; IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride; if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); if(y-1<(unsigned)height) horizontal_compose53i(b0, width); if(y+0<(unsigned)height) horizontal_compose53i(b1, width); cs->b0 = b2; cs->b1 = b3; cs->y += 2;}static void av_unused spatial_compose53i(IDWTELEM *buffer, int width, int height, int stride){ dwt_compose_t cs; spatial_compose53i_init(&cs, buffer, height, stride); while(cs.y <= height) spatial_compose53i_dy(&cs, buffer, width, height, stride);}void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){#ifdef __CW32__ IDWTELEM *temp;#else IDWTELEM temp[width];#endif const int w2= (width+1)>>1; inv_lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); inv_lift (temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1); inv_liftS(b , temp , temp+w2, 2, 1, 1, width, W_BM, W_BO, W_BS, 0, 1); inv_lift (b+1 , temp+w2, b , 2, 1, 2, width, W_AM, W_AO, W_AS, 1, 0);}static void vertical_compose97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){ b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; }}static void vertical_compose97iH1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){ b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS; }}static void vertical_compose97iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){#ifdef liftS b1[i] += (W_BM*(b0[i] + b2[i])+W_BO)>>W_BS;#else b1[i] += (W_BM*(b0[i] + b2[i])+4*b1[i]+W_BO)>>W_BS;#endif }}static void vertical_compose97iL1(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ int i; for(i=0; i<width; i++){ b1[i] -= (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS; }}void ff_snow_vertical_compose97i(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width){ int i; for(i=0; i<width; i++){ b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS; b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;#ifdef liftS b2[i] += (W_BM*(b1[i] + b3[i])+W_BO)>>W_BS;#else b2[i] += (W_BM*(b1[i] + b3[i])+4*b2[i]+W_BO)>>W_BS;#endif b1[i] += (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS; }}static void spatial_compose97i_buffered_init(dwt_compose_t *cs, slice_buffer * sb, int height, int stride_line){ cs->b0 = slice_buffer_get_line(sb, mirror(-3-1, height-1) * stride_line); cs->b1 = slice_buffer_get_line(sb, mirror(-3 , height-1) * stride_line); cs->b2 = slice_buffer_get_line(sb, mirror(-3+1, height-1) * stride_line); cs->b3 = slice_buffer_get_line(sb, mirror(-3+2, height-1) * stride_line); cs->y = -3;}static void spatial_compose97i_init(dwt_compose_t *cs, IDWTELEM *buffer, int height, int stride){ cs->b0 = buffer + mirror(-3-1, height-1)*stride; cs->b1 = buffer + mirror(-3 , height-1)*stride; cs->b2 = buffer + mirror(-3+1, height-1)*stride; cs->b3 = buffer + mirror(-3+2, height-1)*stride; cs->y = -3;}static void spatial_compose97i_dy_buffered(DSPContext *dsp, dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line){ int y = cs->y; IDWTELEM *b0= cs->b0; IDWTELEM *b1= cs->b1; IDWTELEM *b2= cs->b2; IDWTELEM *b3= cs->b3; IDWTELEM *b4= slice_buffer_get_line(sb, mirror(y + 3, height - 1) * stride_line); IDWTELEM *b5= slice_buffer_get_line(sb, mirror(y + 4, height - 1) * stride_line); if(y>0 && y+4<height){ dsp->vertical_compose97i(b0, b1, b2, b3, b4, b5, width); }else{ if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); } if(y-1<(unsigned)height) dsp->horizontal_compose97i(b0, width); if(y+0<(unsigned)height) dsp->horizontal_compose97i(b1, width); cs->b0=b2; cs->b1=b3; cs->b2=b4; cs->b3=b5; cs->y += 2;}static void spatial_compose97i_dy(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride){ int y = cs->y; IDWTELEM *b0= cs->b0; IDWTELEM *b1= cs->b1; IDWTELEM *b2= cs->b2; IDWTELEM *b3= cs->b3; IDWTELEM *b4= buffer + mirror(y+3, height-1)*stride; IDWTELEM *b5= buffer + mirror(y+4, height-1)*stride; if(y+3<(unsigned)height) vertical_compose97iL1(b3, b4, b5, width); if(y+2<(unsigned)height) vertical_compose97iH1(b2, b3, b4, width); if(y+1<(unsigned)height) vertical_compose97iL0(b1, b2, b3, width); if(y+0<(unsigned)height) vertical_compose97iH0(b0, b1, b2, width); if(y-1<(unsigned)height) ff_snow_horizontal_compose97i(b0, width); if(y+0<(unsigned)height) ff_snow_horizontal_compose97i(b1, width); cs->b0=b2; cs->b1=b3; cs->b2=b4; cs->b3=b5; cs->y += 2;}static void av_unused spatial_compose97i(IDWTELEM *buffer, int width, int height, int stride){ dwt_compose_t cs; spatial_compose97i_init(&cs, buffer, height, stride); while(cs.y <= height) spatial_compose97i_dy(&cs, buffer, width, height, stride);}static void ff_spatial_idwt_buffered_init(dwt_compose_t *cs, slice_buffer * sb, int width, int height, int stride_line, int type, int decomposition_count){ int level; for(level=decomposition_count-1; level>=0; level--){ switch(type){ case DWT_97: spatial_compose97i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break; case DWT_53: spatial_compose53i_buffered_init(cs+level, sb, height>>level, stride_line<<level); break; } }}static void ff_spatial_idwt_init(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){ int level; for(level=decomposition_count-1; level>=0; level--){ switch(type){ case DWT_97: spatial_compose97i_init(cs+level, buffer, height>>level, stride<<level); break; case DWT_53: spatial_compose53i_init(cs+level, buffer, height>>level, stride<<level); break; } }}static void ff_spatial_idwt_slice(dwt_compose_t *cs, IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count, int y){ const int support = type==1 ? 3 : 5; int level; if(type==2) return; for(level=decomposition_count-1; level>=0; level--){ while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ switch(type){ case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); break; case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); break; } } }}static void ff_spatial_idwt_buffered_slice(DSPContext *dsp, dwt_compose_t *cs, slice_buffer * slice_buf, int width, int height, int stride_line, int type, int decomposition_count, int y){ const int support = type==1 ? 3 : 5; int level; if(type==2) return; for(level=decomposition_count-1; level>=0; level--){ while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ switch(type){ case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<<level); break; case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level); break; } } }}static void ff_spatial_idwt(IDWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){ dwt_compose_t cs[MAX_DECOMPOSITIONS]; int y; ff_spatial_idwt_init(cs, buffer, width, height, stride, type, decomposition_count); for(y=0; y<height; y+=4) ff_spatial_idwt_slice(cs, buffer, width, height, stride, type, decomposition_count, y);}static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ const int w= b->width; const int h= b->height; int x, y; if(1){ int run=0;#ifdef __CW32__ int *runs;#else int runs[w*h];#endif int run_index=0; int max_index;#ifdef __CW32__ runs = av_malloc(sizeof(int)*w*h);#endif for(y=0; y<h; y++){ for(x=0; x<w; x++){ int v, p=0; int /*ll=0, */l=0, lt=0, t=0, rt=0; v= src[x + y*stride]; if(y){ t= src[x + (y-1)*stride]; if(x){ lt= src[x - 1 + (y-1)*stride]; } if(x + 1 < w){ rt= src[x + 1 + (y-1)*stride]; } } if(x){ l= src[x - 1 + y*stride];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -