Skip to main content

ph_color/
lib.rs

1//! Fixed-point `no_std` color math for embedded targets.
2//!
3//! This crate applies baked coefficients and tables to typed [`Color`]
4//! values: [`Matrix3`] and [`Gain`] apply, [`InterpLut`]/[`Gradient`]
5//! interpolation, and [`quantize()`]/[`quantize_round()`]/[`expand`] at the
6//! dither seam. It does not derive, invert, adapt, or solve; host derivation
7//! lives in `ph-color-bake`. Shipped [`SrgbEotf`]/[`SrgbOetf`] tables cover
8//! the sRGB transfer function.
9//!
10//! `feature = "oklab"` adds linear-sRGB ↔ Oklab conversion via [`Oklab`].
11//! `feature = "f32"` adds [`ColorF32`] and `*_f32` apply/lookup/lerp
12//! alongside the fixed-point path; Oklab has no `f32` entry points.
13//!
14//! [`Matrix3`] and [`Gain`] coefficients are [`Q4_28`], not a bare `i32`.
15//! [`Color`] channels and interpolation parameters are [`Q0_16`], not a bare
16//! `u16`.
17
18#![no_std]
19#![forbid(unsafe_code)]
20#![deny(missing_docs)]
21
22pub(crate) mod arith;
23pub mod chromaticities;
24pub mod color;
25#[cfg(feature = "f32")]
26pub(crate) mod color_f32;
27pub mod encoding;
28pub mod fixed;
29pub mod gain;
30pub mod interp;
31pub mod matrix;
32#[cfg(feature = "oklab")]
33pub mod oklab;
34pub mod quantize;
35pub mod space;
36pub mod srgb;
37
38pub use chromaticities::Chromaticities;
39pub use color::Color;
40#[cfg(feature = "f32")]
41pub use color_f32::{ColorF32, F32_MAX_ERR_LSB};
42pub use encoding::{Encoded, Encoding, Linear};
43pub use fixed::{Q0_16, Q4_28};
44pub use gain::Gain;
45pub use interp::{Gradient, InterpLut};
46pub use matrix::Matrix3;
47#[cfg(feature = "oklab")]
48pub use oklab::{
49    A_B_BIAS_Q428, CBRT, CBRT_MAX_ERR_LSB, OKLAB_FORWARD_MAX_LSB, OKLAB_M1, OKLAB_M1_INV, OKLAB_M2,
50    OKLAB_M2_INV, OKLAB_M2_INV_OFFSET, OKLAB_ROUNDTRIP_MAX_LSB, Oklab, oklab_to_srgb,
51    srgb_to_oklab,
52};
53pub use quantize::{expand, quantize, quantize_round};
54pub use space::{ColorSpace, Perceptual, Srgb};
55pub use srgb::{
56    SRGB_EOTF, SRGB_EOTF_MAX_ERR_LSB, SRGB_OETF, SRGB_OETF_MAX_ERR_LSB, SrgbEotf, SrgbOetf,
57};