lcms2.Profile¶
- class Profile(source: Any = None, *, white_point: Any = None, degrees: int = 2, temperature: float | None = None)[source]¶
Bases:
ProfileDataAn ICC profile.
- Parameters:
source (str, os.PathLike, bytes, Profile, colour space or None) – A built-in name (case-insensitive, lenient:
"adobe rgb","display p3","prophoto"; seebuiltins()), a path to an.icc/.icmfile, raw profile bytes, an object withto_icc_profile()(aColorSpace) or None for the NULL profile.white_point (str or sequence of float, optional) – For
"Lab"only: illuminant name ("D65") or xyY of the Lab white (D50 by default).degrees ({2, 10}) – Observer for illuminant names.
temperature (float, optional) – For
"Lab"only: white point as a daylight colour temperature in kelvin.
- Raises:
FileNotFoundError – For a string that is neither a built-in name nor an existing file.
CMSError – When the data is not a valid ICC profile.
Examples
>>> import lcms2 >>> p = lcms2.Profile("sRGB") >>> p.color_space, p.device_class (<ColorSpaceSignature.RGB: 'RGB'>, <DeviceClass.DISPLAY: 'display'>) >>> lcms2.Profile("display p3").description 'Display P3'
- __init__(source: Any = None, *, white_point: Any = None, degrees: int = 2, temperature: float | None = None) None[source]¶
Methods
__init__([source, white_point, degrees, ...])abstract([brightness, contrast, hue, ...])Abstract Lab profile adjusting brightness, contrast, hue, saturation and white temperature.
black_point([intent, destination])Detected black point XYZ (Y = 1 white) or None.
builtin(name)A built-in profile by (lenient) name; see
builtins().builtins()Names of the built-in profiles.
Compute the MD5 profile ID, store it in the header and return it.
from_bytes(data)Parse a profile from memory.
from_space(space[, strict])An exact profile of a colour space object (anything with
to_icc_profile()).gray([white_point, gamma, degrees])Gray profile from a white point and a transfer function (gamma, ToneCurve or (type, params)).
has_tag(sig)Whether the profile has tag
sig.ink_limiting([limit, color_space])CMYK device link limiting total ink coverage to
limitpercent.is_clut([intent, direction])Whether
intentis implemented by a CLUT indirection(input/output/proof).is_intent_supported(intent[, direction])Whether the profile implements
intentindirection(input/output/proof).lab([white_point, version, degrees, temperature])Lab identity profile (v4 or v2) relative to a white point (D50 by default).
linearization(curves[, color_space])Device link applying one curve (gamma, ToneCurve or (type, params)) per channel.
open(path)Read a profile file (any path, including non-ASCII ones on Windows).
read_tag_raw(sig)Serialised tag data including its 8-byte type header.
rgb([white_point, primaries, gamma, ...])Matrix-shaper RGB profile.
save(path)Write the profile to a file.
set_header(**fields)Change header fields: device_class, color_space, pcs, version, rendering_intent, flags, manufacturer, model, attributes, profile_id.
srgb()LittleCMS's built-in sRGB profile.
to_bytes()The profile as ICC bytes.
transform(data, to, *[, intent, bpc, proof, ...])Convert
datafrom this profile toto; same keywords aslcms2.convert().write_tag_raw(sig, data)Store raw tag data (with its type header) under
sig.xyz()XYZ identity profile (D50 PCS, Y = 1 for the white).
Attributes
Number of channels of the data colour space.
chromatic_adaptationThe
chad3x3 matrix, or None.Data colour space (
"RGB","CMYK","Lab"...).colorants3x3 array of the rXYZ, gXYZ, bXYZ rows, or None when not a matrix-shaper.
Copyright text (settable).
Creation date from the header.
Profile description text (settable).
Profile class (
display,output,link...).Raw header fields (signatures as 4-character strings).
is_matrix_shaperWhether the profile is a matrix-shaper.
luminanceXYZ of the luminance tag (cd/m²), or None.
Device manufacturer text (settable).
media_white_pointXYZ of the media white point tag, or None.
Device model text (settable).
named_colorsNamed colours
(name, prefix, suffix, pcs, colorants)or None.Profile connection space (
"XYZ"or"Lab").The 16-byte MD5 profile ID (zeros when unset); see
compute_id().Header rendering intent (settable).
A
lcms2.spaces.ColorSpaceview of this profile (pure NumPy evaluation).supported_intentsICC intents the profile implements as input or output.
tacTotal area coverage (max ink sum, percent) of an output profile; 0 when not applicable.
tagsTag signatures present in the profile (4-character strings).
trcTone curves by tag (
rTRC,gTRC,bTRC,kTRC) that are present.ICC version, e.g. 4.3 or 2.1 (settable).
- classmethod open(path: str | PathLike[str]) Profile[source]¶
Read a profile file (any path, including non-ASCII ones on Windows).
- classmethod from_bytes(data: bytes | bytearray | memoryview) Profile[source]¶
Parse a profile from memory.
Examples
>>> p = Profile.from_bytes(Profile("sRGB").to_bytes()) >>> p.description 'sRGB built-in'
- classmethod from_space(space: Any, strict: bool = False) Profile[source]¶
An exact profile of a colour space object (anything with
to_icc_profile()).- Parameters:
space (ColorSpace) – The space; its NumPy
to_xyz/from_xyzare traced into an exact profile.strict (bool, optional) – Raise
ICCWriteErrorinstead of falling back to sampled lookup tables when the functions cannot be traced (data-dependent branching,float(), random numbers, non-NumPy libraries). Default False.
- Raises:
ICCWriteError – With
strict=True, naming the operation that prevents an exact profile.
- classmethod builtin(name: str) Profile[source]¶
A built-in profile by (lenient) name; see
builtins().
- static builtins() list[str][source]¶
Names of the built-in profiles.
Examples
>>> "Display P3" in Profile.builtins() True
- classmethod lab(white_point: Any = None, *, version: int = 4, degrees: int = 2, temperature: float | None = None) Profile[source]¶
Lab identity profile (v4 or v2) relative to a white point (D50 by default).
Examples
>>> Profile.lab("D65").color_space <ColorSpaceSignature.LAB: 'Lab'>
- classmethod rgb(white_point: Any = 'D65', primaries: Sequence[Sequence[float]] = ((0.64, 0.33), (0.3, 0.6), (0.15, 0.06)), gamma: Any = 2.2, *, degrees: int = 2, description: str | None = None) Profile[source]¶
Matrix-shaper RGB profile.
- Parameters:
white_point (str or sequence of float) – Illuminant name or xyY.
primaries (three (x, y) or (x, y, Y) sequences) – Red, green and blue chromaticities.
gamma (float, ToneCurve, (type, params) or a sequence of 3 of those) – Transfer function(s) from encoded to linear values.
description (str, optional) – Profile description text. Defaults to one naming the white point and gamma, such as
"RGB (D65, gamma 2.2)".
Examples
>>> Profile.rgb("D65", gamma=2.2).description 'RGB (D65, gamma 2.2)' >>> p = Profile.rgb("D65", gamma=2.2, description="my RGB") >>> p.description, p.is_matrix_shaper ('my RGB', True)
- classmethod gray(white_point: Any = 'D50', gamma: Any = 2.2, *, degrees: int = 2) Profile[source]¶
Gray profile from a white point and a transfer function (gamma, ToneCurve or (type, params)).
- classmethod abstract(brightness: float = 0.0, contrast: float = 1.0, hue: float = 0.0, saturation: float = 0.0, *, temp_src: int = 0, temp_dst: int = 0, lut_points: int = 17) Profile[source]¶
Abstract Lab profile adjusting brightness, contrast, hue, saturation and white temperature.
- classmethod ink_limiting(limit: float = 300.0, color_space: str = 'CMYK') Profile[source]¶
CMYK device link limiting total ink coverage to
limitpercent.
- classmethod linearization(curves: Sequence[Any], color_space: str = 'RGB') Profile[source]¶
Device link applying one curve (gamma, ToneCurve or (type, params)) per channel.
- property space: ICCSpace¶
A
lcms2.spaces.ColorSpaceview of this profile (pure NumPy evaluation).Examples
>>> import lcms2 >>> lcms2.Profile("sRGB").space.n_channels 3
- set_header(**fields: Any) None[source]¶
Change header fields: device_class, color_space, pcs, version, rendering_intent, flags, manufacturer, model, attributes, profile_id.
- property profile_id: bytes¶
The 16-byte MD5 profile ID (zeros when unset); see
compute_id().
- transform(data: Any, to: Any, *, intent: Any = 'relative', bpc: bool = False, proof: Any = None, gamut_check: bool = False, optimize: bool = True, precision: str = 'auto', flags: Any = None, out: ndarray | None = None, out_dtype: DTypeLike = None) ndarray[source]¶
Convert
datafrom this profile toto; same keywords aslcms2.convert().Examples
>>> Profile("sRGB").transform([255, 255, 255], "Lab").round(2) + 0.0 array([100., 0., 0.])