Plain-English Mental Model (ELI5)

New to the zenpixels 0.5 stack? This page explains how garb, linear-srgb, zenpixels, and zenpixels-convert fit together, what every type actually means, and the real-world gotchas to avoid on day one.

§1. Which crate should I reach for?

If you want to…UseWhy
Swap, expand, or strip raw u8 channels (RGBA↔BGRA, RGB→RGBA, strided rows) with zero color mathgarb (garb::bytes)Tiny, no_std, zero-panic Result<(), SizeError>, pure byte layout
Apply a transfer curve (sRGB, gamma, PQ, HLG, BT.709) to f32/u8/u16 sliceslinear-srgb (linear_srgb::default)Pure transfer math, SIMD slices (*_slice / *_slice_into), no buffer types
Carry images, row stride, and color meaning (PixelBuf, PixelView, PlanarBuf, PixelFormat, ColorOrigin)zenpixelsLightweight interchange types (no_std + alloc, #![forbid(unsafe_code)]) for codecs and image pipelines
Convert images, rows, planar YCbCr, gain maps, orientation, HDR, or ICC profileszenpixels-convertFull planner + executor (re-exports zenpixels::* flat at the crate root)

§2. The 5 nouns in zenpixels 0.5

Think of a shipping box:

  1. SampleLayout = the box shape (sample: SampleType, order: ChannelOrder, packing: BitPacking — e.g. SampleLayout::RGB8, RGBAF32, or 10-bit U10_LSB / P010). It describes bytes in memory only; it cannot authorize a color conversion by itself.
  2. ColorSpace = what the numbers mean right now (Rgb, Gray, Oklab, Xyz, Perceptual, Cmyk, Icc, or Untagged). Primaries (Primaries), transfer curve (Transfer), signal range (SignalRange), alpha mode (AlphaMode), and optional diffuse-white anchor (Option<DiffuseWhite>) live inside the variant that actually uses them — impossible states don’t exist.
  3. PixelFormat = the complete shipping label (layout: SampleLayout + color: ColorSpace).
  4. ColorOrigin = what the original file claimed on disk (for example a PNG or AVIF carrying both an ICC chunk and a CICP chunk). It is history for encoder provenance (OutputSignaling::PreserveOrigin / Auto) and never overrides the active ColorSpace.
  5. Carriers (PixelBuf, PixelView, BandedBuf, PlanarBuf, DualLayerHdrBuf):

§3. Policy → Plan → Execute

Converting pixels separates policy (what lossy changes are allowed) from plan compilation and zero-scratch execution:

  1. Choose a ConvertPolicy:
  2. Pick the entry point that matches your loop:

§4. Universal scalar core vs. opt-in SIMD (accelerators & const Accelerators)

In Rust, Cargo features unify globally across the dependency tree. If every codec crate turned on every SIMD conversion table (sRGB, BT.709, Gamma 2.2, PQ, HLG, Oklab, GainMap, gamut matrices), tiny decoders and Wasm apps would pay hundreds of kilobytes of dead code and slow builds.

Instead, zenpixels-convert 0.5 separates correctness from SIMD codegen:

use zenpixels_convert::{Accelerators, ConvertPolicy, accelerators};

// Full SIMD for apps/CLIs/servers (returns true on first install, false if already installed):
let _ = Accelerators::ALL.install_global();

// Compile-time scoped subset (dead-strips unused SIMD families):
const LAYOUT_AND_SRGB: Accelerators = Accelerators::SCALAR
    .with_byte_layout()
    .with_strip_simd()
    .with_srgb();
let scoped = ConvertPolicy::lossless().with_accelerators(LAYOUT_AND_SRGB);

// Hermetic scalar-only override for 0-bit parity tests (ignores global registry):
let scalar = ConvertPolicy::lossless().with_accelerators(Accelerators::SCALAR);
assert!(!accelerators::resolve(Some(Accelerators::SCALAR)).has_byte_layout());

See Balancing speed and light compilation for feature budgets and recipes by workload.

§5. SampleClaims & FloatClaims: proven bounds without guesswork

Untrusted f32 buffers can contain NaN, ±inf, subnormals, negatives, or values above 1.0, and RGBA8 buffers may secretly be 100% opaque or grayscale.

SampleClaims bundles content invariants on buffers, views, and policies:

use zenpixels_convert::{
    ConvertPolicy, DepthPolicy, FloatClaims, PixelBuf, PixelFormat, SampleClaims, PixelConvertExt,
    PixelScanExt, formats,
};

let mut buf = PixelBuf::new(4, 1, PixelFormat::RGBF32_LINEAR)?;
let claims = buf.measure_claims();
assert!(claims.float.contains(FloatClaims::UNIT_INTERVAL));

// Attach proven claims to the buffer or policy:
buf.assume_claims(claims);
let policy = ConvertPolicy::lossless()
    .with_depth(DepthPolicy::Round)
    .with_source_claims(claims);
let srgb = buf.convert_to(&formats::RGB8_SRGB, &policy)?;
assert_eq!(srgb.row(0), &[0; 12]);

// Any mutable borrow automatically clears cached claims so stale proofs never lie:
let _mut_view = buf.as_view_mut();
assert_eq!(buf.attached_claims(), SampleClaims::NONE);

§6. Real-world gotchas (Oklab, HDR, CMS, features, errors)

Data Structures Atlas · Type drilldown · Pixel types guide · Transfer functions · Primaries, HDR & CICP/ICC · Kernel browser · Speed & light builds · Explore one pixel · Quick starts