Skip to main content

Crate ph_color

Crate ph_color 

Source
Expand description

Fixed-point no_std color math for embedded targets.

This crate applies baked coefficients and tables to typed Color values: Matrix3 and Gain apply, InterpLut/Gradient interpolation, and quantize()/quantize_round()/expand at the dither seam. It does not derive, invert, adapt, or solve; host derivation lives in ph-color-bake. Shipped SrgbEotf/SrgbOetf tables cover the sRGB transfer function.

feature = "oklab" adds linear-sRGB ↔ Oklab conversion via Oklab. feature = "f32" adds ColorF32 and *_f32 apply/lookup/lerp alongside the fixed-point path; Oklab has no f32 entry points.

Matrix3 and Gain coefficients are Q4_28, not a bare i32. Color channels and interpolation parameters are Q0_16, not a bare u16.

Re-exports§

pub use chromaticities::Chromaticities;
pub use color::Color;
pub use encoding::Encoded;
pub use encoding::Encoding;
pub use encoding::Linear;
pub use fixed::Q0_16;
pub use fixed::Q4_28;
pub use gain::Gain;
pub use interp::Gradient;
pub use interp::InterpLut;
pub use matrix::Matrix3;
pub use oklab::A_B_BIAS_Q428;
pub use oklab::CBRT;
pub use oklab::CBRT_MAX_ERR_LSB;
pub use oklab::OKLAB_FORWARD_MAX_LSB;
pub use oklab::OKLAB_M1;
pub use oklab::OKLAB_M1_INV;
pub use oklab::OKLAB_M2;
pub use oklab::OKLAB_M2_INV;
pub use oklab::OKLAB_M2_INV_OFFSET;
pub use oklab::OKLAB_ROUNDTRIP_MAX_LSB;
pub use oklab::Oklab;
pub use oklab::oklab_to_srgb;
pub use oklab::srgb_to_oklab;
pub use quantize::expand;
pub use quantize::quantize;
pub use quantize::quantize_round;
pub use space::ColorSpace;
pub use space::Perceptual;
pub use space::Srgb;
pub use srgb::SRGB_EOTF;
pub use srgb::SRGB_EOTF_MAX_ERR_LSB;
pub use srgb::SRGB_OETF;
pub use srgb::SRGB_OETF_MAX_ERR_LSB;
pub use srgb::SrgbEotf;
pub use srgb::SrgbOetf;

Modules§

chromaticities
CIE xy chromaticities stored as millionths. Identity metadata only.
color
Typed color triple.
encoding
Sealed encoding: linear versus transfer-encoded.
fixed
Fixed-point value types (see docs/NUMERICS.md): Q4_28, the single signed format for every matrix and gain coefficient, and Q0_16, the single unsigned format for every color channel and interpolation parameter.
gain
Typed per-channel gain on linear colors of one space.
interp
Interpolation LUTs and color gradients.
matrix
Typed 3×3 matrix from linear Src to linear Dst.
oklab
Feature-gated linear-sRGB <-> Oklab conversion.
quantize
Policy-free bit-depth reduction for the dither seam.
space
Open color-space trait and the built-in sRGB space.
srgb
Shipped sRGB EOTF/OETF tables. Host ph-color-bake derived the knots; this crate only applies them.

Structs§

ColorF32
Three f32 channels tagged with space and encoding.

Constants§

F32_MAX_ERR_LSB
Maximum absolute error of the f32 path versus frozen UQ0.16 W7 goldens, in LSBs after rounding (channel * 65535) to nearest (half away from zero).