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
{
4
5
/** five and six bit channels widen by repeating their high bits, not by shifting */
6
constexpr
uint8_t expand5(uint16_t value) {
return
static_cast<
uint8_t
>
((value << 3) | (value >> 2)); }
7
constexpr
uint8_t expand6(uint16_t value) {
return
static_cast<
uint8_t
>
((value << 2) | (value >> 4)); }
8
9
}
10
11
namespace
Haio::Codecs
{
12
13
/**
14
* @addtogroup move
15
* @{
16
*/
17
template
<>
18
Result<void>
Move<Color::RGB565, Color::RGBA8888>
(
Bytes
src, std::span<uint8_t> dst, Size size) {
19
const
auto
pixels =
static_cast<
size_t
>
(size.width) *
static_cast<
size_t
>
(size.height);
20
if
(src.size() < pixels * 2 || dst.size() < pixels * 4) {
21
HAIO_FAIL
(InvalidInput,
"rgb565 to rgba8888 got a buffer that is too small"
);
22
}
23
24
for
(
size_t
at = 0, to = 0; at < pixels * 2; at += 2, to += 4) {
25
const
auto
packed =
static_cast<
uint16_t
>
(src[at + 0] | (src[at + 1] << 8));
26
dst[to + 0] = expand5((packed >> 11) & 0x1f);
27
dst[to + 1] = expand6((packed >> 5) & 0x3f);
28
dst[to + 2] = expand5(packed & 0x1f);
29
dst[to + 3] = 255;
30
}
31
return
{};
32
}
33
/** @} */
34
35
/**
36
* @addtogroup convert
37
* @{
38
*/
39
template
<>
40
Result<Image<Color::RGBA8888>
>
Convert<Color::RGB565, Color::RGBA8888>
(Image<Color::RGB565> src) {
41
return
convertVia<Color::RGB565, Color::RGBA8888>
(std::move(src));
42
}
43
/** @} */
44
45
}
Haio::Codecs::Convert< Color::RGB565, Color::RGBA8888 >
Result< Image< Color::RGBA8888 > > Convert< Color::RGB565, Color::RGBA8888 >(Image< Color::RGB565 > src)
Definition
rgba8888.cpp:40
Haio::Codecs::Move< Color::RGB565, Color::RGBA8888 >
Result< void > Move< Color::RGB565, Color::RGBA8888 >(Bytes src, std::span< uint8_t > dst, Size size)
Definition
rgba8888.cpp:18
HAIO_FAIL
#define HAIO_FAIL(why, message)
Definition
haio_codec.hpp:258
haio_convert.hpp
Haio::Codecs
Definition
haio_codec.hpp:136
Haio::Codecs::convertVia
Result< Image< To > > convertVia(Image< From > src)
Definition
haio_convert.hpp:21
Haio::Result
std::expected< T, Error > Result
Definition
haio_codec.hpp:32
Haio::Bytes
std::span< const uint8_t > Bytes
Definition
haio_codec.hpp:14
library
backend
codecs
color
rgb565
rgba8888.cpp
Generated by
1.18.0