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