33 #define OFFSET(x) offsetof(ConvolutionContext, x) 34 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM 65 static const int same5x5[25] = {0, 0, 0, 0, 0,
71 static const int same7x7[49] = {0, 0, 0, 0, 0, 0, 0,
111 float scale,
float delta,
const int *
const matrix,
115 uint16_t *
dst = (uint16_t *)dstp;
118 for (x = 0; x <
width; x++) {
124 dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
129 float scale,
float delta,
const int *
const matrix,
133 uint16_t *
dst = (uint16_t *)dstp;
136 for (x = 0; x <
width; x++) {
140 dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
145 float scale,
float delta,
const int *
const matrix,
149 uint16_t *
dst = (uint16_t *)dstp;
152 for (x = 0; x <
width; x++) {
158 dst[x] = av_clip(sqrtf(suma*suma + sumb*sumb) * scale + delta, 0, peak);
163 float scale,
float delta,
const int *
const matrix,
172 for (x = 0; x <
width; x++) {
173 float suma = c0[x] * -1 + c1[x] * -1 + c2[x] * -1 +
174 c6[x] * 1 + c7[x] * 1 + c8[x] * 1;
175 float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -1 +
176 c5[x] * 1 + c6[x] * -1 + c8[x] * 1;
178 dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
183 float scale,
float delta,
const int *
const matrix,
189 for (x = 0; x <
width; x++) {
190 float suma = c[0][x] * 1 + c[1][x] * -1;
191 float sumb = c[4][x] * 1 + c[3][x] * -1;
193 dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
198 float scale,
float delta,
const int *
const matrix,
207 for (x = 0; x <
width; x++) {
208 float suma = c0[x] * -1 + c1[x] * -2 + c2[x] * -1 +
209 c6[x] * 1 + c7[x] * 2 + c8[x] * 1;
210 float sumb = c0[x] * -1 + c2[x] * 1 + c3[x] * -2 +
211 c5[x] * 2 + c6[x] * -1 + c8[x] * 1;
213 dst[x] = av_clip_uint8(sqrtf(suma*suma + sumb*sumb) * scale + delta);
218 float rdiv,
float bias,
const int *
const matrix,
222 uint16_t *
dst = (uint16_t *)dstp;
225 for (x = 0; x <
width; x++) {
226 int sum =
AV_RN16A(&c[0][2 * x]) * matrix[0] +
227 AV_RN16A(&c[1][2 * x]) * matrix[1] +
228 AV_RN16A(&c[2][2 * x]) * matrix[2] +
229 AV_RN16A(&c[3][2 * x]) * matrix[3] +
230 AV_RN16A(&c[4][2 * x]) * matrix[4] +
231 AV_RN16A(&c[5][2 * x]) * matrix[5] +
232 AV_RN16A(&c[6][2 * x]) * matrix[6] +
233 AV_RN16A(&c[7][2 * x]) * matrix[7] +
235 sum = (
int)(sum * rdiv + bias + 0.5
f);
236 dst[x] = av_clip(sum, 0, peak);
241 float rdiv,
float bias,
const int *
const matrix,
245 uint16_t *
dst = (uint16_t *)dstp;
248 for (x = 0; x <
width; x++) {
251 for (i = 0; i < 25; i++)
252 sum +=
AV_RN16A(&c[i][2 * x]) * matrix[
i];
254 sum = (
int)(sum * rdiv + bias + 0.5
f);
255 dst[x] = av_clip(sum, 0, peak);
260 float rdiv,
float bias,
const int *
const matrix,
264 uint16_t *
dst = (uint16_t *)dstp;
267 for (x = 0; x <
width; x++) {
270 for (i = 0; i < 49; i++)
271 sum +=
AV_RN16A(&c[i][2 * x]) * matrix[
i];
273 sum = (
int)(sum * rdiv + bias + 0.5
f);
274 dst[x] = av_clip(sum, 0, peak);
279 float rdiv,
float bias,
const int *
const matrix,
283 uint16_t *
dst = (uint16_t *)dstp;
286 for (x = 0; x <
width; x++) {
289 for (i = 0; i < 2 * radius + 1; i++)
290 sum +=
AV_RN16A(&c[i][2 * x]) * matrix[
i];
292 sum = (
int)(sum * rdiv + bias + 0.5
f);
293 dst[x] = av_clip(sum, 0, peak);
298 float rdiv,
float bias,
const int *
const matrix,
302 uint16_t *
dst = (uint16_t *)dstp;
305 for (y = 0; y <
height; y++) {
308 for (i = 0; i < 2 * radius + 1; i++)
309 sum +=
AV_RN16A(&c[i][0 + y * stride]) * matrix[
i];
311 sum = (
int)(sum * rdiv + bias + 0.5
f);
312 dst[0] = av_clip(sum, 0, peak);
318 float rdiv,
float bias,
const int *
const matrix,
324 for (x = 0; x <
width; x++) {
327 for (i = 0; i < 49; i++)
328 sum += c[i][x] * matrix[i];
330 sum = (
int)(sum * rdiv + bias + 0.5
f);
331 dst[x] = av_clip_uint8(sum);
336 float rdiv,
float bias,
const int *
const matrix,
342 for (x = 0; x <
width; x++) {
345 for (i = 0; i < 25; i++)
346 sum += c[i][x] * matrix[i];
348 sum = (
int)(sum * rdiv + bias + 0.5
f);
349 dst[x] = av_clip_uint8(sum);
354 float rdiv,
float bias,
const int *
const matrix,
363 for (x = 0; x <
width; x++) {
364 int sum = c0[x] * matrix[0] + c1[x] * matrix[1] + c2[x] * matrix[2] +
365 c3[x] * matrix[3] + c4[x] * matrix[4] + c5[x] * matrix[5] +
366 c6[x] * matrix[6] + c7[x] * matrix[7] + c8[x] * matrix[8];
367 sum = (
int)(sum * rdiv + bias + 0.5
f);
368 dst[x] = av_clip_uint8(sum);
373 float rdiv,
float bias,
const int *
const matrix,
379 for (x = 0; x <
width; x++) {
382 for (i = 0; i < 2 * radius + 1; i++)
383 sum += c[i][x] * matrix[i];
385 sum = (
int)(sum * rdiv + bias + 0.5
f);
386 dst[x] = av_clip_uint8(sum);
391 float rdiv,
float bias,
const int *
const matrix,
397 for (y = 0; y <
height; y++) {
400 for (i = 0; i < 2 * radius + 1; i++)
401 sum += c[i][0 + y * stride] * matrix[i];
403 sum = (
int)(sum * rdiv + bias + 0.5
f);
404 dst[0] = av_clip_uint8(sum);
410 int x,
int w,
int y,
int h,
int bpc)
414 for (i = 0; i < 9; i++) {
418 xoff = xoff >= w ? 2 * w - 1 -
xoff :
xoff;
419 yoff = yoff >= h ? 2 * h - 1 -
yoff :
yoff;
421 c[
i] = src + xoff * bpc + yoff *
stride;
426 int x,
int w,
int y,
int h,
int bpc)
430 for (i = 0; i < 25; i++) {
434 xoff = xoff >= w ? 2 * w - 1 -
xoff :
xoff;
435 yoff = yoff >= h ? 2 * h - 1 -
yoff :
yoff;
437 c[
i] = src + xoff * bpc + yoff *
stride;
442 int x,
int w,
int y,
int h,
int bpc)
446 for (i = 0; i < 49; i++) {
450 xoff = xoff >= w ? 2 * w - 1 -
xoff :
xoff;
451 yoff = yoff >= h ? 2 * h - 1 -
yoff :
yoff;
453 c[
i] = src + xoff * bpc + yoff *
stride;
458 int x,
int w,
int y,
int h,
int bpc)
462 for (i = 0; i < radius * 2 + 1; i++) {
465 xoff = xoff >= w ? 2 * w - 1 -
xoff :
xoff;
467 c[
i] = src + xoff * bpc + y *
stride;
472 int x,
int w,
int y,
int h,
int bpc)
476 for (i = 0; i < radius * 2 + 1; i++) {
479 xoff = xoff >= h ? 2 * h - 1 -
xoff :
xoff;
481 c[
i] = src + y * bpc + xoff *
stride;
493 for (plane = 0; plane < s->
nb_planes; plane++) {
495 const int bpc = s->
bpc;
503 const int slice_start = (sizeh * jobnr) / nb_jobs;
504 const int slice_end = (sizeh * (jobnr+1)) / nb_jobs;
508 const int dst_pos = slice_start * (mode ==
MATRIX_COLUMN ? bpc : dstride);
514 if (s->
copy[plane]) {
517 (slice_end - slice_start) * bpc, height);
520 width * bpc, slice_end - slice_start);
524 for (y = slice_start; y <
slice_end; y++) {
528 for (x = 0; x < radius; x++) {
529 const int xoff = mode ==
MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
534 bias, matrix,
c, s->
max, radius,
539 rdiv, bias, matrix,
c, s->
max, radius,
541 for (x = sizew - radius; x < sizew; x++) {
542 const int xoff = mode ==
MATRIX_COLUMN ? (y - slice_start) * bpc : x * bpc;
547 bias, matrix,
c, s->
max, radius,
577 if (!strcmp(ctx->
filter->
name,
"convolution")) {
584 else if (s->
size[p] == 3)
586 else if (s->
size[p] == 5)
588 else if (s->
size[p] == 7)
592 #if CONFIG_CONVOLUTION_FILTER && ARCH_X86_64 595 }
else if (!strcmp(ctx->
filter->
name,
"prewitt")) {
599 }
else if (!strcmp(ctx->
filter->
name,
"roberts")) {
603 }
else if (!strcmp(ctx->
filter->
name,
"sobel")) {
640 if (!strcmp(ctx->
filter->
name,
"convolution")) {
641 for (i = 0; i < 4; i++) {
642 int *matrix = (
int *)s->
matrix[i];
697 s->
rdiv[
i] = 1. / sum;
699 if (s->
copy[i] && (s->
rdiv[i] != 1. || s->
bias[i] != 0.))
702 }
else if (!strcmp(ctx->
filter->
name,
"prewitt")) {
703 for (i = 0; i < 4; i++) {
713 }
else if (!strcmp(ctx->
filter->
name,
"roberts")) {
714 for (i = 0; i < 4; i++) {
724 }
else if (!strcmp(ctx->
filter->
name,
"sobel")) {
725 for (i = 0; i < 4; i++) {
758 #if CONFIG_CONVOLUTION_FILTER 761 .
name =
"convolution",
764 .priv_class = &convolution_class,
767 .
inputs = convolution_inputs,
768 .
outputs = convolution_outputs,
774 #if CONFIG_PREWITT_FILTER 776 static const AVOption prewitt_options[] = {
789 .priv_class = &prewitt_class,
792 .
inputs = convolution_inputs,
793 .
outputs = convolution_outputs,
799 #if CONFIG_SOBEL_FILTER 801 static const AVOption sobel_options[] = {
814 .priv_class = &sobel_class,
817 .
inputs = convolution_inputs,
818 .
outputs = convolution_outputs,
824 #if CONFIG_ROBERTS_FILTER 826 static const AVOption roberts_options[] = {
839 .priv_class = &roberts_class,
842 .
inputs = convolution_inputs,
843 .
outputs = convolution_outputs,
#define AV_PIX_FMT_YUVA422P16
#define AV_PIX_FMT_YUVA422P9
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
#define AV_PIX_FMT_YUVA420P10
#define AV_PIX_FMT_YUV444P14
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)
#define AV_PIX_FMT_GBRAP10
#define AV_PIX_FMT_YUVA422P10
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Main libavfilter public API header.
static void sobel(int w, int h, uint16_t *dst, int dst_linesize, int8_t *dir, int dir_linesize, const uint8_t *src, int src_linesize)
int h
agreed upon image height
#define AV_PIX_FMT_GBRP10
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)
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_YUV420P12
AVFrame * ff_get_video_buffer(AVFilterLink *link, int w, int h)
Request a picture buffer with a specific set of permissions.
static int filter_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
uint8_t log2_chroma_w
Amount to shift the luma width right to find the chroma width.
#define AV_PIX_FMT_GRAY10
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)
#define AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC
Some filters support a generic "enable" expression option that can be used to enable or disable a fil...
const char * name
Pad name.
#define AV_PIX_FMT_GRAY12
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 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 ff_filter_frame(AVFilterLink *link, AVFrame *frame)
Send a frame of data to the next filter.
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
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)
#define AV_PIX_FMT_YUVA420P9
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range...
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
void(* setup[4])(int radius, const uint8_t *c[], const uint8_t *src, int stride, int x, int width, int y, int height, int bpc)
#define AV_PIX_FMT_YUV444P16
#define AV_PIX_FMT_YUV422P12
#define AV_PIX_FMT_YUVA420P16
AVFilter ff_vf_convolution
A filter pad used for either input or output.
A link between two filters.
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
#define i(width, name, range_min, range_max)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const int same7x7[49]
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static const AVFilterPad convolution_inputs[]
void * priv
private data for use by the filter
#define AVFILTER_FLAG_SLICE_THREADS
The filter supports multithreading by splitting frames into multiple parts and processing them concur...
#define AV_PIX_FMT_YUVA444P16
#define AV_PIX_FMT_GBRAP12
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)
#define AV_PIX_FMT_YUV444P10
#define AV_PIX_FMT_GBRAP16
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
int w
agreed upon image width
#define AV_PIX_FMT_YUV422P9
static const struct @315 planes[]
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)
#define AV_PIX_FMT_GBRP16
int ff_filter_get_nb_threads(AVFilterContext *ctx)
Get number of threads for current filter instance.
#define AV_PIX_FMT_GRAY16
static const AVFilterPad convolution_outputs[]
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
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)
#define AV_PIX_FMT_YUVA444P12
static const AVOption convolution_options[]
static int query_formats(AVFilterContext *ctx)
static av_cold int init(AVFilterContext *ctx)
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)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_PIX_FMT_YUVA444P10
static const AVFilterPad inputs[]
#define AV_PIX_FMT_YUV444P9
#define AV_PIX_FMT_GBRP14
static const AVFilterPad outputs[]
int format
agreed upon media format
#define AV_PIX_FMT_YUV420P16
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)
#define AV_PIX_FMT_YUV420P14
Used for passing data between threads.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
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)
#define AV_PIX_FMT_GRAY14
#define AV_PIX_FMT_YUV420P10
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
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)
AVFILTER_DEFINE_CLASS(convolution)
static const int same3x3[9]
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)
const char * name
Filter name.
#define AV_PIX_FMT_YUV440P12
#define AV_PIX_FMT_YUV420P9
AVFilterLink ** outputs
array of pointers to output links
static enum AVPixelFormat pix_fmts[]
#define AV_PIX_FMT_YUV422P14
#define AV_PIX_FMT_GBRP12
#define flags(name, subs,...)
AVFilterInternal * internal
An opaque struct for libavfilter internal use.
#define AV_PIX_FMT_YUV422P10
void ff_convolution_init_x86(ConvolutionContext *s)
#define AV_PIX_FMT_YUV444P12
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
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()...
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)
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)
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
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)
planar GBRA 4:4:4:4 32bpp
static const int same5x5[25]
#define AV_PIX_FMT_YUVA444P9
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
avfilter_execute_func * execute
static int slice_end(AVCodecContext *avctx, AVFrame *pict)
Handle slice ends.
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)
AVFilterContext * dst
dest filter
const AVPixFmtDescriptor * desc
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)
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
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)
static int config_input(AVFilterLink *inlink)
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
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.
void(* filter[4])(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 depth
Number of bits in the component.
AVPixelFormat
Pixel format.
mode
Use these values in ebur128_init (or'ed).
const AVFilter * filter
the AVFilter of which this is an instance
#define AV_PIX_FMT_YUV422P16
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
#define AV_PIX_FMT_YUVA422P12
#define AV_CEIL_RSHIFT(a, b)