mirror of
https://github.com/xenia-project/FFmpeg.git
synced 2024-11-24 12:09:55 +00:00
vf_boxblur: switch to an AVOptions-based system.
This commit is contained in:
parent
62dcdb028c
commit
51def31dbe
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user