Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -126,7 +126,7 @@ struct AVExpr {
|
| 126 | 126 |
e_mod, e_max, e_min, e_eq, e_gt, e_gte, |
| 127 | 127 |
e_pow, e_mul, e_div, e_add, |
| 128 | 128 |
e_last, e_st, e_while, e_floor, e_ceil, e_trunc, |
| 129 |
- e_sqrt, e_not, |
|
| 129 |
+ e_sqrt, e_not, e_random, |
|
| 130 | 130 |
} type; |
| 131 | 131 |
double value; // is sign in other types |
| 132 | 132 |
union {
|
| ... | ... |
@@ -156,6 +156,13 @@ static double eval_expr(Parser *p, AVExpr *e) |
| 156 | 156 |
case e_trunc: return e->value * trunc(eval_expr(p, e->param[0])); |
| 157 | 157 |
case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0])); |
| 158 | 158 |
case e_not: return e->value * eval_expr(p, e->param[0]) == 0; |
| 159 |
+ case e_random:{
|
|
| 160 |
+ int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1); |
|
| 161 |
+ uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx]; |
|
| 162 |
+ r= r*1664525+1013904223; |
|
| 163 |
+ p->var[idx]= r; |
|
| 164 |
+ return e->value * (r * (1.0/UINT64_MAX)); |
|
| 165 |
+ } |
|
| 159 | 166 |
case e_while: {
|
| 160 | 167 |
double d = NAN; |
| 161 | 168 |
while (eval_expr(p, e->param[0])) |
| ... | ... |
@@ -294,6 +301,7 @@ static int parse_primary(AVExpr **e, Parser *p) |
| 294 | 294 |
else if (strmatch(next, "sqrt" )) d->type = e_sqrt; |
| 295 | 295 |
else if (strmatch(next, "not" )) d->type = e_not; |
| 296 | 296 |
else if (strmatch(next, "pow" )) d->type = e_pow; |
| 297 |
+ else if (strmatch(next, "random")) d->type = e_random; |
|
| 297 | 298 |
else {
|
| 298 | 299 |
for (i=0; p->func1_names && p->func1_names[i]; i++) {
|
| 299 | 300 |
if (strmatch(next, p->func1_names[i])) {
|
| ... | ... |
@@ -463,6 +471,7 @@ static int verify_expr(AVExpr *e) |
| 463 | 463 |
case e_trunc: |
| 464 | 464 |
case e_sqrt: |
| 465 | 465 |
case e_not: |
| 466 |
+ case e_random: |
|
| 466 | 467 |
return verify_expr(e->param[0]); |
| 467 | 468 |
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); |
| 468 | 469 |
} |