History

avfilter: add kirsch video filter

Paul B Mahol committed 5 years ago

Commit 35f86281 parent 021dc4f6 files · +158 −1Browse files

Unified · Split

6 files
  1. Changelog +1 −0
  2. doc/filters.texi +21 −0
  3. libavfilter/Makefile +1 −0
  4. libavfilter/allfilters.c +1 −0
  5. libavfilter/version.h +1 −1
  6. libavfilter/vf_convolution.c +133 −0
Changelog+1−0
@@ -59,6 +59,7 @@ version <next>: · 58 unmodified lines
5959 - epx filter
6060 - Dolby E parser
6161 - shear filter
62+- kirsch filter
6263
6364
6465 version 4.3:
doc/filters.texi+21−0
@@ -13400,6 +13400,27 @@ kerndeint=map=1 · 13399 unmodified lines
1340013400 @end example
1340113401 @end itemize
1340213402
13403+@section kirsch
13404+Apply kirsch operator to input video stream.
13405+
13406+The filter accepts the following option:
13407+
13408+@table @option
13409+@item planes
13410+Set which planes will be processed, unprocessed planes will be copied.
13411+By default value 0xf, all planes will be processed.
13412+
13413+@item scale
13414+Set value which will be multiplied with filtered result.
13415+
13416+@item delta
13417+Set value which will be added to filtered result.
13418+@end table
13419+
13420+@subsection Commands
13421+
13422+This filter supports the all above options as @ref{commands}.
13423+
1340313424 @section lagfun
1340413425
1340513426 Slowly update darker pixels.
libavfilter/Makefile+1−0
@@ -298,6 +298,7 @@ OBJS-$(CONFIG_INFLATE_FILTER) += vf_neighbor.o · 297 unmodified lines
298298 OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o
299299 OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
300300 OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o
301+OBJS-$(CONFIG_KIRSCH_FILTER) += vf_convolution.o
301302 OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o
302303 OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
303304 OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
libavfilter/allfilters.c+1−0
@@ -283,6 +283,7 @@ extern AVFilter ff_vf_inflate; · 282 unmodified lines
283283 extern AVFilter ff_vf_interlace;
284284 extern AVFilter ff_vf_interleave;
285285 extern AVFilter ff_vf_kerndeint;
286+extern AVFilter ff_vf_kirsch;
286287 extern AVFilter ff_vf_lagfun;
287288 extern AVFilter ff_vf_lenscorrection;
288289 extern AVFilter ff_vf_lensfun;
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030 #include "libavutil/version.h"
3131
3232 #define LIBAVFILTER_VERSION_MAJOR 7
33−#define LIBAVFILTER_VERSION_MINOR 98
33+#define LIBAVFILTER_VERSION_MINOR 99
3434 #define LIBAVFILTER_VERSION_MICRO 100
3535
3636
libavfilter/vf_convolution.c+133−0
@@ -159,6 +159,55 @@ static void filter16_sobel(uint8_t *dstp, int width, · 158 unmodified lines
159159 }
160160 }
161161
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)
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+
162211 static void filter_prewitt(uint8_t *dst, int width,
163212 float scale, float delta, const int *const matrix,
164213 const uint8_t *c[], int peak, int radius,
@@ -214,6 +263,54 @@ static void filter_sobel(uint8_t *dst, int width, · 49 unmodified lines
214263 }
215264 }
216265
266+static void filter_kirsch(uint8_t *dst, int width,
267+ float scale, float delta, const int *const matrix,
268+ const uint8_t *c[], int peak, int radius,
269+ int dstride, int stride)
270+{
271+ const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
272+ const uint8_t *c3 = c[3], *c5 = c[5];
273+ const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
274+ int x;
275+
276+ for (x = 0; x < width; x++) {
277+ int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
278+ c3[x] * -3 + c5[x] * -3 +
279+ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
280+ int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
281+ c3[x] * 5 + c5[x] * -3 +
282+ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
283+ int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
284+ c3[x] * 5 + c5[x] * 5 +
285+ c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
286+ int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
287+ c3[x] * 5 + c5[x] * 5 +
288+ c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
289+ int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
290+ c3[x] * -3 + c5[x] * 5 +
291+ c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
292+ int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
293+ c3[x] * -3 + c5[x] * -3 +
294+ c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
295+ int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
296+ c3[x] * -3 + c5[x] * -3 +
297+ c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
298+ int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
299+ c3[x] * -3 + c5[x] * -3 +
300+ c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
301+
302+ sum0 = FFMAX(sum0, sum1);
303+ sum2 = FFMAX(sum2, sum3);
304+ sum4 = FFMAX(sum4, sum5);
305+ sum6 = FFMAX(sum6, sum7);
306+ sum0 = FFMAX(sum0, sum2);
307+ sum4 = FFMAX(sum4, sum6);
308+ sum0 = FFMAX(sum0, sum4);
309+
310+ dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta);
311+ }
312+}
313+
217314 static void filter16_3x3(uint8_t *dstp, int width,
218315 float rdiv, float bias, const int *const matrix,
219316 const uint8_t *c[], int peak, int radius,
@@ -604,6 +701,10 @@ static int config_input(AVFilterLink *inlink) · 384 unmodified lines
604701 if (s->depth > 8)
605702 for (p = 0; p < s->nb_planes; p++)
606703 s->filter[p] = filter16_sobel;
704+ } else if (!strcmp(ctx->filter->name, "kirsch")) {
705+ if (s->depth > 8)
706+ for (p = 0; p < s->nb_planes; p++)
707+ s->filter[p] = filter16_kirsch;
607708 }
608709
609710 return 0;
@@ -744,6 +845,17 @@ static av_cold int init(AVFilterContext *ctx) · 134 unmodified lines
744845 s->rdiv[i] = s->scale;
745846 s->bias[i] = s->delta;
746847 }
848+ } else if (!strcmp(ctx->filter->name, "kirsch")) {
849+ for (i = 0; i < 4; i++) {
850+ if ((1 << i) & s->planes)
851+ s->filter[i] = filter_kirsch;
852+ else
853+ s->copy[i] = 1;
854+ s->size[i] = 3;
855+ s->setup[i] = setup_3x3;
856+ s->rdiv[i] = s->scale;
857+ s->bias[i] = s->delta;
858+ }
747859 }
748860
749861 return 0;
@@ -864,4 +976,25 @@ AVFilter ff_vf_roberts = { · 114 unmodified lines
864976 };
865977
866978 #endif /* CONFIG_ROBERTS_FILTER */
979+
980+#if CONFIG_KIRSCH_FILTER
981+
982+#define kirsch_options prewitt_roberts_sobel_options
983+AVFILTER_DEFINE_CLASS(kirsch);
984+
985+AVFilter ff_vf_kirsch = {
986+ .name = "kirsch",
987+ .description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
988+ .priv_size = sizeof(ConvolutionContext),
989+ .priv_class = &kirsch_class,
990+ .init = init,
991+ .query_formats = query_formats,
992+ .inputs = convolution_inputs,
993+ .outputs = convolution_outputs,
994+ .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
995+ .process_command = process_command,
996+};
997+
998+#endif /* CONFIG_KIRSCH_FILTER */
999+
8671000 #endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t