linear_srgb/precise.rs
1//! Exact conversion functions using `powf()`.
2//!
3//! These functions use the mathematical sRGB transfer function with `powf()`,
4//! providing maximum accuracy at the cost of speed (~6 ULP max vs f64 reference).
5//! For faster alternatives, use [`crate::default`] which provides rational
6//! polynomial approximations (~14 ULP max, ~0.5 ULP avg, perfectly monotonic).
7//!
8//! # Constants: C0-continuous (moxcms)
9//!
10//! Both this module and [`crate::default`] use C0-continuous constants (from the
11//! moxcms reference implementation) that eliminate the ~2.3×10⁻⁹ discontinuity
12//! present in the IEC 61966-2-1 textbook constants:
13//!
14//! | Constant | IEC textbook | This crate |
15//! |----------|-------------|------------|
16//! | Gamma threshold | 0.04045 | 0.039293... |
17//! | Linear threshold | 0.0031308 | 0.003041... |
18//! | Offset (*a*) | 0.055 | 0.055011... |
19//!
20//! The adjusted constants solve `12.92 × threshold = (1+a) × threshold^(1/2.4) − a`
21//! exactly, making the piecewise function mathematically continuous. The difference
22//! is unmeasurable at u8 precision and within 1 LSB at u16.
23//!
24//! # Extended-range variants
25//!
26//! The `_extended` functions do not clamp to \[0, 1\], making them suitable
27//! for HDR, ICC, and cross-gamut pipelines. See the crate-level docs on
28//! clamping for details.
29
30// sRGB f32 (powf, clamped)
31pub use crate::scalar::{linear_to_srgb, srgb_to_linear};
32
33// sRGB f32 (powf, extended/unclamped)
34pub use crate::scalar::{linear_to_srgb_extended, srgb_to_linear_extended};
35
36// sRGB f64 (powf)
37pub use crate::scalar::{linear_to_srgb_f64, srgb_to_linear_f64};
38
39// Custom gamma f64
40pub use crate::scalar::{gamma_to_linear_f64, linear_to_gamma_f64};