Debian Codegraph @

cvd/internal/io/tiff.h

raw symbols SCIP
1 #ifndef PNM_TIFF
2 #define PNM_TIFF
3
4 #include <cvd/image.h>
5 #include <cvd/internal/load_and_save.h>
6 #include <iostream>
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 namespace CVD
12 {
13 namespace TIFF
14 {
15
16 using CVD::Internal::Head;
17 using CVD::Internal::TypeList;
18
19 ////////////////////////////////////////////////////////////////////////////////
20 //
21 // TIFF reading
22 //
23
24 class TIFFPimpl;
25 class Reader
26 {
27 public:
28 Reader(std::istream&);
29 ~Reader();
30
31 ImageRef size();
32 bool top_row_first();
33
34 void get_raw_pixel_line(bool*);
35 void get_raw_pixel_line(unsigned char*);
36 void get_raw_pixel_line(unsigned short*);
37 void get_raw_pixel_line(float*);
38 void get_raw_pixel_line(double*);
39
40 void get_raw_pixel_line(Rgb<unsigned char>*);
41 void get_raw_pixel_line(Rgb<unsigned short>*);
42 void get_raw_pixel_line(Rgb<float>*);
43 void get_raw_pixel_line(Rgb<double>*);
44
45 void get_raw_pixel_line(Rgba<unsigned char>*);
46 void get_raw_pixel_line(Rgba<unsigned short>*);
47 void get_raw_pixel_line(Rgba<float>*);
48 void get_raw_pixel_line(Rgba<double>*);
49
50 std::string datatype();
51 std::string name();
52
53 typedef TypeList<bool,
54 TypeList<byte,
55 TypeList<unsigned short,
56 TypeList<float,
57 TypeList<double,
58 TypeList<Rgb<byte>,
59 TypeList<Rgb<unsigned short>,
60 TypeList<Rgb<float>,
61 TypeList<Rgb<double>,
62 TypeList<Rgba<byte>,
63 TypeList<Rgba<unsigned short>,
64 TypeList<Rgba<float>,
65 TypeList<Rgba<double>,
66 Head>>>>>>>>>>>>>
67 Types;
68
69 static bool first_byte_matches(const int c)
70 {
71 return c == 'I' || c == 'M';
72 }
73
74 private:
75 std::unique_ptr<TIFFPimpl> t;
76 };
77
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // TIFF writing
81 //
82
83 //This is a really nasty way of doing pattern matching for ranges of numbers.
84 //The range is encoded un unary notation. The range is on some integer, x.
85 //g1 is set if x > 1. g8 is set if x > 8 and so on.
86 //This allows us to choose a type with a reasonable number of bits.
87 template <int g1, int g8>
88 struct IntMapper
89 {
90 typedef unsigned short type;
91 };
92 template <>
93 struct IntMapper<1, 0>
94 {
95 typedef unsigned char type;
96 };
97 template <>
98 struct IntMapper<0, 0>
99 {
100 typedef bool type;
101 };
102
103 //Mapping for integral types
104 template <class ComponentIn, int is_integral>
105 struct ComponentMapper_
106 {
107 typedef typename IntMapper<
108 (Pixel::traits<ComponentIn>::bits_used > 1),
109 (Pixel::traits<ComponentIn>::bits_used > 8)>::type type;
110 };
111
112 //Mapping for non integral types
113 template <class ComponentIn>
114 struct ComponentMapper_<ComponentIn, 0>
115 {
116 typedef double type;
117 };
118 template <>
119 struct ComponentMapper_<float, 0>
120 {
121 typedef float type;
122 };
123
124 template <class ComponentIn>
125 struct ComponentMapper
126 {
127 typedef typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type type;
128 };
129
130 //Mapping for Rgbish types
131 template <class ComponentIn>
132 struct ComponentMapper<Rgb<ComponentIn>>
133 {
134 typedef Rgb<typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type> type;
135 };
136
137 template <class ComponentIn>
138 struct ComponentMapper<Rgba<ComponentIn>>
139 {
140 typedef Rgba<typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type> type;
141 };
142
143 template <>
144 struct ComponentMapper<Rgb8>
145 {
146 typedef Rgb<byte> type;
147 };
148
149 class TIFFWritePimpl;
150
151 class tiff_writer
152 {
153 public:
154 tiff_writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<>>& p);
155 ~tiff_writer();
156
157 void write_raw_pixel_line(const bool*);
158 void write_raw_pixel_line(const unsigned char*);
159 void write_raw_pixel_line(const unsigned short*);
160 void write_raw_pixel_line(const float*);
161 void write_raw_pixel_line(const double*);
162
163 void write_raw_pixel_line(const Rgb<unsigned char>*);
164 void write_raw_pixel_line(const Rgb<unsigned short>*);
165 void write_raw_pixel_line(const Rgb<float>*);
166 void write_raw_pixel_line(const Rgb<double>*);
167
168 void write_raw_pixel_line(const Rgba<unsigned char>*);
169 void write_raw_pixel_line(const Rgba<unsigned short>*);
170 void write_raw_pixel_line(const Rgba<float>*);
171 void write_raw_pixel_line(const Rgba<double>*);
172
173 template <class Incoming>
174 struct Outgoing
175 {
176 typedef typename ComponentMapper<Incoming>::type type;
177 };
178
179 static const int top_row_first = 1;
180
181 private:
182 std::unique_ptr<TIFFWritePimpl> t;
183 };
184
185 }
186 }
187 #endif