Small crate implementing fast conversion between linear float and 8-bit sRGB.
- Maximum error of 0.6 ULP (on integer side) — Note that in practice this is a higher max error than the naive implementation will give you, so for applications like scientific or medical imaging, perhaps this is less acceptable. That said, for normal graphics work, this should be fine.
- Monotonic across the 0.0..=1.0 range. (If
f32_to_srgb8(a) > f32_to_srgb8(b), then
a > b)
- All possible outputs are achievable (round-trips with
f32x4_to_srgb8: Produces results identical to calling
f32_to_srgb84 times in a row. On targets where we have a SIMD implementation (currently SSE2-enabled x86 and x86_64), this will use that. Otherwise, it will just call
f32_to_srgb8four times in a row, and return the results.
- Large performance improvments over the naive implementation (see README.md for benchmarks)
no_std(normally this is tricky, as these operations require
powfnaively, which is not available to libcore)
- No dependencies.
- SIMD support for conversion to sRGB (conversion from sRGB is already ~20x faster than naive impl, and would probably be slower in SIMD, so for now it’s not implemented).
- Consistent and correct (according to at least one relevant spec) handling of edge cases, such as NaN/Inf/etc.
- Exhaustive checking of all inputs for correctness (in tests).
Converts linear f32 RGB component to an 8-bit sRGB value.
Performs 4 simultaneous calls to
Convert from a 8-bit sRGB component to a linear f32.