Debian Codegraph @

cvd/internal/io/fits.h

raw symbols SCIP
1 #ifndef CVD_INCLUDE_INTERNAL_IO_FITS_H
2 #define CVD_INCLUDE_INTERNAL_IO_FITS_H
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 FITS
14 {
15
16 using CVD::Internal::Head;
17 using CVD::Internal::TypeList;
18
19 //Probably not the best way to deal with FITS. Data is unlikely to be RGBA, for
20 //instance. Maybe it would be best to implement loading of tr1::array and Vector.
21
22 ////////////////////////////////////////////////////////////////////////////////
23 //
24 // FITS reading
25 //
26
27 class ReadPimpl;
28 class Reader
29 {
30 public:
31 Reader(std::istream&);
32 ~Reader();
33
34 ImageRef size();
35 bool top_row_first();
36
37 void get_raw_pixel_line(unsigned char*);
38 void get_raw_pixel_line(signed short*);
39 void get_raw_pixel_line(unsigned short*);
40 void get_raw_pixel_line(signed int*);
41 void get_raw_pixel_line(float*);
42 void get_raw_pixel_line(double*);
43
44 void get_raw_pixel_line(Rgb<unsigned char>*);
45 void get_raw_pixel_line(Rgb<signed short>*);
46 void get_raw_pixel_line(Rgb<unsigned short>*);
47 void get_raw_pixel_line(Rgb<signed int>*);
48 void get_raw_pixel_line(Rgb<float>*);
49 void get_raw_pixel_line(Rgb<double>*);
50
51 void get_raw_pixel_line(Rgba<unsigned char>*);
52 void get_raw_pixel_line(Rgba<signed short>*);
53 void get_raw_pixel_line(Rgba<unsigned short>*);
54 void get_raw_pixel_line(Rgba<signed int>*);
55 void get_raw_pixel_line(Rgba<float>*);
56 void get_raw_pixel_line(Rgba<double>*);
57
58 std::string datatype();
59 std::string name();
60
61 typedef TypeList<byte,
62 TypeList<signed short,
63 TypeList<unsigned short,
64 TypeList<signed int,
65 TypeList<float,
66 TypeList<double,
67 TypeList<Rgb<byte>,
68 TypeList<Rgb<signed short>,
69 TypeList<Rgb<unsigned short>,
70 TypeList<Rgb<signed int>,
71 TypeList<Rgb<float>,
72 TypeList<Rgb<double>,
73 TypeList<Rgba<byte>,
74 TypeList<Rgba<signed short>,
75 TypeList<Rgba<unsigned short>,
76 TypeList<Rgba<signed int>,
77 TypeList<Rgba<float>,
78 TypeList<Rgba<double>,
79 Head>>>>>>>>>>>>>>>>>>
80 Types;
81
82 static bool first_byte_matches(const int b)
83 {
84 return b == 'S';
85 }
86
87 private:
88 std::unique_ptr<ReadPimpl> t;
89 };
90
91 ////////////////////////////////////////////////////////////////////////////////
92 //
93 // FITS writing, copied and modified from tiff.h
94 //
95
96 template <typename C>
97 struct IntMapper
98 {
99 typedef int type;
100 };
101 template <>
102 struct IntMapper<bool>
103 {
104 typedef unsigned char type;
105 };
106 template <>
107 struct IntMapper<char>
108 {
109 typedef short type;
110 };
111 template <>
112 struct IntMapper<unsigned char>
113 {
114 typedef unsigned char type;
115 };
116 template <>
117 struct IntMapper<short>
118 {
119 typedef short type;
120 };
121 template <>
122 struct IntMapper<unsigned short>
123 {
124 typedef unsigned short type;
125 };
126 template <>
127 struct IntMapper<int>
128 {
129 typedef int type;
130 };
131
132 //Mapping for integral types
133 template <class ComponentIn, int is_integral>
134 struct ComponentMapper_
135 {
136 typedef typename IntMapper<ComponentIn>::type type;
137 };
138
139 //Mapping for non integral types
140 template <class ComponentIn>
141 struct ComponentMapper_<ComponentIn, 0>
142 {
143 typedef double type;
144 };
145 template <>
146 struct ComponentMapper_<float, 0>
147 {
148 typedef float type;
149 };
150
151 template <class ComponentIn>
152 struct ComponentMapper
153 {
154 typedef typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type type;
155 };
156
157 //Mapping for Rgbish types
158 template <class ComponentIn>
159 struct ComponentMapper<Rgb<ComponentIn>>
160 {
161 typedef Rgb<typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type> type;
162 };
163
164 template <class ComponentIn>
165 struct ComponentMapper<Rgba<ComponentIn>>
166 {
167 typedef Rgba<typename ComponentMapper_<ComponentIn, Pixel::traits<ComponentIn>::integral>::type> type;
168 };
169
170 template <>
171 struct ComponentMapper<Rgb8>
172 {
173 typedef Rgb<byte> type;
174 };
175
176 class WritePimpl;
177
178 class writer
179 {
180 public:
181 writer(std::ostream&, ImageRef size, const std::string& type, const std::map<std::string, Parameter<>>& p);
182 ~writer();
183
184 void write_raw_pixel_line(const unsigned char*);
185 void write_raw_pixel_line(const short*);
186 void write_raw_pixel_line(const unsigned short*);
187 void write_raw_pixel_line(const int*);
188 void write_raw_pixel_line(const float*);
189 void write_raw_pixel_line(const double*);
190
191 void write_raw_pixel_line(const Rgb<unsigned char>*);
192 void write_raw_pixel_line(const Rgb<short>*);
193 void write_raw_pixel_line(const Rgb<unsigned short>*);
194 void write_raw_pixel_line(const Rgb<int>*);
195 void write_raw_pixel_line(const Rgb<float>*);
196 void write_raw_pixel_line(const Rgb<double>*);
197
198 void write_raw_pixel_line(const Rgba<unsigned char>*);
199 void write_raw_pixel_line(const Rgba<short>*);
200 void write_raw_pixel_line(const Rgba<unsigned short>*);
201 void write_raw_pixel_line(const Rgba<int>*);
202 void write_raw_pixel_line(const Rgba<float>*);
203 void write_raw_pixel_line(const Rgba<double>*);
204
205 template <class Incoming>
206 struct Outgoing
207 {
208 typedef typename ComponentMapper<Incoming>::type type;
209 };
210
211 static const int top_row_first = 1;
212
213 private:
214 WritePimpl* t;
215 };
216
217 }
218 }
219 #endif