hn.today

Nibnib: Image compression with extreme decompression speed

github.com3 points0 comments
Screenshot of Nibnib: Image compression with extreme decompression speed

Nibnib is an experimental image format designed to make decompression exceptionally fast on small microcontrollers, where each pixel has a tight processing budget. It stores images at four bits per pixel and decodes two pixels from each input byte. Rather than having palette entries represent complete colors, each entry represents a color change from the preceding pixel pair. The decoder duplicates the previous pixel, adds the selected 32-bit palette delta, and obtains two RGB565 pixels. This simple, deterministic process is intended to fit devices such as the RP2350, where a pixel fetch, palette lookup, and line-buffer write must take only a few cycles.

Encoding is much more involved and currently far slower than decoding. The encoder searches a fixed 256-entry palette, combining small delta values with randomly generated values; including the small deltas helps avoid severe artifacts near color extremes. For each pixel pair, it chooses the entry with the lowest combined error and diffuses remaining error to neighboring pixels using a Floyd-Steinberg method. The pairwise search gives greater weight to overall color similarity than to differences between the two pixels. The file stores dimensions, the palette, starting pixels for each row, and palette indices. Current limitations include edge artifacts, an encoder that does not adapt its palette to the image, and a greedy search. Better palette design and deeper searches could improve quality without changing the decoder, though they would add encoding cost.

Read on github.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.