📄 snow.c
字号:
}
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 ];
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);
}
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;
if(y+1<(unsigned)height) horizontal_decompose53i(b2, width);
if(y+2<(unsigned)height) horizontal_decompose53i(b3, width);
if(y+1<(unsigned)height) vertical_decompose53iH0(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_decompose53iL0(b0, b1, b2, width);
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;
for(i=0; i<width; i++){
b1[i] -= (W_AM*(b0[i] + b2[i])+W_AO)>>W_AS;
}
}
static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
#ifdef lift5
b1[i] += (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
#else
int r= 3*(b0[i] + b2[i]);
r+= r>>4;
r+= r>>8;
b1[i] += (r+W_CO)>>W_CS;
#endif
}
}
static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *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] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + 8*5 + (5<<27)) / (5*16) - (1<<23);
#endif
}
}
static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
b1[i] += (W_DM*(b0[i] + b2[i])+W_DO)>>W_DS;
}
}
static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){
int y;
DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride;
DWTELEM *b1= buffer + mirror(-4 , height-1)*stride;
DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride;
DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride;
for(y=-4; y<height; y+=2){
DWTELEM *b4= buffer + mirror(y+3, height-1)*stride;
DWTELEM *b5= buffer + mirror(y+4, height-1)*stride;
if(y+3<(unsigned)height) horizontal_decompose97i(b4, width);
if(y+4<(unsigned)height) horizontal_decompose97i(b5, width);
if(y+3<(unsigned)height) vertical_decompose97iH0(b3, b4, b5, width);
if(y+2<(unsigned)height) vertical_decompose97iL0(b2, b3, b4, width);
if(y+1<(unsigned)height) vertical_decompose97iH1(b1, b2, b3, width);
if(y+0<(unsigned)height) vertical_decompose97iL1(b0, b1, b2, width);
b0=b2;
b1=b3;
b2=b4;
b3=b5;
}
}
void ff_spatial_dwt(DWTELEM *buffer, int width, int height, int stride, int type, int decomposition_count){
int level;
for(level=0; level<decomposition_count; level++){
switch(type){
case DWT_97: spatial_decompose97i(buffer, width>>level, height>>level, stride<<level); break;
case DWT_53: spatial_decompose53i(buffer, width>>level, height>>level, stride<<level); break;
case DWT_X: spatial_decomposeX (buffer, width>>level, height>>level, stride<<level); break;
}
}
}
static void horizontal_compose53i(DWTELEM *b, int width){
DWTELEM temp[width];
const int width2= width>>1;
const int w2= (width+1)>>1;
int x;
lift(temp , b , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 1);
lift(temp+w2, b+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 1);
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 ];
}
static void vertical_compose53iH0(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_compose53iL0(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_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, DWTELEM *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;
DWTELEM *b0= cs->b0;
DWTELEM *b1= cs->b1;
DWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line);
DWTELEM *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, DWTELEM *buffer, int width, int height, int stride){
int y= cs->y;
DWTELEM *b0= cs->b0;
DWTELEM *b1= cs->b1;
DWTELEM *b2= buffer + mirror(y+1, height-1)*stride;
DWTELEM *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 spatial_compose53i(DWTELEM *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(DWTELEM *b, int width){
DWTELEM temp[width];
const int w2= (width+1)>>1;
lift (temp , b , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 1);
lift5(temp+w2, b +w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 1);
liftS(b , temp , temp+w2, 2, 1, 1, width, -W_BM, W_BO, W_BS, 0, 1);
lift (b+1 , temp+w2, b , 2, 1, 2, width, -W_AM, W_AO, W_AS, 1, 1);
}
static void vertical_compose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *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(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){
int i;
for(i=0; i<width; i++){
#ifdef lift5
b1[i] -= (W_CM*(b0[i] + b2[i])+W_CO)>>W_CS;
#else
int r= 3*(b0[i] + b2[i]);
r+= r>>4;
r+= r>>8;
b1[i] -= (r+W_CO)>>W_CS;
#endif
}
}
static void vertical_compose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *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(DWTELEM *b0, DWTELEM *b1, DWTELEM *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(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, DWTELEM *b3, DWTELEM *b4, DWTELEM *b5, int width){
int i;
for(i=0; i<width; i++){
#ifndef lift5
int r;
#endif
b4[i] -= (W_DM*(b3[i] + b5[i])+W_DO)>>W_DS;
#ifdef lift5
b3[i] -= (W_CM*(b2[i] + b4[i])+W_CO)>>W_CS;
#else
r= 3*(b2[i] + b4[i]);
r+= r>>4;
r+= r>>8;
b3[i] -= (r+W_CO)>>W_CS;
#endif
#ifdef liftS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -