1
- /* UPSTREAM: https://github.com/ImageOptim/gifski/blob/master/gifski.h */
2
-
3
1
#include <stdint.h>
4
2
#include <stdlib.h>
5
3
#include <stdbool.h>
6
4
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
7
10
struct gifski ;
8
11
typedef struct gifski gifski ;
9
12
@@ -12,22 +15,25 @@ typedef struct gifski gifski;
12
15
Please note that it is impossible to use this API in a single-threaded program.
13
16
You must have at least two threads -- one for adding the frames, and another for writing.
14
17
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
+ }
17
26
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
+ ```
21
31
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.
26
33
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.
28
36
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.
31
37
*/
32
38
33
39
/**
@@ -120,9 +126,13 @@ GifskiError gifski_add_frame_png_file(gifski *handle,
120
126
uint16_t delay );
121
127
122
128
/**
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.
124
131
*
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.
126
136
*
127
137
* While you add frames, `gifski_write()` should be running already on another thread.
128
138
* 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,
141
151
142
152
/** Same as `gifski_add_frame_rgba`, except it expects components in ARGB order.
143
153
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.
145
156
*/
146
157
GifskiError gifski_add_frame_argb (gifski * handle ,
147
158
uint32_t index ,
@@ -153,7 +164,8 @@ GifskiError gifski_add_frame_argb(gifski *handle,
153
164
154
165
/** Same as `gifski_add_frame_rgba`, except it expects RGB components (3 bytes per pixel)
155
166
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.
157
169
*/
158
170
GifskiError gifski_add_frame_rgb (gifski * handle ,
159
171
uint32_t index ,
@@ -184,6 +196,7 @@ void gifski_set_progress_callback(gifski *handle, int (cb)(void *), void *user_d
184
196
185
197
/**
186
198
* 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.
187
200
*
188
201
* This call will block until the entire file is written. You will need to add frames on another thread.
189
202
*
@@ -195,3 +208,7 @@ GifskiError gifski_write(gifski *handle, const char *destination);
195
208
* Call to free all memory
196
209
*/
197
210
void gifski_drop (gifski * g );
211
+
212
+ #ifdef __cplusplus
213
+ }
214
+ #endif
0 commit comments