diff options
author | Anton Khirnov <anton@khirnov.net> | 2013-02-25 21:21:29 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2013-04-09 19:00:39 +0200 |
commit | 51def31dbe5b6e857536de8fa428f263d64f3ae5 (patch) | |
tree | c77f677e1d82bc65b450eeb6d9387977e3f32e96 | |
parent | 62dcdb028cc84845fd263bb09304c4c6500bda7a (diff) | |
download | ffmpeg-51def31dbe5b6e857536de8fa428f263d64f3ae5.tar.gz |
vf_boxblur: switch to an AVOptions-based system.
-rw-r--r-- | doc/filters.texi | 18 | ||||
-rw-r--r-- | libavfilter/vf_boxblur.c | 62 |
2 files changed, 52 insertions, 28 deletions
diff --git a/doc/filters.texi b/doc/filters.texi index c878472c83..bdde8f5380 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -550,8 +550,18 @@ Threshold below which a pixel value is considered black, defaults to 32. Apply boxblur algorithm to the input video. -This filter accepts the parameters: -@var{luma_power}:@var{luma_radius}:@var{chroma_radius}:@var{chroma_power}:@var{alpha_radius}:@var{alpha_power} +This filter accepts the following options: + +@table @option + +@item luma_radius +@item luma_power +@item chroma_radius +@item chroma_power +@item alpha_radius +@item alpha_power + +@end table Chroma and alpha parameters are optional, if not specified they default to the corresponding values set for @var{luma_radius} and @@ -589,7 +599,7 @@ Some examples follow: Apply a boxblur filter with luma, chroma, and alpha radius set to 2: @example -boxblur=2:1 +boxblur=luma_radius=2:luma_power=1 @end example @item @@ -601,7 +611,7 @@ boxblur=2:1:0:0:0:0 @item Set luma and chroma radius to a fraction of the video dimension @example -boxblur=min(h\,w)/10:1:min(cw\,ch)/10:1 +boxblur=luma_radius=min(h\,w)/10:luma_power=1:chroma_radius=min(cw\,ch)/10:chroma_power=1 @end example @end itemize diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c index e839c12060..c69bfe5890 100644 --- a/libavfilter/vf_boxblur.c +++ b/libavfilter/vf_boxblur.c @@ -28,6 +28,7 @@ #include "libavutil/avstring.h" #include "libavutil/common.h" #include "libavutil/eval.h" +#include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" @@ -60,12 +61,13 @@ typedef struct { } FilterParam; typedef struct { + const AVClass *class; FilterParam luma_param; FilterParam chroma_param; FilterParam alpha_param; - char luma_radius_expr [256]; - char chroma_radius_expr[256]; - char alpha_radius_expr [256]; + char *luma_radius_expr; + char *chroma_radius_expr; + char *alpha_radius_expr; int hsub, vsub; int radius[4]; @@ -81,34 +83,23 @@ typedef struct { static av_cold int init(AVFilterContext *ctx, const char *args) { BoxBlurContext *boxblur = ctx->priv; - int e; - if (!args) { - av_log(ctx, AV_LOG_ERROR, - "Filter expects 2 or 4 or 6 arguments, none provided\n"); + if (!boxblur->luma_radius_expr) { + av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n"); return AVERROR(EINVAL); } - e = sscanf(args, "%255[^:]:%d:%255[^:]:%d:%255[^:]:%d", - boxblur->luma_radius_expr, &boxblur->luma_param .power, - boxblur->chroma_radius_expr, &boxblur->chroma_param.power, - boxblur->alpha_radius_expr, &boxblur->alpha_param .power); - - if (e != 2 && e != 4 && e != 6) { - av_log(ctx, AV_LOG_ERROR, - "Filter expects 2 or 4 or 6 params, provided %d\n", e); - return AVERROR(EINVAL); - } - - if (e < 4) { + if (!boxblur->chroma_radius_expr) { + boxblur->chroma_radius_expr = av_strdup(boxblur->luma_radius_expr); + if (!boxblur->chroma_radius_expr) + return AVERROR(ENOMEM); boxblur->chroma_param.power = boxblur->luma_param.power; - av_strlcpy(boxblur->chroma_radius_expr, boxblur->luma_radius_expr, - sizeof(boxblur->chroma_radius_expr)); } - if (e < 6) { + if (!boxblur->alpha_radius_expr) { + boxblur->alpha_radius_expr = av_strdup(boxblur->luma_radius_expr); + if (!boxblur->alpha_radius_expr) + return AVERROR(ENOMEM); boxblur->alpha_param.power = boxblur->luma_param.power; - av_strlcpy(boxblur->alpha_radius_expr, boxblur->luma_radius_expr, - sizeof(boxblur->alpha_radius_expr)); } return 0; @@ -342,6 +333,28 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) return ff_filter_frame(outlink, out); } +#define OFFSET(x) offsetof(BoxBlurContext, x) +#define FLAGS AV_OPT_FLAG_VIDEO_PARAM +static const AVOption options[] = { + { "luma_radius", "Radius of the luma blurring box", OFFSET(luma_radius_expr), AV_OPT_TYPE_STRING, .flags = FLAGS }, + { "luma_power", "How many times should the boxblur be applied to luma", + OFFSET(luma_param.power), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, FLAGS }, + { "chroma_radius", "Radius of the chroma blurring box", OFFSET(chroma_radius_expr), AV_OPT_TYPE_STRING, .flags = FLAGS }, + { "chroma_power", "How many times should the boxblur be applied to chroma", + OFFSET(chroma_param.power), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, FLAGS }, + { "alpha_radius", "Radius of the alpha blurring box", OFFSET(alpha_radius_expr), AV_OPT_TYPE_STRING, .flags = FLAGS }, + { "alpha_power", "How many times should the boxblur be applied to alpha", + OFFSET(alpha_param.power), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, INT_MAX, FLAGS }, + { NULL }, +}; + +static const AVClass boxblur_class = { + .class_name = "boxblur", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + static const AVFilterPad avfilter_vf_boxblur_inputs[] = { { .name = "default", @@ -364,6 +377,7 @@ AVFilter avfilter_vf_boxblur = { .name = "boxblur", .description = NULL_IF_CONFIG_SMALL("Blur the input."), .priv_size = sizeof(BoxBlurContext), + .priv_class = &boxblur_class, .init = init, .uninit = uninit, .query_formats = query_formats, |