1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

avfilter/vf_convolution: add scharr operator

This commit is contained in:
Paul B Mahol 2021-09-10 17:52:23 +02:00
parent 0b4d009587
commit 463c71b3b3
6 changed files with 104 additions and 3 deletions

View File

@ -18,6 +18,7 @@ version <next>:
- AV1 Low overhead bitstream format muxer
- swscale slice threading
- MSN Siren decoder
- scharr video filter
version 4.4:

View File

@ -18349,6 +18349,27 @@ If the specified expression is not valid, it is kept at its current
value.
@end table
@section scharr
Apply scharr 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 scroll
Scroll input video horizontally and/or vertically by constant speed.

View File

@ -409,6 +409,7 @@ OBJS-$(CONFIG_SCALE_VAAPI_FILTER) += vf_scale_vaapi.o scale_eval.o va
OBJS-$(CONFIG_SCALE_VULKAN_FILTER) += vf_scale_vulkan.o vulkan.o
OBJS-$(CONFIG_SCALE2REF_FILTER) += vf_scale.o scale_eval.o
OBJS-$(CONFIG_SCDET_FILTER) += vf_scdet.o
OBJS-$(CONFIG_SCHARR_FILTER) += vf_convolution.o
OBJS-$(CONFIG_SCROLL_FILTER) += vf_scroll.o
OBJS-$(CONFIG_SEGMENT_FILTER) += f_segment.o
OBJS-$(CONFIG_SELECT_FILTER) += f_select.o

View File

@ -390,6 +390,7 @@ extern const AVFilter ff_vf_scale_vaapi;
extern const AVFilter ff_vf_scale_vulkan;
extern const AVFilter ff_vf_scale2ref;
extern const AVFilter ff_vf_scdet;
extern const AVFilter ff_vf_scharr;
extern const AVFilter ff_vf_scroll;
extern const AVFilter ff_vf_segment;
extern const AVFilter ff_vf_select;

View File

@ -30,8 +30,8 @@
#include "libavutil/version.h"
#define LIBAVFILTER_VERSION_MAJOR 8
#define LIBAVFILTER_VERSION_MINOR 7
#define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_MINOR 8
#define LIBAVFILTER_VERSION_MICRO 100
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \

View File

@ -160,6 +160,26 @@ static void filter16_sobel(uint8_t *dstp, int width,
}
}
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)
{
uint16_t *dst = (uint16_t *)dstp;
int x;
for (x = 0; x < width; x++) {
float suma = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[1][2 * x]) * -162 + AV_RN16A(&c[2][2 * x]) * -47 +
AV_RN16A(&c[6][2 * x]) * 47 + AV_RN16A(&c[7][2 * x]) * 162 + AV_RN16A(&c[8][2 * x]) * 47;
float sumb = AV_RN16A(&c[0][2 * x]) * -47 + AV_RN16A(&c[2][2 * x]) * 47 + AV_RN16A(&c[3][2 * x]) * -162 +
AV_RN16A(&c[5][2 * x]) * 162 + AV_RN16A(&c[6][2 * x]) * -47 + AV_RN16A(&c[8][2 * x]) * 47;
suma /= 256.f;
sumb /= 256.f;
dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
}
}
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,
@ -264,6 +284,28 @@ static void filter_sobel(uint8_t *dst, int width,
}
}
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)
{
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++) {
float suma = c0[x] * -47 + c1[x] * -162 + c2[x] * -47 +
c6[x] * 47 + c7[x] * 162 + c8[x] * 47;
float sumb = c0[x] * -47 + c2[x] * 47 + c3[x] * -162 +
c5[x] * 162 + c6[x] * -47 + c8[x] * 47;
suma /= 256.f;
sumb /= 256.f;
dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
}
}
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,
@ -715,6 +757,10 @@ static int config_input(AVFilterLink *inlink)
if (s->depth > 8)
for (p = 0; p < s->nb_planes; p++)
s->filter[p] = filter16_kirsch;
} else if (!strcmp(ctx->filter->name, "scharr")) {
if (s->depth > 8)
for (p = 0; p < s->nb_planes; p++)
s->filter[p] = filter16_scharr;
}
return 0;
@ -867,6 +913,17 @@ static av_cold int init(AVFilterContext *ctx)
s->rdiv[i] = s->scale;
s->bias[i] = s->delta;
}
} else if (!strcmp(ctx->filter->name, "scharr")) {
for (i = 0; i < 4; i++) {
if ((1 << i) & s->planes)
s->filter[i] = filter_scharr;
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;
@ -1006,4 +1063,24 @@ const AVFilter ff_vf_kirsch = {
#endif /* CONFIG_KIRSCH_FILTER */
#endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER */
#if CONFIG_SCHARR_FILTER
#define scharr_options prewitt_roberts_sobel_options
AVFILTER_DEFINE_CLASS(scharr);
const AVFilter ff_vf_scharr = {
.name = "scharr",
.description = NULL_IF_CONFIG_SMALL("Apply scharr operator."),
.priv_size = sizeof(ConvolutionContext),
.priv_class = &scharr_class,
.init = init,
.query_formats = query_formats,
FILTER_INPUTS(convolution_inputs),
FILTER_OUTPUTS(convolution_outputs),
.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | AVFILTER_FLAG_SLICE_THREADS,
.process_command = process_command,
};
#endif /* CONFIG_SCHARR_FILTER */
#endif /* CONFIG_PREWITT_FILTER || CONFIG_ROBERTS_FILTER || CONFIG_SOBEL_FILTER || CONFIG_SCHARR_FILTER */