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', ' ', '1', '1', 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::colorFromGL(Util::readU32LE(data, 16), Util::readU32LE(data, 24), Util::readU32LE(data, 28));
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::colorFromGL(Util::readU32LE(data, 16), Util::readU32LE(data, 24), Util::readU32LE(data, 28));
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::colorFromGL(Util::readU32LE(data, 16), Util::readU32LE(data, 24), Util::readU32LE(data, 28));
52 return colour && *colour == Color::RGBA8888;
53}
54/** @} */
55
56}
bool Detect< Format::KTX, Color::RGB565 >(Bytes data)
Definition detect.cpp:37
bool Detect< Format::KTX, Color::RGBA8888 >(Bytes data)
Definition detect.cpp:49
bool Detect< Format::KTX, Color::ETC1 >(Bytes data)
Definition detect.cpp:25
Result< Color > colorFromGL(uint32_t glType, uint32_t glFormat, uint32_t glInternal)
Definition gpu.cpp:38
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