]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/fx.c
(no commit message)
[imagemagick] / MagickCore / fx.c
index 51dacb37a01e54014c781cd61e1ee0f5e76c5201..44c4e5e56bb4c39725cc65e726162dff840046ac 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-2015 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;
@@ -600,8 +601,7 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius,
   clone_image=CloneImage(image,0,0,MagickTrue,exception);
   if (clone_image == (Image *) NULL)
     return((Image *) NULL);
-  edge_image=EdgeImage(clone_image,GetOptimalKernelWidth1D(radius,1.0),
-    exception);
+  edge_image=EdgeImage(clone_image,radius,exception);
   clone_image=DestroyImage(clone_image);
   if (edge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -701,8 +701,8 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   if ((IsGrayColorspace(image->colorspace) != MagickFalse) ||
       (IsPixelInfoGray(colorize) != MagickFalse))
     (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
-  if ((colorize_image->alpha_trait != BlendPixelTrait) &&
-      (colorize->alpha_trait == BlendPixelTrait))
+  if ((colorize_image->alpha_trait == UndefinedPixelTrait) &&
+      (colorize->alpha_trait != UndefinedPixelTrait))
     (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
   if (blend == (const char *) NULL)
     return(colorize_image);
@@ -712,7 +712,7 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   blend_percentage.green=geometry_info.rho;
   blend_percentage.blue=geometry_info.rho;
   blend_percentage.black=geometry_info.rho;
-  blend_percentage.alpha=geometry_info.rho;
+  blend_percentage.alpha=(MagickRealType) TransparentAlpha;
   if ((flags & SigmaValue) != 0)
     blend_percentage.green=geometry_info.sigma;
   if ((flags & XiValue) != 0)
@@ -993,7 +993,7 @@ MagickExport Image *ColorMatrixImage(const Image *image,
           GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
         if (image->colorspace == CMYKColorspace)
           sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
-        if (image->alpha_trait == BlendPixelTrait)
+        if (image->alpha_trait != UndefinedPixelTrait)
           sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
         sum+=QuantumRange*ColorMatrix[v][5];
         switch (v)
@@ -1115,13 +1115,6 @@ static inline double MagickMax(const double x,const double y)
   return(y);
 }
 
-static inline double MagickMin(const double x,const double y)
-{
-  if (x < y)
-    return(x);
-  return(y);
-}
-
 static double FxChannelStatistics(FxInfo *fx_info,Image *image,
   PixelChannel channel,const char *symbol,ExceptionInfo *exception)
 {
@@ -1309,7 +1302,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)
         {
@@ -1351,7 +1344,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 == '{')
@@ -1410,7 +1403,8 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   length=GetImageListLength(fx_info->images);
   while (i < 0)
     i+=(ssize_t) length;
-  i%=length;
+  if (length != 0)
+    i%=length;
   image=GetImageFromList(fx_info->images,i);
   if (image == (Image *) NULL)
     {
@@ -1422,8 +1416,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
@@ -1493,7 +1487,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           double
             alpha;
 
-          if (pixel.alpha_trait != BlendPixelTrait)
+          if (pixel.alpha_trait == UndefinedPixelTrait)
             return(1.0);
           alpha=(double) (QuantumScale*pixel.alpha);
           return(alpha);
@@ -1501,9 +1495,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
         case IndexPixelChannel:
           return(0.0);
         case IntensityPixelChannel:
-        {
           return(QuantumScale*GetPixelInfoIntensity(&pixel));
-        }
         default:
           break;
       }
@@ -1610,7 +1602,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);
@@ -1708,12 +1699,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;
@@ -1728,7 +1727,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
       if (LocaleNCompare(symbol,"minima",6) == 0)
         return(FxChannelStatistics(fx_info,image,channel,symbol,exception));
       if (LocaleCompare(symbol,"m") == 0)
-        return(QuantumScale*pixel.blue);
+        return(QuantumScale*pixel.green);
       break;
     }
     case 'N':
@@ -1807,7 +1806,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'y':
     {
       if (LocaleCompare(symbol,"y") == 0)
-        return(QuantumScale*pixel.green);
+        return(QuantumScale*pixel.blue);
       break;
     }
     case 'Z':
@@ -1879,7 +1878,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;
@@ -1920,9 +1919,10 @@ static const char *FxOperatorPrecedence(const char *expression,
       case 'E':
       case 'e':
       {
-        if ((LocaleNCompare(expression,"E+",2) == 0) ||
-            (LocaleNCompare(expression,"E-",2) == 0))
-          {
+        if ((isdigit((int) ((unsigned char) c)) != 0) &&
+            ((LocaleNCompare(expression,"E+",2) == 0) ||
+             (LocaleNCompare(expression,"E-",2) == 0)))
+          { 
             expression+=2;  /* scientific notation */
             break;
           }
@@ -1969,13 +1969,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;
         }
@@ -2106,16 +2106,12 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     *p;
 
   *beta=0.0;
-  if (exception->severity != UndefinedException)
+  if (exception->severity >= ErrorException)
     return(0.0);
-  while (isspace((int) *expression) != 0)
+  while (isspace((int) ((unsigned char) *expression)) != 0)
     expression++;
   if (*expression == '\0')
-    {
-      (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "MissingExpression","`%s'",expression);
-      return(0.0);
-    }
+    return(0.0);
   *subexpression='\0';
   p=FxOperatorPrecedence(expression,exception);
   if (p != (const char *) NULL)
@@ -2154,9 +2150,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
           if (*beta == 0.0)
             {
-              if (exception->severity == UndefinedException)
-                (void) ThrowMagickException(exception,GetMagickModule(),
-                  OptionError,"DivideByZero","`%s'",expression);
+              (void) ThrowMagickException(exception,GetMagickModule(),
+                OptionError,"DivideByZero","`%s'",expression);
               return(0.0);
             }
           return(alpha/(*beta));
@@ -2218,7 +2213,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         case EqualOperator:
         {
           *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
+          return(fabs(alpha-(*beta)) < MagickEpsilon ? 1.0 : 0.0);
         }
         case NotEqualOperator:
         {
@@ -2733,7 +2728,16 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     case 'r':
     {
       if (LocaleNCompare(expression,"rand",4) == 0)
-        return((double) GetPseudoRandomValue(fx_info->random_info));
+        {
+          double
+            alpha;
+
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+        #pragma omp critical (MagickCore_FxEvaluateSubexpression)
+#endif
+          alpha=GetPseudoRandomValue(fx_info->random_info);
+          return(alpha);
+        }
       if (LocaleNCompare(expression,"round",5) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
@@ -2988,7 +2992,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
@@ -3288,6 +3292,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;
@@ -3522,14 +3527,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;
@@ -3717,7 +3722,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)
@@ -3740,7 +3745,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);
         }
@@ -3767,7 +3772,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);
         }
@@ -3791,7 +3796,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);
         }
@@ -3817,7 +3822,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);
     }
@@ -3937,6 +3942,9 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
       DrawInfo
         *annotate_info;
 
+      ImageInfo
+        *image_info;
+
       MagickBooleanType
         status;
 
@@ -3952,9 +3960,11 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
       caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
       if (caption_image == (Image *) NULL)
         return((Image *) NULL);
+      image_info=AcquireImageInfo();
       annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
-      text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
+      text=InterpretImageProperties(image_info,(Image *) image,caption,
         exception);
+      image_info=DestroyImageInfo(image_info);
       (void) CloneString(&annotate_info->text,text);
       count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
         &text,exception);
@@ -4169,6 +4179,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);
     }
@@ -4267,7 +4278,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
   if (clone_image == (Image *) NULL)
     return((Image *) NULL);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(clone_image,sRGBColorspace,exception);
+    (void) SetImageColorspace(clone_image,sRGBColorspace,exception);
   (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
     exception);
   border_info.width=(size_t) floor(2.0*sigma+0.5);
@@ -4281,7 +4292,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
   clone_image=DestroyImage(clone_image);
   if (border_image == (Image *) NULL)
     return((Image *) NULL);
-  if (border_image->alpha_trait != BlendPixelTrait)
+  if (border_image->alpha_trait == UndefinedPixelTrait)
     (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
   /*
     Shadow image.
@@ -4312,7 +4323,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
     background_color.alpha_trait=BlendPixelTrait;
     for (x=0; x < (ssize_t) border_image->columns; x++)
     {
-      if (border_image->alpha_trait == BlendPixelTrait)
+      if (border_image->alpha_trait != UndefinedPixelTrait)
         background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
       SetPixelInfoPixel(border_image,&background_color,q);
       q+=GetPixelChannels(border_image);
@@ -4331,7 +4342,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
   border_image=DestroyImage(border_image);
   if (shadow_image == (Image *) NULL)
     return((Image *) NULL);
-  (void) SetPixelChannelMask(shadow_image,channel_mask);
+  SetPixelChannelMask(shadow_image,channel_mask);
   if (shadow_image->page.width == 0)
     shadow_image->page.width=shadow_image->columns;
   if (shadow_image->page.height == 0)
@@ -4481,8 +4492,7 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
   random_image=DestroyImage(random_image);
   if (blur_image == (Image *) NULL)
     return((Image *) NULL);
-  dodge_image=EdgeImage(blur_image,GetOptimalKernelWidth1D(radius,0.5),
-    exception);
+  dodge_image=EdgeImage(blur_image,radius,exception);
   blur_image=DestroyImage(blur_image);
   if (dodge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -4563,7 +4573,7 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(image,sRGBColorspace,exception);
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
   if (image->storage_class == PseudoClass)
     {
       register ssize_t
@@ -4577,11 +4587,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;
       }
     }
   /*
@@ -4624,8 +4632,7 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
       {
         PixelChannel channel=GetPixelChannelChannel(image,i);
         PixelTrait traits=GetPixelChannelTraits(image,channel);
-        if ((traits == UndefinedPixelTrait) ||
-            ((traits & CopyPixelTrait) != 0))
+        if ((traits & UpdatePixelTrait) == 0)
           continue;
         if ((double) q[i] > threshold)
           q[i]=QuantumRange-q[i];
@@ -5105,6 +5112,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;