@@ -1633,24 +1633,26 @@ static MagickBooleanType GetRootMeanSquaredDistortion(const Image *image,
1633
1633
const Image * reconstruct_image ,const ChannelType channel ,double * distortion ,
1634
1634
ExceptionInfo * exception )
1635
1635
{
1636
+ #define RMSESquareRoot (x ) sqrt((x) < 0.0 ? 0.0 : (x))
1637
+
1636
1638
MagickBooleanType
1637
1639
status ;
1638
1640
1639
1641
status = GetMeanSquaredDistortion (image ,reconstruct_image ,channel ,distortion ,
1640
1642
exception );
1641
1643
if ((channel & RedChannel ) != 0 )
1642
- distortion [RedChannel ]= sqrt (distortion [RedChannel ]);
1644
+ distortion [RedChannel ]= RMSESquareRoot (distortion [RedChannel ]);
1643
1645
if ((channel & GreenChannel ) != 0 )
1644
- distortion [GreenChannel ]= sqrt (distortion [GreenChannel ]);
1646
+ distortion [GreenChannel ]= RMSESquareRoot (distortion [GreenChannel ]);
1645
1647
if ((channel & BlueChannel ) != 0 )
1646
- distortion [BlueChannel ]= sqrt (distortion [BlueChannel ]);
1648
+ distortion [BlueChannel ]= RMSESquareRoot (distortion [BlueChannel ]);
1647
1649
if (((channel & OpacityChannel ) != 0 ) &&
1648
1650
(image -> matte != MagickFalse ))
1649
- distortion [OpacityChannel ]= sqrt (distortion [OpacityChannel ]);
1651
+ distortion [OpacityChannel ]= RMSESquareRoot (distortion [OpacityChannel ]);
1650
1652
if (((channel & IndexChannel ) != 0 ) &&
1651
1653
(image -> colorspace == CMYKColorspace ))
1652
- distortion [BlackChannel ]= sqrt (distortion [BlackChannel ]);
1653
- distortion [CompositeChannels ]= sqrt (distortion [CompositeChannels ]);
1654
+ distortion [BlackChannel ]= RMSESquareRoot (distortion [BlackChannel ]);
1655
+ distortion [CompositeChannels ]= RMSESquareRoot (distortion [CompositeChannels ]);
1654
1656
return (status );
1655
1657
}
1656
1658
0 commit comments