From: Cristy Date: Sat, 14 Sep 2019 18:53:33 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/1680 X-Git-Tag: 7.0.8-65~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=93f6510f63edc88438ac5d2c7df93899f655af73;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/1680 --- diff --git a/MagickCore/colorspace.c b/MagickCore/colorspace.c index a8abee774..05265432e 100644 --- a/MagickCore/colorspace.c +++ b/MagickCore/colorspace.c @@ -380,6 +380,61 @@ static MagickBooleanType sRGBTransformImage(Image *image, return(status); } case LinearGRAYColorspace: + { + /* + Transform image from sRGB to GRAY. + */ + if (image->storage_class == PseudoClass) + { + if (SyncImage(image,exception) == MagickFalse) + return(MagickFalse); + if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) + return(MagickFalse); + } + image_view=AcquireAuthenticCacheView(image,exception); +#if defined(MAGICKCORE_OPENMP_SUPPORT) + #pragma omp parallel for schedule(static) shared(status) \ + magick_number_threads(image,image,image->rows,1) +#endif + for (y=0; y < (ssize_t) image->rows; y++) + { + MagickBooleanType + sync; + + register ssize_t + x; + + register Quantum + *magick_restrict q; + + if (status == MagickFalse) + continue; + q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, + exception); + if (q == (Quantum *) NULL) + { + status=MagickFalse; + continue; + } + for (x=0; x < (ssize_t) image->columns; x++) + { + MagickRealType + gray; + + gray=(MagickRealType) GetPixelIntensity(image,q); + SetPixelGray(image,ClampToQuantum(DecodePixelGamma(gray)),q); + q+=GetPixelChannels(image); + } + sync=SyncCacheViewAuthenticPixels(image_view,exception); + if (sync == MagickFalse) + status=MagickFalse; + } + image_view=DestroyCacheView(image_view); + if (SetImageColorspace(image,colorspace,exception) == MagickFalse) + return(MagickFalse); + image->type=GrayscaleType; + return(status); + } case GRAYColorspace: { /* @@ -1849,6 +1904,62 @@ static MagickBooleanType TransformsRGBImage(Image *image, return(status); } case LinearGRAYColorspace: + { + /* + Transform linear GRAY to sRGB colorspace. + */ + if (image->storage_class == PseudoClass) + { + if (SyncImage(image,exception) == MagickFalse) + return(MagickFalse); + if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) + return(MagickFalse); + } + if (SetImageColorspace(image,sRGBColorspace,exception) == MagickFalse) + return(MagickFalse); + image_view=AcquireAuthenticCacheView(image,exception); +#if defined(MAGICKCORE_OPENMP_SUPPORT) + #pragma omp parallel for schedule(static) shared(status) \ + magick_number_threads(image,image,image->rows,1) +#endif + for (y=0; y < (ssize_t) image->rows; y++) + { + MagickBooleanType + sync; + + register ssize_t + x; + + register Quantum + *magick_restrict q; + + if (status == MagickFalse) + continue; + q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, + exception); + if (q == (Quantum *) NULL) + { + status=MagickFalse; + continue; + } + for (x=(ssize_t) image->columns; x != 0; x--) + { + MagickRealType + gray; + + gray=(MagickRealType) GetPixelIntensity(image,q); + SetPixelGray(image,ClampToQuantum(EncodePixelGamma(gray)),q); + q+=GetPixelChannels(image); + } + sync=SyncCacheViewAuthenticPixels(image_view,exception); + if (sync == MagickFalse) + status=MagickFalse; + } + image_view=DestroyCacheView(image_view); + if (SetImageColorspace(image,sRGBColorspace,exception) == MagickFalse) + return(MagickFalse); + return(status); + } case GRAYColorspace: { /*