]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/gil/extension/io/png/detail/supported_types.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / gil / extension / io / png / detail / supported_types.hpp
1 //
2 // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 #ifndef BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
9 #define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
10
11 #include <boost/gil/extension/io/png/tags.hpp>
12
13 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
14 #include <boost/gil/extension/toolbox/color_spaces/gray_alpha.hpp>
15 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
16
17 #include <cstddef>
18 #include <type_traits>
19
20 namespace boost { namespace gil { namespace detail {
21
22 static const size_t PNG_BYTES_TO_CHECK = 4;
23
24 // Read support
25 template< png_bitdepth::type BitDepth
26 , png_color_type::type ColorType
27 >
28 struct png_rw_support_base
29 {
30 static const png_bitdepth::type _bit_depth = BitDepth;
31 static const png_color_type::type _color_type = ColorType;
32 };
33
34 template< typename Channel
35 , typename ColorSpace
36 >
37 struct png_read_support : read_support_false
38 , png_rw_support_base< 1
39 , PNG_COLOR_TYPE_GRAY
40 > {};
41
42 template< typename BitField
43 , bool Mutable
44 >
45 struct png_read_support< packed_dynamic_channel_reference< BitField
46 , 1
47 , Mutable
48 >
49 , gray_t
50 > : read_support_true
51 , png_rw_support_base< 1
52 , PNG_COLOR_TYPE_GRAY
53 > {};
54
55 template< typename BitField
56 , bool Mutable
57 >
58 struct png_read_support< packed_dynamic_channel_reference< BitField
59 , 2
60 , Mutable
61 >
62 , gray_t
63 > : read_support_true
64 , png_rw_support_base< 2
65 , PNG_COLOR_TYPE_GRAY
66 > {};
67
68 template< typename BitField
69 , bool Mutable
70 >
71 struct png_read_support< packed_dynamic_channel_reference< BitField
72 , 4
73 , Mutable
74 >
75 , gray_t
76 > : read_support_true
77 , png_rw_support_base< 4
78 , PNG_COLOR_TYPE_GRAY
79 > {};
80
81 template<>
82 struct png_read_support<uint8_t
83 , gray_t
84 > : read_support_true
85 , png_rw_support_base< 8
86 , PNG_COLOR_TYPE_GRAY
87 > {};
88
89 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
90 template<>
91 struct png_read_support<uint8_t
92 , gray_alpha_t
93 > : read_support_true
94 , png_rw_support_base< 8
95 , PNG_COLOR_TYPE_GA
96 > {};
97 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
98
99 template<>
100 struct png_read_support<uint8_t
101 , rgb_t
102 > : read_support_true
103 , png_rw_support_base< 8
104 , PNG_COLOR_TYPE_RGB
105 > {};
106
107 template<>
108 struct png_read_support<uint8_t
109 , rgba_t
110 > : read_support_true
111 , png_rw_support_base< 8
112 , PNG_COLOR_TYPE_RGBA
113 > {};
114
115 template<>
116 struct png_read_support<uint16_t
117 , gray_t
118 > : read_support_true
119 , png_rw_support_base< 16
120 , PNG_COLOR_TYPE_GRAY
121 > {};
122
123 template<>
124 struct png_read_support<uint16_t
125 , rgb_t
126 > : read_support_true
127 , png_rw_support_base< 16
128 , PNG_COLOR_TYPE_RGB
129 > {};
130
131 template<>
132 struct png_read_support<uint16_t
133 , rgba_t
134 > : read_support_true
135 , png_rw_support_base< 16
136 , PNG_COLOR_TYPE_RGBA
137 > {};
138
139 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
140 template<>
141 struct png_read_support<uint16_t
142 , gray_alpha_t
143 > : read_support_true
144 , png_rw_support_base< 16
145 , PNG_COLOR_TYPE_GA
146 > {};
147 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
148
149 // Write support
150
151 template< typename Channel
152 , typename ColorSpace
153 >
154 struct png_write_support : write_support_false
155 , png_rw_support_base< 1
156 , PNG_COLOR_TYPE_GRAY
157 > {};
158
159 template< typename BitField
160 , bool Mutable
161 >
162 struct png_write_support< packed_dynamic_channel_reference< BitField
163 , 1
164 , Mutable
165 >
166 , gray_t
167 > : write_support_true
168 , png_rw_support_base< 1
169 , PNG_COLOR_TYPE_GRAY
170 >
171 {};
172
173 template< typename BitField
174 , bool Mutable
175 >
176 struct png_write_support< packed_dynamic_channel_reference< BitField
177 , 1
178 , Mutable
179 > const
180 , gray_t
181 > : write_support_true
182 , png_rw_support_base< 1
183 , PNG_COLOR_TYPE_GRAY
184 >
185 {};
186
187 template< typename BitField
188 , bool Mutable
189 >
190 struct png_write_support< packed_dynamic_channel_reference< BitField
191 , 2
192 , Mutable
193 >
194 , gray_t
195 > : write_support_true
196 , png_rw_support_base< 2
197 , PNG_COLOR_TYPE_GRAY
198 >
199 {};
200
201 template< typename BitField
202 , bool Mutable
203 >
204 struct png_write_support< packed_dynamic_channel_reference< BitField
205 , 2
206 , Mutable
207 > const
208 , gray_t
209 > : write_support_true
210 , png_rw_support_base< 2
211 , PNG_COLOR_TYPE_GRAY
212 >
213 {};
214
215 template< typename BitField
216 , bool Mutable
217 >
218 struct png_write_support< packed_dynamic_channel_reference< BitField
219 , 4
220 , Mutable
221 >
222 , gray_t
223 > : write_support_true
224 , png_rw_support_base< 4
225 , PNG_COLOR_TYPE_GRAY
226 >
227 {};
228
229 template< typename BitField
230 , bool Mutable
231 >
232 struct png_write_support< packed_dynamic_channel_reference< BitField
233 , 4
234 , Mutable
235 > const
236 , gray_t
237 > : write_support_true
238 , png_rw_support_base< 4
239 , PNG_COLOR_TYPE_GRAY
240 >
241 {};
242
243 template<>
244 struct png_write_support<uint8_t
245 , gray_t
246 > : write_support_true
247 , png_rw_support_base< 8
248 , PNG_COLOR_TYPE_GRAY
249 >
250 {};
251
252 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
253 template<>
254 struct png_write_support<uint8_t
255 , gray_alpha_t
256 > : write_support_true
257 , png_rw_support_base< 8
258 , PNG_COLOR_TYPE_GA
259 >
260 {};
261 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
262
263 template<>
264 struct png_write_support<uint8_t
265 , rgb_t
266 > : write_support_true
267 , png_rw_support_base< 8
268 , PNG_COLOR_TYPE_RGB
269 >
270 {};
271
272 template<>
273 struct png_write_support<uint8_t
274 , rgba_t
275 > : write_support_true
276 , png_rw_support_base< 8
277 , PNG_COLOR_TYPE_RGBA
278 >
279 {};
280
281 template<>
282 struct png_write_support<uint16_t
283 , gray_t
284 > : write_support_true
285 , png_rw_support_base< 16
286 , PNG_COLOR_TYPE_GRAY
287 >
288 {};
289
290 template<>
291 struct png_write_support<uint16_t
292 , rgb_t
293 > : write_support_true
294 , png_rw_support_base< 16
295 , PNG_COLOR_TYPE_RGB
296 >
297 {};
298
299 template<>
300 struct png_write_support<uint16_t
301 , rgba_t
302 > : write_support_true
303 , png_rw_support_base< 16
304 , PNG_COLOR_TYPE_RGBA
305 >
306 {};
307
308 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
309 template<>
310 struct png_write_support<uint16_t
311 , gray_alpha_t
312 > : write_support_true
313 , png_rw_support_base< 16
314 , PNG_COLOR_TYPE_GA
315 >
316 {};
317 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
318
319
320 } // namespace detail
321
322 template<typename Pixel>
323 struct is_read_supported<Pixel, png_tag>
324 : std::integral_constant
325 <
326 bool,
327 detail::png_read_support
328 <
329 typename channel_type<Pixel>::type,
330 typename color_space_type<Pixel>::type
331 >::is_supported
332 >
333 {
334 using parent_t = detail::png_read_support
335 <
336 typename channel_type<Pixel>::type,
337 typename color_space_type<Pixel>::type
338 >;
339
340 static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
341 static const png_color_type::type _color_type = parent_t::_color_type;
342 };
343
344 template<typename Pixel>
345 struct is_write_supported<Pixel, png_tag>
346 : std::integral_constant
347 <
348 bool,
349 detail::png_write_support
350 <
351 typename channel_type<Pixel>::type,
352 typename color_space_type<Pixel>::type
353 >::is_supported
354 >
355 {
356 using parent_t = detail::png_write_support
357 <
358 typename channel_type<Pixel>::type,
359 typename color_space_type<Pixel>::type
360 >;
361
362 static const png_bitdepth::type _bit_depth = parent_t::_bit_depth;
363 static const png_color_type::type _color_type = parent_t::_color_type;
364 };
365
366 } // namespace gil
367 } // namespace boost
368
369 #endif