FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_convolution.c
Date: 2026-09-30 17:13:31
Exec Total Coverage
Lines: 0 456 0.0%
Functions: 0 27 0.0%
Branches: 0 206 0.0%

Line Branch Exec Source
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.h"
28 #include "libavutil/mem_internal.h"
29 #include "libavutil/opt.h"
30 #include "libavutil/pixdesc.h"
31 #include "avfilter.h"
32 #include "convolution.h"
33 #include "filters.h"
34 #include "video.h"
35
36 #define OFFSET(x) offsetof(ConvolutionContext, x)
37 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
38
39 static const AVOption convolution_options[] = {
40 { "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 },
41 { "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 },
42 { "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 },
43 { "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 },
44 { "0rdiv", "set rdiv for 1st plane", OFFSET(user_rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
45 { "1rdiv", "set rdiv for 2nd plane", OFFSET(user_rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
46 { "2rdiv", "set rdiv for 3rd plane", OFFSET(user_rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
47 { "3rdiv", "set rdiv for 4th plane", OFFSET(user_rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
48 { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
49 { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
50 { "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
51 { "3bias", "set bias for 4th plane", OFFSET(bias[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
52 { "0mode", "set matrix mode for 1st plane", OFFSET(mode[0]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, .unit = "mode" },
53 { "1mode", "set matrix mode for 2nd plane", OFFSET(mode[1]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, .unit = "mode" },
54 { "2mode", "set matrix mode for 3rd plane", OFFSET(mode[2]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, .unit = "mode" },
55 { "3mode", "set matrix mode for 4th plane", OFFSET(mode[3]), AV_OPT_TYPE_INT, {.i64=MATRIX_SQUARE}, 0, MATRIX_NBMODES-1, FLAGS, .unit = "mode" },
56 { "square", "square matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_SQUARE}, 0, 0, FLAGS, .unit = "mode" },
57 { "row", "single row matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_ROW} , 0, 0, FLAGS, .unit = "mode" },
58 { "column", "single column matrix", 0, AV_OPT_TYPE_CONST, {.i64=MATRIX_COLUMN}, 0, 0, FLAGS, .unit = "mode" },
59 { NULL }
60 };
61
62 AVFILTER_DEFINE_CLASS(convolution);
63
64 static const int same3x3[9] = {0, 0, 0,
65 0, 1, 0,
66 0, 0, 0};
67
68 static const int same5x5[25] = {0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0,
70 0, 0, 1, 0, 0,
71 0, 0, 0, 0, 0,
72 0, 0, 0, 0, 0};
73
74 static const int same7x7[49] = {0, 0, 0, 0, 0, 0, 0,
75 0, 0, 0, 0, 0, 0, 0,
76 0, 0, 0, 0, 0, 0, 0,
77 0, 0, 0, 1, 0, 0, 0,
78 0, 0, 0, 0, 0, 0, 0,
79 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0};
81
82 static const enum AVPixelFormat pix_fmts[] = {
83 AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUV440P,
84 AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVJ440P,
85 AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUV420P,
86 AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ420P,
87 AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV410P,
88 AV_PIX_FMT_YUV420P9, AV_PIX_FMT_YUV422P9, AV_PIX_FMT_YUV444P9,
89 AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
90 AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12, AV_PIX_FMT_YUV440P12,
91 AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
92 AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
93 AV_PIX_FMT_YUVA420P9, AV_PIX_FMT_YUVA422P9, AV_PIX_FMT_YUVA444P9,
94 AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_YUVA444P10,
95 AV_PIX_FMT_YUVA422P12, AV_PIX_FMT_YUVA444P12,
96 AV_PIX_FMT_YUVA420P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA444P16,
97 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10,
98 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
99 AV_PIX_FMT_GBRAP, AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16,
100 AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY9, AV_PIX_FMT_GRAY10, AV_PIX_FMT_GRAY12, AV_PIX_FMT_GRAY14, AV_PIX_FMT_GRAY16,
101 AV_PIX_FMT_NONE
102 };
103
104 typedef struct ThreadData {
105 AVFrame *in, *out;
106 } ThreadData;
107
108 ✗ static void filter16_prewitt(uint8_t *dstp, int width,
109 float scale, float delta, const int *const matrix,
110 const uint8_t *c[], int peak, int radius,
111 int dstride, int stride, int size)
112 {
113 ✗ uint16_t *dst = (uint16_t *)dstp;
114 int x;
115
116 ✗ for (x = 0; x < width; x++) {
117 ✗ float suma = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[1][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * -1 +
118 ✗ AV_RN16A(&c[6][2 * x]) * 1 + AV_RN16A(&c[7][2 * x]) * 1 + AV_RN16A(&c[8][2 * x]) * 1;
119 ✗ float sumb = AV_RN16A(&c[0][2 * x]) * -1 + AV_RN16A(&c[2][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1 +
120 ✗ AV_RN16A(&c[5][2 * x]) * 1 + AV_RN16A(&c[6][2 * x]) * -1 + AV_RN16A(&c[8][2 * x]) * 1;
121
122 ✗ dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
123 }
124 ✗ }
125
126 ✗ static void filter16_roberts(uint8_t *dstp, int width,
127 float scale, float delta, const int *const matrix,
128 const uint8_t *c[], int peak, int radius,
129 int dstride, int stride, int size)
130 {
131 ✗ uint16_t *dst = (uint16_t *)dstp;
132 int x;
133
134 ✗ for (x = 0; x < width; x++) {
135 ✗ float suma = AV_RN16A(&c[0][2 * x]) * 1 + AV_RN16A(&c[1][2 * x]) * -1;
136 ✗ float sumb = AV_RN16A(&c[4][2 * x]) * 1 + AV_RN16A(&c[3][2 * x]) * -1;
137
138 ✗ dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
139 }
140 ✗ }
141
142 ✗ static void filter16_scharr(uint8_t *dstp, int width,
143 float scale, float delta, const int *const matrix,
144 const uint8_t *c[], int peak, int radius,
145 int dstride, int stride, int size)
146 {
147 ✗ uint16_t *dst = (uint16_t *)dstp;
148 int x;
149
150 ✗ for (x = 0; x < width; x++) {
151 ✗ float suma = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[1][2 * x]) * -162 + AV_RN16A(&c[2][2 * x]) * -47 +
152 ✗ AV_RN16A(&c[6][2 * x]) * 47 + AV_RN16A(&c[7][2 * x]) * 162 + AV_RN16A(&c[8][2 * x]) * 47;
153 ✗ float sumb = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[2][2 * x]) * 47 + AV_RN16A(&c[3][2 * x]) * -162 +
154 ✗ AV_RN16A(&c[5][2 * x]) * 162 + AV_RN16A(&c[6][2 * x]) * -47 + AV_RN16A(&c[8][2 * x]) * 47;
155
156 ✗ suma /= 256.f;
157 ✗ sumb /= 256.f;
158 ✗ dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
159 }
160 ✗ }
161
162 ✗ static void filter16_kirsch(uint8_t *dstp, int width,
163 float scale, float delta, const int *const matrix,
164 const uint8_t *c[], int peak, int radius,
165 int dstride, int stride, int size)
166 {
167 ✗ uint16_t *dst = (uint16_t *)dstp;
168 ✗ const uint16_t *c0 = (const uint16_t *)c[0], *c1 = (const uint16_t *)c[1], *c2 = (const uint16_t *)c[2];
169 ✗ const uint16_t *c3 = (const uint16_t *)c[3], *c5 = (const uint16_t *)c[5];
170 ✗ const uint16_t *c6 = (const uint16_t *)c[6], *c7 = (const uint16_t *)c[7], *c8 = (const uint16_t *)c[8];
171 int x;
172
173 ✗ for (x = 0; x < width; x++) {
174 ✗ int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
175 ✗ c3[x] * -3 + c5[x] * -3 +
176 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
177 ✗ int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
178 ✗ c3[x] * 5 + c5[x] * -3 +
179 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
180 ✗ int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
181 ✗ c3[x] * 5 + c5[x] * 5 +
182 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
183 ✗ int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
184 ✗ c3[x] * 5 + c5[x] * 5 +
185 ✗ c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
186 ✗ int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
187 ✗ c3[x] * -3 + c5[x] * 5 +
188 ✗ c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
189 ✗ int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
190 ✗ c3[x] * -3 + c5[x] * -3 +
191 ✗ c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
192 ✗ int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
193 ✗ c3[x] * -3 + c5[x] * -3 +
194 ✗ c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
195 ✗ int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
196 ✗ c3[x] * -3 + c5[x] * -3 +
197 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
198
199 ✗ sum0 = FFMAX(sum0, sum1);
200 ✗ sum2 = FFMAX(sum2, sum3);
201 ✗ sum4 = FFMAX(sum4, sum5);
202 ✗ sum6 = FFMAX(sum6, sum7);
203 ✗ sum0 = FFMAX(sum0, sum2);
204 ✗ sum4 = FFMAX(sum4, sum6);
205 ✗ sum0 = FFMAX(sum0, sum4);
206
207 ✗ dst[x] = av_clip(FFABS(sum0) * scale + delta, 0, peak);
208 }
209 ✗ }
210
211 ✗ static void filter_prewitt(uint8_t *dst, int width,
212 float scale, float delta, const int *const matrix,
213 const uint8_t *c[], int peak, int radius,
214 int dstride, int stride, int size)
215 {
216 ✗ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
217 ✗ const uint8_t *c3 = c[3], *c5 = c[5];
218 ✗ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
219 int x;
220
221 ✗ for (x = 0; x < width; x++) {
222 ✗ float suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
223 ✗ c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
224 ✗ float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
225 ✗ c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
226
227 ✗ dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
228 }
229 ✗ }
230
231 ✗ static void filter_roberts(uint8_t *dst, int width,
232 float scale, float delta, const int *const matrix,
233 const uint8_t *c[], int peak, int radius,
234 int dstride, int stride, int size)
235 {
236 int x;
237
238 ✗ for (x = 0; x < width; x++) {
239 ✗ float suma = c[0][x] * 1 + c[1][x] * -1;
240 ✗ float sumb = c[4][x] * 1 + c[3][x] * -1;
241
242 ✗ dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
243 }
244 ✗ }
245
246 ✗ static void filter_scharr(uint8_t *dst, int width,
247 float scale, float delta, const int *const matrix,
248 const uint8_t *c[], int peak, int radius,
249 int dstride, int stride, int size)
250 {
251 ✗ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
252 ✗ const uint8_t *c3 = c[3], *c5 = c[5];
253 ✗ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
254 int x;
255
256 ✗ for (x = 0; x < width; x++) {
257 ✗ float suma = c0[x] * -47 + c1[x] * -162 + c2[x] * -47 +
258 ✗ c6[x] * 47 + c7[x] * 162 + c8[x] * 47;
259 ✗ float sumb = c0[x] * -47 + c2[x] * 47 + c3[x] * -162 +
260 ✗ c5[x] * 162 + c6[x] * -47 + c8[x] * 47;
261
262 ✗ suma /= 256.f;
263 ✗ sumb /= 256.f;
264 ✗ dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
265 }
266 ✗ }
267
268 ✗ static void filter_kirsch(uint8_t *dst, int width,
269 float scale, float delta, const int *const matrix,
270 const uint8_t *c[], int peak, int radius,
271 int dstride, int stride, int size)
272 {
273 ✗ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
274 ✗ const uint8_t *c3 = c[3], *c5 = c[5];
275 ✗ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
276 int x;
277
278 ✗ for (x = 0; x < width; x++) {
279 ✗ int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
280 ✗ c3[x] * -3 + c5[x] * -3 +
281 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
282 ✗ int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
283 ✗ c3[x] * 5 + c5[x] * -3 +
284 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
285 ✗ int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
286 ✗ c3[x] * 5 + c5[x] * 5 +
287 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
288 ✗ int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
289 ✗ c3[x] * 5 + c5[x] * 5 +
290 ✗ c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
291 ✗ int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
292 ✗ c3[x] * -3 + c5[x] * 5 +
293 ✗ c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
294 ✗ int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
295 ✗ c3[x] * -3 + c5[x] * -3 +
296 ✗ c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
297 ✗ int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
298 ✗ c3[x] * -3 + c5[x] * -3 +
299 ✗ c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
300 ✗ int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
301 ✗ c3[x] * -3 + c5[x] * -3 +
302 ✗ c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
303
304 ✗ sum0 = FFMAX(sum0, sum1);
305 ✗ sum2 = FFMAX(sum2, sum3);
306 ✗ sum4 = FFMAX(sum4, sum5);
307 ✗ sum6 = FFMAX(sum6, sum7);
308 ✗ sum0 = FFMAX(sum0, sum2);
309 ✗ sum4 = FFMAX(sum4, sum6);
310 ✗ sum0 = FFMAX(sum0, sum4);
311
312 ✗ dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta);
313 }
314 ✗ }
315
316 ✗ static void filter16_3x3(uint8_t *dstp, 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, int size)
320 {
321 ✗ uint16_t *dst = (uint16_t *)dstp;
322 int x;
323
324 ✗ for (x = 0; x < width; x++) {
325 ✗ unsigned sum = (unsigned)AV_RN16A(&c[0][2 * x]) * matrix[0] +
326 ✗ (unsigned)AV_RN16A(&c[1][2 * x]) * matrix[1] +
327 ✗ (unsigned)AV_RN16A(&c[2][2 * x]) * matrix[2] +
328 ✗ (unsigned)AV_RN16A(&c[3][2 * x]) * matrix[3] +
329 ✗ (unsigned)AV_RN16A(&c[4][2 * x]) * matrix[4] +
330 ✗ (unsigned)AV_RN16A(&c[5][2 * x]) * matrix[5] +
331 ✗ (unsigned)AV_RN16A(&c[6][2 * x]) * matrix[6] +
332 ✗ (unsigned)AV_RN16A(&c[7][2 * x]) * matrix[7] +
333 ✗ (unsigned)AV_RN16A(&c[8][2 * x]) * matrix[8];
334 ✗ dst[x] = av_clip((int)sum * rdiv + bias + 0.5f, 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;
348 ✗ unsigned sum = 0;
349
350 ✗ for (i = 0; i < 25; i++)
351 ✗ sum += (unsigned)AV_RN16A(&c[i][2 * x]) * matrix[i];
352
353 ✗ dst[x] = av_clip((int)sum * rdiv + bias + 0.5f, 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;
367 ✗ unsigned sum = 0;
368
369 ✗ for (i = 0; i < 49; i++)
370 ✗ sum += (unsigned)AV_RN16A(&c[i][2 * x]) * matrix[i];
371
372 ✗ dst[x] = av_clip((int)sum * rdiv + bias + 0.5f, 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;
386 ✗ unsigned sum = 0;
387
388 ✗ for (i = 0; i < 2 * radius + 1; i++)
389 ✗ sum += (unsigned)AV_RN16A(&c[i][2 * x]) * matrix[i];
390
391 ✗ dst[x] = av_clip((int)sum * rdiv + bias + 0.5f, 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, unsigned, 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] += (unsigned)AV_RN16A(&c[i][0 + y * stride + off16 * 2]) * matrix[i];
410 }
411
412 ✗ for (int off16 = 0; off16 < width; off16++) {
413 ✗ dst[off16] = av_clip((int)sum[off16] * rdiv + bias + 0.5f, 0, peak);
414 }
415 ✗ dst += dstride / 2;
416 }
417 ✗ }
418
419 ✗ static void filter_7x7(uint8_t *dst, int width,
420 float rdiv, float bias, const int *const matrix,
421 const uint8_t *c[], int peak, int radius,
422 int dstride, int stride, int size)
423 {
424 int x;
425
426 ✗ for (x = 0; x < width; x++) {
427 int i;
428 ✗ unsigned sum = 0;
429
430 ✗ for (i = 0; i < 49; i++)
431 ✗ sum += (unsigned)c[i][x] * matrix[i];
432
433 ✗ dst[x] = av_clip_uint8((int)sum * rdiv + bias + 0.5f);
434 }
435 ✗ }
436
437 ✗ static void filter_5x5(uint8_t *dst, int width,
438 float rdiv, float bias, const int *const matrix,
439 const uint8_t *c[], int peak, int radius,
440 int dstride, int stride, int size)
441 {
442 int x;
443
444 ✗ for (x = 0; x < width; x++) {
445 int i;
446 ✗ unsigned sum = 0;
447
448 ✗ for (i = 0; i < 25; i++)
449 ✗ sum += (unsigned)c[i][x] * matrix[i];
450
451 ✗ dst[x] = av_clip_uint8((int)sum * rdiv + bias + 0.5f);
452 }
453 ✗ }
454
455 ✗ static void filter_3x3(uint8_t *dst, int width,
456 float rdiv, float bias, const int *const matrix,
457 const uint8_t *c[], int peak, int radius,
458 int dstride, int stride, int size)
459 {
460 ✗ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
461 ✗ const uint8_t *c3 = c[3], *c4 = c[4], *c5 = c[5];
462 ✗ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
463 int x;
464
465 ✗ for (x = 0; x < width; x++) {
466 ✗ unsigned sum = (unsigned)c0[x] * matrix[0] + (unsigned)c1[x] * matrix[1] + (unsigned)c2[x] * matrix[2] +
467 ✗ (unsigned)c3[x] * matrix[3] + (unsigned)c4[x] * matrix[4] + (unsigned)c5[x] * matrix[5] +
468 ✗ (unsigned)c6[x] * matrix[6] + (unsigned)c7[x] * matrix[7] + (unsigned)c8[x] * matrix[8];
469 ✗ dst[x] = av_clip_uint8((int)sum * rdiv + bias + 0.5f);
470 }
471 ✗ }
472
473 ✗ static void filter_row(uint8_t *dst, int width,
474 float rdiv, float bias, const int *const matrix,
475 const uint8_t *c[], int peak, int radius,
476 int dstride, int stride, int size)
477 {
478 int x;
479
480 ✗ for (x = 0; x < width; x++) {
481 int i;
482 ✗ unsigned sum = 0;
483
484 ✗ for (i = 0; i < 2 * radius + 1; i++)
485 ✗ sum += (unsigned)c[i][x] * matrix[i];
486
487 ✗ dst[x] = av_clip_uint8((int)sum * rdiv + bias + 0.5f);
488 }
489 ✗ }
490
491 ✗ static void filter_column(uint8_t *dst, int height,
492 float rdiv, float bias, const int *const matrix,
493 const uint8_t *c[], int peak, int radius,
494 int dstride, int stride, int size)
495 {
496 DECLARE_ALIGNED(64, unsigned, sum)[16];
497 ✗ const int width = FFMIN(16, size);
498
499 ✗ for (int y = 0; y < height; y++) {
500 ✗ memset(sum, 0, sizeof(sum));
501
502 ✗ for (int i = 0; i < 2 * radius + 1; i++) {
503 ✗ for (int off16 = 0; off16 < width; off16++)
504 ✗ sum[off16] += (unsigned)c[i][0 + y * stride + off16] * matrix[i];
505 }
506
507 ✗ for (int off16 = 0; off16 < width; off16++) {
508 ✗ dst[off16] = av_clip_uint8((int)sum[off16] * rdiv + bias + 0.5f);
509 }
510 ✗ dst += dstride;
511 }
512 ✗ }
513
514 ✗ static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride,
515 int x, int w, int y, int h, int bpc)
516 {
517 int i;
518
519 ✗ for (i = 0; i < 25; i++) {
520 ✗ int xoff = avpriv_mirror(x + (i % 5) - 2, w - 1);
521 ✗ int yoff = avpriv_mirror(y + (i / 5) - 2, h - 1);
522
523 ✗ c[i] = src + xoff * bpc + yoff * stride;
524 }
525 ✗ }
526
527 ✗ static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride,
528 int x, int w, int y, int h, int bpc)
529 {
530 int i;
531
532 ✗ for (i = 0; i < 49; i++) {
533 ✗ int xoff = avpriv_mirror(x + (i % 7) - 3, w - 1);
534 ✗ int yoff = avpriv_mirror(y + (i / 7) - 3, h - 1);
535
536 ✗ c[i] = src + xoff * bpc + yoff * stride;
537 }
538 ✗ }
539
540 ✗ static void setup_row(int radius, const uint8_t *c[], const uint8_t *src, int stride,
541 int x, int w, int y, int h, int bpc)
542 {
543 int i;
544
545 ✗ for (i = 0; i < radius * 2 + 1; i++) {
546 ✗ int xoff = avpriv_mirror(x + i - radius, w - 1);
547
548 ✗ c[i] = src + xoff * bpc + y * stride;
549 }
550 ✗ }
551
552 ✗ static void setup_column(int radius, const uint8_t *c[], const uint8_t *src, int stride,
553 int x, int w, int y, int h, int bpc)
554 {
555 int i;
556
557 ✗ for (i = 0; i < radius * 2 + 1; i++) {
558 ✗ int xoff = avpriv_mirror(x + i - radius, h - 1);
559
560 ✗ c[i] = src + y * bpc + xoff * stride;
561 }
562 ✗ }
563
564 ✗ static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
565 {
566 ✗ ConvolutionContext *s = ctx->priv;
567 ✗ ThreadData *td = arg;
568 ✗ AVFrame *in = td->in;
569 ✗ AVFrame *out = td->out;
570 int plane;
571
572 ✗ for (plane = 0; plane < s->nb_planes; plane++) {
573 ✗ const int mode = s->mode[plane];
574 ✗ const int bpc = s->bpc;
575 ✗ const int radius = s->size[plane] / 2;
576 ✗ const int height = s->planeheight[plane];
577 ✗ const int width = s->planewidth[plane];
578 ✗ const int stride = in->linesize[plane];
579 ✗ const int dstride = out->linesize[plane];
580 ✗ const int sizeh = mode == MATRIX_COLUMN ? width : height;
581 ✗ const int sizew = mode == MATRIX_COLUMN ? height : width;
582 ✗ const int slice_start = ff_slice_pos(sizeh, jobnr, nb_jobs);
583 ✗ const int slice_end = ff_slice_pos(sizeh, jobnr + 1, nb_jobs);
584 ✗ const float rdiv = s->rdiv[plane];
585 ✗ const float bias = s->bias[plane];
586 ✗ const uint8_t *src = in->data[plane];
587 ✗ const int dst_pos = slice_start * (mode == MATRIX_COLUMN ? bpc : dstride);
588 ✗ uint8_t *dst = out->data[plane] + dst_pos;
589 ✗ const int *matrix = s->matrix[plane];
590 ✗ const int step = mode == MATRIX_COLUMN ? 16 : 1;
591 const uint8_t *c[49];
592 int y, x;
593
594 ✗ if (s->copy[plane]) {
595 ✗ if (mode == MATRIX_COLUMN)
596 ✗ av_image_copy_plane(dst, dstride, src + slice_start * bpc, stride,
597 ✗ (slice_end - slice_start) * bpc, height);
598 else
599 ✗ av_image_copy_plane(dst, dstride, src + slice_start * stride, stride,
600 width * bpc, slice_end - slice_start);
601 ✗ continue;
602 }
603 ✗ for (y = slice_start; y < slice_end; y += step) {
604 ✗ const int left = FFMIN(radius, sizew);
605 ✗ const int right = FFMAX(left, sizew - radius);
606 ✗ const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : left * bpc;
607 ✗ const int yoff = mode == MATRIX_COLUMN ? left * dstride : 0;
608
609 ✗ for (x = 0; x < left; x++) {
610 ✗ const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
611 ✗ const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
612
613 ✗ s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
614 ✗ s->filter[plane](dst + yoff + xoff, 1, rdiv,
615 bias, matrix, c, s->max, radius,
616 dstride, stride, slice_end - y);
617 }
618 ✗ s->setup[plane](radius, c, src, stride, left, width, y, height, bpc);
619 ✗ s->filter[plane](dst + yoff + xoff, right - left,
620 rdiv, bias, matrix, c, s->max, radius,
621 dstride, stride, slice_end - y);
622 ✗ for (x = right; x < sizew; x++) {
623 ✗ const int xoff = mode == MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
624 ✗ const int yoff = mode == MATRIX_COLUMN ? x * dstride : 0;
625
626 ✗ s->setup[plane](radius, c, src, stride, x, width, y, height, bpc);
627 ✗ s->filter[plane](dst + yoff + xoff, 1, rdiv,
628 bias, matrix, c, s->max, radius,
629 dstride, stride, slice_end - y);
630 }
631 ✗ if (mode != MATRIX_COLUMN)
632 ✗ dst += dstride;
633 }
634 }
635
636 ✗ return 0;
637 }
638
639 ✗ static int param_init(AVFilterContext *ctx)
640 {
641 ✗ ConvolutionContext *s = ctx->priv;
642 ✗ AVFilterLink *inlink = ctx->inputs[0];
643 ✗ const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
644 int p, i;
645
646 ✗ s->depth = desc->comp[0].depth;
647 ✗ s->max = (1 << s->depth) - 1;
648
649 ✗ s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
650 ✗ s->planewidth[0] = s->planewidth[3] = inlink->w;
651 ✗ s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
652 ✗ s->planeheight[0] = s->planeheight[3] = inlink->h;
653
654 ✗ s->nb_planes = av_pix_fmt_count_planes(inlink->format);
655 ✗ s->nb_threads = ff_filter_get_nb_threads(ctx);
656 ✗ s->bpc = (s->depth + 7) / 8;
657
658 ✗ if (!strcmp(ctx->filter->name, "convolution")) {
659 ✗ for (i = 0; i < 4; i++) {
660 ✗ int *matrix = (int *)s->matrix[i];
661 ✗ char *orig, *p, *arg, *saveptr = NULL;
662 ✗ float sum = 1.f;
663
664 ✗ p = orig = av_strdup(s->matrix_str[i]);
665 ✗ if (p) {
666 ✗ s->matrix_length[i] = 0;
667 ✗ s->rdiv[i] = s->user_rdiv[i];
668 ✗ sum = 0.f;
669
670 ✗ while (s->matrix_length[i] < 49) {
671 ✗ if (!(arg = av_strtok(p, " |", &saveptr)))
672 ✗ break;
673
674 ✗ p = NULL;
675 ✗ sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
676 ✗ sum += matrix[s->matrix_length[i]];
677 ✗ s->matrix_length[i]++;
678 }
679
680 ✗ av_freep(&orig);
681 ✗ if (!(s->matrix_length[i] & 1)) {
682 ✗ av_log(ctx, AV_LOG_ERROR, "number of matrix elements must be odd\n");
683 ✗ return AVERROR(EINVAL);
684 }
685 }
686
687 ✗ if (s->mode[i] == MATRIX_ROW) {
688 ✗ s->filter[i] = filter_row;
689 ✗ s->setup[i] = setup_row;
690 ✗ s->size[i] = s->matrix_length[i];
691 ✗ } else if (s->mode[i] == MATRIX_COLUMN) {
692 ✗ s->filter[i] = filter_column;
693 ✗ s->setup[i] = setup_column;
694 ✗ s->size[i] = s->matrix_length[i];
695 ✗ } else if (s->matrix_length[i] == 9) {
696 ✗ s->size[i] = 3;
697
698 ✗ if (!memcmp(matrix, same3x3, sizeof(same3x3))) {
699 ✗ s->copy[i] = 1;
700 } else {
701 ✗ s->filter[i] = filter_3x3;
702 ✗ s->copy[i] = 0;
703 }
704 ✗ s->setup[i] = setup_3x3;
705 ✗ } else if (s->matrix_length[i] == 25) {
706 ✗ s->size[i] = 5;
707 ✗ if (!memcmp(matrix, same5x5, sizeof(same5x5))) {
708 ✗ s->copy[i] = 1;
709 } else {
710 ✗ s->filter[i] = filter_5x5;
711 ✗ s->copy[i] = 0;
712 }
713 ✗ s->setup[i] = setup_5x5;
714 ✗ } else if (s->matrix_length[i] == 49) {
715 ✗ s->size[i] = 7;
716 ✗ if (!memcmp(matrix, same7x7, sizeof(same7x7))) {
717 ✗ s->copy[i] = 1;
718 } else {
719 ✗ s->filter[i] = filter_7x7;
720 ✗ s->copy[i] = 0;
721 }
722 ✗ s->setup[i] = setup_7x7;
723 } else {
724 ✗ return AVERROR(EINVAL);
725 }
726
727 ✗ if (sum == 0)
728 ✗ sum = 1;
729 ✗ if (s->rdiv[i] == 0)
730 ✗ s->rdiv[i] = 1. / sum;
731
732 ✗ if (s->copy[i] && (s->rdiv[i] != 1. || s->bias[i] != 0.))
733 ✗ s->copy[i] = 0;
734 }
735 ✗ } else if (!strcmp(ctx->filter->name, "prewitt")) {
736 ✗ for (i = 0; i < 4; i++) {
737 ✗ s->filter[i] = filter_prewitt;
738 ✗ s->copy[i] = !((1 << i) & s->planes);
739 ✗ s->size[i] = 3;
740 ✗ s->setup[i] = setup_3x3;
741 ✗ s->rdiv[i] = s->scale;
742 ✗ s->bias[i] = s->delta;
743 }
744 ✗ } else if (!strcmp(ctx->filter->name, "roberts")) {
745 ✗ for (i = 0; i < 4; i++) {
746 ✗ s->filter[i] = filter_roberts;
747 ✗ s->copy[i] = !((1 << i) & s->planes);
748 ✗ s->size[i] = 3;
749 ✗ s->setup[i] = setup_3x3;
750 ✗ s->rdiv[i] = s->scale;
751 ✗ s->bias[i] = s->delta;
752 }
753 #if CONFIG_SOBEL_FILTER
754 ✗ } else if (!strcmp(ctx->filter->name, "sobel")) {
755 ✗ ff_sobel_init(s, s->depth, s->nb_planes);
756 #endif
757 ✗ } else if (!strcmp(ctx->filter->name, "kirsch")) {
758 ✗ for (i = 0; i < 4; i++) {
759 ✗ s->filter[i] = filter_kirsch;
760 ✗ s->copy[i] = !((1 << i) & s->planes);
761 ✗ s->size[i] = 3;
762 ✗ s->setup[i] = setup_3x3;
763 ✗ s->rdiv[i] = s->scale;
764 ✗ s->bias[i] = s->delta;
765 }
766 ✗ } else if (!strcmp(ctx->filter->name, "scharr")) {
767 ✗ for (i = 0; i < 4; i++) {
768 ✗ s->filter[i] = filter_scharr;
769 ✗ s->copy[i] = !((1 << i) & s->planes);
770 ✗ s->size[i] = 3;
771 ✗ s->setup[i] = setup_3x3;
772 ✗ s->rdiv[i] = s->scale;
773 ✗ s->bias[i] = s->delta;
774 }
775 }
776
777 ✗ if (!strcmp(ctx->filter->name, "convolution")) {
778 ✗ if (s->depth > 8) {
779 ✗ for (p = 0; p < s->nb_planes; p++) {
780 ✗ if (s->mode[p] == MATRIX_ROW)
781 ✗ s->filter[p] = filter16_row;
782 ✗ else if (s->mode[p] == MATRIX_COLUMN)
783 ✗ s->filter[p] = filter16_column;
784 ✗ else if (s->size[p] == 3)
785 ✗ s->filter[p] = filter16_3x3;
786 ✗ else if (s->size[p] == 5)
787 ✗ s->filter[p] = filter16_5x5;
788 ✗ else if (s->size[p] == 7)
789 ✗ s->filter[p] = filter16_7x7;
790 }
791 }
792 #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 && HAVE_X86ASM
793 ✗ ff_convolution_init_x86(s);
794 #endif
795 ✗ } else if (!strcmp(ctx->filter->name, "prewitt")) {
796 ✗ if (s->depth > 8)
797 ✗ for (p = 0; p < s->nb_planes; p++)
798 ✗ s->filter[p] = filter16_prewitt;
799 ✗ } else if (!strcmp(ctx->filter->name, "roberts")) {
800 ✗ if (s->depth > 8)
801 ✗ for (p = 0; p < s->nb_planes; p++)
802 ✗ s->filter[p] = filter16_roberts;
803 ✗ } else if (!strcmp(ctx->filter->name, "kirsch")) {
804 ✗ if (s->depth > 8)
805 ✗ for (p = 0; p < s->nb_planes; p++)
806 ✗ s->filter[p] = filter16_kirsch;
807 ✗ } else if (!strcmp(ctx->filter->name, "scharr")) {
808 ✗ if (s->depth > 8)
809 ✗ for (p = 0; p < s->nb_planes; p++)
810 ✗ s->filter[p] = filter16_scharr;
811 }
812
813 ✗ return 0;
814 }
815
816 ✗ static int config_input(AVFilterLink *inlink)
817 {
818 ✗ AVFilterContext *ctx = inlink->dst;
819 ✗ return param_init(ctx);
820 }
821
822 ✗ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
823 {
824 ✗ AVFilterContext *ctx = inlink->dst;
825 ✗ ConvolutionContext *s = ctx->priv;
826 ✗ AVFilterLink *outlink = ctx->outputs[0];
827 AVFrame *out;
828 ThreadData td;
829
830 ✗ out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
831 ✗ if (!out) {
832 ✗ av_frame_free(&in);
833 ✗ return AVERROR(ENOMEM);
834 }
835 ✗ av_frame_copy_props(out, in);
836
837 ✗ td.in = in;
838 ✗ td.out = out;
839 ✗ ff_filter_execute(ctx, filter_slice, &td, NULL,
840 ✗ FFMIN3(s->planeheight[1], s->planewidth[1], s->nb_threads));
841
842 ✗ av_frame_free(&in);
843 ✗ return ff_filter_frame(outlink, out);
844 }
845
846 ✗ static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
847 char *res, int res_len, int flags)
848 {
849 int ret;
850
851 ✗ ret = ff_filter_process_command(ctx, cmd, args, res, res_len, flags);
852 ✗ if (ret < 0)
853 ✗ return ret;
854
855 ✗ return param_init(ctx);
856 }
857
858 static const AVFilterPad convolution_inputs[] = {
859 {
860 .name = "default",
861 .type = AVMEDIA_TYPE_VIDEO,
862 .config_props = config_input,
863 .filter_frame = filter_frame,
864 },
865 };
866
867 #if CONFIG_CONVOLUTION_FILTER
868
869 const FFFilter ff_vf_convolution = {
870 .p.name = "convolution",
871 .p.description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
872 .p.priv_class = &convolution_class,
873 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
874 .priv_size = sizeof(ConvolutionContext),
875 FILTER_INPUTS(convolution_inputs),
876 FILTER_OUTPUTS(ff_video_default_filterpad),
877 FILTER_PIXFMTS_ARRAY(pix_fmts),
878 .process_command = process_command,
879 };
880
881 #endif /* CONFIG_CONVOLUTION_FILTER */
882
883 static const AVOption common_options[] = {
884 { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
885 { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
886 { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
887 { NULL }
888 };
889
890 AVFILTER_DEFINE_CLASS_EXT(common, "kirsch/prewitt/roberts/scharr/sobel",
891 common_options);
892
893 #if CONFIG_PREWITT_FILTER
894
895 const FFFilter ff_vf_prewitt = {
896 .p.name = "prewitt",
897 .p.description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
898 .p.priv_class = &common_class,
899 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
900 .priv_size = sizeof(ConvolutionContext),
901 FILTER_INPUTS(convolution_inputs),
902 FILTER_OUTPUTS(ff_video_default_filterpad),
903 FILTER_PIXFMTS_ARRAY(pix_fmts),
904 .process_command = process_command,
905 };
906
907 #endif /* CONFIG_PREWITT_FILTER */
908
909 #if CONFIG_SOBEL_FILTER
910
911 const FFFilter ff_vf_sobel = {
912 .p.name = "sobel",
913 .p.description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
914 .p.priv_class = &common_class,
915 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
916 .priv_size = sizeof(ConvolutionContext),
917 FILTER_INPUTS(convolution_inputs),
918 FILTER_OUTPUTS(ff_video_default_filterpad),
919 FILTER_PIXFMTS_ARRAY(pix_fmts),
920 .process_command = process_command,
921 };
922
923 #endif /* CONFIG_SOBEL_FILTER */
924
925 #if CONFIG_ROBERTS_FILTER
926
927 const FFFilter ff_vf_roberts = {
928 .p.name = "roberts",
929 .p.description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
930 .p.priv_class = &common_class,
931 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
932 .priv_size = sizeof(ConvolutionContext),
933 FILTER_INPUTS(convolution_inputs),
934 FILTER_OUTPUTS(ff_video_default_filterpad),
935 FILTER_PIXFMTS_ARRAY(pix_fmts),
936 .process_command = process_command,
937 };
938
939 #endif /* CONFIG_ROBERTS_FILTER */
940
941 #if CONFIG_KIRSCH_FILTER
942
943 const FFFilter ff_vf_kirsch = {
944 .p.name = "kirsch",
945 .p.description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
946 .p.priv_class = &common_class,
947 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
948 .priv_size = sizeof(ConvolutionContext),
949 FILTER_INPUTS(convolution_inputs),
950 FILTER_OUTPUTS(ff_video_default_filterpad),
951 FILTER_PIXFMTS_ARRAY(pix_fmts),
952 .process_command = process_command,
953 };
954
955 #endif /* CONFIG_KIRSCH_FILTER */
956
957 #if CONFIG_SCHARR_FILTER
958
959 const FFFilter ff_vf_scharr = {
960 .p.name = "scharr",
961 .p.description = NULL_IF_CONFIG_SMALL("Apply scharr operator."),
962 .p.priv_class = &common_class,
963 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
964 .priv_size = sizeof(ConvolutionContext),
965 FILTER_INPUTS(convolution_inputs),
966 FILTER_OUTPUTS(ff_video_default_filterpad),
967 FILTER_PIXFMTS_ARRAY(pix_fmts),
968 .process_command = process_command,
969 };
970
971 #endif /* CONFIG_SCHARR_FILTER */
972