Haio
0.2.X
Homebrew Asset IO/CDN
Toggle main menu visibility
Loading...
Searching...
No Matches
detect.cpp
Go to the documentation of this file.
1
#include "
header.hpp
"
2
3
#include <
haio_codec.hpp
>
4
5
namespace
{
6
7
/** the header has to parse and then has to be describing the colour being asked about */
8
bool
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
17
namespace
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
*/
25
template
<>
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 */
32
template
<>
33
bool
Detect<Format::TGA, Color::BGRA8888>
(
Bytes
data) {
34
return
holds(data,
Color::BGRA8888
);
35
}
36
/** @} */
37
38
/**
39
* @addtogroup detect
40
* @{
41
*/
42
/** twenty four bits a pixel, blue first */
43
template
<>
44
bool
Detect<Format::TGA, Color::BGR888>
(
Bytes
data) {
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
*/
58
template
<>
59
bool
Detect<Format::TGA, Color::RGBA5551>
(
Bytes
data) {
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 */
69
template
<>
70
bool
Detect<Format::TGA, Color::RGB555>
(
Bytes
data) {
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 */
80
template
<>
81
bool
Detect<Format::TGA, Color::PALETTE>
(
Bytes
data) {
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 */
91
template
<>
92
bool
Detect<Format::TGA, Color::GRAY8>
(
Bytes
data) {
93
return
holds(data,
Color::GRAY8
);
94
}
95
/** @} */
96
97
}
Haio::Codecs::Detect< Format::TGA, Color::BGR888 >
bool Detect< Format::TGA, Color::BGR888 >(Bytes data)
Definition
detect.cpp:44
Haio::Codecs::Detect< Format::TGA, Color::PALETTE >
bool Detect< Format::TGA, Color::PALETTE >(Bytes data)
Definition
detect.cpp:81
Haio::Codecs::Detect< Format::TGA, Color::RGB555 >
bool Detect< Format::TGA, Color::RGB555 >(Bytes data)
Definition
detect.cpp:70
Haio::Codecs::Detect< Format::TGA, Color::BGRA8888 >
bool Detect< Format::TGA, Color::BGRA8888 >(Bytes data)
Definition
detect.cpp:33
Haio::Codecs::Detect< Format::TGA, Color::RGBA5551 >
bool Detect< Format::TGA, Color::RGBA5551 >(Bytes data)
Definition
detect.cpp:59
Haio::Codecs::Detect< Format::TGA, Color::GRAY8 >
bool Detect< Format::TGA, Color::GRAY8 >(Bytes data)
Definition
detect.cpp:92
haio_codec.hpp
header.hpp
Haio::Codecs::Tga::colorOf
std::optional< Color > colorOf(const Header &header)
Definition
header.hpp:176
Haio::Codecs::Tga::readHeader
Result< Header > readHeader(Bytes data)
Definition
header.hpp:92
Haio::Codecs
Definition
haio_codec.hpp:136
Haio::Codecs::DefaultColor
Definition
haio_codec.hpp:143
Haio::Color
Color
Definition
haio_formats.hpp:106
Haio::Color::BGRA8888
@ BGRA8888
Definition
haio_formats.hpp:135
Haio::Color::PALETTE
@ PALETTE
Definition
haio_formats.hpp:145
Haio::Color::BGR888
@ BGR888
Definition
haio_formats.hpp:134
Haio::Color::RGBA5551
@ RGBA5551
Definition
haio_formats.hpp:127
Haio::Color::GRAY8
@ GRAY8
Definition
haio_formats.hpp:137
Haio::Color::RGB555
@ RGB555
Definition
haio_formats.hpp:117
Haio::Format
Format
Definition
haio_formats.hpp:17
Haio::Format::TGA
@ TGA
Definition
haio_formats.hpp:93
Haio::Bytes
std::span< const uint8_t > Bytes
Definition
haio_codec.hpp:14
Haio::Codecs::DefaultColor< Format::TGA >::value
static constexpr Color value
Definition
detect.cpp:25
library
backend
codecs
container
tga
detect.cpp
Generated by
1.18.0