@@ -50,6 +50,53 @@ function XYZ_to_lin_sRGB(XYZ) {
5050 return math . multiply ( M , XYZ ) . valueOf ( ) ;
5151}
5252
53+ // DCI P3-related functions
54+
55+
56+ function lin_P3 ( RGB ) {
57+ // convert an array of DCI P3 RGB values in the range 0.0 - 1.0
58+ // to linear light (un-companded) form.
59+
60+ return RGB . map ( function ( val ) {
61+ return Math . pow ( val , 2.6 ) ;
62+ } ) ;
63+ }
64+
65+ function gam_P3 ( RGB ) {
66+ // convert an array of linear-light P3 RGB in the range 0.0-1.0
67+ // to gamma corrected form
68+
69+ return RGB . map ( function ( val ) {
70+ return Math . pow ( val , 1 / 2.6 ) ;
71+ }
72+ } ) ;
73+ }
74+
75+ function lin_P3_to_XYZ ( rgb ) {
76+ // convert an array of linear-light P3 values to CIE XYZ
77+ // using D65 (no chromatic adaptation)
78+ // http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
79+ var M = math . matrix ( [
80+ [ 0.4865709486482162 , 0.26566769316909306 , 0.1982172852343625 ] ,
81+ [ 0.2289745640697488 , 0.6917385218365064 , 0.079286914093745 ] ,
82+ [ 0.0000000000000000 , 0.04511338185890264 , 1.043944368900976 ]
83+ ] ) ;
84+ // 0 was computed as -3.972075516933488e-17
85+
86+ return math . multiply ( M , rgb ) . valueOf ( ) ;
87+ }
88+
89+ function XYZ_to_lin_P3 ( XYZ ) {
90+ // convert XYZ to linear-light P3
91+ var M = math . matrix ( [
92+ [ 2.493496911941425 , - 0.9313836179191239 , - 0.40271078445071684 ] ,
93+ [ - 0.8294889695615747 , 1.7626640603183463 , 0.023624685841943577 ] ,
94+ [ 0.03584583024378447 , - 0.07617238926804182 , 0.9568845240076872 ]
95+ ] ) ;
96+
97+ return math . multiply ( M , XYZ ) . valueOf ( ) ;
98+ }
99+
53100//Rec.2020-related functions
54101
55102function lin_2020 ( RGB ) {
0 commit comments