]> granicus.if.org Git - imagemagick/blobdiff - magick/compare.c
(no commit message)
[imagemagick] / magick / compare.c
index 8f354cb5bd3b8913d8f10b29af0ae6758e5c5758..a48fcf80484e3d5db100380ee0320870c8d80175 100644 (file)
@@ -110,7 +110,7 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
   Image
     *highlight_image;
 
-  highlight_image=CompareImageChannels(image,reconstruct_image,AllChannels,
+  highlight_image=CompareImageChannels(image,reconstruct_image,CompositeChannels,
     metric,distortion,exception);
   return(highlight_image);
 }
@@ -255,26 +255,31 @@ MagickExport Image *CompareImageChannels(Image *image,
       SetMagickPixelPacket(reconstruct_image,q,reconstruct_indexes+x,
         &reconstruct_pixel);
       difference=MagickFalse;
-      if (channel == AllChannels)
+      if (channel == CompositeChannels)
         {
           if (IsMagickColorSimilar(&pixel,&reconstruct_pixel) == MagickFalse)
             difference=MagickTrue;
         }
       else
         {
-          if (((channel & RedChannel) != 0) && (GetRedPixelComponent(p) != q->red))
+          if (((channel & RedChannel) != 0) &&
+              (GetRedPixelComponent(p) != GetRedPixelComponent(q)))
             difference=MagickTrue;
-          if (((channel & GreenChannel) != 0) && (GetGreenPixelComponent(p) != q->green))
+          if (((channel & GreenChannel) != 0) &&
+              (GetGreenPixelComponent(p) != GetGreenPixelComponent(q)))
             difference=MagickTrue;
-          if (((channel & BlueChannel) != 0) && (GetBluePixelComponent(p) != q->blue))
+          if (((channel & BlueChannel) != 0) &&
+              (GetBluePixelComponent(p) != GetBluePixelComponent(q)))
             difference=MagickTrue;
           if (((channel & OpacityChannel) != 0) &&
-              (image->matte != MagickFalse) && (GetOpacityPixelComponent(p) != q->opacity))
+              (image->matte != MagickFalse) &&
+              (GetOpacityPixelComponent(p) != GetOpacityPixelComponent(q)))
             difference=MagickTrue;
           if ((((channel & IndexChannel) != 0) &&
                (image->colorspace == CMYKColorspace) &&
                (reconstruct_image->colorspace == CMYKColorspace)) &&
-              (indexes[x] != reconstruct_indexes[x]))
+              (GetIndexPixelComponent(indexes+x) !=
+               GetIndexPixelComponent(reconstruct_indexes+x)))
             difference=MagickTrue;
         }
       if (difference != MagickFalse)
@@ -342,7 +347,7 @@ MagickExport MagickBooleanType GetImageDistortion(Image *image,
   MagickBooleanType
     status;
 
-  status=GetImageChannelDistortion(image,reconstruct_image,AllChannels,
+  status=GetImageChannelDistortion(image,reconstruct_image,CompositeChannels,
     metric,distortion,exception);
   return(status);
 }
@@ -377,7 +382,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     double
-      channel_distortion[AllChannels+1];
+      channel_distortion[CompositeChannels+1];
 
     MagickPixelPacket
       pixel,
@@ -429,7 +434,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
           if (((channel & IndexChannel) != 0) &&
               (image->colorspace == CMYKColorspace))
             channel_distortion[BlackChannel]++;
-          channel_distortion[AllChannels]++;
+          channel_distortion[CompositeChannels]++;
         }
       p++;
       q++;
@@ -437,7 +442,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetAbsoluteError)
 #endif
-    for (i=0; i <= (ssize_t) AllChannels; i++)
+    for (i=0; i <= (ssize_t) CompositeChannels; i++)
       distortion[i]+=channel_distortion[i];
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
@@ -493,7 +498,7 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     double
-      channel_distortion[AllChannels+1];
+      channel_distortion[CompositeChannels+1];
 
     register const IndexPacket
       *restrict indexes,
@@ -527,39 +532,43 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
 
       if ((channel & RedChannel) != 0)
         {
-          distance=QuantumScale*(GetRedPixelComponent(p)-(MagickRealType) q->red);
+          distance=QuantumScale*(GetRedPixelComponent(p)-(MagickRealType)
+            GetRedPixelComponent(q));
           channel_distortion[RedChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if ((channel & GreenChannel) != 0)
         {
-          distance=QuantumScale*(GetGreenPixelComponent(p)-(MagickRealType) q->green);
+          distance=QuantumScale*(GetGreenPixelComponent(p)-(MagickRealType)
+            GetGreenPixelComponent(q));
           channel_distortion[GreenChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if ((channel & BlueChannel) != 0)
         {
-          distance=QuantumScale*(GetBluePixelComponent(p)-(MagickRealType) q->blue);
+          distance=QuantumScale*(GetBluePixelComponent(p)-(MagickRealType)
+            GetBluePixelComponent(q));
           channel_distortion[BlueChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if (((channel & OpacityChannel) != 0) && ((image->matte != MagickFalse) ||
           (reconstruct_image->matte != MagickFalse)))
         {
-          distance=QuantumScale*((image->matte != MagickFalse ? GetOpacityPixelComponent(p) :
-            OpaqueOpacity)-(reconstruct_image->matte != MagickFalse ?
-            q->opacity : OpaqueOpacity));
+          distance=QuantumScale*((image->matte != MagickFalse ?
+            GetOpacityPixelComponent(p) : OpaqueOpacity)-
+            (reconstruct_image->matte != MagickFalse ?
+            GetOpacityPixelComponent(q): OpaqueOpacity));
           channel_distortion[OpacityChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if (((channel & IndexChannel) != 0) &&
           (image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
         {
-          distance=QuantumScale*(indexes[x]-(MagickRealType)
-            reconstruct_indexes[x]);
+          distance=QuantumScale*(GetIndexPixelComponent(indexes+x)-
+            (MagickRealType) GetIndexPixelComponent(reconstruct_indexes+x));
           channel_distortion[BlackChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       p++;
       q++;
@@ -567,19 +576,19 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetMeanSquaredError)
 #endif
-    for (i=0; i <= (ssize_t) AllChannels; i++)
+    for (i=0; i <= (ssize_t) CompositeChannels; i++)
       distortion[i]+=channel_distortion[i];
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  for (i=0; i <= (ssize_t) AllChannels; i++)
+  for (i=0; i <= (ssize_t) CompositeChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
   if (((channel & OpacityChannel) != 0) && ((image->matte != MagickFalse) ||
       (reconstruct_image->matte != MagickFalse)))
-    distortion[AllChannels]/=(double) (GetNumberChannels(image,channel)-1);
+    distortion[CompositeChannels]/=(double) (GetNumberChannels(image,channel)-1);
   else
-    distortion[AllChannels]/=(double) GetNumberChannels(image,channel);
-  distortion[AllChannels]=sqrt(distortion[AllChannels]);
+    distortion[CompositeChannels]/=(double) GetNumberChannels(image,channel);
+  distortion[CompositeChannels]=sqrt(distortion[CompositeChannels]);
   return(status);
 }
 
@@ -609,7 +618,7 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     double
-      channel_distortion[AllChannels+1];
+      channel_distortion[CompositeChannels+1];
 
     register const IndexPacket
       *restrict indexes,
@@ -643,36 +652,40 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
 
       if ((channel & RedChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetRedPixelComponent(p)-(double) q->red);
+          distance=QuantumScale*fabs(GetRedPixelComponent(p)-(double)
+            GetRedPixelComponent(q));
           channel_distortion[RedChannel]+=distance;
-          channel_distortion[AllChannels]+=distance;
+          channel_distortion[CompositeChannels]+=distance;
         }
       if ((channel & GreenChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetGreenPixelComponent(p)-(double) q->green);
+          distance=QuantumScale*fabs(GetGreenPixelComponent(p)-(double)
+            GetGreenPixelComponent(q));
           channel_distortion[GreenChannel]+=distance;
-          channel_distortion[AllChannels]+=distance;
+          channel_distortion[CompositeChannels]+=distance;
         }
       if ((channel & BlueChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetBluePixelComponent(p)-(double) q->blue);
+          distance=QuantumScale*fabs(GetBluePixelComponent(p)-(double)
+            GetBluePixelComponent(q));
           channel_distortion[BlueChannel]+=distance;
-          channel_distortion[AllChannels]+=distance;
+          channel_distortion[CompositeChannels]+=distance;
         }
       if (((channel & OpacityChannel) != 0) &&
           (image->matte != MagickFalse))
         {
-          distance=QuantumScale*fabs(GetOpacityPixelComponent(p)-(double) q->opacity);
+          distance=QuantumScale*fabs(GetOpacityPixelComponent(p)-(double)
+            GetOpacityPixelComponent(q));
           channel_distortion[OpacityChannel]+=distance;
-          channel_distortion[AllChannels]+=distance;
+          channel_distortion[CompositeChannels]+=distance;
         }
       if (((channel & IndexChannel) != 0) &&
           (image->colorspace == CMYKColorspace))
         {
-          distance=QuantumScale*fabs(indexes[x]-(double)
-            reconstruct_indexes[x]);
+          distance=QuantumScale*fabs(GetIndexPixelComponent(indexes+x)-(double)
+            GetIndexPixelComponent(reconstruct_indexes+x));
           channel_distortion[BlackChannel]+=distance;
-          channel_distortion[AllChannels]+=distance;
+          channel_distortion[CompositeChannels]+=distance;
         }
       p++;
       q++;
@@ -680,14 +693,14 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetMeanAbsoluteError)
 #endif
-    for (i=0; i <= (ssize_t) AllChannels; i++)
+    for (i=0; i <= (ssize_t) CompositeChannels; i++)
       distortion[i]+=channel_distortion[i];
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  for (i=0; i <= (ssize_t) AllChannels; i++)
+  for (i=0; i <= (ssize_t) CompositeChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
-  distortion[AllChannels]/=(double) GetNumberChannels(image,channel);
+  distortion[CompositeChannels]/=(double) GetNumberChannels(image,channel);
   return(status);
 }
 
@@ -757,9 +770,10 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
         }
       if ((channel & RedChannel) != 0)
         {
-          distance=fabs(alpha*GetRedPixelComponent(p)-beta*q->red);
+          distance=fabs(alpha*GetRedPixelComponent(p)-beta*
+            GetRedPixelComponent(q));
           distortion[RedChannel]+=distance;
-          distortion[AllChannels]+=distance;
+          distortion[CompositeChannels]+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
             maximum_error=distance;
@@ -767,9 +781,10 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
         }
       if ((channel & GreenChannel) != 0)
         {
-          distance=fabs(alpha*GetGreenPixelComponent(p)-beta*q->green);
+          distance=fabs(alpha*GetGreenPixelComponent(p)-beta*
+            GetGreenPixelComponent(q));
           distortion[GreenChannel]+=distance;
-          distortion[AllChannels]+=distance;
+          distortion[CompositeChannels]+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
             maximum_error=distance;
@@ -777,9 +792,10 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
         }
       if ((channel & BlueChannel) != 0)
         {
-          distance=fabs(alpha*GetBluePixelComponent(p)-beta*q->blue);
+          distance=fabs(alpha*GetBluePixelComponent(p)-beta*
+            GetBluePixelComponent(q));
           distortion[BlueChannel]+=distance;
-          distortion[AllChannels]+=distance;
+          distortion[CompositeChannels]+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
             maximum_error=distance;
@@ -788,9 +804,10 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
       if (((channel & OpacityChannel) != 0) &&
           (image->matte != MagickFalse))
         {
-          distance=fabs((double) GetOpacityPixelComponent(p)-q->opacity);
+          distance=fabs((double) GetOpacityPixelComponent(p)-
+            GetOpacityPixelComponent(q));
           distortion[OpacityChannel]+=distance;
-          distortion[AllChannels]+=distance;
+          distortion[CompositeChannels]+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
             maximum_error=distance;
@@ -800,9 +817,10 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
           (image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
         {
-          distance=fabs(alpha*indexes[x]-beta*reconstruct_indexes[x]);
+          distance=fabs(alpha*GetIndexPixelComponent(indexes+x)-beta*
+            GetIndexPixelComponent(reconstruct_indexes+x));
           distortion[BlackChannel]+=distance;
-          distortion[AllChannels]+=distance;
+          distortion[CompositeChannels]+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
             maximum_error=distance;
@@ -814,7 +832,7 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  image->error.mean_error_per_pixel=distortion[AllChannels]/area;
+  image->error.mean_error_per_pixel=distortion[CompositeChannels]/area;
   image->error.normalized_mean_error=QuantumScale*QuantumScale*mean_error/area;
   image->error.normalized_maximum_error=QuantumScale*maximum_error;
   return(status);
@@ -846,7 +864,7 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     double
-      channel_distortion[AllChannels+1];
+      channel_distortion[CompositeChannels+1];
 
     register const IndexPacket
       *restrict indexes,
@@ -880,37 +898,41 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
 
       if ((channel & RedChannel) != 0)
         {
-          distance=QuantumScale*(GetRedPixelComponent(p)-(MagickRealType) q->red);
+          distance=QuantumScale*(GetRedPixelComponent(p)-(MagickRealType)
+            GetRedPixelComponent(q));
           channel_distortion[RedChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if ((channel & GreenChannel) != 0)
         {
-          distance=QuantumScale*(GetGreenPixelComponent(p)-(MagickRealType) q->green);
+          distance=QuantumScale*(GetGreenPixelComponent(p)-(MagickRealType)
+            GetGreenPixelComponent(q));
           channel_distortion[GreenChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if ((channel & BlueChannel) != 0)
         {
-          distance=QuantumScale*(GetBluePixelComponent(p)-(MagickRealType) q->blue);
+          distance=QuantumScale*(GetBluePixelComponent(p)-(MagickRealType)
+            GetBluePixelComponent(q));
           channel_distortion[BlueChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if (((channel & OpacityChannel) != 0) &&
           (image->matte != MagickFalse))
         {
-          distance=QuantumScale*(GetOpacityPixelComponent(p)-(MagickRealType) q->opacity);
+          distance=QuantumScale*(GetOpacityPixelComponent(p)-(MagickRealType)
+            GetOpacityPixelComponent(q));
           channel_distortion[OpacityChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       if (((channel & IndexChannel) != 0) &&
           (image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
         {
-          distance=QuantumScale*(indexes[x]-(MagickRealType)
-            reconstruct_indexes[x]);
+          distance=QuantumScale*(GetIndexPixelComponent(indexes+x)-
+            (MagickRealType) GetIndexPixelComponent(reconstruct_indexes+x));
           channel_distortion[BlackChannel]+=distance*distance;
-          channel_distortion[AllChannels]+=distance*distance;
+          channel_distortion[CompositeChannels]+=distance*distance;
         }
       p++;
       q++;
@@ -918,14 +940,14 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetMeanSquaredError)
 #endif
-    for (i=0; i <= (ssize_t) AllChannels; i++)
+    for (i=0; i <= (ssize_t) CompositeChannels; i++)
       distortion[i]+=channel_distortion[i];
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  for (i=0; i <= (ssize_t) AllChannels; i++)
+  for (i=0; i <= (ssize_t) CompositeChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
-  distortion[AllChannels]/=(double) GetNumberChannels(image,channel);
+  distortion[CompositeChannels]/=(double) GetNumberChannels(image,channel);
   return(status);
 }
 
@@ -965,7 +987,7 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
   reconstruct_statistics=GetImageChannelStatistics(reconstruct_image,exception);
   status=MagickTrue;
   progress=0;
-  for (i=0; i <= (ssize_t) AllChannels; i++)
+  for (i=0; i <= (ssize_t) CompositeChannels; i++)
     distortion[i]=0.0;
   area=1.0/((MagickRealType) image->columns*image->rows);
   image_view=AcquireCacheView(image);
@@ -999,26 +1021,29 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
     {
       if ((channel & RedChannel) != 0)
         distortion[RedChannel]+=area*QuantumScale*(GetRedPixelComponent(p)-
-          image_statistics[RedChannel].mean)*(q->red-
+          image_statistics[RedChannel].mean)*(GetRedPixelComponent(q)-
           reconstruct_statistics[RedChannel].mean);
       if ((channel & GreenChannel) != 0)
         distortion[GreenChannel]+=area*QuantumScale*(GetGreenPixelComponent(p)-
-          image_statistics[GreenChannel].mean)*(q->green-
+          image_statistics[GreenChannel].mean)*(GetGreenPixelComponent(q)-
           reconstruct_statistics[GreenChannel].mean);
       if ((channel & BlueChannel) != 0)
         distortion[BlueChannel]+=area*QuantumScale*(GetBluePixelComponent(p)-
-          image_statistics[BlueChannel].mean)*(q->blue-
+          image_statistics[BlueChannel].mean)*(GetBluePixelComponent(q)-
           reconstruct_statistics[BlueChannel].mean);
       if (((channel & OpacityChannel) != 0) &&
           (image->matte != MagickFalse))
-        distortion[OpacityChannel]+=area*QuantumScale*(GetOpacityPixelComponent(p)-
-          image_statistics[OpacityChannel].mean)*(q->opacity-
+        distortion[OpacityChannel]+=area*QuantumScale*(
+          GetOpacityPixelComponent(p)-image_statistics[OpacityChannel].mean)*
+          (GetOpacityPixelComponent(q)-
           reconstruct_statistics[OpacityChannel].mean);
       if (((channel & IndexChannel) != 0) &&
           (image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
-        distortion[BlackChannel]+=area*QuantumScale*(indexes[x]-
-          image_statistics[OpacityChannel].mean)*(reconstruct_indexes[x]-
+        distortion[BlackChannel]+=area*QuantumScale*(
+          GetIndexPixelComponent(indexes+x)-
+          image_statistics[OpacityChannel].mean)*(
+          GetIndexPixelComponent(reconstruct_indexes+x)-
           reconstruct_statistics[OpacityChannel].mean);
       p++;
       q++;
@@ -1039,7 +1064,7 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
   /*
     Divide by the standard deviation.
   */
-  for (i=0; i < (ssize_t) AllChannels; i++)
+  for (i=0; i < (ssize_t) CompositeChannels; i++)
   {
     MagickRealType
       gamma;
@@ -1049,20 +1074,20 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
     gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
     distortion[i]=QuantumRange*gamma*distortion[i];
   }
-  distortion[AllChannels]=0.0;
+  distortion[CompositeChannels]=0.0;
   if ((channel & RedChannel) != 0)
-    distortion[AllChannels]+=distortion[RedChannel]*distortion[RedChannel];
+    distortion[CompositeChannels]+=distortion[RedChannel]*distortion[RedChannel];
   if ((channel & GreenChannel) != 0)
-    distortion[AllChannels]+=distortion[GreenChannel]*distortion[GreenChannel];
+    distortion[CompositeChannels]+=distortion[GreenChannel]*distortion[GreenChannel];
   if ((channel & BlueChannel) != 0)
-    distortion[AllChannels]+=distortion[BlueChannel]*distortion[BlueChannel];
+    distortion[CompositeChannels]+=distortion[BlueChannel]*distortion[BlueChannel];
   if (((channel & OpacityChannel) != 0) && (image->matte != MagickFalse))
-    distortion[AllChannels]+=distortion[OpacityChannel]*
+    distortion[CompositeChannels]+=distortion[OpacityChannel]*
       distortion[OpacityChannel];
   if (((channel & IndexChannel) != 0) &&
       (image->colorspace == CMYKColorspace))
-    distortion[AllChannels]+=distortion[BlackChannel]*distortion[BlackChannel];
-  distortion[AllChannels]=sqrt(distortion[AllChannels]/GetNumberChannels(image,
+    distortion[CompositeChannels]+=distortion[BlackChannel]*distortion[BlackChannel];
+  distortion[CompositeChannels]=sqrt(distortion[CompositeChannels]/GetNumberChannels(image,
     channel));
   /*
     Free resources.
@@ -1097,7 +1122,7 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
   for (y=0; y < (ssize_t) image->rows; y++)
   {
     double
-      channel_distortion[AllChannels+1];
+      channel_distortion[CompositeChannels+1];
 
     register const IndexPacket
       *restrict indexes,
@@ -1131,47 +1156,51 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
 
       if ((channel & RedChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetRedPixelComponent(p)-(double) q->red);
+          distance=QuantumScale*fabs(GetRedPixelComponent(p)-(double)
+            GetRedPixelComponent(q));
           if (distance > channel_distortion[RedChannel])
             channel_distortion[RedChannel]=distance;
-          if (distance > channel_distortion[AllChannels])
-            channel_distortion[AllChannels]=distance;
+          if (distance > channel_distortion[CompositeChannels])
+            channel_distortion[CompositeChannels]=distance;
         }
       if ((channel & GreenChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetGreenPixelComponent(p)-(double) q->green);
+          distance=QuantumScale*fabs(GetGreenPixelComponent(p)-(double)
+            GetGreenPixelComponent(q));
           if (distance > channel_distortion[GreenChannel])
             channel_distortion[GreenChannel]=distance;
-          if (distance > channel_distortion[AllChannels])
-            channel_distortion[AllChannels]=distance;
+          if (distance > channel_distortion[CompositeChannels])
+            channel_distortion[CompositeChannels]=distance;
         }
       if ((channel & BlueChannel) != 0)
         {
-          distance=QuantumScale*fabs(GetBluePixelComponent(p)-(double) q->blue);
+          distance=QuantumScale*fabs(GetBluePixelComponent(p)-(double)
+            GetBluePixelComponent(q));
           if (distance > channel_distortion[BlueChannel])
             channel_distortion[BlueChannel]=distance;
-          if (distance > channel_distortion[AllChannels])
-            channel_distortion[AllChannels]=distance;
+          if (distance > channel_distortion[CompositeChannels])
+            channel_distortion[CompositeChannels]=distance;
         }
       if (((channel & OpacityChannel) != 0) &&
           (image->matte != MagickFalse))
         {
-          distance=QuantumScale*fabs(GetOpacityPixelComponent(p)-(double) q->opacity);
+          distance=QuantumScale*fabs(GetOpacityPixelComponent(p)-(double)
+            GetOpacityPixelComponent(q));
           if (distance > channel_distortion[OpacityChannel])
             channel_distortion[OpacityChannel]=distance;
-          if (distance > channel_distortion[AllChannels])
-            channel_distortion[AllChannels]=distance;
+          if (distance > channel_distortion[CompositeChannels])
+            channel_distortion[CompositeChannels]=distance;
         }
       if (((channel & IndexChannel) != 0) &&
           (image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
         {
-          distance=QuantumScale*fabs(indexes[x]-(double)
-            reconstruct_indexes[x]);
+          distance=QuantumScale*fabs(GetIndexPixelComponent(indexes+x)-(double)
+            GetIndexPixelComponent(reconstruct_indexes+x));
           if (distance > channel_distortion[BlackChannel])
             channel_distortion[BlackChannel]=distance;
-          if (distance > channel_distortion[AllChannels])
-            channel_distortion[AllChannels]=distance;
+          if (distance > channel_distortion[CompositeChannels])
+            channel_distortion[CompositeChannels]=distance;
         }
       p++;
       q++;
@@ -1179,7 +1208,7 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetPeakAbsoluteError)
 #endif
-    for (i=0; i <= (ssize_t) AllChannels; i++)
+    for (i=0; i <= (ssize_t) CompositeChannels; i++)
       if (channel_distortion[i] > distortion[i])
         distortion[i]=channel_distortion[i];
   }
@@ -1214,8 +1243,8 @@ static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image,
       (image->colorspace == CMYKColorspace))
     distortion[BlackChannel]=20.0*log10((double) 1.0/sqrt(
       distortion[BlackChannel]));
-  distortion[AllChannels]=20.0*log10((double) 1.0/sqrt(
-    distortion[AllChannels]));
+  distortion[CompositeChannels]=20.0*log10((double) 1.0/sqrt(
+    distortion[CompositeChannels]));
   return(status);
 }
 
@@ -1240,7 +1269,7 @@ static MagickBooleanType GetRootMeanSquaredDistortion(const Image *image,
   if (((channel & IndexChannel) != 0) &&
       (image->colorspace == CMYKColorspace))
     distortion[BlackChannel]=sqrt(distortion[BlackChannel]);
-  distortion[AllChannels]=sqrt(distortion[AllChannels]);
+  distortion[CompositeChannels]=sqrt(distortion[CompositeChannels]);
   return(status);
 }
 
@@ -1273,7 +1302,7 @@ MagickExport MagickBooleanType GetImageChannelDistortion(Image *image,
   /*
     Get image distortion.
   */
-  length=AllChannels+1UL;
+  length=CompositeChannels+1UL;
   channel_distortion=(double *) AcquireQuantumMemory(length,
     sizeof(*channel_distortion));
   if (channel_distortion == (double *) NULL)
@@ -1338,7 +1367,7 @@ MagickExport MagickBooleanType GetImageChannelDistortion(Image *image,
       break;
     }
   }
-  *distortion=channel_distortion[AllChannels];
+  *distortion=channel_distortion[CompositeChannels];
   channel_distortion=(double *) RelinquishMagickMemory(channel_distortion);
   return(status);
 }
@@ -1406,7 +1435,7 @@ MagickExport double *GetImageChannelDistortions(Image *image,
   /*
     Get image distortion.
   */
-  length=AllChannels+1UL;
+  length=CompositeChannels+1UL;
   channel_distortion=(double *) AcquireQuantumMemory(length,
     sizeof(*channel_distortion));
   if (channel_distortion == (double *) NULL)
@@ -1418,31 +1447,31 @@ MagickExport double *GetImageChannelDistortions(Image *image,
   {
     case AbsoluteErrorMetric:
     {
-      status=GetAbsoluteDistortion(image,reconstruct_image,AllChannels,
+      status=GetAbsoluteDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case FuzzErrorMetric:
     {
-      status=GetFuzzDistortion(image,reconstruct_image,AllChannels,
+      status=GetFuzzDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case MeanAbsoluteErrorMetric:
     {
-      status=GetMeanAbsoluteDistortion(image,reconstruct_image,AllChannels,
+      status=GetMeanAbsoluteDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case MeanErrorPerPixelMetric:
     {
-      status=GetMeanErrorPerPixel(image,reconstruct_image,AllChannels,
+      status=GetMeanErrorPerPixel(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case MeanSquaredErrorMetric:
     {
-      status=GetMeanSquaredDistortion(image,reconstruct_image,AllChannels,
+      status=GetMeanSquaredDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
@@ -1450,24 +1479,24 @@ MagickExport double *GetImageChannelDistortions(Image *image,
     default:
     {
       status=GetNormalizedCrossCorrelationDistortion(image,reconstruct_image,
-        AllChannels,channel_distortion,exception);
+        CompositeChannels,channel_distortion,exception);
       break;
     }
     case PeakAbsoluteErrorMetric:
     {
-      status=GetPeakAbsoluteDistortion(image,reconstruct_image,AllChannels,
+      status=GetPeakAbsoluteDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case PeakSignalToNoiseRatioMetric:
     {
-      status=GetPeakSignalToNoiseRatio(image,reconstruct_image,AllChannels,
+      status=GetPeakSignalToNoiseRatio(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
     case RootMeanSquaredErrorMetric:
     {
-      status=GetRootMeanSquaredDistortion(image,reconstruct_image,AllChannels,
+      status=GetRootMeanSquaredDistortion(image,reconstruct_image,CompositeChannels,
         channel_distortion,exception);
       break;
     }
@@ -1588,19 +1617,22 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image,
       MagickRealType
         distance;
 
-      distance=fabs(GetRedPixelComponent(p)-(double) q->red);
+      distance=fabs(GetRedPixelComponent(p)-(double)
+        GetRedPixelComponent(q));
       mean_error_per_pixel+=distance;
       mean_error+=distance*distance;
       if (distance > maximum_error)
         maximum_error=distance;
       area++;
-      distance=fabs(GetGreenPixelComponent(p)-(double) q->green);
+      distance=fabs(GetGreenPixelComponent(p)-(double)
+        GetGreenPixelComponent(q));
       mean_error_per_pixel+=distance;
       mean_error+=distance*distance;
       if (distance > maximum_error)
         maximum_error=distance;
       area++;
-      distance=fabs(GetBluePixelComponent(p)-(double) q->blue);
+      distance=fabs(GetBluePixelComponent(p)-(double)
+        GetBluePixelComponent(q));
       mean_error_per_pixel+=distance;
       mean_error+=distance*distance;
       if (distance > maximum_error)
@@ -1608,7 +1640,8 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image,
       area++;
       if (image->matte != MagickFalse)
         {
-          distance=fabs(GetOpacityPixelComponent(p)-(double) q->opacity);
+          distance=fabs(GetOpacityPixelComponent(p)-(double)
+            GetOpacityPixelComponent(q));
           mean_error_per_pixel+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
@@ -1618,7 +1651,8 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image,
       if ((image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
         {
-          distance=fabs(indexes[x]-(double) reconstruct_indexes[x]);
+          distance=fabs(GetIndexPixelComponent(indexes+x)-(double)
+            GetIndexPixelComponent(reconstruct_indexes+x));
           mean_error_per_pixel+=distance;
           mean_error+=distance*distance;
           if (distance > maximum_error)
@@ -1740,23 +1774,23 @@ static double GetNCCDistortion(const Image *image,
     for (x=0; x < (ssize_t) image->columns; x++)
     {
       distortion+=area*QuantumScale*(GetRedPixelComponent(p)-
-        image_statistics[RedChannel].mean)*(q->red-
+        image_statistics[RedChannel].mean)*(GetRedPixelComponent(q)-
         reconstruct_statistics[RedChannel].mean);
       distortion+=area*QuantumScale*(GetGreenPixelComponent(p)-
-        image_statistics[GreenChannel].mean)*(q->green-
+        image_statistics[GreenChannel].mean)*(GetGreenPixelComponent(q)-
         reconstruct_statistics[GreenChannel].mean);
       distortion+=area*QuantumScale*(GetBluePixelComponent(p)-
         image_statistics[BlueChannel].mean)*(q->blue-
         reconstruct_statistics[BlueChannel].mean);
       if (image->matte != MagickFalse)
         distortion+=area*QuantumScale*(GetOpacityPixelComponent(p)-
-          image_statistics[OpacityChannel].mean)*(q->opacity-
+          image_statistics[OpacityChannel].mean)*(GetOpacityPixelComponent(q)-
           reconstruct_statistics[OpacityChannel].mean);
       if ((image->colorspace == CMYKColorspace) &&
           (reconstruct_image->colorspace == CMYKColorspace))
-        distortion+=area*QuantumScale*(indexes[x]-
-          image_statistics[OpacityChannel].mean)*(reconstruct_indexes[x]-
-          reconstruct_statistics[OpacityChannel].mean);
+        distortion+=area*QuantumScale*(GetIndexPixelComponent(indexes+x)-
+          image_statistics[OpacityChannel].mean)*(GetIndexPixelComponent(
+          reconstruct_indexes+x)-reconstruct_statistics[OpacityChannel].mean);
       p++;
       q++;
     }
@@ -1766,8 +1800,8 @@ static double GetNCCDistortion(const Image *image,
   /*
     Divide by the standard deviation.
   */
-  gamma=image_statistics[AllChannels].standard_deviation*
-    reconstruct_statistics[AllChannels].standard_deviation;
+  gamma=image_statistics[CompositeChannels].standard_deviation*
+    reconstruct_statistics[CompositeChannels].standard_deviation;
   gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
   distortion=QuantumRange*gamma*distortion;
   number_channels=3;
@@ -1896,9 +1930,10 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference,
           offset->x=x;
           offset->y=y;
         }
-      q->red=ClampToQuantum(QuantumRange-QuantumRange*similarity);
-      q->green=q->red;
-      q->blue=q->red;
+      SetRedPixelComponent(q,ClampToQuantum(QuantumRange-QuantumRange*
+        similarity));
+      SetGreenPixelComponent(q,GetRedPixelComponent(q));
+      SetBluePixelComponent(q,GetRedPixelComponent(q));
       q++;
     }
     if (SyncCacheViewAuthenticPixels(similarity_view,exception) == MagickFalse)