h,
m,
r,
- x;
+ x,
+ z;
/*
Convert HCL to RGB colorspace.
b=0.0;
if ((0.0 <= h) && (h < 1.0))
{
- r=c;
- g=x;
+ r=c;
+ g=x;
}
else
if ((1.0 <= h) && (h < 2.0))
{
- r=x;
- g=c;
+ r=x;
+ g=c;
}
else
if ((2.0 <= h) && (h < 3.0))
{
- g=c;
- b=x;
+ g=c;
+ b=x;
}
else
if ((3.0 <= h) && (h < 4.0))
{
- g=x;
- b=c;
+ g=x;
+ b=c;
}
else
if ((4.0 <= h) && (h < 5.0))
{
- r=x;
- b=c;
+ r=x;
+ b=c;
}
else
if ((5.0 <= h) && (h < 6.0))
{
- r=c;
- b=x;
+ r=c;
+ b=x;
}
- m=luma-0.298839*r+0.586811*g+0.114350*b;
- *red=QuantumRange*(r+m);
- *green=QuantumRange*(g+m);
- *blue=QuantumRange*(b+m);
+ m=luma-(0.298839*r+0.586811*g+0.114350*b);
+ /*
+ Choose saturation strategy to clip it into the RGB cube; hue and luma are
+ preserved and chroma may be changed.
+ */
+ z=1.0;
+ if (m < 0.0)
+ {
+ z=luma/(luma-m);
+ m=0.0;
+ }
+ else
+ if ((m+c) > 1.0)
+ {
+ z=(1.0-luma)/(m+c-luma);
+ m=1.0-z*c;
+ }
+ *red=QuantumRange*(z*r+m);
+ *green=QuantumRange*(z*g+m);
+ *blue=QuantumRange*(z*b+m);
}
\f
/*
max=MagickMax(r,MagickMax(g,b));
c=max-(double) MagickMin(r,MagickMin(g,b));
h=0.0;
- if (c == 0)
+ if (c == 0.0)
h=0.0;
else
if (red == max)
- h=fmod((g-b)/c,6.0);
+ h=fmod((g-b)/c+6.0,6.0);
else
if (green == max)
h=((b-r)/c)+2.0;
{
return(GetOptimalKernelWidth1D(radius,sigma));
}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% I n v e r s e s R G B C o m p a n d o r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% InversesRGBCompandor() removes the gamma function from a sRGB pixel.
+%
+% The format of the InversesRGBCompandor method is:
+%
+% double InversesRGBCompandor(const double pixel)
+%
+% A description of each parameter follows:
+%
+% o pixel: the pixel.
+%
+*/
+MagickExport double InversesRGBCompandor(const double pixel)
+{
+ if (pixel <= (0.0404482362771076*QuantumRange))
+ return(pixel/12.92);
+ return(QuantumRange*pow((QuantumScale*pixel+0.055)/1.055,2.4));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% s R G B C o m p a n d o r %
+% %
+% %
+% %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+% sRGBCompandor() adds the gamma function to a sRGB pixel.
+%
+% The format of the sRGBCompandor method is:
+%
+% double sRGBCompandor(const double pixel)
+%
+% A description of each parameter follows:
+%
+% o pixel: the pixel.
+%
+*/
+MagickExport double sRGBCompandor(const double pixel)
+{
+ if (pixel <= (0.0031306684425005883*QuantumRange))
+ return(12.92*pixel);
+ return(QuantumRange*(1.055*pow(QuantumScale*pixel,1.0/2.4)-0.055));
+}