device_n.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. Copyright 2005-2007 Adobe Systems Incorporated
  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. See http://stlab.adobe.com/gil for most recent version including documentation.
  7. */
  8. /*************************************************************************************************/
  9. #ifndef GIL_DEVICE_N_H
  10. #define GIL_DEVICE_N_H
  11. ////////////////////////////////////////////////////////////////////////////////////////
  12. /// \file
  13. /// \brief Support for color space of N channels and variants
  14. /// \author Lubomir Bourdev and Hailin Jin \n
  15. /// Adobe Systems Incorporated
  16. /// \date 2005-2009 \n Last updated on February 20, 2009
  17. ////////////////////////////////////////////////////////////////////////////////////////
  18. #include <cstddef>
  19. #include <boost/type_traits.hpp>
  20. #include <boost/config.hpp>
  21. #include <boost/mpl/range_c.hpp>
  22. #include <boost/mpl/vector_c.hpp>
  23. #include "gil_config.hpp"
  24. #include "utilities.hpp"
  25. #include "metafunctions.hpp"
  26. namespace boost { namespace gil {
  27. /// \brief unnamed color
  28. /// \ingroup ColorNameModel
  29. template <int N> struct devicen_color_t {};
  30. template <int N> struct devicen_t;
  31. /// \brief unnamed color space of one channel
  32. /// \ingroup ColorSpaceModel
  33. template <> struct devicen_t<1> : public mpl::vector1<devicen_color_t<0> > {};
  34. /// \brief unnamed color space of two channels
  35. /// \ingroup ColorSpaceModel
  36. template <> struct devicen_t<2> : public mpl::vector2<devicen_color_t<0>, devicen_color_t<1> > {};
  37. /// \brief unnamed color space of three channels
  38. /// \ingroup ColorSpaceModel
  39. template <> struct devicen_t<3> : public mpl::vector3<devicen_color_t<0>, devicen_color_t<1>, devicen_color_t<2> > {};
  40. /// \brief unnamed color space of four channels
  41. /// \ingroup ColorSpaceModel
  42. template <> struct devicen_t<4> : public mpl::vector4<devicen_color_t<0>, devicen_color_t<1>, devicen_color_t<2>, devicen_color_t<3> > {};
  43. /// \brief unnamed color space of five channels
  44. /// \ingroup ColorSpaceModel
  45. template <> struct devicen_t<5> : public mpl::vector5<devicen_color_t<0>, devicen_color_t<1>, devicen_color_t<2>, devicen_color_t<3>, devicen_color_t<4> > {};
  46. /// \brief unnamed color layout of up to five channels
  47. /// \ingroup LayoutModel
  48. template <int N> struct devicen_layout_t : public layout<devicen_t<N> > {};
  49. /// \ingroup ImageViewConstructors
  50. /// \brief from 2-channel planar data
  51. template <typename IC>
  52. inline typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2> > >::view_t
  53. planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, std::ptrdiff_t rowsize_in_bytes) {
  54. typedef typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2> > >::view_t view_t;
  55. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1), rowsize_in_bytes));
  56. }
  57. /// \ingroup ImageViewConstructors
  58. /// \brief from 3-channel planar data
  59. template <typename IC>
  60. inline typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3> > >::view_t
  61. planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, IC c2, std::ptrdiff_t rowsize_in_bytes) {
  62. typedef typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3> > >::view_t view_t;
  63. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2), rowsize_in_bytes));
  64. }
  65. /// \ingroup ImageViewConstructors
  66. /// \brief from 4-channel planar data
  67. template <typename IC>
  68. inline typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4> > >::view_t
  69. planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, IC c2, IC c3, std::ptrdiff_t rowsize_in_bytes) {
  70. typedef typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4> > >::view_t view_t;
  71. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3), rowsize_in_bytes));
  72. }
  73. /// \ingroup ImageViewConstructors
  74. /// \brief from 5-channel planar data
  75. template <typename IC>
  76. inline typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5> > >::view_t
  77. planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, IC c2, IC c3, IC c4, std::ptrdiff_t rowsize_in_bytes) {
  78. typedef typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5> > >::view_t view_t;
  79. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3,c4), rowsize_in_bytes));
  80. }
  81. } } // namespace boost::gil
  82. #endif