]> granicus.if.org Git - imagemagick/commitdiff
...
authorCristy <urban-warrior@imagemagick.org>
Tue, 2 Jul 2019 14:43:49 +0000 (10:43 -0400)
committerCristy <urban-warrior@imagemagick.org>
Tue, 2 Jul 2019 14:43:49 +0000 (10:43 -0400)
MagickCore/fx.c

index 518f4da0040b8243e8d249689919cdd49e950a41..7e3b7e709c0751214e9e8362d8542b0a82c70a1b 100644 (file)
@@ -1223,6 +1223,19 @@ static double
   FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
     const ssize_t,const char *,const size_t,double *,ExceptionInfo *);
 
+static inline MagickBooleanType IsFxFunction(const char *expression,
+  const char *name,const size_t length)
+{
+  int
+    c;
+
+  c=name[length];
+  if ((LocaleNCompare(expression,name,length) == 0) &&
+      ((isspace(c) == 0) || (c == '(')))
+    return(MagickTrue);
+  return(MagickFalse);
+}
+
 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
 {
   if (beta != 0)
@@ -1524,7 +1537,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'C':
     case 'c':
     {
-      if (LocaleNCompare(symbol,"channel",7) == 0)
+      if (IsFxFunction(symbol,"channel",7) != MagickFalse)
         {
           GeometryInfo
             channel_info;
@@ -1913,27 +1926,27 @@ static const char *FxOperatorPrecedence(const char *expression,
       case 'a':
       {
 #if defined(MAGICKCORE_HAVE_ACOSH)
-        if (LocaleNCompare(expression,"acosh",5) == 0)
+        if (IsFxFunction(expression,"acosh",5) != MagickFalse)
           {
             expression+=5;
             break;
           }
 #endif
 #if defined(MAGICKCORE_HAVE_ASINH)
-        if (LocaleNCompare(expression,"asinh",5) == 0)
+        if (IsFxFunction(expression,"asinh",5) != MagickFalse)
           {
             expression+=5;
             break;
           }
 #endif
 #if defined(MAGICKCORE_HAVE_ATANH)
-        if (LocaleNCompare(expression,"atanh",5) == 0)
+        if (IsFxFunction(expression,"atanh",5) != MagickFalse)
           {
             expression+=5;
             break;
           }
 #endif
-        if (LocaleNCompare(expression,"atan2",5) == 0)
+        if (IsFxFunction(expression,"atan2",5) != MagickFalse)
           {
             expression+=5;
             break;
@@ -1954,8 +1967,8 @@ static const char *FxOperatorPrecedence(const char *expression,
       case 'J':
       case 'j':
       {
-        if ((LocaleNCompare(expression,"j0",2) == 0) ||
-            (LocaleNCompare(expression,"j1",2) == 0))
+        if ((IsFxFunction(expression,"j0",2) != MagickFalse) ||
+            (IsFxFunction(expression,"j1",2) != MagickFalse))
           {
             expression+=2;
             break;
@@ -2413,28 +2426,28 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'A':
     case 'a':
     {
-      if (LocaleNCompare(expression,"abs",3) == 0)
+      if (IsFxFunction(expression,"abs",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(fabs(alpha));
         }
 #if defined(MAGICKCORE_HAVE_ACOSH)
-      if (LocaleNCompare(expression,"acosh",5) == 0)
+      if (IsFxFunction(expression,"acosh",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
           FxReturn(acosh(alpha));
         }
 #endif
-      if (LocaleNCompare(expression,"acos",4) == 0)
+      if (IsFxFunction(expression,"acos",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(acos(alpha));
         }
 #if defined(MAGICKCORE_HAVE_J1)
-      if (LocaleNCompare(expression,"airy",4) == 0)
+      if (IsFxFunction(expression,"airy",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
@@ -2445,40 +2458,40 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
 #endif
 #if defined(MAGICKCORE_HAVE_ASINH)
-      if (LocaleNCompare(expression,"asinh",5) == 0)
+      if (IsFxFunction(expression,"asinh",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
           FxReturn(asinh(alpha));
         }
 #endif
-      if (LocaleNCompare(expression,"asin",4) == 0)
+      if (IsFxFunction(expression,"asin",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(asin(alpha));
         }
-      if (LocaleNCompare(expression,"alt",3) == 0)
+      if (IsFxFunction(expression,"alt",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
         }
-      if (LocaleNCompare(expression,"atan2",5) == 0)
+      if (IsFxFunction(expression,"atan2",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
           FxReturn(atan2(alpha,*beta));
         }
 #if defined(MAGICKCORE_HAVE_ATANH)
-      if (LocaleNCompare(expression,"atanh",5) == 0)
+      if (IsFxFunction(expression,"atanh",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
           FxReturn(atanh(alpha));
         }
 #endif
-      if (LocaleNCompare(expression,"atan",4) == 0)
+      if (IsFxFunction(expression,"atan",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
@@ -2498,13 +2511,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'C':
     case 'c':
     {
-      if (LocaleNCompare(expression,"ceil",4) == 0)
+      if (IsFxFunction(expression,"ceil",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(ceil(alpha));
         }
-      if (LocaleNCompare(expression,"clamp",5) == 0)
+      if (IsFxFunction(expression,"clamp",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2514,13 +2527,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
             FxReturn(1.0);
           FxReturn(alpha);
         }
-      if (LocaleNCompare(expression,"cosh",4) == 0)
+      if (IsFxFunction(expression,"cosh",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(cosh(alpha));
         }
-      if (LocaleNCompare(expression,"cos",3) == 0)
+      if (IsFxFunction(expression,"cos",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2533,7 +2546,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'D':
     case 'd':
     {
-      if (LocaleNCompare(expression,"debug",5) == 0)
+      if (IsFxFunction(expression,"debug",5) != MagickFalse)
         {
           const char
             *type;
@@ -2571,7 +2584,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
               subexpression,GetMagickPrecision(),alpha);
           FxReturn(0.0);
         }
-      if (LocaleNCompare(expression,"drc",3) == 0)
+      if (IsFxFunction(expression,"drc",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2585,14 +2598,14 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
       if (LocaleCompare(expression,"epsilon") == 0)
         FxReturn(MagickEpsilon);
 #if defined(MAGICKCORE_HAVE_ERF)
-      if (LocaleNCompare(expression,"erf",3) == 0)
+      if (IsFxFunction(expression,"erf",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(erf(alpha));
         }
 #endif
-      if (LocaleNCompare(expression,"exp",3) == 0)
+      if (IsFxFunction(expression,"exp",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2605,7 +2618,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'F':
     case 'f':
     {
-      if (LocaleNCompare(expression,"floor",5) == 0)
+      if (IsFxFunction(expression,"floor",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2616,14 +2629,14 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'G':
     case 'g':
     {
-      if (LocaleNCompare(expression,"gauss",5) == 0)
+      if (IsFxFunction(expression,"gauss",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
           gamma=exp((-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
           FxReturn(gamma);
         }
-      if (LocaleNCompare(expression,"gcd",3) == 0)
+      if (IsFxFunction(expression,"gcd",3) != MagickFalse)
         {
           MagickOffsetType
             gcd;
@@ -2645,7 +2658,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         FxReturn(FxGetSymbol(fx_info,channel,x,y,expression,depth+1,exception));
       if (LocaleCompare(expression,"hue") == 0)
         FxReturn(FxGetSymbol(fx_info,channel,x,y,expression,depth+1,exception));
-      if (LocaleNCompare(expression,"hypot",5) == 0)
+      if (IsFxFunction(expression,"hypot",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2665,13 +2678,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleCompare(expression,"intensity") == 0)
         FxReturn(FxGetSymbol(fx_info,channel,x,y,expression,depth+1,exception));
-      if (LocaleNCompare(expression,"int",3) == 0)
+      if (IsFxFunction(expression,"int",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(floor(alpha));
         }
-      if (LocaleNCompare(expression,"isnan",5) == 0)
+      if (IsFxFunction(expression,"isnan",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2687,7 +2700,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
       if (LocaleCompare(expression,"j") == 0)
         FxReturn(FxGetSymbol(fx_info,channel,x,y,expression,depth+1,exception));
 #if defined(MAGICKCORE_HAVE_J0)
-      if (LocaleNCompare(expression,"j0",2) == 0)
+      if (IsFxFunction(expression,"j0",2) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,
             depth+1,beta,exception);
@@ -2695,7 +2708,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
-      if (LocaleNCompare(expression,"j1",2) == 0)
+      if (IsFxFunction(expression,"j1",2) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,
             depth+1,beta,exception);
@@ -2703,7 +2716,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
-      if (LocaleNCompare(expression,"jinc",4) == 0)
+      if (IsFxFunction(expression,"jinc",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
@@ -2718,19 +2731,19 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'L':
     case 'l':
     {
-      if (LocaleNCompare(expression,"ln",2) == 0)
+      if (IsFxFunction(expression,"ln",2) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,
             depth+1,beta,exception);
           FxReturn(log(alpha));
         }
-      if (LocaleNCompare(expression,"logtwo",6) == 0)
+      if (IsFxFunction(expression,"logtwo",6) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,
             depth+1,beta,exception);
           FxReturn(log10(alpha)/log10(2.0));
         }
-      if (LocaleNCompare(expression,"log",3) == 0)
+      if (IsFxFunction(expression,"log",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2747,7 +2760,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         FxReturn(QuantumRange);
       if (LocaleNCompare(expression,"maxima",6) == 0)
         break;
-      if (LocaleNCompare(expression,"max",3) == 0)
+      if (IsFxFunction(expression,"max",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2755,13 +2768,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
       if (LocaleNCompare(expression,"minima",6) == 0)
         break;
-      if (LocaleNCompare(expression,"min",3) == 0)
+      if (IsFxFunction(expression,"min",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(alpha < *beta ? alpha : *beta);
         }
-      if (LocaleNCompare(expression,"mod",3) == 0)
+      if (IsFxFunction(expression,"mod",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2775,7 +2788,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'N':
     case 'n':
     {
-      if (LocaleNCompare(expression,"not",3) == 0)
+      if (IsFxFunction(expression,"not",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2801,7 +2814,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         FxReturn(MagickPHI);
       if (LocaleCompare(expression,"pi") == 0)
         FxReturn(MagickPI);
-      if (LocaleNCompare(expression,"pow",3) == 0)
+      if (IsFxFunction(expression,"pow",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2823,7 +2836,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'R':
     case 'r':
     {
-      if (LocaleNCompare(expression,"rand",4) == 0)
+      if (IsFxFunction(expression,"rand",4) != MagickFalse)
         {
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
         #pragma omp critical (MagickCore_FxEvaluateSubexpression)
@@ -2831,7 +2844,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           alpha=GetPseudoRandomValue(fx_info->random_info);
           FxReturn(alpha);
         }
-      if (LocaleNCompare(expression,"round",5) == 0)
+      if (IsFxFunction(expression,"round",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2846,13 +2859,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleCompare(expression,"saturation") == 0)
         FxReturn(FxGetSymbol(fx_info,channel,x,y,expression,depth+1,exception));
-      if (LocaleNCompare(expression,"sign",4) == 0)
+      if (IsFxFunction(expression,"sign",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(alpha < 0.0 ? -1.0 : 1.0);
         }
-      if (LocaleNCompare(expression,"sinc",4) == 0)
+      if (IsFxFunction(expression,"sinc",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
@@ -2861,25 +2874,25 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           gamma=sin((MagickPI*alpha))/(MagickPI*alpha);
           FxReturn(gamma);
         }
-      if (LocaleNCompare(expression,"sinh",4) == 0)
+      if (IsFxFunction(expression,"sinh",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(sinh(alpha));
         }
-      if (LocaleNCompare(expression,"sin",3) == 0)
+      if (IsFxFunction(expression,"sin",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
           FxReturn(sin(alpha));
         }
-      if (LocaleNCompare(expression,"sqrt",4) == 0)
+      if (IsFxFunction(expression,"sqrt",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(sqrt(alpha));
         }
-      if (LocaleNCompare(expression,"squish",6) == 0)
+      if (IsFxFunction(expression,"squish",6) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,
             depth+1,beta,exception);
@@ -2892,13 +2905,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'T':
     case 't':
     {
-      if (LocaleNCompare(expression,"tanh",4) == 0)
+      if (IsFxFunction(expression,"tanh",4) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,
             depth+1,beta,exception);
           FxReturn(tanh(alpha));
         }
-      if (LocaleNCompare(expression,"tan",3) == 0)
+      if (IsFxFunction(expression,"tan",3) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,
             depth+1,beta,exception);
@@ -2906,7 +2919,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
       if (LocaleCompare(expression,"Transparent") == 0)
         FxReturn(0.0);
-      if (LocaleNCompare(expression,"trunc",5) == 0)
+      if (IsFxFunction(expression,"trunc",5) != MagickFalse)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
             depth+1,beta,exception);
@@ -2935,7 +2948,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'W':
     case 'w':
     {
-      if (LocaleNCompare(expression,"while(",6) == 0)
+      if (IsFxFunction(expression,"while",5) != MagickFalse)
         {
           do
           {