@@ -45,6 +45,18 @@ function P3_to_LCH(RGB) {
4545
4646 return Lab_to_LCH ( XYZ_to_Lab ( D65_to_D50 ( lin_P3_to_XYZ ( lin_P3 ( RGB ) ) ) ) ) ;
4747}
48+
49+ function 2020 _to_LCH ( RGB ) {
50+ // convert an array of gamma-corrected rec.2020 values
51+ // in the 0.0 to 1.0 range
52+ // to linear-light sRGB, then to CIE XYZ,
53+ // then adapt from D65 to D50,
54+ // then convert XYZ to CIE Lab
55+ // and finally, convert to CIE LCH
56+
57+ return Lab_to_LCH ( XYZ_to_Lab ( D65_to_D50 ( lin_2020_to_XYZ ( lin_2020 ( RGB ) ) ) ) ) ;
58+ }
59+
4860function LCH_to_sRGB ( LCH ) {
4961 // convert an array of CIE LCH values
5062 // to CIE Lab, and then to XYZ,
@@ -71,4 +83,18 @@ function LCH_to_P3(LCH) {
7183 // so check for that :)
7284
7385 return gam_P3 ( XYZ_to_lin_P3 ( D50_to_D65 ( Lab_to_XYZ ( LCH_to_Lab ( LCH ) ) ) ) ) ;
86+ }
87+
88+ function LCH_to_2020 ( LCH ) {
89+ // convert an array of CIE LCH values
90+ // to CIE Lab, and then to XYZ,
91+ // adapt from D50 to D65,
92+ // then convert XYZ to linear-light rec.2020
93+ // and finally to gamma corrected rec.2020
94+ // for in-gamut colors, components are in the 0.0 to 1.0 range
95+ // out of gamut colors may have negative components
96+ // or components greater than 1.0
97+ // so check for that :)
98+
99+ return gam_2020 ( XYZ_to_lin_2020 ( D50_to_D65 ( Lab_to_XYZ ( LCH_to_Lab ( LCH ) ) ) ) ) ;
74100}
0 commit comments