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
* @addtogroup move
7
* @{
8
*/
9
/**
10
* add an opaque alpha channel.
11
*
12
* @todo the mirror of the rgba8888 to rgb888 pack, and just as hot, but left scalar:
13
* the 3 to 4 unpack needs a load that straddles the shuffle window, so it is a real
14
* port rather than the same mask backwards.
15
*/
16
template
<>
17
Result<void>
Move<Color::RGB888, 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 * 3 || dst.size() < pixels * 4) {
20
HAIO_FAIL
(
InvalidInput
,
"rgb888 to rgba8888 got a buffer that is too small"
);
21
}
22
for
(
size_t
at = 0, to = 0; to < pixels * 4; at += 3, to += 4) {
23
dst[to + 0] = src[at + 0];
24
dst[to + 1] = src[at + 1];
25
dst[to + 2] = src[at + 2];
26
dst[to + 3] = 0xFF;
27
}
28
return
{};
29
}
30
/** @} */
31
32
/**
33
* @addtogroup convert
34
* @{
35
*/
36
template
<>
37
Result<Image<Color::RGBA8888>
>
Convert<Color::RGB888, Color::RGBA8888>
(
Image<Color::RGB888>
src) {
38
return
convertVia<Color::RGB888, Color::RGBA8888>
(std::move(src));
39
}
40
/** @} */
41
42
}
Haio::Codecs::Convert< Color::RGB888, Color::RGBA8888 >
Result< Image< Color::RGBA8888 > > Convert< Color::RGB888, Color::RGBA8888 >(Image< Color::RGB888 > src)
Definition
rgba8888.cpp:37
Haio::Codecs::Move< Color::RGB888, Color::RGBA8888 >
Result< void > Move< Color::RGB888, Color::RGBA8888 >(Bytes src, std::span< uint8_t > dst, Size size)
Definition
rgba8888.cpp:17
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::Size::height
int height
Definition
haio_object.hpp:14
Haio::ErrorCode::InvalidInput
@ InvalidInput
Definition
haio_codec.hpp:18
Haio::Bytes
std::span< const uint8_t > Bytes
Definition
haio_codec.hpp:14
Haio::Size::width
int width
Definition
haio_object.hpp:13
Haio::Size
Definition
haio_object.hpp:12
Haio::Image
Definition
haio_codec.hpp:36
library
backend
codecs
color
rgb888
rgba8888.cpp
Generated by
1.18.0