From b83e9efc53e5491716625aa31c69006b1119b280 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 25 Feb 2013 21:21:29 +0100 Subject: [PATCH] vf_unsharp: switch to an AVOptions-based system. --- doc/filters.texi | 11 +++++----- libavfilter/vf_unsharp.c | 45 ++++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index c6a50670a4..e19ea15ff5 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -2157,11 +2157,6 @@ l.r l.L Sharpen or blur the input video. It accepts the following parameters: -@var{luma_msize_x}:@var{luma_msize_y}:@var{luma_amount}:@var{chroma_msize_x}:@var{chroma_msize_y}:@var{chroma_amount} - -Negative values for the amount will blur the input video, while positive -values will sharpen. All parameters are optional and default to the -equivalent of the string '5:5:1.0:5:5:0.0'. @table @option @@ -2191,9 +2186,13 @@ and 5.0, default value is 0.0. @end table +Negative values for the amount will blur the input video, while positive +values will sharpen. All parameters are optional and default to the +equivalent of the string '5:5:1.0:5:5:0.0'. + @example # Strong luma sharpen effect parameters -unsharp=7:7:2.5 +unsharp=luma_msize_x=7:luma_msize_y=7:luma_amount=2.5 # Strong blur of both luma and chroma parameters unsharp=7:7:-2:7:7:-2 diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c index fab1a6a815..644a714ea6 100644 --- a/libavfilter/vf_unsharp.c +++ b/libavfilter/vf_unsharp.c @@ -42,6 +42,7 @@ #include "video.h" #include "libavutil/common.h" #include "libavutil/mem.h" +#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #define MIN_SIZE 3 @@ -62,6 +63,9 @@ typedef struct FilterParam { } FilterParam; typedef struct { + const AVClass *class; + int lmsize_x, lmsize_y, cmsize_x, cmsize_y; + float lamount, camount; FilterParam luma; ///< luma parameters (width, height, amount) FilterParam chroma; ///< chroma parameters (width, height, amount) int hsub, vsub; @@ -120,7 +124,7 @@ static void apply_unsharp( uint8_t *dst, int dst_stride, } } -static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, double amount) +static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, float amount) { fp->msize_x = msize_x; fp->msize_y = msize_y; @@ -135,24 +139,9 @@ static void set_filter_param(FilterParam *fp, int msize_x, int msize_y, double a static av_cold int init(AVFilterContext *ctx, const char *args) { UnsharpContext *unsharp = ctx->priv; - int lmsize_x = 5, cmsize_x = 5; - int lmsize_y = 5, cmsize_y = 5; - double lamount = 1.0f, camount = 0.0f; - if (args) - sscanf(args, "%d:%d:%lf:%d:%d:%lf", &lmsize_x, &lmsize_y, &lamount, - &cmsize_x, &cmsize_y, &camount); - - if ((lamount && (lmsize_x < 2 || lmsize_y < 2)) || - (camount && (cmsize_x < 2 || cmsize_y < 2))) { - av_log(ctx, AV_LOG_ERROR, - "Invalid value <2 for lmsize_x:%d or lmsize_y:%d or cmsize_x:%d or cmsize_y:%d\n", - lmsize_x, lmsize_y, cmsize_x, cmsize_y); - return AVERROR(EINVAL); - } - - set_filter_param(&unsharp->luma, lmsize_x, lmsize_y, lamount); - set_filter_param(&unsharp->chroma, cmsize_x, cmsize_y, camount); + set_filter_param(&unsharp->luma, unsharp->lmsize_x, unsharp->lmsize_y, unsharp->lamount); + set_filter_param(&unsharp->chroma, unsharp->cmsize_x, unsharp->cmsize_y, unsharp->camount); return 0; } @@ -237,6 +226,25 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) return ff_filter_frame(outlink, out); } +#define OFFSET(x) offsetof(UnsharpContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM +static const AVOption options[] = { + { "luma_msize_x", "luma matrix horizontal size", OFFSET(lmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS }, + { "luma_msize_y", "luma matrix vertical size", OFFSET(lmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS }, + { "luma_amount", "luma effect strength", OFFSET(lamount), AV_OPT_TYPE_FLOAT, { .dbl = 1 }, -2, 5, FLAGS }, + { "chroma_msize_x", "chroma matrix horizontal size", OFFSET(cmsize_x), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS }, + { "chroma_msize_y", "chroma matrix vertical size", OFFSET(cmsize_y), AV_OPT_TYPE_INT, { .i64 = 5 }, MIN_SIZE, MAX_SIZE, FLAGS }, + { "chroma_amount", "chroma effect strength", OFFSET(camount), AV_OPT_TYPE_FLOAT, { .dbl = 0 }, -2, 5, FLAGS }, + { NULL }, +}; + +static const AVClass unsharp_class = { + .class_name = "unsharp", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + static const AVFilterPad avfilter_vf_unsharp_inputs[] = { { .name = "default", @@ -260,6 +268,7 @@ AVFilter avfilter_vf_unsharp = { .description = NULL_IF_CONFIG_SMALL("Sharpen or blur the input video."), .priv_size = sizeof(UnsharpContext), + .priv_class = &unsharp_class, .init = init, .uninit = uninit,