22// Conversion can also be done using ICC profiles and a Color Management System
33// For clarity, a library is used for matrix multiplication (multiply-matrices.js)
44
5+ // standard white points, defined by 4-figure CIE x,y chromaticities
6+ const D50 = [ 0.3457 / 0.3585 , 1.00000 , ( 1.0 - 0.3457 - 0.3585 ) / 0.3585 ] ;
7+ const D65 = [ 0.3127 / 0.3290 , 1.00000 , ( 1.0 - 0.3127 - 0.3290 ) / 0.3290 ] ;
8+
59// sRGB-related functions
610
711function lin_sRGB ( RGB ) {
@@ -330,10 +334,9 @@ function XYZ_to_Lab(XYZ) {
330334 // from CIE standard, which now defines these as a rational fraction
331335 var ε = 216 / 24389 ; // 6^3/29^3
332336 var κ = 24389 / 27 ; // 29^3/3^3
333- var white = [ 0.96422 , 1.00000 , 0.82521 ] ; // D50 reference white
334337
335338 // compute xyz, which is XYZ scaled relative to reference white
336- var xyz = XYZ . map ( ( value , i ) => value / white [ i ] ) ;
339+ var xyz = XYZ . map ( ( value , i ) => value / D50 [ i ] ) ;
337340
338341 // now compute f
339342 var f = xyz . map ( value => value > ε ? Math . cbrt ( value ) : ( κ * value + 16 ) / 116 ) ;
@@ -350,7 +353,6 @@ function Lab_to_XYZ(Lab) {
350353 // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
351354 var κ = 24389 / 27 ; // 29^3/3^3
352355 var ε = 216 / 24389 ; // 6^3/29^3
353- var white = [ 0.96422 , 1.00000 , 0.82521 ] ; // D50 reference white
354356 var f = [ ] ;
355357
356358 // compute f, starting with the luminance-related term
@@ -366,7 +368,7 @@ function Lab_to_XYZ(Lab) {
366368 ] ;
367369
368370 // Compute XYZ by scaling xyz by reference white
369- return xyz . map ( ( value , i ) => value * white [ i ] ) ;
371+ return xyz . map ( ( value , i ) => value * D50 [ i ] ) ;
370372}
371373
372374function Lab_to_LCH ( Lab ) {
0 commit comments