[FFmpeg-devel] [PATCH] eval: implement not() expression

Stefano Sabatini stefano.sabatini-lala at poste.it
Mon May 23 16:47:23 CEST 2011


---
 doc/eval.texi    |    3 +++
 libavutil/eval.c |    8 +++++++-
 2 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index e07267b..458d15a 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -76,6 +76,9 @@ integer. For example, "trunc(-1.5)" is "-1.0".
 @item sqrt(expr)
 Compute the square root of @var{expr}. This is equivalent to
 "(@var{expr})^.5".
+
+ at item not(expr)
+Return 1.0 if @var{expr} is zero, 0.0 otherwise.
 @end table
 
 Note that:
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 9271fd6..3312215 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -125,7 +125,7 @@ struct AVExpr {
         e_mod, e_max, e_min, e_eq, e_gt, e_gte,
         e_pow, e_mul, e_div, e_add,
         e_last, e_st, e_while, e_floor, e_ceil, e_trunc,
-        e_sqrt,
+        e_sqrt, e_not,
     } type;
     double value; // is sign in other types
     union {
@@ -153,6 +153,7 @@ static double eval_expr(Parser *p, AVExpr *e)
         case e_ceil :  return e->value * ceil (eval_expr(p, e->param[0]));
         case e_trunc:  return e->value * trunc(eval_expr(p, e->param[0]));
         case e_sqrt:   return e->value * sqrt (eval_expr(p, e->param[0]));
+        case e_not:    return e->value * eval_expr(p, e->param[0]) == 0;
         case e_while: {
             double d = NAN;
             while (eval_expr(p, e->param[0]))
@@ -288,6 +289,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "ceil"  )) d->type = e_ceil;
     else if (strmatch(next, "trunc" )) d->type = e_trunc;
     else if (strmatch(next, "sqrt"  )) d->type = e_sqrt;
+    else if (strmatch(next, "not"   )) d->type = e_not;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -456,6 +458,7 @@ static int verify_expr(AVExpr *e)
         case e_ceil:
         case e_trunc:
         case e_sqrt:
+        case e_not:
             return verify_expr(e->param[0]);
         default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
     }
@@ -637,6 +640,9 @@ int main(void)
         "ceil(-123.123)",
         "sqrt(1764)",
         "sqrt(-1)",
+        "not(1)",
+        "not(NAN)",
+        "not(0)",
         NULL
     };
 
-- 
1.7.2.3



More information about the ffmpeg-devel mailing list