[FFmpeg-devel] [PATCH] lavfi/eq: factorize code in process_command through a macro

Stefano Sabatini stefasab at gmail.com
Fri Mar 13 17:16:53 CET 2015


---
 libavfilter/vf_eq.c | 56 ++++++++++++++---------------------------------------
 1 file changed, 15 insertions(+), 41 deletions(-)

diff --git a/libavfilter/vf_eq.c b/libavfilter/vf_eq.c
index 980e9ca..e1aa206 100644
--- a/libavfilter/vf_eq.c
+++ b/libavfilter/vf_eq.c
@@ -282,48 +282,22 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar
     EQContext *eq = ctx->priv;
     int ret;
 
-    if (!strcmp(cmd, "contrast")) {
-        ret = set_expr(&eq->contrast_pexpr, args, cmd, ctx);
-        set_contrast(eq);
-        return ret;
-    }
-    else if (!strcmp(cmd, "brightness")) {
-        ret = set_expr(&eq->brightness_pexpr, args, cmd, ctx);
-        set_brightness(eq);
-        return ret;
-    }
-    else if (!strcmp(cmd, "saturation")) {
-        ret = set_expr(&eq->saturation_pexpr, args, cmd, ctx);
-        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;
+#define SET_PARAM(param_name, set_name)                                 \
+    if (!strcmp(cmd, #param_name)) {                                    \
+        ret = set_expr(&eq->param_name##_pexpr, args, cmd, ctx);        \
+        set_##set_name(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);
+
+         SET_PARAM(contrast, contrast)
+    else SET_PARAM(brightness, brightness)
+    else SET_PARAM(saturation, saturation)
+    else SET_PARAM(gamma, gamma)
+    else SET_PARAM(gamma_r, gamma)
+    else SET_PARAM(gamma_g, gamma)
+    else SET_PARAM(gamma_b, gamma)
+    else SET_PARAM(gamma_weight, gamma)
+    else return AVERROR(ENOSYS);
 }
 
 static const AVFilterPad eq_inputs[] = {
-- 
1.8.3.2



More information about the ffmpeg-devel mailing list