[FFmpeg-cvslog] eval: add support for trunc, ceil, and floor functions

Stefano Sabatini git at videolan.org
Tue Apr 5 16:48:51 CEST 2011


ffmpeg | branch: master | Stefano Sabatini <stefano.sabatini-lala at poste.it> | Sun Mar 27 22:56:49 2011 +0200| [25601bc5649fb71f645e9a619871cc85170f5dd8] | committer: Stefano Sabatini

eval: add support for trunc, ceil, and floor functions

Signed-off-by: Stefano Sabatini <stefano.sabatini-lala at poste.it>

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

 doc/eval.texi      |   12 ++++++++++++
 libavutil/avutil.h |    2 +-
 libavutil/eval.c   |   21 +++++++++++++++++++--
 3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/doc/eval.texi b/doc/eval.texi
index 99cd034..d0e04c0 100644
--- a/doc/eval.texi
+++ b/doc/eval.texi
@@ -60,6 +60,18 @@ The function returns the loaded value.
 Evaluate expression @var{expr} while the expression @var{cond} is
 non-zero, and returns the value of the last @var{expr} evaluation, or
 NAN if @var{cond} was always false.
+
+ at item ceil(expr)
+Round the value of expression @var{expr} upwards to the nearest
+integer. For example, "ceil(1.5)" is "2.0".
+
+ at item floor(expr)
+Round the value of expression @var{expr} downwards to the nearest
+integer. For example, "floor(-1.5)" is "-2.0".
+
+ at item trunc(expr)
+Round the value of expression @var{expr} towards zero to the nearest
+integer. For example, "trunc(-1.5)" is "-1.0".
 @end table
 
 Note that:
diff --git a/libavutil/avutil.h b/libavutil/avutil.h
index 095540c..e44a2b7 100644
--- a/libavutil/avutil.h
+++ b/libavutil/avutil.h
@@ -41,7 +41,7 @@
 
 #define LIBAVUTIL_VERSION_MAJOR 50
 #define LIBAVUTIL_VERSION_MINOR 40
-#define LIBAVUTIL_VERSION_MICRO  0
+#define LIBAVUTIL_VERSION_MICRO  1
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
                                                LIBAVUTIL_VERSION_MINOR, \
diff --git a/libavutil/eval.c b/libavutil/eval.c
index 0fef97b..494b936 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -121,7 +121,7 @@ struct AVExpr {
         e_squish, e_gauss, e_ld, e_isnan,
         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_last, e_st, e_while, e_floor, e_ceil, e_trunc,
     } type;
     double value; // is sign in other types
     union {
@@ -145,6 +145,9 @@ static double eval_expr(Parser *p, AVExpr *e)
         case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
         case e_ld:     return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
         case e_isnan:  return e->value * !!isnan(eval_expr(p, e->param[0]));
+        case e_floor:  return e->value * floor(eval_expr(p, e->param[0]));
+        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_while: {
             double d = NAN;
             while (eval_expr(p, e->param[0]))
@@ -276,6 +279,9 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "isnan" )) d->type = e_isnan;
     else if (strmatch(next, "st"    )) d->type = e_st;
     else if (strmatch(next, "while" )) d->type = e_while;
+    else if (strmatch(next, "floor" )) d->type = e_floor;
+    else if (strmatch(next, "ceil"  )) d->type = e_ceil;
+    else if (strmatch(next, "trunc" )) d->type = e_trunc;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -439,7 +445,11 @@ static int verify_expr(AVExpr *e)
         case e_squish:
         case e_ld:
         case e_gauss:
-        case e_isnan: return verify_expr(e->param[0]);
+        case e_isnan:
+        case e_floor:
+        case e_ceil:
+        case e_trunc:
+            return verify_expr(e->param[0]);
         default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
     }
 }
@@ -611,6 +621,13 @@ int main(void)
         "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
         "isnan(1)",
         "isnan(NAN)",
+        "floor(NAN)",
+        "floor(123.123)",
+        "floor(-123.123)",
+        "trunc(123.123)",
+        "trunc(-123.123)",
+        "ceil(123.123)",
+        "ceil(-123.123)",
         NULL
     };
 



More information about the ffmpeg-cvslog mailing list