diff --git a/MagickCore/compare.c b/MagickCore/compare.c
index 6d638e0..a2f9b30 100644
--- a/MagickCore/compare.c
+++ b/MagickCore/compare.c
@@ -1631,12 +1631,12 @@
           offset->x=x;
           offset->y=y;
         }
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelMask(similarity_image,q) != 0)
         {
-          q+=GetPixelChannels(image);
+          q+=GetPixelChannels(similarity_image);
           continue;
         }
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      for (i=0; i < (ssize_t) GetPixelChannels(similarity_image); i++)
       {
         PixelChannel
           channel;
diff --git a/MagickCore/composite.c b/MagickCore/composite.c
index b12212d..71acbb3 100644
--- a/MagickCore/composite.c
+++ b/MagickCore/composite.c
@@ -392,13 +392,13 @@
               Sc: source color.
               Dc: destination color.
           */
-          (void) GetOneVirtualPixel(composite_image,x-x_offset,y-y_offset,
-            source,exception);
           if (GetPixelMask(image,q) != 0)
             {
               q+=GetPixelChannels(image);
               continue;
             }
+          (void) GetOneVirtualPixel(composite_image,x-x_offset,y-y_offset,
+            source,exception);
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
             PixelChannel
@@ -424,6 +424,15 @@
           Sa:  normalized source alpha.
           Da:  normalized destination alpha.
       */
+      if (GetPixelMask(composite_image,p) != 0)
+        {
+          p+=GetPixelChannels(composite_image);
+          channels=GetPixelChannels(composite_image);
+          if (p >= (pixels+channels*composite_image->columns))
+            p=pixels;
+          q+=GetPixelChannels(image);
+          continue;
+        }
       Sa=QuantumScale*GetPixelAlpha(composite_image,p);
       Da=QuantumScale*GetPixelAlpha(image,q);
       alpha=Sa*(-Da)+Sa+Da;
diff --git a/MagickCore/effect.c b/MagickCore/effect.c
index 6459f39..e396ba4 100644
--- a/MagickCore/effect.c
+++ b/MagickCore/effect.c
@@ -674,13 +674,13 @@
         break;
       center=(ssize_t) GetPixelChannels(image)*(width-j)*
         ((width-j)/2L)+GetPixelChannels(image)*((width-j)/2);
-      if (GetPixelMask(image,q) != 0)
+      if (GetPixelMask(sharp_image,q) != 0)
         {
           q+=GetPixelChannels(sharp_image);
           r+=GetPixelChannels(edge_image);
           continue;
         }
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      for (i=0; i < (ssize_t) GetPixelChannels(sharp_image); i++)
       {
         MagickRealType
           alpha,
diff --git a/MagickCore/enhance.c b/MagickCore/enhance.c
index a574ee9..8b4eda5 100644
--- a/MagickCore/enhance.c
+++ b/MagickCore/enhance.c
@@ -1101,7 +1101,7 @@
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status)
 #endif
-  for (i=0; i < number_channels; i++)
+  for (i=0; i < (ssize_t) number_channels; i++)
   {
     double
       intensity;
@@ -1590,7 +1590,7 @@
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(static,4) shared(progress,status)
 #endif
-  for (i=0; i < (size_t) number_channels; i++)
+  for (i=0; i < (ssize_t) number_channels; i++)
   {
     MagickRealType
       intensity;
@@ -1834,16 +1834,16 @@
       for (i=0; i < (ssize_t) image->colors; i++)
       {
         if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0)
-          image->colormap[i].red=gamma_map[
+          image->colormap[i].red=(MagickRealType) gamma_map[
             ScaleQuantumToMap(ClampToQuantum(image->colormap[i].red))];
         if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0)
-          image->colormap[i].green=gamma_map[
+          image->colormap[i].green=(MagickRealType) gamma_map[
             ScaleQuantumToMap(ClampToQuantum(image->colormap[i].green))];
         if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0)
-          image->colormap[i].blue=gamma_map[
+          image->colormap[i].blue=(MagickRealType) gamma_map[
             ScaleQuantumToMap(ClampToQuantum(image->colormap[i].blue))];
         if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
-          image->colormap[i].alpha=gamma_map[
+          image->colormap[i].alpha=(MagickRealType) gamma_map[
             ScaleQuantumToMap(ClampToQuantum(image->colormap[i].alpha))];
       }
     }
diff --git a/MagickCore/statistic.c b/MagickCore/statistic.c
index b9c7150..fd46f89 100644
--- a/MagickCore/statistic.c
+++ b/MagickCore/statistic.c
@@ -659,9 +659,9 @@
             register ssize_t
               i;
 
-            if (GetPixelMask(evaluate_image,p) != 0)
+            if (GetPixelMask(next,p) != 0)
               {
-                p+=GetPixelChannels(evaluate_image);
+                p+=GetPixelChannels(next);
                 continue;
               }
             for (i=0; i < (ssize_t) GetPixelChannels(next); i++)
diff --git a/MagickCore/threshold.c b/MagickCore/threshold.c
index 535559c..a1420e9 100644
--- a/MagickCore/threshold.c
+++ b/MagickCore/threshold.c
@@ -567,12 +567,12 @@
       ssize_t
         n;
 
-      n=0;
       if (GetPixelMask(image,q) != 0)
         {
           q+=GetPixelChannels(image);
           continue;
         }
+      n=0;
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         PixelChannel
diff --git a/MagickCore/transform.c b/MagickCore/transform.c
index fa99fce..0969de2 100644
--- a/MagickCore/transform.c
+++ b/MagickCore/transform.c
@@ -190,11 +190,6 @@
           register ssize_t
             i;
 
-          if (GetPixelMask(image,p) != 0)
-            {
-              q+=GetPixelChannels(chop_image);
-              continue;
-            }
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
             PixelChannel
@@ -266,12 +261,6 @@
           register ssize_t
             i;
 
-         if (GetPixelMask(image,p) != 0)
-           {
-             p+=GetPixelChannels(image);
-             q+=GetPixelChannels(chop_image);
-             continue;
-           }
           for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
           {
             PixelChannel