Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
rgba8888.cpp
Go to the documentation of this file.
1
#include <
haio_convert.hpp
>
2
3
namespace
Haio::Codecs
{
4
5
/**
6
* indices become the colours they point at.
7
*
8
* this one direction is always possible and never loses anything, which is why it
9
* needs no filter while the way back does.
10
*/
11
template
<>
12
Result<Image<Color::RGBA8888>
>
Convert<Color::PALETTE, Color::RGBA8888>
(
Image<Color::PALETTE>
src) {
13
const
auto
pixels =
static_cast<
size_t
>
(src.
width
) *
static_cast<
size_t
>
(src.
height
);
14
if
(src.
data
.size() != pixels)
HAIO_FAIL
(
InvalidInput
,
"invalid palette image: one index per pixel"
);
15
if
(src.entries.empty()) {
16
HAIO_FAIL
(
InvalidInput
,
"this picture is indices with no palette; give it one with -palete"
);
17
}
18
19
std::vector<uint8_t> out(pixels * 4);
20
for
(
size_t
at = 0; at < pixels; at++) {
21
const
auto
index = src.
data
[at];
22
if
(index >= src.entries.size()) {
23
HAIO_FAIL
(
InvalidInput
,
"the picture points at colour "
+ std::to_string(index)
24
+
" and the palette has "
+ std::to_string(src.entries.size()));
25
}
26
const
auto
colour = src.entries[index];
27
out[at * 4 + 0] =
static_cast<
uint8_t
>
((colour >> 16) & 0xFF);
28
out[at * 4 + 1] =
static_cast<
uint8_t
>
((colour >> 8) & 0xFF);
29
out[at * 4 + 2] =
static_cast<
uint8_t
>
(colour & 0xFF);
30
out[at * 4 + 3] = 0xFF;
31
}
32
return
Image<Color::RGBA8888>
{src.
width
, src.
height
, std::move(out)};
33
}
34
35
}
HAIO_FAIL
#define HAIO_FAIL(why, message)
Definition
haio_codec.hpp:258
haio_convert.hpp
Haio::Codecs
Definition
haio_codec.hpp:136
Haio::Codecs::Convert< Color::PALETTE, Color::RGBA8888 >
Result< Image< Color::RGBA8888 > > Convert< Color::PALETTE, Color::RGBA8888 >(Image< Color::PALETTE > src)
Definition
rgba8888.cpp:12
Haio::Result
std::expected< T, Error > Result
Definition
haio_codec.hpp:32
Haio::ErrorCode::InvalidInput
@ InvalidInput
Definition
haio_codec.hpp:18
Haio::Image
Definition
haio_codec.hpp:36
Haio::Image::height
int height
Definition
haio_codec.hpp:39
Haio::Image::width
int width
Definition
haio_codec.hpp:38
Haio::Image::data
std::vector< uint8_t > data
Definition
haio_codec.hpp:40
library
backend
codecs
color
palette
rgba8888.cpp
Generated by
1.18.0