Commit e6547cce authored by Stefano Sabatini's avatar Stefano Sabatini

lavfi/eq: factorize code in process_command()

parent 6b940b8c
...@@ -276,54 +276,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) ...@@ -276,54 +276,34 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
return ff_filter_frame(outlink, out); return ff_filter_frame(outlink, out);
} }
static inline int set_param(AVExpr **pexpr, const char *args, const char *cmd,
void (*set_fn)(EQContext *eq), AVFilterContext *ctx)
{
EQContext *eq = ctx->priv;
int ret;
if ((ret = set_expr(pexpr, args, cmd, ctx)) < 0)
return ret;
set_fn(eq);
return 0;
}
static int process_command(AVFilterContext *ctx, const char *cmd, const char *args, static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
char *res, int res_len, int flags) char *res, int res_len, int flags)
{ {
EQContext *eq = ctx->priv; EQContext *eq = ctx->priv;
int ret;
if (!strcmp(cmd, "contrast")) { #define SET_PARAM(param_name, set_fn_name) \
ret = set_expr(&eq->contrast_pexpr, args, cmd, ctx); if (!strcmp(cmd, #param_name)) return set_param(&eq->param_name##_pexpr, args, cmd, set_##set_fn_name, ctx);
set_contrast(eq);
return ret; SET_PARAM(contrast, contrast)
} else SET_PARAM(brightness, brightness)
else if (!strcmp(cmd, "brightness")) { else SET_PARAM(saturation, saturation)
ret = set_expr(&eq->brightness_pexpr, args, cmd, ctx); else SET_PARAM(gamma, gamma)
set_brightness(eq); else SET_PARAM(gamma_r, gamma)
return ret; else SET_PARAM(gamma_g, gamma)
} else SET_PARAM(gamma_b, gamma)
else if (!strcmp(cmd, "saturation")) { else SET_PARAM(gamma_weight, gamma)
ret = set_expr(&eq->saturation_pexpr, args, cmd, ctx); else return AVERROR(ENOSYS);
set_saturation(eq);
return ret;
}
else if (!strcmp(cmd, "gamma")) {
ret = set_expr(&eq->gamma_pexpr, args, cmd, ctx);
set_gamma(eq);
return ret;
}
else if (!strcmp(cmd, "gamma_r")) {
ret = set_expr(&eq->gamma_r_pexpr, args, cmd, ctx);
set_gamma(eq);
return ret;
}
else if (!strcmp(cmd, "gamma_g")) {
ret = set_expr(&eq->gamma_g_pexpr, args, cmd, ctx);
set_gamma(eq);
return ret;
}
else if (!strcmp(cmd, "gamma_b")) {
ret = set_expr(&eq->gamma_b_pexpr, args, cmd, ctx);
set_gamma(eq);
return ret;
}
else if (!strcmp(cmd, "gamma_weight")) {
ret = set_expr(&eq->gamma_weight_pexpr, args, cmd, ctx);
set_gamma(eq);
return ret;
}
else
return AVERROR(ENOSYS);
} }
static const AVFilterPad eq_inputs[] = { static const AVFilterPad eq_inputs[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment