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 General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * 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 4096
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;
50  int shiftptr;
52  int seed;
53  int8_t *noise;
54  int8_t *prev_shift[MAX_RES][3];
55 } FilterParams;
56 
57 typedef struct {
58  const AVClass *class;
59  int nb_planes;
60  int linesize[4];
61  int height[4];
63  FilterParams param[4];
64  int rand_shift[MAX_RES];
66  void (*line_noise)(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift);
67  void (*line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, int8_t **shift);
68 } NoiseContext;
69 
70 #define OFFSET(x) offsetof(NoiseContext, x)
71 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
72 
73 #define NOISE_PARAMS(name, x, param) \
74  {#name"_seed", "set component #"#x" noise seed", OFFSET(param.seed), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, FLAGS}, \
75  {#name"_strength", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
76  {#name"s", "set component #"#x" strength", OFFSET(param.strength), AV_OPT_TYPE_INT, {.i64=0}, 0, 100, FLAGS}, \
77  {#name"_flags", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
78  {#name"f", "set component #"#x" flags", OFFSET(param.flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 31, FLAGS, #name"_flags"}, \
79  {"a", "averaged noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_AVERAGED}, 0, 0, FLAGS, #name"_flags"}, \
80  {"p", "(semi)regular pattern", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_PATTERN}, 0, 0, FLAGS, #name"_flags"}, \
81  {"t", "temporal noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_TEMPORAL}, 0, 0, FLAGS, #name"_flags"}, \
82  {"u", "uniform noise", 0, AV_OPT_TYPE_CONST, {.i64=NOISE_UNIFORM}, 0, 0, FLAGS, #name"_flags"},
83 
84 static const AVOption noise_options[] = {
85  NOISE_PARAMS(all, 0, all)
86  NOISE_PARAMS(c0, 0, param[0])
87  NOISE_PARAMS(c1, 1, param[1])
88  NOISE_PARAMS(c2, 2, param[2])
89  NOISE_PARAMS(c3, 3, param[3])
90  {NULL}
91 };
92 
94 
95 static const int8_t patt[4] = { -1, 0, 1, 0 };
96 
97 #define RAND_N(range) ((int) ((double) range * av_lfg_get(lfg) / (UINT_MAX + 1.0)))
98 static int init_noise(NoiseContext *n, int comp)
99 {
100  int8_t *noise = av_malloc(MAX_NOISE * sizeof(int8_t));
101  FilterParams *fp = &n->param[comp];
102  AVLFG *lfg = &n->param[comp].lfg;
103  int strength = fp->strength;
104  int flags = fp->flags;
105  int i, j;
106 
107  if (!noise)
108  return AVERROR(ENOMEM);
109 
110  av_lfg_init(&fp->lfg, fp->seed);
111 
112  for (i = 0, j = 0; i < MAX_NOISE; i++, j++) {
113  if (flags & NOISE_UNIFORM) {
114  if (flags & NOISE_AVERAGED) {
115  if (flags & NOISE_PATTERN) {
116  noise[i] = (RAND_N(strength) - strength / 2) / 6
117  + patt[j % 4] * strength * 0.25 / 3;
118  } else {
119  noise[i] = (RAND_N(strength) - strength / 2) / 3;
120  }
121  } else {
122  if (flags & NOISE_PATTERN) {
123  noise[i] = (RAND_N(strength) - strength / 2) / 2
124  + patt[j % 4] * strength * 0.25;
125  } else {
126  noise[i] = RAND_N(strength) - strength / 2;
127  }
128  }
129  } else {
130  double x1, x2, w, y1;
131  do {
132  x1 = 2.0 * av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
133  x2 = 2.0 * av_lfg_get(lfg) / (float)UINT_MAX - 1.0;
134  w = x1 * x1 + x2 * x2;
135  } while (w >= 1.0);
136 
137  w = sqrt((-2.0 * log(w)) / w);
138  y1 = x1 * w;
139  y1 *= strength / sqrt(3.0);
140  if (flags & NOISE_PATTERN) {
141  y1 /= 2;
142  y1 += patt[j % 4] * strength * 0.35;
143  }
144  y1 = av_clipf(y1, -128, 127);
145  if (flags & NOISE_AVERAGED)
146  y1 /= 3.0;
147  noise[i] = (int)y1;
148  }
149  if (RAND_N(6) == 0)
150  j--;
151  }
152 
153  for (i = 0; i < MAX_RES; i++)
154  for (j = 0; j < 3; j++)
155  fp->prev_shift[i][j] = noise + (av_lfg_get(lfg) & (MAX_SHIFT - 1));
156 
157  if (!n->rand_shift_init) {
158  for (i = 0; i < MAX_RES; i++)
159  n->rand_shift[i] = av_lfg_get(lfg) & (MAX_SHIFT - 1);
160  n->rand_shift_init = 1;
161  }
162 
163  fp->noise = noise;
164  fp->shiftptr = 0;
165  return 0;
166 }
167 
169 {
171  int fmt;
172 
173  for (fmt = 0; fmt < AV_PIX_FMT_NB; fmt++) {
174  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
175  if (desc->flags & PIX_FMT_PLANAR && !((desc->comp[0].depth_minus1 + 1) & 7))
176  ff_add_format(&formats, fmt);
177  }
178 
179  ff_set_common_formats(ctx, formats);
180  return 0;
181 }
182 
183 static int config_input(AVFilterLink *inlink)
184 {
185  NoiseContext *n = inlink->dst->priv;
186  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
187  int i, ret;
188 
189  for (i = 0; i < desc->nb_components; i++)
190  n->nb_planes = FFMAX(n->nb_planes, desc->comp[i].plane);
191  n->nb_planes++;
192 
193  if ((ret = av_image_fill_linesizes(n->linesize, inlink->format, inlink->w)) < 0)
194  return ret;
195 
196  n->height[1] = n->height[2] = 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 height, NoiseContext *n, int comp)
336 {
337  int8_t *noise = n->param[comp].noise;
338  int flags = n->param[comp].flags;
339  AVLFG *lfg = &n->param[comp].lfg;
340  int shift, y;
341 
342  if (!noise) {
343  if (dst != src) {
344  for (y = 0; y < height; y++) {
345  memcpy(dst, src, width);
346  dst += dst_linesize;
347  src += src_linesize;
348  }
349  }
350 
351  return;
352  }
353 
354  for (y = 0; y < height; y++) {
355  if (flags & NOISE_TEMPORAL)
356  shift = av_lfg_get(lfg) & (MAX_SHIFT - 1);
357  else
358  shift = n->rand_shift[y];
359 
360  if (flags & NOISE_AVERAGED) {
361  n->line_noise_avg(dst, src, width, n->param[comp].prev_shift[y]);
362  n->param[comp].prev_shift[y][n->param[comp].shiftptr] = noise + shift;
363  } else {
364  n->line_noise(dst, src, noise, width, shift);
365  }
366  dst += dst_linesize;
367  src += src_linesize;
368  }
369 
370  n->param[comp].shiftptr++;
371  if (n->param[comp].shiftptr == 3)
372  n->param[comp].shiftptr = 0;
373 }
374 
375 static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
376 {
377  NoiseContext *n = inlink->dst->priv;
378  AVFilterLink *outlink = inlink->dst->outputs[0];
379  AVFrame *out;
380  int i;
381 
382  if (av_frame_is_writable(inpicref)) {
383  out = inpicref;
384  } else {
385  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
386  if (!out) {
387  av_frame_free(&inpicref);
388  return AVERROR(ENOMEM);
389  }
390  av_frame_copy_props(out, inpicref);
391  }
392 
393  for (i = 0; i < n->nb_planes; i++)
394  noise(out->data[i], inpicref->data[i], out->linesize[i],
395  inpicref->linesize[i], n->linesize[i], n->height[i], n, i);
396 
397  if (inpicref != out)
398  av_frame_free(&inpicref);
399  return ff_filter_frame(outlink, out);
400 }
401 
402 static av_cold int init(AVFilterContext *ctx)
403 {
404  NoiseContext *n = ctx->priv;
405  int ret, i;
406  int cpu_flags = av_get_cpu_flags();
407 
408  for (i = 0; i < 4; i++) {
409  if (n->all.seed >= 0)
410  n->param[i].seed = n->all.seed;
411  else
412  n->param[i].seed = 123457;
413  if (n->all.strength)
414  n->param[i].strength = n->all.strength;
415  if (n->all.flags)
416  n->param[i].flags = n->all.flags;
417  }
418 
419  for (i = 0; i < 4; i++) {
420  if (n->param[i].strength && ((ret = init_noise(n, i)) < 0))
421  return ret;
422  }
423 
424  if (HAVE_MMX_INLINE &&
425  cpu_flags & AV_CPU_FLAG_MMX) {
428  }
429  if (HAVE_MMXEXT_INLINE &&
430  cpu_flags & AV_CPU_FLAG_MMXEXT)
432 
433  return 0;
434 }
435 
436 static av_cold void uninit(AVFilterContext *ctx)
437 {
438  NoiseContext *n = ctx->priv;
439  int i;
440 
441  for (i = 0; i < 4; i++)
442  av_freep(&n->param[i].noise);
443 }
444 
445 static const AVFilterPad noise_inputs[] = {
446  {
447  .name = "default",
448  .type = AVMEDIA_TYPE_VIDEO,
449  .get_video_buffer = ff_null_get_video_buffer,
450  .filter_frame = filter_frame,
451  .config_props = config_input,
452  },
453  { NULL }
454 };
455 
456 static const AVFilterPad noise_outputs[] = {
457  {
458  .name = "default",
459  .type = AVMEDIA_TYPE_VIDEO,
460  },
461  { NULL }
462 };
463 
465  .name = "noise",
466  .description = NULL_IF_CONFIG_SMALL("Add noise."),
467  .priv_size = sizeof(NoiseContext),
468  .init = init,
469  .uninit = uninit,
471  .inputs = noise_inputs,
472  .outputs = noise_outputs,
473  .priv_class = &noise_class,
474 };
Definition: lfg.h:25
float v
static const AVFilterPad noise_inputs[]
Definition: vf_noise.c:445
static int shift(int a, int b)
Definition: sonic.c:86
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:424
FilterParams param[4]
Definition: vf_noise.c:63
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
#define NOISE_PATTERN
Definition: vf_noise.c:45
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
#define c2
Definition: idct_sh4.c:27
AVOption.
Definition: opt.h:251
int height[4]
Definition: vf_noise.c:61
const char * fmt
Definition: avisynth_c.h:669
int nb_planes
Definition: vf_noise.c:59
misc image utilities
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:117
external API header
static int config_input(AVFilterLink *inlink)
Definition: vf_noise.c:183
static int init_noise(NoiseContext *n, int comp)
Definition: vf_noise.c:98
static const AVOption noise_options[]
Definition: vf_noise.c:84
AVLFG lfg
Definition: vf_noise.c:51
y1
Definition: lab5.m:33
AVFrame * ff_null_get_video_buffer(AVFilterLink *link, int w, int h)
Definition: video.c:35
#define MAX_RES
Definition: vf_noise.c:40
x1
Definition: genspecsines3.m:7
static int query_formats(AVFilterContext *ctx)
Definition: vf_noise.c:168
FilterParams all
Definition: vf_noise.c:62
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:143
output residual component w
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
const char * name
Pad name.
static const AVFilterPad noise_outputs[]
Definition: vf_noise.c:456
#define NOISE_UNIFORM
Definition: vf_noise.c:42
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:86
uint8_t
it can be given away to ff_start_frame *A reference passed to ff_filter_frame(or the deprecated ff_start_frame) is given away and must no longer be used.*A reference created with avfilter_ref_buffer belongs to the code that created it.*A reference obtained with ff_get_video_buffer or ff_get_audio_buffer belongs to the code that requested it.*A reference given as return value by the get_video_buffer or get_audio_buffer method is given away and must no longer be used.Link reference fields---------------------The AVFilterLink structure has a few AVFilterBufferRef fields.The cur_buf and out_buf were used with the deprecated start_frame/draw_slice/end_frame API and should no longer be used.src_buf
#define av_cold
Definition: attributes.h:78
AVFILTER_DEFINE_CLASS(noise)
int shiftptr
Definition: vf_noise.c:50
AVOptions.
int strength
Definition: vf_noise.c:48
#define AV_CPU_FLAG_MMXEXT
SSE integer functions or AMD MMX ext.
Definition: cpu.h:30
static av_cold int init(AVFilterContext *ctx)
Definition: vf_noise.c:402
static void line_noise_mmx(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:217
integer sqrt
Definition: avutil.txt:2
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:545
#define ASMALIGN(ZEROBITS)
Definition: vf_noise.c:215
#define NOISE_TEMPORAL
Definition: vf_noise.c:43
unsigned flags
Definition: vf_noise.c:49
A filter pad used for either input or output.
uint16_t depth_minus1
number of bits in the component minus 1
Definition: pixdesc.h:43
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
void * priv
private data for use by the filter
Definition: avfilter.h:545
void(* line_noise)(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:66
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:361
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:344
#define FFMAX(a, b)
Definition: common.h:56
#define NOISE_PARAMS(name, x, param)
Definition: vf_noise.c:73
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:57
static void line_noise_c(uint8_t *dst, const uint8_t *src, int8_t *noise, int len, int shift)
Definition: vf_noise.c:202
ret
Definition: avfilter.c:821
#define NOISE_AVERAGED
Definition: vf_noise.c:44
int linesize[4]
Definition: vf_noise.c:60
int8_t * prev_shift[MAX_RES][3]
Definition: vf_noise.c:54
static int cpu_flags
Definition: dct-test.c:77
int8_t * noise
Definition: vf_noise.c:53
NULL
Definition: eval.c:55
static int width
Definition: tests/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
AVS_Value src
Definition: avisynth_c.h:523
typedef void(RENAME(mix_any_func_type))
#define PIX_FMT_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:93
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
#define AV_CPU_FLAG_MMX
standard MMX
Definition: cpu.h:29
static const int8_t patt[4]
Definition: vf_noise.c:95
#define fp
Definition: regdef.h:44
static unsigned int av_lfg_get(AVLFG *c)
Get the next random unsigned 32-bit number using an ALFG.
Definition: lfg.h:38
filter data
Definition: mlp.h:74
int rand_shift_init
Definition: vf_noise.c:65
BYTE int const BYTE int int int height
Definition: avisynth_c.h:713
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
Describe the class of an AVClass context structure.
Definition: log.h:50
x2
Definition: genspecsines3.m:8
Filter definition.
Definition: avfilter.h:436
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
synthesis window for stochastic i
static int filter_frame(AVFilterLink *inlink, AVFrame *inpicref)
Definition: vf_noise.c:375
static void line_noise_avg_mmx(uint8_t *dst, const uint8_t *src, int len, int8_t **shift)
Definition: vf_noise.c:289
const char * name
filter name
Definition: avfilter.h:437
av_cold void av_lfg_init(AVLFG *c, unsigned int seed)
Definition: lfg.c:30
int av_get_cpu_flags(void)
Return the flags which specify extensions supported by the CPU.
Definition: cpu.c:30
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer 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.Buffer references ownership and permissions
misc parsing utilities
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:539
static int flags
Definition: cpu.c:23
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
AVFilter avfilter_vf_noise
Definition: vf_noise.c:464
uint16_t plane
which of the 4 planes contains the component
Definition: pixdesc.h:29
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common formats
Definition: swscale.txt:33
static const int shift2[6]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
int rand_shift[MAX_RES]
Definition: vf_noise.c:64
#define MAX_SHIFT
Definition: vf_noise.c:39
function y
Definition: D.m:1
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
#define MAX_NOISE
Definition: vf_noise.c:38
int len
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
A list of supported formats for one end of a filter link.
Definition: formats.h:64
struct FilterParams FilterParams
filter data
#define HAVE_MMX_INLINE
Definition: config.h:98
An instance of a filter.
Definition: avfilter.h:524
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition: pixfmt.h:237
static void comp(unsigned char *dst, int dst_stride, unsigned char *src, int src_stride, int add)
Definition: eamad.c:71
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;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);return NULL;}return ac;}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;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> out
internal API functions
static void noise(uint8_t *dst, const uint8_t *src, int dst_linesize, int src_linesize, int width, int height, NoiseContext *n, int comp)
Definition: vf_noise.c:333
#define RAND_N(range)
Definition: vf_noise.c:97
#define c3
Definition: idct_sh4.c:28
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several inputs
void(* line_noise_avg)(uint8_t *dst, const uint8_t *src, int len, int8_t **shift)
Definition: vf_noise.c:67
#define c1
Definition: idct_sh4.c:26
#define HAVE_MMXEXT_INLINE
Definition: config.h:99
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_noise.c:436