]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/fx.c
(no commit message)
[imagemagick] / MagickCore / fx.c
index 971524d21842d633911cbf8d48e869bb2f265c1b..707fcb7624f6f6efc96e765c28d65ae88b6b9f22 100644 (file)
 %                   MagickCore Image Special Effects Methods                  %
 %                                                                             %
 %                               Software Design                               %
-%                                 John Cristy                                 %
+%                                    Cristy                                   %
 %                                 October 1996                                %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2012 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(
@@ -200,8 +201,11 @@ MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
     Force right-to-left associativity for unary negation.
   */
   (void) SubstituteString(&fx_info->expression,"-","-1.0*");
+  (void) SubstituteString(&fx_info->expression,"^-1.0*","^-");
+  (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;
@@ -281,8 +285,10 @@ MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
   ssize_t
     y;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
   unsigned long
     key;
+#endif
 
   /*
     Initialize noise image attributes.
@@ -309,10 +315,10 @@ MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
   random_info=AcquireRandomInfoThreadSet();
   image_view=AcquireVirtualCacheView(image,exception);
   noise_view=AcquireAuthenticCacheView(noise_image,exception);
-  key=GetRandomSecretKey(random_info[0]);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
+  key=GetRandomSecretKey(random_info[0]);
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,key == ~0UL)
+    magick_threads(image,noise_image,image->rows,key == ~0UL)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -346,28 +352,16 @@ MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
-        {
-          p+=GetPixelChannels(image);
-          q+=GetPixelChannels(noise_image);
-          continue;
-        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          noise_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        noise_traits=GetPixelChannelMapTraits(noise_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait noise_traits=GetPixelChannelTraits(noise_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (noise_traits == UndefinedPixelTrait))
           continue;
-        if ((noise_traits & CopyPixelTrait) != 0)
+        if (((noise_traits & CopyPixelTrait) != 0) ||
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(noise_image,channel,p[i],q);
             continue;
@@ -479,7 +473,7 @@ MagickExport Image *BlueShiftImage(const Image *image,const double factor,
   shift_view=AcquireAuthenticCacheView(shift_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,shift_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -607,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);
-  (void) SetImageType(clone_image,GrayscaleType,exception);
-  edge_image=EdgeImage(clone_image,radius,sigma,exception);
+  edge_image=EdgeImage(clone_image,radius,exception);
   clone_image=DestroyImage(clone_image);
   if (edge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -618,7 +611,7 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius,
     return((Image *) NULL);
   (void) NormalizeImage(charcoal_image,exception);
   (void) NegateImage(charcoal_image,MagickFalse,exception);
-  (void) SetImageType(charcoal_image,GrayscaleType,exception);
+  (void) GrayscaleImage(charcoal_image,image->intensity,exception);
   return(charcoal_image);
 }
 \f
@@ -660,7 +653,7 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
 {
 #define ColorizeImageTag  "Colorize/Image"
 #define Colorize(pixel,blend_percentage,colorize)  \
-  (pixel)=((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0;
+  (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
 
   CacheView
     *colorize_view,
@@ -705,11 +698,11 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
       colorize_image=DestroyImage(colorize_image);
       return((Image *) NULL);
     }
-  if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+  if ((IsGrayColorspace(image->colorspace) != MagickFalse) ||
       (IsPixelInfoGray(colorize) != MagickFalse))
     (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
-  if ((colorize_image->matte == MagickFalse) &&
-      (colorize->matte != MagickFalse))
+  if ((colorize_image->alpha_trait != BlendPixelTrait) &&
+      (colorize->alpha_trait == BlendPixelTrait))
     (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
   if (blend == (const char *) NULL)
     return(colorize_image);
@@ -742,25 +735,22 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,colorize_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     MagickBooleanType
       sync;
 
-    PixelInfo
-      pixel;
-
     register const Quantum
       *restrict p;
 
-    register ssize_t
-      x;
-
     register Quantum
       *restrict q;
 
+    register ssize_t
+      x;
+
     if (status == MagickFalse)
       continue;
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
@@ -771,22 +761,30 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
         status=MagickFalse;
         continue;
       }
-    GetPixelInfo(colorize_image,&pixel);
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if (GetPixelMask(colorize_image,q) != 0)
-        {
-          p+=GetPixelChannels(image);
-          q+=GetPixelChannels(colorize_image);
+      register ssize_t
+        i;
+
+      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      {
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait colorize_traits=GetPixelChannelTraits(colorize_image,
+          channel);
+        if ((traits == UndefinedPixelTrait) ||
+            (colorize_traits == UndefinedPixelTrait))
           continue;
-        }
-      GetPixelInfoPixel(image,p,&pixel);
-      Colorize(pixel.red,blend_percentage.red,colorize->red);
-      Colorize(pixel.green,blend_percentage.green,colorize->green);
-      Colorize(pixel.blue,blend_percentage.blue,colorize->blue);
-      Colorize(pixel.black,blend_percentage.black,colorize->black);
-      Colorize(pixel.alpha,blend_percentage.alpha,colorize->alpha);
-      SetPixelInfoPixel(colorize_image,&pixel,q);
+        if (((colorize_traits & CopyPixelTrait) != 0) ||
+            (GetPixelReadMask(image,p) == 0))
+          {
+            SetPixelChannel(colorize_image,channel,p[i],q);
+            continue;
+          }
+        SetPixelChannel(colorize_image,channel,ClampToQuantum(Colorize(p[i],
+          GetPixelInfoChannel(&blend_percentage,channel),GetPixelInfoChannel(
+          colorize,channel))),q);
+      }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(colorize_image);
     }
@@ -949,7 +947,7 @@ MagickExport Image *ColorMatrixImage(const Image *image,
   color_view=AcquireAuthenticCacheView(color_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,color_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -988,14 +986,14 @@ MagickExport Image *ColorMatrixImage(const Image *image,
       height=color_matrix->height > 6 ? 6UL : color_matrix->height;
       for (v=0; v < (ssize_t) height; v++)
       {
-        MagickRealType
+        double
           sum;
 
         sum=ColorMatrix[v][0]*GetPixelRed(image,p)+ColorMatrix[v][1]*
           GetPixelGreen(image,p)+ColorMatrix[v][2]*GetPixelBlue(image,p);
         if (image->colorspace == CMYKColorspace)
           sum+=ColorMatrix[v][3]*GetPixelBlack(image,p);
-        if (image->matte != MagickFalse)
+        if (image->alpha_trait == BlendPixelTrait)
           sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
         sum+=QuantumRange*ColorMatrix[v][5];
         switch (v)
@@ -1090,11 +1088,11 @@ MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
 %
 %  The format of the FxEvaluateExpression method is:
 %
-%      MagickRealType FxEvaluateChannelExpression(FxInfo *fx_info,
+%      double FxEvaluateChannelExpression(FxInfo *fx_info,
 %        const PixelChannel channel,const ssize_t x,const ssize_t y,
-%        MagickRealType *alpha,Exceptioninfo *exception)
-%      MagickRealType FxEvaluateExpression(FxInfo *fx_info,
-%        MagickRealType *alpha,Exceptioninfo *exception)
+%        double *alpha,Exceptioninfo *exception)
+%      double FxEvaluateExpression(FxInfo *fx_info,
+%        double *alpha,Exceptioninfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -1124,9 +1122,12 @@ static inline double MagickMin(const double x,const double y)
   return(y);
 }
 
-static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
+static double FxChannelStatistics(FxInfo *fx_info,Image *image,
   PixelChannel channel,const char *symbol,ExceptionInfo *exception)
 {
+  ChannelType
+    channel_mask;
+
   char
     key[MaxTextExtent],
     statistic[MaxTextExtent];
@@ -1137,24 +1138,30 @@ static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
   register const char
     *p;
 
+  channel_mask=UndefinedChannel;
   for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
   if (*p == '.')
-    switch (*++p)  /* e.g. depth.r */
     {
-      case 'r': channel=RedPixelChannel; break;
-      case 'g': channel=GreenPixelChannel; break;
-      case 'b': channel=BluePixelChannel; break;
-      case 'c': channel=CyanPixelChannel; break;
-      case 'm': channel=MagentaPixelChannel; break;
-      case 'y': channel=YellowPixelChannel; break;
-      case 'k': channel=BlackPixelChannel; break;
-      default: break;
+      ssize_t
+        option;
+
+      option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1);
+      if (option >= 0)
+        {
+          channel=(PixelChannel) option;
+          channel_mask=(ChannelType) (channel_mask | (1 << channel));
+          SetPixelChannelMask(image,channel_mask);
+        }
     }
   (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
     (double) channel,symbol);
   value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
   if (value != (const char *) NULL)
-    return(QuantumScale*StringToDouble(value,(char **) NULL));
+    {
+      if (channel_mask != UndefinedChannel)
+        SetPixelChannelMask(image,channel_mask);
+      return(QuantumScale*StringToDouble(value,(char **) NULL));
+    }
   (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
   if (LocaleNCompare(symbol,"depth",5) == 0)
     {
@@ -1219,14 +1226,16 @@ static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
       (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
         standard_deviation);
     }
+  if (channel_mask != UndefinedChannel)
+    SetPixelChannelMask(image,channel_mask);
   (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
     ConstantString(statistic));
   return(QuantumScale*StringToDouble(statistic,(char **) NULL));
 }
 
-static MagickRealType
+static double
   FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
-    const ssize_t,const char *,MagickRealType *,ExceptionInfo *);
+    const ssize_t,const char *,double *,ExceptionInfo *);
 
 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
 {
@@ -1258,11 +1267,11 @@ static inline const char *FxSubexpression(const char *expression,
   }
   if (*subexpression == '\0')
     (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-      "UnbalancedParenthesis","'%s'",expression);
+      "UnbalancedParenthesis","`%s'",expression);
   return(subexpression);
 }
 
-static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
+static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   const ssize_t x,const ssize_t y,const char *expression,
   ExceptionInfo *exception)
 {
@@ -1281,7 +1290,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   PixelInfo
     pixel;
 
-  MagickRealType
+  double
     alpha,
     beta;
 
@@ -1300,7 +1309,7 @@ static MagickRealType 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)
         {
@@ -1342,7 +1351,7 @@ static MagickRealType 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 == '{')
@@ -1406,15 +1415,15 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   if (image == (Image *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "NoSuchImage","'%s'",expression);
+        "NoSuchImage","`%s'",expression);
       return(0.0);
     }
   GetPixelInfo(image,&pixel);
   (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
@@ -1473,7 +1482,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           if (image->colorspace != CMYKColorspace)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                ImageError,"ColorSeparatedImageRequired","'%s'",
+                ImageError,"ColorSeparatedImageRequired","`%s'",
                 image->filename);
               return(0.0);
             }
@@ -1481,12 +1490,12 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
         }
         case AlphaPixelChannel:
         {
-          MagickRealType
+          double
             alpha;
 
-          if (pixel.matte == MagickFalse)
+          if (pixel.alpha_trait != BlendPixelTrait)
             return(1.0);
-          alpha=(MagickRealType) (QuantumScale*pixel.alpha);
+          alpha=(double) (QuantumScale*pixel.alpha);
           return(alpha);
         }
         case IndexPixelChannel:
@@ -1499,7 +1508,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           break;
       }
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "UnableToParseExpression","'%s'",p);
+        "UnableToParseExpression","`%s'",p);
       return(0.0);
     }
   switch (*symbol)
@@ -1508,7 +1517,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'a':
     {
       if (LocaleCompare(symbol,"a") == 0)
-        return((MagickRealType) (QuantumScale*pixel.alpha));
+        return((double) (QuantumScale*pixel.alpha));
       break;
     }
     case 'B':
@@ -1601,7 +1610,6 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             default:
               return(0.0);
           }
-          return(0.0);
         }
       if (LocaleCompare(symbol,"c") == 0)
         return(QuantumScale*pixel.red);
@@ -1631,7 +1639,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           if (image->colorspace != CMYKColorspace)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"ColorSeparatedImageRequired","'%s'",
+                OptionError,"ColorSeparatedImageRequired","`%s'",
                 image->filename);
               return(0.0);
             }
@@ -1643,7 +1651,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'h':
     {
       if (LocaleCompare(symbol,"h") == 0)
-        return((MagickRealType) image->rows);
+        return((double) image->rows);
       if (LocaleCompare(symbol,"hue") == 0)
         {
           double
@@ -1675,14 +1683,14 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
       if (LocaleCompare(symbol,"intensity") == 0)
         return(QuantumScale*GetPixelInfoIntensity(&pixel));
       if (LocaleCompare(symbol,"i") == 0)
-        return((MagickRealType) x);
+        return((double) x);
       break;
     }
     case 'J':
     case 'j':
     {
       if (LocaleCompare(symbol,"j") == 0)
-        return((MagickRealType) y);
+        return((double) y);
       break;
     }
     case 'L':
@@ -1699,12 +1707,20 @@ static MagickRealType 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.2126*pixel.red+0.7152*pixel.green+0.0722*pixel.blue;
+          luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
           return(QuantumScale*luminence);
         }
       break;
@@ -1726,7 +1742,7 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'n':
     {
       if (LocaleCompare(symbol,"n") == 0)
-        return((MagickRealType) GetImageListLength(fx_info->images));
+        return((double) GetImageListLength(fx_info->images));
       break;
     }
     case 'O':
@@ -1740,13 +1756,13 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 'p':
     {
       if (LocaleCompare(symbol,"page.height") == 0)
-        return((MagickRealType) image->page.height);
+        return((double) image->page.height);
       if (LocaleCompare(symbol,"page.width") == 0)
-        return((MagickRealType) image->page.width);
+        return((double) image->page.width);
       if (LocaleCompare(symbol,"page.x") == 0)
-        return((MagickRealType) image->page.x);
+        return((double) image->page.x);
       if (LocaleCompare(symbol,"page.y") == 0)
-        return((MagickRealType) image->page.y);
+        return((double) image->page.y);
       break;
     }
     case 'R':
@@ -1784,14 +1800,14 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     case 't':
     {
       if (LocaleCompare(symbol,"t") == 0)
-        return((MagickRealType) GetImageIndexInList(fx_info->images));
+        return((double) GetImageIndexInList(fx_info->images));
       break;
     }
     case 'W':
     case 'w':
     {
       if (LocaleCompare(symbol,"w") == 0)
-        return((MagickRealType) image->columns);
+        return((double) image->columns);
       break;
     }
     case 'Y':
@@ -1806,10 +1822,10 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     {
       if (LocaleCompare(symbol,"z") == 0)
         {
-          MagickRealType
+          double
             depth;
 
-          depth=(MagickRealType) GetImageDepth(image,fx_info->exception);
+          depth=(double) GetImageDepth(image,fx_info->exception);
           return(depth);
         }
       break;
@@ -1819,9 +1835,9 @@ static MagickRealType FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   }
   value=(const char *) GetValueFromSplayTree(fx_info->symbols,symbol);
   if (value != (const char *) NULL)
-    return((MagickRealType) StringToDouble(value,(char **) NULL));
+    return((double) StringToDouble(value,(char **) NULL));
   (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-    "UnableToParseExpression","'%s'",symbol);
+    "UnableToParseExpression","`%s'",symbol);
   return(0.0);
 }
 
@@ -1870,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;
@@ -1901,6 +1917,11 @@ static const char *FxOperatorPrecedence(const char *expression,
             break;
           }
 #endif
+        if (LocaleNCompare(expression,"atan2",5) == 0)
+          {
+            expression+=5;
+            break;
+          }
         break;
       }
       case 'E':
@@ -1955,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;
         }
@@ -2076,15 +2097,15 @@ static const char *FxOperatorPrecedence(const char *expression,
   return(subexpression);
 }
 
-static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
+static double FxEvaluateSubexpression(FxInfo *fx_info,
   const PixelChannel channel,const ssize_t x,const ssize_t y,
-  const char *expression,MagickRealType *beta,ExceptionInfo *exception)
+  const char *expression,double *beta,ExceptionInfo *exception)
 {
   char
     *q,
     subexpression[MaxTextExtent];
 
-  MagickRealType
+  double
     alpha,
     gamma;
 
@@ -2094,12 +2115,12 @@ static MagickRealType 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')
     {
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "MissingExpression","'%s'",expression);
+        "MissingExpression","`%s'",expression);
       return(0.0);
     }
   *subexpression='\0';
@@ -2115,7 +2136,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         case '~':
         {
           *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(MagickRealType) (~(size_t) *beta);
+          *beta=(double) (~(size_t) *beta);
           return(*beta);
         }
         case '!':
@@ -2142,7 +2163,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
             {
               if (exception->severity == UndefinedException)
                 (void) ThrowMagickException(exception,GetMagickModule(),
-                  OptionError,"DivideByZero","'%s'",expression);
+                  OptionError,"DivideByZero","`%s'",expression);
               return(0.0);
             }
           return(alpha/(*beta));
@@ -2154,7 +2175,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
           if (*beta == 0.0)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"DivideByZero","'%s'",expression);
+                OptionError,"DivideByZero","`%s'",expression);
               return(0.0);
             }
           return(fmod((double) alpha,(double) *beta));
@@ -2172,13 +2193,13 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         case LeftShiftOperator:
         {
           gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(MagickRealType) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
+          *beta=(double) ((size_t) (alpha+0.5) << (size_t) (gamma+0.5));
           return(*beta);
         }
         case RightShiftOperator:
         {
           gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(MagickRealType) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
+          *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
           return(*beta);
         }
         case '<':
@@ -2204,23 +2225,23 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         case EqualOperator:
         {
           *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          return(fabs(alpha-(*beta)) <= MagickEpsilon ? 1.0 : 0.0);
+          return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
         }
         case NotEqualOperator:
         {
           *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          return(fabs(alpha-(*beta)) > MagickEpsilon ? 1.0 : 0.0);
+          return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0);
         }
         case '&':
         {
           gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(MagickRealType) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
+          *beta=(double) ((size_t) (alpha+0.5) & (size_t) (gamma+0.5));
           return(*beta);
         }
         case '|':
         {
           gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(MagickRealType) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
+          *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
           return(*beta);
         }
         case LogicalAndOperator:
@@ -2237,7 +2258,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         }
         case '?':
         {
-          MagickRealType
+          double
             gamma;
 
           (void) CopyMagickString(subexpression,++p,MaxTextExtent);
@@ -2246,10 +2267,10 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
           if (q == (char *) NULL)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"UnableToParseExpression","'%s'",subexpression);
+                OptionError,"UnableToParseExpression","`%s'",subexpression);
               return(0.0);
             }
-          if (fabs((double) alpha) > MagickEpsilon)
+          if (fabs((double) alpha) >= MagickEpsilon)
             gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
           else
             gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
@@ -2266,7 +2287,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
           if (*q != '\0')
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"UnableToParseExpression","'%s'",subexpression);
+                OptionError,"UnableToParseExpression","`%s'",subexpression);
               return(0.0);
             }
           ClearMagickException(exception);
@@ -2322,7 +2343,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
     {
       gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
         exception);
-      return((MagickRealType) (~(size_t) (gamma+0.5)));
+      return((double) (~(size_t) (gamma+0.5)));
     }
     case 'A':
     case 'a':
@@ -2331,21 +2352,21 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) fabs((double) alpha));
+          return((double) fabs((double) alpha));
         }
 #if defined(MAGICKCORE_HAVE_ACOSH)
       if (LocaleNCompare(expression,"acosh",5) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) acosh((double) alpha));
+          return((double) acosh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"acos",4) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) acos((double) alpha));
+          return((double) acos((double) alpha));
         }
 #if defined(MAGICKCORE_HAVE_J1)
       if (LocaleNCompare(expression,"airy",4) == 0)
@@ -2363,14 +2384,14 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) asinh((double) alpha));
+          return((double) asinh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"asin",4) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) asin((double) alpha));
+          return((double) asin((double) alpha));
         }
       if (LocaleNCompare(expression,"alt",3) == 0)
         {
@@ -2382,21 +2403,21 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) atan2((double) alpha,(double) *beta));
+          return((double) atan2((double) alpha,(double) *beta));
         }
 #if defined(MAGICKCORE_HAVE_ATANH)
       if (LocaleNCompare(expression,"atanh",5) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) atanh((double) alpha));
+          return((double) atanh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"atan",4) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) atan((double) alpha));
+          return((double) atan((double) alpha));
         }
       if (LocaleCompare(expression,"a") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2416,19 +2437,19 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) ceil((double) alpha));
+          return((double) ceil((double) alpha));
         }
       if (LocaleNCompare(expression,"cosh",4) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) cosh((double) alpha));
+          return((double) cosh((double) alpha));
         }
       if (LocaleNCompare(expression,"cos",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) cos((double) alpha));
+          return((double) cos((double) alpha));
         }
       if (LocaleCompare(expression,"c") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2476,7 +2497,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) (alpha/(*beta*(alpha-1.0)+1.0)));
+          return((double) (alpha/(*beta*(alpha-1.0)+1.0)));
         }
       break;
     }
@@ -2484,15 +2505,15 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
     case 'e':
     {
       if (LocaleCompare(expression,"epsilon") == 0)
-        return((MagickRealType) MagickEpsilon);
+        return((double) MagickEpsilon);
       if (LocaleNCompare(expression,"exp",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) exp((double) alpha));
+          return((double) exp((double) alpha));
         }
       if (LocaleCompare(expression,"e") == 0)
-        return((MagickRealType) 2.7182818284590452354);
+        return((double) 2.7182818284590452354);
       break;
     }
     case 'F':
@@ -2502,7 +2523,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) floor((double) alpha));
+          return((double) floor((double) alpha));
         }
       break;
     }
@@ -2514,7 +2535,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
           gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
-          return((MagickRealType) gamma);
+          return((double) gamma);
         }
       if (LocaleNCompare(expression,"gcd",3) == 0)
         {
@@ -2525,7 +2546,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
             exception);
           gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
             0.5));
-          return((MagickRealType) gcd);
+          return((double) gcd);
         }
       if (LocaleCompare(expression,"g") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2542,7 +2563,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) hypot((double) alpha,(double) *beta));
+          return((double) hypot((double) alpha,(double) *beta));
         }
       break;
     }
@@ -2562,14 +2583,14 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) floor(alpha));
+          return((double) floor(alpha));
         }
 #if defined(MAGICKCORE_HAVE_ISNAN)
       if (LocaleNCompare(expression,"isnan",5) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) !!isnan((double) alpha));
+          return((double) !!isnan((double) alpha));
         }
 #endif
       if (LocaleCompare(expression,"i") == 0)
@@ -2586,7 +2607,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
             exception);
-          return((MagickRealType) j0((double) alpha));
+          return((double) j0((double) alpha));
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
@@ -2594,7 +2615,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
             exception);
-          return((MagickRealType) j1((double) alpha));
+          return((double) j1((double) alpha));
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
@@ -2604,8 +2625,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
             exception);
           if (alpha == 0.0)
             return(1.0);
-          gamma=(MagickRealType) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
-            alpha));
+          gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha));
           return(gamma);
         }
 #endif
@@ -2618,19 +2638,19 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
             exception);
-          return((MagickRealType) log((double) alpha));
+          return((double) log((double) alpha));
         }
       if (LocaleNCompare(expression,"logtwo",6) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
             exception);
-          return((MagickRealType) log10((double) alpha))/log10(2.0);
+          return((double) log10((double) alpha))/log10(2.0);
         }
       if (LocaleNCompare(expression,"log",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) log10((double) alpha));
+          return((double) log10((double) alpha));
         }
       if (LocaleCompare(expression,"lightness") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2640,7 +2660,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
     case 'm':
     {
       if (LocaleCompare(expression,"MaxRGB") == 0)
-        return((MagickRealType) QuantumRange);
+        return((double) QuantumRange);
       if (LocaleNCompare(expression,"maxima",6) == 0)
         break;
       if (LocaleNCompare(expression,"max",3) == 0)
@@ -2675,7 +2695,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) (alpha < MagickEpsilon));
+          return((double) (alpha < MagickEpsilon));
         }
       if (LocaleCompare(expression,"n") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2694,14 +2714,14 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
     case 'p':
     {
       if (LocaleCompare(expression,"phi") == 0)
-        return((MagickRealType) MagickPHI);
+        return((double) MagickPHI);
       if (LocaleCompare(expression,"pi") == 0)
-        return((MagickRealType) MagickPI);
+        return((double) MagickPI);
       if (LocaleNCompare(expression,"pow",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) pow((double) alpha,(double) *beta));
+          return((double) pow((double) alpha,(double) *beta));
         }
       if (LocaleCompare(expression,"p") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2711,21 +2731,21 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
     case 'q':
     {
       if (LocaleCompare(expression,"QuantumRange") == 0)
-        return((MagickRealType) QuantumRange);
+        return((double) QuantumRange);
       if (LocaleCompare(expression,"QuantumScale") == 0)
-        return((MagickRealType) QuantumScale);
+        return((double) QuantumScale);
       break;
     }
     case 'R':
     case 'r':
     {
       if (LocaleNCompare(expression,"rand",4) == 0)
-        return((MagickRealType) GetPseudoRandomValue(fx_info->random_info));
+        return((double) GetPseudoRandomValue(fx_info->random_info));
       if (LocaleNCompare(expression,"round",5) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
-          return((MagickRealType) floor((double) alpha+0.5));
+          return((double) floor((double) alpha+0.5));
         }
       if (LocaleCompare(expression,"r") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2748,7 +2768,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
             exception);
           if (alpha == 0)
             return(1.0);
-          gamma=(MagickRealType) (sin((double) (MagickPI*alpha))/
+          gamma=(double) (sin((double) (MagickPI*alpha))/
             (MagickPI*alpha));
           return(gamma);
         }
@@ -2756,25 +2776,25 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) sinh((double) alpha));
+          return((double) sinh((double) alpha));
         }
       if (LocaleNCompare(expression,"sin",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) sin((double) alpha));
+          return((double) sin((double) alpha));
         }
       if (LocaleNCompare(expression,"sqrt",4) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) sqrt((double) alpha));
+          return((double) sqrt((double) alpha));
         }
       if (LocaleNCompare(expression,"squish",6) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
             exception);
-          return((MagickRealType) (1.0/(1.0+exp((double) (-alpha)))));
+          return((double) (1.0/(1.0+exp((double) (-alpha)))));
         }
       if (LocaleCompare(expression,"s") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2787,13 +2807,13 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
             exception);
-          return((MagickRealType) tanh((double) alpha));
+          return((double) tanh((double) alpha));
         }
       if (LocaleNCompare(expression,"tan",3) == 0)
         {
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
             exception);
-          return((MagickRealType) tan((double) alpha));
+          return((double) tan((double) alpha));
         }
       if (LocaleCompare(expression,"Transparent") == 0)
         return(0.0);
@@ -2802,8 +2822,8 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
           alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
             exception);
           if (alpha >= 0.0)
-            return((MagickRealType) floor((double) alpha));
-          return((MagickRealType) ceil((double) alpha));
+            return((double) floor((double) alpha));
+          return((double) ceil((double) alpha));
         }
       if (LocaleCompare(expression,"t") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2833,7 +2853,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
             alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
               exception);
           } while (fabs((double) alpha) >= MagickEpsilon);
-          return((MagickRealType) *beta);
+          return((double) *beta);
         }
       if (LocaleCompare(expression,"w") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
@@ -2864,7 +2884,7 @@ static MagickRealType FxEvaluateSubexpression(FxInfo *fx_info,
 }
 
 MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
-  MagickRealType *alpha,ExceptionInfo *exception)
+  double *alpha,ExceptionInfo *exception)
 {
   MagickBooleanType
     status;
@@ -2875,7 +2895,7 @@ MagickPrivate MagickBooleanType FxEvaluateExpression(FxInfo *fx_info,
 }
 
 MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
-  MagickRealType *alpha,ExceptionInfo *exception)
+  double *alpha,ExceptionInfo *exception)
 {
   FILE
     *file;
@@ -2893,9 +2913,9 @@ MagickExport MagickBooleanType FxPreprocessExpression(FxInfo *fx_info,
 
 MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
   const PixelChannel channel,const ssize_t x,const ssize_t y,
-  MagickRealType *alpha,ExceptionInfo *exception)
+  double *alpha,ExceptionInfo *exception)
 {
-  MagickRealType
+  double
     beta;
 
   beta=0.0;
@@ -2954,7 +2974,7 @@ static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
   FxInfo
     **fx_info;
 
-  MagickRealType
+  double
     alpha;
 
   register ssize_t
@@ -2963,23 +2983,34 @@ static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
   size_t
     number_threads;
 
-  number_threads=GetOpenMPMaximumThreads();
+  number_threads=(size_t) GetMagickResourceLimit(ThreadResource);
   fx_info=(FxInfo **) AcquireQuantumMemory(number_threads,sizeof(*fx_info));
   if (fx_info == (FxInfo **) NULL)
-    return((FxInfo **) NULL);
+    {
+      (void) ThrowMagickException(exception,GetMagickModule(),
+        ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
+      return((FxInfo **) NULL);
+    }
   (void) ResetMagickMemory(fx_info,0,number_threads*sizeof(*fx_info));
   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
+      status;
+
     fx_info[i]=AcquireFxInfo(image,fx_expression,exception);
     if (fx_info[i] == (FxInfo *) NULL)
-      return(DestroyFxThreadSet(fx_info));
-    (void) FxPreprocessExpression(fx_info[i],&alpha,fx_info[i]->exception);
+      break;
+    status=FxPreprocessExpression(fx_info[i],&alpha,exception);
+    if (status == MagickFalse)
+      break;
   }
   fx_expression=DestroyString(fx_expression);
+  if (i < (ssize_t) number_threads)
+    fx_info=DestroyFxThreadSet(fx_info);
   return(fx_info);
 }
 
@@ -3004,9 +3035,6 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
   MagickOffsetType
     progress;
 
-  MagickRealType
-    alpha;
-
   ssize_t
     y;
 
@@ -3014,25 +3042,19 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  fx_info=AcquireFxThreadSet(image,expression,exception);
+  if (fx_info == (FxInfo **) NULL)
+    return((Image *) NULL);
   fx_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (fx_image == (Image *) NULL)
-    return((Image *) NULL);
-  if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
     {
-      fx_image=DestroyImage(fx_image);
+      fx_info=DestroyFxThreadSet(fx_info);
       return((Image *) NULL);
     }
-  fx_info=AcquireFxThreadSet(image,expression,exception);
-  if (fx_info == (FxInfo **) NULL)
-    {
-      fx_image=DestroyImage(fx_image);
-      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-    }
-  status=FxPreprocessExpression(fx_info[0],&alpha,exception);
-  if (status == MagickFalse)
+  if (SetImageStorageClass(fx_image,DirectClass,exception) == MagickFalse)
     {
-      fx_image=DestroyImage(fx_image);
       fx_info=DestroyFxThreadSet(fx_info);
+      fx_image=DestroyImage(fx_image);
       return((Image *) NULL);
     }
   /*
@@ -3044,7 +3066,7 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
   fx_view=AcquireAuthenticCacheView(fx_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,fx_image,fx_image->rows,1)
 #endif
   for (y=0; y < (ssize_t) fx_image->rows; y++)
   {
@@ -3074,31 +3096,19 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
-        {
-          p+=GetPixelChannels(image);
-          q+=GetPixelChannels(fx_image);
-          continue;
-        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        MagickRealType
+        double
           alpha;
 
-        PixelChannel
-          channel;
-
-        PixelTrait
-          fx_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        fx_traits=GetPixelChannelMapTraits(fx_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait fx_traits=GetPixelChannelTraits(fx_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (fx_traits == UndefinedPixelTrait))
           continue;
-        if ((fx_traits & CopyPixelTrait) != 0)
+        if (((fx_traits & CopyPixelTrait) != 0) ||
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(fx_image,channel,p[i],q);
             continue;
@@ -3106,7 +3116,7 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
         alpha=0.0;
         (void) FxEvaluateChannelExpression(fx_info[id],channel,x,y,&alpha,
           exception);
-        q[i]=ClampToQuantum((MagickRealType) QuantumRange*alpha);
+        q[i]=ClampToQuantum(QuantumRange*alpha);
       }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(fx_image);
@@ -3177,7 +3187,8 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 
   CacheView
     *image_view,
-    *implode_view;
+    *implode_view,
+    *interpolate_view;
 
   Image
     *implode_image;
@@ -3188,7 +3199,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
   MagickOffsetType
     progress;
 
-  MagickRealType
+  double
     radius;
 
   PointInfo
@@ -3217,7 +3228,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       return((Image *) NULL);
     }
   if (implode_image->background_color.alpha != OpaqueAlpha)
-    implode_image->matte=MagickTrue;
+    implode_image->alpha_trait=BlendPixelTrait;
   /*
     Compute scaling factor.
   */
@@ -3240,14 +3251,15 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
   status=MagickTrue;
   progress=0;
   image_view=AcquireVirtualCacheView(image,exception);
+  interpolate_view=AcquireVirtualCacheView(image,exception);
   implode_view=AcquireAuthenticCacheView(implode_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,implode_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
-    MagickRealType
+    double
       distance;
 
     PointInfo
@@ -3264,7 +3276,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 
     if (status == MagickFalse)
       continue;
-    p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
     q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
       exception);
     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
@@ -3281,8 +3293,9 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       /*
         Determine if the pixel is within an ellipse.
       */
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(implode_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(implode_image);
           continue;
@@ -3292,16 +3305,10 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       if (distance >= (radius*radius))
         for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
         {
-          PixelChannel
-            channel;
-
-          PixelTrait
-            implode_traits,
-            traits;
-
-          channel=GetPixelChannelMapChannel(image,i);
-          traits=GetPixelChannelMapTraits(image,channel);
-          implode_traits=GetPixelChannelMapTraits(implode_image,channel);
+          PixelChannel channel=GetPixelChannelChannel(image,i);
+          PixelTrait traits=GetPixelChannelTraits(image,channel);
+          PixelTrait implode_traits=GetPixelChannelTraits(implode_image,
+            channel);
           if ((traits == UndefinedPixelTrait) ||
               (implode_traits == UndefinedPixelTrait))
             continue;
@@ -3319,9 +3326,9 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
           if (distance > 0.0)
             factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
               2)),-amount);
-          status=InterpolatePixelChannels(image,image_view,implode_image,method,
-            (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
-            scale.y+center.y),q,exception);
+          status=InterpolatePixelChannels(image,interpolate_view,implode_image,
+            method,(double) (factor*delta.x/scale.x+center.x),(double) (factor*
+            delta.y/scale.y+center.y),q,exception);
         }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(implode_image);
@@ -3342,6 +3349,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       }
   }
   implode_view=DestroyCacheView(implode_view);
+  interpolate_view=DestroyCacheView(interpolate_view);
   image_view=DestroyCacheView(image_view);
   if (status == MagickFalse)
     implode_image=DestroyImage(implode_image);
@@ -3378,11 +3386,15 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport Image *MorphImages(const Image *image,
-  const size_t number_frames,ExceptionInfo *exception)
+MagickExport Image *MorphImages(const Image *image,const size_t number_frames,
+  ExceptionInfo *exception)
 {
 #define MorphImageTag  "Morph/Image"
 
+  double
+    alpha,
+    beta;
+
   Image
     *morph_image,
     *morph_images;
@@ -3393,10 +3405,6 @@ MagickExport Image *MorphImages(const Image *image,
   MagickOffsetType
     scene;
 
-  MagickRealType
-    alpha,
-    beta;
-
   register const Image
     *next;
 
@@ -3459,7 +3467,7 @@ MagickExport Image *MorphImages(const Image *image,
         *image_view,
         *morph_view;
 
-      beta=(MagickRealType) (i+1.0)/(MagickRealType) (number_frames+1.0);
+      beta=(double) (i+1.0)/(double) (number_frames+1.0);
       alpha=1.0-beta;
       morph_image=ResizeImage(next,(size_t) (alpha*next->columns+beta*
         GetNextImageInList(next)->columns+0.5),(size_t) (alpha*next->rows+beta*
@@ -3488,7 +3496,7 @@ MagickExport Image *MorphImages(const Image *image,
       morph_view=AcquireAuthenticCacheView(morph_images,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
       #pragma omp parallel for schedule(static,4) shared(status) \
-        dynamic_number_threads(image->columns,image->rows,1)
+        magick_threads(morph_image,morph_image,morph_image->rows,1)
 #endif
       for (y=0; y < (ssize_t) morph_images->rows; y++)
       {
@@ -3520,28 +3528,16 @@ MagickExport Image *MorphImages(const Image *image,
           register ssize_t
             i;
 
-          if (GetPixelMask(image,p) != 0)
-            {
-              p+=GetPixelChannels(image);
-              q+=GetPixelChannels(morph_image);
-              continue;
-            }
           for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              morph_traits,
-              traits;
-
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
-            morph_traits=GetPixelChannelMapTraits(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)
+            if (((morph_traits & CopyPixelTrait) != 0) ||
+                (GetPixelReadMask(morph_images,p) == 0))
               {
                 SetPixelChannel(morph_image,channel,p[i],q);
                 continue;
@@ -3631,7 +3627,7 @@ MagickExport Image *MorphImages(const Image *image,
 */
 
 static inline Quantum PlasmaPixel(RandomInfo *random_info,
-  const MagickRealType pixel,const MagickRealType noise)
+  const double pixel,const double noise)
 {
   Quantum
     plasma;
@@ -3646,15 +3642,9 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
   const SegmentInfo *segment,size_t attenuate,size_t depth,
   ExceptionInfo *exception)
 {
-  MagickRealType
+  double
     plasma;
 
-  PixelChannel
-    channel;
-
-  PixelTrait
-    traits;
-
   register const Quantum
     *restrict u,
     *restrict v;
@@ -3714,7 +3704,7 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
   /*
     Average pixels and apply plasma.
   */
-  plasma=(MagickRealType) QuantumRange/(2.0*attenuate);
+  plasma=(double) QuantumRange/(2.0*attenuate);
   if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
     {
       /*
@@ -3731,11 +3721,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         return(MagickTrue);
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        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)
@@ -3754,11 +3744,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            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);
         }
@@ -3781,11 +3771,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            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);
         }
@@ -3805,11 +3795,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            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);
         }
@@ -3831,11 +3821,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         return(MagickTrue);
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        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);
     }
@@ -3955,6 +3945,9 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
       DrawInfo
         *annotate_info;
 
+      ImageInfo
+        *image_info;
+
       MagickBooleanType
         status;
 
@@ -3970,9 +3963,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);
@@ -4144,7 +4139,7 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
   sepia_view=AcquireAuthenticCacheView(sepia_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,sepia_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -4169,24 +4164,25 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
       }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      MagickRealType
+      double
         intensity,
         tone;
 
-      intensity=(MagickRealType) GetPixelIntensity(image,p);
-      tone=intensity > threshold ? (MagickRealType) QuantumRange : intensity+
-        (MagickRealType) QuantumRange-threshold;
+      intensity=GetPixelIntensity(image,p);
+      tone=intensity > threshold ? (double) QuantumRange : intensity+
+        (double) QuantumRange-threshold;
       SetPixelRed(sepia_image,ClampToQuantum(tone),q);
-      tone=intensity > (7.0*threshold/6.0) ? (MagickRealType) QuantumRange :
-        intensity+(MagickRealType) QuantumRange-7.0*threshold/6.0;
+      tone=intensity > (7.0*threshold/6.0) ? (double) QuantumRange :
+        intensity+(double) QuantumRange-7.0*threshold/6.0;
       SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
       tone=intensity < (threshold/6.0) ? 0 : intensity-threshold/6.0;
       SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
       tone=threshold/7.0;
-      if ((MagickRealType) GetPixelGreen(image,q) < tone)
+      if ((double) GetPixelGreen(image,q) < tone)
         SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
-      if ((MagickRealType) GetPixelBlue(image,q) < tone)
+      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);
     }
@@ -4285,8 +4281,8 @@ 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) SetImageVirtualPixelMethod(clone_image,EdgeVirtualPixelMethod,
+    (void) SetImageColorspace(clone_image,sRGBColorspace,exception);
+  (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
     exception);
   border_info.width=(size_t) floor(2.0*sigma+0.5);
   border_info.height=(size_t) floor(2.0*sigma+0.5);
@@ -4294,12 +4290,12 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
   border_info.y=0;
   (void) QueryColorCompliance("none",AllCompliance,&clone_image->border_color,
     exception);
-  clone_image->matte=MagickTrue;
+  clone_image->alpha_trait=BlendPixelTrait;
   border_image=BorderImage(clone_image,&border_info,OverCompositeOp,exception);
   clone_image=DestroyImage(clone_image);
   if (border_image == (Image *) NULL)
     return((Image *) NULL);
-  if (border_image->matte == MagickFalse)
+  if (border_image->alpha_trait != BlendPixelTrait)
     (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
   /*
     Shadow image.
@@ -4327,10 +4323,10 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
         continue;
       }
     background_color=border_image->background_color;
-    background_color.matte=MagickTrue;
+    background_color.alpha_trait=BlendPixelTrait;
     for (x=0; x < (ssize_t) border_image->columns; x++)
     {
-      if (border_image->matte != MagickFalse)
+      if (border_image->alpha_trait == BlendPixelTrait)
         background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
       SetPixelInfoPixel(border_image,&background_color,q);
       q+=GetPixelChannels(border_image);
@@ -4344,12 +4340,12 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
       border_image=DestroyImage(border_image);
       return((Image *) NULL);
     }
-  channel_mask=SetPixelChannelMask(border_image,AlphaChannel);
+  channel_mask=SetImageChannelMask(border_image,AlphaChannel);
   shadow_image=BlurImage(border_image,0.0,sigma,exception);
   border_image=DestroyImage(border_image);
   if (shadow_image == (Image *) NULL)
     return((Image *) NULL);
-  (void) SetPixelChannelMapMask(shadow_image,channel_mask);
+  (void) SetPixelChannelMask(shadow_image,channel_mask);
   if (shadow_image->page.width == 0)
     shadow_image->page.width=shadow_image->columns;
   if (shadow_image->page.height == 0)
@@ -4419,8 +4415,10 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
   ssize_t
     y;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
   unsigned long
     key;
+#endif
 
   /*
     Sketch image.
@@ -4431,11 +4429,13 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
     return((Image *) NULL);
   status=MagickTrue;
   random_info=AcquireRandomInfoThreadSet();
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
   key=GetRandomSecretKey(random_info[0]);
+#endif
   random_view=AcquireAuthenticCacheView(random_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image->columns,image->rows,key == ~0UL)
+    magick_threads(random_image,random_image,random_image->rows,key == ~0UL)
 #endif
   for (y=0; y < (ssize_t) random_image->rows; y++)
   {
@@ -4459,13 +4459,13 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
       }
     for (x=0; x < (ssize_t) random_image->columns; x++)
     {
-      MagickRealType
+      double
         value;
 
       register ssize_t
         i;
 
-      if (GetPixelMask(random_image,q) != 0)
+      if (GetPixelReadMask(random_image,q) == 0)
         {
           q+=GetPixelChannels(random_image);
           continue;
@@ -4473,14 +4473,8 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
       value=GetPseudoRandomValue(random_info[id]);
       for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
         if (traits == UndefinedPixelTrait)
           continue;
         q[i]=ClampToQuantum(QuantumRange*value);
@@ -4501,7 +4495,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,radius,1.0,exception);
+  dodge_image=EdgeImage(blur_image,radius,exception);
   blur_image=DestroyImage(blur_image);
   if (dodge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -4581,6 +4575,8 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  if (IsGrayColorspace(image->colorspace) != MagickFalse)
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
   if (image->storage_class == PseudoClass)
     {
       register ssize_t
@@ -4591,14 +4587,12 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
       */
       for (i=0; i < (ssize_t) image->colors; i++)
       {
-        if ((MagickRealType) image->colormap[i].red > threshold)
-          image->colormap[i].red=(Quantum) QuantumRange-image->colormap[i].red;
-        if ((MagickRealType) image->colormap[i].green > threshold)
-          image->colormap[i].green=(Quantum) QuantumRange-
-            image->colormap[i].green;
-        if ((MagickRealType) image->colormap[i].blue > threshold)
-          image->colormap[i].blue=(Quantum) QuantumRange-
-            image->colormap[i].blue;
+        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;
+        if ((double) image->colormap[i].blue > threshold)
+          image->colormap[i].blue=QuantumRange-image->colormap[i].blue;
       }
     }
   /*
@@ -4609,7 +4603,7 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
   image_view=AcquireAuthenticCacheView(image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -4632,25 +4626,19 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
       register ssize_t
         i;
 
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelReadMask(image,q) == 0)
         {
           q+=GetPixelChannels(image);
           continue;
         }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
         if ((traits == UndefinedPixelTrait) ||
             ((traits & CopyPixelTrait) != 0))
           continue;
-        if ((MagickRealType) q[i] > threshold)
+        if ((double) q[i] > threshold)
           q[i]=QuantumRange-q[i];
       }
       q+=GetPixelChannels(image);
@@ -4841,10 +4829,7 @@ MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
   stegano_view=DestroyCacheView(stegano_view);
   watermark_view=DestroyCacheView(watermark_view);
   if (status == MagickFalse)
-    {
-      stegano_image=DestroyImage(stegano_image);
-      return((Image *) NULL);
-    }
+    stegano_image=DestroyImage(stegano_image);
   return(stegano_image);
 }
 \f
@@ -4937,6 +4922,7 @@ MagickExport Image *StereoAnaglyphImage(const Image *left_image,
       stereo_image=DestroyImage(stereo_image);
       return((Image *) NULL);
     }
+  (void) SetImageColorspace(stereo_image,sRGBColorspace,exception);
   /*
     Copy left image to red channel and right image to blue channel.
   */
@@ -4986,10 +4972,7 @@ MagickExport Image *StereoAnaglyphImage(const Image *left_image,
       }
   }
   if (status == MagickFalse)
-    {
-      stereo_image=DestroyImage(stereo_image);
-      return((Image *) NULL);
-    }
+    stereo_image=DestroyImage(stereo_image);
   return(stereo_image);
 }
 \f
@@ -5031,6 +5014,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
   CacheView
     *image_view,
+    *interpolate_view,
     *swirl_view;
 
   Image
@@ -5042,7 +5026,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
   MagickOffsetType
     progress;
 
-  MagickRealType
+  double
     radius;
 
   PointInfo
@@ -5070,7 +5054,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       return((Image *) NULL);
     }
   if (swirl_image->background_color.alpha != OpaqueAlpha)
-    swirl_image->matte=MagickTrue;
+    swirl_image->alpha_trait=BlendPixelTrait;
   /*
     Compute scaling factor.
   */
@@ -5091,14 +5075,15 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
   status=MagickTrue;
   progress=0;
   image_view=AcquireVirtualCacheView(image,exception);
+  interpolate_view=AcquireVirtualCacheView(image,exception);
   swirl_view=AcquireAuthenticCacheView(swirl_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,swirl_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
-    MagickRealType
+    double
       distance;
 
     PointInfo
@@ -5115,7 +5100,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
     if (status == MagickFalse)
       continue;
-    p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
     q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
       exception);
     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
@@ -5129,8 +5114,9 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       /*
         Determine if the pixel is within an ellipse.
       */
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(swirl_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(swirl_image);
           continue;
@@ -5144,16 +5130,9 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              swirl_traits,
-              traits;
-
-            channel=GetPixelChannelMapChannel(image,i);
-            traits=GetPixelChannelMapTraits(image,channel);
-            swirl_traits=GetPixelChannelMapTraits(swirl_image,channel);
+            PixelChannel channel=GetPixelChannelChannel(image,i);
+            PixelTrait traits=GetPixelChannelTraits(image,channel);
+            PixelTrait swirl_traits=GetPixelChannelTraits(swirl_image,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (swirl_traits == UndefinedPixelTrait))
               continue;
@@ -5162,7 +5141,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
         }
       else
         {
-          MagickRealType
+          double
             cosine,
             factor,
             sine;
@@ -5173,8 +5152,8 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
           factor=1.0-sqrt((double) distance)/radius;
           sine=sin((double) (degrees*factor*factor));
           cosine=cos((double) (degrees*factor*factor));
-          status=InterpolatePixelChannels(image,image_view,swirl_image,method,
-            ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
+          status=InterpolatePixelChannels(image,interpolate_view,swirl_image,
+            method,((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
             ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
         }
       p+=GetPixelChannels(image);
@@ -5196,6 +5175,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       }
   }
   swirl_view=DestroyCacheView(swirl_view);
+  interpolate_view=DestroyCacheView(interpolate_view);
   image_view=DestroyCacheView(image_view);
   if (status == MagickFalse)
     swirl_image=DestroyImage(swirl_image);
@@ -5242,6 +5222,9 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
     *image_view,
     *tint_view;
 
+  double
+    intensity;
+
   GeometryInfo
     geometry_info;
 
@@ -5254,9 +5237,6 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   MagickOffsetType
     progress;
 
-  MagickRealType
-    intensity;
-
   PixelInfo
     color_vector;
 
@@ -5283,6 +5263,9 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       tint_image=DestroyImage(tint_image);
       return((Image *) NULL);
     }
+  if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+      (IsPixelInfoGray(tint) == MagickFalse))
+    (void) SetImageColorspace(tint_image,sRGBColorspace,exception);
   if (blend == (const char *) NULL)
     return(tint_image);
   /*
@@ -5293,7 +5276,7 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   color_vector.red=geometry_info.rho;
   color_vector.green=geometry_info.rho;
   color_vector.blue=geometry_info.rho;
-  color_vector.alpha=OpaqueAlpha;
+  color_vector.alpha=(MagickRealType) OpaqueAlpha;
   if ((flags & SigmaValue) != 0)
     color_vector.green=geometry_info.sigma;
   if ((flags & XiValue) != 0)
@@ -5308,17 +5291,12 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       if ((flags & ChiValue) != 0)
         color_vector.alpha=geometry_info.chi;
     }
-  intensity=(MagickRealType) GetPixelInfoIntensity(tint);
-  color_vector.red=(MagickRealType) (color_vector.red*tint->red/100.0-
-    intensity);
-  color_vector.green=(MagickRealType) (color_vector.green*tint->green/100.0-
-    intensity);
-  color_vector.blue=(MagickRealType) (color_vector.blue*tint->blue/100.0-
-    intensity);
-  color_vector.black=(MagickRealType) (color_vector.black*tint->black/100.0-
-    intensity);
-  color_vector.alpha=(MagickRealType) (color_vector.alpha*tint->alpha/100.0-
-    intensity);
+  intensity=(double) GetPixelInfoIntensity(tint);
+  color_vector.red=(double) (color_vector.red*tint->red/100.0-intensity);
+  color_vector.green=(double) (color_vector.green*tint->green/100.0-intensity);
+  color_vector.blue=(double) (color_vector.blue*tint->blue/100.0-intensity);
+  color_vector.black=(double) (color_vector.black*tint->black/100.0-intensity);
+  color_vector.alpha=(double) (color_vector.alpha*tint->alpha/100.0-intensity);
   /*
     Tint image.
   */
@@ -5328,7 +5306,7 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   tint_view=AcquireAuthenticCacheView(tint_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,tint_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -5356,34 +5334,22 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       PixelInfo
         pixel;
 
-      MagickRealType
+      double
         weight;
 
       register ssize_t
         i;
 
-      if (GetPixelMask(image,p) != 0)
-        {
-          p+=GetPixelChannels(image);
-          q+=GetPixelChannels(tint_image);
-          continue;
-        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          tint_traits,
-          traits;
-
-        channel=GetPixelChannelMapChannel(image,i);
-        traits=GetPixelChannelMapTraits(image,channel);
-        tint_traits=GetPixelChannelMapTraits(tint_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait tint_traits=GetPixelChannelTraits(tint_image,channel);
         if ((traits == UndefinedPixelTrait) ||
             (tint_traits == UndefinedPixelTrait))
           continue;
-        if ((tint_traits & CopyPixelTrait) != 0)
+        if (((tint_traits & CopyPixelTrait) != 0) ||
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(tint_image,channel,p[i],q);
             continue;
@@ -5391,17 +5357,17 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       }
       GetPixelInfo(image,&pixel);
       weight=QuantumScale*GetPixelRed(image,p)-0.5;
-      pixel.red=(MagickRealType) GetPixelRed(image,p)+color_vector.red*
-        (1.0-(4.0*(weight*weight)));
+      pixel.red=(double) GetPixelRed(image,p)+color_vector.red*(1.0-(4.0*
+        (weight*weight)));
       weight=QuantumScale*GetPixelGreen(image,p)-0.5;
-      pixel.green=(MagickRealType) GetPixelGreen(image,p)+color_vector.green*
-        (1.0-(4.0*(weight*weight)));
+      pixel.green=(double) GetPixelGreen(image,p)+color_vector.green*(1.0-(4.0*
+        (weight*weight)));
       weight=QuantumScale*GetPixelBlue(image,p)-0.5;
-      pixel.blue=(MagickRealType) GetPixelBlue(image,p)+color_vector.blue*
-        (1.0-(4.0*(weight*weight)));
+      pixel.blue=(double) GetPixelBlue(image,p)+color_vector.blue*(1.0-(4.0*
+        (weight*weight)));
       weight=QuantumScale*GetPixelBlack(image,p)-0.5;
-      pixel.black=(MagickRealType) GetPixelBlack(image,p)+color_vector.black*
-        (1.0-(4.0*(weight*weight)));
+      pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0*
+        (weight*weight)));
       SetPixelInfoPixel(tint_image,&pixel,q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(tint_image);
@@ -5489,7 +5455,7 @@ MagickExport Image *VignetteImage(const Image *image,const double radius,
       canvas_image=DestroyImage(canvas_image);
       return((Image *) NULL);
     }
-  canvas_image->matte=MagickTrue;
+  canvas_image->alpha_trait=BlendPixelTrait;
   oval_image=CloneImage(canvas_image,canvas_image->columns,canvas_image->rows,
     MagickTrue,exception);
   if (oval_image == (Image *) NULL)
@@ -5518,12 +5484,14 @@ MagickExport Image *VignetteImage(const Image *image,const double radius,
       canvas_image=DestroyImage(canvas_image);
       return((Image *) NULL);
     }
-  blur_image->matte=MagickFalse;
+  blur_image->alpha_trait=UndefinedPixelTrait;
   (void) CompositeImage(canvas_image,blur_image,IntensityCompositeOp,MagickTrue,
     0,0,exception);
   blur_image=DestroyImage(blur_image);
   vignette_image=MergeImageLayers(canvas_image,FlattenLayer,exception);
   canvas_image=DestroyImage(canvas_image);
+  if (vignette_image != (Image *) NULL)
+    (void) TransformImageColorspace(vignette_image,image->colorspace,exception);
   return(vignette_image);
 }
 \f
@@ -5579,7 +5547,7 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
   MagickOffsetType
     progress;
 
-  MagickRealType
+  double
     *sine_map;
 
   register ssize_t
@@ -5607,13 +5575,13 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
       return((Image *) NULL);
     }
   if (wave_image->background_color.alpha != OpaqueAlpha)
-    wave_image->matte=MagickTrue;
+    wave_image->alpha_trait=BlendPixelTrait;
   /*
     Allocate sine map.
   */
-  sine_map=(MagickRealType *) AcquireQuantumMemory((size_t) wave_image->columns,
+  sine_map=(double *) AcquireQuantumMemory((size_t) wave_image->columns,
     sizeof(*sine_map));
-  if (sine_map == (MagickRealType *) NULL)
+  if (sine_map == (double *) NULL)
     {
       wave_image=DestroyImage(wave_image);
       ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
@@ -5632,7 +5600,7 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
     BackgroundVirtualPixelMethod);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image->columns,image->rows,1)
+    magick_threads(image,wave_image,wave_image->rows,1)
 #endif
   for (y=0; y < (ssize_t) wave_image->rows; y++)
   {
@@ -5674,7 +5642,7 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
   }
   wave_view=DestroyCacheView(wave_view);
   image_view=DestroyCacheView(image_view);
-  sine_map=(MagickRealType *) RelinquishMagickMemory(sine_map);
+  sine_map=(double *) RelinquishMagickMemory(sine_map);
   if (status == MagickFalse)
     wave_image=DestroyImage(wave_image);
   return(wave_image);