/// <summary> /// Create a new HSB color from another HSB color /// </summary> /// <param name="other">The color to copy</param> public Hsb(Hsb other) { Hue = other.Hue; Saturation = other.Saturation; Brightness = other.Brightness; }
/// <summary> /// Convert an HSB color space to RBB color space /// </summary> /// <param name="other">The color to convert</param> public Rgb(Hsb other) { double r, b, g; if (other.Brightness < 0) { r = b = g = 0; } else if (other.Saturation < 0) { r = g = b = other.Brightness; } else { var h = other.Hue * 6D; if (h == 6D) { h = 0; } var i = (int)Math.Floor(h); var v1 = other.Brightness * (1 - other.Saturation); var v2 = other.Brightness * (1 - other.Saturation * (h - i)); var v3 = other.Brightness * (1 - other.Saturation * (1 - (h - i))); switch (i) { case 0: r = other.Brightness; g = v3; b = v1; break; case 1: r = v2; g = other.Brightness; b = v1; break; case 2: r = v1; g = other.Brightness; b = v3; break; case 3: r = v1; g = v2; b = other.Brightness; break; case 4: r = v3; g = v1; b = other.Brightness; break; default: r = other.Brightness; g = v1; b = v2; break; } } Red = (byte)Math.Round(r * 255D); Green = (byte)Math.Round(g * 255D); Blue = (byte)Math.Round(b * 255D); }