forked from kornelski/pngquant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
68 lines (53 loc) · 1.73 KB
/
test.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#undef NDEBUG
#include <assert.h>
#include "../lib/libimagequant.h"
#include <stdio.h>
static void test_fixed_colors() {
liq_attr *attr = liq_attr_create();
unsigned char dummy[4] = {0};
liq_image *img = liq_image_create_rgba(attr, dummy, 1, 1, 0);
assert(img);
liq_image_add_fixed_color(img, (liq_color){0,0,0,0});
liq_result *res = liq_quantize_image(attr, img);
assert(res);
const liq_palette *pal = liq_get_palette(res);
assert(pal);
assert(pal->count == 1);
liq_result_destroy(res);
liq_image_destroy(img);
liq_attr_destroy(attr);
}
static void test_fixed_colors_order() {
liq_attr *attr = liq_attr_create();
unsigned char dummy[4] = {0};
liq_image *img = liq_image_create_rgba(attr, dummy, 1, 1, 0);
assert(img);
liq_color colors[17] = {
{0,0,0,0}, {1,1,1,1}, {2,2,2,2}, {3,3,3,3}, {4,4,4,4}, {5,4,4,4},
{6,4,4,4}, {6,7,4,4}, {6,7,8,4}, {6,7,8,9}, {10,7,8,9}, {10,11,8,9},
{10,11,12,9}, {10,11,12,13}, {14,11,12,13}, {14,15,12,13}, {14,15,16,13},
};
for(int i=0; i < 17; i++) {
liq_image_add_fixed_color(img, colors[i]);
}
liq_result *res = liq_quantize_image(attr, img);
assert(res);
const liq_palette *pal = liq_get_palette(res);
assert(pal);
assert(pal->count == 17);
for(int i=0; i < 17; i++) {
assert(pal->entries[i].r == colors[i].r);
assert(pal->entries[i].g == colors[i].g);
assert(pal->entries[i].b == colors[i].b);
assert(pal->entries[i].a == colors[i].a);
}
liq_result_destroy(res);
liq_image_destroy(img);
liq_attr_destroy(attr);
}
int main(void) {
test_fixed_colors();
test_fixed_colors_order();
assert(printf("OK\n"));
return 0;
}