2
2
// Conversion can also be done using ICC profiles and a Color Management System
3
3
// For clarity, a library is used for matrix multiplication (multiply-matrices.js)
4
4
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
+
5
9
// sRGB-related functions
6
10
7
11
function lin_sRGB ( RGB ) {
@@ -330,10 +334,9 @@ function XYZ_to_Lab(XYZ) {
330
334
// from CIE standard, which now defines these as a rational fraction
331
335
var ε = 216 / 24389 ; // 6^3/29^3
332
336
var κ = 24389 / 27 ; // 29^3/3^3
333
- var white = [ 0.96422 , 1.00000 , 0.82521 ] ; // D50 reference white
334
337
335
338
// 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 ] ) ;
337
340
338
341
// now compute f
339
342
var f = xyz . map ( value => value > ε ? Math . cbrt ( value ) : ( κ * value + 16 ) / 116 ) ;
@@ -350,7 +353,6 @@ function Lab_to_XYZ(Lab) {
350
353
// http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
351
354
var κ = 24389 / 27 ; // 29^3/3^3
352
355
var ε = 216 / 24389 ; // 6^3/29^3
353
- var white = [ 0.96422 , 1.00000 , 0.82521 ] ; // D50 reference white
354
356
var f = [ ] ;
355
357
356
358
// compute f, starting with the luminance-related term
@@ -366,7 +368,7 @@ function Lab_to_XYZ(Lab) {
366
368
] ;
367
369
368
370
// 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 ] ) ;
370
372
}
371
373
372
374
function Lab_to_LCH ( Lab ) {
0 commit comments