Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
decode.cpp
Go to the documentation of this file.
1
#include <
haio_codec.hpp
>
2
#include <
haio_convert.hpp
>
3
#include <
haio_util.hpp
>
4
5
namespace
Haio::Codecs
{
6
namespace
{
7
8
/** one body for every colour the container can hold; the caller names which */
9
template
<Color P>
10
Result<Image<P>
> decodePvr(
const
Blob
& blob) {
11
if
(blob.
data
.size() < 52)
HAIO_FAIL
(
InvalidInput
,
"invalid pvr header"
);
12
if
(
Util::readU32LE
(blob.
data
, 32) != 1 ||
Util::readU32LE
(blob.
data
, 36) != 1
13
||
Util::readU32LE
(blob.
data
, 40) != 1 ||
Util::readU32LE
(blob.
data
, 44) != 1) {
14
HAIO_FAIL
(
InvalidInput
,
"unsupported pvr texture shape"
);
15
}
16
17
const
Size
size{
static_cast<
int
>
(
Util::readU32LE
(blob.
data
, 28)),
static_cast<
int
>
(
Util::readU32LE
(blob.
data
, 24))};
18
HAIO_TRY
(want,
sizeOf
(P, size));
19
HAIO_TRY
(data,
Util::slice
(blob.
data
,
static_cast<
size_t
>
(52) +
Util::readU32LE
(blob.
data
, 48), want));
20
21
HAIO_TRY
(expected,
sizeOf
(P, size));
22
if
(data.size() != expected)
HAIO_FAIL
(
InvalidInput
,
"invalid pvr payload size"
);
23
24
return
Image<P>
{size.
width
, size.
height
, std::move(data)};
25
}
26
27
}
28
29
/**
30
* @addtogroup decode
31
* @{
32
*/
33
template
<>
34
Result<Image<Color::ETC1>
>
Decode<Format::PVR, Color::ETC1>
(
const
Blob
& blob) {
35
return
decodePvr<Color::ETC1>(blob);
36
}
37
/** @} */
38
39
/**
40
* @addtogroup decode
41
* @{
42
*/
43
template
<>
44
Result<Image<Color::RGB565>
>
Decode<Format::PVR, Color::RGB565>
(
const
Blob
& blob) {
45
return
decodePvr<Color::RGB565>(blob);
46
}
47
/** @} */
48
49
/**
50
* @addtogroup decode
51
* @{
52
*/
53
template
<>
54
Result<Image<Color::RGBA8888>
>
Decode<Format::PVR, Color::RGBA8888>
(
const
Blob
& blob) {
55
return
decodePvr<Color::RGBA8888>(blob);
56
}
57
/** @} */
58
59
}
Haio::Codecs::Decode< Format::PVR, Color::RGBA8888 >
Result< Image< Color::RGBA8888 > > Decode< Format::PVR, Color::RGBA8888 >(const Blob &blob)
Definition
decode.cpp:54
Haio::Codecs::Decode< Format::PVR, Color::ETC1 >
Result< Image< Color::ETC1 > > Decode< Format::PVR, Color::ETC1 >(const Blob &blob)
Definition
decode.cpp:34
Haio::Codecs::Decode< Format::PVR, Color::RGB565 >
Result< Image< Color::RGB565 > > Decode< Format::PVR, Color::RGB565 >(const Blob &blob)
Definition
decode.cpp:44
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_convert.hpp
haio_util.hpp
Haio::Codecs
Definition
haio_codec.hpp:136
Haio::Util::slice
Result< std::vector< uint8_t > > slice(Bytes data, size_t off, size_t len)
Definition
bytes.cpp:42
Haio::Util::readU32LE
uint32_t readU32LE(Bytes data, size_t off)
Definition
bytes.cpp:21
Haio::Blob::data
std::vector< uint8_t > data
Definition
haio_codec.hpp:127
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::Size::height
int height
Definition
haio_object.hpp:14
Haio::ErrorCode::InvalidInput
@ InvalidInput
Definition
haio_codec.hpp:18
Haio::Size::width
int width
Definition
haio_object.hpp:13
Haio::Blob
Definition
haio_codec.hpp:122
Haio::Size
Definition
haio_object.hpp:12
Haio::Image
Definition
haio_codec.hpp:36
library
backend
codecs
container
pvr
decode.cpp
Generated by
1.18.0