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 <
haio_codec.hpp
>
2
3
namespace
{
4
5
/** the magic is two bytes and a separator: "P6\n", never "P6x" */
6
bool
isNetpbm(
Haio::Bytes
data,
char
low,
char
high) {
7
return
data.size() >= 3 && data[0] ==
'P'
&& data[1] >=
static_cast<
uint8_t
>
(low)
8
&& data[1] <=
static_cast<
uint8_t
>
(high)
9
&& (data[2] ==
'\n'
|| data[2] ==
'\r'
|| data[2] ==
' '
|| data[2] ==
'\t'
|| data[2] ==
'#'
);
10
}
11
12
}
13
14
namespace
Haio::Codecs
{
15
16
/** what a bare "ppm" means when nobody says which colour */
17
template
<>
struct
DefaultColor
<
Format
::
PPM
> {
static
constexpr
Color
value
=
Color::RGB888
; };
18
19
/**
20
* @addtogroup detect
21
* @{
22
*/
23
/** P3 is ascii pixmap and P6 binary pixmap: three samples a pixel */
24
template
<>
25
bool
Detect<Format::PPM, Color::RGB888>
(
Bytes
data) {
26
return
isNetpbm(data,
'3'
,
'3'
) || isNetpbm(data,
'6'
,
'6'
);
27
}
28
/** @} */
29
30
/**
31
* @addtogroup detect
32
* @{
33
*/
34
/**
35
* the rest of the family is one sample a pixel: P1 and P4 bitmaps, P2 and P5
36
* graymaps. they answer as grey so the decoder that gets them is the right one.
37
*/
38
template
<>
39
bool
Detect<Format::PPM, Color::GRAY8>
(
Bytes
data) {
40
return
isNetpbm(data,
'1'
,
'2'
) || isNetpbm(data,
'4'
,
'5'
);
41
}
42
/** @} */
43
44
}
Haio::Codecs::Detect< Format::PPM, Color::RGB888 >
bool Detect< Format::PPM, Color::RGB888 >(Bytes data)
Definition
detect.cpp:25
Haio::Codecs::Detect< Format::PPM, Color::GRAY8 >
bool Detect< Format::PPM, Color::GRAY8 >(Bytes data)
Definition
detect.cpp:39
haio_codec.hpp
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::RGB888
@ RGB888
Definition
haio_formats.hpp:108
Haio::Format
Format
Definition
haio_formats.hpp:17
Haio::Format::PPM
@ PPM
Definition
haio_formats.hpp:29
Haio::Bytes
std::span< const uint8_t > Bytes
Definition
haio_codec.hpp:14
Haio::Codecs::DefaultColor< Format::PPM >::value
static constexpr Color value
Definition
detect.cpp:17
library
backend
codecs
container
ppm
detect.cpp
Generated by
1.18.0