]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/fx.c
Update web pages
[imagemagick] / MagickCore / fx.c
index 8796a8d11cfed1915721f2e275d9865d8dec1e4d..9e765c3ab84eea08a22b11116d803856c3527f84 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-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
 {
@@ -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,10 +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;
@@ -283,18 +285,20 @@ 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.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (noise_image == (Image *) NULL)
     return((Image *) NULL);
@@ -303,8 +307,6 @@ MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
       noise_image=DestroyImage(noise_image);
       return((Image *) NULL);
     }
-  if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(noise_image,RGBColorspace,exception);
   /*
     Add noise in each row.
   */
@@ -313,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,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++)
   {
@@ -352,21 +354,14 @@ MagickExport Image *AddNoiseImage(const Image *image,const NoiseType noise_type,
 
       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) ||
-            (GetPixelMask(image,p) != 0))
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(noise_image,channel,p[i],q);
             continue;
@@ -456,11 +451,11 @@ MagickExport Image *BlueShiftImage(const Image *image,const double factor,
     Allocate blue shift image.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   shift_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (shift_image == (Image *) NULL)
     return((Image *) NULL);
@@ -478,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,image->columns,image->rows,1)
+    magick_threads(image,shift_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -598,16 +593,15 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius,
     *edge_image;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   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);
@@ -617,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
@@ -658,11 +652,10 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   const PixelInfo *colorize,ExceptionInfo *exception)
 {
 #define ColorizeImageTag  "Colorize/Image"
-#define Colorize(pixel,blend_percentage,colorize)  (pixel)= \
-  ((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0
+#define Colorize(pixel,blend_percentage,colorize)  \
+  (((pixel)*(100.0-(blend_percentage))+(colorize)*(blend_percentage))/100.0)
 
   CacheView
-    *colorize_view,
     *image_view;
 
   GeometryInfo
@@ -690,13 +683,12 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
     Allocate colorized image.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
-  colorize_image=CloneImage(image,image->columns,image->rows,MagickTrue,
-    exception);
+  assert(exception->signature == MagickCoreSignature);
+  colorize_image=CloneImage(image,0,0,MagickTrue,exception);
   if (colorize_image == (Image *) NULL)
     return((Image *) NULL);
   if (SetImageStorageClass(colorize_image,DirectClass,exception) == MagickFalse)
@@ -704,21 +696,21 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
       colorize_image=DestroyImage(colorize_image);
       return((Image *) NULL);
     }
-  if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+  if ((IsGrayColorspace(colorize_image->colorspace) != MagickFalse) ||
       (IsPixelInfoGray(colorize) != MagickFalse))
-    (void) SetImageColorspace(colorize_image,RGBColorspace,exception);
-  if ((colorize_image->matte == MagickFalse) &&
-      (colorize->matte != MagickFalse))
+    (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
+  if ((colorize_image->alpha_trait == UndefinedPixelTrait) &&
+      (colorize->alpha_trait != UndefinedPixelTrait))
     (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
   if (blend == (const char *) NULL)
     return(colorize_image);
-  GetPixelInfo(image,&blend_percentage);
+  GetPixelInfo(colorize_image,&blend_percentage);
   flags=ParseGeometry(blend,&geometry_info);
   blend_percentage.red=geometry_info.rho;
   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)
@@ -737,23 +729,16 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image,exception);
-  colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
+  image_view=AcquireVirtualCacheView(colorize_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(colorize_image,colorize_image,colorize_image->rows,1)
 #endif
-  for (y=0; y < (ssize_t) image->rows; y++)
+  for (y=0; y < (ssize_t) colorize_image->rows; y++)
   {
     MagickBooleanType
       sync;
 
-    PixelInfo
-      pixel;
-
-    register const Quantum
-      *restrict p;
-
     register Quantum
       *restrict q;
 
@@ -762,34 +747,34 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
 
     if (status == MagickFalse)
       continue;
-    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
-    q=QueueCacheViewAuthenticPixels(colorize_view,0,y,colorize_image->columns,1,
+    q=GetCacheViewAuthenticPixels(image_view,0,y,colorize_image->columns,1,
       exception);
-    if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
+    if (q == (Quantum *) NULL)
       {
         status=MagickFalse;
         continue;
       }
-    GetPixelInfo(colorize_image,&pixel);
-    for (x=0; x < (ssize_t) image->columns; x++)
+    for (x=0; x < (ssize_t) colorize_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(colorize_image); i++)
+      {
+        PixelTrait traits=GetPixelChannelTraits(colorize_image,
+          (PixelChannel) i);
+        if (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);
-      p+=GetPixelChannels(image);
+        if (((traits & CopyPixelTrait) != 0) ||
+            (GetPixelReadMask(colorize_image,q) == 0))
+          continue;
+        SetPixelChannel(colorize_image,(PixelChannel) i,ClampToQuantum(
+          Colorize(q[i],GetPixelInfoChannel(&blend_percentage,(PixelChannel) i),
+          GetPixelInfoChannel(colorize,(PixelChannel) i))),q);
+      }
       q+=GetPixelChannels(colorize_image);
     }
-    sync=SyncCacheViewAuthenticPixels(colorize_view,exception);
+    sync=SyncCacheViewAuthenticPixels(image_view,exception);
     if (sync == MagickFalse)
       status=MagickFalse;
     if (image->progress_monitor != (MagickProgressMonitor) NULL)
@@ -800,13 +785,13 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
         #pragma omp critical (MagickCore_ColorizeImage)
 #endif
-        proceed=SetImageProgress(image,ColorizeImageTag,progress++,image->rows);
+        proceed=SetImageProgress(image,ColorizeImageTag,progress++,
+          colorize_image->rows);
         if (proceed == MagickFalse)
           status=MagickFalse;
       }
   }
   image_view=DestroyCacheView(image_view);
-  colorize_view=DestroyCacheView(colorize_view);
   if (status == MagickFalse)
     colorize_image=DestroyImage(colorize_image);
   return(colorize_image);
@@ -891,11 +876,11 @@ MagickExport Image *ColorMatrixImage(const Image *image,
     Map given color_matrix, into a 6x6 matrix   RGBKA and a constant
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   i=0;
   for (v=0; v < (ssize_t) color_matrix->height; v++)
     for (u=0; u < (ssize_t) color_matrix->width; u++)
@@ -918,7 +903,7 @@ MagickExport Image *ColorMatrixImage(const Image *image,
   if (image->debug != MagickFalse)
     {
       char
-        format[MaxTextExtent],
+        format[MagickPathExtent],
         *message;
 
       (void) LogMagickEvent(TransformEvent,GetMagickModule(),
@@ -927,11 +912,11 @@ MagickExport Image *ColorMatrixImage(const Image *image,
       for (v=0; v < 6; v++)
       {
         *message='\0';
-        (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) v);
+        (void) FormatLocaleString(format,MagickPathExtent,"%.20g: ",(double) v);
         (void) ConcatenateString(&message,format);
         for (u=0; u < 6; u++)
         {
-          (void) FormatLocaleString(format,MaxTextExtent,"%+f ",
+          (void) FormatLocaleString(format,MagickPathExtent,"%+f ",
             ColorMatrix[v][u]);
           (void) ConcatenateString(&message,format);
         }
@@ -948,7 +933,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,image->columns,image->rows,1)
+    magick_threads(image,color_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -994,7 +979,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->matte != MagickFalse)
+        if (image->alpha_trait != UndefinedPixelTrait)
           sum+=ColorMatrix[v][4]*GetPixelAlpha(image,p);
         sum+=QuantumRange*ColorMatrix[v][5];
         switch (v)
@@ -1007,7 +992,7 @@ MagickExport Image *ColorMatrixImage(const Image *image,
           default: break;
         }
       }
-      SetPixelInfoPixel(color_image,&pixel,q);
+      SetPixelViaPixelInfo(color_image,&pixel,q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(color_image);
     }
@@ -1109,20 +1094,6 @@ MagickPrivate FxInfo *DestroyFxInfo(FxInfo *fx_info)
 %
 */
 
-static inline double MagickMax(const double x,const double y)
-{
-  if (x > y)
-    return(x);
-  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)
 {
@@ -1130,8 +1101,8 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
     channel_mask;
 
   char
-    key[MaxTextExtent],
-    statistic[MaxTextExtent];
+    key[MagickPathExtent],
+    statistic[MagickPathExtent];
 
   const char
     *value;
@@ -1151,16 +1122,16 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         {
           channel=(PixelChannel) option;
           channel_mask=(ChannelType) (channel_mask | (1 << channel));
-          SetPixelChannelMapMask(image,channel_mask);
+          (void) SetPixelChannelMask(image,channel_mask);
         }
     }
-  (void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
+  (void) FormatLocaleString(key,MagickPathExtent,"%p.%.20g.%s",(void *) image,
     (double) channel,symbol);
   value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
   if (value != (const char *) NULL)
     {
       if (channel_mask != UndefinedChannel)
-        SetPixelChannelMapMask(image,channel_mask);
+        (void) SetPixelChannelMask(image,channel_mask);
       return(QuantumScale*StringToDouble(value,(char **) NULL));
     }
   (void) DeleteNodeFromSplayTree(fx_info->symbols,key);
@@ -1170,7 +1141,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         depth;
 
       depth=GetImageDepth(image,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%.20g",(double) depth);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%.20g",(double) depth);
     }
   if (LocaleNCompare(symbol,"kurtosis",8) == 0)
     {
@@ -1179,7 +1150,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         skewness;
 
       (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",kurtosis);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",kurtosis);
     }
   if (LocaleNCompare(symbol,"maxima",6) == 0)
     {
@@ -1188,7 +1159,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         minima;
 
       (void) GetImageRange(image,&minima,&maxima,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",maxima);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",maxima);
     }
   if (LocaleNCompare(symbol,"mean",4) == 0)
     {
@@ -1197,7 +1168,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         standard_deviation;
 
       (void) GetImageMean(image,&mean,&standard_deviation,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",mean);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",mean);
     }
   if (LocaleNCompare(symbol,"minima",6) == 0)
     {
@@ -1206,7 +1177,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         minima;
 
       (void) GetImageRange(image,&minima,&maxima,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",minima);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",minima);
     }
   if (LocaleNCompare(symbol,"skewness",8) == 0)
     {
@@ -1215,7 +1186,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         skewness;
 
       (void) GetImageKurtosis(image,&kurtosis,&skewness,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",skewness);
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",skewness);
     }
   if (LocaleNCompare(symbol,"standard_deviation",18) == 0)
     {
@@ -1224,11 +1195,11 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
         standard_deviation;
 
       (void) GetImageMean(image,&mean,&standard_deviation,exception);
-      (void) FormatLocaleString(statistic,MaxTextExtent,"%g",
+      (void) FormatLocaleString(statistic,MagickPathExtent,"%g",
         standard_deviation);
     }
   if (channel_mask != UndefinedChannel)
-    SetPixelChannelMapMask(image,channel_mask);
+    (void) SetPixelChannelMask(image,channel_mask);
   (void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
     ConstantString(statistic));
   return(QuantumScale*StringToDouble(statistic,(char **) NULL));
@@ -1236,7 +1207,7 @@ static double FxChannelStatistics(FxInfo *fx_info,Image *image,
 
 static double
   FxEvaluateSubexpression(FxInfo *,const PixelChannel,const ssize_t,
-    const ssize_t,const char *,double *,ExceptionInfo *);
+    const ssize_t,const char *,size_t *,double *,ExceptionInfo *);
 
 static MagickOffsetType FxGCD(MagickOffsetType alpha,MagickOffsetType beta)
 {
@@ -1268,7 +1239,7 @@ static inline const char *FxSubexpression(const char *expression,
   }
   if (*subexpression == '\0')
     (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-      "UnbalancedParenthesis","'%s'",expression);
+      "UnbalancedParenthesis","`%s'",expression);
   return(subexpression);
 }
 
@@ -1278,8 +1249,8 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
 {
   char
     *q,
-    subexpression[MaxTextExtent],
-    symbol[MaxTextExtent];
+    subexpression[MagickPathExtent],
+    symbol[MagickPathExtent];
 
   const char
     *p,
@@ -1302,15 +1273,17 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
     i;
 
   size_t
+    depth,
     length,
     level;
 
   p=expression;
   i=GetImageIndexInList(fx_info->images);
+  depth=0;
   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)
         {
@@ -1345,14 +1318,14 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
               }
               *q='\0';
               alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
-                &beta,exception);
+                &depth,&beta,exception);
               i=(ssize_t) (alpha+0.5);
               p++;
             }
           if (*p == '.')
             p++;
         }
-      if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
+      if ((*p == 'p') && (isalpha((int) ((unsigned char) *(p+1))) == 0))
         {
           p++;
           if (*p == '{')
@@ -1374,7 +1347,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
               }
               *q='\0';
               alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
-                &beta,exception);
+                &depth,&beta,exception);
               point.x=alpha;
               point.y=beta;
               p++;
@@ -1399,7 +1372,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
                 }
                 *q='\0';
                 alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,
-                  &beta,exception);
+                  &depth,&beta,exception);
                 point.x+=alpha;
                 point.y+=beta;
                 p++;
@@ -1411,26 +1384,27 @@ 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)
     {
       (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
-        name[MaxTextExtent];
+        name[MagickPathExtent];
 
-      (void) CopyMagickString(name,p,MaxTextExtent);
+      (void) CopyMagickString(name,p,MagickPathExtent);
       for (q=name+(strlen(name)-1); q > name; q--)
       {
         if (*q == ')')
@@ -1469,7 +1443,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             }
         }
     }
-  (void) CopyMagickString(symbol,p,MaxTextExtent);
+  (void) CopyMagickString(symbol,p,MagickPathExtent);
   StripString(symbol);
   if (*symbol == '\0')
     {
@@ -1483,7 +1457,7 @@ static double 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);
             }
@@ -1494,7 +1468,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           double
             alpha;
 
-          if (pixel.matte == MagickFalse)
+          if (pixel.alpha_trait == UndefinedPixelTrait)
             return(1.0);
           alpha=(double) (QuantumScale*pixel.alpha);
           return(alpha);
@@ -1503,13 +1477,17 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           return(0.0);
         case IntensityPixelChannel:
         {
-          return(QuantumScale*GetPixelInfoIntensity(&pixel));
+          Quantum
+            quantum_pixel[MaxPixelChannels];
+
+          SetPixelViaPixelInfo(image,&pixel,quantum_pixel);
+          return(QuantumScale*GetPixelIntensity(image,quantum_pixel));
         }
         default:
           break;
       }
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "UnableToParseExpression","'%s'",p);
+        "UnableToParseExpression","`%s'",p);
       return(0.0);
     }
   switch (*symbol)
@@ -1611,7 +1589,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);
@@ -1641,7 +1618,7 @@ static double 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);
             }
@@ -1683,7 +1660,13 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
       if (LocaleCompare(symbol,"image.resolution.y") == 0)
         return(image->resolution.y);
       if (LocaleCompare(symbol,"intensity") == 0)
-        return(QuantumScale*GetPixelInfoIntensity(&pixel));
+        {
+          Quantum
+            quantum_pixel[MaxPixelChannels];
+
+          SetPixelViaPixelInfo(image,&pixel,quantum_pixel);
+          return(QuantumScale*GetPixelIntensity(image,quantum_pixel));
+        }
       if (LocaleCompare(symbol,"i") == 0)
         return((double) x);
       break;
@@ -1709,12 +1692,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.21267*pixel.red+0.71516*pixel.green+0.07217*pixel.blue;
+          luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
           return(QuantumScale*luminence);
         }
       break;
@@ -1729,7 +1720,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':
@@ -1759,6 +1750,13 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
         return((double) image->page.y);
       break;
     }
+    case 'Q':
+    case 'q':
+    {
+      if (LocaleCompare(symbol,"quality") == 0)
+        return((double) image->quality);
+      break;
+    }
     case 'R':
     case 'r':
     {
@@ -1808,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':
@@ -1831,7 +1829,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   if (value != (const char *) NULL)
     return((double) StringToDouble(value,(char **) NULL));
   (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-    "UnableToParseExpression","'%s'",symbol);
+    "UnableToParseExpression","`%s'",symbol);
   return(0.0);
 }
 
@@ -1880,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;
@@ -1921,8 +1919,9 @@ 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;
@@ -1970,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;
         }
@@ -2093,11 +2092,13 @@ static const char *FxOperatorPrecedence(const char *expression,
 
 static double FxEvaluateSubexpression(FxInfo *fx_info,
   const PixelChannel channel,const ssize_t x,const ssize_t y,
-  const char *expression,double *beta,ExceptionInfo *exception)
+  const char *expression,size_t *depth,double *beta,ExceptionInfo *exception)
 {
+#define FxMaxParenthesisDepth  58
+
   char
     *q,
-    subexpression[MaxTextExtent];
+    subexpression[MagickPathExtent];
 
   double
     alpha,
@@ -2107,147 +2108,173 @@ 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)
     {
       (void) CopyMagickString(subexpression,expression,(size_t)
         (p-expression+1));
-      alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
-        exception);
+      alpha=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,depth,
+        beta,exception);
       switch ((unsigned char) *p)
       {
         case '~':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *beta=(double) (~(size_t) *beta);
           return(*beta);
         }
         case '!':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(*beta == 0.0 ? 1.0 : 0.0);
         }
         case '^':
         {
           *beta=pow((double) alpha,(double) FxEvaluateSubexpression(fx_info,
-            channel,x,y,++p,beta,exception));
+            channel,x,y,++p,depth,beta,exception));
           return(*beta);
         }
         case '*':
         case ExponentialNotation:
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha*(*beta));
         }
         case '/':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,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));
         }
         case '%':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *beta=fabs(floor(((double) *beta)+0.5));
           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));
         }
         case '+':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha+(*beta));
         }
         case '-':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha-(*beta));
         }
         case LeftShiftOperator:
         {
-          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *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);
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *beta=(double) ((size_t) (alpha+0.5) >> (size_t) (gamma+0.5));
           return(*beta);
         }
         case '<':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha < *beta ? 1.0 : 0.0);
         }
         case LessThanEqualOperator:
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha <= *beta ? 1.0 : 0.0);
         }
         case '>':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha > *beta ? 1.0 : 0.0);
         }
         case GreaterThanEqualOperator:
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha >= *beta ? 1.0 : 0.0);
         }
         case EqualOperator:
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          return(fabs(alpha-(*beta)) < MagickEpsilon ? MagickEpsilon : 0.0);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
+          return(fabs(alpha-(*beta)) < MagickEpsilon ? 1.0 : 0.0);
         }
         case NotEqualOperator:
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(fabs(alpha-(*beta)) >= MagickEpsilon ? 1.0 : 0.0);
         }
         case '&':
         {
-          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *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);
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           *beta=(double) ((size_t) (alpha+0.5) | (size_t) (gamma+0.5));
           return(*beta);
         }
         case LogicalAndOperator:
         {
-          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(alpha > 0.0) && (gamma > 0.0) ? 1.0 : 0.0;
+          p++;
+          if (alpha <= 0.0)
+            {
+              *beta=0.0;
+              return(*beta);
+            }
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,depth,beta,
+            exception);
+          *beta=(gamma > 0.0) ? 1.0 : 0.0;
           return(*beta);
         }
         case LogicalOrOperator:
         {
-          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          *beta=(alpha > 0.0) || (gamma > 0.0) ? 1.0 : 0.0;
+          p++;
+          if (alpha > 0.0)
+            {
+             *beta=1.0;
+             return(*beta);
+            }
+          gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,depth,beta,
+            exception);
+          *beta=(gamma > 0.0) ? 1.0 : 0.0;
           return(*beta);
         }
         case '?':
@@ -2255,25 +2282,27 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           double
             gamma;
 
-          (void) CopyMagickString(subexpression,++p,MaxTextExtent);
+          (void) CopyMagickString(subexpression,++p,MagickPathExtent);
           q=subexpression;
           p=StringToken(":",&q);
           if (q == (char *) NULL)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"UnableToParseExpression","'%s'",subexpression);
+                OptionError,"UnableToParseExpression","`%s'",subexpression);
               return(0.0);
             }
           if (fabs((double) alpha) >= MagickEpsilon)
-            gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,exception);
+            gamma=FxEvaluateSubexpression(fx_info,channel,x,y,p,depth,beta,
+              exception);
           else
-            gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,beta,exception);
+            gamma=FxEvaluateSubexpression(fx_info,channel,x,y,q,depth,beta,
+              exception);
           return(gamma);
         }
         case '=':
         {
           char
-            numeric[MaxTextExtent];
+            numeric[MagickPathExtent];
 
           q=subexpression;
           while (isalpha((int) ((unsigned char) *q)) != 0)
@@ -2281,12 +2310,13 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           if (*q != '\0')
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"UnableToParseExpression","'%s'",subexpression);
+                OptionError,"UnableToParseExpression","`%s'",subexpression);
               return(0.0);
             }
           ClearMagickException(exception);
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
-          (void) FormatLocaleString(numeric,MaxTextExtent,"%g",(double)
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
+          (void) FormatLocaleString(numeric,MagickPathExtent,"%g",(double)
             *beta);
           (void) DeleteNodeFromSplayTree(fx_info->symbols,subexpression);
           (void) AddValueToSplayTree(fx_info->symbols,ConstantString(
@@ -2295,17 +2325,19 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
         case ',':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(alpha);
         }
         case ';':
         {
-          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,beta,exception);
+          *beta=FxEvaluateSubexpression(fx_info,channel,x,y,++p,depth,beta,
+            exception);
           return(*beta);
         }
         default:
         {
-          gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,beta,
+          gamma=alpha*FxEvaluateSubexpression(fx_info,channel,x,y,p,depth,beta,
             exception);
           return(gamma);
         }
@@ -2313,29 +2345,34 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     }
   if (strchr("(",(int) *expression) != (char *) NULL)
     {
-      (void) CopyMagickString(subexpression,expression+1,MaxTextExtent);
+      (*depth)++;
+      if (*depth >= FxMaxParenthesisDepth)
+        (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+          "ParenthesisNestedTooDeeply","`%s'",expression);
+      (void) CopyMagickString(subexpression,expression+1,MagickPathExtent);
       subexpression[strlen(subexpression)-1]='\0';
-      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,beta,
-        exception);
+      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,subexpression,depth,
+        beta,exception);
+      (*depth)--;
       return(gamma);
     }
   switch (*expression)
   {
     case '+':
     {
-      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
+      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,depth,beta,
         exception);
       return(1.0*gamma);
     }
     case '-':
     {
-      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
+      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,depth,beta,
         exception);
       return(-1.0*gamma);
     }
     case '~':
     {
-      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,beta,
+      gamma=FxEvaluateSubexpression(fx_info,channel,x,y,expression+1,depth,beta,
         exception);
       return((double) (~(size_t) (gamma+0.5)));
     }
@@ -2344,29 +2381,29 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"abs",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           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);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) acosh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"acos",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) acos((double) alpha));
         }
 #if defined(MAGICKCORE_HAVE_J1)
       if (LocaleNCompare(expression,"airy",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           if (alpha == 0.0)
             return(1.0);
           gamma=2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha);
@@ -2376,41 +2413,41 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
 #if defined(MAGICKCORE_HAVE_ASINH)
       if (LocaleNCompare(expression,"asinh",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) asinh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"asin",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) asin((double) alpha));
         }
       if (LocaleNCompare(expression,"alt",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return(((ssize_t) alpha) & 0x01 ? -1.0 : 1.0);
         }
       if (LocaleNCompare(expression,"atan2",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           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);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) atanh((double) alpha));
         }
 #endif
       if (LocaleNCompare(expression,"atan",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) atan((double) alpha));
         }
       if (LocaleCompare(expression,"a") == 0)
@@ -2429,20 +2466,30 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"ceil",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) ceil((double) alpha));
         }
+      if (LocaleNCompare(expression,"clamp",5) == 0)
+        {
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
+          if (alpha < 0.0)
+            return(0.0);
+          if (alpha > 1.0)
+            return(1.0);
+          return(alpha);
+        }
       if (LocaleNCompare(expression,"cosh",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) cosh((double) alpha));
         }
       if (LocaleNCompare(expression,"cos",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) cos((double) alpha));
         }
       if (LocaleCompare(expression,"c") == 0)
@@ -2457,8 +2504,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           const char
             *type;
 
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           if (fx_info->images->colorspace == CMYKColorspace)
             switch (channel)
             {
@@ -2478,7 +2525,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
               case AlphaPixelChannel: type="opacity"; break;
               default: type="unknown"; break;
             }
-          (void) CopyMagickString(subexpression,expression+6,MaxTextExtent);
+          (void) CopyMagickString(subexpression,expression+6,MagickPathExtent);
           if (strlen(subexpression) > 1)
             subexpression[strlen(subexpression)-1]='\0';
           if (fx_info->file != (FILE *) NULL)
@@ -2489,8 +2536,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
       if (LocaleNCompare(expression,"drc",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) (alpha/(*beta*(alpha-1.0)+1.0)));
         }
       break;
@@ -2502,8 +2549,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         return((double) MagickEpsilon);
       if (LocaleNCompare(expression,"exp",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) exp((double) alpha));
         }
       if (LocaleCompare(expression,"e") == 0)
@@ -2515,8 +2562,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"floor",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) floor((double) alpha));
         }
       break;
@@ -2526,8 +2573,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"gauss",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           gamma=exp((double) (-alpha*alpha/2.0))/sqrt(2.0*MagickPI);
           return((double) gamma);
         }
@@ -2536,8 +2583,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           MagickOffsetType
             gcd;
 
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           gcd=FxGCD((MagickOffsetType) (alpha+0.5),(MagickOffsetType) (*beta+
             0.5));
           return((double) gcd);
@@ -2555,8 +2602,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
       if (LocaleNCompare(expression,"hypot",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) hypot((double) alpha,(double) *beta));
         }
       break;
@@ -2575,18 +2622,16 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
       if (LocaleNCompare(expression,"int",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           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((double) !!isnan((double) alpha));
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
+          return((double) !!IsNaN((double) alpha));
         }
-#endif
       if (LocaleCompare(expression,"i") == 0)
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
       break;
@@ -2599,28 +2644,27 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
 #if defined(MAGICKCORE_HAVE_J0)
       if (LocaleNCompare(expression,"j0",2) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,depth,
+            beta,exception);
           return((double) j0((double) alpha));
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
       if (LocaleNCompare(expression,"j1",2) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,depth,
+            beta,exception);
           return((double) j1((double) alpha));
         }
 #endif
 #if defined(MAGICKCORE_HAVE_J1)
       if (LocaleNCompare(expression,"jinc",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           if (alpha == 0.0)
             return(1.0);
-          gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*
-            alpha));
+          gamma=(double) (2.0*j1((double) (MagickPI*alpha))/(MagickPI*alpha));
           return(gamma);
         }
 #endif
@@ -2631,20 +2675,20 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"ln",2) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+2,depth,
+            beta,exception);
           return((double) log((double) alpha));
         }
       if (LocaleNCompare(expression,"logtwo",6) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,depth,
+            beta,exception);
           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);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) log10((double) alpha));
         }
       if (LocaleCompare(expression,"lightness") == 0)
@@ -2660,22 +2704,22 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         break;
       if (LocaleNCompare(expression,"max",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return(alpha > *beta ? alpha : *beta);
         }
       if (LocaleNCompare(expression,"minima",6) == 0)
         break;
       if (LocaleNCompare(expression,"min",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return(alpha < *beta ? alpha : *beta);
         }
       if (LocaleNCompare(expression,"mod",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           gamma=alpha-floor((double) (alpha/(*beta)))*(*beta);
           return(gamma);
         }
@@ -2688,8 +2732,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"not",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) (alpha < MagickEpsilon));
         }
       if (LocaleCompare(expression,"n") == 0)
@@ -2714,8 +2758,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         return((double) MagickPI);
       if (LocaleNCompare(expression,"pow",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) pow((double) alpha,(double) *beta));
         }
       if (LocaleCompare(expression,"p") == 0)
@@ -2735,11 +2779,20 @@ 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,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           return((double) floor((double) alpha+0.5));
         }
       if (LocaleCompare(expression,"r") == 0)
@@ -2753,14 +2806,14 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         return(FxGetSymbol(fx_info,channel,x,y,expression,exception));
       if (LocaleNCompare(expression,"sign",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return(alpha < 0.0 ? -1.0 : 1.0);
         }
       if (LocaleNCompare(expression,"sinc",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           if (alpha == 0)
             return(1.0);
           gamma=(double) (sin((double) (MagickPI*alpha))/
@@ -2769,26 +2822,26 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         }
       if (LocaleNCompare(expression,"sinh",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) sinh((double) alpha));
         }
       if (LocaleNCompare(expression,"sin",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) sin((double) alpha));
         }
       if (LocaleNCompare(expression,"sqrt",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) sqrt((double) alpha));
         }
       if (LocaleNCompare(expression,"squish",6) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+6,depth,
+            beta,exception);
           return((double) (1.0/(1.0+exp((double) (-alpha)))));
         }
       if (LocaleCompare(expression,"s") == 0)
@@ -2800,22 +2853,22 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
     {
       if (LocaleNCompare(expression,"tanh",4) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+4,depth,
+            beta,exception);
           return((double) tanh((double) alpha));
         }
       if (LocaleNCompare(expression,"tan",3) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+3,depth,
+            beta,exception);
           return((double) tan((double) alpha));
         }
       if (LocaleCompare(expression,"Transparent") == 0)
         return(0.0);
       if (LocaleNCompare(expression,"trunc",5) == 0)
         {
-          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-            exception);
+          alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,depth,
+            beta,exception);
           if (alpha >= 0.0)
             return((double) floor((double) alpha));
           return((double) ceil((double) alpha));
@@ -2845,8 +2898,8 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
         {
           do
           {
-            alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,beta,
-              exception);
+            alpha=FxEvaluateSubexpression(fx_info,channel,x,y,expression+5,
+              depth,beta,exception);
           } while (fabs((double) alpha) >= MagickEpsilon);
           return((double) *beta);
         }
@@ -2913,9 +2966,13 @@ MagickPrivate MagickBooleanType FxEvaluateChannelExpression(FxInfo *fx_info,
   double
     beta;
 
+  size_t
+    depth;
+
+  depth=0;
   beta=0.0;
-  *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&beta,
-    exception);
+  *alpha=FxEvaluateSubexpression(fx_info,channel,x,y,fx_info->expression,&depth,
+    &beta,exception);
   return(exception->severity == OptionError ? MagickFalse : MagickTrue);
 }
 \f
@@ -2981,20 +3038,31 @@ static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
   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);
 }
 
@@ -3019,35 +3087,26 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
   MagickOffsetType
     progress;
 
-  double
-    alpha;
-
   ssize_t
     y;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   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);
     }
   /*
@@ -3059,7 +3118,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,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++)
   {
@@ -3094,21 +3153,14 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
         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) ||
-            (GetPixelMask(image,p) != 0))
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(fx_image,channel,p[i],q);
             continue;
@@ -3187,7 +3239,8 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 
   CacheView
     *image_view,
-    *implode_view;
+    *implode_view,
+    *interpolate_view;
 
   Image
     *implode_image;
@@ -3212,11 +3265,11 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
     Initialize implode image attributes.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   implode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
     exception);
   if (implode_image == (Image *) NULL)
@@ -3227,7 +3280,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.
   */
@@ -3250,10 +3303,11 @@ 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,image->columns,image->rows,1)
+    magick_threads(image,implode_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -3274,7 +3328,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))
@@ -3291,8 +3345,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;
@@ -3302,16 +3357,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;
@@ -3329,9 +3378,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);
@@ -3352,6 +3401,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);
@@ -3388,11 +3438,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;
@@ -3403,10 +3457,6 @@ MagickExport Image *MorphImages(const Image *image,
   MagickOffsetType
     scene;
 
-  double
-    alpha,
-    beta;
-
   register const Image
     *next;
 
@@ -3420,11 +3470,11 @@ MagickExport Image *MorphImages(const Image *image,
     Clone first frame in sequence.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   morph_images=CloneImage(image,0,0,MagickTrue,exception);
   if (morph_images == (Image *) NULL)
     return((Image *) NULL);
@@ -3498,7 +3548,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,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++)
       {
@@ -3532,21 +3582,14 @@ MagickExport Image *MorphImages(const Image *image,
 
           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) ||
-                (GetPixelMask(image,p) != 0))
+                (GetPixelReadMask(morph_images,p) == 0))
               {
                 SetPixelChannel(morph_image,channel,p[i],q);
                 continue;
@@ -3643,6 +3686,10 @@ static inline Quantum PlasmaPixel(RandomInfo *random_info,
 
   plasma=ClampToQuantum(pixel+noise*GetPseudoRandomValue(random_info)-
     noise/2.0);
+  if (plasma <= 0)
+    return((Quantum) 0);
+  if (plasma >= QuantumRange)
+    return(QuantumRange);
   return(plasma);
 }
 
@@ -3654,12 +3701,6 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
   double
     plasma;
 
-  PixelChannel
-    channel;
-
-  PixelTrait
-    traits;
-
   register const Quantum
     *restrict u,
     *restrict v;
@@ -3676,10 +3717,14 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
     y,
     y_mid;
 
-  if (((segment->x2-segment->x1) == 0.0) && ((segment->y2-segment->y1) == 0.0))
+  if ((fabs(segment->x2-segment->x1) <= MagickEpsilon) &&
+      (fabs(segment->y2-segment->y1) <= MagickEpsilon))
     return(MagickTrue);
   if (depth != 0)
     {
+      MagickBooleanType
+        status;
+
       SegmentInfo
         local_info;
 
@@ -3708,19 +3753,23 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
       local_info=(*segment);
       local_info.x1=(double) x_mid;
       local_info.y1=(double) y_mid;
-      return(PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
-        &local_info,attenuate,depth,exception));
+      status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,
+        &local_info,attenuate,depth,exception);
+      return(status);
     }
   x_mid=(ssize_t) ceil((segment->x1+segment->x2)/2-0.5);
   y_mid=(ssize_t) ceil((segment->y1+segment->y2)/2-0.5);
-  if ((segment->x1 == (double) x_mid) && (segment->x2 == (double) x_mid) &&
-      (segment->y1 == (double) y_mid) && (segment->y2 == (double) y_mid))
+  if ((fabs(segment->x1-x_mid) < MagickEpsilon) &&
+      (fabs(segment->x2-x_mid) < MagickEpsilon) &&
+      (fabs(segment->y1-y_mid) < MagickEpsilon) &&
+      (fabs(segment->y2-y_mid) < MagickEpsilon))
     return(MagickFalse);
   /*
     Average pixels and apply plasma.
   */
   plasma=(double) QuantumRange/(2.0*attenuate);
-  if ((segment->x1 != (double) x_mid) || (segment->x2 != (double) x_mid))
+  if ((fabs(segment->x1-x_mid) > MagickEpsilon) ||
+      (fabs(segment->x2-x_mid) > MagickEpsilon))
     {
       /*
         Left pixel.
@@ -3736,14 +3785,14 @@ 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)
+      if (fabs(segment->x1-segment->x2) > MagickEpsilon)
         {
           /*
             Right pixel.
@@ -3759,18 +3808,20 @@ 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->y1 != (double) y_mid) || (segment->y2 != (double) y_mid))
+  if ((fabs(segment->y1-y_mid) > MagickEpsilon) ||
+      (fabs(segment->y2-y_mid) > MagickEpsilon))
     {
-      if ((segment->x1 != (double) x_mid) || (segment->y2 != (double) y_mid))
+      if ((fabs(segment->x1-x_mid) > MagickEpsilon) ||
+          (fabs(segment->y2-y_mid) > MagickEpsilon))
         {
           /*
             Bottom pixel.
@@ -3786,15 +3837,15 @@ 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->y1 != segment->y2)
+      if (fabs(segment->y1-segment->y2) > MagickEpsilon)
         {
           /*
             Top pixel.
@@ -3810,16 +3861,17 @@ 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) || (segment->y1 != segment->y2))
+  if ((fabs(segment->x1-segment->x2) > MagickEpsilon) ||
+      (fabs(segment->y1-segment->y2) > MagickEpsilon))
     {
       /*
         Middle pixel.
@@ -3836,15 +3888,16 @@ 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->x2-segment->x1) < 3.0) && ((segment->y2-segment->y1) < 3.0))
+  if ((fabs(segment->x2-segment->x1) < 3.0) &&
+      (fabs(segment->y2-segment->y1) < 3.0))
     return(MagickTrue);
   return(MagickFalse);
 }
@@ -3867,7 +3920,7 @@ MagickExport MagickBooleanType PlasmaImage(Image *image,
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
@@ -3942,11 +3995,11 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
     Simulate a Polaroid picture.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   quantum=(ssize_t) MagickMax(MagickMax((double) image->columns,(double)
     image->rows)/25.0,10.0);
   height=image->rows+2*quantum;
@@ -3954,12 +4007,15 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
   if (caption != (const char *) NULL)
     {
       char
-        geometry[MaxTextExtent],
+        geometry[MagickPathExtent],
         *text;
 
       DrawInfo
         *annotate_info;
 
+      ImageInfo
+        *image_info;
+
       MagickBooleanType
         status;
 
@@ -3975,9 +4031,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);
@@ -3990,7 +4048,7 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
           caption_image->background_color=image->border_color;
           (void) SetImageBackgroundColor(caption_image,exception);
           (void) CloneString(&annotate_info->text,text);
-          (void) FormatLocaleString(geometry,MaxTextExtent,"+0+%g",
+          (void) FormatLocaleString(geometry,MagickPathExtent,"+0+%g",
             metrics.ascent);
           if (annotate_info->gravity == UndefinedGravity)
             (void) CloneString(&annotate_info->geometry,AcquireString(
@@ -4127,11 +4185,11 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
     Initialize sepia-toned image attributes.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   sepia_image=CloneImage(image,0,0,MagickTrue,exception);
   if (sepia_image == (Image *) NULL)
     return((Image *) NULL);
@@ -4149,7 +4207,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,image->columns,image->rows,1)
+    magick_threads(image,sepia_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -4192,6 +4250,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);
     }
@@ -4281,16 +4340,16 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
     y;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   clone_image=CloneImage(image,0,0,MagickTrue,exception);
   if (clone_image == (Image *) NULL)
     return((Image *) NULL);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(clone_image,RGBColorspace,exception);
+    (void) SetImageColorspace(clone_image,sRGBColorspace,exception);
   (void) SetImageVirtualPixelMethod(clone_image,TransparentVirtualPixelMethod,
     exception);
   border_info.width=(size_t) floor(2.0*sigma+0.5);
@@ -4299,12 +4358,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 == UndefinedPixelTrait)
     (void) SetImageAlphaChannel(border_image,OpaqueAlphaChannel,exception);
   /*
     Shadow image.
@@ -4332,12 +4391,12 @@ 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 != UndefinedPixelTrait)
         background_color.alpha=GetPixelAlpha(border_image,q)*alpha/100.0;
-      SetPixelInfoPixel(border_image,&background_color,q);
+      SetPixelViaPixelInfo(border_image,&background_color,q);
       q+=GetPixelChannels(border_image);
     }
     if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
@@ -4349,12 +4408,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)
@@ -4424,8 +4483,10 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
   ssize_t
     y;
 
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
   unsigned long
     key;
+#endif
 
   /*
     Sketch image.
@@ -4436,11 +4497,11 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
     return((Image *) NULL);
   status=MagickTrue;
   random_info=AcquireRandomInfoThreadSet();
-  key=GetRandomSecretKey(random_info[0]);
   random_view=AcquireAuthenticCacheView(random_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
+  key=GetRandomSecretKey(random_info[0]);
   #pragma omp parallel for schedule(static,4) shared(status) \
-    dynamic_number_threads(image,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++)
   {
@@ -4470,7 +4531,7 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
       register ssize_t
         i;
 
-      if (GetPixelMask(random_image,q) != 0)
+      if (GetPixelReadMask(random_image,q) == 0)
         {
           q+=GetPixelChannels(random_image);
           continue;
@@ -4478,14 +4539,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);
@@ -4506,7 +4561,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);
@@ -4583,9 +4638,11 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
     y;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   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
@@ -4599,11 +4656,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;
       }
     }
   /*
@@ -4614,7 +4669,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,image->columns,image->rows,1)
+    magick_threads(image,image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -4637,23 +4692,16 @@ 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);
-        if ((traits == UndefinedPixelTrait) ||
-            ((traits & CopyPixelTrait) != 0))
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        if ((traits & UpdatePixelTrait) == 0)
           continue;
         if ((double) q[i] > threshold)
           q[i]=QuantumRange-q[i];
@@ -4752,13 +4800,13 @@ MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
     Initialize steganographic image attributes.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(watermark != (const Image *) NULL);
-  assert(watermark->signature == MagickSignature);
+  assert(watermark->signature == MagickCoreSignature);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   one=1UL;
   stegano_image=CloneImage(image,0,0,MagickTrue,exception);
   if (stegano_image == (Image *) NULL)
@@ -4804,19 +4852,19 @@ MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
           case 0:
           {
             SetPixelRed(stegano_image,SetBit(GetPixelRed(stegano_image,q),j,
-              GetBit(GetPixelInfoIntensity(&pixel),i)),q);
+              GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
             break;
           }
           case 1:
           {
             SetPixelGreen(stegano_image,SetBit(GetPixelGreen(stegano_image,q),j,
-              GetBit(GetPixelInfoIntensity(&pixel),i)),q);
+              GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
             break;
           }
           case 2:
           {
             SetPixelBlue(stegano_image,SetBit(GetPixelBlue(stegano_image,q),j,
-              GetBit(GetPixelInfoIntensity(&pixel),i)),q);
+              GetBit(GetPixelInfoIntensity(stegano_image,&pixel),i)),q);
             break;
           }
         }
@@ -4846,10 +4894,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
@@ -4917,14 +4962,14 @@ MagickExport Image *StereoAnaglyphImage(const Image *left_image,
     y;
 
   assert(left_image != (const Image *) NULL);
-  assert(left_image->signature == MagickSignature);
+  assert(left_image->signature == MagickCoreSignature);
   if (left_image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
       left_image->filename);
   assert(right_image != (const Image *) NULL);
-  assert(right_image->signature == MagickSignature);
+  assert(right_image->signature == MagickCoreSignature);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   assert(right_image != (const Image *) NULL);
   image=left_image;
   if ((left_image->columns != right_image->columns) ||
@@ -4992,10 +5037,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
@@ -5037,6 +5079,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
   CacheView
     *image_view,
+    *interpolate_view,
     *swirl_view;
 
   Image
@@ -5062,11 +5105,11 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
     Initialize swirl image attributes.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   swirl_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (swirl_image == (Image *) NULL)
     return((Image *) NULL);
@@ -5076,7 +5119,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.
   */
@@ -5097,10 +5140,11 @@ 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,image->columns,image->rows,1)
+    magick_threads(image,swirl_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -5121,7 +5165,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))
@@ -5135,8 +5179,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;
@@ -5150,16 +5195,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;
@@ -5179,8 +5217,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);
@@ -5202,6 +5240,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);
@@ -5248,6 +5287,9 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
     *image_view,
     *tint_view;
 
+  double
+    intensity;
+
   GeometryInfo
     geometry_info;
 
@@ -5260,9 +5302,6 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   MagickOffsetType
     progress;
 
-  double
-    intensity;
-
   PixelInfo
     color_vector;
 
@@ -5276,11 +5315,11 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
     Allocate tint image.
   */
   assert(image != (const Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   tint_image=CloneImage(image,image->columns,image->rows,MagickTrue,exception);
   if (tint_image == (Image *) NULL)
     return((Image *) NULL);
@@ -5291,7 +5330,7 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
     }
   if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
       (IsPixelInfoGray(tint) == MagickFalse))
-    (void) SetImageColorspace(tint_image,RGBColorspace,exception);
+    (void) SetImageColorspace(tint_image,sRGBColorspace,exception);
   if (blend == (const char *) NULL)
     return(tint_image);
   /*
@@ -5302,7 +5341,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)
@@ -5317,17 +5356,12 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       if ((flags & ChiValue) != 0)
         color_vector.alpha=geometry_info.chi;
     }
-  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);
+  intensity=(double) GetPixelInfoIntensity((const Image *) NULL,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.
   */
@@ -5337,7 +5371,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,image->columns,image->rows,1)
+    magick_threads(image,tint_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -5373,21 +5407,14 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
 
       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) ||
-            (GetPixelMask(image,p) != 0))
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(tint_image,channel,p[i],q);
             continue;
@@ -5406,7 +5433,7 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
       weight=QuantumScale*GetPixelBlack(image,p)-0.5;
       pixel.black=(double) GetPixelBlack(image,p)+color_vector.black*(1.0-(4.0*
         (weight*weight)));
-      SetPixelInfoPixel(tint_image,&pixel,q);
+      SetPixelViaPixelInfo(tint_image,&pixel,q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(tint_image);
     }
@@ -5468,7 +5495,7 @@ MagickExport Image *VignetteImage(const Image *image,const double radius,
   const double sigma,const ssize_t x,const ssize_t y,ExceptionInfo *exception)
 {
   char
-    ellipse[MaxTextExtent];
+    ellipse[MagickPathExtent];
 
   DrawInfo
     *draw_info;
@@ -5480,11 +5507,11 @@ MagickExport Image *VignetteImage(const Image *image,const double radius,
     *vignette_image;
 
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   canvas_image=CloneImage(image,0,0,MagickTrue,exception);
   if (canvas_image == (Image *) NULL)
     return((Image *) NULL);
@@ -5493,7 +5520,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)
@@ -5509,7 +5536,7 @@ MagickExport Image *VignetteImage(const Image *image,const double radius,
     exception);
   (void) QueryColorCompliance("#ffffff",AllCompliance,&draw_info->stroke,
     exception);
-  (void) FormatLocaleString(ellipse,MaxTextExtent,"ellipse %g,%g,%g,%g,"
+  (void) FormatLocaleString(ellipse,MagickPathExtent,"ellipse %g,%g,%g,%g,"
     "0.0,360.0",image->columns/2.0,image->rows/2.0,image->columns/2.0-x,
     image->rows/2.0-y);
   draw_info->primitive=AcquireString(ellipse);
@@ -5522,7 +5549,7 @@ 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);
@@ -5598,11 +5625,11 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
     Initialize wave image attributes.
   */
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  assert(exception->signature == MagickSignature);
+  assert(exception->signature == MagickCoreSignature);
   wave_image=CloneImage(image,image->columns,(size_t) (image->rows+2.0*
     fabs(amplitude)),MagickTrue,exception);
   if (wave_image == (Image *) NULL)
@@ -5613,7 +5640,7 @@ 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.
   */
@@ -5638,7 +5665,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,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++)
   {