% Graphic Gems - Graphic Support Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% August 1996 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
const double intensity,double *red,double *green,double *blue)
{
double
- h;
+ b,
+ g,
+ h,
+ r;
/*
Convert HSI to RGB colorspace.
h-=360.0*floor(h/360.0);
if (h < 120.0)
{
- *blue=intensity*(1.0-saturation);
- *red=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ b=intensity*(1.0-saturation);
+ r=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
(MagickPI/180.0)));
- *green=3.0*intensity-*red-*blue;
+ g=3.0*intensity-r-b;
}
else
if (h < 240.0)
{
h-=120.0;
- *red=intensity*(1.0-saturation);
- *green=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ r=intensity*(1.0-saturation);
+ g=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
(MagickPI/180.0)));
- *blue=3.0*intensity-*red-*green;
+ b=3.0*intensity-r-g;
}
else
{
h-=240.0;
- *green=intensity*(1.0-saturation);
- *blue=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
+ g=intensity*(1.0-saturation);
+ b=intensity*(1.0+saturation*cos(h*(MagickPI/180.0))/cos((60.0-h)*
(MagickPI/180.0)));
- *red=3.0*intensity-*green-*blue;
+ r=3.0*intensity-g-b;
}
- *red*=QuantumRange;
- *green*=QuantumRange;
- *blue*=QuantumRange;
+ *red=QuantumRange*r;
+ *green=QuantumRange*g;
+ *blue=QuantumRange*b;
}
\f
/*
assert(red != (double *) NULL);
assert(green != (double *) NULL);
assert(blue != (double *) NULL);
- ConvertLCHabToXYZ(100.0*luma,255.0*(chroma-0.5),255.0*(hue-0.5),&X,&Y,&Z);
+ ConvertLCHabToXYZ(100.0*luma,255.0*(chroma-0.5),360.0*hue,&X,&Y,&Z);
ConvertXYZToRGB(X,Y,Z,red,green,blue);
}
\f
assert(red != (double *) NULL);
assert(green != (double *) NULL);
assert(blue != (double *) NULL);
- ConvertLCHuvToXYZ(100.0*luma,354.0*chroma-134.0,262.0*hue-140.0,&X,&Y,&Z);
+ ConvertLCHuvToXYZ(100.0*luma,255.0*(chroma-0.5),360.0*hue,&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;
+ max;
/*
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));
+ max=MagickMax(red,MagickMax(green,blue));
+ c=max-(double) MagickMin(red,MagickMin(green,blue));
h=0.0;
if (c == 0.0)
h=0.0;
else
if (red == max)
- h=fmod((g-b)/c+6.0,6.0);
+ h=fmod((green-blue)/c+6.0,6.0);
else
if (green == max)
- h=((b-r)/c)+2.0;
+ h=((blue-red)/c)+2.0;
else
if (blue == max)
- h=((r-g)/c)+4.0;
+ h=((red-green)/c)+4.0;
*hue=(h/6.0);
*chroma=QuantumScale*c;
- *luma=QuantumScale*(0.298839*r+0.586811*g+0.114350*b);
+ *luma=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
}
\f
/*
const double blue,double *hue,double *chroma,double *luma)
{
double
- b,
c,
- g,
h,
- max,
- r;
+ max;
/*
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));
+ max=MagickMax(red,MagickMax(green,blue));
+ c=max-MagickMin(red,MagickMin(green,blue));
h=0.0;
if (c == 0.0)
h=0.0;
else
if (red == max)
- h=fmod((g-b)/c+6.0,6.0);
+ h=fmod((green-blue)/c+6.0,6.0);
else
if (green == max)
- h=((b-r)/c)+2.0;
+ h=((blue-red)/c)+2.0;
else
if (blue == max)
- h=((r-g)/c)+4.0;
+ h=((red-green)/c)+4.0;
*hue=(h/6.0);
*chroma=QuantumScale*c;
- *luma=QuantumScale*(0.298839*r+0.586811*g+0.114350*b);
+ *luma=QuantumScale*(0.298839*red+0.586811*green+0.114350*blue);
}
\f
/*
const double blue,double *hue,double *saturation,double *brightness)
{
double
- b,
delta,
- g,
max,
- min,
- r;
+ min;
/*
Convert RGB to HSB colorspace.
*hue=0.0;
*saturation=0.0;
*brightness=0.0;
- r=red;
- g=green;
- b=blue;
- min=r < g ? r : g;
- if (b < min)
- min=b;
- max=r > g ? r : g;
- if (b > max)
- max=b;
+ min=red < green ? red : green;
+ if (blue < min)
+ min=blue;
+ max=red > green ? red : green;
+ if (blue > max)
+ max=blue;
if (max == 0.0)
return;
delta=max-min;
*brightness=QuantumScale*max;
if (delta == 0.0)
return;
- if (r == max)
- *hue=(g-b)/delta;
+ if (red == max)
+ *hue=(green-blue)/delta;
else
- if (g == max)
- *hue=2.0+(b-r)/delta;
+ if (green == max)
+ *hue=2.0+(blue-red)/delta;
else
- *hue=4.0+(r-g)/delta;
+ *hue=4.0+(red-green)/delta;
*hue/=6.0;
if (*hue < 0.0)
*hue+=1.0;
const double blue,double *hue,double *whiteness,double *blackness)
{
double
- b,
f,
- g,
p,
- r,
v,
w;
assert(hue != (double *) NULL);
assert(whiteness != (double *) NULL);
assert(blackness != (double *) NULL);
- r=red;
- g=green;
- b=blue;
- w=MagickMin(r,MagickMin(g,b));
- v=MagickMax(r,MagickMax(g,b));
+ w=MagickMin(red,MagickMin(green,blue));
+ v=MagickMax(red,MagickMax(green,blue));
*blackness=1.0-QuantumScale*v;
*whiteness=QuantumScale*w;
if (v == w)
*hue=(-1.0);
return;
}
- f=(r == w) ? g-b : ((g == w) ? b-r : r-g);
- p=(r == w) ? 3.0 : ((g == w) ? 5.0 : 1.0);
+ f=(red == w) ? green-blue : ((green == w) ? blue-red : red-green);
+ p=(red == w) ? 3.0 : ((green == w) ? 5.0 : 1.0);
*hue=(p-f/(v-1.0*w))/6.0;
}
\f
b;
ConvertXYZToLab(X,Y,Z,luma,&a,&b);
- *chroma=hypot(255.0*(a-0.5),255.0*(b-0.5));
- *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI;
+ *chroma=hypot(255.0*(a-0.5),255.0*(b-0.5))/255.0+0.5;
+ *hue=180.0*atan2(255.0*(b-0.5),255.0*(a-0.5))/MagickPI/360.0;
if (*hue < 0.0)
- *hue+=360.0;
- *chroma=(*chroma)/255.0+0.5;
- *hue=(*hue)/255.0+0.5;
+ *hue+=1.0;
}
MagickPrivate void ConvertRGBToLCHab(const double red,const double green,
v;
ConvertXYZToLuv(X,Y,Z,luma,&u,&v);
- *chroma=hypot(354.0*u-134.0,262.0*v-140.0);
- *hue=180.0*atan2(262.0*v-140.0,354.0*u-134.0)/MagickPI;
+ *chroma=hypot(354.0*u-134.0,262.0*v-140.0)/255.0+0.5;
+ *hue=180.0*atan2(262.0*v-140.0,354.0*u-134.0)/MagickPI/360.0;
if (*hue < 0.0)
- *hue+=360.0;
- *chroma=(*chroma+134.0)/354.0;
- *hue=(*hue+140.0)/262.0;
+ *hue+=1.0;
}
MagickPrivate void ConvertRGBToLCHuv(const double red,const double green,