Boost GIL


concepts/pixel.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_PIXEL_HPP
9 #define BOOST_GIL_CONCEPTS_PIXEL_HPP
10 
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/channel.hpp>
13 #include <boost/gil/concepts/color.hpp>
14 #include <boost/gil/concepts/color_base.hpp>
15 #include <boost/gil/concepts/concept_check.hpp>
16 #include <boost/gil/concepts/fwd.hpp>
17 #include <boost/gil/concepts/pixel_based.hpp>
18 #include <boost/gil/concepts/detail/type_traits.hpp>
19 
20 #include <boost/type_traits.hpp>
21 #include <boost/mpl/and.hpp>
22 #include <boost/mpl/bool.hpp>
23 
24 #include <cstddef>
25 
26 #if defined(BOOST_CLANG)
27 #pragma clang diagnostic push
28 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
29 #endif
30 
31 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
32 #pragma GCC diagnostic push
33 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
34 #endif
35 
36 namespace boost { namespace gil {
37 
63 template <typename P>
65 {
66  void constraints()
67  {
68  gil_function_requires<ColorBaseConcept<P>>();
69  gil_function_requires<PixelBasedConcept<P>>();
70 
71  static_assert(is_pixel<P>::value, "");
72  static const bool is_mutable = P::is_mutable;
73  ignore_unused_variable_warning(is_mutable);
74 
75  using value_type = typename P::value_type;
76  // TODO: Is the cyclic dependency intentional? --mloskot
77  // gil_function_requires<PixelValueConcept<value_type>>();
78 
79  using reference = typename P::reference;
80  gil_function_requires<PixelConcept
81  <
82  typename detail::remove_const_and_reference<reference>::type
83  >>();
84 
85  using const_reference = typename P::const_reference;
86  gil_function_requires<PixelConcept
87  <
88  typename detail::remove_const_and_reference<const_reference>::type
89  >>();
90  }
91 };
92 
101 template <typename P>
103 {
104  void constraints()
105  {
106  gil_function_requires<PixelConcept<P>>();
107  static_assert(P::is_mutable, "");
108  }
109 };
110 
123 template <typename P>
125 {
126  void constraints()
127  {
128  gil_function_requires<PixelConcept<P>>();
129  gil_function_requires<HomogeneousColorBaseConcept<P>>();
130  gil_function_requires<HomogeneousPixelBasedConcept<P>>();
131  p[0];
132  }
133  P p;
134 };
135 
148 template <typename P>
150 {
151  void constraints()
152  {
153  gil_function_requires<HomogeneousPixelConcept<P>>();
154  gil_function_requires<MutableHomogeneousColorBaseConcept<P>>();
155  p[0] = v;
156  v = p[0];
157  }
158  typename P::template element_type<P>::type v;
159  P p;
160 };
161 
170 template <typename P>
172 {
173  void constraints()
174  {
175  gil_function_requires<PixelConcept<P>>();
176  gil_function_requires<Regular<P>>();
177  }
178 };
179 
188 template <typename P>
190 {
191  void constraints()
192  {
193  gil_function_requires<HomogeneousPixelConcept<P>>();
194  gil_function_requires<Regular<P>>();
195  static_assert(is_same<P, typename P::value_type>::value, "");
196  }
197 };
198 
199 namespace detail {
200 
201 template <typename P1, typename P2, int K>
202 struct channels_are_pairwise_compatible
203  : public
204  mpl::and_
205  <
206  channels_are_pairwise_compatible<P1, P2, K - 1>,
207  channels_are_compatible
208  <
209  typename kth_semantic_element_reference_type<P1, K>::type,
210  typename kth_semantic_element_reference_type<P2, K>::type
211  >
212  >
213 {
214 };
215 
216 template <typename P1, typename P2>
217 struct channels_are_pairwise_compatible<P1, P2, -1>
218  : public mpl::true_
219 {
220 };
221 
222 } // namespace detail
223 
230 template <typename P1, typename P2>
232  : public
233  mpl::and_
234  <
235  typename color_spaces_are_compatible
236  <
237  typename color_space_type<P1>::type,
238  typename color_space_type<P2>::type
239  >::type,
240  detail::channels_are_pairwise_compatible
241  <
242  P1, P2, num_channels<P1>::value - 1
243  >
244  >
245 {
246 };
247 
261 template <typename P1, typename P2>
263 {
264  void constraints()
265  {
266  static_assert(pixels_are_compatible<P1, P2>::value, "");
267  }
268 };
269 
282 template <typename SrcP, typename DstP>
284 {
285  void constraints()
286  {
287  gil_function_requires<PixelConcept<SrcP>>();
288  gil_function_requires<MutablePixelConcept<DstP>>();
289  color_convert(src, dst);
290  }
291  SrcP src;
292  DstP dst;
293 };
294 
295 }} // namespace boost::gil
296 
297 #if defined(BOOST_CLANG)
298 #pragma clang diagnostic pop
299 #endif
300 
301 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
302 #pragma GCC diagnostic pop
303 #endif
304 
305 #endif
Homogeneous pixel concept that allows for changing its channels.
Definition: concepts/pixel.hpp:149
Definition: algorithm.hpp:30
Concept for pixel compatibility Pixels are compatible if their channels and color space types are com...
Definition: concepts/pixel.hpp:262
Pixel concept that is a Regular type.
Definition: concepts/pixel.hpp:171
Specifies the element type of a homogeneous color base.
Definition: color_base_algorithm.hpp:224
Homogeneous pixel concept that is a Regular type.
Definition: concepts/pixel.hpp:189
Homogeneous pixel concept.
Definition: concepts/pixel.hpp:124
Pixel concept that allows for changing its channels.
Definition: concepts/pixel.hpp:102
Pixel convertible concept Convertibility is non-symmetric and implies that one pixel can be converted...
Definition: concepts/pixel.hpp:283
void color_convert(const SrcP &src, DstP &dst)
helper function for converting one pixel to another using GIL default color-converters where ScrP mod...
Definition: color_convert.hpp:296
Returns whether two pixels are compatible Pixels are compatible if their channels and color space typ...
Definition: concepts/pixel.hpp:231
Pixel concept - A color base whose elements are channels.
Definition: concepts/pixel.hpp:64