FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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/opt.h"
25 #include "libavutil/pixdesc.h"
26 #include "avfilter.h"
27 #include "formats.h"
28 #include "internal.h"
29 #include "video.h"
30 
31 typedef struct ConvolutionContext {
32  const AVClass *class;
33 
34  char *matrix_str[4];
35  float rdiv[4];
36  float bias[4];
37  float scale;
38  float delta;
39  int planes;
40 
41  int size[4];
42  int depth;
43  int bpc;
44  int bstride;
47  int nb_planes;
49  int planewidth[4];
50  int planeheight[4];
51  int matrix[4][25];
52  int matrix_length[4];
53  int copy[4];
54 
55  int (*filter[4])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs);
57 
58 #define OFFSET(x) offsetof(ConvolutionContext, x)
59 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
60 
61 static const AVOption convolution_options[] = {
62  { "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 },
63  { "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 },
64  { "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 },
65  { "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 },
66  { "0rdiv", "set rdiv for 1st plane", OFFSET(rdiv[0]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
67  { "1rdiv", "set rdiv for 2nd plane", OFFSET(rdiv[1]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
68  { "2rdiv", "set rdiv for 3rd plane", OFFSET(rdiv[2]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
69  { "3rdiv", "set rdiv for 4th plane", OFFSET(rdiv[3]), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, INT_MAX, FLAGS},
70  { "0bias", "set bias for 1st plane", OFFSET(bias[0]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
71  { "1bias", "set bias for 2nd plane", OFFSET(bias[1]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
72  { "2bias", "set bias for 3rd plane", OFFSET(bias[2]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
73  { "3bias", "set bias for 4th plane", OFFSET(bias[3]), AV_OPT_TYPE_FLOAT, {.dbl=0.0}, 0.0, INT_MAX, FLAGS},
74  { NULL }
75 };
76 
77 AVFILTER_DEFINE_CLASS(convolution);
78 
79 static const int same3x3[9] = {0, 0, 0,
80  0, 1, 0,
81  0, 0, 0};
82 
83 static const int same5x5[25] = {0, 0, 0, 0, 0,
84  0, 0, 0, 0, 0,
85  0, 0, 1, 0, 0,
86  0, 0, 0, 0, 0,
87  0, 0, 0, 0, 0};
88 
90 {
91  static const enum AVPixelFormat pix_fmts[] = {
110  };
111 
112  return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
113 }
114 
115 static inline void line_copy8(uint8_t *line, const uint8_t *srcp, int width, int mergin)
116 {
117  int i;
118 
119  memcpy(line, srcp, width);
120 
121  for (i = mergin; i > 0; i--) {
122  line[-i] = line[i];
123  line[width - 1 + i] = line[width - 1 - i];
124  }
125 }
126 
127 static inline void line_copy16(uint16_t *line, const uint16_t *srcp, int width, int mergin)
128 {
129  int i;
130 
131  memcpy(line, srcp, width * 2);
132 
133  for (i = mergin; i > 0; i--) {
134  line[-i] = line[i];
135  line[width - 1 + i] = line[width - 1 - i];
136  }
137 }
138 
139 typedef struct ThreadData {
140  AVFrame *in, *out;
141  int plane;
142 } ThreadData;
143 
144 static int filter16_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
145 {
146  ConvolutionContext *s = ctx->priv;
147  ThreadData *td = arg;
148  AVFrame *in = td->in;
149  AVFrame *out = td->out;
150  const int plane = td->plane;
151  const int peak = (1 << s->depth) - 1;
152  const int stride = in->linesize[plane] / 2;
153  const int bstride = s->bstride;
154  const int height = s->planeheight[plane];
155  const int width = s->planewidth[plane];
156  const int slice_start = (height * jobnr) / nb_jobs;
157  const int slice_end = (height * (jobnr+1)) / nb_jobs;
158  const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
159  uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
160  const float scale = s->scale;
161  const float delta = s->delta;
162  uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
163  uint16_t *p1 = p0 + bstride;
164  uint16_t *p2 = p1 + bstride;
165  uint16_t *orig = p0, *end = p2;
166  int y, x;
167 
168  line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
169  line_copy16(p1, src, width, 1);
170 
171  for (y = slice_start; y < slice_end; y++) {
172  src += stride * (y < height - 1 ? 1 : -1);
173  line_copy16(p2, src, width, 1);
174 
175  for (x = 0; x < width; x++) {
176  int suma = p0[x - 1] * -1 +
177  p0[x] * -1 +
178  p0[x + 1] * -1 +
179  p2[x - 1] * 1 +
180  p2[x] * 1 +
181  p2[x + 1] * 1;
182  int sumb = p0[x - 1] * -1 +
183  p0[x + 1] * 1 +
184  p1[x - 1] * -1 +
185  p1[x + 1] * 1 +
186  p2[x - 1] * -1 +
187  p2[x + 1] * 1;
188 
189  dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
190  }
191 
192  p0 = p1;
193  p1 = p2;
194  p2 = (p2 == end) ? orig: p2 + bstride;
195  dst += out->linesize[plane] / 2;
196  }
197 
198  return 0;
199 }
200 
201 static int filter16_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
202 {
203  ConvolutionContext *s = ctx->priv;
204  ThreadData *td = arg;
205  AVFrame *in = td->in;
206  AVFrame *out = td->out;
207  const int plane = td->plane;
208  const int peak = (1 << s->depth) - 1;
209  const int stride = in->linesize[plane] / 2;
210  const int bstride = s->bstride;
211  const int height = s->planeheight[plane];
212  const int width = s->planewidth[plane];
213  const int slice_start = (height * jobnr) / nb_jobs;
214  const int slice_end = (height * (jobnr+1)) / nb_jobs;
215  const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
216  uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
217  const float scale = s->scale;
218  const float delta = s->delta;
219  uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
220  uint16_t *p1 = p0 + bstride;
221  uint16_t *p2 = p1 + bstride;
222  uint16_t *orig = p0, *end = p2;
223  int y, x;
224 
225  line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
226  line_copy16(p1, src, width, 1);
227 
228  for (y = slice_start; y < slice_end; y++) {
229  src += stride * (y < height - 1 ? 1 : -1);
230  line_copy16(p2, src, width, 1);
231 
232  for (x = 0; x < width; x++) {
233  int suma = p0[x - 1] * 1 +
234  p1[x ] * -1;
235  int sumb = p0[x ] * 1 +
236  p1[x - 1] * -1;
237 
238  dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
239  }
240 
241  p0 = p1;
242  p1 = p2;
243  p2 = (p2 == end) ? orig: p2 + bstride;
244  dst += out->linesize[plane] / 2;
245  }
246 
247  return 0;
248 }
249 
250 static int filter16_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
251 {
252  ConvolutionContext *s = ctx->priv;
253  ThreadData *td = arg;
254  AVFrame *in = td->in;
255  AVFrame *out = td->out;
256  const int plane = td->plane;
257  const int peak = (1 << s->depth) - 1;
258  const int stride = in->linesize[plane] / 2;
259  const int bstride = s->bstride;
260  const int height = s->planeheight[plane];
261  const int width = s->planewidth[plane];
262  const int slice_start = (height * jobnr) / nb_jobs;
263  const int slice_end = (height * (jobnr+1)) / nb_jobs;
264  const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
265  uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
266  const float scale = s->scale;
267  const float delta = s->delta;
268  uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
269  uint16_t *p1 = p0 + bstride;
270  uint16_t *p2 = p1 + bstride;
271  uint16_t *orig = p0, *end = p2;
272  int y, x;
273 
274  line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
275  line_copy16(p1, src, width, 1);
276 
277  for (y = slice_start; y < slice_end; y++) {
278  src += stride * (y < height - 1 ? 1 : -1);
279  line_copy16(p2, src, width, 1);
280 
281  for (x = 0; x < width; x++) {
282  int suma = p0[x - 1] * -1 +
283  p0[x] * -2 +
284  p0[x + 1] * -1 +
285  p2[x - 1] * 1 +
286  p2[x] * 2 +
287  p2[x + 1] * 1;
288  int sumb = p0[x - 1] * -1 +
289  p0[x + 1] * 1 +
290  p1[x - 1] * -2 +
291  p1[x + 1] * 2 +
292  p2[x - 1] * -1 +
293  p2[x + 1] * 1;
294 
295  dst[x] = av_clip(sqrt(suma*suma + sumb*sumb) * scale + delta, 0, peak);
296  }
297 
298  p0 = p1;
299  p1 = p2;
300  p2 = (p2 == end) ? orig: p2 + bstride;
301  dst += out->linesize[plane] / 2;
302  }
303 
304  return 0;
305 }
306 
307 static int filter_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
308 {
309  ConvolutionContext *s = ctx->priv;
310  ThreadData *td = arg;
311  AVFrame *in = td->in;
312  AVFrame *out = td->out;
313  const int plane = td->plane;
314  const int stride = in->linesize[plane];
315  const int bstride = s->bstride;
316  const int height = s->planeheight[plane];
317  const int width = s->planewidth[plane];
318  const int slice_start = (height * jobnr) / nb_jobs;
319  const int slice_end = (height * (jobnr+1)) / nb_jobs;
320  const uint8_t *src = in->data[plane] + slice_start * stride;
321  uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
322  const float scale = s->scale;
323  const float delta = s->delta;
324  uint8_t *p0 = s->bptrs[jobnr] + 16;
325  uint8_t *p1 = p0 + bstride;
326  uint8_t *p2 = p1 + bstride;
327  uint8_t *orig = p0, *end = p2;
328  int y, x;
329 
330  line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
331  line_copy8(p1, src, width, 1);
332 
333  for (y = slice_start; y < slice_end; y++) {
334  src += stride * (y < height - 1 ? 1 : -1);
335  line_copy8(p2, src, width, 1);
336 
337  for (x = 0; x < width; x++) {
338  int suma = p0[x - 1] * -1 +
339  p0[x] * -1 +
340  p0[x + 1] * -1 +
341  p2[x - 1] * 1 +
342  p2[x] * 1 +
343  p2[x + 1] * 1;
344  int sumb = p0[x - 1] * -1 +
345  p0[x + 1] * 1 +
346  p1[x - 1] * -1 +
347  p1[x + 1] * 1 +
348  p2[x - 1] * -1 +
349  p2[x + 1] * 1;
350 
351  dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
352  }
353 
354  p0 = p1;
355  p1 = p2;
356  p2 = (p2 == end) ? orig: p2 + bstride;
357  dst += out->linesize[plane];
358  }
359 
360  return 0;
361 }
362 
363 static int filter_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
364 {
365  ConvolutionContext *s = ctx->priv;
366  ThreadData *td = arg;
367  AVFrame *in = td->in;
368  AVFrame *out = td->out;
369  const int plane = td->plane;
370  const int stride = in->linesize[plane];
371  const int bstride = s->bstride;
372  const int height = s->planeheight[plane];
373  const int width = s->planewidth[plane];
374  const int slice_start = (height * jobnr) / nb_jobs;
375  const int slice_end = (height * (jobnr+1)) / nb_jobs;
376  const uint8_t *src = in->data[plane] + slice_start * stride;
377  uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
378  const float scale = s->scale;
379  const float delta = s->delta;
380  uint8_t *p0 = s->bptrs[jobnr] + 16;
381  uint8_t *p1 = p0 + bstride;
382  uint8_t *p2 = p1 + bstride;
383  uint8_t *orig = p0, *end = p2;
384  int y, x;
385 
386  line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
387  line_copy8(p1, src, width, 1);
388 
389  for (y = slice_start; y < slice_end; y++) {
390  src += stride * (y < height - 1 ? 1 : -1);
391  line_copy8(p2, src, width, 1);
392 
393  for (x = 0; x < width; x++) {
394  int suma = p0[x - 1] * 1 +
395  p1[x ] * -1;
396  int sumb = p0[x ] * 1 +
397  p1[x - 1] * -1;
398 
399  dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
400  }
401 
402  p0 = p1;
403  p1 = p2;
404  p2 = (p2 == end) ? orig: p2 + bstride;
405  dst += out->linesize[plane];
406  }
407 
408  return 0;
409 }
410 
411 static int filter_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
412 {
413  ConvolutionContext *s = ctx->priv;
414  ThreadData *td = arg;
415  AVFrame *in = td->in;
416  AVFrame *out = td->out;
417  const int plane = td->plane;
418  const int stride = in->linesize[plane];
419  const int bstride = s->bstride;
420  const int height = s->planeheight[plane];
421  const int width = s->planewidth[plane];
422  const int slice_start = (height * jobnr) / nb_jobs;
423  const int slice_end = (height * (jobnr+1)) / nb_jobs;
424  const uint8_t *src = in->data[plane] + slice_start * stride;
425  uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
426  const float scale = s->scale;
427  const float delta = s->delta;
428  uint8_t *p0 = s->bptrs[jobnr] + 16;
429  uint8_t *p1 = p0 + bstride;
430  uint8_t *p2 = p1 + bstride;
431  uint8_t *orig = p0, *end = p2;
432  int y, x;
433 
434  line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
435  line_copy8(p1, src, width, 1);
436 
437  for (y = slice_start; y < slice_end; y++) {
438  src += stride * (y < height - 1 ? 1 : -1);
439  line_copy8(p2, src, width, 1);
440 
441  for (x = 0; x < width; x++) {
442  int suma = p0[x - 1] * -1 +
443  p0[x] * -2 +
444  p0[x + 1] * -1 +
445  p2[x - 1] * 1 +
446  p2[x] * 2 +
447  p2[x + 1] * 1;
448  int sumb = p0[x - 1] * -1 +
449  p0[x + 1] * 1 +
450  p1[x - 1] * -2 +
451  p1[x + 1] * 2 +
452  p2[x - 1] * -1 +
453  p2[x + 1] * 1;
454 
455  dst[x] = av_clip_uint8(sqrt(suma*suma + sumb*sumb) * scale + delta);
456  }
457 
458  p0 = p1;
459  p1 = p2;
460  p2 = (p2 == end) ? orig: p2 + bstride;
461  dst += out->linesize[plane];
462  }
463 
464  return 0;
465 }
466 
467 static int filter16_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
468 {
469  ConvolutionContext *s = ctx->priv;
470  ThreadData *td = arg;
471  AVFrame *in = td->in;
472  AVFrame *out = td->out;
473  const int plane = td->plane;
474  const int peak = (1 << s->depth) - 1;
475  const int stride = in->linesize[plane] / 2;
476  const int bstride = s->bstride;
477  const int height = s->planeheight[plane];
478  const int width = s->planewidth[plane];
479  const int slice_start = (height * jobnr) / nb_jobs;
480  const int slice_end = (height * (jobnr+1)) / nb_jobs;
481  const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
482  uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
483  uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
484  uint16_t *p1 = p0 + bstride;
485  uint16_t *p2 = p1 + bstride;
486  uint16_t *orig = p0, *end = p2;
487  const int *matrix = s->matrix[plane];
488  const float rdiv = s->rdiv[plane];
489  const float bias = s->bias[plane];
490  int y, x;
491 
492  line_copy16(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
493  line_copy16(p1, src, width, 1);
494 
495  for (y = slice_start; y < slice_end; y++) {
496  src += stride * (y < height - 1 ? 1 : -1);
497  line_copy16(p2, src, width, 1);
498 
499  for (x = 0; x < width; x++) {
500  int sum = p0[x - 1] * matrix[0] +
501  p0[x] * matrix[1] +
502  p0[x + 1] * matrix[2] +
503  p1[x - 1] * matrix[3] +
504  p1[x] * matrix[4] +
505  p1[x + 1] * matrix[5] +
506  p2[x - 1] * matrix[6] +
507  p2[x] * matrix[7] +
508  p2[x + 1] * matrix[8];
509  sum = (int)(sum * rdiv + bias + 0.5f);
510  dst[x] = av_clip(sum, 0, peak);
511  }
512 
513  p0 = p1;
514  p1 = p2;
515  p2 = (p2 == end) ? orig: p2 + bstride;
516  dst += out->linesize[plane] / 2;
517  }
518 
519  return 0;
520 }
521 
522 static int filter16_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
523 {
524  ConvolutionContext *s = ctx->priv;
525  ThreadData *td = arg;
526  AVFrame *in = td->in;
527  AVFrame *out = td->out;
528  const int plane = td->plane;
529  const int peak = (1 << s->depth) - 1;
530  const int stride = in->linesize[plane] / 2;
531  const int bstride = s->bstride;
532  const int height = s->planeheight[plane];
533  const int width = s->planewidth[plane];
534  const int slice_start = (height * jobnr) / nb_jobs;
535  const int slice_end = (height * (jobnr+1)) / nb_jobs;
536  const uint16_t *src = (const uint16_t *)in->data[plane] + slice_start * stride;
537  uint16_t *dst = (uint16_t *)out->data[plane] + slice_start * (out->linesize[plane] / 2);
538  uint16_t *p0 = (uint16_t *)s->bptrs[jobnr] + 16;
539  uint16_t *p1 = p0 + bstride;
540  uint16_t *p2 = p1 + bstride;
541  uint16_t *p3 = p2 + bstride;
542  uint16_t *p4 = p3 + bstride;
543  uint16_t *orig = p0, *end = p4;
544  const int *matrix = s->matrix[plane];
545  float rdiv = s->rdiv[plane];
546  float bias = s->bias[plane];
547  int y, x, i;
548 
549  line_copy16(p0, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 2);
550  line_copy16(p1, src + stride * (slice_start == 0 ? 1 : -1), width, 2);
551  line_copy16(p2, src, width, 2);
552  src += stride;
553  line_copy16(p3, src, width, 2);
554 
555  for (y = slice_start; y < slice_end; y++) {
556  uint16_t *array[] = {
557  p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2,
558  p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2,
559  p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2,
560  p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2,
561  p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2
562  };
563 
564  src += stride * (y < height - 2 ? 1 : -1);
565  line_copy16(p4, src, width, 2);
566 
567  for (x = 0; x < width; x++) {
568  int sum = 0;
569 
570  for (i = 0; i < 25; i++) {
571  sum += *(array[i] + x) * matrix[i];
572  }
573  sum = (int)(sum * rdiv + bias + 0.5f);
574  dst[x] = av_clip(sum, 0, peak);
575  }
576 
577  p0 = p1;
578  p1 = p2;
579  p2 = p3;
580  p3 = p4;
581  p4 = (p4 == end) ? orig: p4 + bstride;
582  dst += out->linesize[plane] / 2;
583  }
584 
585  return 0;
586 }
587 
588 static int filter_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
589 {
590  ConvolutionContext *s = ctx->priv;
591  ThreadData *td = arg;
592  AVFrame *in = td->in;
593  AVFrame *out = td->out;
594  const int plane = td->plane;
595  const int stride = in->linesize[plane];
596  const int bstride = s->bstride;
597  const int height = s->planeheight[plane];
598  const int width = s->planewidth[plane];
599  const int slice_start = (height * jobnr) / nb_jobs;
600  const int slice_end = (height * (jobnr+1)) / nb_jobs;
601  const uint8_t *src = in->data[plane] + slice_start * stride;
602  uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
603  uint8_t *p0 = s->bptrs[jobnr] + 16;
604  uint8_t *p1 = p0 + bstride;
605  uint8_t *p2 = p1 + bstride;
606  uint8_t *orig = p0, *end = p2;
607  const int *matrix = s->matrix[plane];
608  const float rdiv = s->rdiv[plane];
609  const float bias = s->bias[plane];
610  int y, x;
611 
612  line_copy8(p0, src + stride * (slice_start == 0 ? 1 : -1), width, 1);
613  line_copy8(p1, src, width, 1);
614 
615  for (y = slice_start; y < slice_end; y++) {
616  src += stride * (y < height - 1 ? 1 : -1);
617  line_copy8(p2, src, width, 1);
618 
619  for (x = 0; x < width; x++) {
620  int sum = p0[x - 1] * matrix[0] +
621  p0[x] * matrix[1] +
622  p0[x + 1] * matrix[2] +
623  p1[x - 1] * matrix[3] +
624  p1[x] * matrix[4] +
625  p1[x + 1] * matrix[5] +
626  p2[x - 1] * matrix[6] +
627  p2[x] * matrix[7] +
628  p2[x + 1] * matrix[8];
629  sum = (int)(sum * rdiv + bias + 0.5f);
630  dst[x] = av_clip_uint8(sum);
631  }
632 
633  p0 = p1;
634  p1 = p2;
635  p2 = (p2 == end) ? orig: p2 + bstride;
636  dst += out->linesize[plane];
637  }
638 
639  return 0;
640 }
641 
642 static int filter_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
643 {
644  ConvolutionContext *s = ctx->priv;
645  ThreadData *td = arg;
646  AVFrame *in = td->in;
647  AVFrame *out = td->out;
648  const int plane = td->plane;
649  const int stride = in->linesize[plane];
650  const int bstride = s->bstride;
651  const int height = s->planeheight[plane];
652  const int width = s->planewidth[plane];
653  const int slice_start = (height * jobnr) / nb_jobs;
654  const int slice_end = (height * (jobnr+1)) / nb_jobs;
655  const uint8_t *src = in->data[plane] + slice_start * stride;
656  uint8_t *dst = out->data[plane] + slice_start * out->linesize[plane];
657  uint8_t *p0 = s->bptrs[jobnr] + 16;
658  uint8_t *p1 = p0 + bstride;
659  uint8_t *p2 = p1 + bstride;
660  uint8_t *p3 = p2 + bstride;
661  uint8_t *p4 = p3 + bstride;
662  uint8_t *orig = p0, *end = p4;
663  const int *matrix = s->matrix[plane];
664  float rdiv = s->rdiv[plane];
665  float bias = s->bias[plane];
666  int y, x, i;
667 
668  line_copy8(p0, src + 2 * stride * (slice_start < 2 ? 1 : -1), width, 2);
669  line_copy8(p1, src + stride * (slice_start == 0 ? 1 : -1), width, 2);
670  line_copy8(p2, src, width, 2);
671  src += stride;
672  line_copy8(p3, src, width, 2);
673 
674 
675  for (y = slice_start; y < slice_end; y++) {
676  uint8_t *array[] = {
677  p0 - 2, p0 - 1, p0, p0 + 1, p0 + 2,
678  p1 - 2, p1 - 1, p1, p1 + 1, p1 + 2,
679  p2 - 2, p2 - 1, p2, p2 + 1, p2 + 2,
680  p3 - 2, p3 - 1, p3, p3 + 1, p3 + 2,
681  p4 - 2, p4 - 1, p4, p4 + 1, p4 + 2
682  };
683 
684  src += stride * (y < height - 2 ? 1 : -1);
685  line_copy8(p4, src, width, 2);
686 
687  for (x = 0; x < width; x++) {
688  int sum = 0;
689 
690  for (i = 0; i < 25; i++) {
691  sum += *(array[i] + x) * matrix[i];
692  }
693  sum = (int)(sum * rdiv + bias + 0.5f);
694  dst[x] = av_clip_uint8(sum);
695  }
696 
697  p0 = p1;
698  p1 = p2;
699  p2 = p3;
700  p3 = p4;
701  p4 = (p4 == end) ? orig: p4 + bstride;
702  dst += out->linesize[plane];
703  }
704 
705  return 0;
706 }
707 
708 static int config_input(AVFilterLink *inlink)
709 {
710  AVFilterContext *ctx = inlink->dst;
711  ConvolutionContext *s = ctx->priv;
713  int p;
714 
715  s->depth = desc->comp[0].depth;
716 
717  s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w);
718  s->planewidth[0] = s->planewidth[3] = inlink->w;
719  s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h);
720  s->planeheight[0] = s->planeheight[3] = inlink->h;
721 
724  s->bptrs = av_calloc(s->nb_threads, sizeof(*s->bptrs));
725  if (!s->bptrs)
726  return AVERROR(ENOMEM);
727 
728  s->bstride = s->planewidth[0] + 32;
729  s->bpc = (s->depth + 7) / 8;
730  s->buffer = av_malloc_array(5 * s->bstride * s->nb_threads, s->bpc);
731  if (!s->buffer)
732  return AVERROR(ENOMEM);
733 
734  for (p = 0; p < s->nb_threads; p++) {
735  s->bptrs[p] = s->buffer + 5 * s->bstride * s->bpc * p;
736  }
737 
738  if (!strcmp(ctx->filter->name, "convolution")) {
739  if (s->depth > 8) {
740  for (p = 0; p < s->nb_planes; p++) {
741  if (s->size[p] == 3)
742  s->filter[p] = filter16_3x3;
743  else if (s->size[p] == 5)
744  s->filter[p] = filter16_5x5;
745  }
746  }
747  } else if (!strcmp(ctx->filter->name, "prewitt")) {
748  if (s->depth > 8)
749  for (p = 0; p < s->nb_planes; p++)
750  s->filter[p] = filter16_prewitt;
751  } else if (!strcmp(ctx->filter->name, "roberts")) {
752  if (s->depth > 8)
753  for (p = 0; p < s->nb_planes; p++)
754  s->filter[p] = filter16_roberts;
755  } else if (!strcmp(ctx->filter->name, "sobel")) {
756  if (s->depth > 8)
757  for (p = 0; p < s->nb_planes; p++)
758  s->filter[p] = filter16_sobel;
759  }
760 
761  return 0;
762 }
763 
764 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
765 {
766  AVFilterContext *ctx = inlink->dst;
767  ConvolutionContext *s = ctx->priv;
768  AVFilterLink *outlink = ctx->outputs[0];
769  AVFrame *out;
770  int plane;
771 
772  out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
773  if (!out) {
774  av_frame_free(&in);
775  return AVERROR(ENOMEM);
776  }
777  av_frame_copy_props(out, in);
778 
779  for (plane = 0; plane < s->nb_planes; plane++) {
780  ThreadData td;
781 
782  if (s->copy[plane]) {
783  av_image_copy_plane(out->data[plane], out->linesize[plane],
784  in->data[plane], in->linesize[plane],
785  s->planewidth[plane] * s->bpc,
786  s->planeheight[plane]);
787  continue;
788  }
789 
790  td.in = in;
791  td.out = out;
792  td.plane = plane;
793  ctx->internal->execute(ctx, s->filter[plane], &td, NULL, FFMIN(s->planeheight[plane], s->nb_threads));
794  }
795 
796  av_frame_free(&in);
797  return ff_filter_frame(outlink, out);
798 }
799 
801 {
802  ConvolutionContext *s = ctx->priv;
803  int i;
804 
805  if (!strcmp(ctx->filter->name, "convolution")) {
806  for (i = 0; i < 4; i++) {
807  int *matrix = (int *)s->matrix[i];
808  char *p, *arg, *saveptr = NULL;
809 
810  p = s->matrix_str[i];
811  while (s->matrix_length[i] < 25) {
812  if (!(arg = av_strtok(p, " ", &saveptr)))
813  break;
814 
815  p = NULL;
816  sscanf(arg, "%d", &matrix[s->matrix_length[i]]);
817  s->matrix_length[i]++;
818  }
819 
820  if (s->matrix_length[i] == 9) {
821  s->size[i] = 3;
822  if (!memcmp(matrix, same3x3, sizeof(same3x3)))
823  s->copy[i] = 1;
824  else
825  s->filter[i] = filter_3x3;
826  } else if (s->matrix_length[i] == 25) {
827  s->size[i] = 5;
828  if (!memcmp(matrix, same5x5, sizeof(same5x5)))
829  s->copy[i] = 1;
830  else
831  s->filter[i] = filter_5x5;
832  } else {
833  return AVERROR(EINVAL);
834  }
835  }
836  } else if (!strcmp(ctx->filter->name, "prewitt")) {
837  for (i = 0; i < 4; i++) {
838  if ((1 << i) & s->planes)
839  s->filter[i] = filter_prewitt;
840  else
841  s->copy[i] = 1;
842  }
843  } else if (!strcmp(ctx->filter->name, "roberts")) {
844  for (i = 0; i < 4; i++) {
845  if ((1 << i) & s->planes)
846  s->filter[i] = filter_roberts;
847  else
848  s->copy[i] = 1;
849  }
850  } else if (!strcmp(ctx->filter->name, "sobel")) {
851  for (i = 0; i < 4; i++) {
852  if ((1 << i) & s->planes)
853  s->filter[i] = filter_sobel;
854  else
855  s->copy[i] = 1;
856  }
857  }
858 
859  return 0;
860 }
861 
863 {
864  ConvolutionContext *s = ctx->priv;
865 
866  av_freep(&s->bptrs);
867  av_freep(&s->buffer);
868 }
869 
870 static const AVFilterPad convolution_inputs[] = {
871  {
872  .name = "default",
873  .type = AVMEDIA_TYPE_VIDEO,
874  .config_props = config_input,
875  .filter_frame = filter_frame,
876  },
877  { NULL }
878 };
879 
881  {
882  .name = "default",
883  .type = AVMEDIA_TYPE_VIDEO,
884  },
885  { NULL }
886 };
887 
888 #if CONFIG_CONVOLUTION_FILTER
889 
890 AVFilter ff_vf_convolution = {
891  .name = "convolution",
892  .description = NULL_IF_CONFIG_SMALL("Apply convolution filter."),
893  .priv_size = sizeof(ConvolutionContext),
894  .priv_class = &convolution_class,
895  .init = init,
896  .uninit = uninit,
898  .inputs = convolution_inputs,
899  .outputs = convolution_outputs,
901 };
902 
903 #endif /* CONFIG_CONVOLUTION_FILTER */
904 
905 #if CONFIG_PREWITT_FILTER
906 
907 static const AVOption prewitt_options[] = {
908  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
909  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
910  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
911  { NULL }
912 };
913 
914 AVFILTER_DEFINE_CLASS(prewitt);
915 
916 AVFilter ff_vf_prewitt = {
917  .name = "prewitt",
918  .description = NULL_IF_CONFIG_SMALL("Apply prewitt operator."),
919  .priv_size = sizeof(ConvolutionContext),
920  .priv_class = &prewitt_class,
921  .init = init,
922  .uninit = uninit,
924  .inputs = convolution_inputs,
925  .outputs = convolution_outputs,
927 };
928 
929 #endif /* CONFIG_PREWITT_FILTER */
930 
931 #if CONFIG_SOBEL_FILTER
932 
933 static const AVOption sobel_options[] = {
934  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
935  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
936  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
937  { NULL }
938 };
939 
941 
942 AVFilter ff_vf_sobel = {
943  .name = "sobel",
944  .description = NULL_IF_CONFIG_SMALL("Apply sobel operator."),
945  .priv_size = sizeof(ConvolutionContext),
946  .priv_class = &sobel_class,
947  .init = init,
948  .uninit = uninit,
950  .inputs = convolution_inputs,
951  .outputs = convolution_outputs,
953 };
954 
955 #endif /* CONFIG_SOBEL_FILTER */
956 
957 #if CONFIG_ROBERTS_FILTER
958 
959 static const AVOption roberts_options[] = {
960  { "planes", "set planes to filter", OFFSET(planes), AV_OPT_TYPE_INT, {.i64=15}, 0, 15, FLAGS},
961  { "scale", "set scale", OFFSET(scale), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, 0.0, 65535, FLAGS},
962  { "delta", "set delta", OFFSET(delta), AV_OPT_TYPE_FLOAT, {.dbl=0}, -65535, 65535, FLAGS},
963  { NULL }
964 };
965 
966 AVFILTER_DEFINE_CLASS(roberts);
967 
968 AVFilter ff_vf_roberts = {
969  .name = "roberts",
970  .description = NULL_IF_CONFIG_SMALL("Apply roberts cross operator."),
971  .priv_size = sizeof(ConvolutionContext),
972  .priv_class = &roberts_class,
973  .init = init,
974  .uninit = uninit,
976  .inputs = convolution_inputs,
977  .outputs = convolution_outputs,
979 };
980 
981 #endif /* CONFIG_ROBERTS_FILTER */
int plane
Definition: avisynth_c.h:422
static int filter16_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define NULL
Definition: coverity.c:32
#define AV_PIX_FMT_YUVA422P16
Definition: pixfmt.h:418
const char * s
Definition: avisynth_c.h:768
AVFrame * out
Definition: af_headphone.c:146
static int filter16_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA422P9
Definition: pixfmt.h:412
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2419
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
AVOption.
Definition: opt.h:246
#define AV_PIX_FMT_YUVA420P10
Definition: pixfmt.h:414
#define AV_PIX_FMT_YUV444P14
Definition: pixfmt.h:389
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:399
#define AV_PIX_FMT_YUVA422P10
Definition: pixfmt.h:415
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
misc image utilities
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2459
Main libavfilter public API header.
static void sobel(int w, int h, uint16_t *dst, int dst_linesize, int8_t *dir, int dir_linesize, const uint8_t *src, int src_linesize)
const char * desc
Definition: nvenc.c:60
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:395
static int filter16_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_GRAY9
Definition: pixfmt.h:360
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:383
static int filter_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
Definition: video.c:92
#define src
Definition: vp8dsp.c:254
int(* filter[4])(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
Definition: pixdesc.h:92
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
Definition: mem.c:230
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:361
#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
BYTE int const BYTE * srcp
Definition: avisynth_c.h:813
const char * name
Pad name.
Definition: internal.h:60
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:362
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
Definition: avfilter.c:1151
AVFrame * in
Definition: af_headphone.c:146
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:82
float delta
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
static int filter_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AV_PIX_FMT_YUVA420P9
Definition: pixfmt.h:411
#define AV_PIX_FMT_GBRP9
Definition: pixfmt.h:394
#define height
int plane
Definition: vf_blend.c:57
static av_cold void uninit(AVFilterContext *ctx)
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
Definition: pixfmt.h:101
static int flags
Definition: log.c:57
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:75
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:392
ptrdiff_t size
Definition: opengl_enc.c:101
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:384
#define AV_PIX_FMT_YUVA420P16
Definition: pixfmt.h:417
static void line_copy16(uint16_t *line, const uint16_t *srcp, int width, int mergin)
A filter pad used for either input or output.
Definition: internal.h:54
static void line_copy8(uint8_t *line, const uint8_t *srcp, int width, int mergin)
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:188
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
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
static int filter16_roberts(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
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:419
const char * arg
Definition: jacosubdec.c:66
Definition: graph2dot.c:48
uint16_t width
Definition: gdv.c:47
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:400
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:382
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:401
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
#define AV_PIX_FMT_YUV422P9
Definition: pixfmt.h:377
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:398
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Definition: avfilter.c:857
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:363
static const AVFilterPad convolution_outputs[]
#define FFMIN(a, b)
Definition: common.h:96
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:74
static const AVOption convolution_options[]
AVFormatContext * ctx
Definition: movenc.c:48
static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
#define AV_PIX_FMT_YUVA444P10
Definition: pixfmt.h:416
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:389
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:378
#define AV_PIX_FMT_GBRP14
Definition: pixfmt.h:397
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:390
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:379
#define AV_PIX_FMT_YUV420P14
Definition: pixfmt.h:387
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:232
static int filter16_sobel(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:189
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> in
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:379
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
Describe the class of an AVClass context structure.
Definition: log.h:67
Filter definition.
Definition: avfilter.h:144
AVFILTER_DEFINE_CLASS(convolution)
static const int same3x3[9]
const char * name
Filter name.
Definition: avfilter.h:148
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:385
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:376
AVFilterLink ** outputs
array of pointers to output links
Definition: avfilter.h:350
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
#define AV_PIX_FMT_YUV422P14
Definition: pixfmt.h:388
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:396
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
Definition: avfilter.h:378
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:380
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:386
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
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
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
int
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:229
static const int same5x5[25]
#define AV_PIX_FMT_YUVA444P9
Definition: pixfmt.h:413
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:76
static int filter_5x5(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
avfilter_execute_func * execute
Definition: internal.h:155
static int filter_prewitt(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
Definition: mpeg12dec.c:2052
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:272
static int config_input(AVFilterLink *inlink)
#define FLAGS
An instance of a filter.
Definition: avfilter.h:338
#define OFFSET(x)
FILE * out
Definition: movenc.c:54
#define av_freep(p)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
static int array[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:106
#define av_malloc_array(a, b)
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:337
static int filter_3x3(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define stride
internal API functions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
const AVFilter * filter
the AVFilter of which this is an instance
Definition: avfilter.h:341
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:391
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58