History

avfilter: add kirsch video filter

Paul B Mahol committed 5 years ago

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

Showing the changes to libavfilter (4 of 6 files). Show all

Unified · Split

4 files
  1. libavfilter/Makefile +1 −0
  2. libavfilter/allfilters.c +1 −0
  3. libavfilter/version.h +1 −1
  4. libavfilter/vf_convolution.c +133 −0
libavfilter/Makefile+1−0
@@ -298,6 +298,7 @@ OBJS-$(CONFIG_INFLATE_FILTER) += vf_neighbor.o · 297 unmodified lines
298OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o298OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o
299OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o299OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
300OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o300OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o
301OBJS-$(CONFIG_KIRSCH_FILTER) += vf_convolution.o
301OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o302OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o
302OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o303OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
303OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o304OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
libavfilter/allfilters.c+1−0
@@ -283,6 +283,7 @@ extern AVFilter ff_vf_inflate; · 282 unmodified lines
283extern AVFilter ff_vf_interlace;283extern AVFilter ff_vf_interlace;
284extern AVFilter ff_vf_interleave;284extern AVFilter ff_vf_interleave;
285extern AVFilter ff_vf_kerndeint;285extern AVFilter ff_vf_kerndeint;
286extern AVFilter ff_vf_kirsch;
286extern AVFilter ff_vf_lagfun;287extern AVFilter ff_vf_lagfun;
287extern AVFilter ff_vf_lenscorrection;288extern AVFilter ff_vf_lenscorrection;
288extern AVFilter ff_vf_lensfun;289extern AVFilter ff_vf_lensfun;
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
30#include "libavutil/version.h"30#include "libavutil/version.h"
31 31
32#define LIBAVFILTER_VERSION_MAJOR 732#define LIBAVFILTER_VERSION_MAJOR 7
33#define LIBAVFILTER_VERSION_MINOR 9833#define LIBAVFILTER_VERSION_MINOR 99
34#define LIBAVFILTER_VERSION_MICRO 10034#define LIBAVFILTER_VERSION_MICRO 100
35 35
36 36
libavfilter/vf_convolution.c+133−0
@@ -159,6 +159,55 @@ static void filter16_sobel(uint8_t *dstp, int width, · 158 unmodified lines
159 }159 }
160}160}
161 161
162static 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
162static void filter_prewitt(uint8_t *dst, int width,211static void filter_prewitt(uint8_t *dst, int width,
163 float scale, float delta, const int *const matrix,212 float scale, float delta, const int *const matrix,
164 const uint8_t *c[], int peak, int radius,213 const uint8_t *c[], int peak, int radius,
@@ -214,6 +263,54 @@ static void filter_sobel(uint8_t *dst, int width, · 49 unmodified lines
214 }263 }
215}264}
216 265
266static 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
217static void filter16_3x3(uint8_t *dstp, int width,314static void filter16_3x3(uint8_t *dstp, int width,
218 float rdiv, float bias, const int *const matrix,315 float rdiv, float bias, const int *const matrix,
219 const uint8_t *c[], int peak, int radius,316 const uint8_t *c[], int peak, int radius,
@@ -604,6 +701,10 @@ static int config_input(AVFilterLink *inlink) · 384 unmodified lines
604 if (s->depth > 8)701 if (s->depth > 8)
605 for (p = 0; p < s->nb_planes; p++)702 for (p = 0; p < s->nb_planes; p++)
606 s->filter[p] = filter16_sobel;703 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;
607 }708 }
608 709
609 return 0;710 return 0;
@@ -744,6 +845,17 @@ static av_cold int init(AVFilterContext *ctx) · 134 unmodified lines
744 s->rdiv[i] = s->scale;845 s->rdiv[i] = s->scale;
745 s->bias[i] = s->delta;846 s->bias[i] = s->delta;
746 }847 }
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 }
747 }859 }
748 860
749 return 0;861 return 0;
@@ -864,4 +976,25 @@ AVFilter ff_vf_roberts = { · 114 unmodified lines
864};976};
865 977
866#endif /* CONFIG_ROBERTS_FILTER */978#endif /* CONFIG_ROBERTS_FILTER */
979
980#if CONFIG_KIRSCH_FILTER
981
982#define kirsch_options prewitt_roberts_sobel_options
983AVFILTER_DEFINE_CLASS(kirsch);
984
985AVFilter 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
867#endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */1000#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