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 "config_components.h"
23 
24 #include "libavutil/avstring.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/intreadwrite.h"
27 #include "libavutil/mem_internal.h"
28 #include "libavutil/opt.h"
29 #include "libavutil/pixdesc.h"
30 #include "avfilter.h"
31 #include "convolution.h"
32 #include "internal.h"
33 #include "video.h"
34 
35 #define OFFSET(x) offsetof(ConvolutionContext, x)
36 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
37 
38 static const AVOption convolution_options[] = {
39  { "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 },
40  { "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 },
41  { "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 },
42  { "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 },
43  { "0rdiv", "set rdiv for 1st plane", OFFSET(user_rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
44  { "1rdiv", "set rdiv for 2nd plane", OFFSET(user_rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
45  { "2rdiv", "set rdiv for 3rd plane", OFFSET(user_rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
46  { "3rdiv", "set rdiv for 4th plane", OFFSET(user_rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
47  { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
48  { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
49  { "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
50  { "3bias", "set bias for 4th plane", OFFSET(bias[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
51  { "0mode", "set matrix mode for 1st plane", OFFSET(mode[0]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
52  { "1mode", "set matrix mode for 2nd plane", OFFSET(mode[1]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
53  { "2mode", "set matrix mode for 3rd plane", OFFSET(mode[2]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
54  { "3mode", "set matrix mode for 4th plane", OFFSET(mode[3]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, "mode" },
55  { "square", "square matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_SQUARE}, 0, 0, FLAGS, "mode" },
56  { "row", "single row matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_ROW} , 0, 0, FLAGS, "mode" },
57  { "column", "single column matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_COLUMN}, 0, 0, FLAGS, "mode" },
58  { NULL }
59 };
60 
61 AVFILTER_DEFINE_CLASS(convolution);
62 
63 static const int same3x3[9] = {0, 0, 0,
64  0, 1, 0,
65  0, 0, 0};
66 
67 static const int same5x5[25] = {0, 0, 0, 0, 0,
68  0, 0, 0, 0, 0,
69  0, 0, 1, 0, 0,
70  0, 0, 0, 0, 0,
71  0, 0, 0, 0, 0};
72 
73 static const int same7x7[49] = {0, 0, 0, 0, 0, 0, 0,
74  0, 0, 0, 0, 0, 0, 0,
75  0, 0, 0, 0, 0, 0, 0,
76  0, 0, 0, 1, 0, 0, 0,
77  0, 0, 0, 0, 0, 0, 0,
78  0, 0, 0, 0, 0, 0, 0,
79  0, 0, 0, 0, 0, 0, 0};
80 
81 static const enum AVPixelFormat pix_fmts[] = {
101 };
102 
103 typedef struct ThreadData {
104  AVFrame *in, *out;
105 } ThreadData;
106 
107 static void filter16_prewitt(uint8_t *dstp, int width,
108  float scale, float delta, const int *const matrix,
109  const uint8_t *c[], int peak, int radius,
110  int dstride, int stride, int size)
111 {
112  uint16_t *dst = (uint16_t *)dstp;
113  int x;
114 
115  for (x = 0; x < width; x++) {
116  float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * -1 +
117  AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 1 + AV_RN16A(&c[8][2 * x]) * 1;
118  float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1 +
119  AV_RN16A(&c[5][2 * x]) * 1 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
120 
121  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
122  }
123 }
124 
125 static void filter16_roberts(uint8_t *dstp, int width,
126  float scale, float delta, const int *const matrix,
127  const uint8_t *c[], int peak, int radius,
128  int dstride, int stride, int size)
129 {
130  uint16_t *dst = (uint16_t *)dstp;
131  int x;
132 
133  for (x = 0; x < width; x++) {
134  float suma = AV_RN16A(&c[0][2 * x]) * 1 + AV_RN16A(&c[1][2 * x]) * -1;
135  float sumb = AV_RN16A(&c[4][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1;
136 
137  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
138  }
139 }
140 
141 static void filter16_scharr(uint8_t *dstp, int width,
142  float scale, float delta, const int *const matrix,
143  const uint8_t *c[], int peak, int radius,
144  int dstride, int stride, int size)
145 {
146  uint16_t *dst = (uint16_t *)dstp;
147  int x;
148 
149  for (x = 0; x < width; x++) {
150  float suma = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[1][2 * x]) * -162 + AV_RN16A(&c[2][2 * x]) * -47 +
151  AV_RN16A(&c[6][2 * x]) * 47 + AV_RN16A(&c[7][2 * x]) * 162 + AV_RN16A(&c[8][2 * x]) * 47;
152  float sumb = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[2][2 * x]) * 47 + AV_RN16A(&c[3][2 * x]) * -162 +
153  AV_RN16A(&c[5][2 * x]) * 162 + AV_RN16A(&c[6][2 * x]) * -47 + AV_RN16A(&c[8][2 * x]) * 47;
154 
155  suma /= 256.f;
156  sumb /= 256.f;
157  dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
158  }
159 }
160 
161 static void filter16_kirsch(uint8_t *dstp, 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, int size)
165 {
166  uint16_t *dst = (uint16_t *)dstp;
167  const uint16_t *c0 = (const uint16_t *)c[0], *c1 = (const uint16_t *)c[1], *c2 = (const uint16_t *)c[2];
168  const uint16_t *c3 = (const uint16_t *)c[3], *c5 = (const uint16_t *)c[5];
169  const uint16_t *c6 = (const uint16_t *)c[6], *c7 = (const uint16_t *)c[7], *c8 = (const uint16_t *)c[8];
170  int x;
171 
172  for (x = 0; x < width; x++) {
173  int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
174  c3[x] * -3 + c5[x] * -3 +
175  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
176  int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
177  c3[x] * 5 + c5[x] * -3 +
178  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
179  int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
180  c3[x] * 5 + c5[x] * 5 +
181  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
182  int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
183  c3[x] * 5 + c5[x] * 5 +
184  c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
185  int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
186  c3[x] * -3 + c5[x] * 5 +
187  c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
188  int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
189  c3[x] * -3 + c5[x] * -3 +
190  c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
191  int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
192  c3[x] * -3 + c5[x] * -3 +
193  c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
194  int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
195  c3[x] * -3 + c5[x] * -3 +
196  c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
197 
198  sum0 = FFMAX(sum0, sum1);
199  sum2 = FFMAX(sum2, sum3);
200  sum4 = FFMAX(sum4, sum5);
201  sum6 = FFMAX(sum6, sum7);
202  sum0 = FFMAX(sum0, sum2);
203  sum4 = FFMAX(sum4, sum6);
204  sum0 = FFMAX(sum0, sum4);
205 
206  dst[x] = av_clip(FFABS(sum0) * scale + delta, 0, peak);
207  }
208 }
209 
210 static void filter_prewitt(uint8_t *dst, int width,
211  float scale, float delta, const int *const matrix,
212  const uint8_t *c[], int peak, int radius,
213  int dstride, int stride, int size)
214 {
215  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
216  const uint8_t *c3 = c[3], *c5 = c[5];
217  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
218  int x;
219 
220  for (x = 0; x < width; x++) {
221  float suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
222  c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
223  float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
224  c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
225 
226  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
227  }
228 }
229 
230 static void filter_roberts(uint8_t *dst, int width,
231  float scale, float delta, const int *const matrix,
232  const uint8_t *c[], int peak, int radius,
233  int dstride, int stride, int size)
234 {
235  int x;
236 
237  for (x = 0; x < width; x++) {
238  float suma = c[0][x] * 1 + c[1][x] * -1;
239  float sumb = c[4][x] * 1 + c[3][x] * -1;
240 
241  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
242  }
243 }
244 
245 static void filter_scharr(uint8_t *dst, int width,
246  float scale, float delta, const int *const matrix,
247  const uint8_t *c[], int peak, int radius,
248  int dstride, int stride, int size)
249 {
250  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
251  const uint8_t *c3 = c[3], *c5 = c[5];
252  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
253  int x;
254 
255  for (x = 0; x < width; x++) {
256  float suma = c0[x] * -47 + c1[x] * -162 + c2[x] * -47 +
257  c6[x] * 47 + c7[x] * 162 + c8[x] * 47;
258  float sumb = c0[x] * -47 + c2[x] * 47 + c3[x] * -162 +
259  c5[x] * 162 + c6[x] * -47 + c8[x] * 47;
260 
261  suma /= 256.f;
262  sumb /= 256.f;
263  dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
264  }
265 }
266 
267 static void filter_kirsch(uint8_t *dst, int width,
268  float scale, float delta, const int *const matrix,
269  const uint8_t *c[], int peak, int radius,
270  int dstride, int stride, int size)
271 {
272  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
273  const uint8_t *c3 = c[3], *c5 = c[5];
274  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
275  int x;
276 
277  for (x = 0; x < width; x++) {
278  int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
279  c3[x] * -3 + c5[x] * -3 +
280  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
281  int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
282  c3[x] * 5 + c5[x] * -3 +
283  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
284  int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
285  c3[x] * 5 + c5[x] * 5 +
286  c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
287  int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
288  c3[x] * 5 + c5[x] * 5 +
289  c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
290  int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
291  c3[x] * -3 + c5[x] * 5 +
292  c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
293  int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
294  c3[x] * -3 + c5[x] * -3 +
295  c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
296  int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
297  c3[x] * -3 + c5[x] * -3 +
298  c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
299  int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
300  c3[x] * -3 + c5[x] * -3 +
301  c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
302 
303  sum0 = FFMAX(sum0, sum1);
304  sum2 = FFMAX(sum2, sum3);
305  sum4 = FFMAX(sum4, sum5);
306  sum6 = FFMAX(sum6, sum7);
307  sum0 = FFMAX(sum0, sum2);
308  sum4 = FFMAX(sum4, sum6);
309  sum0 = FFMAX(sum0, sum4);
310 
311  dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta);
312  }
313 }
314 
315 static void filter16_3x3(uint8_t *dstp, int width,
316  float rdiv, float bias, const int *const matrix,
317  const uint8_t *c[], int peak, int radius,
318  int dstride, int stride, int size)
319 {
320  uint16_t *dst = (uint16_t *)dstp;
321  int x;
322 
323  for (x = 0; x < width; x++) {
324  int sum = AV_RN16A(&c[0][2 * x]) * matrix[0] +
325  AV_RN16A(&c[1][2 * x]) * matrix[1] +
326  AV_RN16A(&c[2][2 * x]) * matrix[2] +
327  AV_RN16A(&c[3][2 * x]) * matrix[3] +
328  AV_RN16A(&c[4][2 * x]) * matrix[4] +
329  AV_RN16A(&c[5][2 * x]) * matrix[5] +
330  AV_RN16A(&c[6][2 * x]) * matrix[6] +
331  AV_RN16A(&c[7][2 * x]) * matrix[7] +
332  AV_RN16A(&c[8][2 * x]) * matrix[8];
333  sum = (int)(sum * rdiv + bias + 0.5f);
334  dst[x] = av_clip(sum, 0, peak);
335  }
336 }
337 
338 static void filter16_5x5(uint8_t *dstp, int width,
339  float rdiv, float bias, const int *const matrix,
340  const uint8_t *c[], int peak, int radius,
341  int dstride, int stride, int size)
342 {
343  uint16_t *dst = (uint16_t *)dstp;
344  int x;
345 
346  for (x = 0; x < width; x++) {
347  int i, sum = 0;
348 
349  for (i = 0; i < 25; i++)
350  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
351 
352  sum = (int)(sum * rdiv + bias + 0.5f);
353  dst[x] = av_clip(sum, 0, peak);
354  }
355 }
356 
357 static void filter16_7x7(uint8_t *dstp, int width,
358  float rdiv, float bias, const int *const matrix,
359  const uint8_t *c[], int peak, int radius,
360  int dstride, int stride, int size)
361 {
362  uint16_t *dst = (uint16_t *)dstp;
363  int x;
364 
365  for (x = 0; x < width; x++) {
366  int i, sum = 0;
367 
368  for (i = 0; i < 49; i++)
369  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
370 
371  sum = (int)(sum * rdiv + bias + 0.5f);
372  dst[x] = av_clip(sum, 0, peak);
373  }
374 }
375 
376 static void filter16_row(uint8_t *dstp, int width,
377  float rdiv, float bias, const int *const matrix,
378  const uint8_t *c[], int peak, int radius,
379  int dstride, int stride, int size)
380 {
381  uint16_t *dst = (uint16_t *)dstp;
382  int x;
383 
384  for (x = 0; x < width; x++) {
385  int i, sum = 0;
386 
387  for (i = 0; i < 2 * radius + 1; i++)
388  sum += AV_RN16A(&c[i][2 * x]) * matrix[i];
389 
390  sum = (int)(sum * rdiv + bias + 0.5f);
391  dst[x] = av_clip(sum, 0, peak);
392  }
393 }
394 
395 static void filter16_column(uint8_t *dstp, int height,
396  float rdiv, float bias, const int *const matrix,
397  const uint8_t *c[], int peak, int radius,
398  int dstride, int stride, int size)
399 {
400  DECLARE_ALIGNED(64, int, sum)[16];
401  uint16_t *dst = (uint16_t *)dstp;
402  const int width = FFMIN(16, size);
403 
404  for (int y = 0; y < height; y++) {
405 
406  memset(sum, 0, sizeof(sum));
407  for (int i = 0; i < 2 * radius + 1; i++) {
408  for (int off16 = 0; off16 < width; off16++)
409  sum[off16] += AV_RN16A(&c[i][0 + y * stride + off16 * 2]) * matrix[i];
410  }
411 
412  for (int off16 = 0; off16 < width; off16++) {
413  sum[off16] = (int)(sum[off16] * rdiv + bias + 0.5f);
414  dst[off16] = av_clip(sum[off16], 0, peak);
415  }
416  dst += dstride / 2;
417  }
418 }
419 
420 static void filter_7x7(uint8_t *dst, int width,
421  float rdiv, float bias, const int *const matrix,
422  const uint8_t *c[], int peak, int radius,
423  int dstride, int stride, int size)
424 {
425  int x;
426 
427  for (x = 0; x < width; x++) {
428  int i, sum = 0;
429 
430  for (i = 0; i < 49; i++)
431  sum += c[i][x] * matrix[i];
432 
433  sum = (int)(sum * rdiv + bias + 0.5f);
434  dst[x] = av_clip_uint8(sum);
435  }
436 }
437 
438 static void filter_5x5(uint8_t *dst, int width,
439  float rdiv, float bias, const int *const matrix,
440  const uint8_t *c[], int peak, int radius,
441  int dstride, int stride, int size)
442 {
443  int x;
444 
445  for (x = 0; x < width; x++) {
446  int i, sum = 0;
447 
448  for (i = 0; i < 25; i++)
449  sum += c[i][x] * matrix[i];
450 
451  sum = (int)(sum * rdiv + bias + 0.5f);
452  dst[x] = av_clip_uint8(sum);
453  }
454 }
455 
456 static void filter_3x3(uint8_t *dst, int width,
457  float rdiv, float bias, const int *const matrix,
458  const uint8_t *c[], int peak, int radius,
459  int dstride, int stride, int size)
460 {
461  const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
462  const uint8_t *c3 = c[3], *c4 = c[4], *c5 = c[5];
463  const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
464  int x;
465 
466  for (x = 0; x < width; x++) {
467  int sum = c0[x] * matrix[0] + c1[x] * matrix[1] + c2[x] * matrix[2] +
468  c3[x] * matrix[3] + c4[x] * matrix[4] + c5[x] * matrix[5] +
469  c6[x] * matrix[6] + c7[x] * matrix[7] + c8[x] * matrix[8];
470  sum = (int)(sum * rdiv + bias + 0.5f);
471  dst[x] = av_clip_uint8(sum);
472  }
473 }
474 
475 static void filter_row(uint8_t *dst, int width,
476  float rdiv, float bias, const int *const matrix,
477  const uint8_t *c[], int peak, int radius,
478  int dstride, int stride, int size)
479 {
480  int x;
481 
482  for (x = 0; x < width; x++) {
483  int i, sum = 0;
484 
485  for (i = 0; i < 2 * radius + 1; i++)
486  sum += c[i][x] * matrix[i];
487 
488  sum = (int)(sum * rdiv + bias + 0.5f);
489  dst[x] = av_clip_uint8(sum);
490  }
491 }
492 
493 static void filter_column(uint8_t *dst, int height,
494  float rdiv, float bias, const int *const matrix,
495  const uint8_t *c[], int peak, int radius,
496  int dstride, int stride, int size)
497 {
498  DECLARE_ALIGNED(64, int, sum)[16];
499 
500  for (int y = 0; y < height; y++) {
501  memset(sum, 0, sizeof(sum));
502 
503  for (int i = 0; i < 2 * radius + 1; i++) {
504  for (int off16 = 0; off16 < 16; off16++)
505  sum[off16] += c[i][0 + y * stride + off16] * matrix[i];
506  }
507 
508  for (int off16 = 0; off16 < 16; off16++) {
509  sum[off16] = (int)(sum[off16] * rdiv + bias + 0.5f);
510  dst[off16] = av_clip_uint8(sum[off16]);
511  }
512  dst += dstride;
513  }
514 }
515 
516 static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride,
517  int x, int w, int y, int h, int bpc)
518 {
519  int i;
520 
521  for (i = 0; i < 25; i++) {
522  int xoff = FFABS(x + ((i % 5) - 2));
523  int yoff = FFABS(y + (i / 5) - 2);
524 
525  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
526  yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
527 
528  c[i] = src + xoff * bpc + yoff * stride;
529  }
530 }
531 
532 static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride,
533  int x, int w, int y, int h, int bpc)
534 {
535  int i;
536 
537  for (i = 0; i < 49; i++) {
538  int xoff = FFABS(x + ((i % 7) - 3));
539  int yoff = FFABS(y + (i / 7) - 3);
540 
541  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
542  yoff = yoff >= h ? 2 * h - 1 - yoff : yoff;
543 
544  c[i] = src + xoff * bpc + yoff * stride;
545  }
546 }
547 
548 static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int stride,
549  int x, int w, int y, int h, int bpc)
550 {
551  int i;
552 
553  for (i = 0; i < radius * 2 + 1; i++) {
554  int xoff = FFABS(x + i - radius);
555 
556  xoff = xoff >= w ? 2 * w - 1 - xoff : xoff;
557 
558  c[i] = src + xoff * bpc + y * stride;
559  }
560 }
561 
562 static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int stride,
563  int x, int w, int y, int h, int bpc)
564 {
565  int i;
566 
567  for (i = 0; i < radius * 2 + 1; i++) {
568  int xoff = FFABS(x + i - radius);
569 
570  xoff = xoff >= h ? 2 * h - 1 - xoff : xoff;
571 
572  c[i] = src + y * bpc + xoff * stride;
573  }
574 }
575 
576 static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
577 {
578  ConvolutionContext *s = ctx->priv;
579  ThreadData *td = arg;
580  AVFrame *in = td->in;
581  AVFrame *out = td->out;
582  int plane;
583 
584  for (plane = 0; plane < s->nb_planes; plane++) {
585  const int mode = s->mode[plane];
586  const int bpc = s->bpc;
587  const int radius = s->size[plane] / 2;
588  const int height = s->planeheight[plane];
589  const int width = s->planewidth[plane];
590  const int stride = in->linesize[plane];
591  const int dstride = out->linesize[plane];
592  const int sizeh = mode == MATRIX_COLUMN ? width : height;
593  const int sizew = mode == MATRIX_COLUMN ? height : width;
594  const int slice_start = (sizeh * jobnr) / nb_jobs;
595  const int slice_end = (sizeh * (jobnr+1)) / nb_jobs;
596  const float rdiv = s->rdiv[plane];
597  const float bias = s->bias[plane];
598  const uint8_t *src = in->data[plane];
599  const int dst_pos = slice_start * (mode == MATRIX_COLUMN ? bpc : dstride);
600  uint8_t *dst = out->data[plane] + dst_pos;
601  const int *matrix = s->matrix[plane];
602  const int step = mode == MATRIX_COLUMN ? 16 : 1;
603  const uint8_t *c[49];
604  int y, x;
605 
606  if (s->copy[plane]) {
607  if (mode == MATRIX_COLUMN)
608  av_image_copy_plane(dst, dstride, src + slice_start * bpc, stride,
609  (slice_end - slice_start) * bpc, height);
610  else
611  av_image_copy_plane(dst, dstride, src + slice_start * stride, stride,
612  width * bpc, slice_end - slice_start);
613  continue;
614  }
615  for (y = slice_start; y < slice_end; y += step) {
616  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : radius * bpc;
617  const int yoff = mode == MATRIX_COLUMN ? radius * dstride : 0;
618 
619  for (x = 0; x < radius; x++) {
620  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
621  const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
622 
623  s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
624  s->filter[plane](dst + yoff + xoff, 1, rdiv,
625  bias, matrix, c, s->max, radius,
626  dstride, stride, slice_end - step);
627  }
628  s->setup[plane](radius, c, src, stride, radius, width, y, height, bpc);
629  s->filter[plane](dst + yoff + xoff, sizew - 2 * radius,
630  rdiv, bias, matrix, c, s->max, radius,
631  dstride, stride, slice_end - step);
632  for (x = sizew - radius; x < sizew; x++) {
633  const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
634  const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
635 
636  s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
637  s->filter[plane](dst + yoff + xoff, 1, rdiv,
638  bias, matrix, c, s->max, radius,
639  dstride, stride, slice_end - step);
640  }
641  if (mode != MATRIX_COLUMN)
642  dst += dstride;
643  }
644  }
645 
646  return 0;
647 }
648 
650 {
651  ConvolutionContext *s = ctx->priv;
652  AVFilterLink *inlink = ctx->inputs[0];
654  int p, i;
655 
656  s->depth = desc->comp[0].depth;
657  s->max = (1 << s->depth) - 1;
658 
659  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
660  s->planewidth[0] = s->planewidth[3] = inlink->w;
661  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
662  s->planeheight[0] = s->planeheight[3] = inlink->h;
663 
664  s->nb_planes = av_pix_fmt_count_planes(inlink->format);
665  s->nb_threads = ff_filter_get_nb_threads(ctx);
666  s->bpc = (s->depth + 7) / 8;
667 
668  if (!strcmp(ctx->filter->name, "convolution")) {
669  for (i = 0; i < 4; i++) {
670  int *matrix = (int *)s->matrix[i];
671  char *orig, *p, *arg, *saveptr = NULL;
672  float sum = 1.f;
673 
674  p = orig = av_strdup(s->matrix_str[i]);
675  if (p) {
676  s->matrix_length[i] = 0;
677  s->rdiv[i] = s->user_rdiv[i];
678  sum = 0.f;
679 
680  while (s->matrix_length[i] < 49) {
681  if (!(arg = av_strtok(p, " |", &saveptr)))
682  break;
683 
684  p = NULL;
685  sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
686  sum += matrix[s->matrix_length[i]];
687  s->matrix_length[i]++;
688  }
689 
690  av_freep(&orig);
691  if (!(s->matrix_length[i] & 1)) {
692  av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
693  return AVERROR(EINVAL);
694  }
695  }
696 
697  if (s->mode[i] == MATRIX_ROW) {
698  s->filter[i] = filter_row;
699  s->setup[i] = setup_row;
700  s->size[i] = s->matrix_length[i];
701  } else if (s->mode[i] == MATRIX_COLUMN) {
702  s->filter[i] = filter_column;
703  s->setup[i] = setup_column;
704  s->size[i] = s->matrix_length[i];
705  } else if (s->matrix_length[i] == 9) {
706  s->size[i] = 3;
707 
708  if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
709  s->copy[i] = 1;
710  } else {
711  s->filter[i] = filter_3x3;
712  s->copy[i] = 0;
713  }
714  s->setup[i] = setup_3x3;
715  } else if (s->matrix_length[i] == 25) {
716  s->size[i] = 5;
717  if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
718  s->copy[i] = 1;
719  } else {
720  s->filter[i] = filter_5x5;
721  s->copy[i] = 0;
722  }
723  s->setup[i] = setup_5x5;
724  } else if (s->matrix_length[i] == 49) {
725  s->size[i] = 7;
726  if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
727  s->copy[i] = 1;
728  } else {
729  s->filter[i] = filter_7x7;
730  s->copy[i] = 0;
731  }
732  s->setup[i] = setup_7x7;
733  } else {
734  return AVERROR(EINVAL);
735  }
736 
737  if (sum == 0)
738  sum = 1;
739  if (s->rdiv[i] == 0)
740  s->rdiv[i] = 1. / sum;
741 
742  if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
743  s->copy[i] = 0;
744  }
745  } else if (!strcmp(ctx->filter->name, "prewitt")) {
746  for (i = 0; i < 4; i++) {
747  s->filter[i] = filter_prewitt;
748  s->copy[i] = !((1 << i) & s->planes);
749  s->size[i] = 3;
750  s->setup[i] = setup_3x3;
751  s->rdiv[i] = s->scale;
752  s->bias[i] = s->delta;
753  }
754  } else if (!strcmp(ctx->filter->name, "roberts")) {
755  for (i = 0; i < 4; i++) {
756  s->filter[i] = filter_roberts;
757  s->copy[i] = !((1 << i) & s->planes);
758  s->size[i] = 3;
759  s->setup[i] = setup_3x3;
760  s->rdiv[i] = s->scale;
761  s->bias[i] = s->delta;
762  }
763  } else if (!strcmp(ctx->filter->name, "sobel")) {
764  ff_sobel_init(s, s->depth, s->nb_planes);
765  } else if (!strcmp(ctx->filter->name, "kirsch")) {
766  for (i = 0; i < 4; i++) {
767  s->filter[i] = filter_kirsch;
768  s->copy[i] = !((1 << i) & s->planes);
769  s->size[i] = 3;
770  s->setup[i] = setup_3x3;
771  s->rdiv[i] = s->scale;
772  s->bias[i] = s->delta;
773  }
774  } else if (!strcmp(ctx->filter->name, "scharr")) {
775  for (i = 0; i < 4; i++) {
776  s->filter[i] = filter_scharr;
777  s->copy[i] = !((1 << i) & s->planes);
778  s->size[i] = 3;
779  s->setup[i] = setup_3x3;
780  s->rdiv[i] = s->scale;
781  s->bias[i] = s->delta;
782  }
783  }
784 
785  if (!strcmp(ctx->filter->name, "convolution")) {
786  if (s->depth > 8) {
787  for (p = 0; p < s->nb_planes; p++) {
788  if (s->mode[p] == MATRIX_ROW)
789  s->filter[p] = filter16_row;
790  else if (s->mode[p] == MATRIX_COLUMN)
791  s->filter[p] = filter16_column;
792  else if (s->size[p] == 3)
793  s->filter[p] = filter16_3x3;
794  else if (s->size[p] == 5)
795  s->filter[p] = filter16_5x5;
796  else if (s->size[p] == 7)
797  s->filter[p] = filter16_7x7;
798  }
799  }
800 #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64
802 #endif
803  } else if (!strcmp(ctx->filter->name, "prewitt")) {
804  if (s->depth > 8)
805  for (p = 0; p < s->nb_planes; p++)
806  s->filter[p] = filter16_prewitt;
807  } else if (!strcmp(ctx->filter->name, "roberts")) {
808  if (s->depth > 8)
809  for (p = 0; p < s->nb_planes; p++)
810  s->filter[p] = filter16_roberts;
811  } else if (!strcmp(ctx->filter->name, "kirsch")) {
812  if (s->depth > 8)
813  for (p = 0; p < s->nb_planes; p++)
814  s->filter[p] = filter16_kirsch;
815  } else if (!strcmp(ctx->filter->name, "scharr")) {
816  if (s->depth > 8)
817  for (p = 0; p < s->nb_planes; p++)
818  s->filter[p] = filter16_scharr;
819  }
820 
821  return 0;
822 }
823 
825 {
826  AVFilterContext *ctx = inlink->dst;
827  return param_init(ctx);
828 }
829 
831 {
832  AVFilterContext *ctx = inlink->dst;
833  ConvolutionContext *s = ctx->priv;
834  AVFilterLink *outlink = ctx->outputs[0];
835  AVFrame *out;
836  ThreadData td;
837 
838  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
839  if (!out) {
840  av_frame_free(&in);
841  return AVERROR(ENOMEM);
842  }
844 
845  td.in = in;
846  td.out = out;
848  FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads));
849 
850  av_frame_free(&in);
851  return ff_filter_frame(outlink, out);
852 }
853 
854 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
855  char *res, int res_len, int flags)
856 {
857  int ret;
858 
859  ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
860  if (ret < 0)
861  return ret;
862 
863  return param_init(ctx);
864 }
865 
866 static const AVFilterPad convolution_inputs[] = {
867  {
868  .name = "default",
869  .type = AVMEDIA_TYPE_VIDEO,
870  .config_props = config_input,
871  .filter_frame = filter_frame,
872  },
873 };
874 
875 #if CONFIG_CONVOLUTION_FILTER
876 
877 const AVFilter ff_vf_convolution = {
878  .name = "convolution",
879  .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
880  .priv_size = sizeof(ConvolutionContext),
881  .priv_class = &convolution_class,
886  .process_command = process_command,
887 };
888 
889 #endif /* CONFIG_CONVOLUTION_FILTER */
890 
891 static const AVOption common_options[] = {
892  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
893  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
894  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
895  { NULL }
896 };
897 
898 AVFILTER_DEFINE_CLASS_EXT(common, "kirsch/prewitt/roberts/scharr/sobel",
900 
901 #if CONFIG_PREWITT_FILTER
902 
903 const AVFilter ff_vf_prewitt = {
904  .name = "prewitt",
905  .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
906  .priv_size = sizeof(ConvolutionContext),
907  .priv_class = &common_class,
912  .process_command = process_command,
913 };
914 
915 #endif /* CONFIG_PREWITT_FILTER */
916 
917 #if CONFIG_SOBEL_FILTER
918 
919 const AVFilter ff_vf_sobel = {
920  .name = "sobel",
921  .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
922  .priv_size = sizeof(ConvolutionContext),
923  .priv_class = &common_class,
928  .process_command = process_command,
929 };
930 
931 #endif /* CONFIG_SOBEL_FILTER */
932 
933 #if CONFIG_ROBERTS_FILTER
934 
935 const AVFilter ff_vf_roberts = {
936  .name = "roberts",
937  .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
938  .priv_size = sizeof(ConvolutionContext),
939  .priv_class = &common_class,
944  .process_command = process_command,
945 };
946 
947 #endif /* CONFIG_ROBERTS_FILTER */
948 
949 #if CONFIG_KIRSCH_FILTER
950 
951 const AVFilter ff_vf_kirsch = {
952  .name = "kirsch",
953  .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
954  .priv_size = sizeof(ConvolutionContext),
955  .priv_class = &common_class,
960  .process_command = process_command,
961 };
962 
963 #endif /* CONFIG_KIRSCH_FILTER */
964 
965 #if CONFIG_SCHARR_FILTER
966 
967 const AVFilter ff_vf_scharr = {
968  .name = "scharr",
969  .description = NULL_IF_CONFIG_SMALL("Apply scharr operator."),
970  .priv_size = sizeof(ConvolutionContext),
971  .priv_class = &common_class,
976  .process_command = process_command,
977 };
978 
979 #endif /* CONFIG_SCHARR_FILTER */
ff_get_video_buffer
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:108
AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:512
AV_PIX_FMT_GBRAP16
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:491
setup_3x3
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)
Definition: convolution.h:68
td
#define td
Definition: regdef.h:70
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
av_clip
#define av_clip
Definition: common.h:96
OFFSET
#define OFFSET(x)
Definition: vf_convolution.c:35
AVERROR
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
opt.h
mem_internal.h
out
FILE * out
Definition: movenc.c:54
filter_prewitt
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, int size)
Definition: vf_convolution.c:210
ff_filter_frame
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:978
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
ff_vf_scharr
const AVFilter ff_vf_scharr
matrix
Definition: vc1dsp.c:42
FILTER_PIXFMTS_ARRAY
#define FILTER_PIXFMTS_ARRAY(array)
Definition: internal.h:172
ff_vf_roberts
const AVFilter ff_vf_roberts
inlink
The exact code depends on how similar the blocks are and how related they are to the and needs to apply these operations to the correct inlink or outlink if there are several Macros are available to factor that when no extra processing is inlink
Definition: filter_design.txt:212
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AV_PIX_FMT_YUVA422P9
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:504
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
pixdesc.h
step
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
Definition: rate_distortion.txt:58
AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:511
w
uint8_t w
Definition: llviddspenc.c:38
AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:506
ff_vf_kirsch
const AVFilter ff_vf_kirsch
AVOption
AVOption.
Definition: opt.h:251
AV_PIX_FMT_YUV420P10
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:468
ff_vf_prewitt
const AVFilter ff_vf_prewitt
AV_PIX_FMT_YUV440P
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:99
filter_frame
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: vf_convolution.c:830
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVFilter::name
const char * name
Filter name.
Definition: avfilter.h:170
filter16_7x7
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, int size)
Definition: vf_convolution.c:357
c1
static const uint64_t c1
Definition: murmur3.c:52
filter16_scharr
static void filter16_scharr(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, int size)
Definition: vf_convolution.c:141
ThreadData::out
AVFrame * out
Definition: af_adeclick.c:526
ff_sobel_init
static av_unused void ff_sobel_init(ConvolutionContext *s, int depth, int nb_planes)
Definition: convolution.h:122
convolution.h
video.h
ThreadData::in
AVFrame * in
Definition: af_adecorrelate.c:153
AV_PIX_FMT_YUVA422P10
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:507
AV_PIX_FMT_GRAY9
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:448
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_image_copy_plane
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:374
filter_slice
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
Definition: vf_convolution.c:576
setup_row
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)
Definition: vf_convolution.c:548
same3x3
static const int same3x3[9]
Definition: vf_convolution.c:63
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3004
AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:503
AV_PIX_FMT_GBRP14
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:486
AV_PIX_FMT_GBRAP
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:205
AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:484
AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_YUVA444P16
Definition: pixfmt.h:513
AV_PIX_FMT_YUV422P9
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:466
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
AV_PIX_FMT_GRAY16
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:452
AVFilterPad
A filter pad used for either input or output.
Definition: internal.h:47
AVFILTER_DEFINE_CLASS
AVFILTER_DEFINE_CLASS(convolution)
convolution_inputs
static const AVFilterPad convolution_inputs[]
Definition: vf_convolution.c:866
AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:471
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:276
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:480
MATRIX_NBMODES
@ MATRIX_NBMODES
Definition: convolution.h:30
ff_video_default_filterpad
const AVFilterPad ff_video_default_filterpad[1]
An AVFilterPad array whose only entry has name "default" and is of type AVMEDIA_TYPE_VIDEO.
Definition: video.c:36
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:488
width
#define width
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:198
MATRIX_SQUARE
@ MATRIX_SQUARE
Definition: convolution.h:27
AV_PIX_FMT_GBRAP12
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:489
AV_PIX_FMT_YUVA420P
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:101
AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:481
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
slice_end
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:1979
av_strtok
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:178
AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUVA444P12
Definition: pixfmt.h:510
AV_PIX_FMT_YUV420P9
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:465
AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:479
ctx
AVFormatContext * ctx
Definition: movenc.c:48
process_command
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
Definition: vf_convolution.c:854
AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_GRAY14
Definition: pixfmt.h:451
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
FILTER_INPUTS
#define FILTER_INPUTS(array)
Definition: internal.h:192
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
arg
const char * arg
Definition: jacosubdec.c:67
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:449
AV_PIX_FMT_GBRP16
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:487
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:736
bias
static int bias(int x, int c)
Definition: vqcdec.c:113
MATRIX_ROW
@ MATRIX_ROW
Definition: convolution.h:28
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
sqrtf
static __device__ float sqrtf(float a)
Definition: cuda_runtime.h:184
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: vf_convolution.c:81
ConvolutionContext
Definition: convolution.h:33
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:469
common_options
static const AVOption common_options[]
Definition: vf_convolution.c:891
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_PIX_FMT_GBRP9
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:483
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
filter16_3x3
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, int size)
Definition: vf_convolution.c:315
ff_vf_convolution
const AVFilter ff_vf_convolution
f
f
Definition: af_crystalizer.c:121
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:106
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
convolution_options
static const AVOption convolution_options[]
Definition: vf_convolution.c:38
AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:473
size
int size
Definition: twinvq_data.h:10344
filter16_prewitt
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, int size)
Definition: vf_convolution.c:107
AV_PIX_FMT_YUV444P12
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:475
filter16_column
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, int size)
Definition: vf_convolution.c:395
setup_5x5
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)
Definition: vf_convolution.c:516
filter16_roberts
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, int size)
Definition: vf_convolution.c:125
ff_filter_process_command
int ff_filter_process_command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Generic processing of user supplied commands that are set in the same way as the filter options.
Definition: avfilter.c:851
config_input
static int config_input(AVFilterLink *inlink)
Definition: vf_convolution.c:824
height
#define height
AV_PIX_FMT_YUVA444P
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:167
AV_PIX_FMT_YUVA444P10
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:508
filter_row
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, int size)
Definition: vf_convolution.c:475
same5x5
static const int same5x5[25]
Definition: vf_convolution.c:67
internal.h
AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
#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:147
AV_OPT_TYPE_FLOAT
@ AV_OPT_TYPE_FLOAT
Definition: opt.h:228
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
filter_kirsch
static void filter_kirsch(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, int size)
Definition: vf_convolution.c:267
param_init
static int param_init(AVFilterContext *ctx)
Definition: vf_convolution.c:649
FFMIN3
#define FFMIN3(a, b, c)
Definition: macros.h:50
AV_PIX_FMT_GBRP12
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:485
ff_filter_get_nb_threads
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:786
delta
float delta
Definition: vorbis_enc_data.h:430
ThreadData
Used for passing data between threads.
Definition: dsddec.c:69
planes
static const struct @363 planes[]
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
same7x7
static const int same7x7[49]
Definition: vf_convolution.c:73
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
AVFilterPad::name
const char * name
Pad name.
Definition: internal.h:53
setup_7x7
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)
Definition: vf_convolution.c:532
AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:467
filter_scharr
static void filter_scharr(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, int size)
Definition: vf_convolution.c:245
setup_column
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)
Definition: vf_convolution.c:562
stride
#define stride
Definition: h264pred_template.c:537
AVFilter
Filter definition.
Definition: avfilter.h:166
filter_3x3
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, int size)
Definition: vf_convolution.c:456
filter_7x7
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 size)
Definition: vf_convolution.c:420
ret
ret
Definition: filter_design.txt:187
AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:505
filter_column
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, int size)
Definition: vf_convolution.c:493
AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:472
filter_roberts
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, int size)
Definition: vf_convolution.c:230
AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:477
c2
static const uint64_t c2
Definition: murmur3.c:53
AVFILTER_DEFINE_CLASS_EXT
AVFILTER_DEFINE_CLASS_EXT(common, "kirsch/prewitt/roberts/scharr/sobel", common_options)
mode
mode
Definition: ebur128.h:83
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_PIX_FMT_YUVA422P12
#define AV_PIX_FMT_YUVA422P12
Definition: pixfmt.h:509
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
avfilter.h
AV_RN16A
#define AV_RN16A(p)
Definition: intreadwrite.h:520
FLAGS
#define FLAGS
Definition: vf_convolution.c:36
filter16_5x5
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, int size)
Definition: vf_convolution.c:338
filter_5x5
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, int size)
Definition: vf_convolution.c:438
av_clip_uint8
#define av_clip_uint8
Definition: common.h:102
AV_PIX_FMT_YUV444P
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
AVFilterContext
An instance of a filter.
Definition: avfilter.h:397
MATRIX_COLUMN
@ MATRIX_COLUMN
Definition: convolution.h:29
ff_vf_sobel
const AVFilter ff_vf_sobel
AV_PIX_FMT_GBRP
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:158
AVFILTER_FLAG_SLICE_THREADS
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
Definition: avfilter.h:117
av_strdup
char * av_strdup(const char *s)
Duplicate a string.
Definition: mem.c:270
desc
const char * desc
Definition: libsvtav1.c:83
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
ff_convolution_init_x86
void ff_convolution_init_x86(ConvolutionContext *s)
Definition: vf_convolution_init.c:37
FILTER_OUTPUTS
#define FILTER_OUTPUTS(array)
Definition: internal.h:193
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AV_PIX_FMT_YUV411P
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:73
filter16_kirsch
static void filter16_kirsch(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, int size)
Definition: vf_convolution.c:161
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
AV_PIX_FMT_YUV410P
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:474
h
h
Definition: vp9dsp_template.c:2038
AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:478
avstring.h
AV_OPT_TYPE_STRING
@ AV_OPT_TYPE_STRING
Definition: opt.h:229
AV_PIX_FMT_GRAY12
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:450
ff_filter_execute
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
Definition: internal.h:144
int
int
Definition: ffmpeg_filter.c:368
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
filter16_row
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, int size)
Definition: vf_convolution.c:376
AV_PIX_FMT_YUVA422P
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:166
AV_PIX_FMT_YUV420P14
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:476