FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vf_boxblur.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  * Copyright (c) 2011 Stefano Sabatini
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (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 Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 /**
23  * @file
24  * Apply a boxblur filter to the input video.
25  * Ported from MPlayer libmpcodecs/vf_boxblur.c.
26  */
27 
28 #include "libavutil/avstring.h"
29 #include "libavutil/common.h"
30 #include "libavutil/eval.h"
31 #include "libavutil/opt.h"
32 #include "libavutil/pixdesc.h"
33 #include "avfilter.h"
34 #include "formats.h"
35 #include "internal.h"
36 #include "video.h"
37 
38 static const char *const var_names[] = {
39  "w",
40  "h",
41  "cw",
42  "ch",
43  "hsub",
44  "vsub",
45  NULL
46 };
47 
48 enum var_name {
56 };
57 
58 typedef struct FilterParam {
59  int radius;
60  int power;
61  char *radius_expr;
62 } FilterParam;
63 
64 typedef struct BoxBlurContext {
65  const AVClass *class;
69 
70  int hsub, vsub;
71  int radius[4];
72  int power[4];
73  uint8_t *temp[2]; ///< temporary buffer used in blur_power()
75 
76 #define Y 0
77 #define U 1
78 #define V 2
79 #define A 3
80 
81 static av_cold int init(AVFilterContext *ctx)
82 {
83  BoxBlurContext *s = ctx->priv;
84 
85  if (!s->luma_param.radius_expr) {
86  av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n");
87  return AVERROR(EINVAL);
88  }
89 
90  /* fill missing params */
91  if (!s->chroma_param.radius_expr) {
93  if (!s->chroma_param.radius_expr)
94  return AVERROR(ENOMEM);
95  }
96  if (s->chroma_param.power < 0)
98 
99  if (!s->alpha_param.radius_expr) {
101  if (!s->alpha_param.radius_expr)
102  return AVERROR(ENOMEM);
103  }
104  if (s->alpha_param.power < 0)
106 
107  return 0;
108 }
109 
110 static av_cold void uninit(AVFilterContext *ctx)
111 {
112  BoxBlurContext *s = ctx->priv;
113 
114  av_freep(&s->temp[0]);
115  av_freep(&s->temp[1]);
116 }
117 
119 {
121  int fmt;
122 
123  for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
124  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
126  (desc->flags & AV_PIX_FMT_FLAG_PLANAR || desc->nb_components == 1) &&
127  (!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN || desc->comp[0].depth_minus1 == 7))
128  ff_add_format(&formats, fmt);
129  }
130 
131  return ff_set_common_formats(ctx, formats);
132 }
133 
134 static int config_input(AVFilterLink *inlink)
135 {
136  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
137  AVFilterContext *ctx = inlink->dst;
138  BoxBlurContext *s = ctx->priv;
139  int w = inlink->w, h = inlink->h;
140  int cw, ch;
141  double var_values[VARS_NB], res;
142  char *expr;
143  int ret;
144 
145  if (!(s->temp[0] = av_malloc(2*FFMAX(w, h))) ||
146  !(s->temp[1] = av_malloc(2*FFMAX(w, h))))
147  return AVERROR(ENOMEM);
148 
149  s->hsub = desc->log2_chroma_w;
150  s->vsub = desc->log2_chroma_h;
151 
152  var_values[VAR_W] = inlink->w;
153  var_values[VAR_H] = inlink->h;
154  var_values[VAR_CW] = cw = w>>s->hsub;
155  var_values[VAR_CH] = ch = h>>s->vsub;
156  var_values[VAR_HSUB] = 1<<s->hsub;
157  var_values[VAR_VSUB] = 1<<s->vsub;
158 
159 #define EVAL_RADIUS_EXPR(comp) \
160  expr = s->comp##_param.radius_expr; \
161  ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
162  NULL, NULL, NULL, NULL, NULL, 0, ctx); \
163  s->comp##_param.radius = res; \
164  if (ret < 0) { \
165  av_log(NULL, AV_LOG_ERROR, \
166  "Error when evaluating " #comp " radius expression '%s'\n", expr); \
167  return ret; \
168  }
169  EVAL_RADIUS_EXPR(luma);
172 
173  av_log(ctx, AV_LOG_VERBOSE,
174  "luma_radius:%d luma_power:%d "
175  "chroma_radius:%d chroma_power:%d "
176  "alpha_radius:%d alpha_power:%d "
177  "w:%d chroma_w:%d h:%d chroma_h:%d\n",
181  w, cw, h, ch);
182 
183 #define CHECK_RADIUS_VAL(w_, h_, comp) \
184  if (s->comp##_param.radius < 0 || \
185  2*s->comp##_param.radius > FFMIN(w_, h_)) { \
186  av_log(ctx, AV_LOG_ERROR, \
187  "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \
188  s->comp##_param.radius, FFMIN(w_, h_)/2); \
189  return AVERROR(EINVAL); \
190  }
191  CHECK_RADIUS_VAL(w, h, luma);
192  CHECK_RADIUS_VAL(cw, ch, chroma);
193  CHECK_RADIUS_VAL(w, h, alpha);
194 
195  s->radius[Y] = s->luma_param.radius;
196  s->radius[U] = s->radius[V] = s->chroma_param.radius;
197  s->radius[A] = s->alpha_param.radius;
198 
199  s->power[Y] = s->luma_param.power;
200  s->power[U] = s->power[V] = s->chroma_param.power;
201  s->power[A] = s->alpha_param.power;
202 
203  return 0;
204 }
205 
206 static inline void blur8(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
207  int len, int radius)
208 {
209  /* Naive boxblur would sum source pixels from x-radius .. x+radius
210  * for destination pixel x. That would be O(radius*width).
211  * If you now look at what source pixels represent 2 consecutive
212  * output pixels, then you see they are almost identical and only
213  * differ by 2 pixels, like:
214  * src0 111111111
215  * dst0 1
216  * src1 111111111
217  * dst1 1
218  * src0-src1 1 -1
219  * so when you know one output pixel you can find the next by just adding
220  * and subtracting 1 input pixel.
221  * The following code adopts this faster variant.
222  */
223  const int length = radius*2 + 1;
224  const int inv = ((1<<16) + length/2)/length;
225  int x, sum = src[radius*src_step];
226 
227  for (x = 0; x < radius; x++)
228  sum += src[x*src_step]<<1;
229 
230  sum = sum*inv + (1<<15);
231 
232  for (x = 0; x <= radius; x++) {
233  sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
234  dst[x*dst_step] = sum>>16;
235  }
236 
237  for (; x < len-radius; x++) {
238  sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
239  dst[x*dst_step] = sum >>16;
240  }
241 
242  for (; x < len; x++) {
243  sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
244  dst[x*dst_step] = sum>>16;
245  }
246 }
247 
248 static inline void blur16(uint16_t *dst, int dst_step, const uint16_t *src, int src_step,
249  int len, int radius)
250 {
251  const int length = radius*2 + 1;
252  const int inv = ((1<<16) + length/2)/length;
253  int x, sum = src[radius*src_step];
254 
255  for (x = 0; x < radius; x++)
256  sum += src[x*src_step]<<1;
257 
258  sum = sum*inv + (1<<15);
259 
260  for (x = 0; x <= radius; x++) {
261  sum += (src[(radius+x)*src_step] - src[(radius-x)*src_step])*inv;
262  dst[x*dst_step] = sum>>16;
263  }
264 
265  for (; x < len-radius; x++) {
266  sum += (src[(radius+x)*src_step] - src[(x-radius-1)*src_step])*inv;
267  dst[x*dst_step] = sum >>16;
268  }
269 
270  for (; x < len; x++) {
271  sum += (src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step])*inv;
272  dst[x*dst_step] = sum>>16;
273  }
274 }
275 
276 static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
277  int len, int radius, int pixsize)
278 {
279  if (pixsize == 1) blur8 (dst, dst_step , src, src_step , len, radius);
280  else blur16((uint16_t*)dst, dst_step>>1, (const uint16_t*)src, src_step>>1, len, radius);
281 }
282 
283 static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step,
284  int len, int radius, int power, uint8_t *temp[2], int pixsize)
285 {
286  uint8_t *a = temp[0], *b = temp[1];
287 
288  if (radius && power) {
289  blur(a, pixsize, src, src_step, len, radius, pixsize);
290  for (; power > 2; power--) {
291  uint8_t *c;
292  blur(b, pixsize, a, pixsize, len, radius, pixsize);
293  c = a; a = b; b = c;
294  }
295  if (power > 1) {
296  blur(dst, dst_step, a, pixsize, len, radius, pixsize);
297  } else {
298  int i;
299  if (pixsize == 1) {
300  for (i = 0; i < len; i++)
301  dst[i*dst_step] = a[i];
302  } else
303  for (i = 0; i < len; i++)
304  *(uint16_t*)(dst + i*dst_step) = ((uint16_t*)a)[i];
305  }
306  } else {
307  int i;
308  if (pixsize == 1) {
309  for (i = 0; i < len; i++)
310  dst[i*dst_step] = src[i*src_step];
311  } else
312  for (i = 0; i < len; i++)
313  *(uint16_t*)(dst + i*dst_step) = *(uint16_t*)(src + i*src_step);
314  }
315 }
316 
317 static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
318  int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
319 {
320  int y;
321 
322  if (radius == 0 && dst == src)
323  return;
324 
325  for (y = 0; y < h; y++)
326  blur_power(dst + y*dst_linesize, pixsize, src + y*src_linesize, pixsize,
327  w, radius, power, temp, pixsize);
328 }
329 
330 static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize,
331  int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
332 {
333  int x;
334 
335  if (radius == 0 && dst == src)
336  return;
337 
338  for (x = 0; x < w; x++)
339  blur_power(dst + x*pixsize, dst_linesize, src + x*pixsize, src_linesize,
340  h, radius, power, temp, pixsize);
341 }
342 
343 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
344 {
345  AVFilterContext *ctx = inlink->dst;
346  BoxBlurContext *s = ctx->priv;
347  AVFilterLink *outlink = inlink->dst->outputs[0];
348  AVFrame *out;
349  int plane;
350  int cw = FF_CEIL_RSHIFT(inlink->w, s->hsub), ch = FF_CEIL_RSHIFT(in->height, s->vsub);
351  int w[4] = { inlink->w, cw, cw, inlink->w };
352  int h[4] = { in->height, ch, ch, in->height };
353  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
354  const int depth = desc->comp[0].depth_minus1 + 1;
355  const int pixsize = (depth+7)/8;
356 
357  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
358  if (!out) {
359  av_frame_free(&in);
360  return AVERROR(ENOMEM);
361  }
362  av_frame_copy_props(out, in);
363 
364  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++)
365  hblur(out->data[plane], out->linesize[plane],
366  in ->data[plane], in ->linesize[plane],
367  w[plane], h[plane], s->radius[plane], s->power[plane],
368  s->temp, pixsize);
369 
370  for (plane = 0; plane < 4 && in->data[plane] && in->linesize[plane]; plane++)
371  vblur(out->data[plane], out->linesize[plane],
372  out->data[plane], out->linesize[plane],
373  w[plane], h[plane], s->radius[plane], s->power[plane],
374  s->temp, pixsize);
375 
376  av_frame_free(&in);
377 
378  return ff_filter_frame(outlink, out);
379 }
380 
381 #define OFFSET(x) offsetof(BoxBlurContext, x)
382 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
383 
384 static const AVOption boxblur_options[] = {
385  { "luma_radius", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
386  { "lr", "Radius of the luma blurring box", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
387  { "luma_power", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
388  { "lp", "How many times should the boxblur be applied to luma", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
389 
390  { "chroma_radius", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
391  { "cr", "Radius of the chroma blurring box", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
392  { "chroma_power", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
393  { "cp", "How many times should the boxblur be applied to chroma", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
394 
395  { "alpha_radius", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
396  { "ar", "Radius of the alpha blurring box", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
397  { "alpha_power", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
398  { "ap", "How many times should the boxblur be applied to alpha", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
399 
400  { NULL }
401 };
402 
403 AVFILTER_DEFINE_CLASS(boxblur);
404 
406  {
407  .name = "default",
408  .type = AVMEDIA_TYPE_VIDEO,
409  .config_props = config_input,
410  .filter_frame = filter_frame,
411  },
412  { NULL }
413 };
414 
416  {
417  .name = "default",
418  .type = AVMEDIA_TYPE_VIDEO,
419  },
420  { NULL }
421 };
422 
424  .name = "boxblur",
425  .description = NULL_IF_CONFIG_SMALL("Blur the input."),
426  .priv_size = sizeof(BoxBlurContext),
427  .priv_class = &boxblur_class,
428  .init = init,
429  .uninit = uninit,
431  .inputs = avfilter_vf_boxblur_inputs,
432  .outputs = avfilter_vf_boxblur_outputs,
434 };
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:115
int plane
Definition: avisynth_c.h:291
static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
Definition: vf_boxblur.c:317
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
#define U
Definition: vf_boxblur.c:77
static void blur16(uint16_t *dst, int dst_step, const uint16_t *src, int src_step, int len, int radius)
Definition: vf_boxblur.c:248
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2129
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
AVOption.
Definition: opt.h:255
const char * fmt
Definition: avisynth_c.h:632
static const AVFilterPad outputs[]
Definition: af_ashowinfo.c:248
Main libavfilter public API header.
else temp
Definition: vf_mcdeint.c:257
static int config_input(AVFilterLink *inlink)
Definition: vf_boxblur.c:134
const char * b
Definition: vf_curves.c:109
static void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int pixsize)
Definition: vf_boxblur.c:276
static enum AVSampleFormat formats[]
static av_cold int init(AVFilterContext *ctx)
Definition: vf_boxblur.c:81
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
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:80
#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:451
const char * name
Pad name.
Definition: internal.h:69
static void blur8(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius)
Definition: vf_boxblur.c:206
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1158
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:100
uint8_t
#define av_cold
Definition: attributes.h:74
#define av_malloc(s)
uint8_t * temp[2]
temporary buffer used in blur_power()
Definition: vf_boxblur.c:73
AVOptions.
#define Y
Definition: vf_boxblur.c:76
#define A
Definition: vf_boxblur.c:79
static const AVFilterPad avfilter_vf_boxblur_outputs[]
Definition: vf_boxblur.c:415
char * radius_expr
Definition: vf_boxblur.c:61
static const AVOption boxblur_options[]
Definition: vf_boxblur.c:384
FilterParam alpha_param
Definition: vf_boxblur.c:68
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
#define OFFSET(x)
Definition: vf_boxblur.c:381
#define av_log(a,...)
static void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, int len, int radius, int power, uint8_t *temp[2], int pixsize)
Definition: vf_boxblur.c:283
A filter pad used for either input or output.
Definition: internal.h:63
uint16_t depth_minus1
Number of bits in the component minus 1.
Definition: pixdesc.h:57
static double alpha(void *priv, double x, double y)
Definition: vf_geq.c:99
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int 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:542
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:148
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
void * priv
private data for use by the filter
Definition: avfilter.h:654
static int query_formats(AVFilterContext *ctx)
Definition: vf_boxblur.c:118
int radius[4]
Definition: vf_boxblur.c:71
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:123
GLsizei GLsizei * length
Definition: opengl_enc.c:115
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
Add fmt to the list of media formats contained in *avff.
Definition: formats.c:323
static const AVFilterPad avfilter_vf_boxblur_inputs[]
Definition: vf_boxblur.c:405
#define FFMAX(a, b)
Definition: common.h:79
#define V
Definition: vf_boxblur.c:78
int depth
Definition: v4l.c:62
var_name
Definition: aeval.c:46
#define FLAGS
Definition: vf_boxblur.c:382
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:71
float y
FilterParam luma_param
Definition: vf_boxblur.c:66
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
static const char *const var_names[]
Definition: vf_boxblur.c:38
int power[4]
Definition: vf_boxblur.c:72
#define EVAL_RADIUS_EXPR(comp)
AVS_Value src
Definition: avisynth_c.h:482
char * av_strdup(const char *s)
Duplicate the string s.
Definition: mem.c:267
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:199
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_boxblur.c:343
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:470
static const AVFilterPad inputs[]
Definition: af_ashowinfo.c:239
static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int w, int h, int radius, int power, uint8_t *temp[2], int pixsize)
Definition: vf_boxblur.c:330
static void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset, int column)
Definition: vf_waveform.c:785
static av_cold void uninit(AVFilterContext *ctx)
Definition: vf_boxblur.c:110
const char * name
Filter name.
Definition: avfilter.h:474
AVFILTER_DEFINE_CLASS(boxblur)
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:119
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:648
static int flags
Definition: cpu.c:47
AVFilter ff_vf_boxblur
Definition: vf_boxblur.c:423
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:182
common internal and external API header
#define CHECK_RADIUS_VAL(w_, h_, comp)
static double c[64]
FilterParam chroma_param
Definition: vf_boxblur.c:67
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
Definition: pixdesc.h:111
int len
A list of supported formats for one end of a filter link.
Definition: formats.h:64
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){if(!*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));if(!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=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);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);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) 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_log(ac->avr, AV_LOG_TRACE,"%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
An instance of a filter.
Definition: avfilter.h:633
int height
Definition: frame.h:220
#define av_freep(p)
internal API functions
#define AV_PIX_FMT_FLAG_PLANAR
At least one pixel component is not in the first data plane.
Definition: pixdesc.h:127
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:553
simple arithmetic expression evaluator