Last active
February 3, 2020 16:32
-
-
Save danhollick/6950b2c942f53b9398c8cd509286cd5c to your computer and use it in GitHub Desktop.
Calculating Luminance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function calculateLuminance(color) { | |
const normalizedColor = color.map(channel => channel / 255) | |
const gammaCorrectedRGB = normalizedColor.map(channel => | |
channel <= 0.03928 | |
? channel / 12.92 | |
: Math.pow((channel + 0.055) / 1.055, 2.4) | |
) | |
const luminance = | |
gammaCorrectedRGB[0] * 0.2126 + | |
gammaCorrectedRGB[1] * 0.7152 + | |
gammaCorrectedRGB[2] * 0.0722 | |
return luminance | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment