Skip to main content

compact_in_place

Function compact_in_place 

Source
pub fn compact_in_place(
    buf: &mut PixelBuf,
    alpha_strategy: AlphaCompaction,
) -> Result<CompactOutcome, At<ConvertError>>
Expand description

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).

Depth (U16 → U8) and chroma (RGB → Gray) compaction run whenever justified; alpha_strategy controls whether redundant alpha/padding lanes are retagged in metadata (AlphaCompaction::RetagOpaque) or physically dropped in place (AlphaCompaction::DropUnusedLanes).

Returns Ok(CompactOutcome::Compacted) if any metadata or layout compaction occurred, Ok(CompactOutcome::Unchanged) if buf was already minimal, or Err(ConvertError::Buffer(_)) on CoW allocation failure.