/**
 *
 * @param {number} c
 * @return {number}
 */
export function convert_channel_sRGB_to_linear(c) {
    if (c < 0.04045) {
        return c * 0.0773993808;
    } else {
        return Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
    }
}

/**
 * Colors in normalized scale (0...1) instead of unsigned byte (0...255) so make sure you scale your values appropriately.
 *
 * @param {number[]} output
 * @param {number} output_offset
 * @param {number[]} input
 * @param {number} input_offset
 */
export function sRGB_to_linear(
    output, output_offset,
    input, input_offset
) {

    const sR = input[input_offset];
    const sG = input[input_offset + 1];
    const sB = input[input_offset + 2];

    output[output_offset] = convert_channel_sRGB_to_linear(sR);
    output[output_offset + 1] = convert_channel_sRGB_to_linear(sG);
    output[output_offset + 2] = convert_channel_sRGB_to_linear(sB);
}
