FFmpeg
vf_vaguedenoiser.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003 LeFunGus, lefungus@altern.org
3  *
4  * This file is part of FFmpeg
5  *
6  * FFmpeg is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #include <float.h>
22 
23 #include "libavutil/imgutils.h"
24 #include "libavutil/attributes.h"
25 #include "libavutil/common.h"
26 #include "libavutil/mem.h"
27 #include "libavutil/pixdesc.h"
28 #include "libavutil/opt.h"
29 
30 #include "avfilter.h"
31 #include "filters.h"
32 #include "video.h"
33 
34 typedef struct VagueDenoiserContext {
35  const AVClass *class;
36 
37  float threshold;
38  float percent;
39  int method;
40  int type;
41  int nsteps;
42  int planes;
43 
44  int depth;
45  int bpc;
46  int peak;
47  int nb_planes;
48  int planeheight[4];
49  int planewidth[4];
50 
51  float *block;
52  float *in;
53  float *out;
54  float *tmp;
55 
56  int hlowsize[4][32];
57  int hhighsize[4][32];
58  int vlowsize[4][32];
59  int vhighsize[4][32];
60 
61  void (*thresholding)(float *block, const int width, const int height,
62  const int stride, const float threshold,
63  const float percent);
65 
66 #define OFFSET(x) offsetof(VagueDenoiserContext, x)
67 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_FILTERING_PARAM
68 static const AVOption vaguedenoiser_options[] = {
69  { "threshold", "set filtering strength", OFFSET(threshold), AV_OPT_TYPE_FLOAT, {.dbl=2.}, 0,DBL_MAX, FLAGS },
70  { "method", "set filtering method", OFFSET(method), AV_OPT_TYPE_INT, {.i64=2 }, 0, 2, FLAGS, .unit = "method" },
71  { "hard", "hard thresholding", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, .unit = "method" },
72  { "soft", "soft thresholding", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, .unit = "method" },
73  { "garrote", "garrote thresholding", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, .unit = "method" },
74  { "nsteps", "set number of steps", OFFSET(nsteps), AV_OPT_TYPE_INT, {.i64=6 }, 1, 32, FLAGS },
75  { "percent", "set percent of full denoising", OFFSET(percent),AV_OPT_TYPE_FLOAT, {.dbl=85}, 0,100, FLAGS },
76  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15 }, 0, 15, FLAGS },
77  { "type", "set threshold type", OFFSET(type), AV_OPT_TYPE_INT, {.i64=0 }, 0, 1, FLAGS, .unit = "type" },
78  { "universal", "universal (VisuShrink)", 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, .unit = "type" },
79  { "bayes", "bayes (BayesShrink)", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, .unit = "type" },
80  { NULL }
81 };
82 
83 AVFILTER_DEFINE_CLASS(vaguedenoiser);
84 
85 #define NPAD 10
86 
87 static const float analysis_low[9] = {
88  0.037828455506995f, -0.023849465019380f, -0.110624404418423f, 0.377402855612654f,
89  0.852698679009403f, 0.377402855612654f, -0.110624404418423f, -0.023849465019380f, 0.037828455506995f
90 };
91 
92 static const float analysis_high[7] = {
93  -0.064538882628938f, 0.040689417609558f, 0.418092273222212f, -0.788485616405664f,
94  0.418092273222212f, 0.040689417609558f, -0.064538882628938f
95 };
96 
97 static const float synthesis_low[7] = {
98  -0.064538882628938f, -0.040689417609558f, 0.418092273222212f, 0.788485616405664f,
99  0.418092273222212f, -0.040689417609558f, -0.064538882628938f
100 };
101 
102 static const float synthesis_high[9] = {
103  -0.037828455506995f, -0.023849465019380f, 0.110624404418423f, 0.377402855612654f,
104  -0.852698679009403f, 0.377402855612654f, 0.110624404418423f, -0.023849465019380f, -0.037828455506995f
105 };
106 
107 static const enum AVPixelFormat pix_fmts[] = {
131 };
132 
134 {
135  VagueDenoiserContext *s = inlink->dst->priv;
137  int p, i, nsteps_width, nsteps_height, nsteps_max;
138 
139  s->depth = desc->comp[0].depth;
140  s->bpc = (s->depth + 7) / 8;
141  s->nb_planes = desc->nb_components;
142 
143  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
144  s->planeheight[0] = s->planeheight[3] = inlink->h;
145  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
146  s->planewidth[0] = s->planewidth[3] = inlink->w;
147 
148  s->block = av_malloc_array(inlink->w * inlink->h, sizeof(*s->block));
149  s->in = av_malloc_array(32 + FFMAX(inlink->w, inlink->h), sizeof(*s->in));
150  s->out = av_malloc_array(32 + FFMAX(inlink->w, inlink->h), sizeof(*s->out));
151  s->tmp = av_malloc_array(32 + FFMAX(inlink->w, inlink->h), sizeof(*s->tmp));
152 
153  if (!s->block || !s->in || !s->out || !s->tmp)
154  return AVERROR(ENOMEM);
155 
156  s->threshold *= 1 << (s->depth - 8);
157  s->peak = (1 << s->depth) - 1;
158 
159  nsteps_width = ((s->planes & 2 || s->planes & 4) && s->nb_planes > 1) ? s->planewidth[1] : s->planewidth[0];
160  nsteps_height = ((s->planes & 2 || s->planes & 4) && s->nb_planes > 1) ? s->planeheight[1] : s->planeheight[0];
161 
162  for (nsteps_max = 1; nsteps_max < 15; nsteps_max++) {
163  if (pow(2, nsteps_max) >= nsteps_width || pow(2, nsteps_max) >= nsteps_height)
164  break;
165  }
166 
167  s->nsteps = FFMIN(s->nsteps, nsteps_max - 2);
168 
169  for (p = 0; p < 4; p++) {
170  s->hlowsize[p][0] = (s->planewidth[p] + 1) >> 1;
171  s->hhighsize[p][0] = s->planewidth[p] >> 1;
172  s->vlowsize[p][0] = (s->planeheight[p] + 1) >> 1;
173  s->vhighsize[p][0] = s->planeheight[p] >> 1;
174 
175  for (i = 1; i < s->nsteps; i++) {
176  s->hlowsize[p][i] = (s->hlowsize[p][i - 1] + 1) >> 1;
177  s->hhighsize[p][i] = s->hlowsize[p][i - 1] >> 1;
178  s->vlowsize[p][i] = (s->vlowsize[p][i - 1] + 1) >> 1;
179  s->vhighsize[p][i] = s->vlowsize[p][i - 1] >> 1;
180  }
181  }
182 
183  return 0;
184 }
185 
186 static inline void copy(const float *p1, float *p2, const int length)
187 {
188  memcpy(p2, p1, length * sizeof(float));
189 }
190 
191 static inline void copyv(const float *p1, const int stride1, float *p2, const int length)
192 {
193  int i;
194 
195  for (i = 0; i < length; i++) {
196  p2[i] = *p1;
197  p1 += stride1;
198  }
199 }
200 
201 static inline void copyh(const float *p1, float *p2, const int stride2, const int length)
202 {
203  int i;
204 
205  for (i = 0; i < length; i++) {
206  *p2 = p1[i];
207  p2 += stride2;
208  }
209 }
210 
211 // Do symmetric extension of data using prescribed symmetries
212 // Original values are in output[npad] through output[npad+size-1]
213 // New values will be placed in output[0] through output[npad] and in output[npad+size] through output[2*npad+size-1] (note: end values may not be filled in)
214 // extension at left bdry is ... 3 2 1 0 | 0 1 2 3 ...
215 // same for right boundary
216 // if right_ext=1 then ... 3 2 1 0 | 1 2 3
217 static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
218 {
219  int first = NPAD;
220  int last = NPAD - 1 + size;
221  const int originalLast = last;
222  int i, nextend, idx;
223 
224  if (left_ext == 2)
225  output[--first] = output[NPAD];
226  if (right_ext == 2)
227  output[++last] = output[originalLast];
228 
229  // extend left end
230  nextend = first;
231  for (i = 0; i < nextend; i++)
232  output[--first] = output[NPAD + 1 + i];
233 
234  idx = NPAD + NPAD - 1 + size;
235 
236  // extend right end
237  nextend = idx - last;
238  for (i = 0; i < nextend; i++)
239  output[++last] = output[originalLast - 1 - i];
240 }
241 
242 static void transform_step(float *input, float *output, const int size, const int low_size, VagueDenoiserContext *s)
243 {
244  int i;
245 
247 
248  for (i = NPAD; i < NPAD + low_size; i++) {
249  const float a = input[2 * i - 14] * analysis_low[0];
250  const float b = input[2 * i - 13] * analysis_low[1];
251  const float c = input[2 * i - 12] * analysis_low[2];
252  const float d = input[2 * i - 11] * analysis_low[3];
253  const float e = input[2 * i - 10] * analysis_low[4];
254  const float f = input[2 * i - 9] * analysis_low[3];
255  const float g = input[2 * i - 8] * analysis_low[2];
256  const float h = input[2 * i - 7] * analysis_low[1];
257  const float k = input[2 * i - 6] * analysis_low[0];
258 
259  output[i] = a + b + c + d + e + f + g + h + k;
260  }
261 
262  for (i = NPAD; i < NPAD + low_size; i++) {
263  const float a = input[2 * i - 12] * analysis_high[0];
264  const float b = input[2 * i - 11] * analysis_high[1];
265  const float c = input[2 * i - 10] * analysis_high[2];
266  const float d = input[2 * i - 9] * analysis_high[3];
267  const float e = input[2 * i - 8] * analysis_high[2];
268  const float f = input[2 * i - 7] * analysis_high[1];
269  const float g = input[2 * i - 6] * analysis_high[0];
270 
271  output[i + low_size] = a + b + c + d + e + f + g;
272  }
273 }
274 
275 static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
276 {
277  const int low_size = (size + 1) >> 1;
278  const int high_size = size >> 1;
279  int left_ext = 1, right_ext, i;
280  int findex;
281 
282  memcpy(temp + NPAD, input + NPAD, low_size * sizeof(float));
283 
284  right_ext = (size % 2 == 0) ? 2 : 1;
285  symmetric_extension(temp, low_size, left_ext, right_ext);
286 
287  memset(output, 0, (NPAD + NPAD + size) * sizeof(float));
288  findex = (size + 2) >> 1;
289 
290  for (i = 9; i < findex + 11; i++) {
291  const float a = temp[i] * synthesis_low[0];
292  const float b = temp[i] * synthesis_low[1];
293  const float c = temp[i] * synthesis_low[2];
294  const float d = temp[i] * synthesis_low[3];
295 
296  output[2 * i - 13] += a;
297  output[2 * i - 12] += b;
298  output[2 * i - 11] += c;
299  output[2 * i - 10] += d;
300  output[2 * i - 9] += c;
301  output[2 * i - 8] += b;
302  output[2 * i - 7] += a;
303  }
304 
305  memcpy(temp + NPAD, input + NPAD + low_size, high_size * sizeof(float));
306 
307  left_ext = 2;
308  right_ext = (size % 2 == 0) ? 1 : 2;
309  symmetric_extension(temp, high_size, left_ext, right_ext);
310 
311  for (i = 8; i < findex + 11; i++) {
312  const float a = temp[i] * synthesis_high[0];
313  const float b = temp[i] * synthesis_high[1];
314  const float c = temp[i] * synthesis_high[2];
315  const float d = temp[i] * synthesis_high[3];
316  const float e = temp[i] * synthesis_high[4];
317 
318  output[2 * i - 13] += a;
319  output[2 * i - 12] += b;
320  output[2 * i - 11] += c;
321  output[2 * i - 10] += d;
322  output[2 * i - 9] += e;
323  output[2 * i - 8] += d;
324  output[2 * i - 7] += c;
325  output[2 * i - 6] += b;
326  output[2 * i - 5] += a;
327  }
328 }
329 
330 static void hard_thresholding(float *block, const int width, const int height,
331  const int stride, const float threshold,
332  const float percent)
333 {
334  const float frac = 1.f - percent * 0.01f;
335  int y, x;
336 
337  for (y = 0; y < height; y++) {
338  for (x = 0; x < width; x++) {
339  if (FFABS(block[x]) <= threshold)
340  block[x] *= frac;
341  }
342  block += stride;
343  }
344 }
345 
346 static void soft_thresholding(float *block, const int width, const int height, const int stride,
347  const float threshold, const float percent)
348 {
349  const float frac = 1.f - percent * 0.01f;
350  const float shift = threshold * 0.01f * percent;
351  int y, x;
352 
353  for (y = 0; y < height; y++) {
354  for (x = 0; x < width; x++) {
355  const float temp = FFABS(block[x]);
356  if (temp <= threshold)
357  block[x] *= frac;
358  else
359  block[x] = (block[x] < 0.f ? -1.f : (block[x] > 0.f ? 1.f : 0.f)) * (temp - shift);
360  }
361  block += stride;
362  }
363 }
364 
365 static void qian_thresholding(float *block, const int width, const int height,
366  const int stride, const float threshold,
367  const float percent)
368 {
369  const float percent01 = percent * 0.01f;
370  const float tr2 = threshold * threshold * percent01;
371  const float frac = 1.f - percent01;
372  int y, x;
373 
374  for (y = 0; y < height; y++) {
375  for (x = 0; x < width; x++) {
376  const float temp = FFABS(block[x]);
377  if (temp <= threshold) {
378  block[x] *= frac;
379  } else {
380  const float tp2 = temp * temp;
381  block[x] *= (tp2 - tr2) / tp2;
382  }
383  }
384  block += stride;
385  }
386 }
387 
388 static float bayes_threshold(float *block, const int width, const int height,
389  const int stride, const float threshold)
390 {
391  float mean = 0.f;
392 
393  for (int y = 0; y < height; y++) {
394  for (int x = 0; x < width; x++) {
395  mean += block[x] * block[x];
396  }
397  block += stride;
398  }
399 
400  mean /= width * height;
401 
402  return threshold * threshold / (FFMAX(sqrtf(mean - threshold), FLT_EPSILON));
403 }
404 
406 {
407  int p, y, x, i, j;
408 
409  for (p = 0; p < s->nb_planes; p++) {
410  const int height = s->planeheight[p];
411  const int width = s->planewidth[p];
412  const uint8_t *srcp8 = in->data[p];
413  const uint16_t *srcp16 = (const uint16_t *)in->data[p];
414  uint8_t *dstp8 = out->data[p];
415  uint16_t *dstp16 = (uint16_t *)out->data[p];
416  float *output = s->block;
417  int h_low_size0 = width;
418  int v_low_size0 = height;
419  int nsteps_transform = s->nsteps;
420  int nsteps_invert = s->nsteps;
421  const float *input = s->block;
422 
423  if (!((1 << p) & s->planes)) {
424  av_image_copy_plane(out->data[p], out->linesize[p], in->data[p], in->linesize[p],
425  s->planewidth[p] * s->bpc, s->planeheight[p]);
426  continue;
427  }
428 
429  if (s->depth <= 8) {
430  for (y = 0; y < height; y++) {
431  for (x = 0; x < width; x++)
432  output[x] = srcp8[x];
433  srcp8 += in->linesize[p];
434  output += width;
435  }
436  } else {
437  for (y = 0; y < height; y++) {
438  for (x = 0; x < width; x++)
439  output[x] = srcp16[x];
440  srcp16 += in->linesize[p] / 2;
441  output += width;
442  }
443  }
444 
445  while (nsteps_transform--) {
446  int low_size = (h_low_size0 + 1) >> 1;
447  float *input = s->block;
448  for (j = 0; j < v_low_size0; j++) {
449  copy(input, s->in + NPAD, h_low_size0);
450  transform_step(s->in, s->out, h_low_size0, low_size, s);
451  copy(s->out + NPAD, input, h_low_size0);
452  input += width;
453  }
454 
455  low_size = (v_low_size0 + 1) >> 1;
456  input = s->block;
457  for (j = 0; j < h_low_size0; j++) {
458  copyv(input, width, s->in + NPAD, v_low_size0);
459  transform_step(s->in, s->out, v_low_size0, low_size, s);
460  copyh(s->out + NPAD, input, width, v_low_size0);
461  input++;
462  }
463 
464  h_low_size0 = (h_low_size0 + 1) >> 1;
465  v_low_size0 = (v_low_size0 + 1) >> 1;
466  }
467 
468  if (s->type == 0) {
469  s->thresholding(s->block, width, height, width, s->threshold, s->percent);
470  } else {
471  for (int n = 0; n < s->nsteps; n++) {
472  float threshold;
473  float *block;
474 
475  if (n == s->nsteps - 1) {
476  threshold = bayes_threshold(s->block, s->hlowsize[p][n], s->vlowsize[p][n], width, s->threshold);
477  s->thresholding(s->block, s->hlowsize[p][n], s->vlowsize[p][n], width, threshold, s->percent);
478  }
479  block = s->block + s->hlowsize[p][n];
480  threshold = bayes_threshold(block, s->hhighsize[p][n], s->vlowsize[p][n], width, s->threshold);
481  s->thresholding(block, s->hhighsize[p][n], s->vlowsize[p][n], width, threshold, s->percent);
482  block = s->block + s->vlowsize[p][n] * width;
483  threshold = bayes_threshold(block, s->hlowsize[p][n], s->vhighsize[p][n], width, s->threshold);
484  s->thresholding(block, s->hlowsize[p][n], s->vhighsize[p][n], width, threshold, s->percent);
485  block = s->block + s->hlowsize[p][n] + s->vlowsize[p][n] * width;
486  threshold = bayes_threshold(block, s->hhighsize[p][n], s->vhighsize[p][n], width, s->threshold);
487  s->thresholding(block, s->hhighsize[p][n], s->vhighsize[p][n], width, threshold, s->percent);
488  }
489  }
490 
491  while (nsteps_invert--) {
492  const int idx = s->vlowsize[p][nsteps_invert] + s->vhighsize[p][nsteps_invert];
493  const int idx2 = s->hlowsize[p][nsteps_invert] + s->hhighsize[p][nsteps_invert];
494  float * idx3 = s->block;
495  for (i = 0; i < idx2; i++) {
496  copyv(idx3, width, s->in + NPAD, idx);
497  invert_step(s->in, s->out, s->tmp, idx, s);
498  copyh(s->out + NPAD, idx3, width, idx);
499  idx3++;
500  }
501 
502  idx3 = s->block;
503  for (i = 0; i < idx; i++) {
504  copy(idx3, s->in + NPAD, idx2);
505  invert_step(s->in, s->out, s->tmp, idx2, s);
506  copy(s->out + NPAD, idx3, idx2);
507  idx3 += width;
508  }
509  }
510 
511  if (s->depth <= 8) {
512  for (y = 0; y < height; y++) {
513  for (x = 0; x < width; x++)
514  dstp8[x] = av_clip_uint8(input[x] + 0.5f);
515  input += width;
516  dstp8 += out->linesize[p];
517  }
518  } else {
519  for (y = 0; y < height; y++) {
520  for (x = 0; x < width; x++)
521  dstp16[x] = av_clip(input[x] + 0.5f, 0, s->peak);
522  input += width;
523  dstp16 += out->linesize[p] / 2;
524  }
525  }
526  }
527 }
528 
530 {
531  AVFilterContext *ctx = inlink->dst;
532  VagueDenoiserContext *s = ctx->priv;
533  AVFilterLink *outlink = ctx->outputs[0];
534  AVFrame *out;
535  int direct = av_frame_is_writable(in);
536 
537  if (direct) {
538  out = in;
539  } else {
540  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
541  if (!out) {
542  av_frame_free(&in);
543  return AVERROR(ENOMEM);
544  }
545 
547  }
548 
549  filter(s, in, out);
550 
551  if (!direct)
552  av_frame_free(&in);
553 
554  return ff_filter_frame(outlink, out);
555 }
556 
558 {
559  VagueDenoiserContext *s = ctx->priv;
560 
561  switch (s->method) {
562  case 0:
563  s->thresholding = hard_thresholding;
564  break;
565  case 1:
566  s->thresholding = soft_thresholding;
567  break;
568  case 2:
569  s->thresholding = qian_thresholding;
570  break;
571  }
572 
573  return 0;
574 }
575 
577 {
578  VagueDenoiserContext *s = ctx->priv;
579 
580  av_freep(&s->block);
581  av_freep(&s->in);
582  av_freep(&s->out);
583  av_freep(&s->tmp);
584 }
585 
587  {
588  .name = "default",
589  .type = AVMEDIA_TYPE_VIDEO,
590  .config_props = config_input,
591  .filter_frame = filter_frame,
592  },
593 };
594 
595 
597  .name = "vaguedenoiser",
598  .description = NULL_IF_CONFIG_SMALL("Apply a Wavelet based Denoiser."),
599  .priv_size = sizeof(VagueDenoiserContext),
600  .priv_class = &vaguedenoiser_class,
601  .init = init,
602  .uninit = uninit,
607 };
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:116
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:546
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:525
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
av_clip
#define av_clip
Definition: common.h:100
transform_step
static void transform_step(float *input, float *output, const int size, const int low_size, VagueDenoiserContext *s)
Definition: vf_vaguedenoiser.c:242
filter
static void filter(VagueDenoiserContext *s, AVFrame *in, AVFrame *out)
Definition: vf_vaguedenoiser.c:405
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: filters.h:242
out
FILE * out
Definition: movenc.c:55
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1062
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3170
copyv
static void copyv(const float *p1, const int stride1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:191
OFFSET
#define OFFSET(x)
Definition: vf_vaguedenoiser.c:66
output
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce output
Definition: filter_design.txt:225
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:162
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:538
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: filters.h:262
VagueDenoiserContext::in
float * in
Definition: vf_vaguedenoiser.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
pixdesc.h
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:545
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:540
AVOption
AVOption.
Definition: opt.h:429
b
#define b
Definition: input.c:41
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:502
float.h
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:106
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:205
video.h
copyh
static void copyh(const float *p1, float *p2, const int stride2, const int length)
Definition: vf_vaguedenoiser.c:201
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:541
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:482
symmetric_extension
static void symmetric_extension(float *output, const int size, const int left_ext, const int right_ext)
Definition: vf_vaguedenoiser.c:217
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:410
av_image_copy_plane
void av_image_copy_plane(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int bytewidth, int height)
Copy image plane from src to dst.
Definition: imgutils.c:374
VagueDenoiserContext::hhighsize
int hhighsize[4][32]
Definition: vf_vaguedenoiser.c:57
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:537
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:520
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:212
analysis_high
static const float analysis_high[7]
Definition: vf_vaguedenoiser.c:92
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:518
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:547
VagueDenoiserContext::depth
int depth
Definition: vf_vaguedenoiser.c:44
VagueDenoiserContext::peak
int peak
Definition: vf_vaguedenoiser.c:46
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:500
invert_step
static void invert_step(const float *input, float *output, float *temp, const int size, VagueDenoiserContext *s)
Definition: vf_vaguedenoiser.c:275
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
VagueDenoiserContext::nsteps
int nsteps
Definition: vf_vaguedenoiser.c:41
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:486
qian_thresholding
static void qian_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
Definition: vf_vaguedenoiser.c:365
AVFilterPad
A filter pad used for either input or output.
Definition: filters.h:38
VagueDenoiserContext::nb_planes
int nb_planes
Definition: vf_vaguedenoiser.c:47
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:505
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:283
first
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
Definition: rate_distortion.txt:12
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:514
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:37
VagueDenoiserContext::thresholding
void(* thresholding)(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
Definition: vf_vaguedenoiser.c:61
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:86
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:522
synthesis_low
static const float synthesis_low[7]
Definition: vf_vaguedenoiser.c:97
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:523
VagueDenoiserContext::percent
float percent
Definition: vf_vaguedenoiser.c:38
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:108
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:515
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
g
const char * g
Definition: vf_curves.c:128
filters.h
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:544
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:499
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:513
ctx
AVFormatContext * ctx
Definition: movenc.c:49
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:485
synthesis_high
static const float synthesis_high[9]
Definition: vf_vaguedenoiser.c:102
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: filters.h:263
VagueDenoiserContext::tmp
float * tmp
Definition: vf_vaguedenoiser.c:54
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:87
bayes_threshold
static float bayes_threshold(float *block, const int width, const int height, const int stride, const float threshold)
Definition: vf_vaguedenoiser.c:388
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:74
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:483
VagueDenoiserContext
Definition: vf_vaguedenoiser.c:34
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:521
planes
static const struct @465 planes[]
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:75
NULL
#define NULL
Definition: coverity.c:32
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_vaguedenoiser.c:529
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:713
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:85
hard_thresholding
static void hard_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
Definition: vf_vaguedenoiser.c:330
AV_PIX_FMT_YUV440P10
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:504
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
vaguedenoiser_inputs
static const AVFilterPad vaguedenoiser_inputs[]
Definition: vf_vaguedenoiser.c:586
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:503
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:517
VagueDenoiserContext::threshold
float threshold
Definition: vf_vaguedenoiser.c:37
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
FLAGS
#define FLAGS
Definition: vf_vaguedenoiser.c:67
VagueDenoiserContext::hlowsize
int hlowsize[4][32]
Definition: vf_vaguedenoiser.c:56
f
f
Definition: af_crystalizer.c:122
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_vaguedenoiser.c:557
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:94
copy
static void copy(const float *p1, float *p2, const int length)
Definition: vf_vaguedenoiser.c:186
height
#define height
Definition: dsp.h:85
shift
static int shift(int a, int b)
Definition: bonk.c:261
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(vaguedenoiser)
ff_vf_vaguedenoiser
const AVFilter ff_vf_vaguedenoiser
Definition: vf_vaguedenoiser.c:596
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:507
size
int size
Definition: twinvq_data.h:10344
VagueDenoiserContext::vlowsize
int vlowsize[4][32]
Definition: vf_vaguedenoiser.c:58
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:509
VagueDenoiserContext::block
float * block
Definition: vf_vaguedenoiser.c:51
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:649
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_vaguedenoiser.c:576
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_vaguedenoiser.c:133
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:174
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:542
attributes.h
VagueDenoiserContext::planewidth
int planewidth[4]
Definition: vf_vaguedenoiser.c:49
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
VagueDenoiserContext::vhighsize
int vhighsize[4][32]
Definition: vf_vaguedenoiser.c:59
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
Definition: avfilter.h:182
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Underlying C type is float.
Definition: opt.h:271
VagueDenoiserContext::method
int method
Definition: vf_vaguedenoiser.c:39
VagueDenoiserContext::type
int type
Definition: vf_vaguedenoiser.c:40
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:519
common.h
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:107
AVFilterPad::name
const char * name
Pad name.
Definition: filters.h:44
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:501
vaguedenoiser_options
static const AVOption vaguedenoiser_options[]
Definition: vf_vaguedenoiser.c:68
stride
#define stride
Definition: h264pred_template.c:537
AVFilter
Filter definition.
Definition: avfilter.h:201
VagueDenoiserContext::planeheight
int planeheight[4]
Definition: vf_vaguedenoiser.c:48
analysis_low
static const float analysis_low[9]
Definition: vf_vaguedenoiser.c:87
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:539
left_ext
static int left_ext(int wavelet_length, int levels, uint64_t sn)
Definition: af_afwtdn.c:508
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:506
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:511
soft_thresholding
static void soft_thresholding(float *block, const int width, const int height, const int stride, const float threshold, const float percent)
Definition: vf_vaguedenoiser.c:346
NPAD
#define NPAD
Definition: vf_vaguedenoiser.c:85
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:543
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
avfilter.h
temp
else temp
Definition: vf_mcdeint.c:263
mean
static float mean(const float *input, int size)
Definition: vf_nnedi.c:866
VagueDenoiserContext::planes
int planes
Definition: vf_vaguedenoiser.c:42
av_clip_uint8
#define av_clip_uint8
Definition: common.h:106
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:78
AVFilterContext
An instance of a filter.
Definition: avfilter.h:457
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:165
desc
const char * desc
Definition: libsvtav1.c:79
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:77
VagueDenoiserContext::out
float * out
Definition: vf_vaguedenoiser.c:53
mem.h
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:80
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:434
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:79
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:508
h
h
Definition: vp9dsp_template.c:2070
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:512
width
#define width
Definition: dsp.h:85
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:484
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition: opt.h:299
VagueDenoiserContext::bpc
int bpc
Definition: vf_vaguedenoiser.c:45
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:173
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:510
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_vaguedenoiser.c:107