Expand description
Exact powf()-based conversions with C0-continuous constants.
Uses C0-continuous constants (from the moxcms reference implementation) that eliminate the IEC 61966-2-1 piecewise discontinuity. ~6 ULP max error vs f64 reference. See the module docs for the constant comparison table.
Also provides f64, extended-range (unclamped), and custom gamma functions.
For faster alternatives, use default.
Exact conversion functions using powf().
These functions use the mathematical sRGB transfer function with powf(),
providing maximum accuracy at the cost of speed (~6 ULP max vs f64 reference).
For faster alternatives, use crate::default which provides rational
polynomial approximations (~14 ULP max, ~0.5 ULP avg, perfectly monotonic).
§Constants: C0-continuous (moxcms)
Both this module and crate::default use C0-continuous constants (from the
moxcms reference implementation) that eliminate the ~2.3×10⁻⁹ discontinuity
present in the IEC 61966-2-1 textbook constants:
| Constant | IEC textbook | This crate |
|---|---|---|
| Gamma threshold | 0.04045 | 0.039293… |
| Linear threshold | 0.0031308 | 0.003041… |
| Offset (a) | 0.055 | 0.055011… |
The adjusted constants solve 12.92 × threshold = (1+a) × threshold^(1/2.4) − a
exactly, making the piecewise function mathematically continuous. The difference
is unmeasurable at u8 precision and within 1 LSB at u16.
§Extended-range variants
The _extended functions do not clamp to [0, 1], making them suitable
for HDR, ICC, and cross-gamut pipelines. See the crate-level docs on
clamping for details.
Functions§
- gamma_
to_ linear_ f64 - Convert gamma-encoded value to linear using a custom gamma exponent (f64).
- linear_
to_ gamma_ f64 - Convert linear value to gamma-encoded using a custom gamma exponent (f64).
- linear_
to_ srgb - Convert linear light value to sRGB gamma-encoded (f32).
- linear_
to_ srgb_ extended - Convert linear light value to sRGB gamma-encoded without clamping (f32).
- linear_
to_ srgb_ f64 - Convert linear light value to sRGB gamma-encoded (f64).
- srgb_
to_ linear - Convert sRGB gamma-encoded value to linear light (f32).
- srgb_
to_ linear_ extended - Convert sRGB gamma-encoded value to linear light without clamping (f32).
- srgb_
to_ linear_ f64 - Convert sRGB gamma-encoded value to linear light (f64).