private void Initialize(double red, double green, double blue)
{
double quantumScale = 1.0 / Quantum.Max;
double max = Math.Max(red, Math.Max(green, blue)) * quantumScale;
double min = Math.Min(red, Math.Max(green, blue)) * quantumScale;
double c = max - min;
Lightness = (max + min) / 2.0;
if (c <= 0.0)
{
Hue = 0.0;
Saturation = 0.0;
}
else
{
if (max == (quantumScale * red))
{
Hue = ((quantumScale * green) - (quantumScale * blue)) / c;
if ((quantumScale * green) < (quantumScale * blue))
Hue += 6.0;
}
else if (max == (quantumScale * green))
Hue = 2.0 + (((quantumScale * blue) - (quantumScale * red)) / c);
else
Hue = 4.0 + (((quantumScale * red) - (quantumScale * green)) / c);
Hue *= 60.0 / 360.0;
if (Lightness <= 0.5)
Saturation = c / (2.0 * Lightness);
else
Saturation = c / (2.0 - (2.0 * Lightness));
}
}