Expand description
Spec-aware content analysis and bit-exact lossless format compaction.
Answers: “Which parts of this buffer’s declared PixelFormat are actually
required by its pixel values?” — non-opaque alpha, chroma (R != G or G != B),
and 16-bit precision beyond byte-replicated 8-bit ((v >> 8) != (v & 0xFF) on
full-range U16) — and optionally compacts the pixel buffer either into a fresh
PixelBuf (compact_to_buf) or in place with zero allocation
(compact_in_place).
Every reduction this module performs is bit-exact invertible:
- Dropping an all-max alpha lane (or undefined
RGBX/BGRXpadding). - Collapsing
R == G == BtoGray/GrayAlpha(respecting ICC class authority: an RGB-class ICC requires a qualified GRAY-class replacement). - Narrowing bit-replicated full-range
U16(v * 257) toU8(narrow-rangeU16is kept at 16-bit because its anchors scale by 256, not 257).
Structs§
- Compaction
Report - Which channels and precision of a buffer’s declared
PixelFormatare required to represent its current pixel values without loss.
Enums§
- Alpha
Compaction - How
compact_in_placehandles redundant alpha or padding lanes. - Compact
Outcome - Outcome of
compact_in_place.
Functions§
- compact_
in_ place - Analyze and compact
bufin place without reallocating owned mutable storage (copy-on-write promotes immutable external storage, propagating allocation errors instead of swallowing them). - compact_
in_ place_ with_ pulse - Analyze and compact
bufin place with optional cooperative cancellation and progress viapulse(passNonewhen not needed). - compact_
to_ buf - Analyze
viewand compact into a newly allocatedPixelBufif a narrower bit-exact representation exists (Ok(None)if already minimal), preserving allocation errors. - compact_
to_ buf_ with_ pulse - Analyze
viewand compact into a newly allocatedPixelBufwith optional cooperative cancellation and progress viapulse(passNonewhen not needed).