Imported Upstream version 1.72.0
[platform/upstream/boost.git] / boost / gil / concepts / image.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_CONCEPTS_IMAGE_HPP
9 #define BOOST_GIL_CONCEPTS_IMAGE_HPP
10
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/concept_check.hpp>
13 #include <boost/gil/concepts/fwd.hpp>
14 #include <boost/gil/concepts/image_view.hpp>
15 #include <boost/gil/concepts/point.hpp>
16 #include <boost/gil/detail/mp11.hpp>
17
18 #include <type_traits>
19
20 #if defined(BOOST_CLANG)
21 #pragma clang diagnostic push
22 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
23 #endif
24
25 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
26 #pragma GCC diagnostic push
27 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
28 #endif
29
30 namespace boost { namespace gil {
31
32 /// \ingroup ImageConcept
33 /// \brief N-dimensional container of values
34 ///
35 /// \code
36 /// concept RandomAccessNDImageConcept<typename Image> : Regular<Image>
37 /// {
38 ///     typename view_t; where MutableRandomAccessNDImageViewConcept<view_t>;
39 ///     typename const_view_t = view_t::const_t;
40 ///     typename point_t      = view_t::point_t;
41 ///     typename value_type   = view_t::value_type;
42 ///     typename allocator_type;
43 ///
44 ///     Image::Image(point_t dims, std::size_t alignment=1);
45 ///     Image::Image(point_t dims, value_type fill_value, std::size_t alignment);
46 ///
47 ///     void Image::recreate(point_t new_dims, std::size_t alignment=1);
48 ///     void Image::recreate(point_t new_dims, value_type fill_value, std::size_t alignment);
49 ///
50 ///     const point_t&        Image::dimensions() const;
51 ///     const const_view_t&   const_view(const Image&);
52 ///     const view_t&         view(Image&);
53 /// };
54 /// \endcode
55 template <typename Image>
56 struct RandomAccessNDImageConcept
57 {
58     void constraints()
59     {
60         gil_function_requires<Regular<Image>>();
61
62         using view_t = typename Image::view_t;
63         gil_function_requires<MutableRandomAccessNDImageViewConcept<view_t>>();
64
65         using const_view_t = typename Image::const_view_t;
66         using pixel_t = typename Image::value_type;
67         using point_t = typename Image::point_t;
68         gil_function_requires<PointNDConcept<point_t>>();
69
70         const_view_t cv = const_view(image);
71         ignore_unused_variable_warning(cv);
72         view_t v = view(image);
73         ignore_unused_variable_warning(v);
74
75         pixel_t fill_value;
76         point_t pt = image.dimensions();
77         Image image1(pt);
78         Image image2(pt, 1);
79         Image image3(pt, fill_value, 1);
80         image.recreate(pt);
81         image.recreate(pt, 1);
82         image.recreate(pt, fill_value, 1);
83     }
84     Image image;
85 };
86
87
88 /// \ingroup ImageConcept
89 /// \brief 2-dimensional container of values
90 ///
91 /// \code
92 /// concept RandomAccess2DImageConcept<RandomAccessNDImageConcept Image>
93 /// {
94 ///     typename x_coord_t = const_view_t::x_coord_t;
95 ///     typename y_coord_t = const_view_t::y_coord_t;
96 ///
97 ///     Image::Image(x_coord_t width, y_coord_t height, std::size_t alignment=1);
98 ///     Image::Image(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
99 ///
100 ///     x_coord_t Image::width() const;
101 ///     y_coord_t Image::height() const;
102 ///
103 ///     void Image::recreate(x_coord_t width, y_coord_t height, std::size_t alignment=1);
104 ///     void Image::recreate(x_coord_t width, y_coord_t height, value_type fill_value, std::size_t alignment);
105 /// };
106 /// \endcode
107 template <typename Image>
108 struct RandomAccess2DImageConcept
109 {
110     void constraints()
111     {
112         gil_function_requires<RandomAccessNDImageConcept<Image>>();
113         using x_coord_t = typename Image::x_coord_t;
114         using y_coord_t = typename Image::y_coord_t;
115         using value_t = typename Image::value_type;
116
117         gil_function_requires<MutableRandomAccess2DImageViewConcept<typename Image::view_t>>();
118
119         x_coord_t w=image.width();
120         y_coord_t h=image.height();
121         value_t fill_value;
122         Image im1(w,h);
123         Image im2(w,h,1);
124         Image im3(w,h,fill_value,1);
125         image.recreate(w,h);
126         image.recreate(w,h,1);
127         image.recreate(w,h,fill_value,1);
128     }
129     Image image;
130 };
131
132 /// \ingroup ImageConcept
133 /// \brief 2-dimensional image whose value type models PixelValueConcept
134 ///
135 /// \code
136 /// concept ImageConcept<RandomAccess2DImageConcept Image>
137 /// {
138 ///     where MutableImageViewConcept<view_t>;
139 ///     typename coord_t  = view_t::coord_t;
140 /// };
141 /// \endcode
142 template <typename Image>
143 struct ImageConcept
144 {
145     void constraints()
146     {
147         gil_function_requires<RandomAccess2DImageConcept<Image>>();
148         gil_function_requires<MutableImageViewConcept<typename Image::view_t>>();
149         using coord_t = typename Image::coord_t;
150         static_assert(num_channels<Image>::value == mp11::mp_size<typename color_space_type<Image>::type>::value, "");
151
152         static_assert(std::is_same<coord_t, typename Image::x_coord_t>::value, "");
153         static_assert(std::is_same<coord_t, typename Image::y_coord_t>::value, "");
154     }
155     Image image;
156 };
157
158 }} // namespace boost::gil
159
160 #if defined(BOOST_CLANG)
161 #pragma clang diagnostic pop
162 #endif
163
164 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
165 #pragma GCC diagnostic pop
166 #endif
167
168 #endif