Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
detect.cpp
Go to the documentation of this file.
1#include <haio_codec.hpp>
2#include <haio_util.hpp>
3
4#include <haio_util.hpp>
5
6namespace {
7
8/** the container is only half the answer: the header also says which colour it holds */
9bool isContainer(Haio::Bytes data) {
10
11
12 constexpr std::array<uint8_t, 4> magic = {'P', 'V', 'R', 0x03};
13 return Haio::Util::matches(data, magic);
14}
15
16}
17
18namespace Haio::Codecs {
19
20/**
21 * @addtogroup detect
22 * @{
23 */
24template <>
26 if (!isContainer(data)) return false;
27 const auto colour = Util::GPU::colorFromPVR(Util::readU64LE(data, 8));
28 return colour && *colour == Color::ETC1;
29}
30/** @} */
31
32/**
33 * @addtogroup detect
34 * @{
35 */
36template <>
38 if (!isContainer(data)) return false;
39 const auto colour = Util::GPU::colorFromPVR(Util::readU64LE(data, 8));
40 return colour && *colour == Color::RGB565;
41}
42/** @} */
43
44/**
45 * @addtogroup detect
46 * @{
47 */
48template <>
50 if (!isContainer(data)) return false;
51 const auto colour = Util::GPU::colorFromPVR(Util::readU64LE(data, 8));
52 return colour && *colour == Color::RGBA8888;
53}
54/** @} */
55
56}
bool Detect< Format::PVR, Color::RGB565 >(Bytes data)
Definition detect.cpp:37
bool Detect< Format::PVR, Color::ETC1 >(Bytes data)
Definition detect.cpp:25
bool Detect< Format::PVR, Color::RGBA8888 >(Bytes data)
Definition detect.cpp:49
Result< Color > colorFromPVR(uint64_t format)
Definition gpu.cpp:52
uint64_t readU64LE(Bytes data, size_t off)
Definition bytes.cpp:37
bool matches(Bytes data, Bytes magic)
Definition matches.cpp:7
std::span< const uint8_t > Bytes