Reading GIF files

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Reading GIF files

Post by deshipu » Tue Oct 01, 2019 8:30 pm

We usually use BMP (or worse) images for our microcontroller projects, because with no compression they are relatively easy to read and stream directly from the flash memory. However, they come with their downsides, large size being just one of them.

So I looked around at how GIF files are parsed by various example C and Python programs, and wrote this simple example: https://github.com/deshipu/circuitpytho ... er/code.py

The example is using CircuitPython's displayio library to display the image on the screen, however, if you replace it with your own code, it should work perfectly fine on MicroPython as well. I tried to stream the data as much as possible, to save memory, however, you might still need as much as 4kB of RAM for the table of Huffman codes needed for decompressing the image. Fortunately for small images this table doesn't grow nearly as big.

There is no license, as I don't think there is anything creative in that code that could fall under the copyright law — it simply implements the GIF's decompression algorithm in a straightforward way.

Post Reply