FFmpeg  4.1.11
vf_edgedetect.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2014 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  * @file
23  * Edge detection filter
24  *
25  * @see https://en.wikipedia.org/wiki/Canny_edge_detector
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/opt.h"
31 #include "avfilter.h"
32 #include "formats.h"
33 #include "internal.h"
34 #include "video.h"
35 
36 #define PLANE_R 0x4
37 #define PLANE_G 0x1
38 #define PLANE_B 0x2
39 #define PLANE_Y 0x1
40 #define PLANE_U 0x2
41 #define PLANE_V 0x4
42 #define PLANE_A 0x8
43 
44 enum FilterMode {
49 };
50 
51 struct plane_info {
53  uint16_t *gradients;
54  char *directions;
55  int width, height;
56 };
57 
58 typedef struct EdgeDetectContext {
59  const AVClass *class;
60  struct plane_info planes[3];
62  int nb_planes;
63  double low, high;
64  uint8_t low_u8, high_u8;
65  int mode;
67 
68 #define OFFSET(x) offsetof(EdgeDetectContext, x)
69 #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
70 static const AVOption edgedetect_options[] = {
71  { "high", "set high threshold", OFFSET(high), AV_OPT_TYPE_DOUBLE, {.dbl=50/255.}, 0, 1, FLAGS },
72  { "low", "set low threshold", OFFSET(low), AV_OPT_TYPE_DOUBLE, {.dbl=20/255.}, 0, 1, FLAGS },
73  { "mode", "set mode", OFFSET(mode), AV_OPT_TYPE_INT, {.i64=MODE_WIRES}, 0, NB_MODE-1, FLAGS, "mode" },
74  { "wires", "white/gray wires on black", 0, AV_OPT_TYPE_CONST, {.i64=MODE_WIRES}, INT_MIN, INT_MAX, FLAGS, "mode" },
75  { "colormix", "mix colors", 0, AV_OPT_TYPE_CONST, {.i64=MODE_COLORMIX}, INT_MIN, INT_MAX, FLAGS, "mode" },
76  { "canny", "detect edges on planes", 0, AV_OPT_TYPE_CONST, {.i64=MODE_CANNY}, INT_MIN, INT_MAX, FLAGS, "mode" },
77  { "planes", "set planes to filter", OFFSET(filter_planes), AV_OPT_TYPE_FLAGS, {.i64=7}, 1, 0x7, FLAGS, "flags" },
78  { "y", "filter luma plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_Y}, 0, 0, FLAGS, "flags" },
79  { "u", "filter u plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_U}, 0, 0, FLAGS, "flags" },
80  { "v", "filter v plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_V}, 0, 0, FLAGS, "flags" },
81  { "r", "filter red plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_R}, 0, 0, FLAGS, "flags" },
82  { "g", "filter green plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_G}, 0, 0, FLAGS, "flags" },
83  { "b", "filter blue plane", 0, AV_OPT_TYPE_CONST, {.i64=PLANE_B}, 0, 0, FLAGS, "flags" },
84  { NULL }
85 };
86 
87 AVFILTER_DEFINE_CLASS(edgedetect);
88 
90 {
91  EdgeDetectContext *edgedetect = ctx->priv;
92 
93  edgedetect->low_u8 = edgedetect->low * 255. + .5;
94  edgedetect->high_u8 = edgedetect->high * 255. + .5;
95  return 0;
96 }
97 
99 {
100  const EdgeDetectContext *edgedetect = ctx->priv;
101  static const enum AVPixelFormat wires_pix_fmts[] = {AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
102  static const enum AVPixelFormat canny_pix_fmts[] = {AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
103  static const enum AVPixelFormat colormix_pix_fmts[] = {AV_PIX_FMT_GBRP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE};
104  AVFilterFormats *fmts_list;
105  const enum AVPixelFormat *pix_fmts = NULL;
106 
107  if (edgedetect->mode == MODE_WIRES) {
108  pix_fmts = wires_pix_fmts;
109  } else if (edgedetect->mode == MODE_COLORMIX) {
110  pix_fmts = colormix_pix_fmts;
111  } else if (edgedetect->mode == MODE_CANNY) {
112  pix_fmts = canny_pix_fmts;
113  } else {
114  av_assert0(0);
115  }
116  fmts_list = ff_make_format_list(pix_fmts);
117  if (!fmts_list)
118  return AVERROR(ENOMEM);
119  return ff_set_common_formats(ctx, fmts_list);
120 }
121 
122 static int config_props(AVFilterLink *inlink)
123 {
124  int p;
125  AVFilterContext *ctx = inlink->dst;
126  EdgeDetectContext *edgedetect = ctx->priv;
128 
129  edgedetect->nb_planes = inlink->format == AV_PIX_FMT_GRAY8 ? 1 : 3;
130  for (p = 0; p < edgedetect->nb_planes; p++) {
131  struct plane_info *plane = &edgedetect->planes[p];
132  int vsub = p ? desc->log2_chroma_h : 0;
133  int hsub = p ? desc->log2_chroma_w : 0;
134 
135  plane->width = AV_CEIL_RSHIFT(inlink->w, hsub);
136  plane->height = AV_CEIL_RSHIFT(inlink->h, vsub);
137  plane->tmpbuf = av_malloc(plane->width * plane->height);
138  plane->gradients = av_calloc(plane->width * plane->height, sizeof(*plane->gradients));
139  plane->directions = av_malloc(plane->width * plane->height);
140  if (!plane->tmpbuf || !plane->gradients || !plane->directions)
141  return AVERROR(ENOMEM);
142  }
143  return 0;
144 }
145 
146 static void gaussian_blur(AVFilterContext *ctx, int w, int h,
147  uint8_t *dst, int dst_linesize,
148  const uint8_t *src, int src_linesize)
149 {
150  int i, j;
151 
152  memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
153  if (h > 1)
154  memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
155  for (j = 2; j < h - 2; j++) {
156  dst[0] = src[0];
157  if (w > 1)
158  dst[1] = src[1];
159  for (i = 2; i < w - 2; i++) {
160  /* Gaussian mask of size 5x5 with sigma = 1.4 */
161  dst[i] = ((src[-2*src_linesize + i-2] + src[2*src_linesize + i-2]) * 2
162  + (src[-2*src_linesize + i-1] + src[2*src_linesize + i-1]) * 4
163  + (src[-2*src_linesize + i ] + src[2*src_linesize + i ]) * 5
164  + (src[-2*src_linesize + i+1] + src[2*src_linesize + i+1]) * 4
165  + (src[-2*src_linesize + i+2] + src[2*src_linesize + i+2]) * 2
166 
167  + (src[ -src_linesize + i-2] + src[ src_linesize + i-2]) * 4
168  + (src[ -src_linesize + i-1] + src[ src_linesize + i-1]) * 9
169  + (src[ -src_linesize + i ] + src[ src_linesize + i ]) * 12
170  + (src[ -src_linesize + i+1] + src[ src_linesize + i+1]) * 9
171  + (src[ -src_linesize + i+2] + src[ src_linesize + i+2]) * 4
172 
173  + src[i-2] * 5
174  + src[i-1] * 12
175  + src[i ] * 15
176  + src[i+1] * 12
177  + src[i+2] * 5) / 159;
178  }
179  if (w > 2)
180  dst[i ] = src[i ];
181  if (w > 3)
182  dst[i + 1] = src[i + 1];
183 
184  dst += dst_linesize;
185  src += src_linesize;
186  }
187  if (h > 2)
188  memcpy(dst, src, w); dst += dst_linesize; src += src_linesize;
189  if (h > 3)
190  memcpy(dst, src, w);
191 }
192 
193 enum {
198 };
199 
200 static int get_rounded_direction(int gx, int gy)
201 {
202  /* reference angles:
203  * tan( pi/8) = sqrt(2)-1
204  * tan(3pi/8) = sqrt(2)+1
205  * Gy/Gx is the tangent of the angle (theta), so Gy/Gx is compared against
206  * <ref-angle>, or more simply Gy against <ref-angle>*Gx
207  *
208  * Gx and Gy bounds = [-1020;1020], using 16-bit arithmetic:
209  * round((sqrt(2)-1) * (1<<16)) = 27146
210  * round((sqrt(2)+1) * (1<<16)) = 158218
211  */
212  if (gx) {
213  int tanpi8gx, tan3pi8gx;
214 
215  if (gx < 0)
216  gx = -gx, gy = -gy;
217  gy <<= 16;
218  tanpi8gx = 27146 * gx;
219  tan3pi8gx = 158218 * gx;
220  if (gy > -tan3pi8gx && gy < -tanpi8gx) return DIRECTION_45UP;
221  if (gy > -tanpi8gx && gy < tanpi8gx) return DIRECTION_HORIZONTAL;
222  if (gy > tanpi8gx && gy < tan3pi8gx) return DIRECTION_45DOWN;
223  }
224  return DIRECTION_VERTICAL;
225 }
226 
227 static void sobel(int w, int h,
228  uint16_t *dst, int dst_linesize,
229  int8_t *dir, int dir_linesize,
230  const uint8_t *src, int src_linesize)
231 {
232  int i, j;
233 
234  for (j = 1; j < h - 1; j++) {
235  dst += dst_linesize;
236  dir += dir_linesize;
237  src += src_linesize;
238  for (i = 1; i < w - 1; i++) {
239  const int gx =
240  -1*src[-src_linesize + i-1] + 1*src[-src_linesize + i+1]
241  -2*src[ i-1] + 2*src[ i+1]
242  -1*src[ src_linesize + i-1] + 1*src[ src_linesize + i+1];
243  const int gy =
244  -1*src[-src_linesize + i-1] + 1*src[ src_linesize + i-1]
245  -2*src[-src_linesize + i ] + 2*src[ src_linesize + i ]
246  -1*src[-src_linesize + i+1] + 1*src[ src_linesize + i+1];
247 
248  dst[i] = FFABS(gx) + FFABS(gy);
249  dir[i] = get_rounded_direction(gx, gy);
250  }
251  }
252 }
253 
254 static void non_maximum_suppression(int w, int h,
255  uint8_t *dst, int dst_linesize,
256  const int8_t *dir, int dir_linesize,
257  const uint16_t *src, int src_linesize)
258 {
259  int i, j;
260 
261 #define COPY_MAXIMA(ay, ax, by, bx) do { \
262  if (src[i] > src[(ay)*src_linesize + i+(ax)] && \
263  src[i] > src[(by)*src_linesize + i+(bx)]) \
264  dst[i] = av_clip_uint8(src[i]); \
265 } while (0)
266 
267  for (j = 1; j < h - 1; j++) {
268  dst += dst_linesize;
269  dir += dir_linesize;
270  src += src_linesize;
271  for (i = 1; i < w - 1; i++) {
272  switch (dir[i]) {
273  case DIRECTION_45UP: COPY_MAXIMA( 1, -1, -1, 1); break;
274  case DIRECTION_45DOWN: COPY_MAXIMA(-1, -1, 1, 1); break;
275  case DIRECTION_HORIZONTAL: COPY_MAXIMA( 0, -1, 0, 1); break;
276  case DIRECTION_VERTICAL: COPY_MAXIMA(-1, 0, 1, 0); break;
277  }
278  }
279  }
280 }
281 
282 static void double_threshold(int low, int high, int w, int h,
283  uint8_t *dst, int dst_linesize,
284  const uint8_t *src, int src_linesize)
285 {
286  int i, j;
287 
288  for (j = 0; j < h; j++) {
289  for (i = 0; i < w; i++) {
290  if (src[i] > high) {
291  dst[i] = src[i];
292  continue;
293  }
294 
295  if ((!i || i == w - 1 || !j || j == h - 1) &&
296  src[i] > low &&
297  (src[-src_linesize + i-1] > high ||
298  src[-src_linesize + i ] > high ||
299  src[-src_linesize + i+1] > high ||
300  src[ i-1] > high ||
301  src[ i+1] > high ||
302  src[ src_linesize + i-1] > high ||
303  src[ src_linesize + i ] > high ||
304  src[ src_linesize + i+1] > high))
305  dst[i] = src[i];
306  else
307  dst[i] = 0;
308  }
309  dst += dst_linesize;
310  src += src_linesize;
311  }
312 }
313 
314 static void color_mix(int w, int h,
315  uint8_t *dst, int dst_linesize,
316  const uint8_t *src, int src_linesize)
317 {
318  int i, j;
319 
320  for (j = 0; j < h; j++) {
321  for (i = 0; i < w; i++)
322  dst[i] = (dst[i] + src[i]) >> 1;
323  dst += dst_linesize;
324  src += src_linesize;
325  }
326 }
327 
328 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
329 {
330  AVFilterContext *ctx = inlink->dst;
331  EdgeDetectContext *edgedetect = ctx->priv;
332  AVFilterLink *outlink = ctx->outputs[0];
333  int p, direct = 0;
334  AVFrame *out;
335 
336  if (edgedetect->mode != MODE_COLORMIX && av_frame_is_writable(in)) {
337  direct = 1;
338  out = in;
339  } else {
340  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
341  if (!out) {
342  av_frame_free(&in);
343  return AVERROR(ENOMEM);
344  }
345  av_frame_copy_props(out, in);
346  }
347 
348  for (p = 0; p < edgedetect->nb_planes; p++) {
349  struct plane_info *plane = &edgedetect->planes[p];
350  uint8_t *tmpbuf = plane->tmpbuf;
351  uint16_t *gradients = plane->gradients;
352  int8_t *directions = plane->directions;
353  const int width = plane->width;
354  const int height = plane->height;
355 
356  if (!((1 << p) & edgedetect->filter_planes)) {
357  if (!direct)
358  av_image_copy_plane(out->data[p], out->linesize[p],
359  in->data[p], in->linesize[p],
360  width, height);
361  continue;
362  }
363 
364  /* gaussian filter to reduce noise */
365  gaussian_blur(ctx, width, height,
366  tmpbuf, width,
367  in->data[p], in->linesize[p]);
368 
369  /* compute the 16-bits gradients and directions for the next step */
370  sobel(width, height,
371  gradients, width,
372  directions,width,
373  tmpbuf, width);
374 
375  /* non_maximum_suppression() will actually keep & clip what's necessary and
376  * ignore the rest, so we need a clean output buffer */
377  memset(tmpbuf, 0, width * height);
378  non_maximum_suppression(width, height,
379  tmpbuf, width,
380  directions,width,
381  gradients, width);
382 
383  /* keep high values, or low values surrounded by high values */
384  double_threshold(edgedetect->low_u8, edgedetect->high_u8,
385  width, height,
386  out->data[p], out->linesize[p],
387  tmpbuf, width);
388 
389  if (edgedetect->mode == MODE_COLORMIX) {
390  color_mix(width, height,
391  out->data[p], out->linesize[p],
392  in->data[p], in->linesize[p]);
393  }
394  }
395 
396  if (!direct)
397  av_frame_free(&in);
398  return ff_filter_frame(outlink, out);
399 }
400 
402 {
403  int p;
404  EdgeDetectContext *edgedetect = ctx->priv;
405 
406  for (p = 0; p < edgedetect->nb_planes; p++) {
407  struct plane_info *plane = &edgedetect->planes[p];
408  av_freep(&plane->tmpbuf);
409  av_freep(&plane->gradients);
410  av_freep(&plane->directions);
411  }
412 }
413 
414 static const AVFilterPad edgedetect_inputs[] = {
415  {
416  .name = "default",
417  .type = AVMEDIA_TYPE_VIDEO,
418  .config_props = config_props,
419  .filter_frame = filter_frame,
420  },
421  { NULL }
422 };
423 
424 static const AVFilterPad edgedetect_outputs[] = {
425  {
426  .name = "default",
427  .type = AVMEDIA_TYPE_VIDEO,
428  },
429  { NULL }
430 };
431 
433  .name = "edgedetect",
434  .description = NULL_IF_CONFIG_SMALL("Detect and draw edge."),
435  .priv_size = sizeof(EdgeDetectContext),
436  .init = init,
437  .uninit = uninit,
439  .inputs = edgedetect_inputs,
440  .outputs = edgedetect_outputs,
441  .priv_class = &edgedetect_class,
443 };
int plane
Definition: avisynth_c.h:422
static const AVFilterPad edgedetect_outputs[]
#define NULL
Definition: coverity.c:32
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2446
static av_cold void uninit(AVFilterContext *ctx)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
AVOption.
Definition: opt.h:246
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
Main libavfilter public API header.
static void sobel(int w, int h, uint16_t *dst, int dst_linesize, int8_t *dir, int dir_linesize, const uint8_t *src, int src_linesize)
const char * desc
Definition: nvenc.c:65
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:104
#define src
Definition: vp8dsp.c:254
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
#define PLANE_B
Definition: vf_edgedetect.c:38
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:244
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
static void double_threshold(int low, int high, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
#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:125
const char * name
Pad name.
Definition: internal.h:60
#define PLANE_V
Definition: vf_edgedetect.c:41
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
uint8_t
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
AVOptions.
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static int query_formats(AVFilterContext *ctx)
Definition: vf_edgedetect.c:98
char * directions
Definition: vf_edgedetect.c:54
#define PLANE_G
Definition: vf_edgedetect.c:37
AVFILTER_DEFINE_CLASS(edgedetect)
A filter pad used for either input or output.
Definition: internal.h:54
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
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:568
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static const AVOption edgedetect_options[]
Definition: vf_edgedetect.c:70
#define AVERROR(e)
Definition: error.h:43
#define FLAGS
Definition: vf_edgedetect.c:69
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define PLANE_R
Definition: vf_edgedetect.c:36
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:188
void * priv
private data for use by the filter
Definition: avfilter.h:353
uint16_t * gradients
Definition: vf_edgedetect.c:53
simple assert() macros that are a bit more flexible than ISO C assert().
static int config_props(AVFilterLink *inlink)
AVFilter ff_vf_edgedetect
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
static void gaussian_blur(AVFilterContext *ctx, int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
static const struct @304 planes[]
uint8_t w
Definition: llviddspenc.c:38
AVFormatContext * ctx
Definition: movenc.c:48
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
static int get_rounded_direction(int gx, int gy)
static const AVFilterPad inputs[]
Definition: af_acontrast.c:193
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
static const AVFilterPad edgedetect_inputs[]
static av_cold int init(AVFilterContext *ctx)
Definition: vf_edgedetect.c:89
FilterMode
Definition: vp9.h:64
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:594
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:257
struct plane_info planes[3]
Definition: vf_edgedetect.c:60
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
#define OFFSET(x)
Definition: vf_edgedetect.c:68
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=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;} 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_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);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_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
const char * name
Filter name.
Definition: avfilter.h:148
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
#define COPY_MAXIMA(ay, ax, by, bx)
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
#define flags(name, subs,...)
Definition: cbs_av1.c:610
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:240
static void non_maximum_suppression(int w, int h, uint8_t *dst, int dst_linesize, const int8_t *dir, int dir_linesize, const uint16_t *src, int src_linesize)
#define PLANE_Y
Definition: vf_edgedetect.c:39
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
#define PLANE_U
Definition: vf_edgedetect.c:40
uint8_t * tmpbuf
Definition: vf_edgedetect.c:52
static void color_mix(int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize)
A list of supported formats for one end of a filter link.
Definition: formats.h:64
An instance of a filter.
Definition: avfilter.h:338
FILE * out
Definition: movenc.c:54
#define av_freep(p)
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:338
internal API functions
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:654
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58