]> git.sesse.net Git - casparcg/blob - ffmpeg 0.7/include/libavutil/eval.h
2.0.2: INFO TEMPLATE works on both compressed and uncompressed templates.
[casparcg] / ffmpeg 0.7 / include / libavutil / eval.h
1 /*
2  * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * simple arithmetic expression evaluator
24  */
25
26 #ifndef AVUTIL_EVAL_H
27 #define AVUTIL_EVAL_H
28
29 #include "avutil.h"
30
31 typedef struct AVExpr AVExpr;
32
33 /**
34  * Parse and evaluate an expression.
35  * Note, this is significantly slower than av_expr_eval().
36  *
37  * @param res a pointer to a double where is put the result value of
38  * the expression, or NAN in case of error
39  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
40  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
41  * @param const_values a zero terminated array of values for the identifiers from const_names
42  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
43  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
44  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
45  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
46  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
47  * @param log_ctx parent logging context
48  * @return 0 in case of success, a negative value corresponding to an
49  * AVERROR code otherwise
50  */
51 int av_expr_parse_and_eval(double *res, const char *s,
52                            const char * const *const_names, const double *const_values,
53                            const char * const *func1_names, double (* const *funcs1)(void *, double),
54                            const char * const *func2_names, double (* const *funcs2)(void *, double, double),
55                            void *opaque, int log_offset, void *log_ctx);
56
57 /**
58  * Parse an expression.
59  *
60  * @param expr a pointer where is put an AVExpr containing the parsed
61  * value in case of successfull parsing, or NULL otherwise.
62  * The pointed to AVExpr must be freed with av_expr_free() by the user
63  * when it is not needed anymore.
64  * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)"
65  * @param const_names NULL terminated array of zero terminated strings of constant identifiers, for example {"PI", "E", 0}
66  * @param func1_names NULL terminated array of zero terminated strings of funcs1 identifiers
67  * @param funcs1 NULL terminated array of function pointers for functions which take 1 argument
68  * @param func2_names NULL terminated array of zero terminated strings of funcs2 identifiers
69  * @param funcs2 NULL terminated array of function pointers for functions which take 2 arguments
70  * @param log_ctx parent logging context
71  * @return 0 in case of success, a negative value corresponding to an
72  * AVERROR code otherwise
73  */
74 int av_expr_parse(AVExpr **expr, const char *s,
75                   const char * const *const_names,
76                   const char * const *func1_names, double (* const *funcs1)(void *, double),
77                   const char * const *func2_names, double (* const *funcs2)(void *, double, double),
78                   int log_offset, void *log_ctx);
79
80 /**
81  * Evaluate a previously parsed expression.
82  *
83  * @param const_values a zero terminated array of values for the identifiers from av_expr_parse() const_names
84  * @param opaque a pointer which will be passed to all functions from funcs1 and funcs2
85  * @return the value of the expression
86  */
87 double av_expr_eval(AVExpr *e, const double *const_values, void *opaque);
88
89 /**
90  * Free a parsed expression previously created with av_expr_parse().
91  */
92 void av_expr_free(AVExpr *e);
93
94 #if FF_API_OLD_EVAL_NAMES
95 /**
96  * @deprecated Deprecated in favor of av_expr_parse_and_eval().
97  */
98 attribute_deprecated
99 int av_parse_and_eval_expr(double *res, const char *s,
100                            const char * const *const_names, const double *const_values,
101                            const char * const *func1_names, double (* const *funcs1)(void *, double),
102                            const char * const *func2_names, double (* const *funcs2)(void *, double, double),
103                            void *opaque, int log_offset, void *log_ctx);
104
105 /**
106  * @deprecated Deprecated in favor of av_expr_parse().
107  */
108 attribute_deprecated
109 int av_parse_expr(AVExpr **expr, const char *s,
110                   const char * const *const_names,
111                   const char * const *func1_names, double (* const *funcs1)(void *, double),
112                   const char * const *func2_names, double (* const *funcs2)(void *, double, double),
113                   int log_offset, void *log_ctx);
114 /**
115  * @deprecated Deprecated in favor of av_expr_eval().
116  */
117 attribute_deprecated
118 double av_eval_expr(AVExpr *e, const double *const_values, void *opaque);
119
120 /**
121  * @deprecated Deprecated in favor of av_expr_free().
122  */
123 attribute_deprecated
124 void av_free_expr(AVExpr *e);
125 #endif /* FF_API_OLD_EVAL_NAMES */
126
127 /**
128  * Parse the string in numstr and return its value as a double. If
129  * the string is empty, contains only whitespaces, or does not contain
130  * an initial substring that has the expected syntax for a
131  * floating-point number, no conversion is performed. In this case,
132  * returns a value of zero and the value returned in tail is the value
133  * of numstr.
134  *
135  * @param numstr a string representing a number, may contain one of
136  * the International System number postfixes, for example 'K', 'M',
137  * 'G'. If 'i' is appended after the postfix, powers of 2 are used
138  * instead of powers of 10. The 'B' postfix multiplies the value for
139  * 8, and can be appended after another postfix or used alone. This
140  * allows using for example 'KB', 'MiB', 'G' and 'B' as postfix.
141  * @param tail if non-NULL puts here the pointer to the char next
142  * after the last parsed character
143  */
144 double av_strtod(const char *numstr, char **tail);
145
146 #endif /* AVUTIL_EVAL_H */