From: cristy Date: Wed, 29 Aug 2012 17:22:14 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~5030 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1f09931ef28c09bca4a5faa2b7e46ee5c496ce76;p=imagemagick --- diff --git a/MagickCore/colorspace.c b/MagickCore/colorspace.c index 57e8d8231..b4d160089 100644 --- a/MagickCore/colorspace.c +++ b/MagickCore/colorspace.c @@ -751,6 +751,81 @@ static MagickBooleanType sRGBTransformImage(Image *image, return(MagickFalse); return(status); } + case LCHColorspace: + { + /* + Transform image from sRGB to LCH. + */ + 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,4) shared(status) \ + dynamic_number_threads(image,image->columns,image->rows,1) +#endif + for (y=0; y < (ssize_t) image->rows; y++) + { + MagickBooleanType + sync; + + register ssize_t + x; + + register Quantum + *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++) + { + double + a, + b, + blue, + C, + green, + H, + L, + red, + X, + Y, + Z; + + red=InversesRGBCompandor((double) GetPixelRed(image,q)); + green=InversesRGBCompandor((double) GetPixelGreen(image,q)); + blue=InversesRGBCompandor((double) GetPixelBlue(image,q)); + ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z); + ConvertXYZToLab(X,Y,Z,&L,&a,&b); + C=sqrt(a*a+b*b); + H=atan2(b,a)*180.0/MagickPI; + if (H < 0.0) + H+=1.0; + SetPixelRed(image,ClampToQuantum(QuantumRange*L),q); + SetPixelGreen(image,ClampToQuantum(QuantumRange*C),q); + SetPixelBlue(image,ClampToQuantum(QuantumRange*H),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); + return(status); + } case LogColorspace: { #define DisplayGamma (1.0/1.7) @@ -2549,6 +2624,79 @@ static MagickBooleanType TransformsRGBImage(Image *image, return(MagickFalse); return(status); } + case LCHColorspace: + { + /* + Transform image from LCH to sRGB. + */ + 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,4) shared(status) \ + dynamic_number_threads(image,image->columns,image->rows,1) +#endif + for (y=0; y < (ssize_t) image->rows; y++) + { + MagickBooleanType + sync; + + register ssize_t + x; + + register Quantum + *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++) + { + double + a, + b, + blue, + C, + green, + H, + L, + red, + X, + Y, + Z; + + L=QuantumScale*GetPixelRed(image,q); + C=QuantumScale*GetPixelGreen(image,q); + H=QuantumScale*GetPixelBlue(image,q); + a=C*cos(H*(MagickPI/180.0)); + b=C*sin(H*(MagickPI/180.0)); + ConvertLabToXYZ(L,a,b,&X,&Y,&Z); + ConvertXYZToRGB(X,Y,Z,&red,&green,&blue); + SetPixelRed(image,ClampToQuantum(sRGBCompandor(red)),q); + SetPixelGreen(image,ClampToQuantum(sRGBCompandor(green)),q); + SetPixelBlue(image,ClampToQuantum(sRGBCompandor(blue)),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 LogColorspace: { const char diff --git a/MagickCore/colorspace.h b/MagickCore/colorspace.h index 0442d8ae1..321b4a69f 100644 --- a/MagickCore/colorspace.h +++ b/MagickCore/colorspace.h @@ -33,6 +33,7 @@ typedef enum HSLColorspace, HWBColorspace, LabColorspace, + LCHColorspace, LogColorspace, LuvColorspace, OHTAColorspace, diff --git a/MagickCore/option.c b/MagickCore/option.c index 1e4d824da..9b081ea78 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -870,6 +870,7 @@ static const OptionInfo { "HSL", HSLColorspace, UndefinedOptionFlag, MagickFalse }, { "HWB", HWBColorspace, UndefinedOptionFlag, MagickFalse }, { "Lab", LabColorspace, UndefinedOptionFlag, MagickFalse }, + { "LCH", LCHColorspace, UndefinedOptionFlag, MagickFalse }, { "Log", LogColorspace, UndefinedOptionFlag, MagickFalse }, { "Luv", LuvColorspace, UndefinedOptionFlag, MagickFalse }, { "OHTA", OHTAColorspace, UndefinedOptionFlag, MagickFalse },