Fast linear↔sRGB color space conversion.
This crate is no_std compatible by default. Enable the std feature
if you need std library support.
This crate provides efficient conversion between linear light values and sRGB gamma-encoded values following the IEC 61966-2-1:1999 standard.
Features
- Direct computation: Single value conversion with piecewise functions
- FMA acceleration: Uses hardware FMA when available (x86 FMA, ARM64 NEON)
- LUT-based conversion: Pre-computed tables for batch processing
- Multiple precisions: f32, f64, and u8/u16 conversions
Quick Start
use ;
// Convert sRGB 0.5 to linear
let linear = srgb_to_linear;
assert!;
// Convert back to sRGB
let srgb = linear_to_srgb;
assert!;
LUT-based Conversion
For batch processing, use SrgbConverter which pre-computes lookup tables:
use SrgbConverter;
let conv = new;
// Fast 8-bit conversions
let linear = conv.srgb_u8_to_linear;
let srgb = conv.linear_to_srgb_u8;
Performance
The implementation uses several optimizations:
- Piecewise functions avoid
pow()for ~1.2% of values in the linear segment - Early exit for out-of-range values avoids expensive transcendentals
- FMA instructions combine multiply+add into single-cycle operations
- Pre-computed LUTs trade memory for compute time
Feature Flags
fast-math: Use faster but slightly less accurate pow approximation for extended range conversions (affectslinear_to_srgb_extendedonly)
SIMD Acceleration
For maximum throughput on large batches, use the simd module:
use simd;
let mut values = vec!;
srgb_to_linear_slice;