Preserving Straight-Alpha RGBA Fidelity During AVIF to PNG Conversion
Why Auxiliary AV1 Alpha Planes Corrupt Under Naive Canvas Pipelines
ISO BMFF AVIF stills store transparency inside a separate monochromatic AV1 auxiliary item linked via an auxl item reference rather than interleaving alpha samples into the primary color plane. When browser tools route AVIF bitstreams through a 2D HTMLCanvasElement, the compositor converts unassociated pixels into premultiplied RGBA8 in 8-bit integer precision and then divides back out on PNG serialization. That lossy roundtrip crushes faint drop-shadow gradients and introduces visible color shifts along anti-aliased UI icons.
Our Dedicated Worker bypasses browser 2D canvas quantization entirely by decoding the primary color item and auxiliary alpha item directly through libavif WebAssembly (@jsquash/avif/decode) into canonical straight-alpha RGBA8 memory. If an input container explicitly declares premultiplied association through an ISO iref prem box, the pipeline unpremultiplies color channels exactly once before PNG encoding.
- Canonicalizes RGB bytes to (0, 0, 0) wherever alpha equals zero to maximize PNG DEFLATE compression and eliminate hidden color bleed.
- Validates dimensions and working-set memory before allocation, enforcing a strict 36-megapixel and 25 MB local safety envelope.
- Locks Worker outbound network APIs (fetch, XMLHttpRequest, WebSocket) immediately after WASM instantiation.