mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2025-03-08 13:38:07 +00:00
avutil/eval: add linear interpolation helper
This commit is contained in:
parent
e3a4afca07
commit
1146133df8
@ -864,6 +864,9 @@ Load the value of the internal variable with number
|
|||||||
@var{var}, which was previously stored with st(@var{var}, @var{expr}).
|
@var{var}, which was previously stored with st(@var{var}, @var{expr}).
|
||||||
The function returns the loaded value.
|
The function returns the loaded value.
|
||||||
|
|
||||||
|
@item lerp(x, y, z)
|
||||||
|
Return linear interpolation between @var{x} and @var{y} by amount of @var{z}.
|
||||||
|
|
||||||
@item log(x)
|
@item log(x)
|
||||||
Compute natural logarithm of @var{x}.
|
Compute natural logarithm of @var{x}.
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ struct AVExpr {
|
|||||||
e_pow, e_mul, e_div, e_add,
|
e_pow, e_mul, e_div, e_add,
|
||||||
e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
|
e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
|
||||||
e_sqrt, e_not, e_random, e_hypot, e_gcd,
|
e_sqrt, e_not, e_random, e_hypot, e_gcd,
|
||||||
e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2
|
e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2, e_lerp,
|
||||||
} type;
|
} type;
|
||||||
double value; // is sign in other types
|
double value; // is sign in other types
|
||||||
union {
|
union {
|
||||||
@ -208,6 +208,12 @@ static double eval_expr(Parser *p, AVExpr *e)
|
|||||||
return e->value * (d >= eval_expr(p, e->param[1]) &&
|
return e->value * (d >= eval_expr(p, e->param[1]) &&
|
||||||
d <= eval_expr(p, e->param[2]));
|
d <= eval_expr(p, e->param[2]));
|
||||||
}
|
}
|
||||||
|
case e_lerp: {
|
||||||
|
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;
|
||||||
|
}
|
||||||
case e_print: {
|
case e_print: {
|
||||||
double x = eval_expr(p, e->param[0]);
|
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;
|
int level = e->param[1] ? av_clip(eval_expr(p, e->param[1]), INT_MIN, INT_MAX) : AV_LOG_INFO;
|
||||||
@ -456,6 +462,7 @@ static int parse_primary(AVExpr **e, Parser *p)
|
|||||||
else if (strmatch(next, "between"))d->type = e_between;
|
else if (strmatch(next, "between"))d->type = e_between;
|
||||||
else if (strmatch(next, "clip" )) d->type = e_clip;
|
else if (strmatch(next, "clip" )) d->type = e_clip;
|
||||||
else if (strmatch(next, "atan2" )) d->type = e_atan2;
|
else if (strmatch(next, "atan2" )) d->type = e_atan2;
|
||||||
|
else if (strmatch(next, "lerp" )) d->type = e_lerp;
|
||||||
else {
|
else {
|
||||||
for (i=0; p->func1_names && p->func1_names[i]; i++) {
|
for (i=0; p->func1_names && p->func1_names[i]; i++) {
|
||||||
if (strmatch(next, p->func1_names[i])) {
|
if (strmatch(next, p->func1_names[i])) {
|
||||||
@ -654,6 +661,7 @@ static int verify_expr(AVExpr *e)
|
|||||||
&& (!e->param[2] || verify_expr(e->param[2]));
|
&& (!e->param[2] || verify_expr(e->param[2]));
|
||||||
case e_between:
|
case e_between:
|
||||||
case e_clip:
|
case e_clip:
|
||||||
|
case e_lerp:
|
||||||
return verify_expr(e->param[0]) &&
|
return verify_expr(e->param[0]) &&
|
||||||
verify_expr(e->param[1]) &&
|
verify_expr(e->param[1]) &&
|
||||||
verify_expr(e->param[2]);
|
verify_expr(e->param[2]);
|
||||||
|
Loading…
Reference in New Issue
Block a user