Debian Codegraph @

cvd/internal/io/pnm_grok.h

raw symbols SCIP
1 #ifndef PNM_GROK_H
2 #define PNM_GROK_H
3
4 #include <cvd/image.h>
5 #include <cvd/internal/convert_pixel_types.h>
6 #include <cvd/internal/load_and_save.h>
7 #include <iostream>
8 #include <memory>
9 #include <string>
10 #include <vector>
11
12 namespace CVD
13 {
14 namespace PNM
15 {
16 class pnm_in;
17
18 using CVD::Internal::Head;
19 using CVD::Internal::TypeList;
20 class Reader
21 {
22 public:
23 Reader(std::istream&);
24 ~Reader();
25
26 ImageRef size();
27 bool top_row_first();
28
29 void get_raw_pixel_line(bool*);
30 void get_raw_pixel_line(unsigned char*);
31 void get_raw_pixel_line(unsigned short*);
32 void get_raw_pixel_line(Rgb<unsigned char>*);
33 void get_raw_pixel_line(Rgb<unsigned short>*);
34
35 std::string datatype();
36 std::string name();
37
38 typedef TypeList<bool,
39 TypeList<byte,
40 TypeList<unsigned short,
41 TypeList<Rgb<byte>,
42 TypeList<Rgb<unsigned short>,
43 Head>>>>>
44 Types;
45
46 static bool first_byte_matches(const int b)
47 {
48 return b == 'P';
49 }
50
51 private:
52 std::unique_ptr<pnm_in> p;
53 };
54
55 ////////////////////////////////////////////////////////////////////////////////
56 //
57 // PNM writing.
58 //
59
60 template <int isRgb, int isbyte>
61 struct ComponentMapper
62 {
63 typedef Rgb<byte> type;
64 };
65 template <>
66 struct ComponentMapper<1, 0>
67 {
68 typedef Rgb<unsigned short> type;
69 };
70 template <>
71 struct ComponentMapper<0, 1>
72 {
73 typedef byte type;
74 };
75 template <>
76 struct ComponentMapper<0, 0>
77 {
78 typedef unsigned short type;
79 };
80
81 class pnm_writer;
82 class Writer
83 {
84 public:
85 Writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<>>& p);
86 ~Writer();
87
88 //void write_raw_pixel_line(const bool*);
89 void write_raw_pixel_line(const unsigned char*);
90 void write_raw_pixel_line(const unsigned short*);
91 void write_raw_pixel_line(const Rgb<unsigned char>*);
92 void write_raw_pixel_line(const Rgb<unsigned short>*);
93
94 template <class Incoming>
95 struct Outgoing
96 {
97 typedef typename Pixel::Component<Incoming>::type Element;
98 typedef typename ComponentMapper<Pixel::is_Rgb<Incoming>::value,
99 std::numeric_limits<Element>::is_integer && std::numeric_limits<Element>::digits <= 8>::type type;
100 };
101 static const int top_row_first = 1;
102
103 private:
104 std::unique_ptr<pnm_writer> p;
105 };
106
107 }
108 }
109 #endif