device_n.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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, 3, 4, or 5 channels
  27. /// \tparam N Number of color components (1, 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. N == 1 || (3 <= 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 typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2>>>::view_t
  49. planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, std::ptrdiff_t rowsize_in_bytes)
  50. {
  51. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<2>>>::view_t;
  52. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1), rowsize_in_bytes));
  53. }
  54. /// \ingroup ImageViewConstructors
  55. /// \brief from 3-channel planar data
  56. template <typename IC>
  57. inline
  58. auto planar_devicen_view(std::size_t width, std::size_t height, IC c0, IC c1, IC c2, std::ptrdiff_t rowsize_in_bytes)
  59. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3>>>::view_t
  60. {
  61. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<3>>>::view_t;
  62. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2), rowsize_in_bytes));
  63. }
  64. /// \ingroup ImageViewConstructors
  65. /// \brief from 4-channel planar data
  66. template <typename IC>
  67. inline
  68. 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)
  69. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4>>>::view_t
  70. {
  71. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<4>>>::view_t;
  72. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3), rowsize_in_bytes));
  73. }
  74. /// \ingroup ImageViewConstructors
  75. /// \brief from 5-channel planar data
  76. template <typename IC>
  77. inline
  78. 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)
  79. -> typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5>>>::view_t
  80. {
  81. using view_t = typename type_from_x_iterator<planar_pixel_iterator<IC,devicen_t<5>>>::view_t;
  82. return view_t(width, height, typename view_t::locator(typename view_t::x_iterator(c0,c1,c2,c3,c4), rowsize_in_bytes));
  83. }
  84. }} // namespace boost::gil
  85. #endif