const double luma,double *red,double *green,double *blue)
{
double
- b,
- c,
- g,
- h,
- m,
- r,
- x;
+ C,
+ H,
+ L,
+ u,
+ v,
+ X,
+ Y,
+ Z;
/*
Convert HCL to RGB colorspace.
assert(red != (double *) NULL);
assert(green != (double *) NULL);
assert(blue != (double *) NULL);
- h=6.0*hue;
- c=chroma;
- x=c*(1.0-fabs(fmod(h,2.0)-1.0));
- r=0.0;
- g=0.0;
- b=0.0;
- if ((0.0 <= h) && (h < 1.0))
- {
- r=c;
- g=x;
- }
- else
- if ((1.0 <= h) && (h < 2.0))
- {
- r=x;
- g=c;
- }
- else
- if ((2.0 <= h) && (h < 3.0))
- {
- g=c;
- b=x;
- }
- else
- if ((3.0 <= h) && (h < 4.0))
- {
- g=x;
- b=c;
- }
- else
- if ((4.0 <= h) && (h < 5.0))
- {
- r=x;
- b=c;
- }
- else
- if ((5.0 <= h) && (h < 6.0))
- {
- r=c;
- b=x;
- }
- m=luma-(0.298839f*r+0.586811f*g+0.114350f*b);
- *red=QuantumRange*(r+m);
- *green=QuantumRange*(g+m);
- *blue=QuantumRange*(b+m);
+ L=luma;
+ C=chroma;
+ H=hue;
+ u=C*cos(360.0*H*MagickPI/180.0)+134.0/354.0;
+ v=C*sin(360.0*H*MagickPI/180.0)+140.0/262.0;
+ ConvertLuvToXYZ(L,u,v,&X,&Y,&Z);
+ ConvertXYZToRGB(X,Y,Z,red,green,blue);
}
\f
/*
% component of the HCL color space.
%
*/
-
-static inline double MagickMax(const double x,const double y)
-{
- if (x > y)
- return(x);
- return(y);
-}
-
-static inline double MagickMin(const double x,const double y)
-{
- if (x < y)
- return(x);
- return(y);
-}
-
MagickPrivate void ConvertRGBToHCL(const double red,const double green,
const double blue,double *hue,double *chroma,double *luma)
{
double
- b,
- c,
- g,
- h,
- max,
- r;
+ C,
+ H,
+ L,
+ u,
+ v,
+ X,
+ Y,
+ Z;
/*
Convert RGB to HCL colorspace.
*/
- assert(hue != (double *) NULL);
- assert(chroma != (double *) NULL);
assert(luma != (double *) NULL);
- r=red;
- g=green;
- b=blue;
- max=MagickMax(r,MagickMax(g,b));
- c=max-(double) MagickMin(r,MagickMin(g,b));
- h=0.0;
- if (c == 0.0)
- h=0.0;
- else
- if (red == max)
- h=fmod((g-b)/c+6.0,6.0);
- else
- if (green == max)
- h=((b-r)/c)+2.0;
- else
- if (blue == max)
- h=((r-g)/c)+4.0;
- *hue=(h/6.0);
- *chroma=QuantumScale*c;
- *luma=QuantumScale*(0.298839f*r+0.586811f*g+0.114350f*b);
+ assert(chroma != (double *) NULL);
+ assert(hue != (double *) NULL);
+ ConvertRGBToXYZ(red,green,blue,&X,&Y,&Z);
+ ConvertXYZToLuv(X,Y,Z,&L,&u,&v);
+ C=hypot(u-134.0/254.0,v-140.0/262.0);
+ H=180.0*atan2(v-140.0/262.0,u-134.0/254.0)/MagickPI/360.0;
+ if (H < 0.0)
+ H+=1.0;
+ if (H >= 1.0)
+ H-=1.0;
+ *luma=L;
+ *chroma=C;
+ *hue=H;
}
\f
/*
% component of the HSL color space.
%
*/
+
+static inline double MagickMax(const double x,const double y)
+{
+ if (x > y)
+ return(x);
+ return(y);
+}
+
+static inline double MagickMin(const double x,const double y)
+{
+ if (x < y)
+ return(x);
+ return(y);
+}
+
MagickExport void ConvertRGBToHSL(const double red,const double green,
const double blue,double *hue,double *saturation,double *lightness)
{
Z;
/*
- Convert RGB to LCH colorspace.
+ Convert RGB to LCHab colorspace.
*/
assert(luma != (double *) NULL);
assert(chroma != (double *) NULL);
Z;
/*
- Convert RGB to LCH colorspace.
+ Convert RGB to LCHuv colorspace.
*/
assert(luma != (double *) NULL);
assert(chroma != (double *) NULL);