History

lavfi/hue: apply major simplifications, and switch to AVOption-based system

This also drops support for "flat syntax" and "reinit" command. "reinit" command is not very robust and complicates the logic more than necessary, since requires to reset all the options in the command. *This is a syntax break*.

Stefano Sabatini committed 13 years ago

Commit e4fd58f1 parent c36ab014 files · +66 −116Browse files

Unified · Split

4 files
  1. doc/filters.texi +20 −31
  2. libavfilter/avfilter.c +0 −1
  3. libavfilter/version.h +1 −1
  4. libavfilter/vf_hue.c +45 −83
doc/filters.texi+20−31
@@ -3653,24 +3653,27 @@ a float number which specifies chroma temporal strength, defaults to · 3652 unmodified lines
36533653
36543654 Modify the hue and/or the saturation of the input.
36553655
3656−This filter accepts the following optional named options:
3656+This filter accepts the following options:
36573657
36583658 @table @option
36593659 @item h
3660−Specify the hue angle as a number of degrees. It accepts a float
3661−number or an expression, and defaults to 0.0.
3662−
3663−@item H
3664−Specify the hue angle as a number of radians. It accepts a float
3665−number or an expression, and defaults to 0.0.
3660+Specify the hue angle as a number of degrees. It accepts an expression,
3661+and defaults to "0".
36663662
36673663 @item s
36683664 Specify the saturation in the [-10,10] range. It accepts a float number and
3669−defaults to 1.0.
3665+defaults to "1".
3666+
3667+@item H
3668+Specify the hue angle as a number of radians. It accepts a float
3669+number or an expression, and defaults to "0".
36703670 @end table
36713671
3672−The @var{h}, @var{H} and @var{s} parameters are expressions containing the
3673−following constants:
3672+@option{h} and @option{H} are mutually exclusive, and can't be
3673+specified at the same time.
3674+
3675+The @option{h}, @option{H} and @option{s} option values are
3676+expressions containing the following constants:
36743677
36753678 @table @option
36763679 @item n
@@ -3689,10 +3692,6 @@ timestamp expressed in seconds, NAN if the input timestamp is unknown · 12 unmodified lines
36893692 time base of the input video
36903693 @end table
36913694
3692−The options can also be set using the syntax: @var{hue}:@var{saturation}
3693−
3694−In this case @var{hue} is expressed in degrees.
3695−
36963695 @subsection Examples
36973696
36983697 @itemize
@@ -3708,19 +3707,6 @@ Same command but expressing the hue in radians: · 9 unmodified lines
37083707 hue=H=PI/2:s=1
37093708 @end example
37103709
3711−@item
3712−Same command without named options, hue must be expressed in degrees:
3713−@example
3714−hue=90:1
3715−@end example
3716−
3717−@item
3718−Note that "h:s" syntax does not support expressions for the values of
3719−h and s, so the following example will issue an error:
3720−@example
3721−hue=PI/2:1
3722−@end example
3723−
37243710 @item
37253711 Rotate hue and make the saturation swing between 0
37263712 and 2 over a period of 1 second:
@@ -3756,12 +3742,15 @@ hue="s=max(0\, min(1\, (START+DURATION-t)/DURATION))" · 29 unmodified lines
37563742
37573743 This filter supports the following command:
37583744 @table @option
3759−@item reinit
3745+@item s
3746+@item h
3747+@item H
37603748 Modify the hue and/or the saturation of the input video.
3761−The command accepts the same named options and syntax than when calling the
3762−filter from the command-line.
3749+The command accepts the same options and syntax of the corresponding
3750+options.
37633751
3764−If a parameter is omitted, it is kept at its current value.
3752+If the specified expression is not valid, it is kept at its current
3753+value.
37653754 @end table
37663755
37673756 @section idet
libavfilter/avfilter.c+0−1
@@ -679,7 +679,6 @@ static const char *const filters_left_to_update[] = { · 678 unmodified lines
679679 "atempo",
680680 "buffer",
681681 "flite",
682− "hue",
683682 "mp",
684683 "pan",
685684 "scale",
libavfilter/version.h+1−1
@@ -30,7 +30,7 @@ · 29 unmodified lines
3030
3131 #define LIBAVFILTER_VERSION_MAJOR 3
3232 #define LIBAVFILTER_VERSION_MINOR 52
33−#define LIBAVFILTER_VERSION_MICRO 101
33+#define LIBAVFILTER_VERSION_MICRO 102
3434
3535 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
3636 LIBAVFILTER_VERSION_MINOR, \
libavfilter/vf_hue.c+45−83
@@ -36,12 +36,6 @@ · 35 unmodified lines
3636 #include "internal.h"
3737 #include "video.h"
3838
39−#define HUE_DEFAULT_VAL 0
40−#define SAT_DEFAULT_VAL 1
41−
42−#define HUE_DEFAULT_VAL_STRING AV_STRINGIFY(HUE_DEFAULT_VAL)
43−#define SAT_DEFAULT_VAL_STRING AV_STRINGIFY(SAT_DEFAULT_VAL)
44−
4539 #define SAT_MIN_VAL -10
4640 #define SAT_MAX_VAL 10
4741
@@ -78,7 +72,6 @@ typedef struct { · 30 unmodified lines
7872 int vsub;
7973 int32_t hue_sin;
8074 int32_t hue_cos;
81− int flat_syntax;
8275 double var_values[VAR_NB];
8376 } HueContext;
8477
@@ -87,9 +80,9 @@ typedef struct { · 2 unmodified lines
8780 static const AVOption hue_options[] = {
8881 { "h", "set the hue angle degrees expression", OFFSET(hue_deg_expr), AV_OPT_TYPE_STRING,
8982 { .str = NULL }, .flags = FLAGS },
90− { "H", "set the hue angle radians expression", OFFSET(hue_expr), AV_OPT_TYPE_STRING,
91− { .str = NULL }, .flags = FLAGS },
9283 { "s", "set the saturation expression", OFFSET(saturation_expr), AV_OPT_TYPE_STRING,
84+ { .str = "1" }, .flags = FLAGS },
85+ { "H", "set the hue angle radians expression", OFFSET(hue_expr), AV_OPT_TYPE_STRING,
9386 { .str = NULL }, .flags = FLAGS },
9487 { NULL }
9588 };
@@ -107,99 +100,62 @@ static inline void compute_sin_and_cos(HueContext *hue) · 11 unmodified lines
107100 hue->hue_cos = rint(cos(hue->hue) * (1 << 16) * hue->saturation);
108101 }
109102
110−#define SET_EXPRESSION(attr, name) do { \
111− if (hue->attr##_expr) { \
112− if ((ret = av_expr_parse(&hue->attr##_pexpr, hue->attr##_expr, var_names, \
113− NULL, NULL, NULL, NULL, 0, ctx)) < 0) { \
114− av_log(ctx, AV_LOG_ERROR, \
115− "Parsing failed for expression " #name "='%s'", \
116− hue->attr##_expr); \
117− hue->attr##_expr = old_##attr##_expr; \
118− hue->attr##_pexpr = old_##attr##_pexpr; \
119− return AVERROR(EINVAL); \
120− } else if (old_##attr##_pexpr) { \
121− av_freep(&old_##attr##_expr); \
122− av_expr_free(old_##attr##_pexpr); \
123− old_##attr##_pexpr = NULL; \
124− } \
125− } else { \
126− hue->attr##_expr = old_##attr##_expr; \
127− } \
128−} while (0)
129−
130−static inline int set_options(AVFilterContext *ctx, const char *args)
103+static int set_expr(AVExpr **pexpr, const char *expr, const char *option, void *log_ctx)
131104 {
132− HueContext *hue = ctx->priv;
133105 int ret;
134− char *old_hue_expr, *old_hue_deg_expr, *old_saturation_expr;
135− AVExpr *old_hue_pexpr, *old_hue_deg_pexpr, *old_saturation_pexpr;
136− static const char *shorthand[] = { "h", "s", NULL };
137− old_hue_expr = hue->hue_expr;
138− old_hue_deg_expr = hue->hue_deg_expr;
139− old_saturation_expr = hue->saturation_expr;
140−
141− old_hue_pexpr = hue->hue_pexpr;
142− old_hue_deg_pexpr = hue->hue_deg_pexpr;
143− old_saturation_pexpr = hue->saturation_pexpr;
144−
145− hue->hue_expr = NULL;
146− hue->hue_deg_expr = NULL;
147− hue->saturation_expr = NULL;
148−
149− if ((ret = av_opt_set_from_string(hue, args, shorthand, "=", ":")) < 0)
106+ AVExpr *old = NULL;
107+
108+ if (*pexpr)
109+ old = *pexpr;
110+ ret = av_expr_parse(pexpr, expr, var_names,
111+ NULL, NULL, NULL, NULL, 0, log_ctx);
112+ if (ret < 0) {
113+ av_log(log_ctx, AV_LOG_ERROR,
114+ "Error when evaluating the expression '%s' for %s\n",
115+ expr, option);
116+ *pexpr = old;
150117 return ret;
118+ }
119+ av_expr_free(old);
120+ return 0;
121+}
122+
123+static av_cold int init(AVFilterContext *ctx, const char *args)
124+{
125+ HueContext *hue = ctx->priv;
126+ int ret;
127+
151128 if (hue->hue_expr && hue->hue_deg_expr) {
152129 av_log(ctx, AV_LOG_ERROR,
153130 "H and h options are incompatible and cannot be specified "
154131 "at the same time\n");
155− hue->hue_expr = old_hue_expr;
156− hue->hue_deg_expr = old_hue_deg_expr;
157−
158132 return AVERROR(EINVAL);
159133 }
160134
161− SET_EXPRESSION(hue_deg, h);
162− SET_EXPRESSION(hue, H);
163− SET_EXPRESSION(saturation, s);
164−
165− hue->flat_syntax = 0;
135+#define SET_EXPR(expr, option) \
136+ if (hue->expr##_expr) do { \
137+ ret = set_expr(&hue->expr##_pexpr, hue->expr##_expr, option, ctx); \
138+ if (ret < 0) \
139+ return ret; \
140+ } while (0)
141+ SET_EXPR(saturation, "s");
142+ SET_EXPR(hue_deg, "h");
143+ SET_EXPR(hue, "H");
166144
167145 av_log(ctx, AV_LOG_VERBOSE,
168146 "H_expr:%s h_deg_expr:%s s_expr:%s\n",
169147 hue->hue_expr, hue->hue_deg_expr, hue->saturation_expr);
170−
171148 compute_sin_and_cos(hue);
172149
173150 return 0;
174151 }
175152
176−static av_cold int init(AVFilterContext *ctx, const char *args)
177−{
178− HueContext *hue = ctx->priv;
179−
180− hue->class = &hue_class;
181− av_opt_set_defaults(hue);
182−
183− hue->saturation = SAT_DEFAULT_VAL;
184− hue->hue = HUE_DEFAULT_VAL;
185− hue->hue_deg_pexpr = NULL;
186− hue->hue_pexpr = NULL;
187− hue->flat_syntax = 1;
188−
189− return set_options(ctx, args);
190−}
191−
192153 static av_cold void uninit(AVFilterContext *ctx)
193154 {
194155 HueContext *hue = ctx->priv;
195156
196− av_opt_free(hue);
197−
198− av_free(hue->hue_deg_expr);
199157 av_expr_free(hue->hue_deg_pexpr);
200− av_free(hue->hue_expr);
201158 av_expr_free(hue->hue_pexpr);
202− av_free(hue->saturation_expr);
203159 av_expr_free(hue->saturation_pexpr);
204160 }
205161
@@ -295,7 +251,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 89 unmodified lines
295251 av_frame_copy_props(outpic, inpic);
296252 }
297253
298− if (!hue->flat_syntax) {
254+ /* todo: reindent */
299255 hue->var_values[VAR_T] = TS2T(inpic->pts, inlink->time_base);
300256 hue->var_values[VAR_PTS] = TS2D(inpic->pts);
301257
@@ -323,7 +279,6 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 21 unmodified lines
323279 hue->var_values[VAR_T], (int)hue->var_values[VAR_N]);
324280
325281 compute_sin_and_cos(hue);
326− }
327282
328283 hue->var_values[VAR_N] += 1;
329284
@@ -345,10 +300,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *inpic) · 15 unmodified lines
345300 static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
346301 char *res, int res_len, int flags)
347302 {
348− if (!strcmp(cmd, "reinit"))
349− return set_options(ctx, args);
350− else
351− return AVERROR(ENOSYS);
303+ HueContext *hue = ctx->priv;
304+
305+#define SET_CMD(expr, option) \
306+ if (!strcmp(cmd, option)) do { \
307+ return set_expr(&hue->expr##_pexpr, args, cmd, ctx); \
308+ } while (0)
309+ SET_CMD(hue_deg, "h");
310+ SET_CMD(hue, "H");
311+ SET_CMD(saturation, "s");
312+
313+ return AVERROR(ENOSYS);
352314 }
353315
354316 static const AVFilterPad hue_inputs[] = {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t