FFmpeg
vf_convolution.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013 Oka Motofumi (chikuzen.mo at gmail dot com)
3  * Copyright (c) 2015 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 #include "libavutil/avstring.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/opt.h"
26 #include "libavutil/pixdesc.h"
27 #include "avfilter.h"
28 #include "convolution.h"
29 #include "formats.h"
30 #include "internal.h"
31 #include "video.h"
32 
33 #define OFFSET(x) offsetof(ConvolutionContext, x)
34 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
35 
36 static const AVOption convolution_options[] = {
37  { "0m", "set matrix for 1st plane", OFFSET(matrix_str[0]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
38  { "1m", "set matrix for 2nd plane", OFFSET(matrix_str[1]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
39  { "2m", "set matrix for 3rd plane", OFFSET(matrix_str[2]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
40  { "3m", "set matrix for 4th plane", OFFSET(matrix_str[3]), AV_OPT_TYPE_STRING, {.str="0 0 0 0 1 0 0 0 0"}, 0, 0, FLAGS },
41  { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
42  { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
43  { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
44  { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
45  { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
46  { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
47  { "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
48  { "3bias", "set bias for 4th plane", OFFSET(bias[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
49  { "0mode", "set matrix mode for 1st plane", OFFSET(mode[0]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
50  { "1mode", "set matrix mode for 2nd plane", OFFSET(mode[1]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
51  { "2mode", "set matrix mode for 3rd plane", OFFSET(mode[2]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
52  { "3mode", "set matrix mode for 4th plane", OFFSET(mode[3]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
53  { "square", "square matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_SQUARE}, 0, 0, FLAGS, "mode" },
54  { "row", "single row matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_ROW} , 0, 0, FLAGS, "mode" },
55  { "column", "single column matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_COLUMN}, 0, 0, FLAGS, "mode" },
56  { NULL }
57 };
58 
59 AVFILTER_DEFINE_CLASS(convolution);
60 
61 static const int same3x3[9] = {0, 0, 0,
62  0, 1, 0,
63  0, 0, 0};
64 
65 static const int same5x5[25] = {0, 0, 0, 0, 0,
66  0, 0, 0, 0, 0,
67  0, 0, 1, 0, 0,
68  0, 0, 0, 0, 0,
69  0, 0, 0, 0, 0};
70 
71 static const int same7x7[49] = {0, 0, 0, 0, 0, 0, 0,
72  0, 0, 0, 0, 0, 0, 0,
73  0, 0, 0, 0, 0, 0, 0,
74  0, 0, 0, 1, 0, 0, 0,
75  0, 0, 0, 0, 0, 0, 0,
76  0, 0, 0, 0, 0, 0, 0,
77  0, 0, 0, 0, 0, 0, 0};
78 
80 {
81  static const enum AVPixelFormat pix_fmts[] = {
100  };
101 
102  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
103 }
104 
105 typedef struct ThreadData {
106  AVFrame *in, *out;
107 } ThreadData;
108 
109 static void filter16_prewitt(uint8_t *dstp, int width,
110  float scale, float delta, const int *const matrix,
111  const uint8_t *c[], int peak, int radius,
112  int dstride, int stride)
113 {
114  uint16_t *dst = (uint16_t *)dstp;
115  int x;
116 
117  for (x = 0; x < width; x++) {
118  int suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * -1 +
119  AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 1 + AV_RN16A(&c[8][2 * x]) * 1;
120  int sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1 +
121  AV_RN16A(&c[5][2 * x]) * 1 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
122 
123  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
124  }
125 }
126 
127 static void filter16_roberts(uint8_t *dstp, int width,
128  float scale, float delta, const int *const matrix,
129  const uint8_t *c[], int peak, int radius,
130  int dstride, int stride)
131 {
132  uint16_t *dst = (uint16_t *)dstp;
133  int x;
134 
135  for (x = 0; x < width; x++) {
136  int suma = AV_RN16A(&c[0][2 * x]) * 1 + AV_RN16A(&c[1][2 * x]) * -1;
137  int sumb = AV_RN16A(&c[4][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1;
138 
139  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
140  }
141 }
142 
143 static void filter16_sobel(uint8_t *dstp, int width,
144  float scale, float delta, const int *const matrix,
145  const uint8_t *c[], int peak, int radius,
146  int dstride, int stride)
147 {
148  uint16_t *dst = (uint16_t *)dstp;
149  int x;
150 
151  for (x = 0; x < width; x++) {
152  int suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -2 + AV_RN16A(&c[2][2 * x]) * -1 +
153  AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 2 + AV_RN16A(&c[8][2 * x]) * 1;
154  int sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -2 +
155  AV_RN16A(&c[5][2 * x]) * 2 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
156 
157  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
158  }
159 }
160 
161 static void filter_prewitt(uint8_t *dst, int width,
162  float scale, float delta, const int *const matrix,
163  const uint8_t *c[], int peak, int radius,
164  int dstride, int stride)
165 {
166  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
167  const uint8_t *c3 = c[3], *c5 = c[5];
168  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
169  int x;
170 
171  for (x = 0; x < width; x++) {
172  int suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
173  c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
174  int sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
175  c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
176 
177  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
178  }
179 }
180 
181 static void filter_roberts(uint8_t *dst, int width,
182  float scale, float delta, const int *const matrix,
183  const uint8_t *c[], int peak, int radius,
184  int dstride, int stride)
185 {
186  int x;
187 
188  for (x = 0; x < width; x++) {
189  int suma = c[0][x] * 1 + c[1][x] * -1;
190  int sumb = c[4][x] * 1 + c[3][x] * -1;
191 
192  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
193  }
194 }
195 
196 static void filter_sobel(uint8_t *dst, int width,
197  float scale, float delta, const int *const matrix,
198  const uint8_t *c[], int peak, int radius,
199  int dstride, int stride)
200 {
201  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
202  const uint8_t *c3 = c[3], *c5 = c[5];
203  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
204  int x;
205 
206  for (x = 0; x < width; x++) {
207  int suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
208  c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
209  int sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
210  c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
211 
212  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
213  }
214 }
215 
216 static void filter16_3x3(uint8_t *dstp, int width,
217  float rdiv, float bias, const int *const matrix,
218  const uint8_t *c[], int peak, int radius,
219  int dstride, int stride)
220 {
221  uint16_t *dst = (uint16_t *)dstp;
222  int x;
223 
224  for (x = 0; x < width; x++) {
225  int sum = AV_RN16A(&c[0][2 * x]) * matrix[0] +
226  AV_RN16A(&c[1][2 * x]) * matrix[1] +
227  AV_RN16A(&c[2][2 * x]) * matrix[2] +
228  AV_RN16A(&c[3][2 * x]) * matrix[3] +
229  AV_RN16A(&c[4][2 * x]) * matrix[4] +
230  AV_RN16A(&c[5][2 * x]) * matrix[5] +
231  AV_RN16A(&c[6][2 * x]) * matrix[6] +
232  AV_RN16A(&c[7][2 * x]) * matrix[7] +
233  AV_RN16A(&c[8][2 * x]) * matrix[8];
234  sum = (int)(sum * rdiv + bias + 0.5f);
235  dst[x] = av_clip(sum, 0, peak);
236  }
237 }
238 
239 static void filter16_5x5(uint8_t *dstp, int width,
240  float rdiv, float bias, const int *const matrix,
241  const uint8_t *c[], int peak, int radius,
242  int dstride, int stride)
243 {
244  uint16_t *dst = (uint16_t *)dstp;
245  int x;
246 
247  for (x = 0; x < width; x++) {
248  int i, sum = 0;
249 
250  for (i = 0; i < 25; i++)
251  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
252 
253  sum = (int)(sum * rdiv + bias + 0.5f);
254  dst[x] = av_clip(sum, 0, peak);
255  }
256 }
257 
258 static void filter16_7x7(uint8_t *dstp, int width,
259  float rdiv, float bias, const int *const matrix,
260  const uint8_t *c[], int peak, int radius,
261  int dstride, int stride)
262 {
263  uint16_t *dst = (uint16_t *)dstp;
264  int x;
265 
266  for (x = 0; x < width; x++) {
267  int i, sum = 0;
268 
269  for (i = 0; i < 49; i++)
270  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
271 
272  sum = (int)(sum * rdiv + bias + 0.5f);
273  dst[x] = av_clip(sum, 0, peak);
274  }
275 }
276 
277 static void filter16_row(uint8_t *dstp, int width,
278  float rdiv, float bias, const int *const matrix,
279  const uint8_t *c[], int peak, int radius,
280  int dstride, int stride)
281 {
282  uint16_t *dst = (uint16_t *)dstp;
283  int x;
284 
285  for (x = 0; x < width; x++) {
286  int i, sum = 0;
287 
288  for (i = 0; i < 2 * radius + 1; i++)
289  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
290 
291  sum = (int)(sum * rdiv + bias + 0.5f);
292  dst[x] = av_clip(sum, 0, peak);
293  }
294 }
295 
296 static void filter16_column(uint8_t *dstp, int height,
297  float rdiv, float bias, const int *const matrix,
298  const uint8_t *c[], int peak, int radius,
299  int dstride, int stride)
300 {
301  uint16_t *dst = (uint16_t *)dstp;
302  int y;
303 
304  for (y = 0; y < height; y++) {
305  int i, sum = 0;
306 
307  for (i = 0; i < 2 * radius + 1; i++)
308  sum += AV_RN16A(&c[i][0 + y * stride]) * matrix[i];
309 
310  sum = (int)(sum * rdiv + bias + 0.5f);
311  dst[0] = av_clip(sum, 0, peak);
312  dst += dstride / 2;
313  }
314 }
315 
316 static void filter_7x7(uint8_t *dst, int width,
317  float rdiv, float bias, const int *const matrix,
318  const uint8_t *c[], int peak, int radius,
319  int dstride, int stride)
320 {
321  int x;
322 
323  for (x = 0; x < width; x++) {
324  int i, sum = 0;
325 
326  for (i = 0; i < 49; i++)
327  sum += c[i][x] * matrix[i];
328 
329  sum = (int)(sum * rdiv + bias + 0.5f);
330  dst[x] = av_clip_uint8(sum);
331  }
332 }
333 
334 static void filter_5x5(uint8_t *dst, int width,
335  float rdiv, float bias, const int *const matrix,
336  const uint8_t *c[], int peak, int radius,
337  int dstride, int stride)
338 {
339  int x;
340 
341  for (x = 0; x < width; x++) {
342  int i, sum = 0;
343 
344  for (i = 0; i < 25; i++)
345  sum += c[i][x] * matrix[i];
346 
347  sum = (int)(sum * rdiv + bias + 0.5f);
348  dst[x] = av_clip_uint8(sum);
349  }
350 }
351 
352 static void filter_3x3(uint8_t *dst, int width,
353  float rdiv, float bias, const int *const matrix,
354  const uint8_t *c[], int peak, int radius,
355  int dstride, int stride)
356 {
357  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
358  const uint8_t *c3 = c[3], *c4 = c[4], *c5 = c[5];
359  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
360  int x;
361 
362  for (x = 0; x < width; x++) {
363  int sum = c0[x] * matrix[0] + c1[x] * matrix[1] + c2[x] * matrix[2] +
364  c3[x] * matrix[3] + c4[x] * matrix[4] + c5[x] * matrix[5] +
365  c6[x] * matrix[6] + c7[x] * matrix[7] + c8[x] * matrix[8];
366  sum = (int)(sum * rdiv + bias + 0.5f);
367  dst[x] = av_clip_uint8(sum);
368  }
369 }
370 
371 static void filter_row(uint8_t *dst, int width,
372  float rdiv, float bias, const int *const matrix,
373  const uint8_t *c[], int peak, int radius,
374  int dstride, int stride)
375 {
376  int x;
377 
378  for (x = 0; x < width; x++) {
379  int i, sum = 0;
380 
381  for (i = 0; i < 2 * radius + 1; i++)
382  sum += c[i][x] * matrix[i];
383 
384  sum = (int)(sum * rdiv + bias + 0.5f);
385  dst[x] = av_clip_uint8(sum);
386  }
387 }
388 
389 static void filter_column(uint8_t *dst, int height,
390  float rdiv, float bias, const int *const matrix,
391  const uint8_t *c[], int peak, int radius,
392  int dstride, int stride)
393 {
394  int y;
395 
396  for (y = 0; y < height; y++) {
397  int i, sum = 0;
398 
399  for (i = 0; i < 2 * radius + 1; i++)
400  sum += c[i][0 + y * stride] * matrix[i];
401 
402  sum = (int)(sum * rdiv + bias + 0.5f);
403  dst[0] = av_clip_uint8(sum);
404  dst += dstride;
405  }
406 }
407 
408 static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride,
409  int x, int w, int y, int h, int bpc)
410 {
411  int i;
412 
413  for (i = 0; i < 9; i++) {
414  int xoff = FFABS(x + ((i % 3) - 1));
415  int yoff = FFABS(y + (i / 3) - 1);
416 
417  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
418  yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
419 
420  c[i] = src + xoff * bpc + yoff * stride;
421  }
422 }
423 
424 static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride,
425  int x, int w, int y, int h, int bpc)
426 {
427  int i;
428 
429  for (i = 0; i < 25; i++) {
430  int xoff = FFABS(x + ((i % 5) - 2));
431  int yoff = FFABS(y + (i / 5) - 2);
432 
433  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
434  yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
435 
436  c[i] = src + xoff * bpc + yoff * stride;
437  }
438 }
439 
440 static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride,
441  int x, int w, int y, int h, int bpc)
442 {
443  int i;
444 
445  for (i = 0; i < 49; i++) {
446  int xoff = FFABS(x + ((i % 7) - 3));
447  int yoff = FFABS(y + (i / 7) - 3);
448 
449  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
450  yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
451 
452  c[i] = src + xoff * bpc + yoff * stride;
453  }
454 }
455 
456 static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int stride,
457  int x, int w, int y, int h, int bpc)
458 {
459  int i;
460 
461  for (i = 0; i < radius * 2 + 1; i++) {
462  int xoff = FFABS(x + i - radius);
463 
464  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
465 
466  c[i] = src + xoff * bpc + y * stride;
467  }
468 }
469 
470 static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int stride,
471  int x, int w, int y, int h, int bpc)
472 {
473  int i;
474 
475  for (i = 0; i < radius * 2 + 1; i++) {
476  int xoff = FFABS(x + i - radius);
477 
478  xoff = xoff >= h ? 2 * h - 1 - xoff : xoff;
479 
480  c[i] = src + y * bpc + xoff * stride;
481  }
482 }
483 
484 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
485 {
486  ConvolutionContext *s = ctx->priv;
487  ThreadData *td = arg;
488  AVFrame *in = td->in;
489  AVFrame *out = td->out;
490  int plane;
491 
492  for (plane = 0; plane < s->nb_planes; plane++) {
493  const int mode = s->mode[plane];
494  const int bpc = s->bpc;
495  const int radius = s->size[plane] / 2;
496  const int height = s->planeheight[plane];
497  const int width = s->planewidth[plane];
498  const int stride = in->linesize[plane];
499  const int dstride = out->linesize[plane];
500  const int sizeh = mode == MATRIX_COLUMN ? width : height;
501  const int sizew = mode == MATRIX_COLUMN ? height : width;
502  const int slice_start = (sizeh * jobnr) / nb_jobs;
503  const int slice_end = (sizeh * (jobnr+1)) / nb_jobs;
504  const float rdiv = s->rdiv[plane];
505  const float bias = s->bias[plane];
506  const uint8_t *src = in->data[plane];
507  const int dst_pos = slice_start * (mode == MATRIX_COLUMN ? bpc : dstride);
508  uint8_t *dst = out->data[plane] + dst_pos;
509  const int *matrix = s->matrix[plane];
510  const uint8_t *c[49];
511  int y, x;
512 
513  if (s->copy[plane]) {
514  if (mode == MATRIX_COLUMN)
515  av_image_copy_plane(dst, dstride, src + slice_start * bpc, stride,
516  (slice_end - slice_start) * bpc, height);
517  else
518  av_image_copy_plane(dst, dstride, src + slice_start * stride, stride,
519  width * bpc, slice_end - slice_start);
520  continue;
521  }
522 
523  for (y = slice_start; y < slice_end; y++) {
524  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
525  const int yoff = mode == MATRIX_COLUMN ? radius * stride : 0;
526 
527  for (x = 0; x < radius; x++) {
528  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
529  const int yoff = mode == MATRIX_COLUMN ? x * stride : 0;
530 
531  s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
532  s->filter[plane](dst + yoff + xoff, 1, rdiv,
533  bias, matrix, c, s->max, radius,
534  dstride, stride);
535  }
536  s->setup[plane](radius, c, src, stride, radius, width, y, height, bpc);
537  s->filter[plane](dst + yoff + xoff, sizew - 2 * radius,
538  rdiv, bias, matrix, c, s->max, radius,
539  dstride, stride);
540  for (x = sizew - radius; x < sizew; x++) {
541  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
542  const int yoff = mode == MATRIX_COLUMN ? x * stride : 0;
543 
544  s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
545  s->filter[plane](dst + yoff + xoff, 1, rdiv,
546  bias, matrix, c, s->max, radius,
547  dstride, stride);
548  }
549  if (mode != MATRIX_COLUMN)
550  dst += dstride;
551  }
552  }
553 
554  return 0;
555 }
556 
558 {
559  AVFilterContext *ctx = inlink->dst;
560  ConvolutionContext *s = ctx->priv;
562  int p;
563 
564  s->depth = desc->comp[0].depth;
565  s->max = (1 << s->depth) - 1;
566 
567  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
568  s->planewidth[0] = s->planewidth[3] = inlink->w;
569  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
570  s->planeheight[0] = s->planeheight[3] = inlink->h;
571 
574  s->bpc = (s->depth + 7) / 8;
575 
576  if (!strcmp(ctx->filter->name, "convolution")) {
577  if (s->depth > 8) {
578  for (p = 0; p < s->nb_planes; p++) {
579  if (s->mode[p] == MATRIX_ROW)
580  s->filter[p] = filter16_row;
581  else if (s->mode[p] == MATRIX_COLUMN)
582  s->filter[p] = filter16_column;
583  else if (s->size[p] == 3)
584  s->filter[p] = filter16_3x3;
585  else if (s->size[p] == 5)
586  s->filter[p] = filter16_5x5;
587  else if (s->size[p] == 7)
588  s->filter[p] = filter16_7x7;
589  }
590  }
591 #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64
593 #endif
594  } else if (!strcmp(ctx->filter->name, "prewitt")) {
595  if (s->depth > 8)
596  for (p = 0; p < s->nb_planes; p++)
597  s->filter[p] = filter16_prewitt;
598  } else if (!strcmp(ctx->filter->name, "roberts")) {
599  if (s->depth > 8)
600  for (p = 0; p < s->nb_planes; p++)
601  s->filter[p] = filter16_roberts;
602  } else if (!strcmp(ctx->filter->name, "sobel")) {
603  if (s->depth > 8)
604  for (p = 0; p < s->nb_planes; p++)
605  s->filter[p] = filter16_sobel;
606  }
607 
608  return 0;
609 }
610 
612 {
613  AVFilterContext *ctx = inlink->dst;
614  ConvolutionContext *s = ctx->priv;
615  AVFilterLink *outlink = ctx->outputs[0];
616  AVFrame *out;
617  ThreadData td;
618 
619  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
620  if (!out) {
621  av_frame_free(&in);
622  return AVERROR(ENOMEM);
623  }
624  av_frame_copy_props(out, in);
625 
626  td.in = in;
627  td.out = out;
628  ctx->internal->execute(ctx, filter_slice, &td, NULL, FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads));
629 
630  av_frame_free(&in);
631  return ff_filter_frame(outlink, out);
632 }
633 
635 {
636  ConvolutionContext *s = ctx->priv;
637  int i;
638 
639  if (!strcmp(ctx->filter->name, "convolution")) {
640  for (i = 0; i < 4; i++) {
641  int *matrix = (int *)s->matrix[i];
642  char *p, *arg, *saveptr = NULL;
643  float sum = 0;
644 
645  p = s->matrix_str[i];
646  while (s->matrix_length[i] < 49) {
647  if (!(arg = av_strtok(p, " ", &saveptr)))
648  break;
649 
650  p = NULL;
651  sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
652  sum += matrix[s->matrix_length[i]];
653  s->matrix_length[i]++;
654  }
655 
656  if (!(s->matrix_length[i] & 1)) {
657  av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
658  return AVERROR(EINVAL);
659  }
660  if (s->mode[i] == MATRIX_ROW) {
661  s->filter[i] = filter_row;
662  s->setup[i] = setup_row;
663  s->size[i] = s->matrix_length[i];
664  } else if (s->mode[i] == MATRIX_COLUMN) {
665  s->filter[i] = filter_column;
666  s->setup[i] = setup_column;
667  s->size[i] = s->matrix_length[i];
668  } else if (s->matrix_length[i] == 9) {
669  s->size[i] = 3;
670  if (!memcmp(matrix, same3x3, sizeof(same3x3)))
671  s->copy[i] = 1;
672  else
673  s->filter[i] = filter_3x3;
674  s->setup[i] = setup_3x3;
675  } else if (s->matrix_length[i] == 25) {
676  s->size[i] = 5;
677  if (!memcmp(matrix, same5x5, sizeof(same5x5)))
678  s->copy[i] = 1;
679  else
680  s->filter[i] = filter_5x5;
681  s->setup[i] = setup_5x5;
682  } else if (s->matrix_length[i] == 49) {
683  s->size[i] = 7;
684  if (!memcmp(matrix, same7x7, sizeof(same7x7)))
685  s->copy[i] = 1;
686  else
687  s->filter[i] = filter_7x7;
688  s->setup[i] = setup_7x7;
689  } else {
690  return AVERROR(EINVAL);
691  }
692 
693  if (sum == 0)
694  sum = 1;
695  if (s->rdiv[i] == 0)
696  s->rdiv[i] = 1. / sum;
697 
698  if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
699  s->copy[i] = 0;
700  }
701  } else if (!strcmp(ctx->filter->name, "prewitt")) {
702  for (i = 0; i < 4; i++) {
703  if ((1 << i) & s->planes)
704  s->filter[i] = filter_prewitt;
705  else
706  s->copy[i] = 1;
707  s->size[i] = 3;
708  s->setup[i] = setup_3x3;
709  s->rdiv[i] = s->scale;
710  s->bias[i] = s->delta;
711  }
712  } else if (!strcmp(ctx->filter->name, "roberts")) {
713  for (i = 0; i < 4; i++) {
714  if ((1 << i) & s->planes)
715  s->filter[i] = filter_roberts;
716  else
717  s->copy[i] = 1;
718  s->size[i] = 3;
719  s->setup[i] = setup_3x3;
720  s->rdiv[i] = s->scale;
721  s->bias[i] = s->delta;
722  }
723  } else if (!strcmp(ctx->filter->name, "sobel")) {
724  for (i = 0; i < 4; i++) {
725  if ((1 << i) & s->planes)
726  s->filter[i] = filter_sobel;
727  else
728  s->copy[i] = 1;
729  s->size[i] = 3;
730  s->setup[i] = setup_3x3;
731  s->rdiv[i] = s->scale;
732  s->bias[i] = s->delta;
733  }
734  }
735 
736  return 0;
737 }
738 
739 static const AVFilterPad convolution_inputs[] = {
740  {
741  .name = "default",
742  .type = AVMEDIA_TYPE_VIDEO,
743  .config_props = config_input,
744  .filter_frame = filter_frame,
745  },
746  { NULL }
747 };
748 
750  {
751  .name = "default",
752  .type = AVMEDIA_TYPE_VIDEO,
753  },
754  { NULL }
755 };
756 
757 #if CONFIG_CONVOLUTION_FILTER
758 
760  .name = "convolution",
761  .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
762  .priv_size = sizeof(ConvolutionContext),
763  .priv_class = &convolution_class,
764  .init = init,
766  .inputs = convolution_inputs,
767  .outputs = convolution_outputs,
769 };
770 
771 #endif /* CONFIG_CONVOLUTION_FILTER */
772 
773 #if CONFIG_PREWITT_FILTER
774 
775 static const AVOption prewitt_options[] = {
776  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
777  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
778  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
779  { NULL }
780 };
781 
782 AVFILTER_DEFINE_CLASS(prewitt);
783 
785  .name = "prewitt",
786  .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
787  .priv_size = sizeof(ConvolutionContext),
788  .priv_class = &prewitt_class,
789  .init = init,
791  .inputs = convolution_inputs,
792  .outputs = convolution_outputs,
794 };
795 
796 #endif /* CONFIG_PREWITT_FILTER */
797 
798 #if CONFIG_SOBEL_FILTER
799 
800 static const AVOption sobel_options[] = {
801  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
802  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
803  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
804  { NULL }
805 };
806 
808 
810  .name = "sobel",
811  .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
812  .priv_size = sizeof(ConvolutionContext),
813  .priv_class = &sobel_class,
814  .init = init,
816  .inputs = convolution_inputs,
817  .outputs = convolution_outputs,
819 };
820 
821 #endif /* CONFIG_SOBEL_FILTER */
822 
823 #if CONFIG_ROBERTS_FILTER
824 
825 static const AVOption roberts_options[] = {
826  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
827  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
828  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
829  { NULL }
830 };
831 
832 AVFILTER_DEFINE_CLASS(roberts);
833 
835  .name = "roberts",
836  .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
837  .priv_size = sizeof(ConvolutionContext),
838  .priv_class = &roberts_class,
839  .init = init,
841  .inputs = convolution_inputs,
842  .outputs = convolution_outputs,
844 };
845 
846 #endif /* CONFIG_ROBERTS_FILTER */
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:430
AVFrame * out
Definition: af_adeclick.c:488
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:422
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2522
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
int matrix[4][49]
Definition: convolution.h:51
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:424
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:397
static void filter16_sobel(uint8_t *dstp, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:407
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:425
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
misc image utilities
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2562
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)
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:168
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:403
static void filter16_column(uint8_t *dstp, int height, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
AVFilter ff_vf_prewitt
static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:367
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:391
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:99
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
char * matrix_str[4]
Definition: convolution.h:35
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
AVFilterFormats * ff_make_format_list(const int *fmts)
Create a list of supported formats.
Definition: formats.c:283
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:368
static void filter16_row(uint8_t *dstp, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#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 AV_PIX_FMT_GRAY12
Definition: pixfmt.h:369
static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
static void filter_7x7(uint8_t *dst, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1080
double peak
Definition: vf_tonemap.c:197
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
static void filter_5x5(uint8_t *dst, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
float delta
AVOptions.
#define f(width, name)
Definition: cbs_vp9.c:255
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:421
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:402
int height
Definition: vf_avgblur.c:61
AVFrame * dst
Definition: vf_blend.c:55
int plane
Definition: vf_blend.c:57
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:100
#define FFMIN3(a, b, c)
Definition: common.h:97
static const uint64_t c1
Definition: murmur3.c:49
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
void(* setup[4])(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int width, int y, int height, int bpc)
Definition: convolution.h:55
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:392
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:429
#define av_log(a,...)
AVFilter ff_vf_convolution
A filter pad used for either input or output.
Definition: internal.h:54
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:176
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
#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:568
#define td
Definition: regdef.h:70
static const int same7x7[49]
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
AVFilter ff_vf_sobel
BYTE * dstp
Definition: avisynth_c.h:908
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:202
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
static const AVFilterPad convolution_inputs[]
void * priv
private data for use by the filter
Definition: avfilter.h:353
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:116
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:431
const char * arg
Definition: jacosubdec.c:66
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:408
static void filter_row(uint8_t *dst, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:390
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:409
const uint8_t * src
Definition: vf_bm3d.c:56
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:385
static void filter16_prewitt(uint8_t *dstp, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:406
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:802
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:371
static const AVFilterPad convolution_outputs[]
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
static void filter16_3x3(uint8_t *dstp, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
static const AVOption convolution_options[]
AVFormatContext * ctx
Definition: movenc.c:48
static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
static void filter_prewitt(uint8_t *dst, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:426
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:386
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:405
static const AVFilterPad outputs[]
Definition: af_acontrast.c:203
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:398
static void filter_roberts(uint8_t *dst, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:395
Used for passing data between threads.
Definition: dsddec.c:64
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:177
AVFilter ff_vf_roberts
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static void filter_column(uint8_t *dst, int height, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:370
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
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:387
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
Filter definition.
Definition: avfilter.h:144
static void setup_3x3(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
AVFILTER_DEFINE_CLASS(convolution)
static const int same3x3[9]
static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:393
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:384
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:396
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:404
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
void ff_convolution_init_x86(ConvolutionContext *s)
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:394
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
char * av_strtok(char *s, const char *delim, char **saveptr)
Split the string into several tokens which can be accessed by successive calls to av_strtok()...
Definition: avstring.c:184
static void filter_sobel(uint8_t *dst, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
int
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
Y , 8bpp.
Definition: pixfmt.h:74
static void filter16_5x5(uint8_t *dstp, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:215
static const int same5x5[25]
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:423
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
avfilter_execute_func * execute
Definition: internal.h:155
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2029
static void filter16_roberts(uint8_t *dstp, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
static const struct @317 planes[]
const AVPixFmtDescriptor * desc
Definition: vf_tonemap.c:196
static void filter16_7x7(uint8_t *dstp, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:258
static void filter_3x3(uint8_t *dst, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
#define AV_RN16A(p)
Definition: intreadwrite.h:522
static int config_input(AVFilterLink *inlink)
#define FLAGS
An instance of a filter.
Definition: avfilter.h:338
#define OFFSET(x)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
AVFrame * in
Definition: af_afftdn.c:1082
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
#define stride
AVFilterLink * inlink
Definition: vf_blend.c:56
internal API functions
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
void(* filter[4])(uint8_t *dst, int width, float rdiv, float bias, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride)
Definition: convolution.h:57
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
mode
Use these values in ebur128_init (or&#39;ed).
Definition: ebur128.h:83
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:399
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