channel_view.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. Copyright 2010 Fabien Castan, Christian Henning
  3. Use, modification and distribution are subject to the Boost Software License,
  4. Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. */
  7. /*************************************************************************************************/
  8. #ifndef BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED
  9. #define BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED
  10. ////////////////////////////////////////////////////////////////////////////////////////
  11. /// \file channel_view.hpp
  12. /// \brief Helper to generate channel_view type.
  13. /// \author Fabien Castan, Christian Henning \n
  14. ///
  15. /// \date 2010 \n
  16. ///
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <boost/gil/image_view_factory.hpp>
  19. namespace boost {
  20. namespace gil {
  21. template < typename Channel
  22. , typename View
  23. >
  24. struct channel_type_to_index
  25. {
  26. static const int value = detail::type_to_index< typename color_space_type< View >::type // color (mpl::vector)
  27. , Channel // channel type
  28. >::type::value; //< index of the channel in the color (mpl::vector)
  29. };
  30. template< typename Channel
  31. , typename View
  32. >
  33. struct channel_view_type : public kth_channel_view_type< channel_type_to_index< Channel
  34. , View
  35. >::value
  36. , View
  37. >
  38. {
  39. static const int index = channel_type_to_index< Channel
  40. , View
  41. >::value;
  42. typedef kth_channel_view_type< index
  43. , View
  44. > parent_t;
  45. typedef typename parent_t::type type;
  46. static type make( const View& src )
  47. {
  48. return parent_t::make( src );
  49. }
  50. };
  51. /// \ingroup ImageViewTransformationsKthChannel
  52. template< typename Channel
  53. , typename View
  54. >
  55. typename channel_view_type< Channel
  56. , View
  57. >::type channel_view( const View& src )
  58. {
  59. return channel_view_type< Channel
  60. , View
  61. >::make( src );
  62. }
  63. } // namespace gil
  64. } // namespace boost
  65. #endif // BOOST_GIL_EXTENSION_TOOLBOX_CHANNEL_VIEW_HPP_INCLUDED