Boost GIL


concepts/color_base.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_COLOR_BASE_HPP
9 #define BOOST_GIL_CONCEPTS_COLOR_BASE_HPP
10 
11 #include <boost/gil/concepts/basic.hpp>
12 #include <boost/gil/concepts/color.hpp>
13 #include <boost/gil/concepts/concept_check.hpp>
14 #include <boost/gil/concepts/fwd.hpp>
15 
16 #include <boost/type_traits.hpp>
17 
18 #if defined(BOOST_CLANG)
19 #pragma clang diagnostic push
20 #pragma clang diagnostic ignored "-Wunused-local-typedefs"
21 #endif
22 
23 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
26 #endif
27 
28 namespace boost { namespace gil {
29 
30 // Forward declarations of at_c
31 namespace detail {
32 
33 template <typename Element, typename Layout, int K>
34 struct homogeneous_color_base;
35 
36 } // namespace detail
37 
38 template <int K, typename E, typename L, int N>
39 auto at_c(detail::homogeneous_color_base<E, L, N>& p)
40  -> typename add_reference<E>::type;
41 
42 template <int K, typename E, typename L, int N>
43 auto at_c(detail::homogeneous_color_base<E, L, N> const& p)
44  -> typename add_reference<typename add_const<E>::type>::type;
45 
46 template <typename P, typename C, typename L>
47 struct packed_pixel;
48 
49 template <int K, typename P, typename C, typename L>
50 auto at_c(packed_pixel<P, C, L>& p)
51  -> typename kth_element_reference_type<packed_pixel<P, C, L>, K>::type;
52 
53 template <int K, typename P, typename C, typename L>
54 auto at_c(packed_pixel<P, C, L> const& p)
55  -> typename kth_element_const_reference_type<packed_pixel<P, C, L>, K>::type;
56 
57 template <typename B, typename C, typename L, bool M>
58 struct bit_aligned_pixel_reference;
59 
60 template <int K, typename B, typename C, typename L, bool M>
61 inline auto at_c(bit_aligned_pixel_reference<B, C, L, M> const& p)
62  -> typename kth_element_reference_type
63  <
64  bit_aligned_pixel_reference<B, C, L, M>,
65  K
66  >::type;
67 
68 // Forward declarations of semantic_at_c
69 template <int K, typename ColorBase>
70 auto semantic_at_c(ColorBase& p)
71  -> typename std::enable_if
72  <
73  !std::is_const<ColorBase>::value,
74  typename kth_semantic_element_reference_type<ColorBase, K>::type
75  >::type;
76 
77 template <int K, typename ColorBase>
78 auto semantic_at_c(ColorBase const& p)
79  -> typename kth_semantic_element_const_reference_type<ColorBase, K>::type;
80 
134 template <typename ColorBase>
136 {
137  void constraints()
138  {
139  gil_function_requires<CopyConstructible<ColorBase>>();
140  gil_function_requires<EqualityComparable<ColorBase>>();
141 
142  using color_space_t = typename ColorBase::layout_t::color_space_t;
143  gil_function_requires<ColorSpaceConcept<color_space_t>>();
144 
145  using channel_mapping_t = typename ColorBase::layout_t::channel_mapping_t;
146  // TODO: channel_mapping_t must be an MPL RandomAccessSequence
147 
148  static const int num_elements = size<ColorBase>::value;
149 
150  using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
151  using RN = typename kth_element_const_reference_type<ColorBase, num_elements - 1>::type;
152 
153  RN r = gil::at_c<num_elements - 1>(cb);
154  ignore_unused_variable_warning(r);
155 
156  // functions that work for every pixel (no need to require them)
157  semantic_at_c<0>(cb);
158  semantic_at_c<num_elements-1>(cb);
159  // also static_max(cb), static_min(cb), static_fill(cb,value),
160  // and all variations of static_for_each(), static_generate(), static_transform()
161  }
162  ColorBase cb;
163 };
164 
180 template <typename ColorBase>
182 {
183  void constraints()
184  {
185  gil_function_requires<ColorBaseConcept<ColorBase>>();
186  gil_function_requires<Assignable<ColorBase>>();
187  gil_function_requires<Swappable<ColorBase>>();
188 
189  using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
190 
191  R0 r = gil::at_c<0>(cb);
192  gil::at_c<0>(cb) = r;
193  }
194  ColorBase cb;
195 };
196 
204 template <typename ColorBase>
206 {
207  void constraints()
208  {
209  gil_function_requires<MutableColorBaseConcept<ColorBase>>();
210  gil_function_requires<Regular<ColorBase>>();
211  }
212 };
213 
224 template <typename ColorBase>
226 {
227  void constraints()
228  {
229  gil_function_requires<ColorBaseConcept<ColorBase>>();
230 
231  static const int num_elements = size<ColorBase>::value;
232 
233  using T0 = typename kth_element_type<ColorBase, 0>::type;
234  using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
235 
236  static_assert(is_same<T0, TN>::value, ""); // better than nothing
237 
238  using R0 = typename kth_element_const_reference_type<ColorBase, 0>::type;
239  R0 r = dynamic_at_c(cb, 0);
240  }
241  ColorBase cb;
242 };
243 
253 template <typename ColorBase>
255 {
256  void constraints()
257  {
258  gil_function_requires<ColorBaseConcept<ColorBase>>();
259  gil_function_requires<HomogeneousColorBaseConcept<ColorBase>>();
260  using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
261  R0 r = dynamic_at_c(cb, 0);
262  dynamic_at_c(cb, 0) = dynamic_at_c(cb, 0);
263  }
264  ColorBase cb;
265 };
266 
277 template <typename ColorBase>
279 {
280  void constraints()
281  {
282  gil_function_requires<MutableHomogeneousColorBaseConcept<ColorBase>>();
283  gil_function_requires<Regular<ColorBase>>();
284  }
285 };
286 
298 template <typename ColorBase1, typename ColorBase2>
300 {
301  void constraints()
302  {
303  static_assert(is_same
304  <
305  typename ColorBase1::layout_t::color_space_t,
306  typename ColorBase2::layout_t::color_space_t
307  >::value, "");
308 
309 // using e1 = typename kth_semantic_element_type<ColorBase1,0>::type;
310 // using e2 = typename kth_semantic_element_type<ColorBase2,0>::type;
311 // "e1 is convertible to e2"
312  }
313 };
314 
315 }} // namespace boost::gil
316 
317 #if defined(BOOST_CLANG)
318 #pragma clang diagnostic pop
319 #endif
320 
321 #if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
322 #pragma GCC diagnostic pop
323 #endif
324 
325 #endif
Homogeneous color base that also has a default constructor. Refines Regular.
Definition: concepts/color_base.hpp:278
Homogeneous color base that allows for modifying its elements.
Definition: concepts/color_base.hpp:254
Definition: algorithm.hpp:30
Two color bases are compatible if they have the same color space and their elements are compatible...
Definition: concepts/color_base.hpp:299
auto semantic_at_c(ColorBase const &p) -> typename kth_semantic_element_const_reference_type< ColorBase, K >::type
A constant accessor to the K-th semantic element of a color base.
Definition: color_base_algorithm.hpp:138
A color base is a container of color elements (such as channels, channel references or channel pointe...
Definition: concepts/color_base.hpp:135
Color base which allows for modifying its elements.
Definition: concepts/color_base.hpp:181
auto at_c(detail::homogeneous_color_base< E, L, N > const &p) -> typename add_reference< typename add_const< E >::type >::type
Provides constant access to the K-th element, in physical order.
Definition: color_base.hpp:393
Color base that also has a default-constructor. Refines Regular.
Definition: concepts/color_base.hpp:205
Returns an MPL integral type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:46
Color base whose elements all have the same type.
Definition: concepts/color_base.hpp:225