summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2013-02-20 15:45:02 +0100
committerStefano Sabatini <stefasab@gmail.com>2013-02-22 19:57:20 +0100
commitf30979e0954eaf7682065bc817d5ac227ea2e668 (patch)
tree99e08cce7956481d0604de675abcb18ec842d10d
parent6f77122bf5712da1d860a0ad7174181fd0bcffd9 (diff)
lavfi/boxblur: add support to named options
-rw-r--r--doc/filters.texi50
-rw-r--r--libavfilter/version.h2
-rw-r--r--libavfilter/vf_boxblur.c80
3 files changed, 89 insertions, 43 deletions
diff --git a/doc/filters.texi b/doc/filters.texi
index a93b433a5a..513d8511a1 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -1890,17 +1890,30 @@ blend=all_expr='if(eq(mod(X,2),mod(Y,2)),A,B)'
Apply boxblur algorithm to the input video.
-This filter accepts the parameters:
-@var{luma_radius}:@var{luma_power}:@var{chroma_radius}:@var{chroma_power}:@var{alpha_radius}:@var{alpha_power}
+The filter accepts parameters as a list of @var{key}=@var{value}
+pairs, separated by ":". If the key of the first options is omitted,
+the arguments are interpreted according to the syntax
+@option{luma_radius}:@option{luma_power}:@option{chroma_radius}:@option{chroma_power}:@option{alpha_radius}:@option{alpha_power}.
-Chroma and alpha parameters are optional, if not specified they default
-to the corresponding values set for @var{luma_radius} and
-@var{luma_power}.
+A description of the accepted options follows.
-@var{luma_radius}, @var{chroma_radius}, and @var{alpha_radius} represent
-the radius in pixels of the box used for blurring the corresponding
-input plane. They are expressions, and can contain the following
-constants:
+@table @option
+@item luma_radius, lr
+@item chroma_radius, cr
+@item alpha_radius, ar
+Set an expression for the box radius in pixels used for blurring the
+corresponding input plane.
+
+The radius value must be a non-negative number, and must not be
+greater than the value of the expression @code{min(w,h)/2} for the
+luma and alpha planes, and of @code{min(cw,ch)/2} for the chroma
+planes.
+
+Default value for @option{luma_radius} is "2". If not specified,
+@option{chroma_radius} and @option{alpha_radius} default to the
+corresponding value set for @option{luma_radius}.
+
+The expressions can contain the following constants:
@table @option
@item w, h
the input width and height in pixels
@@ -1913,13 +1926,18 @@ horizontal and vertical chroma subsample values. For example for the
pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1.
@end table
-The radius must be a non-negative number, and must not be greater than
-the value of the expression @code{min(w,h)/2} for the luma and alpha planes,
-and of @code{min(cw,ch)/2} for the chroma planes.
+@item luma_power, lp
+@item chroma_power, cp
+@item alpha_power, ap
+Specify how many times the boxblur filter is applied to the
+corresponding plane.
-@var{luma_power}, @var{chroma_power}, and @var{alpha_power} represent
-how many times the boxblur filter is applied to the corresponding
-plane.
+Default value for @option{luma_power} is 2. If not specified,
+@option{chroma_power} and @option{alpha_power} default to the
+corresponding value set for @option{luma_power}.
+
+A value of 0 will disable the effect.
+@end table
Some examples follow:
@@ -1935,7 +1953,7 @@ boxblur=2:1
@item
Set luma radius to 2, alpha and chroma radius to 0
@example
-boxblur=2:1:0:0:0:0
+boxblur=2:1:cr=0:ar=0
@end example
@item
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 4199a2746b..f3fab7dc4c 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
#define LIBAVFILTER_VERSION_MAJOR 3
#define LIBAVFILTER_VERSION_MINOR 39
-#define LIBAVFILTER_VERSION_MICRO 100
+#define LIBAVFILTER_VERSION_MICRO 101
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
LIBAVFILTER_VERSION_MINOR, \
diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c
index 9ee3ea5bc7..a4ac50afd5 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"
@@ -57,15 +58,14 @@ enum var_name {
typedef struct {
int radius;
int power;
+ char *radius_expr;
} 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];
int hsub, vsub;
int radius[4];
@@ -73,6 +73,30 @@ typedef struct {
uint8_t *temp[2]; ///< temporary buffer used in blur_power()
} BoxBlurContext;
+#define OFFSET(x) offsetof(BoxBlurContext, x)
+#define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
+
+static const AVOption boxblur_options[] = {
+ { "luma_radius", "set luma radius", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+ { "lr", "set luma radius", OFFSET(luma_param.radius_expr), AV_OPT_TYPE_STRING, {.str="2"}, .flags = FLAGS },
+ { "luma_power", "set luma power", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+ { "lp", "set luma power", OFFSET(luma_param.power), AV_OPT_TYPE_INT, {.i64=2}, 0, INT_MAX, .flags = FLAGS },
+
+ { "chroma_radius", "set chroma radius", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "cr", "set chroma radius", OFFSET(chroma_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "chroma_power", "set chroma power", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+ { "cp", "set chroma power", OFFSET(chroma_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+ { "alpha_radius", "set alpha radius", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "ar", "set alpha radius", OFFSET(alpha_param.radius_expr), AV_OPT_TYPE_STRING, {.str=NULL}, .flags = FLAGS },
+ { "alpha_power", "set alpha power", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+ { "ap", "set alpha power", OFFSET(alpha_param.power), AV_OPT_TYPE_INT, {.i64=-1}, -1, INT_MAX, .flags = FLAGS },
+
+ { NULL }
+};
+
+AVFILTER_DEFINE_CLASS(boxblur);
+
#define Y 0
#define U 1
#define V 2
@@ -81,35 +105,36 @@ typedef struct {
static av_cold int init(AVFilterContext *ctx, const char *args)
{
BoxBlurContext *boxblur = ctx->priv;
- int e;
+ static const char *shorthand[] = {
+ "luma_radius", "luma_power",
+ "chroma_radius", "chroma_power",
+ "alpha_radius", "alpha_power",
+ NULL
+ };
+ int ret;
- if (!args) {
- av_log(ctx, AV_LOG_ERROR,
- "Filter expects 2 or 4 or 6 arguments, none provided\n");
- return AVERROR(EINVAL);
- }
+ boxblur->class = &boxblur_class;
+ av_opt_set_defaults(boxblur);
- 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 ((ret = av_opt_set_from_string(boxblur, args, shorthand, "=", ":")) < 0)
+ return ret;
- 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);
+ /* fill missing params */
+ if (!boxblur->chroma_param.radius_expr) {
+ boxblur->chroma_param.radius_expr = av_strdup(boxblur->luma_param.radius_expr);
+ if (!boxblur->chroma_param.radius_expr)
+ return AVERROR(ENOMEM);
}
-
- if (e < 4) {
+ if (boxblur->chroma_param.power < 0)
boxblur->chroma_param.power = boxblur->luma_param.power;
- av_strlcpy(boxblur->chroma_radius_expr, boxblur->luma_radius_expr,
- sizeof(boxblur->chroma_radius_expr));
+
+ if (!boxblur->alpha_param.radius_expr) {
+ boxblur->alpha_param.radius_expr = av_strdup(boxblur->luma_param.radius_expr);
+ if (!boxblur->alpha_param.radius_expr)
+ return AVERROR(ENOMEM);
}
- if (e < 6) {
+ if (boxblur->alpha_param.power < 0)
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;
}
@@ -120,6 +145,7 @@ static av_cold void uninit(AVFilterContext *ctx)
av_freep(&boxblur->temp[0]);
av_freep(&boxblur->temp[1]);
+ av_opt_free(boxblur);
}
static int query_formats(AVFilterContext *ctx)
@@ -163,7 +189,7 @@ static int config_input(AVFilterLink *inlink)
var_values[VAR_VSUB] = 1<<boxblur->vsub;
#define EVAL_RADIUS_EXPR(comp) \
- expr = boxblur->comp##_radius_expr; \
+ expr = boxblur->comp##_param.radius_expr; \
ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \
NULL, NULL, NULL, NULL, NULL, 0, ctx); \
boxblur->comp##_param.radius = res; \
@@ -366,4 +392,6 @@ AVFilter avfilter_vf_boxblur = {
.inputs = avfilter_vf_boxblur_inputs,
.outputs = avfilter_vf_boxblur_outputs,
+
+ .priv_class = &boxblur_class,
};