-#endif
-
-
-static 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
-#endif
-static 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;
- }
- }