[FFmpeg-devel] [PATCH] lavfi/hue: simplify parsing by making use of option shorthands
Stefano Sabatini
stefasab at gmail.com
Tue Feb 19 23:39:24 CET 2013
---
libavfilter/vf_hue.c | 32 +++-----------------------------
1 file changed, 3 insertions(+), 29 deletions(-)
diff --git a/libavfilter/vf_hue.c b/libavfilter/vf_hue.c
index 7bc3d37..0491d57 100644
--- a/libavfilter/vf_hue.c
+++ b/libavfilter/vf_hue.c
@@ -130,13 +130,12 @@ static inline void compute_sin_and_cos(HueContext *hue)
static inline int set_options(AVFilterContext *ctx, const char *args)
{
HueContext *hue = ctx->priv;
- int n, ret;
- char c1 = 0, c2 = 0;
+ int ret;
char *old_hue_expr, *old_hue_deg_expr, *old_saturation_expr;
AVExpr *old_hue_pexpr, *old_hue_deg_pexpr, *old_saturation_pexpr;
if (args) {
- /* named options syntax */
+ static const char *shorthand[] = { "h", "s", NULL };
if (strchr(args, '=')) {
old_hue_expr = hue->hue_expr;
old_hue_deg_expr = hue->hue_deg_expr;
@@ -150,7 +149,7 @@ static inline int set_options(AVFilterContext *ctx, const char *args)
hue->hue_deg_expr = NULL;
hue->saturation_expr = NULL;
- if ((ret = av_set_options_string(hue, args, "=", ":")) < 0)
+ if ((ret = av_opt_set_from_string(hue, args, shorthand, "=", ":")) < 0)
return ret;
if (hue->hue_expr && hue->hue_deg_expr) {
av_log(ctx, AV_LOG_ERROR,
@@ -171,31 +170,6 @@ static inline int set_options(AVFilterContext *ctx, const char *args)
av_log(ctx, AV_LOG_VERBOSE,
"H_expr:%s h_deg_expr:%s s_expr:%s\n",
hue->hue_expr, hue->hue_deg_expr, hue->saturation_expr);
-
- /* compatibility h:s syntax */
- } else {
- n = sscanf(args, "%f%c%f%c", &hue->hue_deg, &c1, &hue->saturation, &c2);
- if (n != 1 && (n != 3 || c1 != ':')) {
- av_log(ctx, AV_LOG_ERROR,
- "Invalid syntax for argument '%s': "
- "must be in the form 'hue[:saturation]'\n", args);
- return AVERROR(EINVAL);
- }
-
- if (hue->saturation < SAT_MIN_VAL || hue->saturation > SAT_MAX_VAL) {
- av_log(ctx, AV_LOG_ERROR,
- "Invalid value for saturation %0.1f: "
- "must be included between range %d and +%d\n",
- hue->saturation, SAT_MIN_VAL, SAT_MAX_VAL);
- return AVERROR(EINVAL);
- }
-
- hue->hue = hue->hue_deg * M_PI / 180;
- hue->flat_syntax = 1;
-
- av_log(ctx, AV_LOG_VERBOSE,
- "H:%0.1f h:%0.1f s:%0.1f\n",
- hue->hue, hue->hue_deg, hue->saturation);
}
}
--
1.7.9.5
More information about the ffmpeg-devel
mailing list