From 944078a01b3d90ea67a59ef6e78a2819102a1024 Mon Sep 17 00:00:00 2001 From: Cristy Date: Sat, 18 Nov 2017 13:08:44 -0500 Subject: [PATCH] https://www.imagemagick.org/discourse-server/viewtopic.php?f=2&t=33059 --- MagickCore/profile.c | 135 +++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 82 deletions(-) diff --git a/MagickCore/profile.c b/MagickCore/profile.c index 1419f7615..0f9b06f65 100644 --- a/MagickCore/profile.c +++ b/MagickCore/profile.c @@ -337,42 +337,41 @@ MagickExport char *GetNextImageProfile(const Image *image) */ #if defined(MAGICKCORE_LCMS_DELEGATE) -static unsigned short **DestroyPixelThreadSet(unsigned short **pixels) +static double **DestroyPixelThreadSet(double **pixels) { register ssize_t i; - assert(pixels != (unsigned short **) NULL); + assert(pixels != (double **) NULL); for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) - if (pixels[i] != (unsigned short *) NULL) - pixels[i]=(unsigned short *) RelinquishMagickMemory(pixels[i]); - pixels=(unsigned short **) RelinquishMagickMemory(pixels); + if (pixels[i] != (double *) NULL) + pixels[i]=(double *) RelinquishMagickMemory(pixels[i]); + pixels=(double **) RelinquishMagickMemory(pixels); return(pixels); } -static unsigned short **AcquirePixelThreadSet(const size_t columns, +static double **AcquirePixelThreadSet(const size_t columns, const size_t channels) { + double + **pixels; + register ssize_t i; - unsigned short - **pixels; - size_t number_threads; number_threads=(size_t) GetMagickResourceLimit(ThreadResource); - pixels=(unsigned short **) AcquireQuantumMemory(number_threads, - sizeof(*pixels)); - if (pixels == (unsigned short **) NULL) - return((unsigned short **) NULL); + pixels=(double **) AcquireQuantumMemory(number_threads,sizeof(*pixels)); + if (pixels == (double **) NULL) + return((double **) NULL); (void) ResetMagickMemory(pixels,0,number_threads*sizeof(*pixels)); for (i=0; i < (ssize_t) number_threads; i++) { - pixels[i]=(unsigned short *) AcquireQuantumMemory(columns,channels* + pixels[i]=(double *) AcquireQuantumMemory(columns,channels* sizeof(**pixels)); - if (pixels[i] == (unsigned short *) NULL) + if (pixels[i] == (double *) NULL) return(DestroyPixelThreadSet(pixels)); } return(pixels); @@ -884,6 +883,12 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, source_type, target_type; + double + **magick_restrict source_pixels, + source_scale, + **magick_restrict target_pixels, + target_scale; + int intent; @@ -897,10 +902,6 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, ssize_t y; - unsigned short - **magick_restrict source_pixels, - **magick_restrict target_pixels; - target_profile=(cmsHPROFILE) NULL; if (icc_profile != (StringInfo *) NULL) { @@ -912,124 +913,94 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, ThrowProfileException(ResourceLimitError, "ColorspaceColorProfileMismatch",name); } + source_scale=1.0; + source_channels=3; switch (cmsGetColorSpace(source_profile)) { case cmsSigCmykData: { source_colorspace=CMYKColorspace; - source_type=(cmsUInt32Number) TYPE_CMYK_16; + source_type=(cmsUInt32Number) TYPE_CMYK_DBL; source_channels=4; + source_scale=100.0; break; } case cmsSigGrayData: { source_colorspace=GRAYColorspace; - source_type=(cmsUInt32Number) TYPE_GRAY_16; + source_type=(cmsUInt32Number) TYPE_GRAY_DBL; source_channels=1; break; } case cmsSigLabData: { source_colorspace=LabColorspace; - source_type=(cmsUInt32Number) TYPE_Lab_16; - source_channels=3; - break; - } - case cmsSigLuvData: - { - source_colorspace=YUVColorspace; - source_type=(cmsUInt32Number) TYPE_YUV_16; - source_channels=3; + source_type=(cmsUInt32Number) TYPE_Lab_DBL; break; } case cmsSigRgbData: { source_colorspace=sRGBColorspace; - source_type=(cmsUInt32Number) TYPE_RGB_16; - source_channels=3; + source_type=(cmsUInt32Number) TYPE_RGB_DBL; break; } case cmsSigXYZData: { source_colorspace=XYZColorspace; - source_type=(cmsUInt32Number) TYPE_XYZ_16; - source_channels=3; - break; - } - case cmsSigYCbCrData: - { - source_colorspace=YCbCrColorspace; - source_type=(cmsUInt32Number) TYPE_YCbCr_16; - source_channels=3; + source_type=(cmsUInt32Number) TYPE_XYZ_DBL; break; } default: { source_colorspace=UndefinedColorspace; - source_type=(cmsUInt32Number) TYPE_RGB_16; - source_channels=3; + source_type=(cmsUInt32Number) TYPE_RGB_DBL; break; } } signature=cmsGetPCS(source_profile); if (target_profile != (cmsHPROFILE) NULL) signature=cmsGetColorSpace(target_profile); + target_scale=1.0; + target_channels=3; switch (signature) { case cmsSigCmykData: { target_colorspace=CMYKColorspace; - target_type=(cmsUInt32Number) TYPE_CMYK_16; + target_type=(cmsUInt32Number) TYPE_CMYK_DBL; target_channels=4; + target_scale=0.01; break; } case cmsSigLabData: { target_colorspace=LabColorspace; - target_type=(cmsUInt32Number) TYPE_Lab_16; - target_channels=3; + target_type=(cmsUInt32Number) TYPE_Lab_DBL; break; } case cmsSigGrayData: { target_colorspace=GRAYColorspace; - target_type=(cmsUInt32Number) TYPE_GRAY_16; + target_type=(cmsUInt32Number) TYPE_GRAY_DBL; target_channels=1; break; } - case cmsSigLuvData: - { - target_colorspace=YUVColorspace; - target_type=(cmsUInt32Number) TYPE_YUV_16; - target_channels=3; - break; - } case cmsSigRgbData: { target_colorspace=sRGBColorspace; - target_type=(cmsUInt32Number) TYPE_RGB_16; - target_channels=3; + target_type=(cmsUInt32Number) TYPE_RGB_DBL; break; } case cmsSigXYZData: { target_colorspace=XYZColorspace; - target_type=(cmsUInt32Number) TYPE_XYZ_16; - target_channels=3; - break; - } - case cmsSigYCbCrData: - { - target_colorspace=YCbCrColorspace; - target_type=(cmsUInt32Number) TYPE_YCbCr_16; - target_channels=3; + target_type=(cmsUInt32Number) TYPE_XYZ_DBL; break; } default: { target_colorspace=UndefinedColorspace; - target_type=(cmsUInt32Number) TYPE_RGB_16; - target_channels=3; + target_type=(cmsUInt32Number) TYPE_RGB_DBL; break; } } @@ -1083,8 +1054,8 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, */ source_pixels=AcquirePixelThreadSet(image->columns,source_channels); target_pixels=AcquirePixelThreadSet(image->columns,target_channels); - if ((source_pixels == (unsigned short **) NULL) || - (target_pixels == (unsigned short **) NULL)) + if ((source_pixels == (double **) NULL) || + (target_pixels == (double **) NULL)) { transform=DestroyTransformThreadSet(transform); ThrowProfileException(ResourceLimitError, @@ -1117,14 +1088,14 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, MagickBooleanType sync; - register ssize_t - x; + register double + *p; register Quantum *magick_restrict q; - register unsigned short - *p; + register ssize_t + x; if (status == MagickFalse) continue; @@ -1138,14 +1109,14 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, p=source_pixels[id]; for (x=0; x < (ssize_t) image->columns; x++) { - *p++=ScaleQuantumToShort(GetPixelRed(image,q)); + *p++=source_scale*QuantumScale*GetPixelRed(image,q); if (source_channels > 1) { - *p++=ScaleQuantumToShort(GetPixelGreen(image,q)); - *p++=ScaleQuantumToShort(GetPixelBlue(image,q)); + *p++=source_scale*QuantumScale*GetPixelGreen(image,q); + *p++=source_scale*QuantumScale*GetPixelBlue(image,q); } if (source_channels > 3) - *p++=ScaleQuantumToShort(GetPixelBlack(image,q)); + *p++=source_scale*QuantumScale*GetPixelBlack(image,q); q+=GetPixelChannels(image); } cmsDoTransform(transform[id],source_pixels[id],target_pixels[id], @@ -1155,20 +1126,20 @@ MagickExport MagickBooleanType ProfileImage(Image *image,const char *name, for (x=0; x < (ssize_t) image->columns; x++) { if (target_channels == 1) - SetPixelGray(image,ScaleShortToQuantum(*p),q); + SetPixelGray(image,target_scale*QuantumRange*(*p),q); else - SetPixelRed(image,ScaleShortToQuantum(*p),q); + SetPixelRed(image,target_scale*QuantumRange*(*p),q); p++; if (target_channels > 1) { - SetPixelGreen(image,ScaleShortToQuantum(*p),q); + SetPixelGreen(image,target_scale*QuantumRange*(*p),q); p++; - SetPixelBlue(image,ScaleShortToQuantum(*p),q); + SetPixelBlue(image,target_scale*QuantumRange*(*p),q); p++; } if (target_channels > 3) { - SetPixelBlack(image,ScaleShortToQuantum(*p),q); + SetPixelBlack(image,target_scale*QuantumRange*(*p),q); p++; } q+=GetPixelChannels(image); -- 2.40.0