Commit 20fcd079 authored by Stefano Sabatini's avatar Stefano Sabatini

Implement isnan() function evaluation.

Originally committed as revision 25666 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 07851d79
...@@ -34,6 +34,9 @@ The following functions are available: ...@@ -34,6 +34,9 @@ The following functions are available:
@item abs(x) @item abs(x)
@item squish(x) @item squish(x)
@item gauss(x) @item gauss(x)
@item isnan(x)
Return 1.0 if @var{x} is NAN, 0.0 otherwise.
@item mod(x, y) @item mod(x, y)
@item max(x, y) @item max(x, y)
@item min(x, y) @item min(x, y)
......
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
#define LIBAVUTIL_VERSION_MAJOR 50 #define LIBAVUTIL_VERSION_MAJOR 50
#define LIBAVUTIL_VERSION_MINOR 32 #define LIBAVUTIL_VERSION_MINOR 32
#define LIBAVUTIL_VERSION_MICRO 5 #define LIBAVUTIL_VERSION_MICRO 6
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \ LIBAVUTIL_VERSION_MINOR, \
......
...@@ -118,7 +118,7 @@ static int strmatch(const char *s, const char *prefix) ...@@ -118,7 +118,7 @@ static int strmatch(const char *s, const char *prefix)
struct AVExpr { struct AVExpr {
enum { enum {
e_value, e_const, e_func0, e_func1, e_func2, e_value, e_const, e_func0, e_func1, e_func2,
e_squish, e_gauss, e_ld, e_squish, e_gauss, e_ld, e_isnan,
e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_mod, e_max, e_min, e_eq, e_gt, e_gte,
e_pow, e_mul, e_div, e_add, e_pow, e_mul, e_div, e_add,
e_last, e_st, e_while, e_last, e_st, e_while,
...@@ -144,6 +144,7 @@ static double eval_expr(Parser *p, AVExpr *e) ...@@ -144,6 +144,7 @@ static double eval_expr(Parser *p, AVExpr *e)
case e_squish: return 1/(1+exp(4*eval_expr(p, e->param[0]))); 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_gauss: { double d = eval_expr(p, e->param[0]); return 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_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_while: { case e_while: {
double d = NAN; double d = NAN;
while (eval_expr(p, e->param[0])) while (eval_expr(p, e->param[0]))
...@@ -272,6 +273,7 @@ static int parse_primary(AVExpr **e, Parser *p) ...@@ -272,6 +273,7 @@ static int parse_primary(AVExpr **e, Parser *p)
else if (strmatch(next, "lte" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; } else if (strmatch(next, "lte" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; }
else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; } else if (strmatch(next, "lt" )) { AVExpr *tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gte; }
else if (strmatch(next, "ld" )) d->type = e_ld; else if (strmatch(next, "ld" )) d->type = e_ld;
else if (strmatch(next, "isnan" )) d->type = e_isnan;
else if (strmatch(next, "st" )) d->type = e_st; else if (strmatch(next, "st" )) d->type = e_st;
else if (strmatch(next, "while" )) d->type = e_while; else if (strmatch(next, "while" )) d->type = e_while;
else { else {
...@@ -436,7 +438,8 @@ static int verify_expr(AVExpr *e) ...@@ -436,7 +438,8 @@ static int verify_expr(AVExpr *e)
case e_func1: case e_func1:
case e_squish: case e_squish:
case e_ld: case e_ld:
case e_gauss: return verify_expr(e->param[0]); case e_gauss:
case e_isnan: return verify_expr(e->param[0]);
default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); default: return verify_expr(e->param[0]) && verify_expr(e->param[1]);
} }
} }
...@@ -574,6 +577,8 @@ int main(void) ...@@ -574,6 +577,8 @@ int main(void)
"st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)", "st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)",
"while(0, 10)", "while(0, 10)",
"st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))",
"isnan(1)",
"isnan(NAN)",
NULL NULL
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment