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