Author: michael Date: Sat Oct 28 00:16:25 2006 New Revision: 6813 Modified: trunk/libavcodec/eval.c Log: support seperating expressons by ; support variables, the syntax isnt beautifull (st(a,b) means var[a]=b and ld(a) var[a]) but for a mere 19 lines of code its fairly simple, if anyone wants to write real variables support with names for variables and = and [] then that would of course be welcome but only if it doesnt bloat the code up terribly...) Modified: trunk/libavcodec/eval.c ============================================================================== --- trunk/libavcodec/eval.c (original) +++ trunk/libavcodec/eval.c Sat Oct 28 00:16:25 2006 @@ -56,6 +56,8 @@ char **func2_name; // NULL terminated void *opaque; char **error; +#define VARS 10 + double var[VARS]; } Parser; static int8_t si_prefixes['z' - 'E' + 1]={ @@ -128,9 +130,10 @@ struct ff_expr_s { enum { e_value, e_const, e_func0, e_func1, e_func2, - e_squish, e_gauss, + e_squish, e_gauss, e_ld, e_mod, e_max, e_min, e_eq, e_gt, e_gte, e_pow, e_mul, e_div, e_add, + e_last, e_st, } type; double value; // is sign in other types union { @@ -151,6 +154,7 @@ case e_func2: return e->value * e->a.func2(p->opaque, eval_expr(p, e->param[0]), eval_expr(p, e->param[1])); 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_ld: return e->value * p->var[clip(eval_expr(p, e->param[0]), 0, VARS-1)]; default: { double d = eval_expr(p, e->param[0]); double d2 = eval_expr(p, e->param[1]); @@ -165,6 +169,8 @@ case e_mul: return e->value * (d * d2); case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2; + case e_st : return e->value * (p->var[clip(d, 0, VARS-1)]= d2); } } } @@ -258,6 +264,8 @@ else if( strmatch(next, "gt" ) ) d->type = e_gt; else if( strmatch(next, "lte" ) ) { AVEvalExpr * tmp = d->param[1]; d->param[1] = d->param[0]; d->param[0] = tmp; d->type = e_gt; } else if( strmatch(next, "lt" ) ) { AVEvalExpr * 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, "st" ) ) d->type = e_st; else { for(i=0; p->func1_name && p->func1_name[i]; i++){ if(strmatch(next, p->func1_name[i])){ @@ -319,6 +327,15 @@ return e; } +static AVEvalExpr * parse_subexpr(Parser *p) { + AVEvalExpr * e = parse_term(p); + while(*p->s == '+' || *p->s == '-') { + e= new_eval_expr(e_add, 1, e, parse_term(p)); + }; + + return e; +} + static AVEvalExpr * parse_expr(Parser *p) { AVEvalExpr * e; @@ -326,10 +343,11 @@ return NULL; p->stack_index--; - e = parse_term(p); + e = parse_subexpr(p); - while(*p->s == '+' || *p->s == '-') { - e= new_eval_expr(e_add, 1, e, parse_term(p)); + while(*p->s == ';') { + p->s++; + e= new_eval_expr(e_last, 1, e, parse_subexpr(p)); }; p->stack_index++; @@ -345,6 +363,7 @@ case e_func0: case e_func1: case e_squish: + case e_ld: case e_gauss: return verify_expr(e->param[0]); default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); }
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2' - ods15
On Sat, Oct 28, 2006 at 08:46:13AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2'
I was almost right, '-(1;2)' - ods15
Oded Shimon <ods15 at ods15.dyndns.org> writes:
On Sat, Oct 28, 2006 at 08:46:13AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2'
I was almost right, '-(1;2)'
What does that mean? -- M?ns Rullg?rd mru at inprovide.com
On Sat, Oct 28, 2006 at 10:36:33AM +0100, M?ns Rullg?rd wrote:
Oded Shimon <ods15 at ods15.dyndns.org> writes:
On Sat, Oct 28, 2006 at 08:46:13AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2'
I was almost right, '-(1;2)'
What does that mean?
';' is a statement seperator, the first value is ignored, the second is used as the result of the expression. So, '(1;2)' returns simply '2'. The bug was that the '-' was ignored, and the overall expression returned '2' instead of '-2'. The reason for that is that the sign is stored always in e->value. - ods15
Hi On Sat, Oct 28, 2006 at 11:39:56AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 10:36:33AM +0100, M?ns Rullg?rd wrote:
Oded Shimon <ods15 at ods15.dyndns.org> writes:
On Sat, Oct 28, 2006 at 08:46:13AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2'
I was almost right, '-(1;2)'
What does that mean?
';' is a statement seperator, the first value is ignored, the second is used as the result of the expression. So, '(1;2)' returns simply '2'. The bug was that the '-' was ignored, and the overall expression returned '2' instead of '-2'. The reason for that is that the sign is stored always in e->value.
btw, what is your oppinion about getting rid of thet value* hack? and replace it either by a negate(x) operation or pass the sign up and switch add to sub (with neg() only if that isnt possible) ? ive implemented both but they are a few lines of code more so iam not sure if its a good idea or not [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB In the past you could go to a library and read, borrow or copy any book Today you'd get arrested for mere telling someone where the library is
On Sat, Oct 28, 2006 at 05:07:08PM +0200, Michael Niedermayer wrote:
Hi
On Sat, Oct 28, 2006 at 11:39:56AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 10:36:33AM +0100, M?ns Rullg?rd wrote:
Oded Shimon <ods15 at ods15.dyndns.org> writes:
On Sat, Oct 28, 2006 at 08:46:13AM +0200, Oded Shimon wrote:
On Sat, Oct 28, 2006 at 12:16:26AM +0200, michael wrote: [..]
case e_div: return e->value * (d / d2); case e_add: return e->value * (d + d2); + case e_last:return d2;
I'm fairly sure there should be an 'e->value *' here... try the expression '5;-2'
I was almost right, '-(1;2)'
What does that mean?
';' is a statement seperator, the first value is ignored, the second is used as the result of the expression. So, '(1;2)' returns simply '2'. The bug was that the '-' was ignored, and the overall expression returned '2' instead of '-2'. The reason for that is that the sign is stored always in e->value.
btw, what is your oppinion about getting rid of thet value* hack? and replace it either by a negate(x) operation or pass the sign up and switch add to sub (with neg() only if that isnt possible) ? ive implemented both but they are a few lines of code more so iam not sure if its a good idea or not
No real thoughts, just make sure to not make a redundant negate on a const value. (for e_value, just multiply by the sign..) - ods15
participants (4)
-
michaelni@gmx.at -
mru@inprovide.com -
ods15@ods15.dyndns.org -
subversion@mplayerhq.hu