channel_view.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <boost/gil/image_view_factory.hpp>
  11. namespace boost {
  12. namespace gil {
  13. template <typename Channel, typename View>
  14. struct channel_type_to_index
  15. {
  16. static constexpr int value = detail::type_to_index
  17. <
  18. typename color_space_type<View>::type, // color (Boost.MP11-compatible list)
  19. Channel // channel type
  20. >::value; // index of the channel in the color (Boost.MP11-compatible list)
  21. };
  22. template<typename Channel, typename View>
  23. struct channel_view_type : kth_channel_view_type
  24. <
  25. channel_type_to_index<Channel, View>::value,
  26. View
  27. >
  28. {
  29. static constexpr int index = channel_type_to_index
  30. <
  31. Channel,
  32. View
  33. >::value;
  34. using parent_t = kth_channel_view_type<index, View>;
  35. using type = typename parent_t::type;
  36. static type make( const View& src )
  37. {
  38. return parent_t::make( src );
  39. }
  40. };
  41. /// \ingroup ImageViewTransformationsKthChannel
  42. template<typename Channel, typename View>
  43. auto channel_view(View const& src)
  44. -> typename channel_view_type<Channel, View>::type
  45. {
  46. return channel_view_type<Channel, View>::make(src);
  47. }
  48. }} // namespace boost::gil
  49. #endif