All Projects → lecram → Gifenc

lecram / Gifenc

small C GIF encoder

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to Gifenc

Bbwebimage
A high performance Swift library for downloading, caching and editing web images asynchronously.
Stars: ✭ 128 (-21.95%)
Mutual labels:  gif, encoder
AnimatedGif
📼 A high performance .NET library for reading and creating animated GIFs
Stars: ✭ 106 (-35.37%)
Mutual labels:  encoder, gif
gogif
The (no longer) missing GIF encoder for #golang
Stars: ✭ 21 (-87.2%)
Mutual labels:  encoder, gif
React Native Blurhash
🖼️ A library to show colorful blurry placeholders while your content loads.
Stars: ✭ 430 (+162.2%)
Mutual labels:  library, encoder
Gifloader
An Android Library to load your GIF files
Stars: ✭ 38 (-76.83%)
Mutual labels:  library, gif
Jvedio
Windows desktop application to manage local video;Support baidu AI, youdao translation;Support FFMPEG video processing;Support multi-database management and statistics;Support skin switching
Stars: ✭ 545 (+232.32%)
Mutual labels:  library, gif
Ffmpegcommand
FFmpegCommand适用于Android的FFmpeg命令库,实现了对音视频相关的处理,能够快速的处理音视频,大概功能包括:音视频剪切,音视频转码,音视频解码原始数据,音视频编码,视频转图片或gif,视频添加水印,多画面拼接,音频混音,视频亮度和对比度,音频淡入和淡出效果等
Stars: ✭ 394 (+140.24%)
Mutual labels:  gif, encoder
Gifdec
small C GIF decoder
Stars: ✭ 100 (-39.02%)
Mutual labels:  library, gif
Ffmediatoolkit
FFMediaToolkit is a cross-platform video decoder/encoder library for .NET that uses FFmpeg native libraries. It supports video frames extraction, reading stream metadata and creating videos from bitmaps in any format supported by FFmpeg.
Stars: ✭ 156 (-4.88%)
Mutual labels:  library, encoder
Nlp bahasa resources
A Curated List of Dataset and Usable Library Resources for NLP in Bahasa Indonesia
Stars: ✭ 158 (-3.66%)
Mutual labels:  library
React Timelines
React Timelines Library
Stars: ✭ 161 (-1.83%)
Mutual labels:  library
Dublin Traceroute
Dublin Traceroute is a NAT-aware multipath tracerouting tool
Stars: ✭ 159 (-3.05%)
Mutual labels:  library
Awesomeimagepicker
Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image selection.
Stars: ✭ 160 (-2.44%)
Mutual labels:  gif
Mahout
Mirror of Apache Mahout
Stars: ✭ 1,960 (+1095.12%)
Mutual labels:  library
Sc
Common libraries and data structures for C.
Stars: ✭ 161 (-1.83%)
Mutual labels:  library
Pysnow
Python library for the ServiceNow REST API
Stars: ✭ 162 (-1.22%)
Mutual labels:  library
Pipeline Library
Collection of custom steps and variables for our Jenkins instance(s)
Stars: ✭ 159 (-3.05%)
Mutual labels:  library
Java Markdown Generator
Java library to generate markdown
Stars: ✭ 159 (-3.05%)
Mutual labels:  library
Aim Ik
A Unity-3D library, to procedural orientate character head (and chest) in a direction without using any animation data.
Stars: ✭ 164 (+0%)
Mutual labels:  library
Blurimage
This Android Project help you to make your image blur in fastest way
Stars: ✭ 162 (-1.22%)
Mutual labels:  library

GIF encoder

This is a small C library that can be used to create GIF animations.

Features

  • user-defined palette of any depth from 1 up to 8
  • each frame has its own (user-specified) delay time
  • flexible looping options: no loop, N repetitions, infinite loop
  • GIF size optimization: only stores frame differences
  • memory efficient: saves frames to file as soon as possible
  • small and portable: less than 300 lines of C99
  • public domain

Limitations

  • no frame-local palettes (incompatible with size optimization)
  • no interlacing (bad for compression, useless for animations)

Documentation

There are only three functions declared in "gifenc.h": ge_new_gif(), ge_add_frame() and ge_close_gif().

The ge_new_gif() function receives GIF global options and returns a ge_GIF handler:

ge_GIF *ge_new_gif(
    const char *fname,                  /* GIF file name */
    uint16_t width, uint16_t height,    /* frame size */
    uint8_t *palette, int depth,        /* color table */
    int loop                            /* looping information */
);

The palette parameter must point to an array of color data. Each entry is a 24-bits RGB color, stored as three contiguous bytes: the first is the red value (0-255), then green, then blue. Entries are stored in a contiguous byte array.

The depth parameter specifies how many colors are present in the given palette. The number of color entries must be 2 ^ depth, where 1 <= depth <= 8.

Example palette and depth values:

uint8_t palette[] = {
    0x00, 0x00, 0x00,   /* entry 0: black */
    0xFF, 0xFF, 0xFF,   /* entry 1: white */
    0xFF, 0x00, 0x00,   /* entry 2: red */
    0x00, 0x00, 0xFF,   /* entry 3: blue */
};
int depth = 2;          /* palette has 1 << 2 (i.e. 4) entries */

If palette is NULL, entries are taken from a default table of 256 colors. If depth < 8, the default table will be truncated to the appropriate size. The default table is composed of the 16 standard VGA colors, plus the 216 web-safe colors (all combinations of RGB with only 6 valid values per channel), plus 24 grey colors equally spaced between black and white, excluding both.

If the loop parameter is zero, the resulting GIF will loop forever. If it is a positive number, the animation will be played that number of times. If loop is negative, no looping information is stored in the GIF file (for most GIF viewers, this is equivalent to loop == 1, i.e., "play once").

The ge_add_frame() function reads pixel data from a buffer and saves the resulting frame to the file associated with the given ge_GIF handler:

void ge_add_frame(ge_GIF *gif, uint16_t delay);

The delay parameter specifies how long the frame will be shown, in hundreths of a second. For example, delay == 100 means "show this frame for one second" and delay == 25 means "show this frame for a quarter of a second". Note that short delays may not be supported by some GIF viewers: it's recommended to keep a minimum of delay == 6. If delay == 0, no delay information will be stored for the frame. This can be used when creating still (single-frame) GIF images.

Pixel data is read from gif->frame, which points to a memory block like this:

uint8_t _frame_[gif->width * gif->height];

Note that the address of gif->frame changes between calls to ge_add_frame() (*). For this reason, each frame must be written in its entirety to the current address, even if one only wants to change a few pixels from the last frame. The encoder will automatically detect the difference between two consecutive frames in order to minimize the size of the output.

Each byte in the frame buffer represents a pixel. The value of each pixel is an index to a palette entry. For instance, given the example palette above, we can create a frame displaying a red-on-black "F" letter like this:

uint8_t pixels[] = {
    2, 2, 2, 2,
    2, 0, 0, 0,
    2, 0, 0, 0,
    2, 2, 2, 0,
    2, 0, 0, 0,
    2, 0, 0, 0,
    2, 0, 0, 0
};
ge_GIF *gif = ge_new_gif("F.gif", 4, 7, palette, depth, -1);
memcpy(gif->frame, pixels, sizeof(pixels));
ge_add_frame(gif, 0);
ge_close_gif(gif);

The function ge_close_gif() finishes writting GIF data to the file associated with the given ge_GIF handler and does memory clean-up. This function must be called once after all desired frames have been added, in order to correctly save the GIF file. After calling this function, the ge_GIF handler cannot be used anymore.

void ge_close_gif(ge_GIF* gif);

(*) The encoder keeps two frame buffers internally, in order to implement the size optimization. The address of gif->frame alternates between those two buffers after each call to ge_add_frame().

Example

See the file "example.c". It can be tested like this:

$ cc -o example gifenc.c example.c $ ./example

That should create an animated GIF named "example.gif".

Copying

All of the source code and documentation for gifenc is released into the public domain and provided without warranty of any kind.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].