]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/fx.c
(no commit message)
[imagemagick] / MagickCore / fx.c
index 529ec822d7fc92397fbf5bf173a02e660706b437..707fcb7624f6f6efc96e765c28d65ae88b6b9f22 100644 (file)
 %                   MagickCore Image Special Effects Methods                  %
 %                                                                             %
 %                               Software Design                               %
-%                                 John Cristy                                 %
+%                                    Cristy                                   %
 %                                 October 1996                                %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -46,6 +46,7 @@
 #include "MagickCore/attribute.h"
 #include "MagickCore/cache.h"
 #include "MagickCore/cache-view.h"
+#include "MagickCore/channel.h"
 #include "MagickCore/color.h"
 #include "MagickCore/color-private.h"
 #include "MagickCore/colorspace-private.h"
 /*
   Define declarations.
 */
-#define LeftShiftOperator 0xf5
-#define RightShiftOperator 0xf6
-#define LessThanEqualOperator 0xf7
-#define GreaterThanEqualOperator 0xf8
-#define EqualOperator 0xf9
-#define NotEqualOperator 0xfa
-#define LogicalAndOperator 0xfb
-#define LogicalOrOperator 0xfc
-#define ExponentialNotation 0xfd
-
+#define LeftShiftOperator  0xf5U
+#define RightShiftOperator  0xf6U
+#define LessThanEqualOperator  0xf7U
+#define GreaterThanEqualOperator  0xf8U
+#define EqualOperator  0xf9U
+#define NotEqualOperator  0xfaU
+#define LogicalAndOperator  0xfbU
+#define LogicalOrOperator  0xfcU
+#define ExponentialNotation 0xfdU
 struct _FxInfo
 {
   const Image
@@ -178,7 +179,7 @@ MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
   fx_info->exception=AcquireExceptionInfo();
   fx_info->images=image;
   fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
-    RelinquishMagickMemory);
+    RelinquishAlignedMemory);
   fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
     RelinquishMagickMemory);
   fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
@@ -204,7 +205,7 @@ MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
   (void) SubstituteString(&fx_info->expression,"E-1.0*","E-");
   (void) SubstituteString(&fx_info->expression,"e-1.0*","e-");
   /*
-    Convert complex to simple operators.
+    Convert compound to simple operators.
   */
   fx_op[1]='\0';
   *fx_op=(char) LeftShiftOperator;
@@ -1308,7 +1309,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   level=0;
   point.x=(double) x;
   point.y=(double) y;
-  if (isalpha((int) *(p+1)) == 0)
+  if (isalpha((int) ((unsigned char) *(p+1))) == 0)
     {
       if (strchr("suv",(int) *p) != (char *) NULL)
         {
@@ -1350,7 +1351,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           if (*p == '.')
             p++;
         }
-      if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
+      if ((*p == 'p') && (isalpha((int) ((unsigned char) *(p+1))) == 0))
         {
           p++;
           if (*p == '{')
@@ -1421,8 +1422,8 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
     point.x,point.y,&pixel,exception);
   if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
-      (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
-      (LocaleCompare(p,"saturation") != 0) &&
+      (LocaleCompare(p,"luma") != 0) && (LocaleCompare(p,"luminance") != 0) &&
+      (LocaleCompare(p,"hue") != 0) && (LocaleCompare(p,"saturation") != 0) &&
       (LocaleCompare(p,"lightness") != 0))
     {
       char
@@ -1609,7 +1610,6 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             default:
               return(0.0);
           }
-          return(0.0);
         }
       if (LocaleCompare(symbol,"c") == 0)
         return(QuantumScale*pixel.red);
@@ -1707,12 +1707,20 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             &lightness);
           return(lightness);
         }
+      if (LocaleCompare(symbol,"luma") == 0)
+        {
+          double
+            luma;
+
+          luma=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
+          return(QuantumScale*luma);
+        }
       if (LocaleCompare(symbol,"luminance") == 0)
         {
           double
             luminence;
 
-          luminence=0.21267f*pixel.red+0.71516f*pixel.green+0.07217f*pixel.blue;
+          luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
           return(QuantumScale*luminence);
         }
       break;
@@ -1878,7 +1886,7 @@ static const char *FxOperatorPrecedence(const char *expression,
   while (*expression != '\0')
   {
     precedence=UndefinedPrecedence;
-    if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
+    if ((isspace((int) ((unsigned char) *expression)) != 0) || (c == (int) '@'))
       {
         expression++;
         continue;
@@ -1968,13 +1976,13 @@ static const char *FxOperatorPrecedence(const char *expression,
         }
         default:
         {
-          if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
-               (strchr(")",c) != (char *) NULL))) &&
-              (((islower((int) ((char) *expression)) != 0) ||
-               (strchr("(",(int) *expression) != (char *) NULL)) ||
-               ((isdigit((int) ((char) c)) == 0) &&
-                (isdigit((int) ((char) *expression)) != 0))) &&
-              (strchr("xy",(int) *expression) == (char *) NULL))
+          if (((c != 0) && ((isdigit((int) ((unsigned char) c)) != 0) ||
+               (strchr(")",(int) ((unsigned char) c)) != (char *) NULL))) &&
+              (((islower((int) ((unsigned char) *expression)) != 0) ||
+               (strchr("(",(int) ((unsigned char) *expression)) != (char *) NULL)) ||
+               ((isdigit((int) ((unsigned char) c)) == 0) &&
+                (isdigit((int) ((unsigned char) *expression)) != 0))) &&
+              (strchr("xy",(int) ((unsigned char) *expression)) == (char *) NULL))
             precedence=MultiplyPrecedence;
           break;
         }
@@ -2107,7 +2115,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
   *beta=0.0;
   if (exception->severity != UndefinedException)
     return(0.0);
-  while (isspace((int) *expression) != 0)
+  while (isspace((int) ((unsigned char) *expression)) != 0)
     expression++;
   if (*expression == '\0')
     {
@@ -2987,7 +2995,7 @@ static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
   if (*expression != '@')
     fx_expression=ConstantString(expression);
   else
-    fx_expression=FileToString(expression+1,~0,exception);
+    fx_expression=FileToString(expression+1,~0UL,exception);
   for (i=0; i < (ssize_t) number_threads; i++)
   {
     MagickBooleanType
@@ -3287,6 +3295,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       */
       if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(implode_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(implode_image);
           continue;
@@ -3521,14 +3530,14 @@ MagickExport Image *MorphImages(const Image *image,const size_t number_frames,
 
           for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
           {
-            PixelChannel channel=GetPixelChannelChannel(image,i);
-            PixelTrait traits=GetPixelChannelTraits(image,channel);
-            PixelTrait morph_traits=GetPixelChannelTraits(morph_image,channel);
+            PixelChannel channel=GetPixelChannelChannel(morph_image,i);
+            PixelTrait traits=GetPixelChannelTraits(morph_image,channel);
+            PixelTrait morph_traits=GetPixelChannelTraits(morph_images,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (morph_traits == UndefinedPixelTrait))
               continue;
             if (((morph_traits & CopyPixelTrait) != 0) ||
-                (GetPixelReadMask(image,p) == 0))
+                (GetPixelReadMask(morph_images,p) == 0))
               {
                 SetPixelChannel(morph_image,channel,p[i],q);
                 continue;
@@ -3716,7 +3725,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         PixelTrait traits=GetPixelChannelTraits(image,channel);
         if (traits == UndefinedPixelTrait)
           continue;
-        q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
+        q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma);
       }
       (void) SyncCacheViewAuthenticPixels(image_view,exception);
       if (segment->x1 != segment->x2)
@@ -3739,7 +3748,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             PixelTrait traits=GetPixelChannelTraits(image,channel);
             if (traits == UndefinedPixelTrait)
               continue;
-            q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
+            q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma);
           }
           (void) SyncCacheViewAuthenticPixels(image_view,exception);
         }
@@ -3766,7 +3775,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             PixelTrait traits=GetPixelChannelTraits(image,channel);
             if (traits == UndefinedPixelTrait)
               continue;
-            q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
+            q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma);
           }
           (void) SyncCacheViewAuthenticPixels(image_view,exception);
         }
@@ -3790,7 +3799,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             PixelTrait traits=GetPixelChannelTraits(image,channel);
             if (traits == UndefinedPixelTrait)
               continue;
-            q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
+            q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma);
           }
           (void) SyncCacheViewAuthenticPixels(image_view,exception);
         }
@@ -3816,7 +3825,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         PixelTrait traits=GetPixelChannelTraits(image,channel);
         if (traits == UndefinedPixelTrait)
           continue;
-        q[i]=PlasmaPixel(random_info,(u[channel]+v[channel])/2.0,plasma);
+        q[i]=PlasmaPixel(random_info,(u[i]+v[i])/2.0,plasma);
       }
       (void) SyncCacheViewAuthenticPixels(image_view,exception);
     }
@@ -4173,6 +4182,7 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
         SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
       if ((double) GetPixelBlue(image,q) < tone)
         SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
+      SetPixelAlpha(sepia_image,GetPixelAlpha(image,p),q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(sepia_image);
     }
@@ -4580,11 +4590,9 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
         if ((double) image->colormap[i].red > threshold)
           image->colormap[i].red=QuantumRange-image->colormap[i].red;
         if ((double) image->colormap[i].green > threshold)
-          image->colormap[i].green=QuantumRange-
-            image->colormap[i].green;
+          image->colormap[i].green=QuantumRange-image->colormap[i].green;
         if ((double) image->colormap[i].blue > threshold)
-          image->colormap[i].blue=QuantumRange-
-            image->colormap[i].blue;
+          image->colormap[i].blue=QuantumRange-image->colormap[i].blue;
       }
     }
   /*
@@ -5108,6 +5116,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       */
       if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(swirl_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(swirl_image);
           continue;