8 ms·
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-HeaderOnly-Fast-ZeroAllocation-PlatformIndependent-Embedded-C-GIF-Decoder https://github.com/Ferki-git-creator/TurboStitchGIF-HeaderOn...
- lnkl 1y agoHow is this a header-only? It contains non-static, non-inline functions in the .h file...
- FerkiHN 1y agoPlease share your thoughts.
- zoo56 1y agoIt looks good, but I wanted to see a demo to see how it would all look in practice.
- FerkiHN 1y agoOkay, I'll do it soon.
- 90s_dev 1y agoHow much was AI used to help create this?
- 0xEF 1y agoRight for the throat. Brutal.
- 90s_dev 1y agoThe readme just looks like it was written by AI, and the initial commit is the entire code. It just seems like AI was used at least somewhat. Just curious how much, if at all. I submitted a link to a project[0] with similar characteristics a few days ago, before I realized it was probably entirely made by AI. That's what got me wondering this in the first place. [0] https://news.ycombinator.com/item?id=44642557 https://news.ycombinator.com/item?id=44642557
- actionfromafar 1y agoI'm laughing so much right now, we live in truly hilarious (but also terrifying) times!
- horseradish7k 1y agocheck op's post history you'll understand
- FerkiHN 1y agoYes, I used ChatGPT to help refine the README and occasionally get suggestions for cleaner or more efficient code patterns. But the core logic, turbo decoding modes, and embedded optimization — that’s all written, tested, and understood by me. I see AI as a tool, not an author — it helps speed things up, but I still do the thinking.
- bmn__ 1y ago[flagged]
- kccqzy 1y agoIt's header-only in the sense that you cut everything that normally goes in the .c file and pasted it in the .h file. Don't you get linker errors when a project includes this header twice in different translation units? If not, please explain how.
- lmz 1y ago"ifdef GIF_IMPLEMENTATION"
- furyofantares 1y agoLooks like you are required to #define GIF_IMPLEMENTATION before #include "gif.h" in exactly one of your translation units.
- magicalhippo 1y agoAt that point, what does header-only gain you in C (ie not C++)? I've included many single .h/.c pair libraries before in my projects and given the of simplicity that was never a pain point.
- snickerbockers 1y agopeople who have to support windows do this sometimes because MS has gone for almost forty years now without ever specifying a default directory where libraries go. This is in spite of the fact that being the creator of the OS, the most-popular compiler, and the SDK should in theory give them enormous leverage to dictate where dependencies get saved. There's this bizarre cultural difference you see between people who learned to program on windows compared to people who learned to program on unix wherein the Windows crowd don't see the value of having an easily reproducible build system because. Usually this results in some combination of needlessly-complicated scripts and checking binary builds of dependencies into version-control. Requiring you to include a header-file while also defining a specific constant in only one place that turns the header file into a c-file is actually one of the more benign workarounds you see.
- rixed 1y agoWhy would you want another gif decoder, in C, in 2025? What's the point of cramming everything in a single file?
- taminka 1y agoeasier to build, easier to navigate, easier to integrate ppl who ask qustions like this must have not worked much on codebases w/ nightmarish build setups, libraries like this are so refreshing/easier to work w/
- rixed 1y agoI've worked with many projects and many dependencies and never felt a need for that. In the worse case, if a dependency was too badly packaged, or its built system too awful, I had to redo it. As I'm always working with pretty standard and portable Unix built tools and debian packages, is never been such a pain. Actually, one of the things I miss from C when I'm using any other environment is how it is simple to build, to package and to debug.
- deleted 1y ago[deleted]
- cornstalks 1y agoThere are multiple comments remarking on the header-only implementation, confused regarding linker errors and why this is desirable. Look into stb lib, which in my opinion popularized this idea: https://github.com/nothings/stb?tab=readme-ov-file#how-do-i-use-these-libraries https://github.com/nothings/stb?tab=readme-ov-file#how-do-i-...
- legobmw99 1y agoIn particular, you can define the implementation flag and include the header in a .c file with no other contents to recover the more “traditional” build set up where you have a separate TU dedicated to the library. I quite like the flexibility it provides in terms of making “unity builds” very easy, and scaling down quite well to small, single-TU projects with minimal build set ups.
- FerkiHN 1y agoExactly! That flexibility was one of my goals. Making integration smooth for both small embedded projects and larger codebases with unity builds — glad to hear it resonates.
- legobmw99 1y agoI first encountered the idea relatively recently with Clay [1] and I have been a fan since. Once you get past the “huh, weird” stage it has a lot of benefits! 1: https://github.com/nicbarker/clay https://github.com/nicbarker/clay
- FerkiHN 1y agoThanks! Yes, stb-style header-only libs were definitely an inspiration. I know some devs find the approach confusing, especially with linker errors if *_IMPLEMENTATION isn't handled correctly. I tried to keep it simple and clearly documented, but feedback like this helps improve it.
- Const-me 1y agoI once did it for a closed-source CAM/CAE software. We wanted to generate high resolution and decent quality GIFs visualizing a progress of a numerical optimization in a few hundred animation frames. I wasn’t able to find a library which would deliver both reasonable size and good quality, so I made my own. 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 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.
- triknomeister 1y agoThis is very interesting that you did the visualization using a GIF. I have only generated mp4 videos for vidoes till now using ffmpeg and png images or through something equivalent. Was there any advantage of GIF that you found? Like may be it was easier to do on the fly or was just simple enough?
- Const-me 1y agoI believe the reason why management specifically asked for animated GIFs was compatibility. The GIF format is ancient and supported by everything, makes it trivial to share or embed these animation files. Ignoring the compatibility, modern video codecs like h264 or h265 are substantially better than animated GIFs, in terms of both size and quality. BTW I supported them as well. The only target platform of that software is modern versions of Windows. It only took couple pages of straightforward C++ because the OS includes a functional equivalent of libavcodec and libavformat libraries. Moreover, GPU drivers install and register the components to leverage the codecs implemented by hardware of these GPUs. The high-level API to encode compressed video files from a sequence of frames is MFCreateSinkWriterFromURL function.
- johnisgood 1y agoI wonder if the README.md of this project has been generated by an LLM, or if LLMs output such READMEs mainly because of their training data and thus mistakenly gets identified as LLM-generated README. The two are not mutually exclusive I suppose. 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.
- triknomeister 1y agoIt is a formally written README which is very usual in formal circle of communication, think proposal writing or papers etc. Outside, it is usual for people to do this when their primary exposure to English is through such channels or when they are not comfortable with having their personal style of talking be viewed by the public. LLM is also similar in that sense, so it produces the same writing. It resists personal touch without being explicitly asked.
- johnisgood 1y agoWhenever I tell an LLM to generate README.md for a project, it comes up with READMEs like this one, full of emojis (easy to generate README.md without them though).
- mort96 1y agoThe use of the AI emoji ("Sparkles"), plus the "Example Projects" section containing no example projects, certainly doesn't help it beat the AI allegations.
- alexvitkov 1y agoStatistically so far 100% of header only C libraries that require you to define XXX_IMPLEMENTATION are fantastic, so this is probably a good library.
- ck45 1y agoNo allocations, reminds me of WUFFS, which also comes with a GIF decoder: https://github.com/google/wuffs/blob/main/std/gif/decode_gif.wuffs https://github.com/google/wuffs/blob/main/std/gif/decode_gif...