1 // 2 // Copyright 2008 Christian Henning 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_PNM_DETAIL_SUPPORTED_TYPES_HPP 9 #define BOOST_GIL_EXTENSION_IO_PNM_DETAIL_SUPPORTED_TYPES_HPP 10 11 #include <boost/gil/extension/io/pnm/tags.hpp> 12 13 #include <boost/gil/channel.hpp> 14 #include <boost/gil/color_base.hpp> 15 #include <boost/gil/io/base.hpp> 16 17 #include <type_traits> 18 19 namespace boost { namespace gil { namespace detail { 20 21 // Read Support 22 23 template< pnm_image_type::type ASCII_Type 24 , pnm_image_type::type Binary_Type 25 > 26 struct pnm_rw_support_base 27 { 28 static const pnm_image_type::type _asc_type = ASCII_Type; 29 static const pnm_image_type::type _bin_type = Binary_Type; 30 }; 31 32 template< typename Channel 33 , typename ColorSpace 34 > 35 struct pnm_read_support : read_support_false 36 , pnm_rw_support_base< 0 37 , 0 38 > {}; 39 40 template< typename BitField, bool Mutable > 41 struct pnm_read_support< packed_dynamic_channel_reference< BitField 42 , 1 43 , Mutable 44 > 45 , gray_t 46 > : read_support_true 47 , pnm_rw_support_base< pnm_image_type::mono_asc_t::value 48 , pnm_image_type::mono_bin_t::value 49 > {}; 50 51 template<> 52 struct pnm_read_support<uint8_t 53 , gray_t 54 > : read_support_true 55 , pnm_rw_support_base< pnm_image_type::gray_asc_t::value 56 , pnm_image_type::gray_bin_t::value 57 > {}; 58 59 60 template<> 61 struct pnm_read_support<uint8_t 62 , rgb_t 63 > : read_support_true 64 , pnm_rw_support_base< pnm_image_type::color_asc_t::value 65 , pnm_image_type::color_bin_t::value 66 > {}; 67 68 // Write support 69 70 template< typename Channel 71 , typename ColorSpace 72 > 73 struct pnm_write_support : write_support_false 74 {}; 75 76 template< typename BitField, bool Mutable > 77 struct pnm_write_support< packed_dynamic_channel_reference< BitField 78 , 1 79 , Mutable 80 > 81 , gray_t 82 > : write_support_true 83 , pnm_rw_support_base< pnm_image_type::mono_asc_t::value 84 , pnm_image_type::mono_bin_t::value 85 > {}; 86 87 88 template<> 89 struct pnm_write_support<uint8_t 90 , gray_t 91 > : write_support_true 92 , pnm_rw_support_base< pnm_image_type::gray_asc_t::value 93 , pnm_image_type::gray_bin_t::value 94 > {}; 95 96 97 template<> 98 struct pnm_write_support<uint8_t 99 , rgb_t 100 > : write_support_true 101 , pnm_rw_support_base< pnm_image_type::color_asc_t::value 102 , pnm_image_type::color_bin_t::value 103 > {}; 104 105 } // namespace detail 106 107 template<typename Pixel> 108 struct is_read_supported<Pixel, pnm_tag> 109 : std::integral_constant 110 < 111 bool, 112 detail::pnm_read_support 113 < 114 typename channel_type<Pixel>::type, 115 typename color_space_type<Pixel>::type 116 >::is_supported 117 > 118 { 119 using parent_t = detail::pnm_read_support 120 < 121 typename channel_type<Pixel>::type, 122 typename color_space_type<Pixel>::type 123 >; 124 125 static const pnm_image_type::type _asc_type = parent_t::_asc_type; 126 static const pnm_image_type::type _bin_type = parent_t::_bin_type; 127 }; 128 129 template<typename Pixel> 130 struct is_write_supported<Pixel, pnm_tag> 131 : std::integral_constant 132 < 133 bool, 134 detail::pnm_write_support 135 < 136 typename channel_type<Pixel>::type, 137 typename color_space_type<Pixel>::type 138 >::is_supported 139 > 140 {}; 141 142 } // namespace gil 143 } // namespace boost 144 145 #endif 146