Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
haio_convert.hpp
Go to the documentation of this file.
1
#pragma once
2
3
#include "
haio_codec.hpp
"
4
5
namespace
Haio
{
6
7
/**
8
* how many bytes one image of this colour and size takes. block formats round up to
9
* whole blocks, so this is not always width times height times something.
10
*/
11
Result<size_t>
sizeOf
(
Color
color,
Size
size);
12
13
namespace
Codecs
{
14
15
/**
16
* the shape every Convert specialisation has: check, allocate, hand the work to Move.
17
* it lives here so a new colour pair is one Move and one line instead of ten.
18
*/
19
template
<Color From, Color To>
20
requires
Movable<From, To>
21
Result<Image<To>
>
convertVia
(
Image<From>
src) {
22
const
Size
size{src.
width
, src.
height
};
23
HAIO_TRY
(want,
sizeOf
(From, size));
24
if
(src.
data
.size() != want) {
25
HAIO_FAIL
(
InvalidInput
,
"image data does not match its own size"
);
26
}
27
28
HAIO_TRY
(bytes,
sizeOf
(To, size));
29
Image<To>
out{src.
width
, src.
height
, std::vector<uint8_t>(bytes)};
30
if
(
auto
moved =
Move<From, To>
(src.
data
, out.
data
, size); !moved) {
31
return
std::unexpected(moved.error());
32
}
33
return
out;
34
}
35
36
}
37
38
}
Haio::Codecs::Movable
Definition
haio_codec.hpp:232
haio_codec.hpp
HAIO_TRY
#define HAIO_TRY(name, expr)
Definition
haio_codec.hpp:246
HAIO_FAIL
#define HAIO_FAIL(why, message)
Definition
haio_codec.hpp:258
Haio::Codecs
Definition
haio_codec.hpp:136
Haio::Codecs::convertVia
Result< Image< To > > convertVia(Image< From > src)
Definition
haio_convert.hpp:21
Haio::Codecs::Move
Result< void > Move(Bytes src, std::span< uint8_t > dst, Size size)=delete
Haio
Definition
haio.hpp:11
Haio::Color
Color
Definition
haio_formats.hpp:106
Haio::Result
std::expected< T, Error > Result
Definition
haio_codec.hpp:32
Haio::sizeOf
Result< size_t > sizeOf(Color color, Size size)
Definition
sizes.cpp:6
Haio::ErrorCode::InvalidInput
@ InvalidInput
Definition
haio_codec.hpp:18
Haio::Size
Definition
haio_object.hpp:12
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
include
haio_convert.hpp
Generated by
1.18.0