]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/eval.c
Simplify vsad16_mmx().
[ffmpeg] / libavcodec / eval.c
index bbd6ae4ca57a82ccfe56a4ad8e17038e0e853049..25e817850647dffeea9bf9368cefb5550bcec64e 100644 (file)
@@ -1,7 +1,8 @@
 /*
  * simple arithmetic expression evaluator
  *
- * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2002-2006 Michael Niedermayer <michaelni@gmx.at>
+ * Copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
  *
  * This file is part of FFmpeg.
  *
@@ -18,7 +19,6 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
  */
 
 /**
@@ -29,7 +29,6 @@
  */
 
 #include "avcodec.h"
-#include "mpegvideo.h"
 #include "eval.h"
 
 #include <stdio.h>
@@ -55,7 +54,7 @@ typedef struct Parser{
     double (**func2)(void *, double a, double b); // NULL terminated
     char **func2_name;          // NULL terminated
     void *opaque;
-    char **error;
+    const char **error;
 #define VARS 10
     double var[VARS];
 } Parser;
@@ -109,7 +108,7 @@ static double av_strtod(const char *name, char **tail) {
 
         if(*next=='B') {
             d*=8;
-            *next++;
+            next++;
         }
     }
     /* if requested, fill in tail with the position after the last parsed
@@ -154,9 +153,9 @@ static double eval_expr(Parser * p, AVEvalExpr * e) {
         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)];
+        case e_ld:     return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)];
         case e_while: {
-            double d;
+            double d = NAN;
             while(eval_expr(p, e->param[0]))
                 d=eval_expr(p, e->param[1]);
             return d;
@@ -175,8 +174,8 @@ static double eval_expr(Parser * p, AVEvalExpr * e) {
                 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);
+                case e_last:return e->value * d2;
+                case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2);
             }
         }
     }
@@ -376,15 +375,20 @@ static int verify_expr(AVEvalExpr * e) {
     }
 }
 
-AVEvalExpr * ff_parse(char *s, const char **const_name,
+AVEvalExpr * ff_parse(const char *s, const char **const_name,
                double (**func1)(void *, double), const char **func1_name,
                double (**func2)(void *, double, double), char **func2_name,
-               char **error){
+               const char **error){
     Parser p;
     AVEvalExpr * e;
+    char w[strlen(s) + 1], * wp = w;
+
+    while (*s)
+        if (!isspace(*s++)) *wp++ = s[-1];
+    *wp++ = 0;
 
     p.stack_index=100;
-    p.s= s;
+    p.s= w;
     p.const_name = const_name;
     p.func1      = func1;
     p.func1_name = func1_name;
@@ -408,10 +412,10 @@ double ff_parse_eval(AVEvalExpr * e, double *const_value, void *opaque) {
     return eval_expr(&p, e);
 }
 
-double ff_eval2(char *s, double *const_value, const char **const_name,
+double ff_eval2(const char *s, double *const_value, const char **const_name,
                double (**func1)(void *, double), const char **func1_name,
                double (**func2)(void *, double, double), char **func2_name,
-               void *opaque, char **error){
+               void *opaque, const char **error){
     AVEvalExpr * e = ff_parse(s, const_name, func1, func1_name, func2, func2_name, error);
     double d;
     if (!e) return NAN;
@@ -425,7 +429,7 @@ attribute_deprecated double ff_eval(char *s, double *const_value, const char **c
                double (**func1)(void *, double), const char **func1_name,
                double (**func2)(void *, double, double), char **func2_name,
                void *opaque){
-    char *error=NULL;
+    const char *error=NULL;
     double ret;
     ret = ff_eval2(s, const_value, const_name, func1, func1_name, func2, func2_name, opaque, &error);
     if (error)
@@ -446,7 +450,7 @@ static const char *const_names[]={
     "E",
     0
 };
-main(){
+int main(void){
     int i;
     printf("%f == 12.7\n", ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
     printf("%f == 0.931322575\n", ff_eval("80G/80Gi", const_values, const_names, NULL, NULL, NULL, NULL, NULL));
@@ -456,5 +460,6 @@ main(){
             ff_eval("1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", const_values, const_names, NULL, NULL, NULL, NULL, NULL);
         STOP_TIMER("ff_eval")
     }
+    return 0;
 }
 #endif