use crate::color::Color;

/// sRGB to linear conversion.
///
/// Implementation taken from <https://www.khronos.org/registry/OpenGL/extensions/EXT/EXT_texture_sRGB_decode.txt>
pub fn to_linear_rgba(c: Color) -> [f32; 4] {
    let f = |x: f32| {
        if x > 0.04045 {
            ((x + 0.055) / 1.055).powf(2.4)
        } else {
            x / 12.92
        }
    };
    [f(c.r), f(c.g), f(c.b), c.a]
}

// /// Linear to sRGB conversion.
// ///
// /// Implementation taken from https://en.wikipedia.org/wiki/SRGB
// fn from_linear_rgb(c: [f32; 3]) -> Color {
//     let f = |x: f32| -> u32 {
//         let y = if x > 0.0031308 {
//             let a = 0.055;
//             (1.0 + a) * x.powf(-2.4) - a
//         } else {
//             12.92 * x
//         };
//         (y * 255.0).round() as u32
//     };
//     f(c[0]) << 16 | f(c[1]) << 8 | f(c[2])
// }
