2 // Copyright 2007-2008 Christian Henning, Andreas Pokorny, Lubomir Bourdev
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
8 #ifndef BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
9 #define BOOST_GIL_EXTENSION_IO_PNG_DETAIL_SUPPORTED_TYPES_HPP
11 #include <boost/gil/extension/io/png/tags.hpp>
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
18 #include <type_traits>
20 namespace boost { namespace gil { namespace detail {
22 static const size_t PNG_BYTES_TO_CHECK = 4;
25 template< png_bitdepth::type BitDepth
26 , png_color_type::type ColorType
28 struct png_rw_support_base
30 static const png_bitdepth::type _bit_depth = BitDepth;
31 static const png_color_type::type _color_type = ColorType;
34 template< typename Channel
37 struct png_read_support : read_support_false
38 , png_rw_support_base< 1
42 template< typename BitField
45 struct png_read_support< packed_dynamic_channel_reference< BitField
51 , png_rw_support_base< 1
55 template< typename BitField
58 struct png_read_support< packed_dynamic_channel_reference< BitField
64 , png_rw_support_base< 2
68 template< typename BitField
71 struct png_read_support< packed_dynamic_channel_reference< BitField
77 , png_rw_support_base< 4
82 struct png_read_support<uint8_t
85 , png_rw_support_base< 8
89 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
91 struct png_read_support<uint8_t
94 , png_rw_support_base< 8
97 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
100 struct png_read_support<uint8_t
102 > : read_support_true
103 , png_rw_support_base< 8
108 struct png_read_support<uint8_t
110 > : read_support_true
111 , png_rw_support_base< 8
112 , PNG_COLOR_TYPE_RGBA
116 struct png_read_support<uint16_t
118 > : read_support_true
119 , png_rw_support_base< 16
120 , PNG_COLOR_TYPE_GRAY
124 struct png_read_support<uint16_t
126 > : read_support_true
127 , png_rw_support_base< 16
132 struct png_read_support<uint16_t
134 > : read_support_true
135 , png_rw_support_base< 16
136 , PNG_COLOR_TYPE_RGBA
139 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
141 struct png_read_support<uint16_t
143 > : read_support_true
144 , png_rw_support_base< 16
147 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
151 template< typename Channel
152 , typename ColorSpace
154 struct png_write_support : write_support_false
155 , png_rw_support_base< 1
156 , PNG_COLOR_TYPE_GRAY
159 template< typename BitField
162 struct png_write_support< packed_dynamic_channel_reference< BitField
167 > : write_support_true
168 , png_rw_support_base< 1
169 , PNG_COLOR_TYPE_GRAY
173 template< typename BitField
176 struct png_write_support< packed_dynamic_channel_reference< BitField
181 > : write_support_true
182 , png_rw_support_base< 1
183 , PNG_COLOR_TYPE_GRAY
187 template< typename BitField
190 struct png_write_support< packed_dynamic_channel_reference< BitField
195 > : write_support_true
196 , png_rw_support_base< 2
197 , PNG_COLOR_TYPE_GRAY
201 template< typename BitField
204 struct png_write_support< packed_dynamic_channel_reference< BitField
209 > : write_support_true
210 , png_rw_support_base< 2
211 , PNG_COLOR_TYPE_GRAY
215 template< typename BitField
218 struct png_write_support< packed_dynamic_channel_reference< BitField
223 > : write_support_true
224 , png_rw_support_base< 4
225 , PNG_COLOR_TYPE_GRAY
229 template< typename BitField
232 struct png_write_support< packed_dynamic_channel_reference< BitField
237 > : write_support_true
238 , png_rw_support_base< 4
239 , PNG_COLOR_TYPE_GRAY
244 struct png_write_support<uint8_t
246 > : write_support_true
247 , png_rw_support_base< 8
248 , PNG_COLOR_TYPE_GRAY
252 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
254 struct png_write_support<uint8_t
256 > : write_support_true
257 , png_rw_support_base< 8
261 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
264 struct png_write_support<uint8_t
266 > : write_support_true
267 , png_rw_support_base< 8
273 struct png_write_support<uint8_t
275 > : write_support_true
276 , png_rw_support_base< 8
277 , PNG_COLOR_TYPE_RGBA
282 struct png_write_support<uint16_t
284 > : write_support_true
285 , png_rw_support_base< 16
286 , PNG_COLOR_TYPE_GRAY
291 struct png_write_support<uint16_t
293 > : write_support_true
294 , png_rw_support_base< 16
300 struct png_write_support<uint16_t
302 > : write_support_true
303 , png_rw_support_base< 16
304 , PNG_COLOR_TYPE_RGBA
308 #ifdef BOOST_GIL_IO_ENABLE_GRAY_ALPHA
310 struct png_write_support<uint16_t
312 > : write_support_true
313 , png_rw_support_base< 16
317 #endif // BOOST_GIL_IO_ENABLE_GRAY_ALPHA
320 } // namespace detail
322 template<typename Pixel>
323 struct is_read_supported<Pixel, png_tag>
324 : std::integral_constant
327 detail::png_read_support
329 typename channel_type<Pixel>::type,
330 typename color_space_type<Pixel>::type
334 using parent_t = detail::png_read_support
336 typename channel_type<Pixel>::type,
337 typename color_space_type<Pixel>::type
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;
344 template<typename Pixel>
345 struct is_write_supported<Pixel, png_tag>
346 : std::integral_constant
349 detail::png_write_support
351 typename channel_type<Pixel>::type,
352 typename color_space_type<Pixel>::type
356 using parent_t = detail::png_write_support
358 typename channel_type<Pixel>::type,
359 typename color_space_type<Pixel>::type
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;