[FFmpeg-cvslog] eval: implement not() expression

Stefano Sabatini git at videolan.org
Mon Sep 19 22:54:14 CEST 2011


ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Mon May 23 13:13:50 2011 +0200| [8cee38a298bb818a400f0dce0efd54d593250eec] | committer: Anton Khirnov

eval: implement not() expression

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8cee38a298bb818a400f0dce0efd54d593250eec
---

 doc/eval.texi       |    8 +++-----
 libavutil/avutil.h  |    2 +-
 libavutil/eval.c    |    8 +++++++-
 tests/ref/fate/eval |    9 +++++++++
 4 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index 4a9495c..7d8106b 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:
@@ -93,11 +96,6 @@ is equivalent to
 A*B + not(A)*C
 @end example
 
-When A evaluates to either 1 or 0, that is the same as
- at example
-A*B + eq(A,0)*C
- at end example
-
 In your C code, you can extend the list of unary and binary functions,
 and define recognized constants, so that they are available for your
 expressions.
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 7d995c2..5d378ce 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -41,7 +41,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR 51
 #define LIBAVUTIL_VERSION_MINOR 10
-#define LIBAVUTIL_VERSION_MICRO  1
+#define LIBAVUTIL_VERSION_MICRO  2
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 878cf5c..4126cd7 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -123,7 +123,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 {
@@ -151,6 +151,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]))
@@ -286,6 +287,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])) {
@@ -454,6 +456,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]);
     }
@@ -606,6 +609,9 @@ int main(int argc, char **argv)
         "ceil(-123.123)",
         "sqrt(1764)",
         "sqrt(-1)",
+        "not(1)",
+        "not(NAN)",
+        "not(0)",
         NULL
     };
 
diff --git a/tests/ref/fate/eval b/tests/ref/fate/eval
index 00e5887..0e4844e 100644
--- a/tests/ref/fate/eval
+++ b/tests/ref/fate/eval
@@ -139,5 +139,14 @@ Evaluating 'sqrt(1764)'
 Evaluating 'sqrt(-1)'
 'sqrt(-1)' -> -nan
 
+Evaluating 'not(1)'
+'not(1)' -> 0.000000
+
+Evaluating 'not(NAN)'
+'not(NAN)' -> 0.000000
+
+Evaluating 'not(0)'
+'not(0)' -> 1.000000
+
 12.700000 == 12.7
 0.931323 == 0.931322575



More information about the ffmpeg-cvslog mailing list