-
Notifications
You must be signed in to change notification settings - Fork 1
/
rle-variant-selection.h
56 lines (50 loc) · 1.22 KB
/
rle-variant-selection.h
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
/*
Shared Run-Length Encoding & Decoding Driver Selection Code
Copyright (c) 2022, Eddy L O Jansson. Licensed under The MIT License.
See https://github.com/eloj/rle-zoo
*/
#include <string.h>
typedef ssize_t (*rle_fp)(const uint8_t *src, size_t slen, uint8_t *dest, size_t dlen);
struct rle_t {
const char *name;
rle_fp compress;
rle_fp decompress;
} rle_variants[] = {
{
.name = "goldbox",
.compress = goldbox_compress,
.decompress = goldbox_decompress
},
{
.name = "packbits",
.compress = packbits_compress,
.decompress = packbits_decompress
},
{
.name = "pcx",
.compress = pcx_compress,
.decompress = pcx_decompress
},
{
.name = "icns",
.compress = icns_compress,
.decompress = icns_decompress
},
};
static const size_t RLE_ZOO_NUM_VARIANTS = sizeof(rle_variants)/sizeof(rle_variants[0]);
static struct rle_t* get_rle_by_name(const char *name) {
for (size_t i = 0 ; i < RLE_ZOO_NUM_VARIANTS ; ++i) {
if (strcmp(name, rle_variants[i].name) == 0) {
return &rle_variants[i];
}
}
return NULL;
}
static void print_variants(void) {
printf("\nAvailable variants:\n");
struct rle_t *rle = rle_variants;
for (size_t i = 0 ; i < RLE_ZOO_NUM_VARIANTS ; ++i) {
printf(" %s\n", rle->name);
++rle;
}
}