MCPcopy Create free account
hub / github.com/csskit/csskit / hsl_to_srgb_float

Function hsl_to_srgb_float

crates/chromashift/src/hsl.rs:81–102  ·  view source on GitHub ↗

Convert HSL to float sRGB (r,g,b in 0..1 range, but may be OOG).

(hue: f64, saturation: f64, lightness: f64)

Source from the content-addressed store, hash-verified

79
80/// Convert HSL to float sRGB (r,g,b in 0..1 range, but may be OOG).
81fn 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
104impl From<Srgb> for Hsl {
105 fn from(value: Srgb) -> Self {

Callers 1

fromMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected