mirror of https://git.videolan.org/git/ffmpeg.git
avfilter: add kirsch video filter
This commit is contained in:
parent
021dc4f107
commit
35f8628047
|
@ -59,6 +59,7 @@ version <next>:
|
||||||
- epx filter
|
- epx filter
|
||||||
- Dolby E parser
|
- Dolby E parser
|
||||||
- shear filter
|
- shear filter
|
||||||
|
- kirsch filter
|
||||||
|
|
||||||
|
|
||||||
version 4.3:
|
version 4.3:
|
||||||
|
|
|
@ -13400,6 +13400,27 @@ kerndeint=map=1
|
||||||
@end example
|
@end example
|
||||||
@end itemize
|
@end itemize
|
||||||
|
|
||||||
|
@section kirsch
|
||||||
|
Apply kirsch operator to input video stream.
|
||||||
|
|
||||||
|
The filter accepts the following option:
|
||||||
|
|
||||||
|
@table @option
|
||||||
|
@item planes
|
||||||
|
Set which planes will be processed, unprocessed planes will be copied.
|
||||||
|
By default value 0xf, all planes will be processed.
|
||||||
|
|
||||||
|
@item scale
|
||||||
|
Set value which will be multiplied with filtered result.
|
||||||
|
|
||||||
|
@item delta
|
||||||
|
Set value which will be added to filtered result.
|
||||||
|
@end table
|
||||||
|
|
||||||
|
@subsection Commands
|
||||||
|
|
||||||
|
This filter supports the all above options as @ref{commands}.
|
||||||
|
|
||||||
@section lagfun
|
@section lagfun
|
||||||
|
|
||||||
Slowly update darker pixels.
|
Slowly update darker pixels.
|
||||||
|
|
|
@ -298,6 +298,7 @@ OBJS-$(CONFIG_INFLATE_FILTER) += vf_neighbor.o
|
||||||
OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o
|
OBJS-$(CONFIG_INTERLACE_FILTER) += vf_tinterlace.o
|
||||||
OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
|
OBJS-$(CONFIG_INTERLEAVE_FILTER) += f_interleave.o
|
||||||
OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o
|
OBJS-$(CONFIG_KERNDEINT_FILTER) += vf_kerndeint.o
|
||||||
|
OBJS-$(CONFIG_KIRSCH_FILTER) += vf_convolution.o
|
||||||
OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o
|
OBJS-$(CONFIG_LAGFUN_FILTER) += vf_lagfun.o
|
||||||
OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
|
OBJS-$(CONFIG_LENSCORRECTION_FILTER) += vf_lenscorrection.o
|
||||||
OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
|
OBJS-$(CONFIG_LENSFUN_FILTER) += vf_lensfun.o
|
||||||
|
|
|
@ -283,6 +283,7 @@ extern AVFilter ff_vf_inflate;
|
||||||
extern AVFilter ff_vf_interlace;
|
extern AVFilter ff_vf_interlace;
|
||||||
extern AVFilter ff_vf_interleave;
|
extern AVFilter ff_vf_interleave;
|
||||||
extern AVFilter ff_vf_kerndeint;
|
extern AVFilter ff_vf_kerndeint;
|
||||||
|
extern AVFilter ff_vf_kirsch;
|
||||||
extern AVFilter ff_vf_lagfun;
|
extern AVFilter ff_vf_lagfun;
|
||||||
extern AVFilter ff_vf_lenscorrection;
|
extern AVFilter ff_vf_lenscorrection;
|
||||||
extern AVFilter ff_vf_lensfun;
|
extern AVFilter ff_vf_lensfun;
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include "libavutil/version.h"
|
#include "libavutil/version.h"
|
||||||
|
|
||||||
#define LIBAVFILTER_VERSION_MAJOR 7
|
#define LIBAVFILTER_VERSION_MAJOR 7
|
||||||
#define LIBAVFILTER_VERSION_MINOR 98
|
#define LIBAVFILTER_VERSION_MINOR 99
|
||||||
#define LIBAVFILTER_VERSION_MICRO 100
|
#define LIBAVFILTER_VERSION_MICRO 100
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,55 @@ static void filter16_sobel(uint8_t *dstp, int width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
uint16_t *dst = (uint16_t *)dstp;
|
||||||
|
const uint16_t *c0 = (const uint16_t *)c[0], *c1 = (const uint16_t *)c[1], *c2 = (const uint16_t *)c[2];
|
||||||
|
const uint16_t *c3 = (const uint16_t *)c[3], *c5 = (const uint16_t *)c[5];
|
||||||
|
const uint16_t *c6 = (const uint16_t *)c[6], *c7 = (const uint16_t *)c[7], *c8 = (const uint16_t *)c[8];
|
||||||
|
int x;
|
||||||
|
|
||||||
|
for (x = 0; x < width; x++) {
|
||||||
|
int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
|
||||||
|
c3[x] * 5 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
|
||||||
|
c3[x] * 5 + c5[x] * 5 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * 5 + c5[x] * 5 +
|
||||||
|
c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * 5 +
|
||||||
|
c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
|
||||||
|
int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
|
||||||
|
int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
|
||||||
|
int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
|
||||||
|
|
||||||
|
sum0 = FFMAX(sum0, sum1);
|
||||||
|
sum2 = FFMAX(sum2, sum3);
|
||||||
|
sum4 = FFMAX(sum4, sum5);
|
||||||
|
sum6 = FFMAX(sum6, sum7);
|
||||||
|
sum0 = FFMAX(sum0, sum2);
|
||||||
|
sum4 = FFMAX(sum4, sum6);
|
||||||
|
sum0 = FFMAX(sum0, sum4);
|
||||||
|
|
||||||
|
dst[x] = av_clip(FFABS(sum0) * scale + delta, 0, peak);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void filter_prewitt(uint8_t *dst, int width,
|
static void filter_prewitt(uint8_t *dst, int width,
|
||||||
float scale, float delta, const int *const matrix,
|
float scale, float delta, const int *const matrix,
|
||||||
const uint8_t *c[], int peak, int radius,
|
const uint8_t *c[], int peak, int radius,
|
||||||
|
@ -214,6 +263,54 @@ static void filter_sobel(uint8_t *dst, int width,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
const uint8_t *c0 = c[0], *c1 = c[1], *c2 = c[2];
|
||||||
|
const uint8_t *c3 = c[3], *c5 = c[5];
|
||||||
|
const uint8_t *c6 = c[6], *c7 = c[7], *c8 = c[8];
|
||||||
|
int x;
|
||||||
|
|
||||||
|
for (x = 0; x < width; x++) {
|
||||||
|
int sum0 = c0[x] * 5 + c1[x] * 5 + c2[x] * 5 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum1 = c0[x] * -3 + c1[x] * 5 + c2[x] * 5 +
|
||||||
|
c3[x] * 5 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum2 = c0[x] * -3 + c1[x] * -3 + c2[x] * 5 +
|
||||||
|
c3[x] * 5 + c5[x] * 5 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum3 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * 5 + c5[x] * 5 +
|
||||||
|
c6[x] * 5 + c7[x] * -3 + c8[x] * -3;
|
||||||
|
int sum4 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * 5 +
|
||||||
|
c6[x] * 5 + c7[x] * 5 + c8[x] * -3;
|
||||||
|
int sum5 = c0[x] * -3 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * 5 + c7[x] * 5 + c8[x] * 5;
|
||||||
|
int sum6 = c0[x] * 5 + c1[x] * -3 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * 5 + c8[x] * 5;
|
||||||
|
int sum7 = c0[x] * 5 + c1[x] * 5 + c2[x] * -3 +
|
||||||
|
c3[x] * -3 + c5[x] * -3 +
|
||||||
|
c6[x] * -3 + c7[x] * -3 + c8[x] * 5;
|
||||||
|
|
||||||
|
sum0 = FFMAX(sum0, sum1);
|
||||||
|
sum2 = FFMAX(sum2, sum3);
|
||||||
|
sum4 = FFMAX(sum4, sum5);
|
||||||
|
sum6 = FFMAX(sum6, sum7);
|
||||||
|
sum0 = FFMAX(sum0, sum2);
|
||||||
|
sum4 = FFMAX(sum4, sum6);
|
||||||
|
sum0 = FFMAX(sum0, sum4);
|
||||||
|
|
||||||
|
dst[x] = av_clip_uint8(FFABS(sum0) * scale + delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void filter16_3x3(uint8_t *dstp, int width,
|
static void filter16_3x3(uint8_t *dstp, int width,
|
||||||
float rdiv, float bias, const int *const matrix,
|
float rdiv, float bias, const int *const matrix,
|
||||||
const uint8_t *c[], int peak, int radius,
|
const uint8_t *c[], int peak, int radius,
|
||||||
|
@ -604,6 +701,10 @@ static int config_input(AVFilterLink *inlink)
|
||||||
if (s->depth > 8)
|
if (s->depth > 8)
|
||||||
for (p = 0; p < s->nb_planes; p++)
|
for (p = 0; p < s->nb_planes; p++)
|
||||||
s->filter[p] = filter16_sobel;
|
s->filter[p] = filter16_sobel;
|
||||||
|
} else if (!strcmp(ctx->filter->name, "kirsch")) {
|
||||||
|
if (s->depth > 8)
|
||||||
|
for (p = 0; p < s->nb_planes; p++)
|
||||||
|
s->filter[p] = filter16_kirsch;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -744,6 +845,17 @@ static av_cold int init(AVFilterContext *ctx)
|
||||||
s->rdiv[i] = s->scale;
|
s->rdiv[i] = s->scale;
|
||||||
s->bias[i] = s->delta;
|
s->bias[i] = s->delta;
|
||||||
}
|
}
|
||||||
|
} else if (!strcmp(ctx->filter->name, "kirsch")) {
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
if ((1 << i) & s->planes)
|
||||||
|
s->filter[i] = filter_kirsch;
|
||||||
|
else
|
||||||
|
s->copy[i] = 1;
|
||||||
|
s->size[i] = 3;
|
||||||
|
s->setup[i] = setup_3x3;
|
||||||
|
s->rdiv[i] = s->scale;
|
||||||
|
s->bias[i] = s->delta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -864,4 +976,25 @@ AVFilter ff_vf_roberts = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CONFIG_ROBERTS_FILTER */
|
#endif /* CONFIG_ROBERTS_FILTER */
|
||||||
|
|
||||||
|
#if CONFIG_KIRSCH_FILTER
|
||||||
|
|
||||||
|
#define kirsch_options prewitt_roberts_sobel_options
|
||||||
|
AVFILTER_DEFINE_CLASS(kirsch);
|
||||||
|
|
||||||
|
AVFilter ff_vf_kirsch = {
|
||||||
|
.name = "kirsch",
|
||||||
|
.description = NULL_IF_CONFIG_SMALL("Apply kirsch operator."),
|
||||||
|
.priv_size = sizeof(ConvolutionContext),
|
||||||
|
.priv_class = &kirsch_class,
|
||||||
|
.init = init,
|
||||||
|
.query_formats = query_formats,
|
||||||
|
.inputs = convolution_inputs,
|
||||||
|
.outputs = convolution_outputs,
|
||||||
|
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
|
||||||
|
.process_command = process_command,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* CONFIG_KIRSCH_FILTER */
|
||||||
|
|
||||||
#endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */
|
#endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */
|
||||||
|
|
Loading…
Reference in New Issue