Show HN: Header-only GIF decoder in pure C – no malloc, easy to use
I built a lightweight GIF decoder in pure C, ideal for embedded or performance-critical environments. It’s header-only, zero dynamic memory allocations, and fully platform-independent. Supports both static and animated GIFs, with turbo and safe decoding modes. Works great on microcontrollers, IoT devices, and anything with a framebuffer. Would love feedback or ideas where this could be useful.
Github: https://github.com/Ferki-git-creator/TurboStitchGIF-HeaderOn...
11 comments
[ 2.8 ms ] story [ 41.9 ms ] threadDon't you get linker errors when a project includes this header twice in different translation units? If not, please explain how.
The trickiest part wasn’t the encoder; it’s computing the palette from RGB images. To minimize the output file size, I wanted a single palette shared by all frames.
The key piece of research was in that sample code from early 90-s https://www.ece.mcmaster.ca/~xwu/cq.c However, I had to rework it heavily because global variables and C language are too old school, also because FP32 precision is insufficient for the count of input pixels in my use case. 200 FullHD frames contain approximately 400M pixels, FP32 numbers don’t have the precision to accumulate that many of them. And the number is dangerously close to int32 limit, I have also upgraded the integer counters to int64.
I checked the code, it gives me "LLM vibes", too. FWIW, I am not against it. Perhaps the developer was using it here and there. Personally I do not care.