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
3namespace {
4
5/** the magic is two bytes and a separator: "P6\n", never "P6x" */
6bool 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
14namespace Haio::Codecs {
15
16/** what a bare "ppm" means when nobody says which colour */
17template <> 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 */
24template <>
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 */
38template <>
40 return isNetpbm(data, '1', '2') || isNetpbm(data, '4', '5');
41}
42/** @} */
43
44}
bool Detect< Format::PPM, Color::RGB888 >(Bytes data)
Definition detect.cpp:25
bool Detect< Format::PPM, Color::GRAY8 >(Bytes data)
Definition detect.cpp:39
std::span< const uint8_t > Bytes