Debian Codegraph @

tests/test_argyll_cgats.py

raw
1 from __future__ import annotations
2
3 import pytest
4
5 from DisplayCAL import argyll_cgats
6 from DisplayCAL.icc_profile import ICCProfile
7 from DisplayCAL.cgats import CGATS
8 from DisplayCAL.debughelpers import Error
9
10
11 def test_quote_nonoption_args_1():
12 """Testing if the quote_nonoption_args() function is working properly."""
13 test_value = [
14 "/home/erkan.yilmaz/Downloads/Argyll_V2.3.0/bin/dispread",
15 "-v",
16 "-d1",
17 "-c1",
18 "-yn",
19 "-P0.4711274060494959,1,1.0",
20 "-k",
21 "'Monitor 1 #1 2022-03-02 23-45 D6500 2.2 F-S XYZLUT+MTX.cal'",
22 "'Monitor 1 #1 2022-03-02 23-45 D6500 2.2 F-S XYZLUT+MTX'",
23 ]
24
25 expected_result = [
26 b'"/home/erkan.yilmaz/Downloads/Argyll_V2.3.0/bin/dispread"',
27 b"-v",
28 b"-d1",
29 b"-c1",
30 b"-yn",
31 b"-P0.4711274060494959,1,1.0",
32 b"-k",
33 b"\"'Monitor 1 #1 2022-03-02 23-45 D6500 2.2 F-S XYZLUT+MTX.cal'\"",
34 b"\"'Monitor 1 #1 2022-03-02 23-45 D6500 2.2 F-S XYZLUT+MTX'\"",
35 ]
36
37 result = argyll_cgats.quote_nonoption_args(test_value)
38 assert result == expected_result
39
40
41 def test_vcgt_to_cal_1(data_files):
42 """Testing the vcgt_to_cal() function."""
43 icc_path = data_files["UP2516D #1 2022-03-23 16-06 D6500 2.2 F-S XYZLUT+MTX.icc"]
44 profile = ICCProfile(icc_path)
45 cgats = argyll_cgats.vcgt_to_cal(profile)
46 assert cgats[0]["COLOR_REP"] == b"RGB"
47 assert cgats[0]["DATA_FORMAT"] == {
48 0: b"RGB_I",
49 1: b"RGB_R",
50 2: b"RGB_G",
51 3: b"RGB_B",
52 }
53 assert cgats[0]["DESCRIPTOR"] == b"Argyll Device Calibration State"
54 assert cgats[0]["DEVICE_CLASS"] == b"DISPLAY"
55 assert cgats[0]["KEYWORDS"] == {0: b"DEVICE_CLASS", 1: b"COLOR_REP", 2: b"RGB_I"}
56 assert cgats[0]["ORIGINATOR"] == b"vcgt"
57
58
59 @pytest.mark.parametrize(
60 "icc_name,exception",
61 (
62 ("UP2516D #1 2022-03-23 16-06 D6500 2.2 F-S XYZLUT+MTX.icc", False),
63 ("vcgt_cm_test_yellowish_blueish.icc", False),
64 ("BenQ PD2700U-AC19BB79-F553-4582-B898-4247D669C2F1.icc", True),
65 ),
66 )
67 def test_extract_cal_from_profile_1(data_files, icc_name: str, exception: bool) -> None:
68 """Testing the extract_cal_from_profile() function."""
69 icc_path = data_files[icc_name]
70 profile = ICCProfile(icc_path)
71 if exception:
72 with pytest.raises(Error):
73 argyll_cgats.extract_cal_from_profile(profile)
74 else:
75 cgats = argyll_cgats.extract_cal_from_profile(profile)
76 assert cgats[0]["COLOR_REP"] == b"RGB"
77 assert cgats[0]["DATA_FORMAT"] == {
78 0: b"RGB_I",
79 1: b"RGB_R",
80 2: b"RGB_G",
81 3: b"RGB_B",
82 }
83 assert cgats[0]["DESCRIPTOR"] == b"Argyll Device Calibration State"
84 assert cgats[0]["DEVICE_CLASS"] == b"DISPLAY"
85 assert cgats[0]["KEYWORDS"] == {
86 0: b"DEVICE_CLASS",
87 1: b"COLOR_REP",
88 2: b"RGB_I",
89 }
90 assert cgats[0]["ORIGINATOR"] == b"vcgt"
91
92
93 @pytest.mark.parametrize(
94 "profile, result",
95 (
96 ("0_16_proper.ti3", b"CTI1"),
97 ("BenQ PD2700U-AC19BB79-F553-4582-B898-4247D669C2F1.icc", None),
98 ),
99 )
100 def test_ti3_to_ti1_1(data_files, profile: str, result: bytes | None) -> None:
101 """Testing the ti3_to_ti1() function."""
102 path = data_files[profile]
103 if not result:
104 assert not argyll_cgats.ti3_to_ti1(path)
105 else:
106 assert result in argyll_cgats.ti3_to_ti1(path)
107
108
109 def test_ti3_to_ti1_2(data_files):
110 """Testing the argyll_cgats.ti3_to_ti1() function."""
111 ti3_path = data_files["0_16_from_issue_129.ti3"].absolute()
112 result = argyll_cgats.ti3_to_ti1(ti3_path)
113 assert result == (
114 b"CTI1 \n"
115 b"\n"
116 b'DESCRIPTOR "Argyll Calibration Target chart information 1"\n'
117 b'ORIGINATOR "Argyll targen"\n'
118 b'CREATED "Sun Jun 5 13:08:54 2022"\n'
119 b'COLOR_REP "RGB"\n'
120 b'TARGET_INSTRUMENT "Datacolor Spyder3"\n'
121 b'DISPLAY_TYPE_REFRESH "NO"\n'
122 b'DISPLAY_TYPE_BASE_ID "1"\n'
123 b'INSTRUMENT_TYPE_SPECTRAL "NO"\n'
124 b'NORMALIZED_TO_Y_100 "YES"\n'
125 b'VIDEO_LUT_CALIBRATION_POSSIBLE "YES"\n'
126 b"\n"
127 b"NUMBER_OF_FIELDS 7\n"
128 b"BEGIN_DATA_FORMAT\n"
129 b"SAMPLE_ID RGB_R RGB_G RGB_B XYZ_X XYZ_Y XYZ_Z\n"
130 b"END_DATA_FORMAT\n"
131 b"\n"
132 b"NUMBER_OF_SETS 3\n"
133 b"BEGIN_DATA\n"
134 b"1 100.0000 100.0000 100.0000 95.01040 100.0000 92.72020\n"
135 b"2 0.000000 0.000000 0.000000 0.277593 0.255279 0.423145\n"
136 b"3 6.250000 6.250000 6.250000 0.512380 0.536117 0.705578\n"
137 b"END_DATA\n"
138 )
139
140
141 @pytest.mark.parametrize("gray", (True, False), ids=("with gray", "without gray"))
142 @pytest.mark.parametrize(
143 "include_neutrals",
144 (True, False),
145 ids=("include neutrals", "don't include neutrals"),
146 )
147 @pytest.mark.parametrize(
148 "profile, sets",
149 (
150 ("0_16_proper.ti3", (3, 2, 0, 1)),
151 ("Monitor_AllBlack.ti3", (52, 120, 120, 167)),
152 ),
153 )
154 def test_extract_device_gray_primaries(
155 data_files,
156 profile: str,
157 sets: tuple[int, int, int, int],
158 include_neutrals: bool,
159 gray: bool,
160 ) -> None:
161 """Testing the extract_device_gray_primaries() function."""
162 path = data_files[profile]
163 cgats = CGATS(cgats=path)
164 (
165 ti3_extracted,
166 RGB_XYZ_extracted,
167 RGB_XYZ_remaining,
168 ) = argyll_cgats.extract_device_gray_primaries(
169 cgats, include_neutrals=include_neutrals, gray=gray
170 )
171 assert len(ti3_extracted) == 4
172 assert len(RGB_XYZ_extracted) == sets[0] if gray else sets[1]
173 assert len(RGB_XYZ_remaining) == sets[2] if gray else sets[3]
174
175
176 def test_verify_cgats_1(data_files):
177 """Testing verify_cgats() for #129."""
178 ti1 = CGATS(data_files["issue129_0_16.ti1"])
179 result = argyll_cgats.verify_cgats(ti1, ("RGB_R", "RGB_B", "RGB_G"))
180 expected_result = {
181 "APPROX_WHITE_POINT": b"95.045781 100.000003 108.905751",
182 "COLOR_REP": b"RGB",
183 "CREATED": b"Thu Apr 20 12:22:05 2017",
184 "DATA": {
185 0: {
186 "RGB_B": 100.0,
187 "RGB_G": 100.0,
188 "RGB_R": 100.0,
189 "SAMPLE_ID": 1,
190 "XYZ_X": 95.046,
191 "XYZ_Y": 100.0,
192 "XYZ_Z": 108.91,
193 },
194 1: {
195 "RGB_B": 0.0,
196 "RGB_G": 0.0,
197 "RGB_R": 0.0,
198 "SAMPLE_ID": 2,
199 "XYZ_X": 0.0,
200 "XYZ_Y": 0.0,
201 "XYZ_Z": 0.0,
202 },
203 2: {
204 "RGB_B": 6.25,
205 "RGB_G": 6.25,
206 "RGB_R": 6.25,
207 "SAMPLE_ID": 3,
208 "XYZ_X": 0.2132,
209 "XYZ_Y": 0.2241,
210 "XYZ_Z": 0.2443,
211 },
212 },
213 "DATA_FORMAT": {
214 0: b"SAMPLE_ID",
215 1: b"RGB_R",
216 2: b"RGB_G",
217 3: b"RGB_B",
218 4: b"XYZ_X",
219 5: b"XYZ_Y",
220 6: b"XYZ_Z",
221 },
222 "DESCRIPTOR": b"Argyll Calibration Target chart information 1",
223 "NUMBER_OF_FIELDS": None,
224 "NUMBER_OF_SETS": None,
225 "ORIGINATOR": b"Argyll targen",
226 }
227 assert result == expected_result
228
229
230 def test_verify_cgats_2(data_files):
231 """Testing verify_cgats() for #129."""
232 cgats = CGATS(
233 argyll_cgats.ti3_to_ti1(
234 open(data_files["issue129_0_16.ti3"], "rb"),
235 )
236 )
237 result = argyll_cgats.verify_cgats(cgats, ("RGB_R", "RGB_B", "RGB_G"))
238 expected_result = {
239 "COLOR_REP": b"RGB",
240 "CREATED": b"Tue Jun 7 19:06:44 2022",
241 "DATA": {
242 0: {
243 "RGB_B": 100.0,
244 "RGB_G": 100.0,
245 "RGB_R": 100.0,
246 "SAMPLE_ID": 1,
247 "XYZ_X": 95.7972,
248 "XYZ_Y": 100.0,
249 "XYZ_Z": 94.14447,
250 },
251 1: {
252 "RGB_B": 0.0,
253 "RGB_G": 0.0,
254 "RGB_R": 0.0,
255 "SAMPLE_ID": 2,
256 "XYZ_X": 0.224507,
257 "XYZ_Y": 0.227491,
258 "XYZ_Z": 0.371222,
259 },
260 2: {
261 "RGB_B": 6.25,
262 "RGB_G": 6.25,
263 "RGB_R": 6.25,
264 "SAMPLE_ID": 3,
265 "XYZ_X": 0.50435,
266 "XYZ_Y": 0.524262,
267 "XYZ_Z": 0.660054,
268 },
269 },
270 "DATA_FORMAT": {
271 0: b"SAMPLE_ID",
272 1: b"RGB_R",
273 2: b"RGB_G",
274 3: b"RGB_B",
275 4: b"XYZ_X",
276 5: b"XYZ_Y",
277 6: b"XYZ_Z",
278 },
279 "DESCRIPTOR": b"Argyll Calibration Target chart information 1",
280 "DISPLAY_TYPE_BASE_ID": 1,
281 "DISPLAY_TYPE_REFRESH": b"NO",
282 "INSTRUMENT_TYPE_SPECTRAL": b"NO",
283 "NORMALIZED_TO_Y_100": b"YES",
284 "NUMBER_OF_FIELDS": None,
285 "NUMBER_OF_SETS": None,
286 "ORIGINATOR": b"Argyll targen",
287 "TARGET_INSTRUMENT": b"Datacolor Spyder3",
288 "VIDEO_LUT_CALIBRATION_POSSIBLE": b"YES",
289 }
290 assert result == expected_result
291
292
293 def test_verify_ti1_rgb_xyz_1(data_files):
294 """Testing verify_ti1_rgb_xyz() for #129."""
295 ti1 = CGATS(data_files["issue129_0_16.ti1"])
296 result = argyll_cgats.verify_ti1_rgb_xyz(ti1)
297 expected_result = {
298 "APPROX_WHITE_POINT": b"95.045781 100.000003 108.905751",
299 "COLOR_REP": b"RGB",
300 "CREATED": b"Thu Apr 20 12:22:05 2017",
301 "DATA": {
302 0: {
303 "RGB_B": 100.0,
304 "RGB_G": 100.0,
305 "RGB_R": 100.0,
306 "SAMPLE_ID": 1,
307 "XYZ_X": 95.046,
308 "XYZ_Y": 100.0,
309 "XYZ_Z": 108.91,
310 },
311 1: {
312 "RGB_B": 0.0,
313 "RGB_G": 0.0,
314 "RGB_R": 0.0,
315 "SAMPLE_ID": 2,
316 "XYZ_X": 0.0,
317 "XYZ_Y": 0.0,
318 "XYZ_Z": 0.0,
319 },
320 2: {
321 "RGB_B": 6.25,
322 "RGB_G": 6.25,
323 "RGB_R": 6.25,
324 "SAMPLE_ID": 3,
325 "XYZ_X": 0.2132,
326 "XYZ_Y": 0.2241,
327 "XYZ_Z": 0.2443,
328 },
329 },
330 "DATA_FORMAT": {
331 0: b"SAMPLE_ID",
332 1: b"RGB_R",
333 2: b"RGB_G",
334 3: b"RGB_B",
335 4: b"XYZ_X",
336 5: b"XYZ_Y",
337 6: b"XYZ_Z",
338 },
339 "DESCRIPTOR": b"Argyll Calibration Target chart information 1",
340 "NUMBER_OF_FIELDS": None,
341 "NUMBER_OF_SETS": None,
342 "ORIGINATOR": b"Argyll targen",
343 }
344 assert result == expected_result