Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
detect.cpp
Go to the documentation of this file.
1#include "header.hpp"
2
3#include <haio_codec.hpp>
4
5namespace {
6
7/** the header has to parse and then has to be describing the colour being asked about */
8bool holds(Haio::Bytes data, Haio::Color wanted) {
9 const auto header = Haio::Codecs::Tga::readHeader(data);
10 if (!header) return false;
11 const auto colour = Haio::Codecs::Tga::colorOf(*header);
12 return colour && *colour == wanted;
13}
14
15}
16
17namespace Haio::Codecs {
18
19/**
20 * a truecolor tga with an alpha, which is what a tga is when nobody says which kind.
21 * it is also the only one of the six that keeps everything a picture arrives with,
22 * so it is what haio writes when the command line names the container and not the
23 * colour inside it.
24 */
25template <> struct DefaultColor<Format::TGA> { static constexpr Color value = Color::BGRA8888; };
26
27/**
28 * @addtogroup detect
29 * @{
30 */
31/** thirty two bits a pixel, blue first, with the last byte an alpha */
32template <>
34 return holds(data, Color::BGRA8888);
35}
36/** @} */
37
38/**
39 * @addtogroup detect
40 * @{
41 */
42/** twenty four bits a pixel, blue first */
43template <>
45 return holds(data, Color::BGR888);
46}
47/** @} */
48
49/**
50 * @addtogroup detect
51 * @{
52 */
53/**
54 * sixteen bits a pixel whose top bit the file says is an alpha. the bytes are the
55 * same as the pair below; the attribute bits in the descriptor are the difference,
56 * and they are a claim the writer made rather than anything visible in the pixels.
57 */
58template <>
60 return holds(data, Color::RGBA5551);
61}
62/** @} */
63
64/**
65 * @addtogroup detect
66 * @{
67 */
68/** the same sixteen bits with nobody claiming the top one */
69template <>
71 return holds(data, Color::RGB555);
72}
73/** @} */
74
75/**
76 * @addtogroup detect
77 * @{
78 */
79/** an index a pixel and the colours it points at, which is the format's own palette */
80template <>
82 return holds(data, Color::PALETTE);
83}
84/** @} */
85
86/**
87 * @addtogroup detect
88 * @{
89 */
90/** one byte a pixel and no colour at all */
91template <>
93 return holds(data, Color::GRAY8);
94}
95/** @} */
96
97}
bool Detect< Format::TGA, Color::BGR888 >(Bytes data)
Definition detect.cpp:44
bool Detect< Format::TGA, Color::PALETTE >(Bytes data)
Definition detect.cpp:81
bool Detect< Format::TGA, Color::RGB555 >(Bytes data)
Definition detect.cpp:70
bool Detect< Format::TGA, Color::BGRA8888 >(Bytes data)
Definition detect.cpp:33
bool Detect< Format::TGA, Color::RGBA5551 >(Bytes data)
Definition detect.cpp:59
bool Detect< Format::TGA, Color::GRAY8 >(Bytes data)
Definition detect.cpp:92
std::optional< Color > colorOf(const Header &header)
Definition header.hpp:176
Result< Header > readHeader(Bytes data)
Definition header.hpp:92
std::span< const uint8_t > Bytes