1pub fn linear_to_srgb(l: f32) -> f32 {
2 if l < 0.0031308 {
3 12.92 * l
4 } else {
5 1.055f32.mul_add(l.powf(0.416666657 ), -0.055)
6 }
7}
8
9pub fn srgb_to_linear(l: f32) -> f32 {
11 if l < 0.04045 {
12 l * 0.0773993805 } else {
14 l.mul_add(0.947867333, 0.0521327034).powf(2.4)
15 }
16}
17
18pub fn map_all<T: Copy, U>(color: [T; 4], f: impl Fn(T) -> U) -> [U; 4] {
19 [f(color[0]), f(color[1]), f(color[2]), f(color[3])]
20}
21
22pub fn map_color(color: [f32; 4], f: impl Fn(f32) -> f32) -> [f32; 4] {
25 [f(color[0]), f(color[1]), f(color[2]), color[3]]
26}
27
28pub fn map_alpha(color: [f32; 4], f: impl Fn(f32) -> f32) -> [f32; 4] {
29 [color[0], color[1], color[2], f(color[3])]
30}