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 #include <boost/gil/detail/mp11.hpp>
20 
21 #include <cstddef>
22 #include <type_traits>
23 
24 #if defined(BOOST_CLANG)
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wunknown-pragmas"
27 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
28 #endif
29 
30 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
33 #endif
34 
35 namespace boost { namespace gil {
36 
62 template <typename P>
64 {
65  void constraints()
66  {
67  gil_function_requires<ColorBaseConcept<P>>();
68  gil_function_requires<PixelBasedConcept<P>>();
69 
70  static_assert(is_pixel<P>::value, "");
71  static const bool is_mutable = P::is_mutable;
72  ignore_unused_variable_warning(is_mutable);
73 
74  using value_type = typename P::value_type;
75  // TODO: Is the cyclic dependency intentional? --mloskot
76  // gil_function_requires<PixelValueConcept<value_type>>();
77 
78  using reference = typename P::reference;
79  gil_function_requires<PixelConcept
80  <
81  typename detail::remove_const_and_reference<reference>::type
82  >>();
83 
84  using const_reference = typename P::const_reference;
85  gil_function_requires<PixelConcept
86  <
87  typename detail::remove_const_and_reference<const_reference>::type
88  >>();
89  }
90 };
91 
100 template <typename P>
102 {
103  void constraints()
104  {
105  gil_function_requires<PixelConcept<P>>();
106  static_assert(P::is_mutable, "");
107  }
108 };
109 
122 template <typename P>
124 {
125  void constraints()
126  {
127  gil_function_requires<PixelConcept<P>>();
128  gil_function_requires<HomogeneousColorBaseConcept<P>>();
129  gil_function_requires<HomogeneousPixelBasedConcept<P>>();
130  p[0];
131  }
132  P p;
133 };
134 
147 template <typename P>
149 {
150  void constraints()
151  {
152  gil_function_requires<HomogeneousPixelConcept<P>>();
153  gil_function_requires<MutableHomogeneousColorBaseConcept<P>>();
154  p[0] = v;
155  v = p[0];
156  }
157  typename P::template element_type<P>::type v;
158  P p;
159 };
160 
169 template <typename P>
171 {
172  void constraints()
173  {
174  gil_function_requires<PixelConcept<P>>();
175  gil_function_requires<Regular<P>>();
176  }
177 };
178 
187 template <typename P>
189 {
190  void constraints()
191  {
192  gil_function_requires<HomogeneousPixelConcept<P>>();
193  gil_function_requires<Regular<P>>();
194  static_assert(std::is_same<P, typename P::value_type>::value, "");
195  }
196 };
197 
198 namespace detail {
199 
200 template <typename P1, typename P2, int K>
201 struct channels_are_pairwise_compatible
202  : mp11::mp_and
203  <
204  channels_are_pairwise_compatible<P1, P2, K - 1>,
205  channels_are_compatible
206  <
207  typename kth_semantic_element_reference_type<P1, K>::type,
208  typename kth_semantic_element_reference_type<P2, K>::type
209  >
210  >
211 {
212 };
213 
214 template <typename P1, typename P2>
215 struct channels_are_pairwise_compatible<P1, P2, -1> : std::true_type {};
216 
217 } // namespace detail
218 
225 template <typename P1, typename P2>
227  : mp11::mp_and
228  <
229  typename color_spaces_are_compatible
230  <
231  typename color_space_type<P1>::type,
232  typename color_space_type<P2>::type
233  >::type,
234  detail::channels_are_pairwise_compatible
235  <
236  P1, P2, num_channels<P1>::value - 1
237  >
238  >
239 {
240 };
241 
255 template <typename P1, typename P2>
257 {
258  void constraints()
259  {
260  static_assert(pixels_are_compatible<P1, P2>::value, "");
261  }
262 };
263 
276 template <typename SrcP, typename DstP>
278 {
279  void constraints()
280  {
281  gil_function_requires<PixelConcept<SrcP>>();
282  gil_function_requires<MutablePixelConcept<DstP>>();
283  color_convert(src, dst);
284  }
285  SrcP src;
286  DstP dst;
287 };
288 
289 }} // namespace boost::gil
290 
291 #if defined(BOOST_CLANG)
292 #pragma clang diagnostic pop
293 #endif
294 
295 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
296 #pragma GCC diagnostic pop
297 #endif
298 
299 #endif
Homogeneous pixel concept that allows for changing its channels.
Definition: concepts/pixel.hpp:148
Concept for pixel compatibility Pixels are compatible if their channels and color space types are com...
Definition: concepts/pixel.hpp:256
Pixel concept that is a Regular type.
Definition: concepts/pixel.hpp:170
Specifies the element type of a homogeneous color base.
Definition: color_base_algorithm.hpp:221
Homogeneous pixel concept that is a Regular type.
Definition: concepts/pixel.hpp:188
Homogeneous pixel concept.
Definition: concepts/pixel.hpp:123
Pixel concept that allows for changing its channels.
Definition: concepts/pixel.hpp:101
Pixel convertible concept Convertibility is non-symmetric and implies that one pixel can be converted...
Definition: concepts/pixel.hpp:277
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:309
Returns whether two pixels are compatible Pixels are compatible if their channels and color space typ...
Definition: concepts/pixel.hpp:226
Pixel concept - A color base whose elements are channels.
Definition: concepts/pixel.hpp:63