FFmpeg  2.1.1
vf_noise.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2013 Paul B Mahol
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file
24  * noise generator
25  */
26 
27 #include "libavutil/opt.h"
28 #include "libavutil/imgutils.h"
29 #include "libavutil/lfg.h"
30 #include "libavutil/parseutils.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/x86/asm.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 #include "video.h"
37 
38 #define MAX_NOISE 5120
39 #define MAX_SHIFT 1024
40 #define MAX_RES (MAX_NOISE-MAX_SHIFT)
41 
42 #define NOISE_UNIFORM 1
43 #define NOISE_TEMPORAL 2
44 #define NOISE_AVERAGED 8
45 #define NOISE_PATTERN 16
46 
47 typedef struct {
48  int strength;
49  unsigned flags;
51  int seed;
52  int8_t *noise;
53  int8_t *prev_shift[MAX_RES][3];
54 } FilterParams;
55 
56 typedef struct {
57  const AVClass *class;
58  int nb_planes;
59  int bytewidth[4];
60  int height[4];
62  FilterParams param[4];
63  int rand_shift[MAX_RES];
65  void (*line_noise)(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift);
66  void (*line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, int8_t **shift);
67 } NoiseContext;
68 
69 typedef struct ThreadData {
70  AVFrame *in, *out;
71 } ThreadData;
72 
73 #define OFFSET(x) offsetof(NoiseContext, x)
74 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
75 
76 #define NOISE_PARAMS(name, x, param) \
77  {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS}, \
78  {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
79  {#name"s", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
80  {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
81  {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
82  {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"}, \
83  {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN}, 0, 0, FLAGS, #name"_flags"}, \
84  {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"}, \
85  {"u", "uniform noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM}, 0, 0, FLAGS, #name"_flags"},
86 
87 static const AVOption noise_options[] = {
88  NOISE_PARAMS(all, 0, all)
89  NOISE_PARAMS(c0, 0, param[0])
90  NOISE_PARAMS(c1, 1, param[1])
91  NOISE_PARAMS(c2, 2, param[2])
92  NOISE_PARAMS(c3, 3, param[3])
93  {NULL}
94 };
95 
97 
98 static const int8_t patt[4] = { -1, 0, 1, 0 };
99 
100 #define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
102 {
103  int8_t *noise = av_malloc(MAX_NOISE * sizeof(int8_t));
104  FilterParams *fp = &n->param[comp];
105  AVLFG *lfg = &n->param[comp].lfg;
106  int strength = fp->strength;
107  int flags = fp->flags;
108  int i, j;
109 
110  if (!noise)
111  return AVERROR(ENOMEM);
112 
113  av_lfg_init(&fp->lfg, fp->seed);
114 
115  for (i = 0, j = 0; i < MAX_NOISE; i++, j++) {
116  if (flags & NOISE_UNIFORM) {
117  if (flags & NOISE_AVERAGED) {
118  if (flags & NOISE_PATTERN) {
119  noise[i] = (RAND_N(strength) - strength / 2) / 6
120  + patt[j % 4] * strength * 0.25 / 3;
121  } else {
122  noise[i] = (RAND_N(strength) - strength / 2) / 3;
123  }
124  } else {
125  if (flags & NOISE_PATTERN) {
126  noise[i] = (RAND_N(strength) - strength / 2) / 2
127  + patt[j % 4] * strength * 0.25;
128  } else {
129  noise[i] = RAND_N(strength) - strength / 2;
130  }
131  }
132  } else {
133  double x1, x2, w, y1;
134  do {
135  x1 = 2.0 * av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
136  x2 = 2.0 * av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
137  w = x1 * x1 + x2 * x2;
138  } while (w >= 1.0);
139 
140  w = sqrt((-2.0 * log(w)) / w);
141  y1 = x1 * w;
142  y1 *= strength / sqrt(3.0);
143  if (flags & NOISE_PATTERN) {
144  y1 /= 2;
145  y1 += patt[j % 4] * strength * 0.35;
146  }
147  y1 = av_clipf(y1, -128, 127);
148  if (flags & NOISE_AVERAGED)
149  y1 /= 3.0;
150  noise[i] = (int)y1;
151  }
152  if (RAND_N(6) == 0)
153  j--;
154  }
155 
156  for (i = 0; i < MAX_RES; i++)
157  for (j = 0; j < 3; j++)
158  fp->prev_shift[i][j] = noise + (av_lfg_get(lfg) & (MAX_SHIFT - 1));
159 
160  if (!n->rand_shift_init) {
161  for (i = 0; i < MAX_RES; i++)
162  n->rand_shift[i] = av_lfg_get(lfg) & (MAX_SHIFT - 1);
163  n->rand_shift_init = 1;
164  }
165 
166  fp->noise = noise;
167  return 0;
168 }
169 
171 {
172  AVFilterFormats *formats = NULL;
173  int fmt;
174 
175  for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
176  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
177  if (desc->flags & AV_PIX_FMT_FLAG_PLANAR && !((desc->comp[0].depth_minus1 + 1) & 7))
178  ff_add_format(&formats, fmt);
179  }
180 
181  ff_set_common_formats(ctx, formats);
182  return 0;
183 }
184 
185 static int config_input(AVFilterLink *inlink)
186 {
187  NoiseContext *n = inlink->dst->priv;
188  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
189  int ret;
190 
192 
193  if ((ret = av_image_fill_linesizes(n->bytewidth, inlink->format, inlink->w)) < 0)
194  return ret;
195 
196  n->height[1] = n->height[2] = FF_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
197  n->height[0] = n->height[3] = inlink->h;
198 
199  return 0;
200 }
201 
202 static inline void line_noise_c(uint8_t *dst, const uint8_t *src, int8_t *noise,
203  int len, int shift)
204 {
205  int i;
206 
207  noise += shift;
208  for (i = 0; i < len; i++) {
209  int v = src[i] + noise[i];
210 
211  dst[i] = av_clip_uint8(v);
212  }
213 }
214 
215 #define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t"
216 
217 static void line_noise_mmx(uint8_t *dst, const uint8_t *src,
218  int8_t *noise, int len, int shift)
219 {
220 #if HAVE_MMX_INLINE
221  x86_reg mmx_len= len&(~7);
222  noise+=shift;
223 
224  __asm__ volatile(
225  "mov %3, %%"REG_a" \n\t"
226  "pcmpeqb %%mm7, %%mm7 \n\t"
227  "psllw $15, %%mm7 \n\t"
228  "packsswb %%mm7, %%mm7 \n\t"
229  ASMALIGN(4)
230  "1: \n\t"
231  "movq (%0, %%"REG_a"), %%mm0 \n\t"
232  "movq (%1, %%"REG_a"), %%mm1 \n\t"
233  "pxor %%mm7, %%mm0 \n\t"
234  "paddsb %%mm1, %%mm0 \n\t"
235  "pxor %%mm7, %%mm0 \n\t"
236  "movq %%mm0, (%2, %%"REG_a") \n\t"
237  "add $8, %%"REG_a" \n\t"
238  " js 1b \n\t"
239  :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
240  : "%"REG_a
241  );
242  if (mmx_len!=len)
243  line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
244 #endif
245 }
246 
247 static void line_noise_mmxext(uint8_t *dst, const uint8_t *src,
248  int8_t *noise, int len, int shift)
249 {
250 #if HAVE_MMXEXT_INLINE
251  x86_reg mmx_len= len&(~7);
252  noise+=shift;
253 
254  __asm__ volatile(
255  "mov %3, %%"REG_a" \n\t"
256  "pcmpeqb %%mm7, %%mm7 \n\t"
257  "psllw $15, %%mm7 \n\t"
258  "packsswb %%mm7, %%mm7 \n\t"
259  ASMALIGN(4)
260  "1: \n\t"
261  "movq (%0, %%"REG_a"), %%mm0 \n\t"
262  "movq (%1, %%"REG_a"), %%mm1 \n\t"
263  "pxor %%mm7, %%mm0 \n\t"
264  "paddsb %%mm1, %%mm0 \n\t"
265  "pxor %%mm7, %%mm0 \n\t"
266  "movntq %%mm0, (%2, %%"REG_a") \n\t"
267  "add $8, %%"REG_a" \n\t"
268  " js 1b \n\t"
269  :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len)
270  : "%"REG_a
271  );
272  if (mmx_len != len)
273  line_noise_c(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0);
274 #endif
275 }
276 
277 static inline void line_noise_avg_c(uint8_t *dst, const uint8_t *src,
278  int len, int8_t **shift)
279 {
280  int i;
281  int8_t *src2 = (int8_t*)src;
282 
283  for (i = 0; i < len; i++) {
284  const int n = shift[0][i] + shift[1][i] + shift[2][i];
285  dst[i] = src2[i] + ((n * src2[i]) >> 7);
286  }
287 }
288 
289 static inline void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src,
290  int len, int8_t **shift)
291 {
292 #if HAVE_MMX_INLINE
293  x86_reg mmx_len= len&(~7);
294 
295  __asm__ volatile(
296  "mov %5, %%"REG_a" \n\t"
297  ASMALIGN(4)
298  "1: \n\t"
299  "movq (%1, %%"REG_a"), %%mm1 \n\t"
300  "movq (%0, %%"REG_a"), %%mm0 \n\t"
301  "paddb (%2, %%"REG_a"), %%mm1 \n\t"
302  "paddb (%3, %%"REG_a"), %%mm1 \n\t"
303  "movq %%mm0, %%mm2 \n\t"
304  "movq %%mm1, %%mm3 \n\t"
305  "punpcklbw %%mm0, %%mm0 \n\t"
306  "punpckhbw %%mm2, %%mm2 \n\t"
307  "punpcklbw %%mm1, %%mm1 \n\t"
308  "punpckhbw %%mm3, %%mm3 \n\t"
309  "pmulhw %%mm0, %%mm1 \n\t"
310  "pmulhw %%mm2, %%mm3 \n\t"
311  "paddw %%mm1, %%mm1 \n\t"
312  "paddw %%mm3, %%mm3 \n\t"
313  "paddw %%mm0, %%mm1 \n\t"
314  "paddw %%mm2, %%mm3 \n\t"
315  "psrlw $8, %%mm1 \n\t"
316  "psrlw $8, %%mm3 \n\t"
317  "packuswb %%mm3, %%mm1 \n\t"
318  "movq %%mm1, (%4, %%"REG_a") \n\t"
319  "add $8, %%"REG_a" \n\t"
320  " js 1b \n\t"
321  :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len),
322  "r" (dst+mmx_len), "g" (-mmx_len)
323  : "%"REG_a
324  );
325 
326  if (mmx_len != len){
327  int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len};
328  line_noise_avg_c(dst+mmx_len, src+mmx_len, len-mmx_len, shift2);
329  }
330 #endif
331 }
332 
333 static void noise(uint8_t *dst, const uint8_t *src,
334  int dst_linesize, int src_linesize,
335  int width, int start, int end, NoiseContext *n, int comp)
336 {
337  FilterParams *p = &n->param[comp];
338  int8_t *noise = p->noise;
339  const int flags = p->flags;
340  AVLFG *lfg = &p->lfg;
341  int shift, y;
342 
343  if (!noise) {
344  if (dst != src)
345  av_image_copy_plane(dst, dst_linesize, src, src_linesize, width, end - start);
346  return;
347  }
348 
349  for (y = start; y < end; y++) {
350  const int ix = y & (MAX_RES - 1);
351  if (flags & NOISE_TEMPORAL)
352  shift = av_lfg_get(lfg) & (MAX_SHIFT - 1);
353  else
354  shift = n->rand_shift[ix];
355 
356  if (flags & NOISE_AVERAGED) {
357  n->line_noise_avg(dst, src, width, p->prev_shift[ix]);
358  p->prev_shift[ix][shift & 3] = noise + shift;
359  } else {
360  n->line_noise(dst, src, noise, width, shift);
361  }
362  dst += dst_linesize;
363  src += src_linesize;
364  }
365 }
366 
367 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
368 {
369  NoiseContext *s = ctx->priv;
370  ThreadData *td = arg;
371  int plane;
372 
373  for (plane = 0; plane < s->nb_planes; plane++) {
374  const int height = s->height[plane];
375  const int start = (height * jobnr ) / nb_jobs;
376  const int end = (height * (jobnr+1)) / nb_jobs;
377  noise(td->out->data[plane] + start * td->out->linesize[plane],
378  td->in->data[plane] + start * td->in->linesize[plane],
379  td->out->linesize[plane], td->in->linesize[plane],
380  s->bytewidth[plane], start, end, s, plane);
381  }
382  return 0;
383 }
384 
385 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
386 {
387  AVFilterContext *ctx = inlink->dst;
388  AVFilterLink *outlink = ctx->outputs[0];
389  NoiseContext *n = ctx->priv;
390  ThreadData td;
391  AVFrame *out;
392 
393  if (av_frame_is_writable(inpicref)) {
394  out = inpicref;
395  } else {
396  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
397  if (!out) {
398  av_frame_free(&inpicref);
399  return AVERROR(ENOMEM);
400  }
401  av_frame_copy_props(out, inpicref);
402  }
403 
404  td.in = inpicref; td.out = out;
405  ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN(n->height[0], ctx->graph->nb_threads));
406  emms_c();
407 
408  if (inpicref != out)
409  av_frame_free(&inpicref);
410  return ff_filter_frame(outlink, out);
411 }
412 
413 static av_cold int init(AVFilterContext *ctx)
414 {
415  NoiseContext *n = ctx->priv;
416  int ret, i;
417  int cpu_flags = av_get_cpu_flags();
418 
419  for (i = 0; i < 4; i++) {
420  if (n->all.seed >= 0)
421  n->param[i].seed = n->all.seed;
422  else
423  n->param[i].seed = 123457;
424  if (n->all.strength)
425  n->param[i].strength = n->all.strength;
426  if (n->all.flags)
427  n->param[i].flags = n->all.flags;
428  }
429 
430  for (i = 0; i < 4; i++) {
431  if (n->param[i].strength && ((ret = init_noise(n, i)) < 0))
432  return ret;
433  }
434 
437 
438  if (HAVE_MMX_INLINE &&
439  cpu_flags & AV_CPU_FLAG_MMX) {
442  }
443  if (HAVE_MMXEXT_INLINE &&
444  cpu_flags & AV_CPU_FLAG_MMXEXT)
446 
447  return 0;
448 }
449 
450 static av_cold void uninit(AVFilterContext *ctx)
451 {
452  NoiseContext *n = ctx->priv;
453  int i;
454 
455  for (i = 0; i < 4; i++)
456  av_freep(&n->param[i].noise);
457 }
458 
459 static const AVFilterPad noise_inputs[] = {
460  {
461  .name = "default",
462  .type = AVMEDIA_TYPE_VIDEO,
463  .filter_frame = filter_frame,
464  .config_props = config_input,
465  },
466  { NULL }
467 };
468 
469 static const AVFilterPad noise_outputs[] = {
470  {
471  .name = "default",
472  .type = AVMEDIA_TYPE_VIDEO,
473  },
474  { NULL }
475 };
476 
478  .name = "noise",
479  .description = NULL_IF_CONFIG_SMALL("Add noise."),
480  .priv_size = sizeof(NoiseContext),
481  .init = init,
482  .uninit = uninit,
484  .inputs = noise_inputs,
485  .outputs = noise_outputs,
486  .priv_class = &noise_class,
488 };
Definition: lfg.h:25
float v
static const AVFilterPad noise_inputs[]
Definition: vf_noise.c:459
const char * s
Definition: avisynth_c.h:668
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
AVFrame * out
Definition: vf_hflip.c:79
static int shift(int a, int b)
Definition: sonic.c:78
FilterParams param[4]
Definition: vf_noise.c:62
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1979
#define NOISE_PATTERN
Definition: vf_noise.c:45
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
#define c2
Definition: idct_sh4.c:27
AVOption.
Definition: opt.h:253
int height[4]
Definition: vf_noise.c:60
const char * name
Filter name.
Definition: avfilter.h:468
const char * fmt
Definition: avisynth_c.h:669
int nb_planes
Definition: vf_noise.c:58
void * priv
private data for use by the filter
Definition: avfilter.h:648
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:111
static int config_input(AVFilterLink *inlink)
Definition: vf_noise.c:185
static const AVOption noise_options[]
Definition: vf_noise.c:87
AVLFG lfg
Definition: vf_noise.c:50
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:88
#define MAX_RES
Definition: vf_noise.c:40
static int query_formats(AVFilterContext *ctx)
Definition: vf_noise.c:170
static enum AVSampleFormat formats[]
FilterParams all
Definition: vf_noise.c:61
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:109
void(* line_noise)(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:65
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
#define av_cold
Definition: avcodec.h:653
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic &quot;enable&quot; expression option that can be used to enable or disable a fil...
Definition: avfilter.h:445
const char * name
Pad name.
Definition: internal.h:66
static const AVFilterPad noise_outputs[]
Definition: vf_noise.c:469
#define NOISE_UNIFORM
Definition: vf_noise.c:42
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1118
AVFrame * in
Definition: vf_hflip.c:79
uint8_t
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
int strength
Definition: vf_noise.c:48
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:67
#define emms_c()
Definition: internal.h:49
static av_cold int init(AVFilterContext *ctx)
Definition: vf_noise.c:413
#define FF_CEIL_RSHIFT(a, b)
Definition: avcodec.h:916
static void noise(uint8_t *dst, const uint8_t *src, int dst_linesize, int src_linesize, int width, int start, int end, NoiseContext *n, int comp)
Definition: vf_noise.c:333
int nb_threads
Maximum number of threads used by filters in this graph.
Definition: avfilter.h:1194
static void line_noise_mmx(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:217
void ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
A helper for query_formats() which sets all links to the same list of formats.
Definition: formats.c:531
#define ASMALIGN(ZEROBITS)
Definition: vf_noise.c:215
#define NOISE_TEMPORAL
Definition: vf_noise.c:43
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:52
unsigned flags
Definition: vf_noise.c:49
A filter pad used for either input or output.
Definition: internal.h:60
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:45
#define td
Definition: regdef.h:70
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:151
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:436
const char * arg
Definition: jacosubdec.c:69
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:330
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
#define NOISE_PARAMS(name, x, param)
Definition: vf_noise.c:76
static void line_noise_c(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:202
float y
ret
Definition: avfilter.c:961
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define FFMIN(a, b)
Definition: avcodec.h:925
#define NOISE_AVERAGED
Definition: vf_noise.c:44
int n
Definition: avisynth_c.h:588
int8_t * prev_shift[MAX_RES][3]
Definition: vf_noise.c:53
static int cpu_flags
Definition: dct-test.c:77
int8_t * noise
Definition: vf_noise.c:52
Main libavfilter public API header.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:642
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_noise.c:367
static int width
Definition: utils.c:158
static void line_noise_mmxext(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:247
int bytewidth[4]
Definition: vf_noise.c:59
AVS_Value src
Definition: avisynth_c.h:523
void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:30
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
typedef void(RENAME(mix_any_func_type))
uint8_t flags
Definition: pixdesc.h:78
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
static const int8_t patt[4]
Definition: vf_noise.c:98
#define fp
Definition: regdef.h:44
filter data
Definition: mlp.h:74
int rand_shift_init
Definition: vf_noise.c:64
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
Describe the class of an AVClass context structure.
Definition: log.h:50
Filter definition.
Definition: avfilter.h:464
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:86
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:110
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:102
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_noise.c:385
static void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src, int len, int8_t **shift)
Definition: vf_noise.c:289
static av_cold int init_noise(NoiseContext *n, int comp)
Definition: vf_noise.c:101
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: avcodec.h:4730
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:673
static int flags
Definition: cpu.c:45
AVFilter avfilter_vf_noise
Definition: vf_noise.c:477
static const int shift2[6]
Definition: dxa.c:50
int rand_shift[MAX_RES]
Definition: vf_noise.c:63
void(* line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, int8_t **shift)
Definition: vf_noise.c:66
#define MAX_SHIFT
Definition: vf_noise.c:39
struct AVFilterGraph * graph
filtergraph this filter belongs to
Definition: avfilter.h:650
avfilter_execute_func * execute
Definition: internal.h:153
static void line_noise_avg_c(uint8_t *dst, const uint8_t *src, int len, int8_t **shift)
Definition: vf_noise.c:277
int x86_reg
Definition: asm.h:70
#define MAX_NOISE
Definition: vf_noise.c:38
int len
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);ff_audio_convert_init_arm(ac);ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
#define AVFILTER_DEFINE_CLASS(fname)
Definition: internal.h:301
A list of supported formats for one end of a filter link.
Definition: formats.h:64
#define HAVE_MMX_INLINE
Definition: config.h:104
#define AVERROR(e)
An instance of a filter.
Definition: avfilter.h:627
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71
void INT64 start
Definition: avisynth_c.h:594
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:242
internal API functions
#define RAND_N(range)
Definition: vf_noise.c:100
#define c3
Definition: idct_sh4.c:28
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
#define c1
Definition: idct_sh4.c:26
#define HAVE_MMXEXT_INLINE
Definition: config.h:105
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_noise.c:450