Skip to main content

Module lqip

Module lqip 

Source
Expand description

LQIP — the chromahash placeholder carried in the signed sidecar’s lqip field. Always compiled, and deliberately so: the placeholder is produced by the import pipeline, read by the apps through the FFI crates, and read by the browser through capsule-wasm, so there is exactly one implementation and every surface links it. chromahash has zero runtime dependencies and targets wasm32-unknown-unknown. The one native-gated part is lqip::sidecar, because sidecar itself is. LQIP — the low-quality image placeholder carried in every asset’s signed sidecar.

SSoT: Thumbnails — LQIP.

§Why this module exists at the crate root

The placeholder is produced by the import pipeline, read by the native apps through the app FFI, and read by the browser through capsule-wasm. A placeholder that differed by which client imported the photo would be a visible defect, so there is exactly one implementation and it must be reachable from all three. That rules out capsule_core::media, the retired decode/encode stack that lives in legacy-review/ and is native-only wherever it is restored. It equally rules out Rawshift, which .claude/rules/capsule-core.md forbids from wrapping Chromahash — Capsule imports it directly.

This module is therefore unconditional: no feature gate, no native, and it compiles for wasm32-unknown-unknown (chromahash has zero runtime dependencies and ships a simd128 backend). The one part that cannot be unconditional is the bridge to the sidecar record, because crate::sidecar is itself native-gated; that lives in sidecar, behind the same gate, over this same encoder.

§The contract

Encoding is Chromahash at [chromahash::DEFAULT_TIER] — exactly 32 bytes. Capsule does not vary the tier per asset, and four chromahash calls carry the whole contract; this module deliberately uses no more than these:

CallRole here
encode(w, h, &rgba, gamut)Lqip::encode — generation at the default tier.
decode_capped(max_w, max_h)Lqip::decode_capped — the band-limited render.
average_color()Lqip::dominant_color — the DC-only fallback fill.
from_bytes / as_bytesLqip::from_bytes / Lqip::as_bytes — the sidecar round trip.

Notably absent: any pre-resize of the source. The 100 px downscale the retired ThumbHash implementation performed before hashing was a ThumbHash artifact — chromahash takes the full RGBA frame and band-limits on the read side via decode_capped, so pre-resizing here would silently cap fidelity that the format is able to carry.

§Versioned fallback

LQIP_FORMAT_V1 tags the payload inside the sidecar. A reader that does not recognize the version — or that holds bytes from_bytes rejects — paints the solid dominant_color fill instead of misrendering (see render). That is the mechanism that makes a future chromahash revision a versioned change rather than a silent break, and it is also what makes any stale non-chromahash payload degrade to a flat colour rather than to noise.

Modules§

sidecar
The bridge between an Lqip payload and the signed sidecar’s lqip record.

Structs§

Lqip
A chromahash LQIP payload — 32 bytes at [chromahash::DEFAULT_TIER].
RgbaImage
A decoded placeholder: packed RGBA8, width * height * 4 bytes.

Enums§

Gamut
The source colour space an Lqip::encode call is told to interpret its pixels in.
LqipError
Why an LQIP could not be produced or parsed.

Constants§

LQIP_FORMAT_V1
The LQIP chromahash format version written into the sidecar.

Functions§

render
Render a stored placeholder record, honouring the versioned fallback.