@@ -35,6 +35,16 @@ function sRGB_to_LCH(RGB) {
3535 return Lab_to_LCH ( XYZ_to_Lab ( D65_to_D50 ( lin_sRGB_to_XYZ ( lin_sRGB ( RGB ) ) ) ) ) ;
3636}
3737
38+ function P3_to_LCH ( RGB ) {
39+ // convert an array of gamma-corrected display-p3 values
40+ // in the 0.0 to 1.0 range
41+ // to linear-light display-p3, then to CIE XYZ,
42+ // then adapt from D65 to D50,
43+ // then convert XYZ to CIE Lab
44+ // and finally, convert to CIE LCH
45+
46+ return Lab_to_LCH ( XYZ_to_Lab ( D65_to_D50 ( lin_P3_to_XYZ ( lin_P3 ( RGB ) ) ) ) ) ;
47+ }
3848function LCH_to_sRGB ( LCH ) {
3949 // convert an array of CIE LCH values
4050 // to CIE Lab, and then to XYZ,
@@ -47,4 +57,18 @@ function LCH_to_sRGB(LCH) {
4757 // so check for that :)
4858
4959 return gam_sRGB ( XYZ_to_lin_sRGB ( D50_to_D65 ( Lab_to_XYZ ( LCH_to_Lab ( LCH ) ) ) ) ) ;
60+ }
61+
62+ function LCH_to_P3 ( LCH ) {
63+ // convert an array of CIE LCH values
64+ // to CIE Lab, and then to XYZ,
65+ // adapt from D50 to D65,
66+ // then convert XYZ to linear-light display-p3
67+ // and finally to gamma corrected display-p3
68+ // for in-gamut colors, components are in the 0.0 to 1.0 range
69+ // out of gamut colors may have negative components
70+ // or components greater than 1.0
71+ // so check for that :)
72+
73+ return gam_P3 ( XYZ_to_lin_P3 ( D50_to_D65 ( Lab_to_XYZ ( LCH_to_Lab ( LCH ) ) ) ) ) ;
5074}
0 commit comments