@@ -20,7 +20,7 @@ function contrast(RGB1, RGB2) {
2020 var L1 = sRGB_to_luminance ( RGB1 ) ;
2121 var L2 = sRGB_to_luminance ( RGB2 ) ;
2222
23- if L1 > L2 return ( L1 + 0.05 ) / ( L2 + 0.05 ) ;
23+ if ( L1 > L2 ) return ( L1 + 0.05 ) / ( L2 + 0.05 ) ;
2424 return ( L2 + 0.05 ) / ( L1 + 0.05 ) ;
2525}
2626
@@ -32,5 +32,19 @@ function sRGB_to_LCH(RGB) {
3232 // then convert XYZ to CIE Lab
3333 // and finally, convert to CIE LCH
3434
35- return lin_sRGB_to_XYZ ( lin_sRGB ( RGB ) ) ;
35+ return Lab_to_LCH ( XYZ_to_Lab ( D65_to_D50 ( lin_sRGB_to_XYZ ( lin_sRGB ( RGB ) ) ) ) ) ;
36+ }
37+
38+ functions LCH_to_sRGB ( LCH ) {
39+ // convert an array of CIE LCH values
40+ // to CIE Lab, and then to XYZ,
41+ // adapt from D50 to D65,
42+ // then convert XYZ to linear-light sRGB
43+ // and finally to gamma corrected sRGB
44+ // for in-gamut colors, components are in the 0.0 to 1.0 range
45+ // out of gamut colors may have negative components
46+ // or components greater than 1.0
47+ // so check for that :)
48+
49+ return gam ( sRGB ( XYZ_to_lin_sRGB ( Lab_to_XYZ ( D50_to_D65 ( LCH_to_Lab ( LCH ) ) ) ) ) ;
3650}
0 commit comments