]> granicus.if.org Git - imagemagick/commitdiff
https://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=33050
authorCristy <urban-warrior@imagemagick.org>
Sat, 18 Nov 2017 20:08:10 +0000 (15:08 -0500)
committerCristy <urban-warrior@imagemagick.org>
Sat, 18 Nov 2017 20:08:10 +0000 (15:08 -0500)
MagickCore/compare.c

index 96a104518391c2d7595df1a470ac1842590010ba..f90ef6a0388f9b853f0dcbc0dff9046702cd9e6a 100644 (file)
@@ -383,8 +383,8 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
     Compute the absolute difference in pixels between two images.
   */
   status=MagickTrue;
-  fuzz=GetFuzzyColorDistance(image,reconstruct_image);
-  fuzz*=fuzz;
+  fuzz=MagickMin(GetPixelChannels(image),GetPixelChannels(reconstruct_image))*
+    GetFuzzyColorDistance(image,reconstruct_image);
   rows=MagickMax(image->rows,reconstruct_image->rows);
   columns=MagickMax(image->columns,reconstruct_image->columns);
   image_view=AcquireVirtualCacheView(image,exception);
@@ -420,6 +420,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
     {
       double
         Da,
+        distance,
         Sa;
 
       MagickBooleanType
@@ -435,12 +436,13 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
           continue;
         }
       difference=MagickFalse;
+      distance=0.0;
       Sa=QuantumScale*GetPixelAlpha(image,p);
       Da=QuantumScale*GetPixelAlpha(reconstruct_image,q);
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         double
-          distance;
+          pixel;
 
         PixelChannel channel = GetPixelChannelChannel(image,i);
         PixelTrait traits = GetPixelChannelTraits(image,channel);
@@ -451,10 +453,11 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
             ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         if (channel == AlphaPixelChannel)
-          distance=(double) p[i]-GetPixelChannel(reconstruct_image,channel,q);
+          pixel=(double) p[i]-GetPixelChannel(reconstruct_image,channel,q);
         else
-          distance=Sa*p[i]-Da*GetPixelChannel(reconstruct_image,channel,q);
-        if ((distance*distance) > fuzz)
+          pixel=Sa*p[i]-Da*GetPixelChannel(reconstruct_image,channel,q);
+        distance+=pixel*pixel;
+        if (distance > fuzz)
           {
             channel_distortion[i]++;
             difference=MagickTrue;