Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
bgra8888.cpp
Go to the documentation of this file.
2
3namespace Haio::Codecs {
4
5/**
6 * @addtogroup move
7 * @{
8 */
9/**
10 * the same swap as the way back, written out again rather than shared.
11 *
12 * it is its own file because the pair is what the build scans for: a move that
13 * appeared in the other direction's file would be declared whenever that one was
14 * compiled, which is not the same thing as this one existing.
15 */
16template <>
17Result<void> Move<Color::RGBA8888, Color::BGRA8888>(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 * 4 || dst.size() < pixels * 4) {
20 HAIO_FAIL(InvalidInput, "rgba8888 to bgra8888 got a buffer that is too small");
21 }
22
23 for (size_t at = 0; at < pixels * 4; at += 4) {
24 dst[at + 0] = src[at + 2];
25 dst[at + 1] = src[at + 1];
26 dst[at + 2] = src[at + 0];
27 dst[at + 3] = src[at + 3];
28 }
29 return {};
30}
31/** @} */
32
33/**
34 * @addtogroup convert
35 * @{
36 */
37template <>
40}
41/** @} */
42
43}
Result< Image< Color::BGRA8888 > > Convert< Color::RGBA8888, Color::BGRA8888 >(Image< Color::RGBA8888 > src)
Definition bgra8888.cpp:38
Result< void > Move< Color::RGBA8888, Color::BGRA8888 >(Bytes src, std::span< uint8_t > dst, Size size)
Definition bgra8888.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