Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
rgba8888.cpp
Go to the documentation of this file.
1#include <haio_convert.hpp>
2
3namespace {
4
5constexpr uint8_t expand5(uint16_t value) { return static_cast<uint8_t>((value << 3) | (value >> 2)); }
6
7}
8
9namespace Haio::Codecs {
10
11/**
12 * @addtogroup move
13 * @{
14 */
15/** the bottom bit is the whole alpha: a pixel is either there or it is not */
16template <>
17Result<void> Move<Color::RGBA5551, Color::RGBA8888>(Bytes src, std::span<uint8_t> dst, Size size) {
18 const auto pixels = static_cast<size_t>(size.width) * static_cast<size_t>(size.height);
19 if (src.size() < pixels * 2 || dst.size() < pixels * 4) {
20 HAIO_FAIL(InvalidInput, "rgba5551 to rgba8888 got a buffer that is too small");
21 }
22
23 for (size_t at = 0, to = 0; at < pixels * 2; at += 2, to += 4) {
24 const auto packed = static_cast<uint16_t>(src[at + 0] | (src[at + 1] << 8));
25 dst[to + 0] = expand5((packed >> 11) & 0x1f);
26 dst[to + 1] = expand5((packed >> 6) & 0x1f);
27 dst[to + 2] = expand5((packed >> 1) & 0x1f);
28 dst[to + 3] = (packed & 1) ? 255 : 0;
29 }
30 return {};
31}
32/** @} */
33
34/**
35 * @addtogroup convert
36 * @{
37 */
38template <>
41}
42/** @} */
43
44}
Result< Image< Color::RGBA8888 > > Convert< Color::RGBA5551, Color::RGBA8888 >(Image< Color::RGBA5551 > src)
Definition rgba8888.cpp:39
Result< void > Move< Color::RGBA5551, Color::RGBA8888 >(Bytes src, std::span< uint8_t > dst, Size size)
Definition rgba8888.cpp:17
#define HAIO_FAIL(why, message)
Result< Image< To > > convertVia(Image< From > src)
std::expected< T, Error > Result
std::span< const uint8_t > Bytes