lcms2.Profile

class Profile(source: Any = None, *, white_point: Any = None, degrees: int = 2, temperature: float | None = None)[source]

Bases: ProfileData

An 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"; see builtins()), a path to an .icc/.icm file, raw profile bytes, an object with to_icc_profile() (a ColorSpace) 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_id()

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 limit percent.

is_clut([intent, direction])

Whether intent is implemented by a CLUT in direction (input/output/proof).

is_intent_supported(intent[, direction])

Whether the profile implements intent in direction (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 data from this profile to to; same keywords as lcms2.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

channels

Number of channels of the data colour space.

chromatic_adaptation

The chad 3x3 matrix, or None.

color_space

Data colour space ("RGB", "CMYK", "Lab" ...).

colorants

3x3 array of the rXYZ, gXYZ, bXYZ rows, or None when not a matrix-shaper.

copyright

Copyright text (settable).

creation_date

Creation date from the header.

description

Profile description text (settable).

device_class

Profile class (display, output, link ...).

header

Raw header fields (signatures as 4-character strings).

is_matrix_shaper

Whether the profile is a matrix-shaper.

luminance

XYZ of the luminance tag (cd/m²), or None.

manufacturer

Device manufacturer text (settable).

media_white_point

XYZ of the media white point tag, or None.

model

Device model text (settable).

named_colors

Named colours (name, prefix, suffix, pcs, colorants) or None.

pcs

Profile connection space ("XYZ" or "Lab").

profile_id

The 16-byte MD5 profile ID (zeros when unset); see compute_id().

rendering_intent

Header rendering intent (settable).

space

A lcms2.spaces.ColorSpace view of this profile (pure NumPy evaluation).

supported_intents

ICC intents the profile implements as input or output.

tac

Total area coverage (max ink sum, percent) of an output profile; 0 when not applicable.

tags

Tag signatures present in the profile (4-character strings).

trc

Tone curves by tag (rTRC, gTRC, bTRC, kTRC) that are present.

version

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_xyz are traced into an exact profile.

  • strict (bool, optional) – Raise ICCWriteError instead 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 srgb() → Profile[source]

LittleCMS’s built-in sRGB profile.

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 xyz() → Profile[source]

XYZ identity profile (D50 PCS, Y = 1 for the white).

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 limit percent.

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.ColorSpace view of this profile (pure NumPy evaluation).

Examples

>>> import lcms2
>>> lcms2.Profile("sRGB").space.n_channels
3
to_bytes() → bytes[source]

The profile as ICC bytes.

save(path: str | PathLike[str]) → None[source]

Write the profile to a file.

property description: str

Profile description text (settable).

property manufacturer: str

Device manufacturer text (settable).

property model: str

Device model text (settable).

property copyright: str

Copyright text (settable).

property header: dict[str, Any]

Raw header fields (signatures as 4-character strings).

set_header(**fields: Any) → None[source]

Change header fields: device_class, color_space, pcs, version, rendering_intent, flags, manufacturer, model, attributes, profile_id.

property color_space: ColorSpaceSignature | str

Data colour space ("RGB", "CMYK", "Lab" …).

property pcs: ColorSpaceSignature | str

Profile connection space ("XYZ" or "Lab").

property device_class: DeviceClass | str

Profile class (display, output, link …).

property version: float

ICC version, e.g. 4.3 or 2.1 (settable).

property channels: int

Number of channels of the data colour space.

property rendering_intent: Intent | int

Header rendering intent (settable).

property creation_date: datetime | None

Creation date from the header.

property profile_id: bytes

The 16-byte MD5 profile ID (zeros when unset); see compute_id().

compute_id() → bytes[source]

Compute the MD5 profile ID, store it in the header and return it.

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 data from this profile to to; same keywords as lcms2.convert().

Examples

>>> Profile("sRGB").transform([255, 255, 255], "Lab").round(2) + 0.0
array([100.,   0.,   0.])