Most Rust image libraries force a bad trade-off: either every small decoder
links hundreds of kilobytes of SIMD tables you never call, or turning SIMD on
breaks no_std and Wasm builds.
zenpixels-convert 0.5 separates correctness from SIMD codegen. Every
valid native pixel pair works out of the box through a compact, zero-heap-scratch
64-pixel L1 stack strip engine (Accelerators::SCALAR) that produces the
exact same bytes (0-bit diff) as the x86-64, AArch64, and WASM128 SIMD
kernels. From there, you opt into only the SIMD families your binary actually
needs — using one-line startup presets or compile-time const Accelerators
helpers.
| What you are building | Recommended setup | Why |
|---|---|---|
| App, CLI, server, or benchmark | Call Accelerators::ALL.install_global() once in main() | Unlocks every compiled SIMD family (including gain-map SIMD) across the process and inside codecs |
| Image pipeline without gain maps | Accelerators::ROW_PIPELINE.install_global() | Full RowPlan / ImagePlan SIMD while dead-stripping gain-map SIMD (+0 B) |
| Web SDR image service | Accelerators::WEB_SDR.install_global() | Accelerates byte layout, strip SIMD, sRGB, 3×3 gamut, and fused U8 sRGB-matrix; BT.709, Gamma 2.2, F16, PQ, HLG, Oklab, and GainMap SIMD dead-strip |
| Modern Web HDR (AVIF / JXL / UltraHDR) | Accelerators::WEB_HDR.install_global() | WEB_SDR + HDR (F16, PQ, HLG) + GAINMAP (when compiled); dead-strips BT.709, Gamma 2.2, and Oklab |
| Tiny Wasm or embedded module | Leave default SCALAR, or pass a custom const Accelerators + default-features = false | Links 0 B of unused SIMD kernels while keeping full format coverage |
| Reusable codec or library crate | Never call enable_*() and never enable Cargo feature fast | Stays tiny for downstream callers; automatically speeds up when the host binary opts in |
| Bit-exact parity test suite | .with_accelerators(Accelerators::SCALAR) vs Accelerators::ALL | Forces scalar execution hermetically even if Accelerators::ALL.install_global() ran earlier |
Do nothing special in library crates, codecs, or size-sensitive tools:
use zenpixels_convert::{
AlphaPolicy, ConvertPolicy, PixelBuf, PixelConvertExt, PixelFormat,
};
let src = PixelBuf::from_typed(vec![64u8, 128, 192, 255], 1, 1, PixelFormat::RGBA8_SRGB)?;
let mut dst = PixelBuf::new(1, 1, PixelFormat::RGBF32_LINEAR)?;
let policy = ConvertPolicy::lossless().with_alpha(AlphaPolicy::DiscardUnchecked);
src.convert_into(&mut dst, &policy)?;
assert_eq!(dst.row(0).len(), 12);Every native format pair succeeds with zero heap scratch and matches the SIMD
kernels bit-for-bit (0-bit parity). Unused SIMD kernels are never referenced,
so LTO dead-strips them to 0 B.
In an application’s main() (or benchmark setup), install SIMD accelerators
into the lock-free process registry once. Every subsequent RowPlan::build,
ImagePlan::build, OutputPlan::build, PlanarCapturePlan::build, and
convert_to call — including calls deep inside codecs — immediately uses
them:
use zenpixels_convert::Accelerators;
// Turn on every compiled SIMD kernel (row pipeline + gain-map SIMD):
let _ = Accelerators::ALL.install_global();
// Or install a targeted preset (the first installation wins):
let _ = Accelerators::ROW_PIPELINE.install_global(); // Full row/image SIMD, dead-strips gainmap SIMD
let _ = Accelerators::WEB_HDR.install_global(); // Modern AVIF/JXL/UltraHDR: WEB_SDR + HDR + GAINMAP
let _ = Accelerators::WEB_SDR.install_global(); // Byte layout + strip SIMD + sRGB + 3x3 gamut + srgb8 matrix
let _ = Accelerators::LAYOUT.install_global(); // Any const Accelerators valueAll enable_* / install helpers are thread-safe (no_std + alloc via
once_cell::race::OnceBox). Any conversion outside the installed slots
seamlessly executes on the 0-bit-identical scalar core.
const Accelerators helpersWhen you want zero global state, exact dead-stripping per pipeline, or
hermetic parity testing, compose an Accelerators value at compile time with
the const presets and builders and pass it by value to
ConvertPolicy::with_accelerators(...):
use zenpixels_convert::{
Accelerators, ConvertPolicy, PixelBuf, PixelFormat, PixelConvertExt, formats,
};
// Built-in const presets:
// Accelerators::SCALAR — pure scalar core (0 B SIMD linked)
// Accelerators::LAYOUT — garb byte swizzle, alpha add/drop, U8 gray, U8 premul
// Accelerators::WEB_SDR — layout + strip SIMD + sRGB + 3x3 gamut + fused srgb8 matrix
// Accelerators::WEB_HDR — WEB_SDR + HDR (F16 + PQ/HLG) + GAINMAP (for AVIF/JXL/UltraHDR)
// Accelerators::HDR — strip SIMD + F16 + PQ/HLG + 3x3 gamut
// Accelerators::OKLAB — strip SIMD + Oklab / SoftCompress (requires `oklab` feature)
// Accelerators::GAINMAP — ISO 21496-1 gain-map SIMD (requires `gainmap` feature)
// Accelerators::ROW_PIPELINE — WEB_SDR + HDR + BT.709 + Gamma 2.2 + OKLAB (no gainmap)
// Accelerators::ALL — ROW_PIPELINE + GAINMAP
// Compose your exact SIMD budget at compile time:
const THUMBNAIL_SIMD: Accelerators = Accelerators::SCALAR
.with_byte_layout()
.with_strip_simd()
.with_srgb();
// Or combine presets with merge_prefer_self:
const PHOTO_EDIT_SIMD: Accelerators = Accelerators::WEB_SDR
.with_oklab()
.merge_prefer_self(Accelerators::HDR);
let src = PixelBuf::from_typed(vec![64u8, 128, 192], 1, 1, PixelFormat::RGB8_SRGB)?;
let simd_policy = ConvertPolicy::lossless().with_accelerators(THUMBNAIL_SIMD);
let scalar_policy = ConvertPolicy::lossless().with_accelerators(Accelerators::SCALAR);
let dst_simd = src.convert_to(&formats::RGBF32_LINEAR, &simd_policy)?;
let dst_scalar = src.convert_to(&formats::RGBF32_LINEAR, &scalar_policy)?;
// 0-bit identical output across SIMD and scalar:
assert_eq!(dst_simd.row(0), dst_scalar.row(0));How const Accelerators keeps compilation and binaries light: each slot in
Accelerators is an Option<fn(...)>. When a slot stays None across your
crate graph, LLVM never emits or links the SIMD dispatch functions behind it.
Bundle composition:
| Constant | Byte layout | Strip SIMD | sRGB + 3×3 + srgb8 matrix | BT.709 / γ2.2 | F16 + PQ/HLG | Oklab | GainMap |
|---|---|---|---|---|---|---|---|
SCALAR | — | — | — | — | — | — | — |
LAYOUT | ✓ | — | — | — | — | — | — |
WEB_SDR | ✓ | ✓ | ✓ | — | — | — | — |
WEB_HDR | ✓ | ✓ | ✓ | pow only | ✓ | — | ✓ |
HDR | — | ✓ | 3×3 only | — | ✓ | — | — |
OKLAB | — | ✓ | — | — | — | ✓ | — |
GAINMAP | — | — | — | — | — | — | ✓ |
ROW_PIPELINE | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | — |
ALL | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
Hermetic override: passing .with_accelerators(...) completely bypasses the
global registry — so Accelerators::SCALAR always runs scalar even if another
library or test called Accelerators::ALL.install_global() or enabled fast.
fast Cargo feature (top-level binaries only)If you have a top-level binary and don’t want to touch main(), enable the
fast Cargo feature in your binary’s Cargo.toml:
[dependencies]
zenpixels-convert = { version = "0.5.0", features = ["fast"] }This makes Accelerators::default() resolve to Accelerators::ROW_PIPELINE
for any policy without an explicit .with_accelerators(...) override.
Library crates should never enable fast, because Cargo features unify
globally across the entire dependency graph and would force every downstream
Wasm or CLI user to compile and link all SIMD kernels.
By default (ConvertPolicy::allow_approximate == false), zenpixels-convert
guarantees exact 0-bit parity between scalar and SIMD (using the exact float
FMA sRGB8 matrix path when converting U8 sRGB primaries like Display P3 ↔
BT.709). When converting high-volume web thumbnails where a <= 1 LSB
fixed-point approximation is acceptable, opt in explicitly via
.with_allow_approximate(true).
For orientation on how strongly dead-stripping affects final binary size, the
table below records measurements from the 0.4 benchmarks/converter-size/
reference harness (bin - base, stripped, fat LTO, codegen-units = 1,
panic = "abort", host r7900x Ryzen 9 7900X Zen 4 — not measured on Zen 5,
run-heavy peak RSS 0.89–1.36 GiB; 0.5 keeps the same function-pointer
dead-stripping architecture with the unified 64-pixel L1 strip engine):
default-features = false, features = ["rgb"], 0.4 baseline)| Target | Default scalar | + layout | + web_sdr | + enable_all |
|---|---|---|---|---|
x86_64 -O3 | +159 KB | +278 KB | +408 KB | +494 KB |
x86_64 -Os | +121 KB | +188 KB | +287 KB | +447 KB |
wasm32 -Oz +simd128 | +87 KB | +141 KB | +207 KB | +244 KB |
+oklab, +hdr-transfers; +std on wasm32, 0.4 baseline)| Target | Default scalar | + layout | + web_sdr | + enable_all |
|---|---|---|---|---|
x86_64 -O3 | +386 KB | +505 KB | +637 KB | +855 KB |
x86_64 -Os | +343 KB | +409 KB | +508 KB | +1,019 KB |
wasm32 -Oz +simd128 | +159 KB | +215 KB | +285 KB | +372 KB |
Key design takeaways:
default-features = false omits Oklab,
HDR, and gain-map code at compile time; choosing SCALAR / LAYOUT /
WEB_SDR / ROW_PIPELINE omits unused SIMD kernels at link time.default-features = false (or WEB_SDR /
SCALAR in tests and Wasm builds) skips monomorphizing unused SIMD
transcendental tiers (AVX2, AVX-512, Wasm128) during release LTO.| Feature | Default | What it adds (and what happens when off) |
|---|---|---|
std | on | Standard library support (disable for no_std + alloc) |
fast-transpose | on | SIMD transpose kernels behind orient::apply_orientation* |
oklab | on | Oklab / OklabA and OKLch SoftCompress; off → returns ConvertError::FeatureRequired("oklab") |
hdr-transfers | on | PQ/HLG transfers and BT.2100-3 HLG display rendering; off → returns ConvertError::FeatureRequired("hdr-transfers") |
gainmap | on | ISO 21496-1 / UltraHDR dual-layer gain-map reconstruction, resampling, and extraction |
perceptual | off | Oklch, CieLab, CieLch, Jzazbz, Jzczhz, Hsl, Hsv; off → returns ConvertError::FeatureRequired("perceptual") |
bt2446a | off | Built-in BT.2446A HDR→SDR tone mapping; off → explicit HDR→SDR returns ConvertError::HdrFeatureRequired |
icc-db | off | Compressed LZ4 CICP→ICC recipe bundle; off → retains compact exports and refuses unsupported synthesis |
cms-moxcms / cms-lcms | off | Pluggable ICC/CMYK CMS backends (always bound explicitly via ColorServices / with_cms) |
rgb / imgref | off | Interop traits with rgb and imgref crates |
avx512 | off | Wider 16-lane x86-64 AVX-512 row-kernel tiers |
precise-portable | off | Single-rounding software FMA on non-fusing Wasm engines (default Wasm uses compact BackendDependent math) |
fast | off | Binaries only — defaults unregistered policies to Accelerators::ROW_PIPELINE |
Minimal SDR web / Wasm dependency in Cargo.toml:
# Smallest Wasm/embedded build with full SDR sRGB + gamut + layout support:
zenpixels-convert = { version = "0.5.0", default-features = false, features = ["std"] }SampleClaimsWhen you already know an f32 buffer has no NaN, ±inf, negatives, or
values above 1.0 — or that an RGBA8 buffer is 100% opaque — measure once
with view.measure_claims() and attach those claims via buf.assume_claims(claims)
or ConvertPolicy::with_source_claims(claims):
use zenpixels_convert::{
Accelerators, ConvertPolicy, DepthPolicy, FloatClaims, PixelBuf, PixelFormat, RowPlan, formats,
PixelScanExt,
};
let mut lin = PixelBuf::new(16, 1, PixelFormat::RGBF32_LINEAR)?;
let claims = lin.measure_claims();
assert!(claims.float.contains(FloatClaims::NO_NAN | FloatClaims::AT_MOST_ONE));
lin.assume_claims(claims);
let policy = ConvertPolicy::lossless()
.with_depth(DepthPolicy::Round)
.with_accelerators(Accelerators::WEB_SDR)
.with_source_claims(claims);
let plan = RowPlan::build(&formats::RGBF32_LINEAR, &formats::RGB8_SRGB, &policy, None)?;
let mut out = vec![0u8; 16 * 3];
plan.convert_row(lin.row(0), &mut out, 16)?;
assert_eq!(out, vec![0u8; 48]);garb or linear-srgb directlyIf you don’t need full format negotiation, ICC/CICP metadata, or multi-step planning, the two lower-level crates in the stack keep builds even smaller:
garb (garb::bytes): raw byte swizzle, alpha add/drop, and strided
rows with zero color math and zero std dependency.linear-srgb (linear_srgb::default): direct SIMD transfer curves
(sRGB, gamma, optional transfer feature for BT.709/PQ/HLG) with
out-of-place *_slice_into functions that avoid copy+modify overhead.Data Structures Atlas · Type drilldown · Pixel types guide · Kernel browser · Transfer functions · Primaries, HDR & CICP/ICC · Plain-English ELI5 · Explore one pixel · Quick starts