| 1 |
"""Tests for the DisplayCAL.icc_profile module.""" |
| 2 |
|
| 3 |
# Standard library imports |
| 4 |
import binascii |
| 5 |
import datetime |
| 6 |
import sys |
| 7 |
from pathlib import Path |
| 8 |
from time import strftime |
| 9 |
|
| 10 |
# Third party imports |
| 11 |
import pytest |
| 12 |
|
| 13 |
# Local Imports |
| 14 |
from DisplayCAL import colormath |
| 15 |
from DisplayCAL.icc_profile import ( |
| 16 |
CMMS, |
| 17 |
dateTimeNumber, |
| 18 |
DictType, |
| 19 |
GAMUT_VOLUME_SRGB, |
| 20 |
GAMUT_VOLUME_ADOBERGB, |
| 21 |
GAMUT_VOLUME_SMPTE431_P3, |
| 22 |
hexrepr, |
| 23 |
ICCProfile, |
| 24 |
ICCProfileTag, |
| 25 |
MultiLocalizedUnicodeType, |
| 26 |
s15Fixed16Number_tohex, |
| 27 |
Text, |
| 28 |
uInt8Number_tohex, |
| 29 |
uInt16Number_tohex, |
| 30 |
uInt32Number_tohex, |
| 31 |
) |
| 32 |
from DisplayCAL.util_os import which |
| 33 |
|
| 34 |
|
| 35 |
def test_iccprofile_from_rgb_space(): |
| 36 |
"""Testing if the ICCProfile.from_rgb_space() method is working properly.""" |
| 37 |
rec709_gamma18 = list(colormath.get_rgb_space("Rec. 709")) |
| 38 |
icc = ICCProfile.from_rgb_space(rec709_gamma18, b"Rec. 709 gamma 1.8") |
| 39 |
|
| 40 |
assert icc is not None |
| 41 |
result = icc.get_info() |
| 42 |
assert isinstance(result, list) |
| 43 |
|
| 44 |
expected_result = [ |
| 45 |
["Size", "0 Bytes (0.00 KiB)"], |
| 46 |
["Preferred CMM", "0x6172676C 'argl' ArgyllCMS"], |
| 47 |
["ICC version", "2.2"], |
| 48 |
["Profile class", "Display device profile"], |
| 49 |
["Color model", "RGB"], |
| 50 |
["Profile connection space (PCS)", "XYZ"], |
| 51 |
["Created", "2022-03-09 00:19:53"] |
| 52 |
] |
| 53 |
|
| 54 |
if sys.platform == "darwin": |
| 55 |
expected_result.append(["Platform", "Apple"]) |
| 56 |
elif sys.platform == "win32": |
| 57 |
expected_result.append(["Platform", "Microsoft"]) |
| 58 |
else: |
| 59 |
expected_result.append(["Platform", "0x2A6E6978 '*nix'"]) |
| 60 |
|
| 61 |
expected_result += [ |
| 62 |
["Is embedded", "No"], |
| 63 |
["Can be used independently", "Yes"], |
| 64 |
["Device", ""], |
| 65 |
[" Manufacturer", "0x00000000"], |
| 66 |
[" Model", "0x00000000"], |
| 67 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 68 |
["Default rendering intent", "Perceptual"], |
| 69 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 70 |
["Creator", "0x4443414C 'DCAL' DisplayCAL"], |
| 71 |
["Checksum", "0xAF709A5BE63B00419875A95394AE7EDF"], |
| 72 |
[" Checksum OK", "Yes"], |
| 73 |
["Description (ASCII)", "Rec. 709 gamma 1.8"], |
| 74 |
["Copyright", "No copyright"], |
| 75 |
["Media white point", ""], |
| 76 |
[" Is illuminant", "Yes"], |
| 77 |
[" Illuminant-relative XYZ", " 95.05 100.00 108.91 (xy 0.3127 0.3290)"], |
| 78 |
[" Illuminant-relative CCT", "6503K"], |
| 79 |
[" ΔE 2000 to daylight locus", "0.09"], |
| 80 |
[" ΔE 2000 to blackbody locus", "4.57"], |
| 81 |
["Absolute to media relative transform", "Bradford"], |
| 82 |
[" Matrix", "0.8951 0.2664 -0.1614"], |
| 83 |
[" ", "-0.7502 1.7135 0.0367"], |
| 84 |
[" ", "0.0389 -0.0685 1.0296"], |
| 85 |
["Chromaticity (illuminant-relative)", ""], |
| 86 |
[" Channel 1 (R) xy", "0.6400 0.3300"], |
| 87 |
[" Channel 2 (G) xy", "0.3000 0.6000"], |
| 88 |
[" Channel 3 (B) xy", "0.1500 0.0600"], |
| 89 |
["Red matrix column", ""], |
| 90 |
[" Illuminant-relative XYZ", " 41.24 21.26 1.93 (xy 0.6400 0.3300)"], |
| 91 |
[" PCS-relative XYZ", " 43.60 22.25 1.39 (xy 0.6484 0.3309)"], |
| 92 |
["Red tone response curve", ""], |
| 93 |
[" Number of entries", "1024"], |
| 94 |
[" Transfer function", "Rec. 709"], |
| 95 |
[" Minimum Y", "0.0000"], |
| 96 |
[" Maximum Y", "100.00"], |
| 97 |
["Green matrix column", ""], |
| 98 |
[" Illuminant-relative XYZ", " 35.76 71.52 11.92 (xy 0.3000 0.6000)"], |
| 99 |
[" PCS-relative XYZ", " 38.51 71.69 9.71 (xy 0.3212 0.5979)"], |
| 100 |
["Green tone response curve", ""], |
| 101 |
[" Number of entries", "1024"], |
| 102 |
[" Transfer function", "Rec. 709"], |
| 103 |
[" Minimum Y", "0.0000"], |
| 104 |
[" Maximum Y", "100.00"], |
| 105 |
["Blue matrix column", ""], |
| 106 |
[" Illuminant-relative XYZ", " 18.05 7.22 95.05 (xy 0.1500 0.0600)"], |
| 107 |
[" PCS-relative XYZ", " 14.30 6.06 71.39 (xy 0.1559 0.0661)"], |
| 108 |
["Blue tone response curve", ""], |
| 109 |
[" Number of entries", "1024"], |
| 110 |
[" Transfer function", "Rec. 709"], |
| 111 |
[" Minimum Y", "0.0000"], |
| 112 |
[" Maximum Y", "100.00"], |
| 113 |
] |
| 114 |
# can't set the created checksum properly |
| 115 |
expected_result[6] = [ |
| 116 |
"Created", |
| 117 |
strftime("%Y-%m-%d %H:%M:%S", icc.dateTime.timetuple()), |
| 118 |
] |
| 119 |
expected_result[17] = [ |
| 120 |
"Checksum", |
| 121 |
"0x{}".format(binascii.hexlify(icc.ID).upper().decode()), |
| 122 |
] |
| 123 |
|
| 124 |
assert result == expected_result |
| 125 |
|
| 126 |
|
| 127 |
def test_iccprofile_from_chromaticies(): |
| 128 |
"""Testing if the ICCProfile.from_chromaticies() method is working properly.""" |
| 129 |
xy = [ |
| 130 |
(0.6771560743827527, 0.32205471727089957), |
| 131 |
(0.19945851033134956, 0.7266949701661809), |
| 132 |
(0.1515536624045438, 0.04081563046813107), |
| 133 |
(0.3133857119826585, 0.3283378912104931), |
| 134 |
] |
| 135 |
desc = "Monitor 1 #1 2022-02-13 20-53 D6500 2.2 VF-S XYZLUT+MTX" |
| 136 |
copyright_str = "No copyright. Created with DisplayCAL 3.8.9.3 and ArgyllCMS 2.3.0" |
| 137 |
display_manufacturer = None |
| 138 |
display_name = "Monitor 1, Output DP-2" |
| 139 |
cat = "Bradford" |
| 140 |
|
| 141 |
icc = ICCProfile.from_chromaticities( |
| 142 |
xy[0][0], |
| 143 |
xy[0][1], |
| 144 |
xy[1][0], |
| 145 |
xy[1][1], |
| 146 |
xy[2][0], |
| 147 |
xy[2][1], |
| 148 |
xy[3][0], |
| 149 |
xy[3][1], |
| 150 |
2.2, |
| 151 |
desc, |
| 152 |
copyright_str, |
| 153 |
display_manufacturer, |
| 154 |
display_name, |
| 155 |
cat=cat, |
| 156 |
) |
| 157 |
|
| 158 |
assert isinstance(icc, ICCProfile) |
| 159 |
|
| 160 |
|
| 161 |
def test_iccprofile_get_info(): |
| 162 |
"""Testing if the ICCProfile.get_info() method is working properly.""" |
| 163 |
xy = [ |
| 164 |
(0.6771560743827527, 0.32205471727089957), |
| 165 |
(0.19945851033134956, 0.7266949701661809), |
| 166 |
(0.1515536624045438, 0.04081563046813107), |
| 167 |
(0.3133857119826585, 0.3283378912104931), |
| 168 |
] |
| 169 |
desc = "Monitor 1 #1 2022-02-13 20-53 D6500 2.2 VF-S XYZLUT+MTX" |
| 170 |
copyright_str = "No copyright. Created with DisplayCAL 3.8.9.3 and ArgyllCMS 2.3.0" |
| 171 |
display_manufacturer = None |
| 172 |
display_name = "Monitor 1, Output DP-2" |
| 173 |
cat = "Bradford" |
| 174 |
|
| 175 |
icc = ICCProfile.from_chromaticities( |
| 176 |
xy[0][0], |
| 177 |
xy[0][1], |
| 178 |
xy[1][0], |
| 179 |
xy[1][1], |
| 180 |
xy[2][0], |
| 181 |
xy[2][1], |
| 182 |
xy[3][0], |
| 183 |
xy[3][1], |
| 184 |
2.2, |
| 185 |
desc, |
| 186 |
copyright_str, |
| 187 |
display_manufacturer, |
| 188 |
display_name, |
| 189 |
cat=cat, |
| 190 |
) |
| 191 |
|
| 192 |
result = icc.get_info() |
| 193 |
assert isinstance(result, list) |
| 194 |
|
| 195 |
expected_result = [ |
| 196 |
["Size", "0 Bytes (0.00 KiB)"], |
| 197 |
["Preferred CMM", "0x6172676C 'argl' ArgyllCMS"], |
| 198 |
["ICC version", "2.2"], |
| 199 |
["Profile class", "Display device profile"], |
| 200 |
["Color model", "RGB"], |
| 201 |
["Profile connection space (PCS)", "XYZ"], |
| 202 |
["Created", "2022-02-14 02:44:22"], |
| 203 |
] |
| 204 |
|
| 205 |
if sys.platform == "darwin": |
| 206 |
expected_result.append(["Platform", "Apple"]) |
| 207 |
elif sys.platform == "win32": |
| 208 |
expected_result.append(["Platform", "Microsoft"]) |
| 209 |
else: |
| 210 |
expected_result.append(["Platform", "0x2A6E6978 '*nix'"]) |
| 211 |
|
| 212 |
expected_result += [ |
| 213 |
["Is embedded", "No"], |
| 214 |
["Can be used independently", "Yes"], |
| 215 |
["Device", ""], |
| 216 |
[" Manufacturer", "0x00000000"], |
| 217 |
[" Model", "0x00000000"], |
| 218 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 219 |
["Default rendering intent", "Perceptual"], |
| 220 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 221 |
["Creator", "0x4443414C 'DCAL' DisplayCAL"], |
| 222 |
["Checksum", "0x02F595E98437CAF1593DB03F9DCD15C9"], |
| 223 |
[" Checksum OK", "Yes"], |
| 224 |
["Description", ""], |
| 225 |
[" ASCII", "Monitor 1 #1 2022-02-13 20-53 D6500 2.2 VF-S XYZLUT+MTX"], |
| 226 |
[" Unicode", "Monitor 1 #1 2022-02-13 20-53 D6500 2.2 VF-S XYZLUT+MTX"], |
| 227 |
[ |
| 228 |
"Copyright", |
| 229 |
"No copyright. Created with DisplayCAL 3.8.9.3 and ArgyllCMS 2.3.0", |
| 230 |
], |
| 231 |
["Device model name", ""], |
| 232 |
[" ASCII", "Monitor 1, Output DP-2"], |
| 233 |
[" Unicode", "Monitor 1, Output DP-2"], |
| 234 |
["Media white point", ""], |
| 235 |
[" Is illuminant", "Yes"], |
| 236 |
[" Illuminant-relative XYZ", " 95.45 100.00 109.12 (xy 0.3134 0.3283)"], |
| 237 |
[" Illuminant-relative CCT", "6471K"], |
| 238 |
[" ΔE 2000 to daylight locus", "1.18"], |
| 239 |
[" ΔE 2000 to blackbody locus", "3.66"], |
| 240 |
["Absolute to media relative transform", "Bradford"], |
| 241 |
[" Matrix", "0.8951 0.2664 -0.1614"], |
| 242 |
[" ", "-0.7502 1.7135 0.0367"], |
| 243 |
[" ", "0.0389 -0.0685 1.0296"], |
| 244 |
["Chromaticity (illuminant-relative)", ""], |
| 245 |
[" Channel 1 (R) xy", "0.6772 0.3221"], |
| 246 |
[" Channel 2 (G) xy", "0.1995 0.7267"], |
| 247 |
[" Channel 3 (B) xy", "0.1516 0.0408"], |
| 248 |
["Red matrix column", ""], |
| 249 |
[" Illuminant-relative XYZ", " 57.78 27.48 0.07 (xy 0.6772 0.3221)"], |
| 250 |
[" PCS-relative XYZ", " 60.96 28.84 -0.07 (xy 0.6794 0.3214)"], |
| 251 |
["Red tone response curve", "Gamma 2.2"], |
| 252 |
["Green matrix column", ""], |
| 253 |
[" Illuminant-relative XYZ", " 18.49 67.35 6.84 (xy 0.1995 0.7267)"], |
| 254 |
[" PCS-relative XYZ", " 20.41 67.24 6.00 (xy 0.2180 0.7180)"], |
| 255 |
["Green tone response curve", "Gamma 2.2"], |
| 256 |
["Blue matrix column", ""], |
| 257 |
[" Illuminant-relative XYZ", " 19.18 5.17 102.21 (xy 0.1516 0.0408)"], |
| 258 |
[" PCS-relative XYZ", " 15.05 3.92 76.56 (xy 0.1575 0.0411)"], |
| 259 |
["Blue tone response curve", "Gamma 2.2"], |
| 260 |
] |
| 261 |
|
| 262 |
# can't set the created checksum properly |
| 263 |
expected_result[6] = [ |
| 264 |
"Created", |
| 265 |
strftime("%Y-%m-%d %H:%M:%S", icc.dateTime.timetuple()), |
| 266 |
] |
| 267 |
expected_result[17] = [ |
| 268 |
"Checksum", |
| 269 |
"0x{}".format(binascii.hexlify(icc.ID).upper().decode()), |
| 270 |
] |
| 271 |
assert result == expected_result |
| 272 |
|
| 273 |
|
| 274 |
def test_iccprofile_from_xyz(): |
| 275 |
"""Testing if ICCProfile.from_xyz() method is working properly.""" |
| 276 |
XYZ = { |
| 277 |
"r": [0.5777977275512667, 0.2747999919455954, 0.0006734086960673902], |
| 278 |
"g": [0.18487094167718518, 0.6735475123298383, 0.06844569117319045], |
| 279 |
"b": [0.19179233077154842, 0.05165249572456644, 1.0220629001307424], |
| 280 |
} |
| 281 |
wXYZ = (0.9544610000000001, 1.0, 1.091182) |
| 282 |
|
| 283 |
desc = b"Monitor 1 #1 2022-02-13 20-53 D6500 2.2 VF-S XYZLUT+MTX" |
| 284 |
copyright = b"No copyright. Created with DisplayCAL 3.8.9.3 and ArgyllCMS 2.3.0" |
| 285 |
display_manufacturer = None |
| 286 |
display_name = b"Monitor 1, Output DP-2" |
| 287 |
cat = "Bradford" |
| 288 |
|
| 289 |
mtx = ICCProfile.from_XYZ( |
| 290 |
XYZ["r"], |
| 291 |
XYZ["g"], |
| 292 |
XYZ["b"], |
| 293 |
wXYZ, |
| 294 |
2.2, |
| 295 |
desc, |
| 296 |
copyright, |
| 297 |
display_manufacturer, |
| 298 |
display_name, |
| 299 |
cat=cat, |
| 300 |
) |
| 301 |
|
| 302 |
assert isinstance(mtx, ICCProfile) |
| 303 |
|
| 304 |
|
| 305 |
def test_uInt8Number_tohex_is_working_properly(): |
| 306 |
"""Testing if uInt8Number_tohex is working properly.""" |
| 307 |
test_value = 1321 |
| 308 |
result = uInt8Number_tohex(test_value) |
| 309 |
expected_value = b")" |
| 310 |
assert result == expected_value |
| 311 |
|
| 312 |
|
| 313 |
def test_uInt32Number_tohex_is_working_properly(): |
| 314 |
"""Testing if uInt32Number_tohex is working properly.""" |
| 315 |
test_value = 132123 |
| 316 |
result = uInt32Number_tohex(test_value) |
| 317 |
expected_value = b"\x00\x02\x04\x1b" |
| 318 |
assert result == expected_value |
| 319 |
|
| 320 |
|
| 321 |
def test_s15Fixed16Number_tohex_is_working_properly(): |
| 322 |
"""Testing if s15Fixed16Number_tohex is working properly.""" |
| 323 |
test_value = 123.12 |
| 324 |
result = s15Fixed16Number_tohex(test_value) |
| 325 |
expected_value = b"\x00{\x1e\xb8" |
| 326 |
assert result == expected_value |
| 327 |
|
| 328 |
|
| 329 |
def test_uInt16Number_tohex_tohex_is_working_properly(): |
| 330 |
"""Testing if uInt16Number_tohex is working properly.""" |
| 331 |
test_value = 12123 |
| 332 |
result = uInt16Number_tohex(test_value) |
| 333 |
expected_value = b"/[" |
| 334 |
assert result == expected_value |
| 335 |
|
| 336 |
|
| 337 |
def test_dict_type(): |
| 338 |
"""Testing the DictType.""" |
| 339 |
d = DictType() |
| 340 |
d.update( |
| 341 |
{ |
| 342 |
"CMF_product": "DisplayCAL", |
| 343 |
"CMF_binary": "DisplayCAL", |
| 344 |
"CMF_version": "3.8.9.3", |
| 345 |
} |
| 346 |
) |
| 347 |
|
| 348 |
expected = ( |
| 349 |
b"dict\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x10\x00\x00\x00@" |
| 350 |
b"\x00\x00\x00\x16\x00\x00\x00X\x00\x00\x00\x14\x00\x00\x00l\x00\x00\x00\x14" |
| 351 |
b"\x00\x00\x00\x80\x00\x00\x00\x14\x00\x00\x00\x94\x00\x00\x00\x16" |
| 352 |
b"\x00\x00\x00\xac\x00\x00\x00\x0e\x00C\x00M\x00F\x00_\x00p\x00r\x00o\x00d" |
| 353 |
b"\x00u\x00c\x00t\x00\x00\x00D\x00i\x00s\x00p\x00l\x00a\x00y\x00C\x00A\x00L" |
| 354 |
b"\x00C\x00M\x00F\x00_\x00b\x00i\x00n\x00a\x00r\x00y\x00D\x00i\x00s\x00p" |
| 355 |
b"\x00l\x00a\x00y\x00C\x00A\x00L\x00C\x00M\x00F\x00_\x00v\x00e\x00r\x00s" |
| 356 |
b"\x00i\x00o\x00n\x00\x00\x003\x00.\x008\x00.\x009\x00.\x003\x00\x00" |
| 357 |
) |
| 358 |
|
| 359 |
assert d.tagData == expected |
| 360 |
|
| 361 |
|
| 362 |
def test_sample_icc_file_1(data_files): |
| 363 |
"""Test with sample icc files. |
| 364 |
|
| 365 |
Args: |
| 366 |
data_files: A fixture supplying data files. |
| 367 |
""" |
| 368 |
icc_profile = ICCProfile(profile=data_files["default.icc"].absolute()) |
| 369 |
result = icc_profile.get_info() |
| 370 |
|
| 371 |
expected_result = [ |
| 372 |
["Size", "20240 Bytes (19.77 KiB)"], |
| 373 |
["Preferred CMM", "0x6172676C 'argl' ArgyllCMS"], |
| 374 |
["ICC version", "2.2"], |
| 375 |
["Profile class", "Display device profile"], |
| 376 |
["Color model", "RGB"], |
| 377 |
["Profile connection space (PCS)", "XYZ"], |
| 378 |
["Created", "2016-01-08 00:59:09"], |
| 379 |
["Platform", "Microsoft"], |
| 380 |
["Is embedded", "No"], |
| 381 |
["Can be used independently", "Yes"], |
| 382 |
["Device", ""], |
| 383 |
[" Manufacturer", "0x00000000"], |
| 384 |
[" Model", "0x00000000"], |
| 385 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 386 |
["Default rendering intent", "Media-relative colorimetric"], |
| 387 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 388 |
["Creator", "0x6172676C 'argl' ArgyllCMS"], |
| 389 |
["Checksum", "0xCE27ED7FC7C06FBB9492BC1408729D6C"], |
| 390 |
[" Checksum OK", "Yes"], |
| 391 |
["Description (ASCII)", "DisplayCAL calibration preset: Default"], |
| 392 |
["Copyright", "Created with DisplayCAL and Argyll CMS"], |
| 393 |
["Media white point", ""], |
| 394 |
[" Is illuminant", "Yes"], |
| 395 |
[" Illuminant-relative XYZ", " 95.05 100.00 108.91 (xy 0.3127 0.3290)"], |
| 396 |
[" Illuminant-relative CCT", "6503K"], |
| 397 |
[" ΔE 2000 to daylight locus", "0.09"], |
| 398 |
[" ΔE 2000 to blackbody locus", "4.57"], |
| 399 |
["Media black point", ""], |
| 400 |
[" Illuminant-relative XYZ", "0.0000 0.0000 0.0000"], |
| 401 |
["Video card gamma table", ""], |
| 402 |
[" Bitdepth", "16"], |
| 403 |
[" Channels", "3"], |
| 404 |
[" Number of entries per channel", "256"], |
| 405 |
[" Channel 1 gamma at 50% input", "1.00"], |
| 406 |
[" Channel 1 minimum", "0.0000%"], |
| 407 |
[" Channel 1 maximum", "100.00%"], |
| 408 |
[" Channel 1 unique values", "256 @ 8 Bit"], |
| 409 |
[" Channel 1 is linear", "Yes"], |
| 410 |
[" Channel 2 gamma at 50% input", "1.00"], |
| 411 |
[" Channel 2 minimum", "0.0000%"], |
| 412 |
[" Channel 2 maximum", "100.00%"], |
| 413 |
[" Channel 2 unique values", "256 @ 8 Bit"], |
| 414 |
[" Channel 2 is linear", "Yes"], |
| 415 |
[" Channel 3 gamma at 50% input", "1.00"], |
| 416 |
[" Channel 3 minimum", "0.0000%"], |
| 417 |
[" Channel 3 maximum", "100.00%"], |
| 418 |
[" Channel 3 unique values", "256 @ 8 Bit"], |
| 419 |
[" Channel 3 is linear", "Yes"], |
| 420 |
["Red matrix column", ""], |
| 421 |
[" Illuminant-relative XYZ", " 41.24 21.26 1.93 (xy 0.6400 0.3300)"], |
| 422 |
[" PCS-relative XYZ", " 43.60 22.25 1.39 (xy 0.6484 0.3309)"], |
| 423 |
["Green matrix column", ""], |
| 424 |
[" Illuminant-relative XYZ", " 35.76 71.52 11.92 (xy 0.3000 0.6000)"], |
| 425 |
[" PCS-relative XYZ", " 38.51 71.69 9.71 (xy 0.3212 0.5979)"], |
| 426 |
["Blue matrix column", ""], |
| 427 |
[" Illuminant-relative XYZ", " 18.05 7.22 95.05 (xy 0.1500 0.0600)"], |
| 428 |
[" PCS-relative XYZ", " 14.31 6.06 71.39 (xy 0.1559 0.0661)"], |
| 429 |
["Red tone response curve", ""], |
| 430 |
[" Number of entries", "256"], |
| 431 |
[" Transfer function", "Gamma 2.20 100%"], |
| 432 |
[" Minimum Y", "0.0000"], |
| 433 |
[" Maximum Y", "100.00"], |
| 434 |
["Green tone response curve", ""], |
| 435 |
[" Number of entries", "256"], |
| 436 |
[" Transfer function", "Gamma 2.20 100%"], |
| 437 |
[" Minimum Y", "0.0000"], |
| 438 |
[" Maximum Y", "100.00"], |
| 439 |
["Blue tone response curve", ""], |
| 440 |
[" Number of entries", "256"], |
| 441 |
[" Transfer function", "Gamma 2.20 100%"], |
| 442 |
[" Minimum Y", "0.0000"], |
| 443 |
[" Maximum Y", "100.00"], |
| 444 |
["Characterization target", "[17538 Bytes]"], |
| 445 |
["Absolute to media relative transform", "Bradford"], |
| 446 |
[" Matrix", "0.8951 0.2664 -0.1614"], |
| 447 |
[" ", "-0.7502 1.7135 0.0367"], |
| 448 |
[" ", "0.0389 -0.0685 1.0296"], |
| 449 |
] |
| 450 |
assert result == expected_result |
| 451 |
|
| 452 |
|
| 453 |
def test_hexrepr_is_with_mapping_supplied(): |
| 454 |
"""Testing DisplayCAL.icc_profile.hexrepr with a mapping is supplied.""" |
| 455 |
test_bytes_string = b"ADBE" |
| 456 |
expected_result = "0x41444245 'ADBE' Adobe" |
| 457 |
result = hexrepr(test_bytes_string, mapping=CMMS) |
| 458 |
assert result == expected_result |
| 459 |
|
| 460 |
|
| 461 |
def test_hexrepr_is_without_mapping_supplied(): |
| 462 |
"""Testing DisplayCAL.icc_profile.hexrepr with no mapping is supplied.""" |
| 463 |
test_bytes_string = b"ADBE" |
| 464 |
expected_result = "0x41444245 'ADBE'" |
| 465 |
result = hexrepr(test_bytes_string) |
| 466 |
assert result == expected_result |
| 467 |
|
| 468 |
|
| 469 |
def test_date_time_number_is_working_properly(): |
| 470 |
"""Testing if DisplayCAL.icc_profile.dataTimeNumber function is working properly.""" |
| 471 |
test_value = b"\x07\xe6\x00\x02\x00\x13\x00\x12\x00*\x002" |
| 472 |
expected_result = datetime.datetime(2022, 2, 19, 18, 42, 50) |
| 473 |
result = dateTimeNumber(test_value) |
| 474 |
assert result == expected_result |
| 475 |
|
| 476 |
|
| 477 |
def test_icc_profile_tag_is_working_properly(): |
| 478 |
"""Testing if the ``ICCProfileTag`` class is working properly.""" |
| 479 |
tag_data = b"\0\0\0\0" |
| 480 |
tag_signature = "desc" |
| 481 |
tag = ICCProfileTag(tag_data, tag_signature) |
| 482 |
assert tag is not None |
| 483 |
assert tag.tagData == tag_data |
| 484 |
assert tag.tagSignature == tag_signature |
| 485 |
|
| 486 |
|
| 487 |
def test_text_tag_is_working_properly(): |
| 488 |
"""Testing if the ``Text`` Tag is working properly.""" |
| 489 |
test_data = b"some text" |
| 490 |
t = Text(test_data) |
| 491 |
t.tagData = test_data |
| 492 |
t.tagSignature = "targ" |
| 493 |
|
| 494 |
assert str(t) == test_data.decode("UTF-8", "replace") |
| 495 |
|
| 496 |
|
| 497 |
def test_for_issue_31_1(data_files): |
| 498 |
"""Test for #31 with user supplied data.""" |
| 499 |
icc_profile_path = data_files[ |
| 500 |
"BenQ PD2700U-AC19BB79-F553-4582-B898-4247D669C2F1.icc" |
| 501 |
] |
| 502 |
icc = ICCProfile(icc_profile_path) |
| 503 |
result = icc.get_info() |
| 504 |
expected_result = [ |
| 505 |
["Size", "532 Bytes (0.52 KiB)"], |
| 506 |
["Preferred CMM", "0x6170706C 'appl' Apple"], |
| 507 |
["ICC version", "4.0"], |
| 508 |
["Profile class", "Display device profile"], |
| 509 |
["Color model", "RGB"], |
| 510 |
["Profile connection space (PCS)", "XYZ"], |
| 511 |
["Created", "2022-03-11 10:47:41"], |
| 512 |
["Platform", "Apple"], |
| 513 |
["Is embedded", "No"], |
| 514 |
["Can be used independently", "Yes"], |
| 515 |
["Device", ""], |
| 516 |
[" Manufacturer", "0x4150504C"], |
| 517 |
[" Model", "0x00000000"], |
| 518 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 519 |
["Default rendering intent", "Perceptual"], |
| 520 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 521 |
["Creator", "0x6170706C 'appl'"], |
| 522 |
["Checksum", "0x30E46970EA5C4B1900877653837B62E9"], |
| 523 |
[" Checksum OK", "Yes"], |
| 524 |
["Description (ASCII)", "BenQ PD2700U"], |
| 525 |
["Copyright", "Copyright Apple Inc., 2022"], |
| 526 |
["Media white point", ""], |
| 527 |
[" Is illuminant", "Yes"], |
| 528 |
[" Illuminant-relative XYZ", " 95.05 100.00 108.91 (xy 0.3127 0.3290)"], |
| 529 |
[" Illuminant-relative CCT", "6503K"], |
| 530 |
[" ΔE 2000 to daylight locus", "0.09"], |
| 531 |
[" ΔE 2000 to blackbody locus", "4.57"], |
| 532 |
[" PCS-relative XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585)"], |
| 533 |
[" PCS-relative CCT", "5000K"], |
| 534 |
["Red matrix column", ""], |
| 535 |
[" Illuminant-relative XYZ", " 41.24 21.26 1.93 (xy 0.6400 0.3300)"], |
| 536 |
[" PCS-relative XYZ", " 43.61 22.25 1.39 (xy 0.6485 0.3309)"], |
| 537 |
["Green matrix column", ""], |
| 538 |
[" Illuminant-relative XYZ", " 35.76 71.51 11.92 (xy 0.3000 0.6000)"], |
| 539 |
[" PCS-relative XYZ", " 38.51 71.69 9.71 (xy 0.3212 0.5978)"], |
| 540 |
["Blue matrix column", ""], |
| 541 |
[" Illuminant-relative XYZ", " 18.05 7.22 95.08 (xy 0.1500 0.0600)"], |
| 542 |
[" PCS-relative XYZ", " 14.31 6.06 71.41 (xy 0.1559 0.0660)"], |
| 543 |
["Red tone response curve", "Gamma 1.96"], |
| 544 |
["Chromatic adaptation transform", "Bradford"], |
| 545 |
[" Matrix", "1.0479 0.0229 -0.0502"], |
| 546 |
[" ", "0.0296 0.9905 -0.0171"], |
| 547 |
[" ", "-0.0092 0.0151 0.7517"], |
| 548 |
["Blue tone response curve", "Gamma 1.96"], |
| 549 |
["Green tone response curve", "Gamma 1.96"], |
| 550 |
] |
| 551 |
assert result == expected_result |
| 552 |
|
| 553 |
|
| 554 |
def test_for_issue_31_2(data_files): |
| 555 |
"""Test for #31 with user supplied data.""" |
| 556 |
icc_profile_path = data_files[ |
| 557 |
"BenQ SW271 #1 2021-11-17 14-21 2.2 F-S 1xCurve+MTX.icc" |
| 558 |
] |
| 559 |
icc = ICCProfile(icc_profile_path) |
| 560 |
result = icc.get_info() |
| 561 |
expected_result = [ |
| 562 |
["Size", "21420 Bytes (20.92 KiB)"], |
| 563 |
["Preferred CMM", "0x6172676C 'argl' ArgyllCMS"], |
| 564 |
["ICC version", "2.2"], |
| 565 |
["Profile class", "Display device profile"], |
| 566 |
["Color model", "RGB"], |
| 567 |
["Profile connection space (PCS)", "XYZ"], |
| 568 |
["Created", "2021-11-17 14:34:47"], |
| 569 |
["Platform", "Apple"], |
| 570 |
["Is embedded", "No"], |
| 571 |
["Can be used independently", "Yes"], |
| 572 |
["Device", ""], |
| 573 |
[" Manufacturer", "0x00000000"], |
| 574 |
[" Model", "0x00000000"], |
| 575 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 576 |
["Default rendering intent", "Media-relative colorimetric"], |
| 577 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 578 |
["Creator", "0x6172676C 'argl' ArgyllCMS"], |
| 579 |
["Checksum", "0x00000000000000000000000000000000"], |
| 580 |
[" Calculated checksum", "0x7C169FE38BEFC4CFCA0606634C381447"], |
| 581 |
["Description (ASCII)", "BenQ SW271 #1 2021-11-17 14-21 2.2 F-S 1xCurve+MTX"], |
| 582 |
[ |
| 583 |
"Copyright", |
| 584 |
"No copyright. Created with DisplayCAL 3.8.9.3 and ArgyllCMS 2.2.1", |
| 585 |
], |
| 586 |
["Device model name (ASCII)", "BenQ SW271"], |
| 587 |
["Luminance", "158.49 cd/m²"], |
| 588 |
["Media white point", ""], |
| 589 |
[" Is illuminant", "Yes"], |
| 590 |
[" Illuminant-relative XYZ", " 94.97 100.00 109.33 (xy 0.3121 0.3286)"], |
| 591 |
[" Illuminant-relative CCT", "6539K"], |
| 592 |
[" ΔE 2000 to daylight locus", "0.09"], |
| 593 |
[" ΔE 2000 to blackbody locus", "4.71"], |
| 594 |
["Media black point", ""], |
| 595 |
[" Illuminant-relative XYZ", "0.1312 0.1389 0.1526 (xy 0.3105 0.3285)"], |
| 596 |
[" Illuminant-relative CCT", "6630K"], |
| 597 |
[" ΔE 2000 to daylight locus", "1.32"], |
| 598 |
[" ΔE 2000 to blackbody locus", "5.68"], |
| 599 |
["Colorants (PCS-relative)", ""], |
| 600 |
[" Red XYZ", " 61.86 31.08 1.65 (xy 0.6539 0.3286)"], |
| 601 |
[" Green XYZ", " 20.25 62.90 5.88 (xy 0.2275 0.7065)"], |
| 602 |
[" Blue XYZ", " 14.58 6.30 75.18 (xy 0.1518 0.0656)"], |
| 603 |
["Video card gamma table", ""], |
| 604 |
[" Bitdepth", "16"], |
| 605 |
[" Channels", "3"], |
| 606 |
[" Number of entries per channel", "256"], |
| 607 |
[" Channel 1 gamma at 50% input", "0.95"], |
| 608 |
[" Channel 1 minimum", "0.0000%"], |
| 609 |
[" Channel 1 maximum", "100.00%"], |
| 610 |
[" Channel 1 unique values", "256 @ 8 Bit"], |
| 611 |
[" Channel 1 is linear", "No"], |
| 612 |
[" Channel 2 gamma at 50% input", "0.97"], |
| 613 |
[" Channel 2 minimum", "0.0000%"], |
| 614 |
[" Channel 2 maximum", "100.00%"], |
| 615 |
[" Channel 2 unique values", "256 @ 8 Bit"], |
| 616 |
[" Channel 2 is linear", "No"], |
| 617 |
[" Channel 3 gamma at 50% input", "0.96"], |
| 618 |
[" Channel 3 minimum", "0.0000%"], |
| 619 |
[" Channel 3 maximum", "100.00%"], |
| 620 |
[" Channel 3 unique values", "256 @ 8 Bit"], |
| 621 |
[" Channel 3 is linear", "No"], |
| 622 |
["Red matrix column", ""], |
| 623 |
[" Illuminant-relative XYZ", " 58.36 29.54 2.19 (xy 0.6478 0.3279)"], |
| 624 |
[" PCS-relative XYZ", " 61.81 30.99 1.54 (xy 0.6552 0.3285)"], |
| 625 |
["Green matrix column", ""], |
| 626 |
[" Illuminant-relative XYZ", " 18.11 63.03 6.66 (xy 0.2063 0.7179)"], |
| 627 |
[" PCS-relative XYZ", " 20.14 62.84 5.78 (xy 0.2269 0.7080)"], |
| 628 |
["Blue matrix column", ""], |
| 629 |
[" Illuminant-relative XYZ", " 18.50 7.42 100.48 (xy 0.1464 0.0587)"], |
| 630 |
[" PCS-relative XYZ", " 14.47 6.17 75.17 (xy 0.1510 0.0644)"], |
| 631 |
["Red tone response curve", "Gamma 2.2"], |
| 632 |
["Green tone response curve", "Gamma 2.2"], |
| 633 |
["Blue tone response curve", "Gamma 2.2"], |
| 634 |
["Characterization target", "[17659 Bytes]"], |
| 635 |
["Characterization device values", "[17659 Bytes]"], |
| 636 |
["Characterization measurement values", "[17659 Bytes]"], |
| 637 |
["Absolute to media relative transform", "Bradford"], |
| 638 |
[" Matrix", "0.8951 0.2664 -0.1614"], |
| 639 |
[" ", "-0.7502 1.7135 0.0367"], |
| 640 |
[" ", "0.0389 -0.0685 1.0296"], |
| 641 |
["Chromaticity (illuminant-relative)", ""], |
| 642 |
[" Channel 1 (R) xy", "0.6471 0.3272"], |
| 643 |
[" Channel 2 (G) xy", "0.2076 0.7142"], |
| 644 |
[" Channel 3 (B) xy", "0.1472 0.0595"], |
| 645 |
["Metadata", ""], |
| 646 |
[" CMF_binary", "DisplayCAL"], |
| 647 |
[" CMF_version", "3.8.9.3"], |
| 648 |
[" CMF_product", "DisplayCAL"], |
| 649 |
[" License", "Public Domain"], |
| 650 |
[" Quality", "high"], |
| 651 |
[" OPENICC_automatic_generated", "0"], |
| 652 |
[" DATA_source", "calib"], |
| 653 |
[" MEASUREMENT_device", "i1 displaypro, colormunki display"], |
| 654 |
[" prefix", "CMF_\nDATA_\nMEASUREMENT_\nOPENICC_\nACCURACY_\nGAMUT_"], |
| 655 |
[" ACCURACY_dE76_avg", "0.876532"], |
| 656 |
[" ACCURACY_dE76_max", "3.995005"], |
| 657 |
[" ACCURACY_dE76_rms", "1.164627"], |
| 658 |
[" GAMUT_volume", "1.52172176238"], |
| 659 |
[" GAMUT_coverage(dci-p3)", "0.8745"], |
| 660 |
[" GAMUT_coverage(srgb)", "0.9997"], |
| 661 |
[" GAMUT_coverage(adobe-rgb)", "0.9997"], |
| 662 |
] |
| 663 |
assert result == expected_result |
| 664 |
|
| 665 |
|
| 666 |
def test_for_issue_31_3(data_files): |
| 667 |
"""Test for issue #31, an ICC files reported to be creating errors.""" |
| 668 |
icc_file_path = data_files["SW271 PM PenalNative_KB1_160_2022-03-17.icc"] |
| 669 |
icc = ICCProfile(icc_file_path) |
| 670 |
result = icc.get_info() |
| 671 |
expected_result = [ |
| 672 |
["Size", "10656 Bytes (10.41 KiB)"], |
| 673 |
["Preferred CMM", "0x6170706C 'appl' Apple"], |
| 674 |
["ICC version", "4.0"], |
| 675 |
["Profile class", "Display device profile"], |
| 676 |
["Color model", "RGB"], |
| 677 |
["Profile connection space (PCS)", "XYZ"], |
| 678 |
["Created", "2022-03-17 15:42:00"], |
| 679 |
["Platform", "Apple"], |
| 680 |
["Is embedded", "No"], |
| 681 |
["Can be used independently", "Yes"], |
| 682 |
["Device", ""], |
| 683 |
[" Manufacturer", "0x00000000"], |
| 684 |
[" Model", "0x00000000"], |
| 685 |
[" Media attributes", "Reflective, Glossy, Positive, Color"], |
| 686 |
["Default rendering intent", "Perceptual"], |
| 687 |
["PCS illuminant XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585, CCT 5000K)"], |
| 688 |
["Creator", "0x52442020 'RD '"], |
| 689 |
["Checksum", "0xC61B1DD94A0ED672203190C72F1EBA61"], |
| 690 |
[" Checksum OK", "No"], |
| 691 |
[" Calculated checksum", "0x4D726857D69314B83F8396D2C3DDBBF9"], |
| 692 |
["Description", ""], |
| 693 |
[" ASCII", "SW271 PM PenalNative_KB1_160_2022-03-17"], |
| 694 |
[" Macintosh", "SW271 PM PenalNative_KB1_160_2022-03-17"], |
| 695 |
["'dscm'", ""], |
| 696 |
[" en/US", ""], |
| 697 |
["Characterization target", "[5938 Bytes]"], |
| 698 |
[ |
| 699 |
"Copyright", |
| 700 |
"Copyright © 2011-2020 Remote Director, LLC. All Rights Reserved.", |
| 701 |
], |
| 702 |
["Media white point", ""], |
| 703 |
[" Is illuminant", "Yes"], |
| 704 |
[" Illuminant-relative XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585)"], |
| 705 |
[" Illuminant-relative CCT", "5000K"], |
| 706 |
[" ΔE 2000 to daylight locus", "0.08"], |
| 707 |
[" ΔE 2000 to blackbody locus", "4.73"], |
| 708 |
[" PCS-relative XYZ", " 96.42 100.00 82.49 (xy 0.3457 0.3585)"], |
| 709 |
[" PCS-relative CCT", "5000K"], |
| 710 |
["Media black point", ""], |
| 711 |
[" Illuminant-relative XYZ", "0.1480 0.1434 0.3220 (xy 0.2413 0.2338)"], |
| 712 |
[" Illuminant-relative CCT", "746507K"], |
| 713 |
[" PCS-relative XYZ", "0.1480 0.1434 0.3220 (xy 0.2413 0.2338)"], |
| 714 |
[" PCS-relative CCT", "746507K"], |
| 715 |
["Red matrix column", ""], |
| 716 |
[" Illuminant-relative XYZ", " 58.29 27.40 0.96 (xy 0.6727 0.3162)"], |
| 717 |
[" PCS-relative XYZ", " 61.66 28.85 0.60 (xy 0.6768 0.3166)"], |
| 718 |
["Green matrix column", ""], |
| 719 |
[" Illuminant-relative XYZ", " 18.42 65.25 7.42 (xy 0.2022 0.7163)"], |
| 720 |
[" PCS-relative XYZ", " 20.43 65.05 6.39 (xy 0.2223 0.7081)"], |
| 721 |
["Blue matrix column", ""], |
| 722 |
[" Illuminant-relative XYZ", " 18.33 7.35 100.53 (xy 0.1453 0.0582)"], |
| 723 |
[" PCS-relative XYZ", " 14.33 6.10 75.50 (xy 0.1494 0.0636)"], |
| 724 |
["Luminance", "158.49 cd/m²"], |
| 725 |
["Red tone response curve", "Gamma 2.2"], |
| 726 |
["Green tone response curve", "Gamma 2.2"], |
| 727 |
["Blue tone response curve", "Gamma 2.2"], |
| 728 |
["Chromatic adaptation transform", "Bradford"], |
| 729 |
[" Matrix", "1.0479 0.0229 -0.0502"], |
| 730 |
[" ", "0.0296 0.9905 -0.0171"], |
| 731 |
[" ", "-0.0093 0.0151 0.7517"], |
| 732 |
["Video card gamma table", ""], |
| 733 |
[" Bitdepth", "16"], |
| 734 |
[" Channels", "3"], |
| 735 |
[" Number of entries per channel", "256"], |
| 736 |
[" Channel 1 gamma at 50% input", "1.00"], |
| 737 |
[" Channel 1 minimum", "0.0000%"], |
| 738 |
[" Channel 1 maximum", "100.00%"], |
| 739 |
[" Channel 1 unique values", "256 @ 8 Bit"], |
| 740 |
[" Channel 1 is linear", "Yes"], |
| 741 |
[" Channel 2 gamma at 50% input", "1.00"], |
| 742 |
[" Channel 2 minimum", "0.0000%"], |
| 743 |
[" Channel 2 maximum", "100.00%"], |
| 744 |
[" Channel 2 unique values", "256 @ 8 Bit"], |
| 745 |
[" Channel 2 is linear", "Yes"], |
| 746 |
[" Channel 3 gamma at 50% input", "1.00"], |
| 747 |
[" Channel 3 minimum", "0.0000%"], |
| 748 |
[" Channel 3 maximum", "100.00%"], |
| 749 |
[" Channel 3 unique values", "256 @ 8 Bit"], |
| 750 |
[" Channel 3 is linear", "Yes"], |
| 751 |
["'pICS'", "[1275 Bytes]"], |
| 752 |
["'pMC '", "'pMC ' [1000 Bytes]"], |
| 753 |
] |
| 754 |
expected_result[6] = [ |
| 755 |
"Created", |
| 756 |
strftime("%Y-%m-%d %H:%M:%S", icc.dateTime.timetuple()), |
| 757 |
] |
| 758 |
expected_result[17] = [ |
| 759 |
"Checksum", |
| 760 |
"0x{}".format(binascii.hexlify(icc.ID).upper().decode()), |
| 761 |
] |
| 762 |
assert result == expected_result |
| 763 |
|
| 764 |
|
| 765 |
def test_for_issue_50_1(data_files): |
| 766 |
"""Testing DictType.tagData() for issue #50.""" |
| 767 |
icc_profile_path = data_files[ |
| 768 |
"UP2516D #1 2022-03-20 02-08 D6500 2.2 F-S XYZLUT+MTX.icc" |
| 769 |
] |
| 770 |
iccp = ICCProfile(icc_profile_path) |
| 771 |
dict_type = iccp.tags["meta"] |
| 772 |
# It seems that we can't reproduce the error with this ICC profile. |
| 773 |
assert dict_type.tagData != "" |
| 774 |
|
| 775 |
|
| 776 |
def test_gamut_coverage_1(data_files): |
| 777 |
"""Test getting GAMUT_coverage metadata""" |
| 778 |
icc_profile_path = data_files[ |
| 779 |
"UP2516D #1 2022-03-20 02-08 D6500 2.2 F-S XYZLUT+MTX.icc" |
| 780 |
] |
| 781 |
iccp = ICCProfile(icc_profile_path) |
| 782 |
|
| 783 |
gamuts = ( |
| 784 |
("srgb", "sRGB", GAMUT_VOLUME_SRGB), |
| 785 |
("adobe-rgb", "Adobe RGB", GAMUT_VOLUME_ADOBERGB), |
| 786 |
("dci-p3", "DCI P3", GAMUT_VOLUME_SMPTE431_P3), |
| 787 |
) |
| 788 |
cinfo = [] |
| 789 |
for key, name, _volume in gamuts: |
| 790 |
gamut_coverage = float(iccp.tags.meta.getvalue(f"GAMUT_coverage({key})")) |
| 791 |
if gamut_coverage: |
| 792 |
cinfo.append("%.1f%% %s" % (gamut_coverage * 100, name)) |
| 793 |
assert cinfo == ["99.7% sRGB", "99.1% Adobe RGB", "93.0% DCI P3"] |
| 794 |
|
| 795 |
|
| 796 |
def test_gamut_volume_1(data_files): |
| 797 |
"""Test getting GAMUT_volume metadata""" |
| 798 |
icc_profile_path = data_files[ |
| 799 |
"UP2516D #1 2022-03-20 02-08 D6500 2.2 F-S XYZLUT+MTX.icc" |
| 800 |
] |
| 801 |
iccp = ICCProfile(icc_profile_path) |
| 802 |
|
| 803 |
gamuts = ( |
| 804 |
("srgb", "sRGB", GAMUT_VOLUME_SRGB), |
| 805 |
("adobe-rgb", "Adobe RGB", GAMUT_VOLUME_ADOBERGB), |
| 806 |
("dci-p3", "DCI P3", GAMUT_VOLUME_SMPTE431_P3), |
| 807 |
) |
| 808 |
vinfo = [] |
| 809 |
gamut_volume = float(iccp.tags.meta.getvalue("GAMUT_volume")) |
| 810 |
for _key, name, volume in gamuts: |
| 811 |
vinfo.append( |
| 812 |
"%.1f%% %s" |
| 813 |
% ( |
| 814 |
gamut_volume * GAMUT_VOLUME_SRGB / volume * 100, |
| 815 |
name, |
| 816 |
) |
| 817 |
) |
| 818 |
assert vinfo == ["169.3% sRGB", "116.7% Adobe RGB", "120.0% DCI P3"] |
| 819 |
|
| 820 |
|
| 821 |
def test_set_gamut_metadata_1(data_files): |
| 822 |
"""Test ICCProfile.set_gamut_metadata() method.""" |
| 823 |
icc_profile_path = data_files[ |
| 824 |
"UP2516D #1 2022-03-20 02-08 D6500 2.2 F-S XYZLUT+MTX.icc" |
| 825 |
] |
| 826 |
iccp = ICCProfile(icc_profile_path) |
| 827 |
|
| 828 |
assert iccp.tags.meta["GAMUT_volume"] == "1.6934613892142165" |
| 829 |
assert iccp.tags.meta["GAMUT_coverage(srgb)"] == "0.9967" |
| 830 |
assert iccp.tags.meta["GAMUT_coverage(dci-p3)"] == "0.9296" |
| 831 |
assert iccp.tags.meta["GAMUT_coverage(adobe-rgb)"] == "0.9906" |
| 832 |
|
| 833 |
gamut_volume = 1.695547156240974 |
| 834 |
gamut_coverage = {"srgb": 0.9973000000000001, "dci-p3": 0.9269, "adobe-rgb": 0.9897} |
| 835 |
iccp.set_gamut_metadata(gamut_volume=gamut_volume, gamut_coverage=gamut_coverage) |
| 836 |
|
| 837 |
assert iccp.tags.meta["GAMUT_volume"] == gamut_volume |
| 838 |
assert iccp.tags.meta["GAMUT_coverage(srgb)"] == gamut_coverage["srgb"] |
| 839 |
assert iccp.tags.meta["GAMUT_coverage(dci-p3)"] == gamut_coverage["dci-p3"] |
| 840 |
assert iccp.tags.meta["GAMUT_coverage(adobe-rgb)"] == gamut_coverage["adobe-rgb"] |
| 841 |
|
| 842 |
|
| 843 |
def test_MultiLocalizedUnicodeType_str_method(data_files): |
| 844 |
"""Test for #151.""" |
| 845 |
mlut = MultiLocalizedUnicodeType() |
| 846 |
assert str(mlut) == "" |
| 847 |
|
| 848 |
|
| 849 |
def test_dict_type_to_json(): |
| 850 |
"""Test DictType.to_json() method.""" |
| 851 |
d = DictType() |
| 852 |
d.update( |
| 853 |
{ |
| 854 |
"\xab": "\x00", |
| 855 |
"\xaf": "\x12", |
| 856 |
} |
| 857 |
) |
| 858 |
expected_result = '{"\\u00ab": "\\u0000", "\\u00af": "\\u0012"}' |
| 859 |
assert d.to_json() == expected_result |
| 860 |
|
| 861 |
|
| 862 |
def test_dict_type_to_json_roundtrip_ascii_and_unicode(): |
| 863 |
"""Ensure DictType JSON output round-trips cleanly.""" |
| 864 |
import json |
| 865 |
|
| 866 |
d = DictType() |
| 867 |
d.update({"CMF_product": "DisplayCAL", "©": "ok"}) |
| 868 |
parsed = json.loads(d.to_json()) |
| 869 |
|
| 870 |
assert parsed["CMF_product"] == "DisplayCAL" |
| 871 |
assert parsed["©"] == "ok" |
| 872 |
|
| 873 |
|
| 874 |
def test_hexrepr_unknown_mapping_does_not_append_vendor_name(): |
| 875 |
"""hexrepr should only append mapped names when available.""" |
| 876 |
result = hexrepr(b"ZZZZ", mapping=CMMS) |
| 877 |
assert result == "0x5A5A5A5A 'ZZZZ'" |
| 878 |
|
| 879 |
|
| 880 |
def test_text_tag_invalid_utf8_uses_replacement_character(): |
| 881 |
"""Text.__str__ should decode invalid UTF-8 with replacement.""" |
| 882 |
t = Text(b"\xff") |
| 883 |
assert str(t) == "\ufffd" |
| 884 |
|
| 885 |
|
| 886 |
def test_issue_185_parsing_of_ref_srgb_profile_from_argyllcms(setup_argyll): |
| 887 |
"""Testing for issue #185, opening sRGB.icm from ArgyllCMS raises TypeError.""" |
| 888 |
xicclu_path = which("xicclu") |
| 889 |
srgb_profile_path = None |
| 890 |
if xicclu_path and xicclu_path.startswith("/usr/bin"): |
| 891 |
# linux, system installed ArgyllCMS |
| 892 |
srgb_profile_path = Path("/usr/share/color/argyll/ref/sRGB.icm") |
| 893 |
else: |
| 894 |
argyll = setup_argyll |
| 895 |
srgb_profile_path = argyll / ".." / "ref" / "sRGB.icm" |
| 896 |
|
| 897 |
if not srgb_profile_path.exists(): |
| 898 |
pytest.skip(f"sRGB.icm not found: {srgb_profile_path}") |
| 899 |
|
| 900 |
icc_profile = ICCProfile(srgb_profile_path) |
| 901 |
# the following should not raise an error |
| 902 |
_ = icc_profile.get_info() |