lcms2.icc¶
Reading and writing ICC profiles (v2, v4 and v5) in pure NumPy.
ICCProfile: a profile’s header and raw tags.
ICCSpace: a ~lcms2.spaces.ColorSpace read from a profile.
write_icc_bytes: serialize any ~lcms2.spaces.ColorSpace as a profile (also available as ColorSpace.to_icc_profile).
ICCParseError, ICCWriteError: reading and writing errors.
- class ICCProfile(header: ICCHeader, tags: dict[bytes, bytes], raw: bytes)[source]¶
Bases:
objectA parsed ICC profile.
- Variables:
- classmethod load(path_or_bytes: str | PathLike[str] | bytes | bytearray) ICCProfile[source]¶
Load an ICC profile from a file path or raw bytes.
- classmethod from_bytes(data: bytes) ICCProfile[source]¶
Parse a raw ICC file byte stream into header + tag table.
- Parameters:
data (bytes) – Full contents of an ICC profile file.
- Returns:
ICCProfile – The parsed profile.
- Raises:
ICCParseError – If the data is too small, has a bad file signature, an unsupported major version, or a truncated/out-of-bounds tag table.
- get_tag(sig4: bytes) bytes | None[source]¶
Return the raw bytes of a tag, or None if not present.
- Parameters:
sig4 (bytes) – 4-byte tag signature, e.g.
b'wtpt'.- Returns:
bytes or None
- has_tag(sig4: bytes) bool[source]¶
Return whether the profile contains a tag with this signature.
- Parameters:
sig4 (bytes) – 4-byte tag signature.
- Returns:
bool
- static build_bytes(*, version: Sequence[int] = (4, 4, 0), device_class: bytes = b'spac', data_colour_space: bytes = b'RGB ', pcs: bytes = b'XYZ ', rendering_intent: int = 1, pcs_illuminant: Sequence[float] = (0.9642, 1.0, 0.8249), cmm: bytes = b'\x00\x00\x00\x00', primary_platform: bytes = b'\x00\x00\x00\x00', manufacturer: bytes = b'\x00\x00\x00\x00', model: bytes = b'\x00\x00\x00\x00', attributes: int = 0, flags: int = 0, creator: bytes = b'lcms', created: datetime | None = None, tags: dict[bytes, bytes] | None = None) bytes[source]¶
Serialize a profile from header fields and raw tag data.
Identical tag payloads share one data block, every block is padded to 4 bytes, and v4+ profiles carry the MD5 profile ID of ICC.1.
- Returns:
bytes
- class ICCSpace(source: str | bytes | ICCProfile)[source]¶
Bases:
ColorSpaceA color space read from an ICC profile (v2, v4 or v5).
- Parameters:
source (str, bytes or ICCProfile) – Path to a profile, its bytes, or a parsed ICCProfile.
- Variables:
profile (ICCProfile) – The parsed profile.
description (str or None) – The profile’s description text.
kind (str) –
'matrix_trc','gray_trc'or'lut'.
- to_icc_profile(path: str | None = None, **kwargs: Any) dict[source]¶
Write this space as an ICC profile.
At the profile’s own major version (and without
force_clut) the original tags are written unchanged withmethodset to'verbatim_tags'; otherwise this behaves like ColorSpace.to_icc_profile.- Parameters:
path (str, optional) – File to write the profile to.
**kwargs – Keyword arguments of ColorSpace.to_icc_profile.
- Returns:
dict –
{'bytes': bytes, 'method': str, 'notes': list of str}.
- exception ICCParseError[source]¶
Bases:
LCMSErrorRaised when an ICC profile byte stream is malformed or unsupported.
- exception ICCWriteError[source]¶
Bases:
LCMSErrorRaised when a ColorSpace cannot be represented as a valid ICC profile.
- write_icc_bytes(colorspace: ColorSpace, *, version: Sequence[int] = (4, 4, 0), rendering_intent: int = 1, grid_size: int | None = None, description: str | None = None, copyright: str = 'No copyright, generated by python-lcms2', force_clut: bool = False, strict: bool = False) dict[source]¶
Serialize a ColorSpace into ICC profile bytes.
- Parameters:
colorspace (ColorSpace) – The space to write.
version (tuple of int, optional) –
(major, minor, bugfix). Default(4, 4, 0).rendering_intent (int, optional) – Header rendering intent. Default 1.
grid_size (int, optional) – CLUT grid points per axis for a sampled fallback.
description (str, optional) – Profile description and copyright text.
copyright (str, optional) – Profile description and copyright text.
force_clut (bool, optional) – Always write sampled CLUTs.
strict (bool, optional) – Require an exact profile built from traced functions: raise ICCWriteError, naming the operation that could not be traced, instead of falling back to sampled CLUTs (or to probing the functions numerically).
- Returns:
dict –
{'bytes': bytes, 'method': str, 'notes': list of str}. When the sampled fallback is used, notes says why (naming the untraceable operation).- Raises:
ICCWriteError – If the space cannot be written at all, or with
strict=Truewhen only a sampled fallback would be possible.