Skip to content

Commit 9fd7112

Browse files
author
Cristy
committed
check for near zero
1 parent eafd854 commit 9fd7112

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

magick/compare.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,8 @@ MagickExport MagickBooleanType GetImageChannelDistortion(Image *image,
17891789
}
17901790
default: break;
17911791
}
1792+
if (fabs(*distortion) < MagickEpsilon)
1793+
*distortion=0.0;
17921794
channel_similarity=(double *) RelinquishMagickMemory(channel_similarity);
17931795
(void) FormatImageProperty(image,"distortion","%.*g",GetMagickPrecision(),
17941796
*distortion);
@@ -1841,6 +1843,9 @@ MagickExport double *GetImageChannelDistortions(Image *image,
18411843
size_t
18421844
length;
18431845

1846+
ssize_t
1847+
i;
1848+
18441849
assert(image != (Image *) NULL);
18451850
assert(image->signature == MagickCoreSignature);
18461851
assert(reconstruct_image != (const Image *) NULL);
@@ -1935,17 +1940,19 @@ MagickExport double *GetImageChannelDistortions(Image *image,
19351940
return((double *) NULL);
19361941
}
19371942
distortion=similarity;
1938-
distortion=channel_similarity;
19391943
switch (metric)
19401944
{
19411945
case NormalizedCrossCorrelationErrorMetric:
19421946
{
1943-
for (i=0; i <= MaxPixelChannels; i++)
1947+
for (i=0; i <= (ssize_t) CompositeChannels; i++)
19441948
distortion[i]=(1.0-distortion[i])/2.0;
19451949
break;
19461950
}
19471951
default: break;
19481952
}
1953+
for (i=0; i <= (ssize_t) CompositeChannels; i++)
1954+
if (fabs(distortion[i]) < MagickEpsilon)
1955+
distortion[i]=0.0;
19491956
return(distortion);
19501957
}
19511958

0 commit comments

Comments
 (0)