X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_boxblur.c;h=bebbd4ef083b4bb114076609d7987f1d478eed57;hb=3a3e8c35b63a40c4d59161097dc8652c15d13779;hp=8e43986846dc507a380f98c511530bd0b40b1c2a;hpb=9e3e9a37289c1a9cdfdb6c7389a3ece3cfa4749c;p=ffmpeg diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c index 8e43986846d..bebbd4ef083 100644 --- a/libavfilter/vf_boxblur.c +++ b/libavfilter/vf_boxblur.c @@ -27,39 +27,13 @@ #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" #include "internal.h" #include "video.h" +#include "boxblur.h" -static const char *const var_names[] = { - "w", - "h", - "cw", - "ch", - "hsub", - "vsub", - NULL -}; - -enum var_name { - VAR_W, - VAR_H, - VAR_CW, - VAR_CH, - VAR_HSUB, - VAR_VSUB, - VARS_NB -}; - -typedef struct FilterParam { - int radius; - int power; - char *radius_expr; -} FilterParam; typedef struct BoxBlurContext { const AVClass *class; @@ -73,40 +47,6 @@ typedef struct BoxBlurContext { uint8_t *temp[2]; ///< temporary buffer used in blur_power() } BoxBlurContext; -#define Y 0 -#define U 1 -#define V 2 -#define A 3 - -static av_cold int init(AVFilterContext *ctx) -{ - BoxBlurContext *s = ctx->priv; - - if (!s->luma_param.radius_expr) { - av_log(ctx, AV_LOG_ERROR, "Luma radius expression is not set.\n"); - return AVERROR(EINVAL); - } - - /* fill missing params */ - if (!s->chroma_param.radius_expr) { - s->chroma_param.radius_expr = av_strdup(s->luma_param.radius_expr); - if (!s->chroma_param.radius_expr) - return AVERROR(ENOMEM); - } - if (s->chroma_param.power < 0) - s->chroma_param.power = s->luma_param.power; - - if (!s->alpha_param.radius_expr) { - s->alpha_param.radius_expr = av_strdup(s->luma_param.radius_expr); - if (!s->alpha_param.radius_expr) - return AVERROR(ENOMEM); - } - if (s->alpha_param.power < 0) - s->alpha_param.power = s->luma_param.power; - - return 0; -} - static av_cold void uninit(AVFilterContext *ctx) { BoxBlurContext *s = ctx->priv; @@ -138,9 +78,6 @@ static int config_input(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; BoxBlurContext *s = ctx->priv; int w = inlink->w, h = inlink->h; - int cw, ch; - double var_values[VARS_NB], res; - char *expr; int ret; if (!(s->temp[0] = av_malloc(2*FFMAX(w, h))) || @@ -150,48 +87,16 @@ static int config_input(AVFilterLink *inlink) s->hsub = desc->log2_chroma_w; s->vsub = desc->log2_chroma_h; - var_values[VAR_W] = inlink->w; - var_values[VAR_H] = inlink->h; - var_values[VAR_CW] = cw = w>>s->hsub; - var_values[VAR_CH] = ch = h>>s->vsub; - var_values[VAR_HSUB] = 1<hsub; - var_values[VAR_VSUB] = 1<vsub; - -#define EVAL_RADIUS_EXPR(comp) \ - expr = s->comp##_param.radius_expr; \ - ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \ - NULL, NULL, NULL, NULL, NULL, 0, ctx); \ - s->comp##_param.radius = res; \ - if (ret < 0) { \ - av_log(NULL, AV_LOG_ERROR, \ - "Error when evaluating " #comp " radius expression '%s'\n", expr); \ - return ret; \ - } - EVAL_RADIUS_EXPR(luma); - EVAL_RADIUS_EXPR(chroma); - EVAL_RADIUS_EXPR(alpha); - - av_log(ctx, AV_LOG_VERBOSE, - "luma_radius:%d luma_power:%d " - "chroma_radius:%d chroma_power:%d " - "alpha_radius:%d alpha_power:%d " - "w:%d chroma_w:%d h:%d chroma_h:%d\n", - s->luma_param .radius, s->luma_param .power, - s->chroma_param.radius, s->chroma_param.power, - s->alpha_param .radius, s->alpha_param .power, - w, cw, h, ch); - -#define CHECK_RADIUS_VAL(w_, h_, comp) \ - if (s->comp##_param.radius < 0 || \ - 2*s->comp##_param.radius > FFMIN(w_, h_)) { \ - av_log(ctx, AV_LOG_ERROR, \ - "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \ - s->comp##_param.radius, FFMIN(w_, h_)/2); \ - return AVERROR(EINVAL); \ + ret = ff_boxblur_eval_filter_params(inlink, + &s->luma_param, + &s->chroma_param, + &s->alpha_param); + + if (ret != 0) { + av_log(ctx, AV_LOG_ERROR, "Failed to evaluate " + "filter params: %d.\n", ret); + return ret; } - CHECK_RADIUS_VAL(w, h, luma); - CHECK_RADIUS_VAL(cw, ch, chroma); - CHECK_RADIUS_VAL(w, h, alpha); s->radius[Y] = s->luma_param.radius; s->radius[U] = s->radius[V] = s->chroma_param.radius; @@ -399,12 +304,11 @@ static const AVFilterPad avfilter_vf_boxblur_outputs[] = { { NULL } }; -AVFilter ff_vf_boxblur = { +const AVFilter ff_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, .inputs = avfilter_vf_boxblur_inputs,