is_homogeneous.hpp 3.5 KB

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