Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / extension / toolbox / metafunctions / channel_view.hpp
1 //
2 // Copyright 2010 Fabien Castan, 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_TOOLBOX_CHANNEL_VIEW_HPP
9 #define BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP
10
11 #include <boost/gil/image_view_factory.hpp>
12
13 namespace boost {
14 namespace gil {
15
16 template <typename Channel, typename View>
17 struct channel_type_to_index
18 {
19     static constexpr int value = detail::type_to_index
20         <
21             typename color_space_type<View>::type, // color (Boost.MP11-compatible list)
22             Channel                                // channel type
23         >::value;                                  // index of the channel in the color (Boost.MP11-compatible list)
24 };
25
26 template<typename Channel, typename View>
27 struct channel_view_type : kth_channel_view_type
28     <
29         channel_type_to_index<Channel, View>::value,
30         View
31     >
32 {
33     static constexpr int index = channel_type_to_index
34         <
35             Channel,
36             View
37         >::value;
38
39     using parent_t = kth_channel_view_type<index, View>;
40     using type = typename parent_t::type;
41
42     static type make( const View& src )
43     {
44         return parent_t::make( src );
45     }
46 };
47
48 /// \ingroup ImageViewTransformationsKthChannel
49 template<typename Channel, typename View>
50 auto channel_view(View const& src)
51     -> typename channel_view_type<Channel, View>::type
52 {
53    return channel_view_type<Channel, View>::make(src);
54 }
55
56 }} // namespace boost::gil
57
58 #endif