nblackburn
5/29/2019 - 6:19 PM

Luminence

module.exports = (red, green, blue) => {
    const rs = red / 255;
    const gs = green / 255;
    const bs = blue / 255;

    const rn = rs <= 0.03928 ? rs / 12.92 : Math.pow((rs + 0.055) / 1.055, 2.4);
    const gn = gs <= 0.03928 ? gs / 12.92 : Math.pow((gs + 0.055) / 1.055, 2.4);
    const bn = bs <= 0.03928 ? bs / 12.92 : Math.pow((bs + 0.055) / 1.055, 2.4);

    return (0.2126 * rn) + (0.7152 * gn) + (0.0722 * bn);
};