42 float *plane[16+1][4];
47 #define OFFSET(x) offsetof(OWDenoiseContext, x)
48 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
61 { 0, 48, 12, 60, 3, 51, 15, 63 },
62 { 32, 16, 44, 28, 35, 19, 47, 31 },
63 { 8, 56, 4, 52, 11, 59, 7, 55 },
64 { 40, 24, 36, 20, 43, 27, 39, 23 },
65 { 2, 50, 14, 62, 1, 49, 13, 61 },
66 { 34, 18, 46, 30, 33, 17, 45, 29 },
67 { 10, 58, 6, 54, 9, 57, 5, 53 },
68 { 42, 26, 38, 22, 41, 25, 37, 21 },
71 static const double coeff[2][5] = {
103 while ((
unsigned)x > (
unsigned)w) {
111 static inline void decompose(
float *dst_l,
float *dst_h,
const float *
src,
115 for (x = 0; x < w; x++) {
116 double sum_l = src[x * linesize] *
coeff[0][0];
117 double sum_h = src[x * linesize] * coeff[1][0];
118 for (i = 1; i <= 4; i++) {
119 const double s = src[
mirror(x - i, w - 1) * linesize]
120 + src[
mirror(x + i, w - 1) * linesize];
122 sum_l += coeff[0][i] *
s;
123 sum_h += coeff[1][i] *
s;
125 dst_l[x * linesize] = sum_l;
126 dst_h[x * linesize] = sum_h;
130 static inline void compose(
float *dst,
const float *src_l,
const float *src_h,
134 for (x = 0; x < w; x++) {
135 double sum_l = src_l[x * linesize] *
icoeff[0][0];
136 double sum_h = src_h[x * linesize] * icoeff[1][0];
137 for (i = 1; i <= 4; i++) {
138 const int x0 =
mirror(x - i, w - 1) * linesize;
139 const int x1 =
mirror(x + i, w - 1) * linesize;
141 sum_l += icoeff[0][i] * (src_l[x0] + src_l[x1]);
142 sum_h += icoeff[1][i] * (src_h[x0] + src_h[x1]);
144 dst[x * linesize] = (sum_l + sum_h) * 0.5;
149 int xlinesize,
int ylinesize,
150 int step,
int w,
int h)
153 for (y = 0; y < h; y++)
154 for (x = 0; x < step; x++)
155 decompose(dst_l + ylinesize*y + xlinesize*x,
156 dst_h + ylinesize*y + xlinesize*x,
157 src + ylinesize*y + xlinesize*x,
158 step * xlinesize, (w - x + step - 1) / step);
161 static inline void compose2D(
float *dst,
const float *src_l,
const float *src_h,
162 int xlinesize,
int ylinesize,
163 int step,
int w,
int h)
166 for (y = 0; y < h; y++)
167 for (x = 0; x < step; x++)
168 compose(dst + ylinesize*y + xlinesize*x,
169 src_l + ylinesize*y + xlinesize*x,
170 src_h + ylinesize*y + xlinesize*x,
171 step * xlinesize, (w - x + step - 1) / step);
175 int linesize,
int step,
int w,
int h)
177 decompose2D(temp[0], temp[1], src, 1, linesize, step, w, h);
178 decompose2D( dst[0], dst[1], temp[0], linesize, 1, step, h, w);
179 decompose2D( dst[2], dst[3], temp[1], linesize, 1, step, h, w);
183 int linesize,
int step,
int w,
int h)
185 compose2D(temp[0], src[0], src[1], linesize, 1, step, h, w);
186 compose2D(temp[1], src[2], src[3], linesize, 1, step, h, w);
187 compose2D(dst, temp[0], temp[1], 1, linesize, step, w, h);
191 uint8_t *dst,
int dst_linesize,
197 while (1<<depth > width || 1<<depth > height)
200 for (y = 0; y <
height; y++)
201 for(x = 0; x <
width; x++)
207 for (i = 0; i <
depth; i++) {
208 for (j = 1; j < 4; j++) {
209 for (y = 0; y <
height; y++) {
210 for (x = 0; x <
width; x++) {
212 if (v > strength) v -= strength;
213 else if (v < -strength) v += strength;
220 for (i = depth-1; i >= 0; i--)
223 for (y = 0; y <
height; y++) {
224 for (x = 0; x <
width; x++) {
226 if ((
unsigned)i > 255
U) i = ~(i >> 31);
227 dst[y*dst_linesize + x] = i;
262 inlink->
w, inlink->
h);
288 const int h =
FFALIGN(inlink->
h, 16);
294 for (j = 0; j < 4; j++) {
295 for (i = 0; i <= s->
depth; i++) {
309 for (j = 0; j < 4; j++)
310 for (i = 0; i <= s->
depth; i++)
338 .
inputs = owdenoise_inputs,
340 .priv_class = &owdenoise_class,