-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQOIDefinitions.h
125 lines (86 loc) · 2.19 KB
/
QOIDefinitions.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright 2022 Jacob Secunda, [email protected]
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef QOI_DEFINITIONS_H
#define QOI_DEFINITIONS_H
/*
* My primary source for creating this fine QOI Image Translator:
* The Quite Ok Image (QOI) Format Specification: https://qoiformat.org/qoi-specification.pdf
*/
/** QOI File Header **/
// 'magic' Field -> qoi_header
#define QOI_MAGIC_LENGTH 4 // Bytes
const uint32 kQOIMagic = "qoif";
// 'channels' Field -> qoi_header
#define QOI_RGB 3
#define QOI_RGBA 4
// 'colorspace' Field -> qoi_header
#define QOI_SRGB_WITH_LINEAR_ALPHA 0
#define QOI_ALL_CHANNELS_LINEAR 1
typedef struct {
uint32 magic;
uint32 width;
// Width in pixels - Big endian
uint32 height;
// Height in pixels - Big endian
uint8 channels;
// Pixel channel count in image - Informative only
uint8 colorspace;
// Pixel channel format - Informative only
} qoi_header;
/** QOI Miscellaneous Types & Definitions **/
#define PREVIOUS_PIXELS_LENGTH 64
static inline uint8 pixel_to_index_hash(rgb_color pixel) {
return ((pixel.red * 3) + (pixel.green * 5) + (pixel.blue * 7)
+ (pixel.alpha * 11)) % PREVIOUS_PIXELS_LENGTH;
}
#define QOI_2_BYTE_TAG_MASK 0b00000011
/** QOI_OP_RGB Chunk **/
#define QOI_OP_RGB_TAG 0b11111110
typedef struct {
uint8 tag;
uint8 red;
uint8 green;
uint8 blue;
} qoi_op_rgb;
/** QOI_OP_RGBA Chunk **/
#define QOI_OP_RGBA_TAG 0b11111111
typedef struct {
uint8 tag;
uint8 red;
uint8 green;
uint8 blue;
uint8 alpha;
} qoi_op_rgba;
/** QOI_OP_INDEX Chunk **/
#define QOI_OP_INDEX_TAG 0b00
typedef struct {
uint8 tag : 2;
uint8 index : 6;
} qoi_op_index;
/** QOI_OP_DIFF Chunk **/
#define QOI_OP_DIFF_TAG 0b01
typedef struct {
uint8 tag : 2;
uint8 red_diff : 2;
uint8 green_diff : 2;
uint8 blue_diff : 2;
} qoi_op_diff;
#define DIFF_BIAS (-2)
/** QOI_OP_LUMA Chunk **/
#define QOI_OP_LUMA_TAG 0b10
typedef struct {
uint8 tag : 2;
uint8 green_diff : 6;
uint8 red_green_diff : 4;
uint8 blue_green_diff : 4;
} qoi_op_luma;
/** QOI_OP_RUN Chunk **/
#define QOI_OP_RUN_TAG 0b11
typedef struct {
uint8 tag : 2;
uint8 run : 6;
} qoi_op_run;
#define RUN_BIAS (-1)
#endif // QOI_DEFINITIONS_H