-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.cpp
44 lines (36 loc) · 1.16 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by xiaozhuai on 2020/12/25.
//
#include <cstdio>
#include "GifEncoder.h"
int main() {
// Suppose that you have three frame to be encoded
const int w = 40;
const int h = 40;
uint32_t frame0[w * h];
uint32_t frame1[w * h];
uint32_t frame2[w * h];
for (int i = 0; i < w * h; ++i) {
frame0[i] = 0xFF0000FF; // red
frame1[i] = 0xFF00FF00; // green
frame2[i] = 0xFFFF0000; // blue
}
int quality = 10;
bool useGlobalColorMap = true;
int loop = 0;
int preAllocSize = useGlobalColorMap ? w * h * 3 * 3 : w * h * 3;
int delay = 20;
GifEncoder gifEncoder;
if (!gifEncoder.open("test.gif", w, h, quality, useGlobalColorMap, loop, preAllocSize)) {
fprintf(stderr, "Error open gif file\n");
return 1;
}
gifEncoder.push(GifEncoder::PIXEL_FORMAT_RGBA, (uint8_t *) frame0, w, h, delay);
gifEncoder.push(GifEncoder::PIXEL_FORMAT_RGBA, (uint8_t *) frame1, w, h, delay);
gifEncoder.push(GifEncoder::PIXEL_FORMAT_RGBA, (uint8_t *) frame2, w, h, delay);
if (!gifEncoder.close()) {
fprintf(stderr, "Error close gif file\n");
return 1;
}
return 0;
}