| 1 |
#!/usr/bin/env python3 |
| 2 |
from time import strftime |
| 3 |
import binascii |
| 4 |
import os |
| 5 |
import sys |
| 6 |
|
| 7 |
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")) |
| 8 |
|
| 9 |
from DisplayCAL import colormath |
| 10 |
from DisplayCAL.icc_profile import ICCProfile, get_display_profile, XYZType |
| 11 |
|
| 12 |
|
| 13 |
def prettyprint(iterable, level=1): |
| 14 |
for key in iterable: |
| 15 |
value = iterable[key] |
| 16 |
if hasattr(value, "items"): |
| 17 |
print(" " * 4 * level, "%s:" % key.capitalize()) |
| 18 |
prettyprint(value, level + 1) |
| 19 |
else: |
| 20 |
print(" " * 4 * level, "%s:" % key.capitalize(), value) |
| 21 |
|
| 22 |
|
| 23 |
def profileinfo(profile): |
| 24 |
if not isinstance(profile, ICCProfile): |
| 25 |
profile = ICCProfile(profile) |
| 26 |
# Attributes |
| 27 |
print("Size:", profile.size, "Bytes (%.1f KB)" % (profile.size / 1024.0)) |
| 28 |
print("Preferred CMM:", profile.preferredCMM) |
| 29 |
print("ICC version:", profile.version) |
| 30 |
print("Class:", profile.profileClass) |
| 31 |
print("Colorspace:", profile.colorSpace) |
| 32 |
print("PCS:", profile.connectionColorSpace) |
| 33 |
print("Date/Time:", strftime("%Y-%m-%d %H:%M:%S", profile.dateTime + (0, 0, -1))) |
| 34 |
print("Platform:", profile.platform) |
| 35 |
print("Embedded:", profile.embedded) |
| 36 |
print("Independent:", profile.independent) |
| 37 |
print("Device:") |
| 38 |
for key in ("manufacturer", "model"): |
| 39 |
profile.device[key] = binascii.hexlify(profile.device[key]).upper() |
| 40 |
prettyprint(profile.device) |
| 41 |
print("Rendering Intent:", profile.intent) |
| 42 |
print("Illuminant:", " ".join(str(n * 100) for n in profile.illuminant.values())) |
| 43 |
print("Creator:", profile.creator) |
| 44 |
print("ID:", binascii.hexlify(profile.ID).upper()) |
| 45 |
# Tags |
| 46 |
print("Description:", profile.getDescription()) |
| 47 |
print("Copyright:", profile.getCopyright()) |
| 48 |
if "dmnd" in profile.tags: |
| 49 |
print( |
| 50 |
"Device Manufacturer Description:", |
| 51 |
) |
| 52 |
print(profile.getDeviceManufacturerDescription()) |
| 53 |
if "dmdd" in profile.tags: |
| 54 |
print("Device Model Description:", profile.getDeviceModelDescription()) |
| 55 |
if "vued" in profile.tags: |
| 56 |
print( |
| 57 |
"Viewing Conditions Description:", |
| 58 |
) |
| 59 |
print(profile.getViewingConditionsDescription()) |
| 60 |
wtpt_profile_norm = tuple(n * 100 for n in profile.tags.wtpt.values()) |
| 61 |
if "chad" in profile.tags: |
| 62 |
# undo chromatic adaption of profile whitepoint |
| 63 |
X, Y, Z = wtpt_profile_norm |
| 64 |
M = colormath.Matrix3x3(profile.tags.chad).inverted() |
| 65 |
XR = X * M[0][0] + Y * M[0][1] + Z * M[0][2] |
| 66 |
YR = X * M[1][0] + Y * M[1][1] + Z * M[1][2] |
| 67 |
ZR = X * M[2][0] + Y * M[2][1] + Z * M[2][2] |
| 68 |
wtpt_profile_norm = tuple((n / YR) * 100.0 for n in (XR, YR, ZR)) |
| 69 |
if "lumi" in profile.tags and isinstance(profile.tags.lumi, XYZType): |
| 70 |
print("Luminance:", profile.tags.lumi.Y) |
| 71 |
print("Actual Whitepoint XYZ:", " ".join(str(n) for n in wtpt_profile_norm)) |
| 72 |
print("Correlated Color Temperature:", colormath.XYZ2CCT(*wtpt_profile_norm)) |
| 73 |
|
| 74 |
|
| 75 |
if __name__ == "__main__": |
| 76 |
for arg in sys.argv[1:] or [get_display_profile()]: |
| 77 |
profileinfo(arg) |