Skip to main content

Module gamut

Module gamut 

Source
Expand description

P7.2 — Gamut / object-colour solid + closest-point gamut mapping. P7.2 — Gamut / object-colour solid as a convex polytope + closest-point gamut mapping.

The sRGB gamut is the convex hull of the primary colours (red, green, blue) and their combinations in XYZ space. An out-of-gamut colour is mapped to the closest point on the gamut boundary.

§Algorithm

  1. The sRGB gamut is the set of all (R,G,B) with 0 ≤ R,G,B ≤ 1, mapped through the sRGB→XYZ matrix.
  2. In-gamut check: convert XYZ to linear sRGB; if all channels are in [0,1], the colour is in-gamut.
  3. Out-of-gamut mapping: clamp each sRGB channel to [0,1] and convert back to XYZ. This is a simple (non-optimal) closest-point mapping.

§Determinism

All operations are deterministic: the XYZ→sRGB matrix is a constant, and clamping is a pure function.

Enums§

GamutError
Gamut mapping error.

Functions§

gamut_map_clamp
Map an out-of-gamut colour to the closest in-gamut colour.
gamut_map_idempotent
Interior idempotence: an in-gamut colour maps to itself.
is_in_gamut
Check if a colour is in the sRGB gamut (all linear sRGB channels in [0,1]).
linear_rgb_is_in_gamut
Check if a linear sRGB colour is in gamut.
linear_srgb_to_xyz
Convert linear sRGB to CIE XYZ (inverse of xyz_to_linear_srgb).