Skip to main content

Module compact

Module compact 

Source
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/BGRX padding).
  • Collapsing R == G == B to Gray/GrayAlpha (respecting ICC class authority: an RGB-class ICC requires a qualified GRAY-class replacement).
  • Narrowing bit-replicated full-range U16 (v * 257) to U8 (narrow-range U16 is kept at 16-bit because its anchors scale by 256, not 257).

Structs§

CompactionReport
Which channels and precision of a buffer’s declared PixelFormat are required to represent its current pixel values without loss.

Enums§

AlphaCompaction
How compact_in_place handles redundant alpha or padding lanes.
CompactOutcome
Outcome of compact_in_place.

Functions§

compact_in_place
Analyze and compact buf in 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 buf in place with optional cooperative cancellation and progress via pulse (pass None when not needed).
compact_to_buf
Analyze view and compact into a newly allocated PixelBuf if a narrower bit-exact representation exists (Ok(None) if already minimal), preserving allocation errors.
compact_to_buf_with_pulse
Analyze view and compact into a newly allocated PixelBuf with optional cooperative cancellation and progress via pulse (pass None when not needed).