[FFmpeg-cvslog] eval: add random()

Michael Niedermayer git at videolan.org
Sat Oct 8 03:25:26 CEST 2011


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Sat Oct  8 03:09:16 2011 +0200| [ac7cda9e149918c2d0afc94b82dea02802ed6f90] | committer: Michael Niedermayer

eval: add random()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavutil/eval.c |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)

diff --git a/libavutil/eval.c b/libavutil/eval.c
index 1ec5694..ecb389b 100644
--- a/libavutil/eval.c
+++ b/libavutil/eval.c
@@ -126,7 +126,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_not,
+        e_sqrt, e_not, e_random,
     } type;
     double value; // is sign in other types
     union {
@@ -156,6 +156,13 @@ static double eval_expr(Parser *p, AVExpr *e)
         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_random:{
+            int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1);
+            uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx];
+            r= r*1664525+1013904223;
+            p->var[idx]= r;
+            return e->value * (r * (1.0/UINT64_MAX));
+        }
         case e_while: {
             double d = NAN;
             while (eval_expr(p, e->param[0]))
@@ -294,6 +301,7 @@ static int parse_primary(AVExpr **e, Parser *p)
     else if (strmatch(next, "sqrt"  )) d->type = e_sqrt;
     else if (strmatch(next, "not"   )) d->type = e_not;
     else if (strmatch(next, "pow"   )) d->type = e_pow;
+    else if (strmatch(next, "random")) d->type = e_random;
     else {
         for (i=0; p->func1_names && p->func1_names[i]; i++) {
             if (strmatch(next, p->func1_names[i])) {
@@ -463,6 +471,7 @@ static int verify_expr(AVExpr *e)
         case e_trunc:
         case e_sqrt:
         case e_not:
+        case e_random:
             return verify_expr(e->param[0]);
         default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
     }



More information about the ffmpeg-cvslog mailing list