/**
 *
 * @param {number} c
 * @return {number}
 */
export function convert_channel_linear_to_sRGB(c) {
    if (c < 0.0031308) {
        return c * 12.92;
    } else {
        return 1.055 * (Math.pow(c, 0.4166666666666667)) - 0.055;
    }
}

/**
 *
 * @param {number[]|ArrayLike<number>} output
 * @param {number} output_offset
 * @param {number[]|ArrayLike<number>} input
 * @param {number} input_offset
 */
export function linear_to_sRGB(
    output, output_offset,
    input, input_offset
) {
    const r = input[input_offset];
    const g = input[input_offset + 1];
    const b = input[input_offset + 2];

    output[output_offset] = convert_channel_linear_to_sRGB(r);
    output[output_offset + 1] = convert_channel_linear_to_sRGB(g);
    output[output_offset + 2] = convert_channel_linear_to_sRGB(b);
}
