Last active
December 21, 2022 22:48
-
-
Save gunslinger/e219c9805ba66ebd7c9b903ea3cb9902 to your computer and use it in GitHub Desktop.
RGB to XY function
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 rgb_to_xy(red, green, blue){ | |
let redC = (red / 255) | |
let greenC = (green / 255) | |
let blueC = (blue / 255) | |
let redN = (redC > 0.04045) ? Math.pow((redC + 0.055) / (1.0 + 0.055), 2.4): (redC / 12.92) | |
let greenN = (greenC > 0.04045) ? Math.pow((greenC + 0.055) / (1.0 + 0.055), 2.4) : (greenC / 12.92) | |
let blueN = (blueC > 0.04045) ? Math.pow((blueC + 0.055) / (1.0 + 0.055), 2.4) : (blueC / 12.92) | |
let X = redN * 0.664511 + greenN * 0.154324 + blueN * 0.162028; | |
let Y = redN * 0.283881 + greenN * 0.668433 + blueN * 0.047685; | |
let Z = redN * 0.000088 + greenN * 0.072310 + blueN * 0.986039; | |
let x = X / (X + Y + Z); | |
let y = Y / (X + Y + Z); | |
return [x, y]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment