annotate libmpcodecs/vf_ow.c @ 27978:9fb2ae256b5c

sync w/r27979
author gpoirier
date Sun, 23 Nov 2008 22:01:54 +0000
parents 82601a38e2a7
children df67d03dde3b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
1 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
2 * Copyright (C) 2007 Michael Niedermayer <michaelni@gmx.at>
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25221
diff changeset
19 */
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
20
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
21 /**
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
22 * @todo try to change to int
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
23 * @todo try lifting based implementation
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
24 * @todo optimize optimize optimize
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
25 * @todo hard tresholding
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
26 * @todo use QP to decide filter strength
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
27 * @todo wavelet normalization / least squares optimal signal vs. noise thresholds
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
28 */
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
29
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
30 #include <stdio.h>
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
31 #include <string.h>
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
32 #include <inttypes.h>
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
33 #include <math.h>
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
34
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
35 #include "config.h"
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
36
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
37 #include "mp_msg.h"
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
38
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
39 #ifdef HAVE_MALLOC_H
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
40 #include <malloc.h>
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
41 #endif
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
42
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
43 #include "img_format.h"
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
44 #include "mp_image.h"
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
45 #include "vf.h"
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
46
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
47 //===========================================================================//
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
48 static const uint8_t __attribute__((aligned(8))) dither[8][8]={
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
49 { 0, 48, 12, 60, 3, 51, 15, 63, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
50 { 32, 16, 44, 28, 35, 19, 47, 31, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
51 { 8, 56, 4, 52, 11, 59, 7, 55, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
52 { 40, 24, 36, 20, 43, 27, 39, 23, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
53 { 2, 50, 14, 62, 1, 49, 13, 61, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
54 { 34, 18, 46, 30, 33, 17, 45, 29, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
55 { 10, 58, 6, 54, 9, 57, 5, 53, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
56 { 42, 26, 38, 22, 41, 25, 37, 21, },
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
57 };
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
58 //FIXME the above is duplicated in many filters
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
59
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
60 struct vf_priv_s {
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
61 float strength[2];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
62 float delta;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
63 int mode;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
64 int depth;
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
65 float *plane[16][4];
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
66 int stride;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
67 };
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
68
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
69 #define S 1.41421356237 //sqrt(2)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
70
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
71 static const double coeff[2][5]={
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
72 {
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
73 0.6029490182363579 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
74 0.2668641184428723 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
75 -0.07822326652898785 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
76 -0.01686411844287495 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
77 0.02674875741080976 *S
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
78 },{
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
79 1.115087052456994 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
80 -0.5912717631142470 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
81 -0.05754352622849957 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
82 0.09127176311424948 /S
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
83 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
84 };
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
85
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
86 static const double icoeff[2][5]={
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
87 {
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
88 1.115087052456994 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
89 0.5912717631142470 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
90 -0.05754352622849957 /S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
91 -0.09127176311424948 /S
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
92 },{
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
93 0.6029490182363579 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
94 -0.2668641184428723 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
95 -0.07822326652898785 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
96 0.01686411844287495 *S,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
97 0.02674875741080976 *S
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
98 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
99 };
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
100 #undef S
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
101
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
102 static inline int mirror(int x, int w){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
103 while((unsigned)x > (unsigned)w){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
104 x=-x;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
105 if(x<0) x+= 2*w;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
106 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
107 return x;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
108 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
109
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
110 static inline void decompose(float *dstL, float *dstH, float *src, int stride, int w){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
111 int x, i;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
112 for(x=0; x<w; x++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
113 double sumL= src[x*stride] * coeff[0][0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
114 double sumH= src[x*stride] * coeff[1][0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
115 for(i=1; i<=4; i++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
116 double s= (src[mirror(x-i, w-1)*stride] + src[mirror(x+i, w-1)*stride]);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
117
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
118 sumL+= coeff[0][i]*s;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
119 sumH+= coeff[1][i]*s;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
120 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
121 dstL[x*stride]= sumL;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
122 dstH[x*stride]= sumH;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
123 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
124 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
125
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
126 static inline void compose(float *dst, float *srcL, float *srcH, int stride, int w){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
127 int x, i;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
128 for(x=0; x<w; x++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
129 double sumL= srcL[x*stride] * icoeff[0][0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
130 double sumH= srcH[x*stride] * icoeff[1][0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
131 for(i=1; i<=4; i++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
132 int x0= mirror(x-i, w-1)*stride;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
133 int x1= mirror(x+i, w-1)*stride;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
134
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
135 sumL+= icoeff[0][i]*(srcL[x0] + srcL[x1]);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
136 sumH+= icoeff[1][i]*(srcH[x0] + srcH[x1]);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
137 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
138 dst[x*stride]= (sumL + sumH)*0.5;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
139 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
140 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
141
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
142 static inline void decompose2D(float *dstL, float *dstH, float *src, int xstride, int ystride, int step, int w, int h){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
143 int y, x;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
144 for(y=0; y<h; y++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
145 for(x=0; x<step; x++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
146 decompose(dstL + ystride*y + xstride*x, dstH + ystride*y + xstride*x, src + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
147 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
148
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
149 static inline void compose2D(float *dst, float *srcL, float *srcH, int xstride, int ystride, int step, int w, int h){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
150 int y, x;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
151 for(y=0; y<h; y++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
152 for(x=0; x<step; x++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
153 compose(dst + ystride*y + xstride*x, srcL + ystride*y + xstride*x, srcH + ystride*y + xstride*x, step*xstride, (w-x+step-1)/step);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
154 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
155
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
156 static void decompose2D2(float *dst[4], float *src, float *temp[2], int stride, int step, int w, int h){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
157 decompose2D(temp[0], temp[1], src , 1, stride, step , w, h);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
158 decompose2D( dst[0], dst[1], temp[0], stride, 1, step , h, w);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
159 decompose2D( dst[2], dst[3], temp[1], stride, 1, step , h, w);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
160 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
161
24680
4d56303b85ab change double arrays to float (this should be accurate enough)
michael
parents: 24679
diff changeset
162 static void compose2D2(float *dst, float *src[4], float *temp[2], int stride, int step, int w, int h){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
163 compose2D(temp[0], src[0], src[1], stride, 1, step , h, w);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
164 compose2D(temp[1], src[2], src[3], stride, 1, step , h, w);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
165 compose2D(dst , temp[0], temp[1], 1, stride, step , w, h);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
166 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
167
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
168 static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, int is_luma){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
169 int x,y, i, j;
24808
1318366cf2da fix warning:
diego
parents: 24680
diff changeset
170 // double sum=0;
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
171 double s= p->strength[!is_luma];
24679
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
172 int depth= p->depth;
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
173
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
174 while(1<<depth > width || 1<<depth > height)
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
175 depth--;
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
176
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
177 for(y=0; y<height; y++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
178 for(x=0; x<width; x++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
179 p->plane[0][0][x + y*p->stride]= src[x + y*src_stride];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
180
24679
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
181 for(i=0; i<depth; i++){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
182 decompose2D2(p->plane[i+1], p->plane[i][0], p->plane[0]+1,p->stride, 1<<i, width, height);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
183 }
24679
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
184 for(i=0; i<depth; i++){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
185 for(j=1; j<4; j++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
186 for(y=0; y<height; y++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
187 for(x=0; x<width; x++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
188 double v= p->plane[i+1][j][x + y*p->stride];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
189 if (v> s) v-=s;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
190 else if(v<-s) v+=s;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
191 else v =0;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
192 p->plane[i+1][j][x + y*p->stride]= v;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
193 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
194 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
195 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
196 }
24679
065d1f97815f fix infinite loop
michael
parents: 24677
diff changeset
197 for(i=depth-1; i>=0; i--){
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
198 compose2D2(p->plane[i][0], p->plane[i+1], p->plane[0]+1, p->stride, 1<<i, width, height);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
199 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
200
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
201 for(y=0; y<height; y++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
202 for(x=0; x<width; x++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
203 i= p->plane[0][0][x + y*p->stride] + dither[x&7][y&7]*(1.0/64) + 1.0/128; //yes the rounding is insane but optimal :)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
204 // double e= i - src[x + y*src_stride];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
205 // sum += e*e;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
206 if((unsigned)i > 255U) i= ~(i>>31);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
207 dst[x + y*dst_stride]= i;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
208 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
209
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
210 // printf("%f\n", sum/height/width);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
211 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
212
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
213 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
214 int h= (height+15)&(~15);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
215 int i,j;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
216
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
217 vf->priv->stride= (width+15)&(~15);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
218 for(j=0; j<4; j++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
219 for(i=0; i<=vf->priv->depth; i++)
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
220 vf->priv->plane[i][j]= malloc(vf->priv->stride*h*sizeof(vf->priv->plane[0][0][0]));
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
221 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
222
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
223 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
224 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
225
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
226 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
227 if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
228 // ok, we can do pp in-place (or pp disabled):
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
229 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
230 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
231 mpi->planes[0]=vf->dmpi->planes[0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
232 mpi->stride[0]=vf->dmpi->stride[0];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
233 mpi->width=vf->dmpi->width;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
234 if(mpi->flags&MP_IMGFLAG_PLANAR){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
235 mpi->planes[1]=vf->dmpi->planes[1];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
236 mpi->planes[2]=vf->dmpi->planes[2];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
237 mpi->stride[1]=vf->dmpi->stride[1];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
238 mpi->stride[2]=vf->dmpi->stride[2];
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
239 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
240 mpi->flags|=MP_IMGFLAG_DIRECT;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
241 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
242
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
243 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
244 mp_image_t *dmpi;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
245
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
246 if(!(mpi->flags&MP_IMGFLAG_DIRECT)){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
247 // no DR, so get a new image! hope we'll get DR buffer:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
248 dmpi=vf_get_image(vf->next,mpi->imgfmt,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
249 MP_IMGTYPE_TEMP,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
250 MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
251 mpi->width,mpi->height);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
252 vf_clone_mpi_attributes(dmpi, mpi);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
253 }else{
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
254 dmpi=vf->dmpi;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
255 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
256
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
257 filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, 1);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
258 filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
259 filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
260
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
261 return vf_next_put_image(vf,dmpi, pts);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
262 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
263
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
264 static void uninit(struct vf_instance_s* vf){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
265 int i,j;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
266 if(!vf->priv) return;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
267
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
268 for(j=0; j<4; j++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
269 for(i=0; i<16; i++){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
270 free(vf->priv->plane[i][j]);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
271 vf->priv->plane[i][j]= NULL;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
272 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
273 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
274
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
275 free(vf->priv);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
276 vf->priv=NULL;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
277 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
278
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
279 //===========================================================================//
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
280 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
281 switch(fmt){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
282 case IMGFMT_YVU9:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
283 case IMGFMT_IF09:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
284 case IMGFMT_YV12:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
285 case IMGFMT_I420:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
286 case IMGFMT_IYUV:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
287 case IMGFMT_CLPL:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
288 case IMGFMT_Y800:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
289 case IMGFMT_Y8:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
290 case IMGFMT_444P:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
291 case IMGFMT_422P:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
292 case IMGFMT_411P:
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
293 return vf_next_query_format(vf,fmt);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
294 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
295 return 0;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
296 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
297
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
298
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
299 static int open(vf_instance_t *vf, char* args){
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
300 vf->config=config;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
301 vf->put_image=put_image;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
302 vf->get_image=get_image;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
303 vf->query_format=query_format;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
304 vf->uninit=uninit;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
305 vf->priv=malloc(sizeof(struct vf_priv_s));
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
306 memset(vf->priv, 0, sizeof(struct vf_priv_s));
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
307
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
308 vf->priv->depth= 8;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
309 vf->priv->strength[0]= 1.0;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
310 vf->priv->strength[1]= 1.0;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
311 vf->priv->delta= 1.0;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
312
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
313 if (args) sscanf(args, "%d:%f:%f:%d:%f", &vf->priv->depth,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
314 &vf->priv->strength[0],
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
315 &vf->priv->strength[1],
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
316 &vf->priv->mode,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
317 &vf->priv->delta);
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
318
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
319 return 1;
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
320 }
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
321
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24865
diff changeset
322 const vf_info_t vf_info_ow = {
24677
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
323 "overcomplete wavelet denoiser",
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
324 "ow",
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
325 "Michael Niedermayer",
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
326 "",
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
327 open,
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
328 NULL
9f81c2175803 overcomplete wavelet denoiser
michael
parents:
diff changeset
329 };