is_homogeneous.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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_IS_HOMOGENEOUS_HPP
  9. #define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_IS_HOMOGENEOUS_HPP
  10. #include <boost/gil/pixel.hpp>
  11. #include <boost/mpl/and.hpp>
  12. #include <boost/mpl/at.hpp>
  13. namespace boost{ namespace gil {
  14. /// is_homogeneous metafunctions
  15. /// \brief Determines if a pixel types are homogeneous.
  16. template<typename C,typename CMP, int Next, int Last> struct is_homogeneous_impl;
  17. template<typename C,typename CMP, int Last>
  18. struct is_homogeneous_impl<C,CMP,Last,Last> : mpl::true_{};
  19. template<typename C,typename CMP, int Next, int Last>
  20. struct is_homogeneous_impl : mpl::and_< is_homogeneous_impl< C, CMP,Next + 1, Last >
  21. , is_same< CMP, typename mpl::at_c<C,Next>::type
  22. > > {};
  23. template < typename P > struct is_homogeneous : mpl::false_ {};
  24. // pixel
  25. template < typename C, typename L > struct is_homogeneous< pixel<C,L> > : mpl::true_ {};
  26. template < typename C, typename L > struct is_homogeneous<const pixel<C,L> > : mpl::true_ {};
  27. template < typename C, typename L > struct is_homogeneous< pixel<C,L>& > : mpl::true_ {};
  28. template < typename C, typename L > struct is_homogeneous<const pixel<C,L>& > : mpl::true_ {};
  29. // planar pixel reference
  30. template <typename Channel, typename ColorSpace>
  31. struct is_homogeneous< planar_pixel_reference< Channel, ColorSpace > > : mpl::true_ {};
  32. template <typename Channel, typename ColorSpace>
  33. struct is_homogeneous< const planar_pixel_reference< Channel, ColorSpace > > : mpl::true_ {};
  34. template<typename C,typename CMP, int I,int Last>
  35. struct is_homogeneous_impl_p {};
  36. // for packed_pixel
  37. template <typename B, typename C, typename L >
  38. struct is_homogeneous<packed_pixel< B, C, L > >
  39. : is_homogeneous_impl_p< C
  40. , typename mpl::at_c< C, 0 >::type
  41. , 1
  42. , mpl::size< C >::value
  43. > {};
  44. template< typename B
  45. , typename C
  46. , typename L
  47. >
  48. struct is_homogeneous< const packed_pixel< B, C, L > >
  49. : is_homogeneous_impl_p< C
  50. , typename mpl::at_c<C,0>::type
  51. , 1
  52. , mpl::size< C >::value
  53. > {};
  54. // for bit_aligned_pixel_reference
  55. template <typename B, typename C, typename L, bool M>
  56. struct is_homogeneous<bit_aligned_pixel_reference<B,C,L,M> >
  57. : is_homogeneous_impl<C,typename mpl::at_c<C,0>::type,1,mpl::size<C>::value>
  58. {};
  59. template <typename B, typename C, typename L, bool M>
  60. struct is_homogeneous<const bit_aligned_pixel_reference<B,C,L,M> >
  61. : is_homogeneous_impl<C,typename mpl::at_c<C,0>::type,1,mpl::size<C>::value>
  62. {};
  63. } // namespace gil
  64. } // namespace boost
  65. #endif