Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
haio_formats.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include <array>
4
#include <string_view>
5
6
namespace
Haio
{
7
8
/**
9
* what a file is: the container that holds pixels. RAW means no container at all,
10
* just the bytes of a colour format, which is why it needs its size supplied.
11
*
12
* the \@mime and \@ext tags are read by scripts/gen_codecs.cpp, which builds the lookups both ways
13
* from them. the first one is what haio writes, the rest are only accepted. this is what
14
* a c++26 enum annotation will carry once the compiler parses them, and until then a
15
* tag keeps them on the enumerator instead of in a table somewhere else.
16
*/
17
enum class
Format
{
18
/** no mime type of its own: bare pixels are application/octet-stream */
19
RAW
,
20
/**
21
* @mime image/png
22
* @ext png
23
*/
24
PNG
,
25
/**
26
* @mime image/x-portable-pixmap image/x-portable-anymap
27
* @ext ppm pgm pbm pnm
28
*/
29
PPM
,
30
/**
31
* @mime image/jpeg
32
* @ext jpg jpeg
33
*/
34
JPEG
,
35
/**
36
* @mime image/ktx
37
* @ext ktx
38
*/
39
KTX
,
40
/**
41
* @mime image/ktx2
42
* @ext ktx2
43
*/
44
KTX2
,
45
/**
46
* @mime image/vnd-ms.dds image/vnd.ms-dds
47
* @ext dds
48
*/
49
DDS
,
50
/**
51
* @mime image/x-pvr
52
* @ext pvr
53
*/
54
PVR
,
55
/**
56
* @mime image/x-zcis
57
* @ext zcis
58
*/
59
ZCIS
,
60
61
/**
62
* not files but pictures drawn with escape codes, for looking at one without
63
* leaving the terminal. they only ever encode: nothing arrives as ansi.
64
*
65
* @mime text/x-ansi
66
* @ext ansi
67
*/
68
ANSI
,
69
/**
70
* @mime text/x-ansi-halfblock
71
* @ext utf8
72
*/
73
UTF8
,
74
75
/**
76
* a cartridge, which is a container like any other: it says where its pattern
77
* data begins and how much of it there is.
78
*
79
* @mime application/x-nes-rom
80
* @ext nes
81
*/
82
ROM
,
83
84
/**
85
* last on purpose. every format above starts with bytes that mean nothing else,
86
* and a tga starts with its own image size: recognising one is a matter of the
87
* header agreeing with itself, so it is asked only after everything that can
88
* prove itself outright has said no.
89
*
90
* @mime image/x-tga image/x-targa image/tga
91
* @ext tga targa tpic
92
*/
93
TGA
,
94
95
/**
96
* @mime image/gif
97
* @ext gif
98
*/
99
GIF
,
100
};
101
102
/**
103
* how the pixels are laid out. these never appear as a file on their own: ETC1 and
104
* RGB565 are what a gpu container carries, the rest are what codecs hand around.
105
*/
106
enum class
Color
{
107
RGBA8888
,
108
RGB888
,
109
RGB565
,
110
111
/**
112
* five bits a channel packed into two bytes, little endian, with the top bit
113
* spare: 0RRRRRGGGGGBBBBB. it is what a sixteen bit tga holds, and the spare bit
114
* is why the same two bytes are a different colour once somebody declares it to
115
* be alpha.
116
*/
117
RGB555
,
118
119
/**
120
* the same two bytes with the alpha at the other end: RRRRRGGGGGBBBBBA. the name
121
* reads from the top bit down, which is the order the bits sit in the sixteen bit
122
* word once it is read little endian.
123
*
124
* one bit of alpha is a yes or a no, so converting to it rounds: half opaque and
125
* up survives, the rest goes clear.
126
*/
127
RGBA5551
,
128
129
/**
130
* blue first, which is how every windows era container stores a pixel. a tga, a
131
* dds and a bmp all write their bytes this way round, so the swap belongs in one
132
* colour rather than inside each of their decoders.
133
*/
134
BGR888
,
135
BGRA8888
,
136
137
GRAY8
,
138
ETC1
,
139
YUV420
,
140
141
/**
142
* an index per pixel plus the colours it indexes, which is why this is the one
143
* colour whose Image carries something besides pixels.
144
*/
145
PALETTE
,
146
147
/**
148
* how a console keeps its indices, which is not one per byte.
149
*
150
* nes chr is two bits a pixel, in eight by eight tiles, with the two bits of a
151
* pixel living in separate planes eight bytes apart. that is a layout and not a
152
* container, the same way ETC1 is, so it is a colour: a .chr file is Format::RAW
153
* holding this, and converting to PALETTE is what unpacks it.
154
*/
155
CHR_NES
,
156
};
157
158
/**
159
* the other names these layouts go by.
160
*
161
* ffmpeg's -pix_fmt is where most people learned to name a pixel layout on a command
162
* line, so what they already type for it is accepted beside the enumerator's own
163
* name. the list sits next to the enum rather than inside the lookup that reads it,
164
* because the command line grammar prints it too, and a list written in two places is
165
* a list that drifts.
166
*/
167
struct
ColorAlias
{
168
std::string_view
spelling
;
169
Color
color
;
170
};
171
172
inline
constexpr
ColorAlias
colorAliases
[] = {
173
// short spellings the enumerator name cannot carry until enum annotations land
174
{
"rgb"
,
Color::RGB888
},
175
{
"rgba"
,
Color::RGBA8888
},
176
{
"rgb24"
,
Color::RGB888
},
177
{
"bgr24"
,
Color::BGR888
},
178
{
"bgra"
,
Color::BGRA8888
},
179
// the way it tends to get written down when it is listed beside rgba8888
180
{
"bgr8888"
,
Color::BGRA8888
},
181
{
"rgb565le"
,
Color::RGB565
},
182
{
"rgb555le"
,
Color::RGB555
},
183
{
"gray"
,
Color::GRAY8
},
184
{
"grey"
,
Color::GRAY8
},
185
{
"pal8"
,
Color::PALETTE
},
186
// the p is for planar, which is the only way haio keeps it
187
{
"yuv420p"
,
Color::YUV420
},
188
};
189
190
}
Haio
Definition
haio.hpp:11
Haio::colorAliases
constexpr ColorAlias colorAliases[]
Definition
haio_formats.hpp:172
Haio::Color
Color
Definition
haio_formats.hpp:106
Haio::Color::BGRA8888
@ BGRA8888
Definition
haio_formats.hpp:135
Haio::Color::RGBA8888
@ RGBA8888
Definition
haio_formats.hpp:107
Haio::Color::CHR_NES
@ CHR_NES
Definition
haio_formats.hpp:155
Haio::Color::RGB888
@ RGB888
Definition
haio_formats.hpp:108
Haio::Color::RGB565
@ RGB565
Definition
haio_formats.hpp:109
Haio::Color::PALETTE
@ PALETTE
Definition
haio_formats.hpp:145
Haio::Color::BGR888
@ BGR888
Definition
haio_formats.hpp:134
Haio::Color::YUV420
@ YUV420
Definition
haio_formats.hpp:139
Haio::Color::ETC1
@ ETC1
Definition
haio_formats.hpp:138
Haio::Color::RGBA5551
@ RGBA5551
Definition
haio_formats.hpp:127
Haio::Color::GRAY8
@ GRAY8
Definition
haio_formats.hpp:137
Haio::Color::RGB555
@ RGB555
Definition
haio_formats.hpp:117
Haio::ColorAlias::spelling
std::string_view spelling
Definition
haio_formats.hpp:168
Haio::ColorAlias::color
Color color
Definition
haio_formats.hpp:169
Haio::Format
Format
Definition
haio_formats.hpp:17
Haio::Format::KTX2
@ KTX2
Definition
haio_formats.hpp:44
Haio::Format::ROM
@ ROM
Definition
haio_formats.hpp:82
Haio::Format::PPM
@ PPM
Definition
haio_formats.hpp:29
Haio::Format::PNG
@ PNG
Definition
haio_formats.hpp:24
Haio::Format::RAW
@ RAW
Definition
haio_formats.hpp:19
Haio::Format::TGA
@ TGA
Definition
haio_formats.hpp:93
Haio::Format::ZCIS
@ ZCIS
Definition
haio_formats.hpp:59
Haio::Format::JPEG
@ JPEG
Definition
haio_formats.hpp:34
Haio::Format::GIF
@ GIF
Definition
haio_formats.hpp:99
Haio::Format::DDS
@ DDS
Definition
haio_formats.hpp:49
Haio::Format::PVR
@ PVR
Definition
haio_formats.hpp:54
Haio::Format::ANSI
@ ANSI
Definition
haio_formats.hpp:68
Haio::Format::KTX
@ KTX
Definition
haio_formats.hpp:39
Haio::Format::UTF8
@ UTF8
Definition
haio_formats.hpp:73
Haio::ColorAlias
Definition
haio_formats.hpp:167
include
haio_formats.hpp
Generated by
1.18.0