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
|
#ifndef LCOLONQ_QOI_H
#define LCOLONQ_QOI_H
#include <lcq/prelude.h>
typedef struct {
u8 r, g, b, a;
} qoi_color;
static inline qoi_color qoi_color_new(u8 r, u8 g, u8 b, u8 a) {
qoi_color ret;
ret.r = r; ret.g = g; ret.b = b; ret.a = a;
return ret;
}
static inline u8 qoi_color_hash(qoi_color c) {
return (u8) (c.r * 3 + c.g * 5 + c.b * 7 + c.a * 11) % 64;
}
typedef enum {
QOI_CHANNELS_RGB = 3,
QOI_CHANNELS_RGBA = 4
} qoi_channels;
typedef enum {
QOI_COLORSPACE_SRGB = 0,
QOI_COLORSPACE_LINEAR = 1
} qoi_colorspace;
typedef struct {
u32 width, height;
u8 channels, colorspace;
} qoi_header;
typedef struct {
u8 *buf;
i64 len;
i64 cur;
qoi_color palette[64];
} qoi_encoder;
typedef struct {
u8 *buf;
i64 len;
i64 cur;
qoi_color palette[64];
} qoi_decoder;
void qoi_decoder_new(qoi_decoder *q, u8 *buf, i64 len);
bool qoi_decode_header(qoi_decoder *q, qoi_header *h);
bool qoi_decode(qoi_decoder *q, qoi_header *h, qoi_color *pixels);
#endif
|