FFmpeg
vf_nlmeans.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Clément Bœsch <u pkh me>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @todo
23  * - better automatic defaults? see "Parameters" @ http://www.ipol.im/pub/art/2011/bcm_nlm/
24  * - temporal support (probably doesn't need any displacement according to
25  * "Denoising image sequences does not require motion estimation")
26  * - Bayer pixel format support for at least raw photos? (DNG support would be
27  * handy here)
28  * - FATE test (probably needs visual threshold test mechanism due to the use
29  * of floats)
30  */
31 
32 #include "libavutil/avassert.h"
33 #include "libavutil/opt.h"
34 #include "libavutil/pixdesc.h"
35 #include "avfilter.h"
36 #include "formats.h"
37 #include "internal.h"
38 #include "vf_nlmeans.h"
39 #include "video.h"
40 
41 struct weighted_avg {
42  float total_weight;
43  float sum;
44 };
45 
46 typedef struct NLMeansContext {
47  const AVClass *class;
48  int nb_planes;
50  double pdiff_scale; // invert of the filtering parameter (sigma*10) squared
51  double sigma; // denoising strength
52  int patch_size, patch_hsize; // patch size and half size
53  int patch_size_uv, patch_hsize_uv; // patch size and half size for chroma planes
54  int research_size, research_hsize; // research size and half size
55  int research_size_uv, research_hsize_uv; // research size and half size for chroma planes
56  uint32_t *ii_orig; // integral image
57  uint32_t *ii; // integral image starting after the 0-line and 0-column
58  int ii_w, ii_h; // width and height of the integral image
59  ptrdiff_t ii_lz_32; // linesize in 32-bit units of the integral image
60  struct weighted_avg *wa; // weighted average of every pixel
61  ptrdiff_t wa_linesize; // linesize for wa in struct size unit
62  float *weight_lut; // lookup table mapping (scaled) patch differences to their associated weights
63  uint32_t max_meaningful_diff; // maximum difference considered (if the patch difference is too high we ignore the pixel)
66 
67 #define OFFSET(x) offsetof(NLMeansContext, x)
68 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
69 static const AVOption nlmeans_options[] = {
70  { "s", "denoising strength", OFFSET(sigma), AV_OPT_TYPE_DOUBLE, { .dbl = 1.0 }, 1.0, 30.0, FLAGS },
71  { "p", "patch size", OFFSET(patch_size), AV_OPT_TYPE_INT, { .i64 = 3*2+1 }, 0, 99, FLAGS },
72  { "pc", "patch size for chroma planes", OFFSET(patch_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
73  { "r", "research window", OFFSET(research_size), AV_OPT_TYPE_INT, { .i64 = 7*2+1 }, 0, 99, FLAGS },
74  { "rc", "research window for chroma planes", OFFSET(research_size_uv), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 99, FLAGS },
75  { NULL }
76 };
77 
78 AVFILTER_DEFINE_CLASS(nlmeans);
79 
80 static const enum AVPixelFormat pix_fmts[] = {
89 };
90 
91 /**
92  * Compute squared difference of the safe area (the zone where s1 and s2
93  * overlap). It is likely the largest integral zone, so it is interesting to do
94  * as little checks as possible; contrary to the unsafe version of this
95  * function, we do not need any clipping here.
96  *
97  * The line above dst and the column to its left are always readable.
98  */
99 static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t dst_linesize_32,
100  const uint8_t *s1, ptrdiff_t linesize1,
101  const uint8_t *s2, ptrdiff_t linesize2,
102  int w, int h)
103 {
104  int x, y;
105  const uint32_t *dst_top = dst - dst_linesize_32;
106 
107  /* SIMD-friendly assumptions allowed here */
108  av_assert2(!(w & 0xf) && w >= 16 && h >= 1);
109 
110  for (y = 0; y < h; y++) {
111  for (x = 0; x < w; x += 4) {
112  const int d0 = s1[x ] - s2[x ];
113  const int d1 = s1[x + 1] - s2[x + 1];
114  const int d2 = s1[x + 2] - s2[x + 2];
115  const int d3 = s1[x + 3] - s2[x + 3];
116 
117  dst[x ] = dst_top[x ] - dst_top[x - 1] + d0*d0;
118  dst[x + 1] = dst_top[x + 1] - dst_top[x ] + d1*d1;
119  dst[x + 2] = dst_top[x + 2] - dst_top[x + 1] + d2*d2;
120  dst[x + 3] = dst_top[x + 3] - dst_top[x + 2] + d3*d3;
121 
122  dst[x ] += dst[x - 1];
123  dst[x + 1] += dst[x ];
124  dst[x + 2] += dst[x + 1];
125  dst[x + 3] += dst[x + 2];
126  }
127  s1 += linesize1;
128  s2 += linesize2;
129  dst += dst_linesize_32;
130  dst_top += dst_linesize_32;
131  }
132 }
133 
134 /**
135  * Compute squared difference of an unsafe area (the zone nor s1 nor s2 could
136  * be readable).
137  *
138  * On the other hand, the line above dst and the column to its left are always
139  * readable.
140  *
141  * There is little point in having this function SIMDified as it is likely too
142  * complex and only handle small portions of the image.
143  *
144  * @param dst integral image
145  * @param dst_linesize_32 integral image linesize (in 32-bit integers unit)
146  * @param startx integral starting x position
147  * @param starty integral starting y position
148  * @param src source plane buffer
149  * @param linesize source plane linesize
150  * @param offx source offsetting in x
151  * @param offy source offsetting in y
152  * @paran r absolute maximum source offsetting
153  * @param sw source width
154  * @param sh source height
155  * @param w width to compute
156  * @param h height to compute
157  */
158 static inline void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t dst_linesize_32,
159  int startx, int starty,
160  const uint8_t *src, ptrdiff_t linesize,
161  int offx, int offy, int r, int sw, int sh,
162  int w, int h)
163 {
164  int x, y;
165 
166  for (y = starty; y < starty + h; y++) {
167  uint32_t acc = dst[y*dst_linesize_32 + startx - 1] - dst[(y-1)*dst_linesize_32 + startx - 1];
168  const int s1y = av_clip(y - r, 0, sh - 1);
169  const int s2y = av_clip(y - (r + offy), 0, sh - 1);
170 
171  for (x = startx; x < startx + w; x++) {
172  const int s1x = av_clip(x - r, 0, sw - 1);
173  const int s2x = av_clip(x - (r + offx), 0, sw - 1);
174  const uint8_t v1 = src[s1y*linesize + s1x];
175  const uint8_t v2 = src[s2y*linesize + s2x];
176  const int d = v1 - v2;
177  acc += d * d;
178  dst[y*dst_linesize_32 + x] = dst[(y-1)*dst_linesize_32 + x] + acc;
179  }
180  }
181 }
182 
183 /*
184  * Compute the sum of squared difference integral image
185  * http://www.ipol.im/pub/art/2014/57/
186  * Integral Images for Block Matching - Gabriele Facciolo, Nicolas Limare, Enric Meinhardt-Llopis
187  *
188  * @param ii integral image of dimension (w+e*2) x (h+e*2) with
189  * an additional zeroed top line and column already
190  * "applied" to the pointer value
191  * @param ii_linesize_32 integral image linesize (in 32-bit integers unit)
192  * @param src source plane buffer
193  * @param linesize source plane linesize
194  * @param offx x-offsetting ranging in [-e;e]
195  * @param offy y-offsetting ranging in [-e;e]
196  * @param w source width
197  * @param h source height
198  * @param e research padding edge
199  */
201  uint32_t *ii, ptrdiff_t ii_linesize_32,
202  const uint8_t *src, ptrdiff_t linesize, int offx, int offy,
203  int e, int w, int h)
204 {
205  // ii has a surrounding padding of thickness "e"
206  const int ii_w = w + e*2;
207  const int ii_h = h + e*2;
208 
209  // we center the first source
210  const int s1x = e;
211  const int s1y = e;
212 
213  // 2nd source is the frame with offsetting
214  const int s2x = e + offx;
215  const int s2y = e + offy;
216 
217  // get the dimension of the overlapping rectangle where it is always safe
218  // to compare the 2 sources pixels
219  const int startx_safe = FFMAX(s1x, s2x);
220  const int starty_safe = FFMAX(s1y, s2y);
221  const int u_endx_safe = FFMIN(s1x + w, s2x + w); // unaligned
222  const int endy_safe = FFMIN(s1y + h, s2y + h);
223 
224  // deduce the safe area width and height
225  const int safe_pw = (u_endx_safe - startx_safe) & ~0xf;
226  const int safe_ph = endy_safe - starty_safe;
227 
228  // adjusted end x position of the safe area after width of the safe area gets aligned
229  const int endx_safe = startx_safe + safe_pw;
230 
231  // top part where only one of s1 and s2 is still readable, or none at all
232  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
233  0, 0,
234  src, linesize,
235  offx, offy, e, w, h,
236  ii_w, starty_safe);
237 
238  // fill the left column integral required to compute the central
239  // overlapping one
240  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
241  0, starty_safe,
242  src, linesize,
243  offx, offy, e, w, h,
244  startx_safe, safe_ph);
245 
246  // main and safe part of the integral
247  av_assert1(startx_safe - s1x >= 0); av_assert1(startx_safe - s1x < w);
248  av_assert1(starty_safe - s1y >= 0); av_assert1(starty_safe - s1y < h);
249  av_assert1(startx_safe - s2x >= 0); av_assert1(startx_safe - s2x < w);
250  av_assert1(starty_safe - s2y >= 0); av_assert1(starty_safe - s2y < h);
251  if (safe_pw && safe_ph)
252  dsp->compute_safe_ssd_integral_image(ii + starty_safe*ii_linesize_32 + startx_safe, ii_linesize_32,
253  src + (starty_safe - s1y) * linesize + (startx_safe - s1x), linesize,
254  src + (starty_safe - s2y) * linesize + (startx_safe - s2x), linesize,
255  safe_pw, safe_ph);
256 
257  // right part of the integral
258  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
259  endx_safe, starty_safe,
260  src, linesize,
261  offx, offy, e, w, h,
262  ii_w - endx_safe, safe_ph);
263 
264  // bottom part where only one of s1 and s2 is still readable, or none at all
265  compute_unsafe_ssd_integral_image(ii, ii_linesize_32,
266  0, endy_safe,
267  src, linesize,
268  offx, offy, e, w, h,
269  ii_w, ii_h - endy_safe);
270 }
271 
273 {
274  AVFilterContext *ctx = inlink->dst;
275  NLMeansContext *s = ctx->priv;
277  const int e = FFMAX(s->research_hsize, s->research_hsize_uv)
278  + FFMAX(s->patch_hsize, s->patch_hsize_uv);
279 
280  s->chroma_w = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
281  s->chroma_h = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
282  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
283 
284  /* Allocate the integral image with extra edges of thickness "e"
285  *
286  * +_+-------------------------------+
287  * |0|0000000000000000000000000000000|
288  * +-x-------------------------------+
289  * |0|\ ^ |
290  * |0| ii | e |
291  * |0| v |
292  * |0| +-----------------------+ |
293  * |0| | | |
294  * |0|<->| | |
295  * |0| e | | |
296  * |0| | | |
297  * |0| +-----------------------+ |
298  * |0| |
299  * |0| |
300  * |0| |
301  * +-+-------------------------------+
302  */
303  s->ii_w = inlink->w + e*2;
304  s->ii_h = inlink->h + e*2;
305 
306  // align to 4 the linesize, "+1" is for the space of the left 0-column
307  s->ii_lz_32 = FFALIGN(s->ii_w + 1, 4);
308 
309  // "+1" is for the space of the top 0-line
310  s->ii_orig = av_calloc(s->ii_h + 1, s->ii_lz_32 * sizeof(*s->ii_orig));
311  if (!s->ii_orig)
312  return AVERROR(ENOMEM);
313 
314  // skip top 0-line and left 0-column
315  s->ii = s->ii_orig + s->ii_lz_32 + 1;
316 
317  // allocate weighted average for every pixel
318  s->wa_linesize = inlink->w;
319  s->wa = av_malloc_array(s->wa_linesize, inlink->h * sizeof(*s->wa));
320  if (!s->wa)
321  return AVERROR(ENOMEM);
322 
323  return 0;
324 }
325 
326 struct thread_data {
327  const uint8_t *src;
328  ptrdiff_t src_linesize;
330  int endx, endy;
331  const uint32_t *ii_start;
332  int p;
333 };
334 
335 static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
336 {
337  int x, y;
338  NLMeansContext *s = ctx->priv;
339  const struct thread_data *td = arg;
340  const ptrdiff_t src_linesize = td->src_linesize;
341  const int process_h = td->endy - td->starty;
342  const int slice_start = (process_h * jobnr ) / nb_jobs;
343  const int slice_end = (process_h * (jobnr+1)) / nb_jobs;
344  const int starty = td->starty + slice_start;
345  const int endy = td->starty + slice_end;
346  const int p = td->p;
347  const uint32_t *ii = td->ii_start + (starty - p - 1) * s->ii_lz_32 - p - 1;
348  const int dist_b = 2*p + 1;
349  const int dist_d = dist_b * s->ii_lz_32;
350  const int dist_e = dist_d + dist_b;
351 
352  for (y = starty; y < endy; y++) {
353  const uint8_t *src = td->src + y*src_linesize;
354  struct weighted_avg *wa = s->wa + y*s->wa_linesize;
355  for (x = td->startx; x < td->endx; x++) {
356  /*
357  * M is a discrete map where every entry contains the sum of all the entries
358  * in the rectangle from the top-left origin of M to its coordinate. In the
359  * following schema, "i" contains the sum of the whole map:
360  *
361  * M = +----------+-----------------+----+
362  * | | | |
363  * | | | |
364  * | a| b| c|
365  * +----------+-----------------+----+
366  * | | | |
367  * | | | |
368  * | | X | |
369  * | | | |
370  * | d| e| f|
371  * +----------+-----------------+----+
372  * | | | |
373  * | g| h| i|
374  * +----------+-----------------+----+
375  *
376  * The sum of the X box can be calculated with:
377  * X = e-d-b+a
378  *
379  * See https://en.wikipedia.org/wiki/Summed_area_table
380  *
381  * The compute*_ssd functions compute the integral image M where every entry
382  * contains the sum of the squared difference of every corresponding pixels of
383  * two input planes of the same size as M.
384  */
385  const uint32_t a = ii[x];
386  const uint32_t b = ii[x + dist_b];
387  const uint32_t d = ii[x + dist_d];
388  const uint32_t e = ii[x + dist_e];
389  const uint32_t patch_diff_sq = e - d - b + a;
390 
391  if (patch_diff_sq < s->max_meaningful_diff) {
392  const float weight = s->weight_lut[patch_diff_sq]; // exp(-patch_diff_sq * s->pdiff_scale)
393  wa[x].total_weight += weight;
394  wa[x].sum += weight * src[x];
395  }
396  }
397  ii += s->ii_lz_32;
398  }
399  return 0;
400 }
401 
402 static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize,
403  const uint8_t *src, ptrdiff_t src_linesize,
404  struct weighted_avg *wa, ptrdiff_t wa_linesize,
405  int w, int h)
406 {
407  int x, y;
408 
409  for (y = 0; y < h; y++) {
410  for (x = 0; x < w; x++) {
411  // Also weight the centered pixel
412  wa[x].total_weight += 1.f;
413  wa[x].sum += 1.f * src[x];
414  dst[x] = av_clip_uint8(wa[x].sum / wa[x].total_weight + 0.5f);
415  }
416  dst += dst_linesize;
417  src += src_linesize;
418  wa += wa_linesize;
419  }
420 }
421 
422 static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r,
423  uint8_t *dst, ptrdiff_t dst_linesize,
424  const uint8_t *src, ptrdiff_t src_linesize)
425 {
426  int offx, offy;
427  NLMeansContext *s = ctx->priv;
428  /* patches center points cover the whole research window so the patches
429  * themselves overflow the research window */
430  const int e = r + p;
431  /* focus an integral pointer on the centered image (s1) */
432  const uint32_t *centered_ii = s->ii + e*s->ii_lz_32 + e;
433 
434  memset(s->wa, 0, s->wa_linesize * h * sizeof(*s->wa));
435 
436  for (offy = -r; offy <= r; offy++) {
437  for (offx = -r; offx <= r; offx++) {
438  if (offx || offy) {
439  struct thread_data td = {
440  .src = src + offy*src_linesize + offx,
441  .src_linesize = src_linesize,
442  .startx = FFMAX(0, -offx),
443  .starty = FFMAX(0, -offy),
444  .endx = FFMIN(w, w - offx),
445  .endy = FFMIN(h, h - offy),
446  .ii_start = centered_ii + offy*s->ii_lz_32 + offx,
447  .p = p,
448  };
449 
450  compute_ssd_integral_image(&s->dsp, s->ii, s->ii_lz_32,
451  src, src_linesize,
452  offx, offy, e, w, h);
454  FFMIN(td.endy - td.starty, ff_filter_get_nb_threads(ctx)));
455  }
456  }
457  }
458 
459  weight_averages(dst, dst_linesize, src, src_linesize,
460  s->wa, s->wa_linesize, w, h);
461 
462  return 0;
463 }
464 
466 {
467  int i;
468  AVFilterContext *ctx = inlink->dst;
469  NLMeansContext *s = ctx->priv;
470  AVFilterLink *outlink = ctx->outputs[0];
471 
472  AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
473  if (!out) {
474  av_frame_free(&in);
475  return AVERROR(ENOMEM);
476  }
478 
479  for (i = 0; i < s->nb_planes; i++) {
480  const int w = i ? s->chroma_w : inlink->w;
481  const int h = i ? s->chroma_h : inlink->h;
482  const int p = i ? s->patch_hsize_uv : s->patch_hsize;
483  const int r = i ? s->research_hsize_uv : s->research_hsize;
484  nlmeans_plane(ctx, w, h, p, r,
485  out->data[i], out->linesize[i],
486  in->data[i], in->linesize[i]);
487  }
488 
489  av_frame_free(&in);
490  return ff_filter_frame(outlink, out);
491 }
492 
493 #define CHECK_ODD_FIELD(field, name) do { \
494  if (!(s->field & 1)) { \
495  s->field |= 1; \
496  av_log(ctx, AV_LOG_WARNING, name " size must be odd, " \
497  "setting it to %d\n", s->field); \
498  } \
499 } while (0)
500 
502 {
504 
505  if (ARCH_AARCH64)
507 }
508 
510 {
511  int i;
512  NLMeansContext *s = ctx->priv;
513  const double h = s->sigma * 10.;
514 
515  s->pdiff_scale = 1. / (h * h);
516  s->max_meaningful_diff = log(255.) / s->pdiff_scale;
517  s->weight_lut = av_calloc(s->max_meaningful_diff, sizeof(*s->weight_lut));
518  if (!s->weight_lut)
519  return AVERROR(ENOMEM);
520  for (i = 0; i < s->max_meaningful_diff; i++)
521  s->weight_lut[i] = exp(-i * s->pdiff_scale);
522 
523  CHECK_ODD_FIELD(research_size, "Luma research window");
524  CHECK_ODD_FIELD(patch_size, "Luma patch");
525 
526  if (!s->research_size_uv) s->research_size_uv = s->research_size;
527  if (!s->patch_size_uv) s->patch_size_uv = s->patch_size;
528 
529  CHECK_ODD_FIELD(research_size_uv, "Chroma research window");
530  CHECK_ODD_FIELD(patch_size_uv, "Chroma patch");
531 
532  s->research_hsize = s->research_size / 2;
533  s->research_hsize_uv = s->research_size_uv / 2;
534  s->patch_hsize = s->patch_size / 2;
535  s->patch_hsize_uv = s->patch_size_uv / 2;
536 
537  av_log(ctx, AV_LOG_INFO, "Research window: %dx%d / %dx%d, patch size: %dx%d / %dx%d\n",
538  s->research_size, s->research_size, s->research_size_uv, s->research_size_uv,
539  s->patch_size, s->patch_size, s->patch_size_uv, s->patch_size_uv);
540 
541  ff_nlmeans_init(&s->dsp);
542 
543  return 0;
544 }
545 
547 {
548  NLMeansContext *s = ctx->priv;
549  av_freep(&s->weight_lut);
550  av_freep(&s->ii_orig);
551  av_freep(&s->wa);
552 }
553 
554 static const AVFilterPad nlmeans_inputs[] = {
555  {
556  .name = "default",
557  .type = AVMEDIA_TYPE_VIDEO,
558  .config_props = config_input,
559  .filter_frame = filter_frame,
560  },
561 };
562 
563 static const AVFilterPad nlmeans_outputs[] = {
564  {
565  .name = "default",
566  .type = AVMEDIA_TYPE_VIDEO,
567  },
568 };
569 
571  .name = "nlmeans",
572  .description = NULL_IF_CONFIG_SMALL("Non-local means denoiser."),
573  .priv_size = sizeof(NLMeansContext),
574  .init = init,
575  .uninit = uninit,
579  .priv_class = &nlmeans_class,
581 };
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:98
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_nlmeans.c:80
av_clip
#define av_clip
Definition: common.h:96
NLMeansContext::weight_lut
float * weight_lut
Definition: vf_nlmeans.c:62
r
const char * r
Definition: vf_curves.c:116
acc
int acc
Definition: yuv2rgb.c:554
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
out
FILE * out
Definition: movenc.c:54
thread_data::src_linesize
ptrdiff_t src_linesize
Definition: vf_nlmeans.c:328
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1018
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2564
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:171
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:112
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
pixdesc.h
w
uint8_t w
Definition: llviddspenc.c:38
NLMeansContext::max_meaningful_diff
uint32_t max_meaningful_diff
Definition: vf_nlmeans.c:63
AVOption
AVOption.
Definition: opt.h:247
b
#define b
Definition: input.c:40
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:153
compute_safe_ssd_integral_image_c
static void compute_safe_ssd_integral_image_c(uint32_t *dst, ptrdiff_t dst_linesize_32, const uint8_t *s1, ptrdiff_t linesize1, const uint8_t *s2, ptrdiff_t linesize2, int w, int h)
Compute squared difference of the safe area (the zone where s1 and s2 overlap).
Definition: vf_nlmeans.c:99
video.h
CHECK_ODD_FIELD
#define CHECK_ODD_FIELD(field, name)
Definition: vf_nlmeans.c:493
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
formats.h
NLMeansContext::wa
struct weighted_avg * wa
Definition: vf_nlmeans.c:60
NLMeansContext::ii_w
int ii_w
Definition: vf_nlmeans.c:58
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2604
NLMeansDSPContext
Definition: vf_nlmeans.h:25
NLMeansContext::nb_planes
int nb_planes
Definition: vf_nlmeans.c:48
nlmeans_outputs
static const AVFilterPad nlmeans_outputs[]
Definition: vf_nlmeans.c:563
compute_ssd_integral_image
static void compute_ssd_integral_image(const NLMeansDSPContext *dsp, uint32_t *ii, ptrdiff_t ii_linesize_32, const uint8_t *src, ptrdiff_t linesize, int offx, int offy, int e, int w, int h)
Definition: vf_nlmeans.c:200
nlmeans_inputs
static const AVFilterPad nlmeans_inputs[]
Definition: vf_nlmeans.c:554
NLMeansDSPContext::compute_safe_ssd_integral_image
void(* compute_safe_ssd_integral_image)(uint32_t *dst, ptrdiff_t dst_linesize_32, const uint8_t *s1, ptrdiff_t linesize1, const uint8_t *s2, ptrdiff_t linesize2, int w, int h)
Definition: vf_nlmeans.h:26
NLMeansContext::wa_linesize
ptrdiff_t wa_linesize
Definition: vf_nlmeans.c:61
weight_averages
static void weight_averages(uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize, struct weighted_avg *wa, ptrdiff_t wa_linesize, int w, int h)
Definition: vf_nlmeans.c:402
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:50
thread_data::starty
int starty
Definition: vf_nlmeans.c:329
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:248
avassert.h
compute_unsafe_ssd_integral_image
static void compute_unsafe_ssd_integral_image(uint32_t *dst, ptrdiff_t dst_linesize_32, int startx, int starty, const uint8_t *src, ptrdiff_t linesize, int offx, int offy, int r, int sw, int sh, int w, int h)
Compute squared difference of an unsafe area (the zone nor s1 nor s2 could be readable).
Definition: vf_nlmeans.c:158
av_cold
#define av_cold
Definition: attributes.h:90
NLMeansContext::dsp
NLMeansDSPContext dsp
Definition: vf_nlmeans.c:64
thread_data
Definition: vf_lut.c:337
NLMeansContext::research_hsize_uv
int research_hsize_uv
Definition: vf_nlmeans.c:55
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:79
NLMeansContext::chroma_h
int chroma_h
Definition: vf_nlmeans.c:49
s
#define s(width, name)
Definition: cbs_vp9.c:257
NLMeansContext::research_hsize
int research_hsize
Definition: vf_nlmeans.c:54
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
AV_OPT_TYPE_DOUBLE
@ AV_OPT_TYPE_DOUBLE
Definition: opt.h:226
s1
#define s1
Definition: regdef.h:38
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2041
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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:66
f
#define f(width, name)
Definition: cbs_vp9.c:255
thread_data::src
const uint8_t * src
Definition: vf_nlmeans.c:327
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:191
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:80
arg
const char * arg
Definition: jacosubdec.c:67
thread_data::endx
int endx
Definition: vf_nlmeans.c:330
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
NULL
#define NULL
Definition: coverity.c:32
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:537
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:78
ff_vf_nlmeans
const AVFilter ff_vf_nlmeans
Definition: vf_nlmeans.c:570
src
#define src
Definition: vp8dsp.c:255
thread_data::startx
int startx
Definition: vf_nlmeans.c:329
NLMeansContext
Definition: vf_nlmeans.c:46
NLMeansContext::ii_lz_32
ptrdiff_t ii_lz_32
Definition: vf_nlmeans.c:59
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
FLAGS
#define FLAGS
Definition: vf_nlmeans.c:68
exp
int8_t exp
Definition: eval.c:72
weight
static int weight(int i, int blen, int offset)
Definition: diracdec.c:1561
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
s2
#define s2
Definition: regdef.h:39
uninit
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_nlmeans.c:546
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:117
vf_nlmeans.h
nlmeans_slice
static int nlmeans_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_nlmeans.c:335
NLMeansContext::pdiff_scale
double pdiff_scale
Definition: vf_nlmeans.c:50
weighted_avg::sum
float sum
Definition: vf_nlmeans.c:43
NLMeansContext::ii_orig
uint32_t * ii_orig
Definition: vf_nlmeans.c:56
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_nlmeans.c:272
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
thread_data::endy
int endy
Definition: vf_nlmeans.c:330
AV_LOG_INFO
#define AV_LOG_INFO
Standard information.
Definition: log.h:191
internal.h
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:130
NLMeansContext::ii_h
int ii_h
Definition: vf_nlmeans.c:58
av_assert2
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
Definition: avassert.h:64
NLMeansContext::patch_size
int patch_size
Definition: vf_nlmeans.c:52
NLMeansContext::ii
uint32_t * ii
Definition: vf_nlmeans.c:57
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:32
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:803
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:664
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:100
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:56
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:271
NLMeansContext::chroma_w
int chroma_w
Definition: vf_nlmeans.c:49
AVFilter
Filter definition.
Definition: avfilter.h:149
NLMeansContext::sigma
double sigma
Definition: vf_nlmeans.c:51
init
static av_cold int init(AVFilterContext *ctx)
Definition: vf_nlmeans.c:509
weighted_avg::total_weight
float total_weight
Definition: vf_nlmeans.c:42
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
avfilter.h
NLMeansContext::patch_hsize
int patch_hsize
Definition: vf_nlmeans.c:52
NLMeansContext::research_size
int research_size
Definition: vf_nlmeans.c:54
NLMeansContext::patch_hsize_uv
int patch_hsize_uv
Definition: vf_nlmeans.c:53
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
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:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:386
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(nlmeans)
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:121
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:70
NLMeansContext::research_size_uv
int research_size_uv
Definition: vf_nlmeans.c:55
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_nlmeans.c:465
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
nlmeans_plane
static int nlmeans_plane(AVFilterContext *ctx, int w, int h, int p, int r, uint8_t *dst, ptrdiff_t dst_linesize, const uint8_t *src, ptrdiff_t src_linesize)
Definition: vf_nlmeans.c:422
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ff_nlmeans_init
void ff_nlmeans_init(NLMeansDSPContext *dsp)
Definition: vf_nlmeans.c:501
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:192
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
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:73
thread_data::in
AVFrame * in
Definition: vf_lut.c:338
d
d
Definition: ffmpeg_filter.c:156
ff_nlmeans_init_aarch64
av_cold void ff_nlmeans_init_aarch64(NLMeansDSPContext *dsp)
Definition: vf_nlmeans_init.c:28
nlmeans_options
static const AVOption nlmeans_options[]
Definition: vf_nlmeans.c:69
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
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:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
h
h
Definition: vp9dsp_template.c:2038
OFFSET
#define OFFSET(x)
Definition: vf_nlmeans.c:67
weighted_avg
Definition: vf_nlmeans.c:41
thread_data::p
int p
Definition: vf_nlmeans.c:332
thread_data::ii_start
const uint32_t * ii_start
Definition: vf_nlmeans.c:331
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:143
NLMeansContext::patch_size_uv
int patch_size_uv
Definition: vf_nlmeans.c:53