Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@davidsonfellipe
Last active December 17, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidsonfellipe/5670604 to your computer and use it in GitHub Desktop.
Save davidsonfellipe/5670604 to your computer and use it in GitHub Desktop.
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