Convert HSL to float sRGB (r,g,b in 0..1 range, but may be OOG).
(hue: f64, saturation: f64, lightness: f64)
| 79 | |
| 80 | /// Convert HSL to float sRGB (r,g,b in 0..1 range, but may be OOG). |
| 81 | fn hsl_to_srgb_float(hue: f64, saturation: f64, lightness: f64) -> (f64, f64, f64) { |
| 82 | let h = hue / 60.0; |
| 83 | let s = saturation / 100.0; |
| 84 | let l = lightness / 100.0; |
| 85 | let c = (1.0 - (2.0 * l - 1.0).abs()) * s; |
| 86 | let x = c * (1.0 - (h % 2.0 - 1.0).abs()); |
| 87 | let m = l - c / 2.0; |
| 88 | let (r_prime, g_prime, b_prime) = if h < 1.0 { |
| 89 | (c, x, 0.0) |
| 90 | } else if h < 2.0 { |
| 91 | (x, c, 0.0) |
| 92 | } else if h < 3.0 { |
| 93 | (0.0, c, x) |
| 94 | } else if h < 4.0 { |
| 95 | (0.0, x, c) |
| 96 | } else if h < 5.0 { |
| 97 | (x, 0.0, c) |
| 98 | } else { |
| 99 | (c, 0.0, x) |
| 100 | }; |
| 101 | (r_prime + m, g_prime + m, b_prime + m) |
| 102 | } |
| 103 | |
| 104 | impl From<Srgb> for Hsl { |
| 105 | fn from(value: Srgb) -> Self { |