2025-07-17 07:56:00
github.com
TurboStitchGIF is a lightweight, header-only C library for decoding GIF images with a focus on efficiency and minimal resource usage. Designed for embedded systems and performance-critical applications, it provides a simple API for decoding both static and animated GIFs while maintaining a tiny footprint.
- Single-header implementation – Just include
gif.h
in your project - Zero dynamic allocations – Works with user-provided memory buffers
- Platform independent – Pure C99 with no OS dependencies
- Dual decoding modes:
- Safe mode: Minimal memory usage (default)
- Turbo mode: Optimized for speed (define
GIF_MODE_TURBO
)
- Low memory footprint – Ideal for embedded systems and microcontrollers
- Full animation support – Handles frames, delays, transparency, and looping
- Configurable limits – Set canvas size and color limits via preprocessor defines
#define GIF_IMPLEMENTATION
#include "gif.h"
// Define scratch buffer size (calculate using GIF_SCRATCH_BUFFER_REQUIRED_SIZE)
uint8_t scratch_buffer[SCRATCH_BUFFER_SIZE];
void process_gif(const uint8_t* gif_data, size_t gif_size) {
GIF_Context ctx;
if(gif_init(&ctx, gif_data, gif_size,
scratch_buffer, sizeof(scratch_buffer)) != GIF_SUCCESS) {
// Handle error
return;
}
int width, height;
gif_get_info(&ctx, &width, &height);
uint8_t* frame_buffer = malloc(width * height * 3);
int delay_ms;
while(gif_next_frame(&ctx, frame_buffer, &delay_ms) > 0) {
// Process frame
// delay_ms contains frame duration
}
gif_close(&ctx);
free(frame_buffer);
}
Customize the library by defining these before including gif.h
:
#define GIF_MAX_WIDTH 800 // Max canvas width
#define GIF_MAX_HEIGHT 600 // Max canvas height
#define GIF_MAX_COLORS 256 // Max colors in palette
#define GIF_MODE_TURBO // Enable faster decoding
#define GIF_MAX_CODE_SIZE 12 // LZW max code size (usually 12)
#include "gif.h"
Function | Description |
---|---|
gif_init() |
Initialize decoder context |
gif_get_info() |
Get GIF dimensions |
gif_next_frame() |
Decode next animation frame |
gif_rewind() |
Restart animation from beginning |
gif_close() |
Clean up decoder context |
gif_set_error_callback() |
Set custom error handler |
The library requires a scratch buffer whose size depends on the selected mode:
// Safe mode (default)
#define GIF_SCRATCH_BUFFER_REQUIRED_SIZE ...
// Turbo mode (faster)
#define GIF_SCRATCH_BUFFER_REQUIRED_SIZE ...
Calculate the exact size needed using these macros in your code.
- Ultra-lightweight – Perfect for resource-constrained environments
- No external dependencies – Just the C standard library
- Simple integration – Single header file simplifies project setup
- Efficient decoding – Optimized LZW implementation with Turbo mode
- Robust error handling – Detailed error codes and callback support
- Transparency support – Handles alpha channel properly
- Animation features – Full support for frame delays and looping
Ideal for:
- Embedded systems displays
- IoT device interfaces
- Game development
- Resource-constrained applications
- Educational projects
- Custom image viewers
If you enjoy using this library and find it useful, consider supporting my work with a coffee!
Your support helps me continue maintaining and improving this project!
This project is licensed under the MIT License – see the LICENSE file for details.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Help Power Techcratic’s Future – Scan To Support
If Techcratic’s content and insights have helped you, consider giving back by supporting the platform with crypto. Every contribution makes a difference, whether it’s for high-quality content, server maintenance, or future updates. Techcratic is constantly evolving, and your support helps drive that progress.
As a solo operator who wears all the hats, creating content, managing the tech, and running the site, your support allows me to stay focused on delivering valuable resources. Your support keeps everything running smoothly and enables me to continue creating the content you love. I’m deeply grateful for your support, it truly means the world to me! Thank you!
BITCOIN bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge Scan the QR code with your crypto wallet app |
DOGECOIN D64GwvvYQxFXYyan3oQCrmWfidf6T3JpBA Scan the QR code with your crypto wallet app |
ETHEREUM 0xe9BC980DF3d985730dA827996B43E4A62CCBAA7a Scan the QR code with your crypto wallet app |
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.