public void FromHsbk(ILifxHsbkColor color) { if (color != this) { this.Hue = color.Hue; this.Saturation = color.Saturation; this.Brightness = color.Brightness; this.Kelvin = color.Kelvin; } }
/// <inheritdoc /> public void FromHsbk(ILifxHsbkColor color) { if (this != color && color is not null) { this.Hue = color.Hue; this.Saturation = color.Saturation; this.Brightness = color.Brightness; this.Kelvin = color.Kelvin; } }
/// <inheritdoc /> public void FromHsbk(ILifxHsbkColor hsbk) { if (hsbk != this && hsbk is not null) { this.Hue = hsbk.Hue; this.Saturation = hsbk.Saturation; this.Brightness = hsbk.Brightness; this.Kelvin = hsbk.Kelvin; } }
/// <inheritdoc /> public void FromHsbk(ILifxHsbkColor hsbk) { if (hsbk == null) { return; } double h = (double)hsbk.Hue / UInt16.MaxValue; double s = (double)hsbk.Saturation / UInt16.MaxValue; double v = (double)hsbk.Brightness / UInt16.MaxValue; double c = v * s; double hHextant = h / 6.0d; double x = c * (1.0d - Math.Abs((hHextant % 2.0d) - 1.0d)); double r; double g; double b; if (hHextant <= 1.0d) { r = c; g = x; b = 0.0d; } else if (hHextant <= 2.0d) { r = x; g = c; b = 0.0d; } else if (hHextant <= 3.0d) { r = 0.0d; g = c; b = x; } else if (hHextant <= 4.0d) { r = 0.0d; g = x; b = c; } else if (hHextant <= 5.0d) { r = x; g = 0.0d; b = c; } else { r = c; g = 0.0d; b = x; } double m = v - c; this.Red = Utilities.MultiplyRoundClampUInt16(r + m); this.Green = Utilities.MultiplyRoundClampUInt16(g + m); this.Blue = Utilities.MultiplyRoundClampUInt16(b + m); this.Kelvin = hsbk.Kelvin; }
/// <inheritdoc /> public void FromHsbk(ILifxHsbkColor hsbk) { if (hsbk == null) { return; } // Scale values double h = (double)hsbk.Hue / UInt16.MaxValue; double s = (double)hsbk.Saturation / UInt16.MaxValue; double v = (double)hsbk.Brightness / UInt16.MaxValue; // https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB double c = v * s; double hHextant = h / 6.0d; double x = c * (1.0d - Math.Abs((hHextant % 2) - 1.0d)); double r; double g; double b; if (hHextant <= 1.0d) { r = c; g = x; b = 0.0d; } else if (hHextant <= 2.0d) { r = x; g = c; b = 0.0d; } else if (hHextant <= 3.0d) { r = 0.0d; g = c; b = x; } else if (hHextant <= 4.0d) { r = 0.0d; g = x; b = c; } else if (hHextant <= 5.0d) { r = x; g = 0.0d; b = c; } else { r = c; g = 0.0d; b = x; } double m = v - c; this.Red = Utilities.MultiplyRoundClampUInt8(r + m); this.Green = Utilities.MultiplyRoundClampUInt8(g + m); this.Blue = Utilities.MultiplyRoundClampUInt8(b + m); this.Kelvin = hsbk.Kelvin; }