Module c_api

Source
Expand description

How to use from C

gifski *g = gifski_new(&(GifskiSettings){
    .quality = 90,
});
gifski_set_file_output(g, "file.gif");

for(int i=0; i < frames; i++) {
     int res = gifski_add_frame_rgba(g, i, width, height, buffer, 5);
     if (res != GIFSKI_OK) break;
}
int res = gifski_finish(g);
if (res != GIFSKI_OK) return;

It’s safe and efficient to call gifski_add_frame_* in a loop as fast as you can get frames, because it blocks and waits until previous frames are written.

To cancel processing, make progress callback return 0 and call gifski_finish(). The write callback may still be called between the cancellation and gifski_finish() returning.

To build as a library:

cargo build --release --lib

it will create target/release/libgifski.a (static library) and target/release/libgifski.so/dylib or gifski.dll (dynamic library)

Static is recommended.

To build for iOS:

rustup target add aarch64-apple-ios
cargo build --release --lib --target aarch64-apple-ios

it will build target/aarch64-apple-ios/release/libgifski.a (ignore the warning about cdylib).

Structs§

ARGB8
GifskiHandle
Opaque handle used in methods. Note that the handle pointer is actually Arc<GifskiHandleInternal>, but Arc::into_raw is nice enough to point past the counter.
GifskiHandleInternal
GifskiSettings
Settings for creating a new encoder instance. See gifski_new

Functions§

gifski_add_fixed_color
Adds a fixed color that will be kept in the palette at all times.
gifski_add_frame_argb
Same as gifski_add_frame_rgba, except it expects components in ARGB order.
gifski_add_frame_png_file
Adds a frame to the animation. This function is asynchronous.
gifski_add_frame_rgb
Same as gifski_add_frame_rgba, except it expects RGB components (3 bytes per pixel).
gifski_add_frame_rgba
Pixels is an array width×height×4 bytes large. The array is copied, so you can free/reuse it immediately.
gifski_add_frame_rgba_stride
Same as gifski_add_frame_rgba, but with bytes per row arg.
gifski_finish
The last step:
gifski_new
Call to start the process
gifski_set_error_message_callback
Get a callback when an error occurs. This is intended mostly for logging and debugging, not for user interface.
gifski_set_extra_effort
If true, encoding will be significantly slower, but may look a bit better.
gifski_set_file_output
Start writing to the destination. This has to be called before any frames are added.
gifski_set_lossy_quality
Quality 1-100 of gifsicle compression. Lower values add noise. Defaults to settings.quality.
gifski_set_motion_quality
Quality 1-100 of temporal denoising. Lower values reduce motion. Defaults to settings.quality.
gifski_set_progress_callback
Get a callback for frame processed, and abort processing if desired.
gifski_set_write_callback
Start writing via callback (any buffer, file, whatever you want). This has to be called before any frames are added. This call will not block.