Skip to content

Instantly share code, notes, and snippets.

@nblackburn
Last active May 29, 2019 18:20
Show Gist options
  • Save nblackburn/05d151774f6a29fc5528169d101ea1d5 to your computer and use it in GitHub Desktop.
Save nblackburn/05d151774f6a29fc5528169d101ea1d5 to your computer and use it in GitHub Desktop.
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);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment