1 // 2 // Copyright 2012 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_TOOLBOX_METAFUNCTIONS_CHANNEL_TYPE_HPP 9 #define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_CHANNEL_TYPE_HPP 10 11 #include <boost/gil/extension/toolbox/dynamic_images.hpp> 12 #include <boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp> 13 #include <boost/gil/extension/toolbox/metafunctions/is_homogeneous.hpp> 14 15 #include <boost/gil/bit_aligned_pixel_reference.hpp> 16 #include <boost/gil/channel.hpp> 17 #include <boost/gil/detail/mp11.hpp> 18 19 #include <boost/utility/enable_if.hpp> // boost::lazy_enable_if 20 21 namespace boost{ namespace gil { 22 23 /// channel_type metafunction 24 /// \brief Generates the channel type for 25 26 template <typename B, typename C, typename L, bool M> 27 struct gen_chan_ref 28 { 29 using type = packed_dynamic_channel_reference 30 < 31 B, 32 mp11::mp_at_c<C, 0>::value, 33 M 34 >; 35 }; 36 37 //! This implementation works for bit_algined_pixel_reference 38 //! with a homogeneous channel layout. 39 //! The result type will be a packed_dynamic_channel_reference, since the 40 //! offset info will be missing. 41 42 // bit_aligned_pixel_reference 43 template <typename B, typename C, typename L, bool M> 44 struct channel_type< bit_aligned_pixel_reference<B,C,L,M> > 45 : lazy_enable_if< is_homogeneous< bit_aligned_pixel_reference< B, C, L, M > > 46 , gen_chan_ref< B, C, L, M > 47 > {}; 48 49 template <typename B, typename C, typename L, bool M> 50 struct channel_type<const bit_aligned_pixel_reference<B,C,L,M> > 51 : lazy_enable_if< is_homogeneous< bit_aligned_pixel_reference< B, C, L, M > > 52 , gen_chan_ref< B, C, L, M > 53 > {}; 54 55 template <typename B, typename C, typename L> 56 struct gen_chan_ref_p 57 { 58 using type = packed_dynamic_channel_reference 59 < 60 B, 61 get_num_bits<mp11::mp_at_c<C, 0>>::value, 62 true 63 >; 64 }; 65 66 // packed_pixel 67 template < typename BitField 68 , typename ChannelRefs 69 , typename Layout 70 > 71 struct channel_type< packed_pixel< BitField 72 , ChannelRefs 73 , Layout 74 > 75 > : lazy_enable_if< is_homogeneous< packed_pixel< BitField 76 , ChannelRefs 77 , Layout 78 > 79 > 80 , gen_chan_ref_p< BitField 81 , ChannelRefs 82 , Layout 83 > 84 > {}; 85 86 template <typename B, typename C, typename L> 87 struct channel_type< const packed_pixel< B, C, L > > 88 : lazy_enable_if< is_homogeneous<packed_pixel< B, C, L > > 89 , gen_chan_ref_p< B, C, L > 90 > 91 {}; 92 93 template<> 94 struct channel_type< any_image_pixel_t > 95 { 96 using type = any_image_channel_t; 97 }; 98 99 } // namespace gil 100 } // namespace boost 101 102 #endif 103