device_n.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // Copyright 2005-2007 Adobe Systems Incorporated
  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_DEVICE_N_HPP
  9. #define BOOST_GIL_DEVICE_N_HPP
  10. #include <boost/gil/metafunctions.hpp>
  11. #include <boost/gil/utilities.hpp>
  12. #include <boost/gil/detail/mp11.hpp>
  13. #include <boost/config.hpp>
  14. #include <cstddef>
  15. #include <type_traits>
  16. namespace boost { namespace gil {
  17. // TODO: Document the DeviceN Color Space and Color Model
  18. // with reference to the Adobe documentation
  19. // https://www.adobe.com/content/dam/acom/en/devnet/postscript/pdfs/TN5604.DeviceN_Color.pdf
  20. /// \brief unnamed color
  21. /// \ingroup ColorNameModel
  22. template <int N>
  23. struct devicen_color_t {};
  24. template <int N>
  25. struct devicen_t;
  26. /// \brief Unnamed color space of 1, 2, 3, 4, or 5 channels
  27. /// \tparam N Number of color components (1, 2, 3, 4 or 5).
  28. /// \ingroup ColorSpaceModel
  29. template <int N>
  30. struct devicen_t
  31. {
  32. private:
  33. template <typename T>
  34. using color_t = devicen_color_t<T::value>;
  35. static_assert(
  36. (1 <= N && N <= 5),
  37. "invalid number of DeviceN color components");
  38. public:
  39. using type = mp11::mp_transform<color_t, mp11::mp_iota_c<N>>;
  40. };
  41. /// \brief unnamed color layout of up to five channels
  42. /// \ingroup LayoutModel
  43. template <int N>
  44. struct devicen_layout_t : layout<typename devicen_t<N>::type> {};
  45. /// \ingroup ImageViewConstructors
  46. /// \brief from 2-channel planar data
  47. template <typename IC>
  48. inline
  49. auto planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, std::ptrdiff_t rowsize_in_bytes)
  50. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2>>>::view_t
  51. {
  52. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2>>>::view_t;
  53. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1), rowsize_in_bytes));
  54. }
  55. /// \ingroup ImageViewConstructors
  56. /// \brief from 3-channel planar data
  57. template <typename IC>
  58. inline
  59. auto planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, IC c2, std::ptrdiff_t rowsize_in_bytes)
  60. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3>>>::view_t
  61. {
  62. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3>>>::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
  69. auto 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. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4>>>::view_t
  71. {
  72. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4>>>::view_t;
  73. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3), rowsize_in_bytes));
  74. }
  75. /// \ingroup ImageViewConstructors
  76. /// \brief from 5-channel planar data
  77. template <typename IC>
  78. inline
  79. auto 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)
  80. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5>>>::view_t
  81. {
  82. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5>>>::view_t;
  83. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3,c4), rowsize_in_bytes));
  84. }
  85. }} // namespace boost::gil
  86. #endif