[FFmpeg-devel] [PATCH] lavu/eval: add clip function
Stefano Sabatini
stefasab at gmail.com
Fri Jul 4 14:13:58 CEST 2014
TODO: bump micro
---
doc/utils.texi | 4 ++++
libavutil/eval.c | 6 +++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/doc/utils.texi b/doc/utils.texi
index 5abfb0c..83ff8b0 100644
--- a/doc/utils.texi
+++ b/doc/utils.texi
@@ -782,6 +782,10 @@ large numbers (usually 2^53 and larger).
Round the value of expression @var{expr} upwards to the nearest
integer. For example, "ceil(1.5)" is "2.0".
+ at item clip(x, min, max)
+Return the value of @var{x} clipped between @var{min} and
+ at var{max}. Result is undefined if @var{min} is greater than @var{max}.
+
@item cos(x)
Compute cosine of @var{x}.
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 4a313bf..d1d048b 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -147,7 +147,7 @@ struct AVExpr {
e_pow, e_mul, e_div, e_add,
e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc,
e_sqrt, e_not, e_random, e_hypot, e_gcd,
- e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between,
+ e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip
} type;
double value; // is sign in other types
union {
@@ -187,6 +187,8 @@ static double eval_expr(Parser *p, AVExpr *e)
e->param[2] ? eval_expr(p, e->param[2]) : 0);
case e_ifnot: return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
e->param[2] ? eval_expr(p, e->param[2]) : 0);
+ case e_clip: return e->value *
+ av_clip(eval_expr(p, e->param[0]), eval_expr(p, e->param[1]), eval_expr(p, e->param[2]));
case e_between: {
double d = eval_expr(p, e->param[0]);
return e->value * (d >= eval_expr(p, e->param[1]) &&
@@ -436,6 +438,7 @@ static int parse_primary(AVExpr **e, Parser *p)
else if (strmatch(next, "bitand")) d->type = e_bitand;
else if (strmatch(next, "bitor" )) d->type = e_bitor;
else if (strmatch(next, "between"))d->type = e_between;
+ else if (strmatch(next, "clip" )) d->type = e_clip;
else {
for (i=0; p->func1_names && p->func1_names[i]; i++) {
if (strmatch(next, p->func1_names[i])) {
@@ -632,6 +635,7 @@ static int verify_expr(AVExpr *e)
return verify_expr(e->param[0]) && verify_expr(e->param[1])
&& (!e->param[2] || verify_expr(e->param[2]));
case e_between:
+ case e_clip:
return verify_expr(e->param[0]) &&
verify_expr(e->param[1]) &&
verify_expr(e->param[2]);
--
1.8.3.2
More information about the ffmpeg-devel
mailing list