1 /*
2  * Copyright (c) 2019 Kevin Townsend (KTOWN)
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <errno.h>
8 #include <zsl/colorimetry.h>
9 
10 /**
11  * @brief 3x3 XYZ to RGB color space correlation matrices.
12  */
13 static struct zsl_mtx zsl_clr_rgb_ccm_list[] = {
14 	/** Linear sRGB with D65 white point. */
15 	{ .sz_rows = 3,
16 	  .sz_cols = 3,
17 	  .data = (zsl_real_t[]) {
18 		  3.2404542, -1.5371385, -0.4985314,
19 		  -0.9692660, 1.8760108,  0.0415560,
20 		  0.0556434, -0.2040259,  1.0572252
21 	  } },
22 
23 	/** Linear sRGB with D50 white point. */
24 	{ .sz_rows = 3,
25 	  .sz_cols = 3,
26 	  .data = (zsl_real_t[]) {
27 		  3.1338561, -1.6168667, -0.4906146,
28 		  -0.9787684, 1.9161415,  0.0334540,
29 		  0.0719453, -0.2289914,  1.4052427
30 	  } },
31 
32 	/** AdobeRGB98. */
33 	{ .sz_rows = 3,
34 	  .sz_cols = 3,
35 	  .data = (zsl_real_t[]) {
36 		  2.0413690, -0.5649464, -0.3446944,
37 		  -0.9692660, 1.8760108,  0.0415560,
38 		  0.0134474, -0.1183897,  1.0154096
39 	  } },
40 
41 	/** Sony S-Gamut3.cine D65. */
42 	{ .sz_rows = 3,
43 	  .sz_cols = 3,
44 	  .data = (zsl_real_t[]) {
45 		  1.84664243, -0.52594723, -0.21052964,
46 		  -0.44417115, 1.25949363,  0.14940599,
47 		  0.04086348,  0.01564397,  0.86837846
48 	  } },
49 
50 	/** NTSC. */
51 	{ .sz_rows = 3,
52 	  .sz_cols = 3,
53 	  .data = (zsl_real_t[]) {
54 		  1.91008143, -0.53247794, -0.28822201,
55 		  -0.98463135, 1.99910001, -0.02830719,
56 		  0.05830945, -0.11838584, 0.89761208
57 	  } },
58 
59 	/** PAL/SECAM. */
60 	{ .sz_rows = 3,
61 	  .sz_cols = 3,
62 	  .data = (zsl_real_t[]) {
63 		  3.06338864, -1.39340271, -0.47582802,
64 		  -0.96922425, 1.87592998, 0.04155423,
65 		  0.06787259, -0.2288382, 1.06927151
66 	  } },
67 
68 	/* Source: Colour python library. */
69 	/** ITU-R BT.709. */
70 	{ .sz_rows = 3,
71 	  .sz_cols = 3,
72 	  .data = (zsl_real_t[]) {
73 		  3.24100326, -1.53739899, -0.49861587,
74 		  -0.96922426, 1.87592999, 0.04155422,
75 		  0.05563942, -0.2040112, 1.05714897
76 	  } },
77 
78 	/* Source: Colour python library. */
79 	/** ITU-R BT.2020. */
80 	{ .sz_rows = 3,
81 	  .sz_cols = 3,
82 	  .data = (zsl_real_t[]) {
83 		  1.71666343, -0.35567332, -0.25336809,
84 		  -0.66667384, 1.61645574, 0.0157683,
85 		  0.01764248, -0.04277698, 0.94224328
86 	  } },
87 
88 	/* Source: Colour python library. */
89 	/** ACES Primaries #0 (AP0). */
90 	{ .sz_rows = 3,
91 	  .sz_cols = 3,
92 	  .data = (zsl_real_t[]) {
93 		  1.04981102e+00, 0.00000000e+00, -9.74845410e-05,
94 		  -4.95903023e-01, 1.37331305e+00, 9.82400365e-02,
95 		  0.00000000e+00, 0.00000000e+00, 9.91252022e-01
96 	  } },
97 
98 	/* Source: Colour python library. */
99 	/** ACES Primaries #1 (AP1). */
100 	{ .sz_rows = 3,
101 	  .sz_cols = 3,
102 	  .data = (zsl_real_t[]) {
103 		  1.64102338, -0.32480329, -0.2364247,
104 		  -0.66366286, 1.61533159, 0.01675635,
105 		  0.01172189, -0.00828444, 0.98839486
106 	  } },
107 
108 	/* Source: Colour python library. */
109 	/** DCI-P3. */
110 	{ .sz_rows = 3,
111 	  .sz_cols = 3,
112 	  .data = (zsl_real_t[]) {
113 		  2.72539403, -1.01800301, -0.4401632,
114 		  -0.79516803, 1.68973205, 0.02264719,
115 		  0.04124189, -0.08763902, 1.10092938
116 	  } },
117 
118 	/* Source: Colour python library. */
119 	/** DCI-P3+. */
120 	{ .sz_rows = 3,
121 	  .sz_cols = 3,
122 	  .data = (zsl_real_t[]) {
123 		  1.99040349, -0.56139586, -0.22966194,
124 		  -0.45849279, 1.262346, 0.15487549,
125 		  0.01563207, -0.00440904, 1.03772867
126 	  } },
127 
128 	/* Source: Colour python library. */
129 	/** CIE linear RGB. */
130 	{ .sz_rows = 3,
131 	  .sz_cols = 3,
132 	  .data = (zsl_real_t[]) {
133 		  2.37067401, -0.9000403, -0.47063371,
134 		  -0.51388479, 1.42530348, 0.0885813,
135 		  0.00529816, -0.0146949, 1.00939674
136 	  } },
137 };
138 
139 void
zsl_clr_rgbccm_get(enum zsl_clr_rgb_ccm ccm,struct zsl_mtx ** mtx)140 zsl_clr_rgbccm_get(enum zsl_clr_rgb_ccm ccm, struct zsl_mtx **mtx)
141 {
142 	*mtx = &zsl_clr_rgb_ccm_list[ccm];
143 }
144