42 { 0, 48, 12, 60, 3, 51, 15, 63, },
43 { 32, 16, 44, 28, 35, 19, 47, 31, },
44 { 8, 56, 4, 52, 11, 59, 7, 55, },
45 { 40, 24, 36, 20, 43, 27, 39, 23, },
46 { 2, 50, 14, 62, 1, 49, 13, 61, },
47 { 34, 18, 46, 30, 33, 17, 45, 29, },
48 { 10, 58, 6, 54, 9, 57, 5, 53, },
49 { 42, 26, 38, 22, 41, 25, 37, 21, },
62 #define S 1.41421356237 //sqrt(2)
64 static const double coeff[2][5]={
66 0.6029490182363579 *
S,
67 0.2668641184428723 *
S,
68 -0.07822326652898785 *
S,
69 -0.01686411844287495 *
S,
70 0.02674875741080976 *
S
73 -0.5912717631142470 /
S,
74 -0.05754352622849957 /
S,
75 0.09127176311424948 /
S
82 0.5912717631142470 /
S,
83 -0.05754352622849957 /
S,
84 -0.09127176311424948 /
S
86 0.6029490182363579 *
S,
87 -0.2668641184428723 *
S,
88 -0.07822326652898785 *
S,
89 0.01686411844287495 *
S,
90 0.02674875741080976 *
S
95 static inline int mirror(
int x,
int w){
96 while((
unsigned)x > (
unsigned)w){
103 static inline void decompose(
float *dstL,
float *dstH,
float *src,
int stride,
int w){
106 double sumL= src[x*
stride] * coeff[0][0];
107 double sumH= src[x*
stride] * coeff[1][0];
111 sumL+= coeff[0][i]*s;
112 sumH+= coeff[1][i]*s;
122 double sumL= srcL[x*
stride] * icoeff[0][0];
123 double sumH= srcH[x*
stride] * icoeff[1][0];
128 sumL+= icoeff[0][i]*(srcL[x0] + srcL[x1]);
129 sumH+= icoeff[1][i]*(srcH[x0] + srcH[x1]);
131 dst[x*
stride]= (sumL + sumH)*0.5;
135 static inline void decompose2D(
float *dstL,
float *dstH,
float *src,
int xstride,
int ystride,
int step,
int w,
int h){
138 for(x=0; x<step; x++)
139 decompose(dstL + ystride*y + xstride*x, dstH + ystride*y + xstride*x, src + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
142 static inline void compose2D(
float *
dst,
float *srcL,
float *srcH,
int xstride,
int ystride,
int step,
int w,
int h){
145 for(x=0; x<step; x++)
146 compose(dst + ystride*y + xstride*x, srcL + ystride*y + xstride*x, srcH + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
150 decompose2D(temp[0], temp[1], src , 1, stride, step , w, h);
151 decompose2D( dst[0], dst[1], temp[0], stride, 1, step , h, w);
152 decompose2D( dst[2], dst[3], temp[1], stride, 1, step , h, w);
156 compose2D(temp[0], src[0], src[1], stride, 1, step , h, w);
157 compose2D(temp[1], src[2], src[3], stride, 1, step , h, w);
158 compose2D(dst , temp[0], temp[1], 1, stride, step , w, h);
167 while(1<<depth > width || 1<<depth > height)
171 for(x=0; x<
width; x++)
172 p->
plane[0][0][x + y*p->
stride]= src[x + y*src_stride];
174 for(i=0; i<depth; i++){
177 for(i=0; i<
depth; i++){
180 for(x=0; x<
width; x++){
190 for(i=depth-1; i>=0; i--){
195 for(x=0; x<
width; x++){
199 if((
unsigned)i > 255
U) i= ~(i>>31);
200 dst[x + y*dst_stride]= i;
206 static int config(
struct vf_instance *vf,
int width,
int height,
int d_width,
int d_height,
unsigned int flags,
unsigned int outfmt){
207 int h= (height+15)&(~15);
210 vf->priv->stride= (width+15)&(~15);
212 for(i=0; i<=vf->priv->depth; i++)
213 vf->priv->plane[i][j]= malloc(vf->priv->stride*h*
sizeof(vf->priv->plane[0][0][0]));
224 mpi->
planes[0]=vf->dmpi->planes[0];
225 mpi->
stride[0]=vf->dmpi->stride[0];
226 mpi->
width=vf->dmpi->width;
228 mpi->
planes[1]=vf->dmpi->planes[1];
229 mpi->
planes[2]=vf->dmpi->planes[2];
230 mpi->
stride[1]=vf->dmpi->stride[1];
231 mpi->
stride[2]=vf->dmpi->stride[2];
257 static void uninit(
struct vf_instance *vf){
259 if(!vf->priv)
return;
263 free(vf->priv->plane[i][j]);
264 vf->priv->plane[i][j]=
NULL;
306 if (args) sscanf(args,
"%d:%f:%f:%d:%f", &vf->
priv->
depth,
316 "overcomplete wavelet denoiser",
318 "Michael Niedermayer",