summaryrefslogtreecommitdiff
path: root/qoi/include/lcq/qoi.h
diff options
context:
space:
mode:
Diffstat (limited to 'qoi/include/lcq/qoi.h')
-rw-r--r--qoi/include/lcq/qoi.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/qoi/include/lcq/qoi.h b/qoi/include/lcq/qoi.h
new file mode 100644
index 0000000..b90c4b2
--- /dev/null
+++ b/qoi/include/lcq/qoi.h
@@ -0,0 +1,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