Last active
December 17, 2015 20:49
-
-
Save davidsonfellipe/5670604 to your computer and use it in GitHub Desktop.
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 xyz_from_wavelength (ColorTemp, lw, currentCIE) { | |
var nmMin = 380; | |
var nmMax = 780; | |
var degrees = 5; | |
var XYZ = {x: 0, | |
y: 0, | |
z: 0}; | |
//currentCIE pode ser "1931" ou "1965" | |
var nmMinIndex = nmMin - beta[currentCIE][0][0]; | |
var nmMaxIndex = beta[currentCIE].length - 1 - | |
(beta[currentCIE][beta[currentCIE].length - 1][0] - nmMax); | |
var XSum = 0, | |
YSum = 0, | |
ZSum = 0; | |
var wSum = 0, | |
mac = 0; | |
for (nm = nmMinIndex; nm <= nmMaxIndex; nm += degrees) { | |
// calculate X | |
XSum += beta[currentCIE][nm][1] * lw[illuminant][nm][1] * ColorTemp[mac]; | |
// calculate Y | |
YSum += beta[currentCIE][nm][2] * lw[illuminant][nm][1] * ColorTemp[mac]; | |
// calculate Z | |
ZSum += beta[currentCIE][nm][3] * lw[illuminant][nm][1] * ColorTemp[mac]; | |
wSum += beta[currentCIE][nm][2] * lw[illuminant][nm][1]; | |
mac++; | |
} | |
return cXYZ(XSum/wSum, YSum/wSum, ZSum/wSum); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment