FFmpeg: libavfilter/vf_convolution.c Source File
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
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
60 };
61
63
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
102 };
103
107
110 const uint8_t *
c[],
int peak,
int radius,
112 {
113 uint16_t *dst = (uint16_t *)dstp;
114 int x;
115
116 for (x = 0; x <
width; x++) {
121
123 }
124 }
125
128 const uint8_t *
c[],
int peak,
int radius,
130 {
131 uint16_t *dst = (uint16_t *)dstp;
132 int x;
133
134 for (x = 0; x <
width; x++) {
137
139 }
140 }
141
144 const uint8_t *
c[],
int peak,
int radius,
146 {
147 uint16_t *dst = (uint16_t *)dstp;
148 int x;
149
150 for (x = 0; x <
width; x++) {
155
157 }
158 }
159
162 const uint8_t *
c[],
int peak,
int radius,
164 {
165 uint16_t *dst = (uint16_t *)dstp;
166 int x;
167
168 for (x = 0; x <
width; x++) {
173
174 suma /= 256.f;
175 sumb /= 256.f;
177 }
178 }
179
182 const uint8_t *
c[],
int peak,
int radius,
184 {
185 uint16_t *dst = (uint16_t *)dstp;
186 const uint16_t *c0 = (
const uint16_t *)
c[0], *
c1 = (
const uint16_t *)
c[1], *
c2 = (
const uint16_t *)
c[2];
187 const uint16_t *c3 = (
const uint16_t *)
c[3], *c5 = (
const uint16_t *)
c[5];
188 const uint16_t *c6 = (
const uint16_t *)
c[6], *c7 = (
const uint16_t *)
c[7], *c8 = (
const uint16_t *)
c[8];
189 int x;
190
191 for (x = 0; x <
width; x++) {
192 int sum0 = c0[x] * 5 +
c1[x] * 5 +
c2[x] * 5 +
193 c3[x] * -3 + c5[x] * -3 +
194 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
195 int sum1 = c0[x] * -3 +
c1[x] * 5 +
c2[x] * 5 +
196 c3[x] * 5 + c5[x] * -3 +
197 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
198 int sum2 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * 5 +
199 c3[x] * 5 + c5[x] * 5 +
200 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
201 int sum3 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
202 c3[x] * 5 + c5[x] * 5 +
203 c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
204 int sum4 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
205 c3[x] * -3 + c5[x] * 5 +
206 c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
207 int sum5 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
208 c3[x] * -3 + c5[x] * -3 +
209 c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
210 int sum6 = c0[x] * 5 +
c1[x] * -3 +
c2[x] * -3 +
211 c3[x] * -3 + c5[x] * -3 +
212 c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
213 int sum7 = c0[x] * 5 +
c1[x] * 5 +
c2[x] * -3 +
214 c3[x] * -3 + c5[x] * -3 +
215 c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
216
217 sum0 =
FFMAX(sum0, sum1);
218 sum2 =
FFMAX(sum2, sum3);
219 sum4 =
FFMAX(sum4, sum5);
220 sum6 =
FFMAX(sum6, sum7);
221 sum0 =
FFMAX(sum0, sum2);
222 sum4 =
FFMAX(sum4, sum6);
223 sum0 =
FFMAX(sum0, sum4);
224
226 }
227 }
228
231 const uint8_t *
c[],
int peak,
int radius,
233 {
234 const uint8_t *c0 =
c[0], *
c1 =
c[1], *
c2 =
c[2];
235 const uint8_t *c3 =
c[3], *c5 =
c[5];
236 const uint8_t *c6 =
c[6], *c7 =
c[7], *c8 =
c[8];
237 int x;
238
239 for (x = 0; x <
width; x++) {
240 float suma = c0[x] * -1 +
c1[x] * -1 +
c2[x] * -1 +
241 c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
242 float sumb = c0[x] * -1 +
c2[x] * 1 + c3[x] * -1 +
243 c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
244
246 }
247 }
248
251 const uint8_t *
c[],
int peak,
int radius,
253 {
254 int x;
255
256 for (x = 0; x <
width; x++) {
257 float suma =
c[0][x] * 1 +
c[1][x] * -1;
258 float sumb =
c[4][x] * 1 +
c[3][x] * -1;
259
261 }
262 }
263
266 const uint8_t *
c[],
int peak,
int radius,
268 {
269 const uint8_t *c0 =
c[0], *
c1 =
c[1], *
c2 =
c[2];
270 const uint8_t *c3 =
c[3], *c5 =
c[5];
271 const uint8_t *c6 =
c[6], *c7 =
c[7], *c8 =
c[8];
272 int x;
273
274 for (x = 0; x <
width; x++) {
275 float suma = c0[x] * -1 +
c1[x] * -2 +
c2[x] * -1 +
276 c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
277 float sumb = c0[x] * -1 +
c2[x] * 1 + c3[x] * -2 +
278 c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
279
281 }
282 }
283
286 const uint8_t *
c[],
int peak,
int radius,
288 {
289 const uint8_t *c0 =
c[0], *
c1 =
c[1], *
c2 =
c[2];
290 const uint8_t *c3 =
c[3], *c5 =
c[5];
291 const uint8_t *c6 =
c[6], *c7 =
c[7], *c8 =
c[8];
292 int x;
293
294 for (x = 0; x <
width; x++) {
295 float suma = c0[x] * -47 +
c1[x] * -162 +
c2[x] * -47 +
296 c6[x] * 47 + c7[x] * 162 + c8[x] * 47;
297 float sumb = c0[x] * -47 +
c2[x] * 47 + c3[x] * -162 +
298 c5[x] * 162 + c6[x] * -47 + c8[x] * 47;
299
300 suma /= 256.f;
301 sumb /= 256.f;
303 }
304 }
305
308 const uint8_t *
c[],
int peak,
int radius,
310 {
311 const uint8_t *c0 =
c[0], *
c1 =
c[1], *
c2 =
c[2];
312 const uint8_t *c3 =
c[3], *c5 =
c[5];
313 const uint8_t *c6 =
c[6], *c7 =
c[7], *c8 =
c[8];
314 int x;
315
316 for (x = 0; x <
width; x++) {
317 int sum0 = c0[x] * 5 +
c1[x] * 5 +
c2[x] * 5 +
318 c3[x] * -3 + c5[x] * -3 +
319 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
320 int sum1 = c0[x] * -3 +
c1[x] * 5 +
c2[x] * 5 +
321 c3[x] * 5 + c5[x] * -3 +
322 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
323 int sum2 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * 5 +
324 c3[x] * 5 + c5[x] * 5 +
325 c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
326 int sum3 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
327 c3[x] * 5 + c5[x] * 5 +
328 c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
329 int sum4 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
330 c3[x] * -3 + c5[x] * 5 +
331 c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
332 int sum5 = c0[x] * -3 +
c1[x] * -3 +
c2[x] * -3 +
333 c3[x] * -3 + c5[x] * -3 +
334 c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
335 int sum6 = c0[x] * 5 +
c1[x] * -3 +
c2[x] * -3 +
336 c3[x] * -3 + c5[x] * -3 +
337 c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
338 int sum7 = c0[x] * 5 +
c1[x] * 5 +
c2[x] * -3 +
339 c3[x] * -3 + c5[x] * -3 +
340 c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
341
342 sum0 =
FFMAX(sum0, sum1);
343 sum2 =
FFMAX(sum2, sum3);
344 sum4 =
FFMAX(sum4, sum5);
345 sum6 =
FFMAX(sum6, sum7);
346 sum0 =
FFMAX(sum0, sum2);
347 sum4 =
FFMAX(sum4, sum6);
348 sum0 =
FFMAX(sum0, sum4);
349
351 }
352 }
353
355 float rdiv,
float bias,
const int *
const matrix,
356 const uint8_t *
c[],
int peak,
int radius,
358 {
359 uint16_t *dst = (uint16_t *)dstp;
360 int x;
361
362 for (x = 0; x <
width; x++) {
372 sum = (
int)(sum * rdiv + bias + 0.5
f);
373 dst[x] =
av_clip(sum, 0, peak);
374 }
375 }
376
378 float rdiv,
float bias,
const int *
const matrix,
379 const uint8_t *
c[],
int peak,
int radius,
381 {
382 uint16_t *dst = (uint16_t *)dstp;
383 int x;
384
385 for (x = 0; x <
width; x++) {
387
388 for (
i = 0;
i < 25;
i++)
390
391 sum = (
int)(sum * rdiv + bias + 0.5
f);
392 dst[x] =
av_clip(sum, 0, peak);
393 }
394 }
395
397 float rdiv,
float bias,
const int *
const matrix,
398 const uint8_t *
c[],
int peak,
int radius,
400 {
401 uint16_t *dst = (uint16_t *)dstp;
402 int x;
403
404 for (x = 0; x <
width; x++) {
406
407 for (
i = 0;
i < 49;
i++)
409
410 sum = (
int)(sum * rdiv + bias + 0.5
f);
411 dst[x] =
av_clip(sum, 0, peak);
412 }
413 }
414
416 float rdiv,
float bias,
const int *
const matrix,
417 const uint8_t *
c[],
int peak,
int radius,
419 {
420 uint16_t *dst = (uint16_t *)dstp;
421 int x;
422
423 for (x = 0; x <
width; x++) {
425
426 for (
i = 0;
i < 2 * radius + 1;
i++)
428
429 sum = (
int)(sum * rdiv + bias + 0.5
f);
430 dst[x] =
av_clip(sum, 0, peak);
431 }
432 }
433
435 float rdiv,
float bias,
const int *
const matrix,
436 const uint8_t *
c[],
int peak,
int radius,
438 {
440 uint16_t *dst = (uint16_t *)dstp;
442
443 for (
int y = 0; y <
height; y++) {
444
445 memset(sum, 0, sizeof(sum));
446 for (
int i = 0;
i < 2 * radius + 1;
i++) {
447 for (
int off16 = 0; off16 <
width; off16++)
449 }
450
451 for (
int off16 = 0; off16 <
width; off16++) {
452 sum[off16] = (
int)(sum[off16] * rdiv + bias + 0.5
f);
453 dst[off16] =
av_clip(sum[off16], 0, peak);
454 }
455 dst += dstride / 2;
456 }
457 }
458
460 float rdiv,
float bias,
const int *
const matrix,
461 const uint8_t *
c[],
int peak,
int radius,
463 {
464 int x;
465
466 for (x = 0; x <
width; x++) {
468
469 for (
i = 0;
i < 49;
i++)
471
472 sum = (
int)(sum * rdiv + bias + 0.5
f);
474 }
475 }
476
478 float rdiv,
float bias,
const int *
const matrix,
479 const uint8_t *
c[],
int peak,
int radius,
481 {
482 int x;
483
484 for (x = 0; x <
width; x++) {
486
487 for (
i = 0;
i < 25;
i++)
489
490 sum = (
int)(sum * rdiv + bias + 0.5
f);
492 }
493 }
494
496 float rdiv,
float bias,
const int *
const matrix,
497 const uint8_t *
c[],
int peak,
int radius,
499 {
500 const uint8_t *c0 =
c[0], *
c1 =
c[1], *
c2 =
c[2];
501 const uint8_t *c3 =
c[3], *c4 =
c[4], *c5 =
c[5];
502 const uint8_t *c6 =
c[6], *c7 =
c[7], *c8 =
c[8];
503 int x;
504
505 for (x = 0; x <
width; x++) {
509 sum = (
int)(sum * rdiv + bias + 0.5
f);
511 }
512 }
513
515 float rdiv,
float bias,
const int *
const matrix,
516 const uint8_t *
c[],
int peak,
int radius,
518 {
519 int x;
520
521 for (x = 0; x <
width; x++) {
523
524 for (
i = 0;
i < 2 * radius + 1;
i++)
526
527 sum = (
int)(sum * rdiv + bias + 0.5
f);
529 }
530 }
531
533 float rdiv,
float bias,
const int *
const matrix,
534 const uint8_t *
c[],
int peak,
int radius,
536 {
538
539 for (
int y = 0; y <
height; y++) {
540 memset(sum, 0, sizeof(sum));
541
542 for (
int i = 0;
i < 2 * radius + 1;
i++) {
543 for (int off16 = 0; off16 < 16; off16++)
545 }
546
547 for (int off16 = 0; off16 < 16; off16++) {
548 sum[off16] = (
int)(sum[off16] * rdiv + bias + 0.5
f);
550 }
551 dst += dstride;
552 }
553 }
554
556 int x,
int w,
int y,
int h,
int bpc)
557 {
559
560 for (
i = 0;
i < 9;
i++) {
561 int xoff =
FFABS(x + ((
i % 3) - 1));
562 int yoff =
FFABS(y + (
i / 3) - 1);
563
564 xoff = xoff >=
w ? 2 *
w - 1 - xoff : xoff;
565 yoff = yoff >=
h ? 2 *
h - 1 - yoff : yoff;
566
568 }
569 }
570
572 int x,
int w,
int y,
int h,
int bpc)
573 {
575
576 for (
i = 0;
i < 25;
i++) {
577 int xoff =
FFABS(x + ((
i % 5) - 2));
578 int yoff =
FFABS(y + (
i / 5) - 2);
579
580 xoff = xoff >=
w ? 2 *
w - 1 - xoff : xoff;
581 yoff = yoff >=
h ? 2 *
h - 1 - yoff : yoff;
582
584 }
585 }
586
588 int x,
int w,
int y,
int h,
int bpc)
589 {
591
592 for (
i = 0;
i < 49;
i++) {
593 int xoff =
FFABS(x + ((
i % 7) - 3));
594 int yoff =
FFABS(y + (
i / 7) - 3);
595
596 xoff = xoff >=
w ? 2 *
w - 1 - xoff : xoff;
597 yoff = yoff >=
h ? 2 *
h - 1 - yoff : yoff;
598
600 }
601 }
602
604 int x,
int w,
int y,
int h,
int bpc)
605 {
607
608 for (
i = 0;
i < radius * 2 + 1;
i++) {
609 int xoff =
FFABS(x +
i - radius);
610
611 xoff = xoff >=
w ? 2 *
w - 1 - xoff : xoff;
612
614 }
615 }
616
618 int x,
int w,
int y,
int h,
int bpc)
619 {
621
622 for (
i = 0;
i < radius * 2 + 1;
i++) {
623 int xoff =
FFABS(x +
i - radius);
624
625 xoff = xoff >=
h ? 2 *
h - 1 - xoff : xoff;
626
628 }
629 }
630
632 {
637 int plane;
638
639 for (plane = 0; plane <
s->nb_planes; plane++) {
640 const int mode =
s->mode[plane];
641 const int bpc =
s->bpc;
642 const int radius =
s->size[plane] / 2;
643 const int height =
s->planeheight[plane];
644 const int width =
s->planewidth[plane];
646 const int dstride =
out->linesize[plane];
649 const int slice_start = (sizeh * jobnr) / nb_jobs;
650 const int slice_end = (sizeh * (jobnr+1)) / nb_jobs;
651 const float rdiv =
s->rdiv[plane];
652 const float bias =
s->bias[plane];
653 const uint8_t *
src = in->
data[plane];
655 uint8_t *dst =
out->data[plane] + dst_pos;
656 const int *
matrix =
s->matrix[plane];
658 const uint8_t *
c[49];
659 int y, x;
660
661 if (
s->copy[plane]) {
665 else
668 continue;
669 }
673
674 for (x = 0; x < radius; x++) {
677
679 s->filter[plane](dst + yoff + xoff, 1, rdiv,
682 }
684 s->filter[plane](dst + yoff + xoff, sizew - 2 * radius,
685 rdiv, bias,
matrix,
c,
s->max, radius,
687 for (x = sizew - radius; x < sizew; x++) {
690
692 s->filter[plane](dst + yoff + xoff, 1, rdiv,
695 }
697 dst += dstride;
698 }
699 }
700
701 return 0;
702 }
703
705 {
710
711 if (!strcmp(
ctx->filter->name,
"convolution")) {
712 for (
i = 0;
i < 4;
i++) {
714 char *orig, *p, *
arg, *saveptr =
NULL;
715 float sum = 1.f;
716
718 if (p) {
719 s->matrix_length[
i] = 0;
721 sum = 0.f;
722
723 while (
s->matrix_length[
i] < 49) {
725 break;
726
730 s->matrix_length[
i]++;
731 }
732
734 if (!(
s->matrix_length[
i] & 1)) {
737 }
738 }
739
743 s->size[
i] =
s->matrix_length[
i];
747 s->size[
i] =
s->matrix_length[
i];
748 }
else if (
s->matrix_length[
i] == 9) {
750
753 } else {
756 }
758 }
else if (
s->matrix_length[
i] == 25) {
762 } else {
765 }
767 }
else if (
s->matrix_length[
i] == 49) {
771 } else {
774 }
776 } else {
778 }
779
780 if (sum == 0)
781 sum = 1;
783 s->rdiv[
i] = 1. / sum;
784
785 if (
s->copy[
i] && (
s->rdiv[
i] != 1. ||
s->bias[
i] != 0.))
787 }
788 }
else if (!strcmp(
ctx->filter->name,
"prewitt")) {
789 for (
i = 0;
i < 4;
i++) {
791 s->copy[
i] = !((1 <<
i) &
s->planes);
794 s->rdiv[
i] =
s->scale;
795 s->bias[
i] =
s->delta;
796 }
797 }
else if (!strcmp(
ctx->filter->name,
"roberts")) {
798 for (
i = 0;
i < 4;
i++) {
800 s->copy[
i] = !((1 <<
i) &
s->planes);
803 s->rdiv[
i] =
s->scale;
804 s->bias[
i] =
s->delta;
805 }
806 }
else if (!strcmp(
ctx->filter->name,
"sobel")) {
807 for (
i = 0;
i < 4;
i++) {
809 s->copy[
i] = !((1 <<
i) &
s->planes);
812 s->rdiv[
i] =
s->scale;
813 s->bias[
i] =
s->delta;
814 }
815 }
else if (!strcmp(
ctx->filter->name,
"kirsch")) {
816 for (
i = 0;
i < 4;
i++) {
818 s->copy[
i] = !((1 <<
i) &
s->planes);
821 s->rdiv[
i] =
s->scale;
822 s->bias[
i] =
s->delta;
823 }
824 }
else if (!strcmp(
ctx->filter->name,
"scharr")) {
825 for (
i = 0;
i < 4;
i++) {
827 s->copy[
i] = !((1 <<
i) &
s->planes);
830 s->rdiv[
i] =
s->scale;
831 s->bias[
i] =
s->delta;
832 }
833 }
834
835 s->depth =
desc->comp[0].depth;
836 s->max = (1 <<
s->depth) - 1;
837
839 s->planewidth[0] =
s->planewidth[3] =
inlink->w;
841 s->planeheight[0] =
s->planeheight[3] =
inlink->h;
842
845 s->bpc = (
s->depth + 7) / 8;
846
847 if (!strcmp(
ctx->filter->name,
"convolution")) {
849 for (p = 0; p <
s->nb_planes; p++) {
854 else if (
s->size[p] == 3)
856 else if (
s->size[p] == 5)
858 else if (
s->size[p] == 7)
860 }
861 }
862 #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64
864 #endif
865 }
else if (!strcmp(
ctx->filter->name,
"prewitt")) {
867 for (p = 0; p <
s->nb_planes; p++)
869 }
else if (!strcmp(
ctx->filter->name,
"roberts")) {
871 for (p = 0; p <
s->nb_planes; p++)
873 }
else if (!strcmp(
ctx->filter->name,
"sobel")) {
875 for (p = 0; p <
s->nb_planes; p++)
877 }
else if (!strcmp(
ctx->filter->name,
"kirsch")) {
879 for (p = 0; p <
s->nb_planes; p++)
881 }
else if (!strcmp(
ctx->filter->name,
"scharr")) {
883 for (p = 0; p <
s->nb_planes; p++)
885 }
886
887 return 0;
888 }
889
891 {
894 }
895
897 {
903
908 }
910
914 FFMIN3(
s->planeheight[1],
s->planewidth[1],
s->nb_threads));
915
918 }
919
921 char *res,
int res_len,
int flags)
922 {
924
928
930 }
931
933 {
938 },
939 };
940
942 {
945 },
946 };
947
948 #if CONFIG_CONVOLUTION_FILTER
949
951 .
name =
"convolution",
954 .priv_class = &convolution_class,
960 };
961
962 #endif /* CONFIG_CONVOLUTION_FILTER */
963
969 };
970
973
974 #if CONFIG_PREWITT_FILTER
975
980 .priv_class = &common_class,
986 };
987
988 #endif /* CONFIG_PREWITT_FILTER */
989
990 #if CONFIG_SOBEL_FILTER
991
996 .priv_class = &common_class,
1002 };
1003
1004 #endif /* CONFIG_SOBEL_FILTER */
1005
1006 #if CONFIG_ROBERTS_FILTER
1007
1012 .priv_class = &common_class,
1018 };
1019
1020 #endif /* CONFIG_ROBERTS_FILTER */
1021
1022 #if CONFIG_KIRSCH_FILTER
1023
1028 .priv_class = &common_class,
1034 };
1035
1036 #endif /* CONFIG_KIRSCH_FILTER */
1037
1038 #if CONFIG_SCHARR_FILTER
1039
1044 .priv_class = &common_class,
1050 };
1051
1052 #endif /* CONFIG_SCHARR_FILTER */
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_GBRAP16
static const AVOption common_options[]
AVPixelFormat
Pixel format.
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)
static void setup_5x5(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
static const int same5x5[25]
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)
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
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)
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)
int ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
const AVFilter ff_vf_scharr
#define FILTER_PIXFMTS_ARRAY(array)
static const AVFilterPad convolution_inputs[]
const AVFilter ff_vf_roberts
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
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define AV_PIX_FMT_YUVA422P9
This structure describes decoded (raw) audio or video data.
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
#define AV_PIX_FMT_YUVA420P16
#define AV_PIX_FMT_YUVA420P10
const AVFilter ff_vf_kirsch
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)
#define AV_PIX_FMT_YUV420P10
const AVFilter ff_vf_prewitt
@ AV_PIX_FMT_YUV440P
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
const char * name
Filter name.
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)
A link between two filters.
#define AV_PIX_FMT_YUVA422P10
static void filter_sobel(uint8_t *dst, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride, int size)
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_YUVA420P9
#define AV_PIX_FMT_GBRP14
@ AV_PIX_FMT_GBRAP
planar GBRA 4:4:4:4 32bpp
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)
#define AV_PIX_FMT_GBRP10
#define AV_PIX_FMT_YUVA444P16
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)
#define AV_PIX_FMT_YUV422P9
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
static av_always_inline float scale(float x, float s)
#define AV_PIX_FMT_GRAY16
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)
A filter pad used for either input or output.
#define AV_PIX_FMT_YUV444P10
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, char *res, int res_len, int flags)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_PIX_FMT_YUV422P16
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
#define AV_PIX_FMT_GBRAP10
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)
#define AV_PIX_FMT_GBRAP12
@ AV_PIX_FMT_YUVA420P
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
#define AV_PIX_FMT_YUV444P16
#define AV_CEIL_RSHIFT(a, b)
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)
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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().
AVFILTER_DEFINE_CLASS(convolution)
#define AV_PIX_FMT_YUVA444P12
#define AV_PIX_FMT_YUV420P9
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)
#define AV_PIX_FMT_YUV420P16
#define AV_PIX_FMT_GRAY14
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
#define FILTER_INPUTS(array)
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PIX_FMT_GRAY10
#define AV_PIX_FMT_GBRP16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
static __device__ float sqrtf(float a)
#define AV_PIX_FMT_YUV422P10
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
static int param_init(AVFilterContext *ctx)
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
const AVFilter ff_vf_convolution
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)
static const struct @328 planes[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
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)
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUV444P12
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.
@ AV_PIX_FMT_YUVA444P
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
#define AV_PIX_FMT_YUVA444P10
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
#define DECLARE_ALIGNED(n, t, v)
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
#define i(width, name, range_min, range_max)
int w
agreed upon image width
static void setup_7x7(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int w, int y, int h, int bpc)
#define AV_PIX_FMT_GBRP12
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
Used for passing data between threads.
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)
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)
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
const char * name
Pad name.
#define AV_PIX_FMT_YUV444P9
static const AVOption convolution_options[]
#define AV_PIX_FMT_YUVA444P9
#define AV_PIX_FMT_YUV420P12
#define AV_PIX_FMT_YUV422P14
static const AVFilterPad convolution_outputs[]
int h
agreed upon image height
#define AV_PIX_FMT_YUVA422P12
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)
AVFILTER_DEFINE_CLASS_EXT(common, "kirsch/prewitt/roberts/scharr/sobel", common_options)
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
const AVFilter ff_vf_sobel
@ AV_PIX_FMT_GBRP
planar GBR 4:4:4 24bpp
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
char * av_strdup(const char *s)
Duplicate a string.
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
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)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
void ff_convolution_init_x86(ConvolutionContext *s)
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)
static const int same3x3[9]
static int config_input(AVFilterLink *inlink)
static void filter16_sobel(uint8_t *dstp, int width, float scale, float delta, const int *const matrix, const uint8_t *c[], int peak, int radius, int dstride, int stride, int size)
#define FILTER_OUTPUTS(array)
@ AV_PIX_FMT_YUV411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
#define flags(name, subs,...)
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
@ AV_PIX_FMT_YUV410P
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
static const int same7x7[49]
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV444P14
#define AV_PIX_FMT_GRAY12
static av_always_inline int ff_filter_execute(AVFilterContext *ctx, avfilter_action_func *func, void *arg, int *ret, int nb_jobs)
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)
@ AV_PIX_FMT_YUVA422P
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define AV_PIX_FMT_YUV420P14
Generated on Wed Aug 24 2022 21:42:04 for FFmpeg by
doxygen
1.8.17