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 XYZ tristimulus values for CIE standard illuminants in the A, B, C,
12 * D and E families, as well as the illuminant used in ICC profiles.
13 */
14 static const struct zsl_clr_illum_data zsl_clr_illum_list[] = {
15 { .illuminant = ZSL_CLR_ILLUM_A,
16 .observer = ZSL_CLR_OBS_2_DEG,
17 .name = "A",
18 .data = {
19 .xyz_x = 1.0985,
20 .xyz_y = 1.00000,
21 .xyz_z = 0.3558
22 } },
23
24 { .illuminant = ZSL_CLR_ILLUM_B,
25 .observer = ZSL_CLR_OBS_2_DEG,
26 .name = "B",
27 .data = {
28 .xyz_x = 0.99093,
29 .xyz_y = 1.00000,
30 .xyz_z = 0.85313
31 } },
32
33 { .illuminant = ZSL_CLR_ILLUM_C,
34 .observer = ZSL_CLR_OBS_2_DEG,
35 .name = "C",
36 .data = {
37 .xyz_x = 0.9807,
38 .xyz_y = 1.00000,
39 .xyz_z = 1.1822
40 } },
41
42 { .illuminant = ZSL_CLR_ILLUM_D50,
43 .observer = ZSL_CLR_OBS_2_DEG,
44 .name = "D50",
45 .data = {
46 .xyz_x = 0.96422,
47 .xyz_y = 1.00000,
48 .xyz_z = 0.82521
49 } },
50
51 { .illuminant = ZSL_CLR_ILLUM_D55,
52 .observer = ZSL_CLR_OBS_2_DEG,
53 .name = "D55",
54 .data = {
55 .xyz_x = 0.9568,
56 .xyz_y = 1.00000,
57 .xyz_z = 0.9214
58 } },
59
60 { .illuminant = ZSL_CLR_ILLUM_D65,
61 .observer = ZSL_CLR_OBS_2_DEG,
62 .name = "D65",
63 .data = {
64 .xyz_x = 0.95047,
65 .xyz_y = 1.00000,
66 .xyz_z = 1.08883
67 } },
68
69 { .illuminant = ZSL_CLR_ILLUM_E,
70 .observer = ZSL_CLR_OBS_2_DEG,
71 .name = "E",
72 .data = {
73 .xyz_x = 1.00000,
74 .xyz_y = 1.00000,
75 .xyz_z = 1.00000
76 } },
77
78 { .illuminant = ZSL_CLR_ILLUM_ICC,
79 .observer = ZSL_CLR_OBS_2_DEG,
80 .name = "ICC",
81 .data = {
82 .xyz_x = 0.9642,
83 .xyz_y = 1.00000,
84 .xyz_z = 0.8249
85 } }
86 };
87
88 int
zsl_clr_illum_get(enum zsl_clr_obs obs,enum zsl_clr_illum illum,const struct zsl_clr_illum_data ** data)89 zsl_clr_illum_get(enum zsl_clr_obs obs, enum zsl_clr_illum illum,
90 const struct zsl_clr_illum_data **data)
91 {
92 int count;
93
94 count = sizeof(zsl_clr_illum_list) / sizeof(zsl_clr_illum_list[0]);
95
96 /* Find supplied obs and illum. */
97 for (size_t i = 0; i < count; i++) {
98 if ((zsl_clr_illum_list[i].illuminant == illum) &&
99 (zsl_clr_illum_list[i].observer == obs)) {
100 *data = &zsl_clr_illum_list[i];
101 return 0;
102 }
103 }
104
105 return -EINVAL;
106 }
107