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, 12> magic = {0xab, 'K', 'T', 'X', ' ', '2', '0', 0xbb, '\r', '\n', 0x1a, '\n'};
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::colorFromVK(Util::readU32LE(data, 12));
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::colorFromVK(Util::readU32LE(data, 12));
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::colorFromVK(Util::readU32LE(data, 12));
52 return colour && *colour == Color::RGBA8888;
53}
54/** @} */
55
56}
bool Detect< Format::KTX2, Color::RGBA8888 >(Bytes data)
Definition detect.cpp:49
bool Detect< Format::KTX2, Color::ETC1 >(Bytes data)
Definition detect.cpp:25
bool Detect< Format::KTX2, Color::RGB565 >(Bytes data)
Definition detect.cpp:37
Result< Color > colorFromVK(uint32_t format)
Definition gpu.cpp:45
uint32_t readU32LE(Bytes data, size_t off)
Definition bytes.cpp:21
bool matches(Bytes data, Bytes magic)
Definition matches.cpp:7
std::span< const uint8_t > Bytes