diff options
Diffstat (limited to 'libavutil/eval.c')
-rw-r--r-- | libavutil/eval.c | 51 |
1 files changed, 46 insertions, 5 deletions
diff --git a/libavutil/eval.c b/libavutil/eval.c index a6a59a39ef..9271fd6cbc 100644 --- a/libavutil/eval.c +++ b/libavutil/eval.c @@ -2,20 +2,20 @@ * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at> * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -75,7 +75,10 @@ double av_strtod(const char *numstr, char **tail) { double d; char *next; - d = strtod(numstr, &next); + if(numstr[0]=='0' && (numstr[1]|0x20)=='x') { + d = strtol(numstr, &next, 16); + } else + d = strtod(numstr, &next); /* if parsing succeeded, check for and interpret postfixes */ if (next!=numstr) { if (*next >= 'E' && *next <= 'z') { @@ -122,6 +125,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, } type; double value; // is sign in other types union { @@ -148,6 +152,7 @@ static double eval_expr(Parser *p, AVExpr *e) case e_floor: return e->value * floor(eval_expr(p, e->param[0])); case e_ceil : return e->value * ceil (eval_expr(p, e->param[0])); 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_while: { double d = NAN; while (eval_expr(p, e->param[0])) @@ -282,6 +287,7 @@ static int parse_primary(AVExpr **e, Parser *p) else if (strmatch(next, "floor" )) d->type = e_floor; else if (strmatch(next, "ceil" )) d->type = e_ceil; else if (strmatch(next, "trunc" )) d->type = e_trunc; + else if (strmatch(next, "sqrt" )) d->type = e_sqrt; else { for (i=0; p->func1_names && p->func1_names[i]; i++) { if (strmatch(next, p->func1_names[i])) { @@ -449,6 +455,7 @@ static int verify_expr(AVExpr *e) case e_floor: case e_ceil: case e_trunc: + case e_sqrt: return verify_expr(e->param[0]); default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); } @@ -530,6 +537,38 @@ int av_expr_parse_and_eval(double *d, const char *s, return isnan(*d) ? AVERROR(EINVAL) : 0; } +#if FF_API_OLD_EVAL_NAMES +int av_parse_expr(AVExpr **expr, const char *s, + const char * const *const_names, + const char * const *func1_names, double (* const *funcs1)(void *, double), + const char * const *func2_names, double (* const *funcs2)(void *, double, double), + int log_offset, void *log_ctx) +{ + return av_expr_parse(expr, s, const_names, func1_names, funcs1, func2_names, funcs2, + log_offset, log_ctx); +} + +double av_eval_expr(AVExpr *e, const double *const_values, void *opaque) +{ + return av_expr_eval(e, const_values, opaque); +} + +int av_parse_and_eval_expr(double *res, const char *s, + const char * const *const_names, const double *const_values, + const char * const *func1_names, double (* const *funcs1)(void *, double), + const char * const *func2_names, double (* const *funcs2)(void *, double, double), + void *opaque, int log_offset, void *log_ctx) +{ + return av_expr_parse_and_eval(res, s, const_names, const_values, func1_names, funcs1, func2_names, funcs2, + opaque, log_offset, log_ctx); +} + +void av_free_expr(AVExpr *e) +{ + av_expr_free(e); +} +#endif /* FF_API_OLD_EVAL_NAMES */ + #ifdef TEST #undef printf static double const_values[] = { @@ -596,6 +635,8 @@ int main(void) "trunc(-123.123)", "ceil(123.123)", "ceil(-123.123)", + "sqrt(1764)", + "sqrt(-1)", NULL }; |