]> granicus.if.org Git - imagemagick/commitdiff
https://github.com/ImageMagick/ImageMagick/issues/1680
authorCristy <urban-warrior@imagemagick.org>
Sat, 14 Sep 2019 23:56:21 +0000 (19:56 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sat, 14 Sep 2019 23:56:21 +0000 (19:56 -0400)
MagickCore/colorspace.c

index 05265432ea3efd5b12803062d2869c876681a069..c29bf37952951ae2a15f0530f15a669f4075e49d 100644 (file)
@@ -421,7 +421,8 @@ static MagickBooleanType sRGBTransformImage(Image *image,
           MagickRealType
             gray;
 
-          gray=(MagickRealType) GetPixelIntensity(image,q);
+          gray=0.212656*GetPixelRed(image,q)+0.715158*GetPixelGreen(image,q)+
+            0.072186*GetPixelBlue(image,q);
           SetPixelGray(image,ClampToQuantum(DecodePixelGamma(gray)),q);
           q+=GetPixelChannels(image);
         }
@@ -477,7 +478,8 @@ static MagickBooleanType sRGBTransformImage(Image *image,
           MagickRealType
             gray;
 
-          gray=(MagickRealType) GetPixelIntensity(image,q);
+          gray=0.212656*GetPixelRed(image,q)+0.715158*GetPixelGreen(image,q)+
+            0.072186*GetPixelBlue(image,q);
           SetPixelGray(image,ClampToQuantum(gray),q);
           q+=GetPixelChannels(image);
         }
@@ -1284,7 +1286,7 @@ MagickExport MagickBooleanType SetImageGray(Image *image,
   assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  if (IsImageGray(image) != MagickFalse)
+  if (IsImageGray(image))
     return(MagickTrue);
   if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
     return(MagickFalse);
@@ -1947,8 +1949,12 @@ static MagickBooleanType TransformsRGBImage(Image *image,
           MagickRealType
             gray;
 
-          gray=(MagickRealType) GetPixelIntensity(image,q);
-          SetPixelGray(image,ClampToQuantum(EncodePixelGamma(gray)),q);
+          gray=0.212656*GetPixelRed(image,q)+0.715158*GetPixelGreen(image,q)+
+            0.072186*GetPixelBlue(image,q);
+          gray=EncodePixelGamma(gray);
+          SetPixelRed(image,ClampToQuantum(gray),q);
+          SetPixelGreen(image,ClampToQuantum(gray),q);
+          SetPixelBlue(image,ClampToQuantum(gray),q);
           q+=GetPixelChannels(image);
         }
         sync=SyncCacheViewAuthenticPixels(image_view,exception);
@@ -2004,8 +2010,11 @@ static MagickBooleanType TransformsRGBImage(Image *image,
           MagickRealType
             gray;
 
-          gray=(MagickRealType) GetPixelIntensity(image,q);
-          SetPixelGray(image,ClampToQuantum(gray),q);
+          gray=0.212656*GetPixelRed(image,q)+0.715158*GetPixelGreen(image,q)+
+            0.072186*GetPixelBlue(image,q);
+          SetPixelRed(image,ClampToQuantum(gray),q);
+          SetPixelGreen(image,ClampToQuantum(gray),q);
+          SetPixelBlue(image,ClampToQuantum(gray),q);
           q+=GetPixelChannels(image);
         }
         sync=SyncCacheViewAuthenticPixels(image_view,exception);