]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/fx.c
(no commit message)
[imagemagick] / MagickCore / fx.c
index c0841ad6a11ff694596a011bbba6751a529642a8..707fcb7624f6f6efc96e765c28d65ae88b6b9f22 100644 (file)
 %                   MagickCore Image Special Effects Methods                  %
 %                                                                             %
 %                               Software Design                               %
-%                                 John Cristy                                 %
+%                                    Cristy                                   %
 %                                 October 1996                                %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -46,6 +46,7 @@
 #include "MagickCore/attribute.h"
 #include "MagickCore/cache.h"
 #include "MagickCore/cache-view.h"
+#include "MagickCore/channel.h"
 #include "MagickCore/color.h"
 #include "MagickCore/color-private.h"
 #include "MagickCore/colorspace-private.h"
 /*
   Define declarations.
 */
-#define LeftShiftOperator 0xf5
-#define RightShiftOperator 0xf6
-#define LessThanEqualOperator 0xf7
-#define GreaterThanEqualOperator 0xf8
-#define EqualOperator 0xf9
-#define NotEqualOperator 0xfa
-#define LogicalAndOperator 0xfb
-#define LogicalOrOperator 0xfc
-#define ExponentialNotation 0xfd
-
+#define LeftShiftOperator  0xf5U
+#define RightShiftOperator  0xf6U
+#define LessThanEqualOperator  0xf7U
+#define GreaterThanEqualOperator  0xf8U
+#define EqualOperator  0xf9U
+#define NotEqualOperator  0xfaU
+#define LogicalAndOperator  0xfbU
+#define LogicalOrOperator  0xfcU
+#define ExponentialNotation 0xfdU
 struct _FxInfo
 {
   const Image
@@ -178,7 +179,7 @@ MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
   fx_info->exception=AcquireExceptionInfo();
   fx_info->images=image;
   fx_info->colors=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
-    RelinquishMagickMemory);
+    RelinquishAlignedMemory);
   fx_info->symbols=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
     RelinquishMagickMemory);
   fx_info->view=(CacheView **) AcquireQuantumMemory(GetImageListLength(
@@ -189,7 +190,7 @@ MagickPrivate FxInfo *AcquireFxInfo(const Image *image,const char *expression,
   next=GetFirstImageInList(fx_info->images);
   for ( ; next != (Image *) NULL; next=next->next)
   {
-    fx_info->view[i]=AcquireVirtualCacheView(next);
+    fx_info->view[i]=AcquireVirtualCacheView(next,exception);
     i++;
   }
   fx_info->random_info=AcquireRandomInfo();
@@ -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;
@@ -305,20 +307,18 @@ 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.
   */
   status=MagickTrue;
   progress=0;
   random_info=AcquireRandomInfoThreadSet();
-  image_view=AcquireVirtualCacheView(image);
-  noise_view=AcquireAuthenticCacheView(noise_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  noise_view=AcquireAuthenticCacheView(noise_image,exception);
 #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++)
   {
@@ -354,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=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
-        noise_traits=GetPixelChannelTraits(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;
@@ -476,11 +469,11 @@ MagickExport Image *BlueShiftImage(const Image *image,const double factor,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  shift_view=AcquireAuthenticCacheView(shift_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  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++)
   {
@@ -608,8 +601,7 @@ MagickExport Image *CharcoalImage(const Image *image,const double radius,
   clone_image=CloneImage(image,0,0,MagickTrue,exception);
   if (clone_image == (Image *) NULL)
     return((Image *) NULL);
-  (void) SetImageType(clone_image,GrayscaleType,exception);
-  edge_image=EdgeImage(clone_image,radius,sigma,exception);
+  edge_image=EdgeImage(clone_image,radius,exception);
   clone_image=DestroyImage(clone_image);
   if (edge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -619,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
@@ -706,9 +698,9 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
       colorize_image=DestroyImage(colorize_image);
       return((Image *) NULL);
     }
-  if ((IsGrayColorspace(image->colorspace) != MagickFalse) &&
+  if ((IsGrayColorspace(image->colorspace) != MagickFalse) ||
       (IsPixelInfoGray(colorize) != MagickFalse))
-    (void) SetImageColorspace(colorize_image,RGBColorspace,exception);
+    (void) SetImageColorspace(colorize_image,sRGBColorspace,exception);
   if ((colorize_image->alpha_trait != BlendPixelTrait) &&
       (colorize->alpha_trait == BlendPixelTrait))
     (void) SetImageAlpha(colorize_image,OpaqueAlpha,exception);
@@ -739,11 +731,11 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  colorize_view=AcquireAuthenticCacheView(colorize_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  colorize_view=AcquireAuthenticCacheView(colorize_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    dynamic_number_threads(image,image->columns,image->rows,1)
+    magick_threads(image,colorize_image,image->rows,1)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -776,28 +768,22 @@ MagickExport Image *ColorizeImage(const Image *image,const char *blend,
 
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          colorize_traits,
-          traits;
-
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
-        colorize_traits=GetPixelChannelTraits(colorize_image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
+        PixelTrait colorize_traits=GetPixelChannelTraits(colorize_image,
+          channel);
         if ((traits == UndefinedPixelTrait) ||
             (colorize_traits == UndefinedPixelTrait))
           continue;
         if (((colorize_traits & CopyPixelTrait) != 0) ||
-            (GetPixelMask(image,p) != 0))
+            (GetPixelReadMask(image,p) == 0))
           {
             SetPixelChannel(colorize_image,channel,p[i],q);
             continue;
           }
-        SetPixelChannel(colorize_image,channel,
-          ClampToQuantum(Colorize(p[i],GetPixelInfoChannel(&blend_percentage,
-          channel),GetPixelInfoChannel(colorize,channel))),q);
+        SetPixelChannel(colorize_image,channel,ClampToQuantum(Colorize(p[i],
+          GetPixelInfoChannel(&blend_percentage,channel),GetPixelInfoChannel(
+          colorize,channel))),q);
       }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(colorize_image);
@@ -957,11 +943,11 @@ MagickExport Image *ColorMatrixImage(const Image *image,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  color_view=AcquireAuthenticCacheView(color_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  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++)
   {
@@ -1281,7 +1267,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);
 }
 
@@ -1323,7 +1309,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   level=0;
   point.x=(double) x;
   point.y=(double) y;
-  if (isalpha((int) *(p+1)) == 0)
+  if (isalpha((int) ((unsigned char) *(p+1))) == 0)
     {
       if (strchr("suv",(int) *p) != (char *) NULL)
         {
@@ -1365,7 +1351,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           if (*p == '.')
             p++;
         }
-      if ((isalpha((int) *(p+1)) == 0) && (*p == 'p'))
+      if ((*p == 'p') && (isalpha((int) ((unsigned char) *(p+1))) == 0))
         {
           p++;
           if (*p == '{')
@@ -1429,15 +1415,15 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
   if (image == (Image *) NULL)
     {
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "NoSuchImage","'%s'",expression);
+        "NoSuchImage","`%s'",expression);
       return(0.0);
     }
   GetPixelInfo(image,&pixel);
   (void) InterpolatePixelInfo(image,fx_info->view[i],image->interpolate,
     point.x,point.y,&pixel,exception);
   if ((strlen(p) > 2) && (LocaleCompare(p,"intensity") != 0) &&
-      (LocaleCompare(p,"luminance") != 0) && (LocaleCompare(p,"hue") != 0) &&
-      (LocaleCompare(p,"saturation") != 0) &&
+      (LocaleCompare(p,"luma") != 0) && (LocaleCompare(p,"luminance") != 0) &&
+      (LocaleCompare(p,"hue") != 0) && (LocaleCompare(p,"saturation") != 0) &&
       (LocaleCompare(p,"lightness") != 0))
     {
       char
@@ -1496,7 +1482,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);
             }
@@ -1522,7 +1508,7 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
           break;
       }
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "UnableToParseExpression","'%s'",p);
+        "UnableToParseExpression","`%s'",p);
       return(0.0);
     }
   switch (*symbol)
@@ -1624,7 +1610,6 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             default:
               return(0.0);
           }
-          return(0.0);
         }
       if (LocaleCompare(symbol,"c") == 0)
         return(QuantumScale*pixel.red);
@@ -1654,7 +1639,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);
             }
@@ -1722,12 +1707,20 @@ static double FxGetSymbol(FxInfo *fx_info,const PixelChannel channel,
             &lightness);
           return(lightness);
         }
+      if (LocaleCompare(symbol,"luma") == 0)
+        {
+          double
+            luma;
+
+          luma=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
+          return(QuantumScale*luma);
+        }
       if (LocaleCompare(symbol,"luminance") == 0)
         {
           double
             luminence;
 
-          luminence=0.21267f*pixel.red+0.71516f*pixel.green+0.07217f*pixel.blue;
+          luminence=0.212656*pixel.red+0.715158*pixel.green+0.072186*pixel.blue;
           return(QuantumScale*luminence);
         }
       break;
@@ -1844,7 +1837,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);
 }
 
@@ -1893,7 +1886,7 @@ static const char *FxOperatorPrecedence(const char *expression,
   while (*expression != '\0')
   {
     precedence=UndefinedPrecedence;
-    if ((isspace((int) ((char) *expression)) != 0) || (c == (int) '@'))
+    if ((isspace((int) ((unsigned char) *expression)) != 0) || (c == (int) '@'))
       {
         expression++;
         continue;
@@ -1983,13 +1976,13 @@ static const char *FxOperatorPrecedence(const char *expression,
         }
         default:
         {
-          if (((c != 0) && ((isdigit((int) ((char) c)) != 0) ||
-               (strchr(")",c) != (char *) NULL))) &&
-              (((islower((int) ((char) *expression)) != 0) ||
-               (strchr("(",(int) *expression) != (char *) NULL)) ||
-               ((isdigit((int) ((char) c)) == 0) &&
-                (isdigit((int) ((char) *expression)) != 0))) &&
-              (strchr("xy",(int) *expression) == (char *) NULL))
+          if (((c != 0) && ((isdigit((int) ((unsigned char) c)) != 0) ||
+               (strchr(")",(int) ((unsigned char) c)) != (char *) NULL))) &&
+              (((islower((int) ((unsigned char) *expression)) != 0) ||
+               (strchr("(",(int) ((unsigned char) *expression)) != (char *) NULL)) ||
+               ((isdigit((int) ((unsigned char) c)) == 0) &&
+                (isdigit((int) ((unsigned char) *expression)) != 0))) &&
+              (strchr("xy",(int) ((unsigned char) *expression)) == (char *) NULL))
             precedence=MultiplyPrecedence;
           break;
         }
@@ -2122,12 +2115,12 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
   *beta=0.0;
   if (exception->severity != UndefinedException)
     return(0.0);
-  while (isspace((int) *expression) != 0)
+  while (isspace((int) ((unsigned char) *expression)) != 0)
     expression++;
   if (*expression == '\0')
     {
       (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
-        "MissingExpression","'%s'",expression);
+        "MissingExpression","`%s'",expression);
       return(0.0);
     }
   *subexpression='\0';
@@ -2170,7 +2163,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
             {
               if (exception->severity == UndefinedException)
                 (void) ThrowMagickException(exception,GetMagickModule(),
-                  OptionError,"DivideByZero","'%s'",expression);
+                  OptionError,"DivideByZero","`%s'",expression);
               return(0.0);
             }
           return(alpha/(*beta));
@@ -2182,7 +2175,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           if (*beta == 0.0)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"DivideByZero","'%s'",expression);
+                OptionError,"DivideByZero","`%s'",expression);
               return(0.0);
             }
           return(fmod((double) alpha,(double) *beta));
@@ -2274,7 +2267,7 @@ static double FxEvaluateSubexpression(FxInfo *fx_info,
           if (q == (char *) NULL)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),
-                OptionError,"UnableToParseExpression","'%s'",subexpression);
+                OptionError,"UnableToParseExpression","`%s'",subexpression);
               return(0.0);
             }
           if (fabs((double) alpha) >= MagickEpsilon)
@@ -2294,7 +2287,7 @@ 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);
@@ -3002,7 +2995,7 @@ static FxInfo **AcquireFxThreadSet(const Image *image,const char *expression,
   if (*expression != '@')
     fx_expression=ConstantString(expression);
   else
-    fx_expression=FileToString(expression+1,~0,exception);
+    fx_expression=FileToString(expression+1,~0UL,exception);
   for (i=0; i < (ssize_t) number_threads; i++)
   {
     MagickBooleanType
@@ -3069,11 +3062,11 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  fx_view=AcquireAuthenticCacheView(fx_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  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++)
   {
@@ -3108,21 +3101,14 @@ MagickExport Image *FxImage(const Image *image,const char *expression,
         double
           alpha;
 
-        PixelChannel
-          channel;
-
-        PixelTrait
-          fx_traits,
-          traits;
-
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
-        fx_traits=GetPixelChannelTraits(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;
@@ -3201,7 +3187,8 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 
   CacheView
     *image_view,
-    *implode_view;
+    *implode_view,
+    *interpolate_view;
 
   Image
     *implode_image;
@@ -3263,11 +3250,12 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  implode_view=AcquireAuthenticCacheView(implode_image);
+  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++)
   {
@@ -3288,7 +3276,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 
     if (status == MagickFalse)
       continue;
-    p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
     q=QueueCacheViewAuthenticPixels(implode_view,0,y,implode_image->columns,1,
       exception);
     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
@@ -3305,8 +3293,9 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       /*
         Determine if the pixel is within an ellipse.
       */
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(implode_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(implode_image);
           continue;
@@ -3316,16 +3305,10 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       if (distance >= (radius*radius))
         for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
         {
-          PixelChannel
-            channel;
-
-          PixelTrait
-            implode_traits,
-            traits;
-
-          channel=GetPixelChannelChannel(image,i);
-          traits=GetPixelChannelTraits(image,channel);
-          implode_traits=GetPixelChannelTraits(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;
@@ -3343,9 +3326,9 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
           if (distance > 0.0)
             factor=pow(sin((double) (MagickPI*sqrt((double) distance)/radius/
               2)),-amount);
-          status=InterpolatePixelChannels(image,image_view,implode_image,method,
-            (double) (factor*delta.x/scale.x+center.x),(double) (factor*delta.y/
-            scale.y+center.y),q,exception);
+          status=InterpolatePixelChannels(image,interpolate_view,implode_image,
+            method,(double) (factor*delta.x/scale.x+center.x),(double) (factor*
+            delta.y/scale.y+center.y),q,exception);
         }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(implode_image);
@@ -3366,6 +3349,7 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
       }
   }
   implode_view=DestroyCacheView(implode_view);
+  interpolate_view=DestroyCacheView(interpolate_view);
   image_view=DestroyCacheView(image_view);
   if (status == MagickFalse)
     implode_image=DestroyImage(implode_image);
@@ -3402,11 +3386,15 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-MagickExport Image *MorphImages(const Image *image,
-  const size_t number_frames,ExceptionInfo *exception)
+MagickExport Image *MorphImages(const Image *image,const size_t number_frames,
+  ExceptionInfo *exception)
 {
 #define MorphImageTag  "Morph/Image"
 
+  double
+    alpha,
+    beta;
+
   Image
     *morph_image,
     *morph_images;
@@ -3417,10 +3405,6 @@ MagickExport Image *MorphImages(const Image *image,
   MagickOffsetType
     scene;
 
-  double
-    alpha,
-    beta;
-
   register const Image
     *next;
 
@@ -3508,11 +3492,11 @@ MagickExport Image *MorphImages(const Image *image,
           morph_images=DestroyImageList(morph_images);
           return((Image *) NULL);
         }
-      image_view=AcquireVirtualCacheView(morph_image);
-      morph_view=AcquireAuthenticCacheView(morph_images);
+      image_view=AcquireVirtualCacheView(morph_image,exception);
+      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++)
       {
@@ -3546,21 +3530,14 @@ MagickExport Image *MorphImages(const Image *image,
 
           for (i=0; i < (ssize_t) GetPixelChannels(morph_image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              morph_traits,
-              traits;
-
-            channel=GetPixelChannelChannel(image,i);
-            traits=GetPixelChannelTraits(image,channel);
-            morph_traits=GetPixelChannelTraits(morph_image,channel);
+            PixelChannel channel=GetPixelChannelChannel(morph_image,i);
+            PixelTrait traits=GetPixelChannelTraits(morph_image,channel);
+            PixelTrait morph_traits=GetPixelChannelTraits(morph_images,channel);
             if ((traits == UndefinedPixelTrait) ||
                 (morph_traits == UndefinedPixelTrait))
               continue;
             if (((morph_traits & CopyPixelTrait) != 0) ||
-                (GetPixelMask(image,p) != 0))
+                (GetPixelReadMask(morph_images,p) == 0))
               {
                 SetPixelChannel(morph_image,channel,p[i],q);
                 continue;
@@ -3668,12 +3645,6 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
   double
     plasma;
 
-  PixelChannel
-    channel;
-
-  PixelTrait
-    traits;
-
   register const Quantum
     *restrict u,
     *restrict v;
@@ -3750,11 +3721,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         return(MagickTrue);
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(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)
@@ -3773,11 +3744,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelChannel(image,i);
-            traits=GetPixelChannelTraits(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);
         }
@@ -3800,11 +3771,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelChannel(image,i);
-            traits=GetPixelChannelTraits(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);
         }
@@ -3824,11 +3795,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
             return(MagickTrue);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            channel=GetPixelChannelChannel(image,i);
-            traits=GetPixelChannelTraits(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);
         }
@@ -3850,11 +3821,11 @@ static MagickBooleanType PlasmaImageProxy(Image *image,CacheView *image_view,
         return(MagickTrue);
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(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);
     }
@@ -3886,9 +3857,9 @@ MagickExport MagickBooleanType PlasmaImage(Image *image,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse)
     return(MagickFalse);
-  image_view=AcquireAuthenticCacheView(image);
-  u_view=AcquireVirtualCacheView(image);
-  v_view=AcquireVirtualCacheView(image);
+  image_view=AcquireAuthenticCacheView(image,exception);
+  u_view=AcquireVirtualCacheView(image,exception);
+  v_view=AcquireVirtualCacheView(image,exception);
   random_info=AcquireRandomInfo();
   status=PlasmaImageProxy(image,image_view,u_view,v_view,random_info,segment,
     attenuate,depth,exception);
@@ -3974,6 +3945,9 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
       DrawInfo
         *annotate_info;
 
+      ImageInfo
+        *image_info;
+
       MagickBooleanType
         status;
 
@@ -3989,9 +3963,11 @@ MagickExport Image *PolaroidImage(const Image *image,const DrawInfo *draw_info,
       caption_image=CloneImage(image,image->columns,1,MagickTrue,exception);
       if (caption_image == (Image *) NULL)
         return((Image *) NULL);
+      image_info=AcquireImageInfo();
       annotate_info=CloneDrawInfo((const ImageInfo *) NULL,draw_info);
-      text=InterpretImageProperties((ImageInfo *) NULL,(Image *) image,caption,
+      text=InterpretImageProperties(image_info,(Image *) image,caption,
         exception);
+      image_info=DestroyImageInfo(image_info);
       (void) CloneString(&annotate_info->text,text);
       count=FormatMagickCaption(caption_image,annotate_info,MagickTrue,&metrics,
         &text,exception);
@@ -4159,11 +4135,11 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  sepia_view=AcquireAuthenticCacheView(sepia_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  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++)
   {
@@ -4206,6 +4182,7 @@ MagickExport Image *SepiaToneImage(const Image *image,const double threshold,
         SetPixelGreen(sepia_image,ClampToQuantum(tone),q);
       if ((double) GetPixelBlue(image,q) < tone)
         SetPixelBlue(sepia_image,ClampToQuantum(tone),q);
+      SetPixelAlpha(sepia_image,GetPixelAlpha(image,p),q);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(sepia_image);
     }
@@ -4304,7 +4281,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
   if (clone_image == (Image *) NULL)
     return((Image *) NULL);
   if (IsGrayColorspace(image->colorspace) != MagickFalse)
-    (void) TransformImageColorspace(clone_image,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);
@@ -4324,7 +4301,7 @@ MagickExport Image *ShadowImage(const Image *image,const double alpha,
     Shadow image.
   */
   status=MagickTrue;
-  image_view=AcquireAuthenticCacheView(border_image);
+  image_view=AcquireAuthenticCacheView(border_image,exception);
   for (y=0; y < (ssize_t) border_image->rows; y++)
   {
     PixelInfo
@@ -4455,10 +4432,10 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   key=GetRandomSecretKey(random_info[0]);
 #endif
-  random_view=AcquireAuthenticCacheView(random_image);
+  random_view=AcquireAuthenticCacheView(random_image,exception);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #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++)
   {
@@ -4488,7 +4465,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;
@@ -4496,14 +4473,8 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
       value=GetPseudoRandomValue(random_info[id]);
       for (i=0; i < (ssize_t) GetPixelChannels(random_image); i++)
       {
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits;
-
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
         if (traits == UndefinedPixelTrait)
           continue;
         q[i]=ClampToQuantum(QuantumRange*value);
@@ -4524,7 +4495,7 @@ MagickExport Image *SketchImage(const Image *image,const double radius,
   random_image=DestroyImage(random_image);
   if (blur_image == (Image *) NULL)
     return((Image *) NULL);
-  dodge_image=EdgeImage(blur_image,radius,1.0,exception);
+  dodge_image=EdgeImage(blur_image,radius,exception);
   blur_image=DestroyImage(blur_image);
   if (dodge_image == (Image *) NULL)
     return((Image *) NULL);
@@ -4604,6 +4575,8 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  if (IsGrayColorspace(image->colorspace) != MagickFalse)
+    (void) SetImageColorspace(image,sRGBColorspace,exception);
   if (image->storage_class == PseudoClass)
     {
       register ssize_t
@@ -4617,11 +4590,9 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
         if ((double) image->colormap[i].red > threshold)
           image->colormap[i].red=QuantumRange-image->colormap[i].red;
         if ((double) image->colormap[i].green > threshold)
-          image->colormap[i].green=QuantumRange-
-            image->colormap[i].green;
+          image->colormap[i].green=QuantumRange-image->colormap[i].green;
         if ((double) image->colormap[i].blue > threshold)
-          image->colormap[i].blue=QuantumRange-
-            image->colormap[i].blue;
+          image->colormap[i].blue=QuantumRange-image->colormap[i].blue;
       }
     }
   /*
@@ -4629,10 +4600,10 @@ MagickExport MagickBooleanType SolarizeImage(Image *image,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireAuthenticCacheView(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++)
   {
@@ -4655,21 +4626,15 @@ 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=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
+        PixelChannel channel=GetPixelChannelChannel(image,i);
+        PixelTrait traits=GetPixelChannelTraits(image,channel);
         if ((traits == UndefinedPixelTrait) ||
             ((traits & CopyPixelTrait) != 0))
           continue;
@@ -4796,8 +4761,8 @@ MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
   depth=stegano_image->depth;
   k=stegano_image->offset;
   status=MagickTrue;
-  watermark_view=AcquireVirtualCacheView(watermark);
-  stegano_view=AcquireAuthenticCacheView(stegano_image);
+  watermark_view=AcquireVirtualCacheView(watermark,exception);
+  stegano_view=AcquireAuthenticCacheView(stegano_image,exception);
   for (i=(ssize_t) depth-1; (i >= 0) && (j < (ssize_t) depth); i--)
   {
     for (y=0; (y < (ssize_t) watermark->rows) && (j < (ssize_t) depth); y++)
@@ -4864,10 +4829,7 @@ MagickExport Image *SteganoImage(const Image *image,const Image *watermark,
   stegano_view=DestroyCacheView(stegano_view);
   watermark_view=DestroyCacheView(watermark_view);
   if (status == MagickFalse)
-    {
-      stegano_image=DestroyImage(stegano_image);
-      return((Image *) NULL);
-    }
+    stegano_image=DestroyImage(stegano_image);
   return(stegano_image);
 }
 \f
@@ -5010,10 +4972,7 @@ MagickExport Image *StereoAnaglyphImage(const Image *left_image,
       }
   }
   if (status == MagickFalse)
-    {
-      stereo_image=DestroyImage(stereo_image);
-      return((Image *) NULL);
-    }
+    stereo_image=DestroyImage(stereo_image);
   return(stereo_image);
 }
 \f
@@ -5055,6 +5014,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
   CacheView
     *image_view,
+    *interpolate_view,
     *swirl_view;
 
   Image
@@ -5114,11 +5074,12 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  swirl_view=AcquireAuthenticCacheView(swirl_image);
+  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++)
   {
@@ -5139,7 +5100,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
     if (status == MagickFalse)
       continue;
-    p=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
+    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
     q=QueueCacheViewAuthenticPixels(swirl_view,0,y,swirl_image->columns,1,
       exception);
     if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
@@ -5153,8 +5114,9 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       /*
         Determine if the pixel is within an ellipse.
       */
-      if (GetPixelMask(image,p) != 0)
+      if (GetPixelReadMask(image,p) == 0)
         {
+          SetPixelBackgoundColor(swirl_image,q);
           p+=GetPixelChannels(image);
           q+=GetPixelChannels(swirl_image);
           continue;
@@ -5168,16 +5130,9 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
 
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
-            PixelChannel
-              channel;
-
-            PixelTrait
-              swirl_traits,
-              traits;
-
-            channel=GetPixelChannelChannel(image,i);
-            traits=GetPixelChannelTraits(image,channel);
-            swirl_traits=GetPixelChannelTraits(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;
@@ -5197,8 +5152,8 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
           factor=1.0-sqrt((double) distance)/radius;
           sine=sin((double) (degrees*factor*factor));
           cosine=cos((double) (degrees*factor*factor));
-          status=InterpolatePixelChannels(image,image_view,swirl_image,method,
-            ((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
+          status=InterpolatePixelChannels(image,interpolate_view,swirl_image,
+            method,((cosine*delta.x-sine*delta.y)/scale.x+center.x),(double)
             ((sine*delta.x+cosine*delta.y)/scale.y+center.y),q,exception);
         }
       p+=GetPixelChannels(image);
@@ -5220,6 +5175,7 @@ MagickExport Image *SwirlImage(const Image *image,double degrees,
       }
   }
   swirl_view=DestroyCacheView(swirl_view);
+  interpolate_view=DestroyCacheView(interpolate_view);
   image_view=DestroyCacheView(image_view);
   if (status == MagickFalse)
     swirl_image=DestroyImage(swirl_image);
@@ -5266,6 +5222,9 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
     *image_view,
     *tint_view;
 
+  double
+    intensity;
+
   GeometryInfo
     geometry_info;
 
@@ -5278,9 +5237,6 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   MagickOffsetType
     progress;
 
-  double
-    intensity;
-
   PixelInfo
     color_vector;
 
@@ -5309,7 +5265,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);
   /*
@@ -5320,7 +5276,7 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
   color_vector.red=geometry_info.rho;
   color_vector.green=geometry_info.rho;
   color_vector.blue=geometry_info.rho;
-  color_vector.alpha=OpaqueAlpha;
+  color_vector.alpha=(MagickRealType) OpaqueAlpha;
   if ((flags & SigmaValue) != 0)
     color_vector.green=geometry_info.sigma;
   if ((flags & XiValue) != 0)
@@ -5336,26 +5292,21 @@ MagickExport Image *TintImage(const Image *image,const char *blend,
         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);
+  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.
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  tint_view=AcquireAuthenticCacheView(tint_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  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++)
   {
@@ -5391,21 +5342,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=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
-        tint_traits=GetPixelChannelTraits(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;
@@ -5650,13 +5594,13 @@ MagickExport Image *WaveImage(const Image *image,const double amplitude,
   */
   status=MagickTrue;
   progress=0;
-  image_view=AcquireVirtualCacheView(image);
-  wave_view=AcquireAuthenticCacheView(wave_image);
+  image_view=AcquireVirtualCacheView(image,exception);
+  wave_view=AcquireAuthenticCacheView(wave_image,exception);
   (void) SetCacheViewVirtualPixelMethod(image_view,
     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++)
   {