channel_type.hpp 3.3 KB

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