1- /* UPSTREAM: https://github.com/ImageOptim/gifski/blob/master/gifski.h */
2-
31#include <stdint.h>
42#include <stdlib.h>
53#include <stdbool.h>
64
5+
6+ #ifdef __cplusplus
7+ extern "C" {
8+ #endif
9+
710struct gifski ;
811typedef struct gifski gifski ;
912
@@ -12,22 +15,25 @@ typedef struct gifski gifski;
1215 Please note that it is impossible to use this API in a single-threaded program.
1316 You must have at least two threads -- one for adding the frames, and another for writing.
1417
15- ```c
16- gifski *g = gifski_new(&settings);
18+ ```c
19+ gifski *g = gifski_new(&settings);
20+
21+ // Call asynchronously on a decoder thread:
22+ {
23+ gifski_add_frame_rgba(g, i, width, height, buffer, 5);
24+ gifski_end_adding_frames(g);
25+ }
1726
18- // Call on decoder thread:
19- gifski_add_frame_rgba(g, i, width, height, buffer, 5);
20- gifski_end_adding_frames(g);
27+ // Call on encoder thread:
28+ gifski_write(g, "file.gif"); // blocking
29+ gifski_drop(g); // must be on the same thread as gifski_write() call
30+ ```
2131
22- // Call on encoder thread:
23- gifski_write(g, "file.gif");
24- gifski_drop(g);
25- ```
32+ It's safe to call `gifski_drop()` after `gifski_write()`, because `gifski_write()` blocks until `gifski_end_adding_frames()` is called.
2633
27- It's safe to call `gifski_drop()` after `gifski_write()`, because `gifski_write()` blocks until `gifski_end_adding_frames()` is called.
34+ It's safe and efficient to call `gifski_add_frame_*` in a loop as fast as you can get frames,
35+ because it blocks and waits until previous frames are written.
2836
29- It's safe and efficient to call `gifski_add_frame_*` in a loop as fast as you can get frames,
30- because it blocks and waits until previous frames are written.
3137*/
3238
3339/**
@@ -120,9 +126,13 @@ GifskiError gifski_add_frame_png_file(gifski *handle,
120126 uint16_t delay );
121127
122128/**
123- * Pixels is an array width×height×4 bytes large. The array is copied, so you can free/reuse it immediately.
129+ * `pixels` is an array width×height×4 bytes large.
130+ * The array is copied, so you can free/reuse it immediately after this function returns.
124131 *
125- * Delay is in 1/100ths of a second.
132+ * `index` is the frame number, counting from 0.
133+ * You can add frames in any order (if you need to), and they will be sorted by their index.
134+ *
135+ * Delay is in 1/100ths of a second. 5 is 20fps.
126136 *
127137 * While you add frames, `gifski_write()` should be running already on another thread.
128138 * If `gifski_write()` is not running already, it may make `gifski_add_frame_*` block and wait for
@@ -141,7 +151,8 @@ GifskiError gifski_add_frame_rgba(gifski *handle,
141151
142152/** Same as `gifski_add_frame_rgba`, except it expects components in ARGB order.
143153
144- Bytes per row must be multiple of 4 and greater or equal width×4.
154+ Bytes per row must be multiple of 4, and greater or equal width×4.
155+ If the bytes per row value is invalid (e.g. an odd number), frames may look sheared/skewed.
145156*/
146157GifskiError gifski_add_frame_argb (gifski * handle ,
147158 uint32_t index ,
@@ -153,7 +164,8 @@ GifskiError gifski_add_frame_argb(gifski *handle,
153164
154165/** Same as `gifski_add_frame_rgba`, except it expects RGB components (3 bytes per pixel)
155166
156- Bytes per row must be multiple of 3 and greater or equal width×3.
167+ Bytes per row must be multiple of 3, and greater or equal width×3.
168+ If the bytes per row value is invalid (not multiple of 3), frames may look sheared/skewed.
157169*/
158170GifskiError gifski_add_frame_rgb (gifski * handle ,
159171 uint32_t index ,
@@ -184,6 +196,7 @@ void gifski_set_progress_callback(gifski *handle, int (cb)(void *), void *user_d
184196
185197/**
186198 * Start writing to the `destination` and keep waiting for more frames until `gifski_end_adding_frames()` is called.
199+ * The file path must be ASCII or valid UTF-8.
187200 *
188201 * This call will block until the entire file is written. You will need to add frames on another thread.
189202 *
@@ -195,3 +208,7 @@ GifskiError gifski_write(gifski *handle, const char *destination);
195208 * Call to free all memory
196209 */
197210void gifski_drop (gifski * g );
211+
212+ #ifdef __cplusplus
213+ }
214+ #endif
0 commit comments