History

libavutil/eval: Add round function to expression parser

We have floor, ceil, and trunc. Let's add round.

Kevin Mark committed 9 years ago

Commit 482566c1 parent 850cbd42 files · +7 −1Browse files

Unified · Split

2 files
  1. doc/utils.texi +3 −0
  2. libavutil/eval.c +4 −1
doc/utils.texi+3−0
@@ -914,6 +914,9 @@ various input values that the expression can access through · 913 unmodified lines
914@code{ld(0)}. When the expression evaluates to 0 then the914@code{ld(0)}. When the expression evaluates to 0 then the
915corresponding input value will be returned.915corresponding input value will be returned.
916 916
917@item round(expr)
918Round the value of expression @var{expr} to the nearest integer. For example, "round(1.5)" is "2.0".
919
917@item sin(x)920@item sin(x)
918Compute sine of @var{x}.921Compute sine of @var{x}.
919 922
libavutil/eval.c+4−1
@@ -153,7 +153,7 @@ struct AVExpr { · 152 unmodified lines
153 e_squish, e_gauss, e_ld, e_isnan, e_isinf,153 e_squish, e_gauss, e_ld, e_isnan, e_isinf,
154 e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt,154 e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_lte, e_lt,
155 e_pow, e_mul, e_div, e_add,155 e_pow, e_mul, e_div, e_add,
156 e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc,156 e_last, e_st, e_while, e_taylor, e_root, e_floor, e_ceil, e_trunc, e_round,
157 e_sqrt, e_not, e_random, e_hypot, e_gcd,157 e_sqrt, e_not, e_random, e_hypot, e_gcd,
158 e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2158 e_if, e_ifnot, e_print, e_bitand, e_bitor, e_between, e_clip, e_atan2
159 } type;159 } type;
@@ -189,6 +189,7 @@ static double eval_expr(Parser *p, AVExpr *e) · 29 unmodified lines
189 case e_floor: return e->value * floor(eval_expr(p, e->param[0]));189 case e_floor: return e->value * floor(eval_expr(p, e->param[0]));
190 case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));190 case e_ceil : return e->value * ceil (eval_expr(p, e->param[0]));
191 case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));191 case e_trunc: return e->value * trunc(eval_expr(p, e->param[0]));
192 case e_round: return e->value * round(eval_expr(p, e->param[0]));
192 case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));193 case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0]));
193 case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);194 case e_not: return e->value * (eval_expr(p, e->param[0]) == 0);
194 case e_if: return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :195 case e_if: return e->value * (eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) :
@@ -440,6 +441,7 @@ static int parse_primary(AVExpr **e, Parser *p) · 245 unmodified lines
440 else if (strmatch(next, "floor" )) d->type = e_floor;441 else if (strmatch(next, "floor" )) d->type = e_floor;
441 else if (strmatch(next, "ceil" )) d->type = e_ceil;442 else if (strmatch(next, "ceil" )) d->type = e_ceil;
442 else if (strmatch(next, "trunc" )) d->type = e_trunc;443 else if (strmatch(next, "trunc" )) d->type = e_trunc;
444 else if (strmatch(next, "round" )) d->type = e_round;
443 else if (strmatch(next, "sqrt" )) d->type = e_sqrt;445 else if (strmatch(next, "sqrt" )) d->type = e_sqrt;
444 else if (strmatch(next, "not" )) d->type = e_not;446 else if (strmatch(next, "not" )) d->type = e_not;
445 else if (strmatch(next, "pow" )) d->type = e_pow;447 else if (strmatch(next, "pow" )) d->type = e_pow;
@@ -637,6 +639,7 @@ static int verify_expr(AVExpr *e) · 191 unmodified lines
637 case e_floor:639 case e_floor:
638 case e_ceil:640 case e_ceil:
639 case e_trunc:641 case e_trunc:
642 case e_round:
640 case e_sqrt:643 case e_sqrt:
641 case e_not:644 case e_not:
642 case e_random:645 case e_random:

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t