mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2026-06-16 04:32:47 +02:00
avutil/eval: apply unary sign to print, squish, gauss and lerp
The leading sign of a (sub)expression is stored as +-1 in each node's
value field (parse_factor) and every other function multiplies its
result by it. print, squish, gauss and lerp ignored it, so e.g.
-print(1) evaluated to 1 instead of -1 and -gauss(0) to 0.398942
instead of -0.398942, while -1*print(1) was correct.
Fixes: ticket #9833
Reported-by: Player701
Signed-off-by: Bogdan Lisman <bogdan@pydevsolutions.com>
(cherry picked from commit 3d1d546f70)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
committed by
Michael Niedermayer
parent
b9dc787d28
commit
213b6561ba
+4
-4
@@ -201,8 +201,8 @@ static double eval_expr(Parser *p, AVExpr *e)
|
||||
case e_func0: return e->value * e->func0(eval_expr(p, e->param[0]));
|
||||
case e_func1: return e->value * e->func1(p->opaque, eval_expr(p, e->param[0]));
|
||||
case e_func2: return e->value * e->func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1]));
|
||||
case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0])));
|
||||
case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); }
|
||||
case e_squish: return e->value/(1+exp(4*eval_expr(p, e->param[0])));
|
||||
case e_gauss: { double d = eval_expr(p, e->param[0]); return e->value * 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_isinf: return e->value * !!isinf(eval_expr(p, e->param[0]));
|
||||
@@ -233,13 +233,13 @@ static double eval_expr(Parser *p, AVExpr *e)
|
||||
double v0 = eval_expr(p, e->param[0]);
|
||||
double v1 = eval_expr(p, e->param[1]);
|
||||
double f = eval_expr(p, e->param[2]);
|
||||
return v0 + (v1 - v0) * f;
|
||||
return e->value * (v0 + (v1 - v0) * f);
|
||||
}
|
||||
case e_print: {
|
||||
double x = eval_expr(p, e->param[0]);
|
||||
int level = e->param[1] ? av_clip(eval_expr(p, e->param[1]), INT_MIN, INT_MAX) : AV_LOG_INFO;
|
||||
av_log(p, level, "%f\n", x);
|
||||
return x;
|
||||
return e->value * x;
|
||||
}
|
||||
|
||||
#define COMPUTE_NEXT_RANDOM() \
|
||||
|
||||
@@ -126,9 +126,14 @@ int main(int argc, char **argv)
|
||||
"root(sin(ld(0))+6+sin(ld(0)/12)-log(ld(0)), 100)",
|
||||
"7000000B*random(0)",
|
||||
"squish(2)",
|
||||
"-squish(2)",
|
||||
"gauss(0.1)",
|
||||
"-gauss(0.1)",
|
||||
"hypot(4,3)",
|
||||
"gcd(30,55)*print(min(9,1))",
|
||||
"-print(42)",
|
||||
"lerp(0, 100, 0.5)",
|
||||
"-lerp(0, 100, 0.5)",
|
||||
"bitor(42, 12)",
|
||||
"bitand(42, 12)",
|
||||
"bitand(NAN, 1)",
|
||||
|
||||
@@ -262,15 +262,30 @@ Evaluating '7000000B*random(0)'
|
||||
Evaluating 'squish(2)'
|
||||
'squish(2)' -> 0.000335
|
||||
|
||||
Evaluating '-squish(2)'
|
||||
'-squish(2)' -> -0.000335
|
||||
|
||||
Evaluating 'gauss(0.1)'
|
||||
'gauss(0.1)' -> 0.396953
|
||||
|
||||
Evaluating '-gauss(0.1)'
|
||||
'-gauss(0.1)' -> -0.396953
|
||||
|
||||
Evaluating 'hypot(4,3)'
|
||||
'hypot(4,3)' -> 5.000000
|
||||
|
||||
Evaluating 'gcd(30,55)*print(min(9,1))'
|
||||
'gcd(30,55)*print(min(9,1))' -> 5.000000
|
||||
|
||||
Evaluating '-print(42)'
|
||||
'-print(42)' -> -42.000000
|
||||
|
||||
Evaluating 'lerp(0, 100, 0.5)'
|
||||
'lerp(0, 100, 0.5)' -> 50.000000
|
||||
|
||||
Evaluating '-lerp(0, 100, 0.5)'
|
||||
'-lerp(0, 100, 0.5)' -> -50.000000
|
||||
|
||||
Evaluating 'bitor(42, 12)'
|
||||
'bitor(42, 12)' -> 46.000000
|
||||
|
||||
|
||||
Reference in New Issue
Block a user