Brifing

Nibnib: Image Compression Optimized for Extreme Decompression Speed

A high-performance image format designed for resource-constrained microcontrollers like the RP2350.

1Origin and Design Goals

Nibnib originated as an experimental image format specifically for DVI output on the RP2350 microcontroller. The primary design constraint was a strict budget of approximately 6 cycles per pixel. This limit allows for essential operations like pixel fetching and palette lookup while maintaining high performance on hardware with limited processing power.

2Delta-Based Palette Mechanism

The format utilizes a palette-based approach but improves upon standard methods by storing color deltas instead of absolute values. This technique significantly enhances the rendering of soft regions. By decoding two pixels simultaneously from a single byte of input, the format achieves 4bpp compression while maintaining a deterministic and highly efficient decompression process.

3Asymmetric Encoding and Decoding

Nibnib features an asymmetric design where the encoder is significantly slower than the decoder. While the decoder performs a simple, deterministic loop, the encoder conducts an extensive search through possible palette entries and codewords. This trade-off prioritizes extreme decompression speed, making it ideal for real-time applications on low-power hardware platforms.

4Decoding Logic Explained

Decoding functions by processing pixel pairs. The system takes the last decoded pixel, doubles it, and adds a 32-bit value retrieved from the palette. This operation yields two 16bpp RGB 565 pixels. The process is computationally inexpensive, requiring only basic arithmetic operations that fit within the tight cycle budget of the RP2350.

5Error Diffusion Techniques

The encoding process employs a strategy similar to error diffusion, distributing quantization errors across subsequent pixels using Floyd-Steinberg weights. Unlike standard single-pixel diffusion, Nibnib minimizes error for two pixels at once. This approach prioritizes lower spatial frequencies, reflecting the human visual system's higher sensitivity to those patterns over sharp edge details.

6Encoding Search Optimization

The current encoder uses a combination of a small delta cube and random Gaussian values to populate the palette. This structure prevents overflow artifacts near zero and full-scale values. Future iterations could improve quality by implementing adaptive palette selection based on specific input images, though this would increase the already high encoding complexity.

7Potential Future Improvements

Current artifacts trailing sharp edges result from the greedy search algorithm. Developers could mitigate this by implementing right-to-left or boustrophedonic encoding paths. Since the addition step is practically invertible, these changes would enhance visual quality without requiring any modifications to the existing, highly optimized decoder implementation used in the target hardware.

8Format Structure and Utility

The file format is intentionally minimalist, consisting of width and height headers, 256 palette entries, and raw row data. It lacks extensive metadata, as it is designed for tight integration with specific decoders rather than general archival. This simplicity ensures that the format remains lightweight for specialized embedded display applications.

Original article: Hacker News (news.ycombinator.com) — Nibnib: Image Compression Optimized for Extreme Decompression Speed