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/core/ignore_unused.hpp>
17 #include <type_traits>
18 
19 #if defined(BOOST_CLANG)
20 #pragma clang diagnostic push
21 #pragma clang diagnostic ignored "-Wunknown-pragmas"
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 // Forward declarations of at_c
33 namespace detail {
34 
35 template <typename Element, typename Layout, int K>
36 struct homogeneous_color_base;
37 
38 } // namespace detail
39 
40 template <int K, typename E, typename L, int N>
41 auto at_c(detail::homogeneous_color_base<E, L, N>& p)
42  -> typename std::add_lvalue_reference<E>::type;
43 
44 template <int K, typename E, typename L, int N>
45 auto at_c(detail::homogeneous_color_base<E, L, N> const& p)
46  -> typename std::add_lvalue_reference<typename std::add_const<E>::type>::type;
47 
48 template <typename P, typename C, typename L>
49 struct packed_pixel;
50 
51 template <int K, typename P, typename C, typename L>
52 auto at_c(packed_pixel<P, C, L>& p)
53  -> typename kth_element_reference_type<packed_pixel<P, C, L>, K>::type;
54 
55 template <int K, typename P, typename C, typename L>
56 auto at_c(packed_pixel<P, C, L> const& p)
57  -> typename kth_element_const_reference_type<packed_pixel<P, C, L>, K>::type;
58 
59 template <typename B, typename C, typename L, bool M>
60 struct bit_aligned_pixel_reference;
61 
62 template <int K, typename B, typename C, typename L, bool M>
63 inline auto at_c(bit_aligned_pixel_reference<B, C, L, M> const& p)
64  -> typename kth_element_reference_type
65  <
66  bit_aligned_pixel_reference<B, C, L, M>,
67  K
68  >::type;
69 
70 // Forward declarations of semantic_at_c
71 template <int K, typename ColorBase>
72 auto semantic_at_c(ColorBase& p)
73  -> typename std::enable_if
74  <
75  !std::is_const<ColorBase>::value,
76  typename kth_semantic_element_reference_type<ColorBase, K>::type
77  >::type;
78 
79 template <int K, typename ColorBase>
80 auto semantic_at_c(ColorBase const& p)
81  -> typename kth_semantic_element_const_reference_type<ColorBase, K>::type;
82 
136 template <typename ColorBase>
138 {
139  void constraints()
140  {
141  gil_function_requires<CopyConstructible<ColorBase>>();
142  gil_function_requires<EqualityComparable<ColorBase>>();
143 
144  using color_space_t = typename ColorBase::layout_t::color_space_t;
145  gil_function_requires<ColorSpaceConcept<color_space_t>>();
146 
147  using channel_mapping_t = typename ColorBase::layout_t::channel_mapping_t;
148  // TODO: channel_mapping_t must be an Boost.MP11-compatible random access sequence
149 
150  static const int num_elements = size<ColorBase>::value;
151 
152  using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
153  using RN = typename kth_element_const_reference_type<ColorBase, num_elements - 1>::type;
154 
155  RN r = gil::at_c<num_elements - 1>(cb);
156  boost::ignore_unused(r);
157 
158  // functions that work for every pixel (no need to require them)
159  semantic_at_c<0>(cb);
160  semantic_at_c<num_elements-1>(cb);
161  // also static_max(cb), static_min(cb), static_fill(cb,value),
162  // and all variations of static_for_each(), static_generate(), static_transform()
163  }
164  ColorBase cb;
165 };
166 
182 template <typename ColorBase>
184 {
185  void constraints()
186  {
187  gil_function_requires<ColorBaseConcept<ColorBase>>();
188  gil_function_requires<Assignable<ColorBase>>();
189  gil_function_requires<Swappable<ColorBase>>();
190 
191  using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
192 
193  R0 r = gil::at_c<0>(cb);
194  gil::at_c<0>(cb) = r;
195  }
196  ColorBase cb;
197 };
198 
206 template <typename ColorBase>
208 {
209  void constraints()
210  {
211  gil_function_requires<MutableColorBaseConcept<ColorBase>>();
212  gil_function_requires<Regular<ColorBase>>();
213  }
214 };
215 
226 template <typename ColorBase>
228 {
229  void constraints()
230  {
231  gil_function_requires<ColorBaseConcept<ColorBase>>();
232 
233  static const int num_elements = size<ColorBase>::value;
234 
235  using T0 = typename kth_element_type<ColorBase, 0>::type;
236  using TN = typename kth_element_type<ColorBase, num_elements - 1>::type;
237 
238  static_assert(std::is_same<T0, TN>::value, ""); // better than nothing
239 
240  using R0 = typename kth_element_const_reference_type<ColorBase, 0>::type;
241  R0 r = dynamic_at_c(cb, 0);
242  boost::ignore_unused(r);
243  }
244  ColorBase cb;
245 };
246 
256 template <typename ColorBase>
258 {
259  void constraints()
260  {
261  gil_function_requires<ColorBaseConcept<ColorBase>>();
262  gil_function_requires<HomogeneousColorBaseConcept<ColorBase>>();
263  using R0 = typename kth_element_reference_type<ColorBase, 0>::type;
264  R0 r = dynamic_at_c(cb, 0);
265  boost::ignore_unused(r);
266  dynamic_at_c(cb, 0) = dynamic_at_c(cb, 0);
267  }
268  ColorBase cb;
269 };
270 
281 template <typename ColorBase>
283 {
284  void constraints()
285  {
286  gil_function_requires<MutableHomogeneousColorBaseConcept<ColorBase>>();
287  gil_function_requires<Regular<ColorBase>>();
288  }
289 };
290 
302 template <typename ColorBase1, typename ColorBase2>
304 {
305  void constraints()
306  {
307  static_assert(std::is_same
308  <
309  typename ColorBase1::layout_t::color_space_t,
310  typename ColorBase2::layout_t::color_space_t
311  >::value, "");
312 
313 // using e1 = typename kth_semantic_element_type<ColorBase1,0>::type;
314 // using e2 = typename kth_semantic_element_type<ColorBase2,0>::type;
315 // "e1 is convertible to e2"
316  }
317 };
318 
319 }} // namespace boost::gil
320 
321 #if defined(BOOST_CLANG)
322 #pragma clang diagnostic pop
323 #endif
324 
325 #if defined(BOOST_GCC) && (BOOST_GCC >= 40900)
326 #pragma GCC diagnostic pop
327 #endif
328 
329 #endif
auto semantic_at_c(ColorBase &p) -> typename std::enable_if< !std::is_const< ColorBase >::value, typename kth_semantic_element_reference_type< ColorBase, K >::type >::type
A mutable accessor to the K-th semantic element of a color base.
Definition: color_base_algorithm.hpp:119
auto at_c(detail::homogeneous_color_base< E, L, N > &p) -> typename std::add_lvalue_reference< E >::type
Provides mutable access to the K-th element, in physical order.
Definition: color_base.hpp:632
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
A color base is a container of color elements (such as channels, channel references or channel pointe...
Definition: concepts/color_base.hpp:138
Color base that also has a default-constructor. Refines Regular.
Definition: concepts/color_base.hpp:208
Two color bases are compatible if they have the same color space and their elements are compatible,...
Definition: concepts/color_base.hpp:304
Color base whose elements all have the same type.
Definition: concepts/color_base.hpp:228
Homogeneous color base that also has a default constructor. Refines Regular.
Definition: concepts/color_base.hpp:283
Color base which allows for modifying its elements.
Definition: concepts/color_base.hpp:184
Homogeneous color base that allows for modifying its elements.
Definition: concepts/color_base.hpp:258
Returns an integral constant type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:42