Skip to main content

Crate gamut_color

Crate gamut_color 

Source
Expand description

Color primitives for the gamut codecs: pixel formats, bit depths, chroma subsampling, the CICP code points carried in nclx / AV1 sequence headers, and planar buffers.

The M0 AVIF encoder uses only a narrow slice — 8-bit RGB in, mapped to identity (mc = 0) 4:4:4 planes. The enums here intentionally model the wider spec surface (more formats, bit depths, subsamplings, and CICP code points) so later milestones (M2 pixel formats, M4 HDR; see gamut-avif/STATUS.md) extend without reshaping the types.

On top of that metadata layer, the transfer, oklab, matrix, gamut_map, and profile modules add f64 colour science — encoder-exact EOTFs, OKLab transforms with per-gamut matrices (derived from chromaticities via Bradford adaptation), gamut clamping, and source-profile bundles over the CICP axes. This math is Tier-1 (correctness only): it uses std f64, so it is not bit-reproducible across platforms — see references/color/README.md.

Re-exports§

pub use cicp::ColorRange;
pub use cicp::ColourPrimaries;
pub use cicp::MatrixCoefficients;
pub use cicp::TransferCharacteristics;

Modules§

cicp
CICP (ITU-T H.273 / ISO/IEC 23091-2) code points shared by the AVIF colr (nclx) box and the AV1 sequence header color_config (AV1 §5.5.2 / §6.4.2).
gamut_map
sRGB gamut membership and a hue-preserving soft gamut clamp.
matrix
Derivation of RGB→XYZ and OKLab M1 matrices from CIE 1931 chromaticities, with Bradford chromatic adaptation.
oklab
OKLab transforms and the per-gamut linear-RGB → LMS (M1) matrices.
profile
Source-profile bundle: ties a colour-science Gamut together with its encoder-exact transfer (and tone map) and projects them back onto gamut’s independent CICP axes.
transfer
Transfer functions (EOTF / inverse-EOTF) in f64, covering the gamuts the gamut ecosystem encodes through.

Structs§

Planar8
Three full-resolution (4:4:4) 8-bit planes, each width * height samples, row-major.
Yuv420
A BT.601 YCbCr image in 4:2:0 layout: a width × height luma plane and two chroma_width × chroma_height chroma planes, all row-major 8-bit, where the chroma dimensions are ceil(width / 2) and ceil(height / 2). The signal range is a property of the conversion (Bt601Range), not of the stored planes.

Enums§

BitDepth
Bits per sample of a coded plane.
Bt601Range
The signal range of a BT.601 YCbCr encoding. See the module docs for which to use.
ChromaSubsampling
Chroma subsampling of the coded planes (AV1 subsampling_x / subsampling_y, §5.5.2).

Functions§

clip_pixel
Saturates a computed integer sample to the unsigned bit_depth-bit pixel range 0..=(1 << bit_depth) - 1 (AV1 Clip1, §3) — the high-bit-depth companion to clip_pixel8.
clip_pixel8
Saturates a computed integer sample to the unsigned 8-bit pixel range 0..=255.
rgb_to_ycbcr
Converts one RGB triple to BT.601 YCbCr in the given Bt601Range (each component 0..=255).
ycbcr_to_rgb
Converts one BT.601 YCbCr triple in the given Bt601Range back to RGB (each 0..=255).