logo
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

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.

Settings for creating a new encoder instance. See gifski_new

Functions

Same as gifski_add_frame_rgba, except it expects components in ARGB order.

Adds a frame to the animation. This function is asynchronous.

Same as gifski_add_frame_rgba, except it expects RGB components (3 bytes per pixel).

Pixels is an array width×height×4 bytes large. The array is copied, so you can free/reuse it immediately.

Same as gifski_add_frame_rgba, but with bytes per row arg.

The last step:

Call to start the process

Start writing to the destination. This has to be called before any frames are added.

Get a callback for frame processed, and abort processing if desired.

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.