9 #ifndef BOOST_GIL_COLOR_BASE_HPP 10 #define BOOST_GIL_COLOR_BASE_HPP 12 #include <boost/gil/utilities.hpp> 13 #include <boost/gil/concepts.hpp> 14 #include <boost/gil/detail/mp11.hpp> 16 #include <boost/assert.hpp> 17 #include <boost/config.hpp> 19 #include <type_traits> 21 namespace boost {
namespace gil {
24 template <
typename P> P* memunit_advanced(
const P* p, std::ptrdiff_t diff);
27 template <
int K,
typename ColorBase>
29 ->
typename std::enable_if
31 !std::is_const<ColorBase>::value,
32 typename kth_semantic_element_reference_type<ColorBase, K>::type
36 template <
int K,
typename ColorBase>
37 typename kth_semantic_element_const_reference_type<ColorBase,K>::type
semantic_at_c(
const ColorBase& p);
42 template <
typename ColorBase,
int K>
struct kth_element_type;
43 template <
typename ColorBase,
int K>
struct kth_element_type<const ColorBase,K> :
public kth_element_type<ColorBase,K> {};
44 template <
typename ColorBase,
int K>
struct kth_element_reference_type;
45 template <
typename ColorBase,
int K>
struct kth_element_reference_type<const ColorBase,K> :
public kth_element_reference_type<ColorBase,K> {};
46 template <
typename ColorBase,
int K>
struct kth_element_const_reference_type;
47 template <
typename ColorBase,
int K>
struct kth_element_const_reference_type<const ColorBase,K> :
public kth_element_const_reference_type<ColorBase,K> {};
51 template <
typename DstLayout,
typename SrcLayout,
int K>
52 struct mapping_transform : mp11::mp_at
54 typename SrcLayout::channel_mapping_t,
55 typename detail::type_to_index
57 typename DstLayout::channel_mapping_t,
58 std::integral_constant<int, K>
69 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 71 #pragma warning(disable:4512) //assignment operator could not be generated 77 template <
typename Element,
typename Layout>
78 struct homogeneous_color_base<Element, Layout, 1>
80 using layout_t = Layout;
82 homogeneous_color_base() =
default;
83 homogeneous_color_base(Element v) : v0_(v) {}
85 template <
typename E2,
typename L2>
86 homogeneous_color_base(homogeneous_color_base<E2, L2, 1>
const& c)
87 : v0_(gil::at_c<0>(c))
90 auto at(std::integral_constant<int, 0>)
94 auto at(std::integral_constant<int, 0>)
const 100 operator Element()
const {
return v0_; }
109 template <
typename Element,
typename Layout>
110 struct homogeneous_color_base<Element, Layout, 2>
112 using layout_t = Layout;
114 homogeneous_color_base() =
default;
115 explicit homogeneous_color_base(Element v) : v0_(v), v1_(v) {}
116 homogeneous_color_base(Element v0, Element v1) : v0_(v0), v1_(v1) {}
118 template <
typename E2,
typename L2>
119 homogeneous_color_base(homogeneous_color_base<E2, L2, 2>
const& c)
120 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
121 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
125 template <
typename E2,
typename L2>
126 homogeneous_color_base(homogeneous_color_base<E2, L2, 2>& c)
127 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
128 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
132 template <
typename P>
133 homogeneous_color_base(P* p,
bool)
134 : v0_(&semantic_at_c<0>(*p))
135 , v1_(&semantic_at_c<1>(*p))
139 template <
typename Ptr>
140 homogeneous_color_base(Ptr
const& ptr, std::ptrdiff_t diff)
141 : v0_(*memunit_advanced(semantic_at_c<0>(ptr), diff))
142 , v1_(*memunit_advanced(semantic_at_c<1>(ptr), diff))
145 template <
typename Ref>
148 return Ref(*semantic_at_c<0>(*
this), *semantic_at_c<1>(*
this));
151 auto at(std::integral_constant<int, 0>)
155 auto at(std::integral_constant<int, 0>)
const 159 auto at(std::integral_constant<int, 1>)
163 auto at(std::integral_constant<int, 1>)
const 168 Element at_c_dynamic(std::size_t i)
const 184 template <
typename Element,
typename Layout>
185 struct homogeneous_color_base<Element, Layout, 3>
187 using layout_t = Layout;
189 homogeneous_color_base() =
default;
190 explicit homogeneous_color_base(Element v) : v0_(v), v1_(v), v2_(v) {}
191 homogeneous_color_base(Element v0, Element v1, Element v2)
192 : v0_(v0), v1_(v1), v2_(v2)
195 template <
typename E2,
typename L2>
196 homogeneous_color_base(homogeneous_color_base<E2, L2, 3>
const& c)
197 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
198 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
199 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
203 template <
typename E2,
typename L2>
204 homogeneous_color_base(homogeneous_color_base<E2, L2, 3>& c)
205 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
206 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
207 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
211 template <
typename P>
212 homogeneous_color_base(P* p,
bool)
213 : v0_(&semantic_at_c<0>(*p))
214 , v1_(&semantic_at_c<1>(*p))
215 , v2_(&semantic_at_c<2>(*p))
219 template <
typename Ptr>
220 homogeneous_color_base(Ptr
const& ptr, std::ptrdiff_t diff)
221 : v0_(*memunit_advanced(semantic_at_c<0>(ptr), diff))
222 , v1_(*memunit_advanced(semantic_at_c<1>(ptr), diff))
223 , v2_(*memunit_advanced(semantic_at_c<2>(ptr), diff))
226 template <
typename Ref>
230 *semantic_at_c<0>(*
this),
231 *semantic_at_c<1>(*
this),
232 *semantic_at_c<2>(*
this));
235 auto at(std::integral_constant<int, 0>)
239 auto at(std::integral_constant<int, 0>)
const 243 auto at(std::integral_constant<int, 1>)
247 auto at(std::integral_constant<int, 1>)
const 251 auto at(std::integral_constant<int, 2>)
255 auto at(std::integral_constant<int, 2>)
const 260 Element at_c_dynamic(std::size_t i)
const 279 template <
typename Element,
typename Layout>
280 struct homogeneous_color_base<Element, Layout, 4>
282 using layout_t = Layout;
284 homogeneous_color_base() =
default;
285 explicit homogeneous_color_base(Element v) : v0_(v), v1_(v), v2_(v), v3_(v) {}
286 homogeneous_color_base(Element v0, Element v1, Element v2, Element v3)
287 : v0_(v0), v1_(v1), v2_(v2), v3_(v3)
290 template <
typename E2,
typename L2>
291 homogeneous_color_base(homogeneous_color_base<E2, L2, 4>
const& c)
292 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
293 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
294 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
295 , v3_(
gil::at_c<mapping_transform<Layout, L2, 3>::value>(c))
299 template <
typename E2,
typename L2>
300 homogeneous_color_base(homogeneous_color_base<E2, L2, 4>& c)
301 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
302 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
303 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
304 , v3_(
gil::at_c<mapping_transform<Layout, L2, 3>::value>(c))
308 template <
typename P>
309 homogeneous_color_base(P * p,
bool)
310 : v0_(&semantic_at_c<0>(*p))
311 , v1_(&semantic_at_c<1>(*p))
312 , v2_(&semantic_at_c<2>(*p))
313 , v3_(&semantic_at_c<3>(*p))
317 template <
typename Ptr>
318 homogeneous_color_base(Ptr
const& ptr, std::ptrdiff_t diff)
319 : v0_(*memunit_advanced(semantic_at_c<0>(ptr), diff))
320 , v1_(*memunit_advanced(semantic_at_c<1>(ptr), diff))
321 , v2_(*memunit_advanced(semantic_at_c<2>(ptr), diff))
322 , v3_(*memunit_advanced(semantic_at_c<3>(ptr), diff))
325 template <
typename Ref>
329 *semantic_at_c<0>(*
this),
330 *semantic_at_c<1>(*
this),
331 *semantic_at_c<2>(*
this),
332 *semantic_at_c<3>(*
this));
335 auto at(std::integral_constant<int, 0>)
339 auto at(std::integral_constant<int, 0>)
const 343 auto at(std::integral_constant<int, 1>)
347 auto at(std::integral_constant<int, 1>)
const 351 auto at(std::integral_constant<int, 2>)
355 auto at(std::integral_constant<int, 2>)
const 359 auto at(std::integral_constant<int, 3>)
363 auto at(std::integral_constant<int, 3>)
const 368 Element at_c_dynamic(std::size_t i)
const 389 template <
typename Element,
typename Layout>
390 struct homogeneous_color_base<Element, Layout, 5>
392 using layout_t = Layout;
394 homogeneous_color_base() =
default;
395 explicit homogeneous_color_base(Element v)
396 : v0_(v), v1_(v), v2_(v), v3_(v), v4_(v)
399 homogeneous_color_base(Element v0, Element v1, Element v2, Element v3, Element v4)
400 : v0_(v0), v1_(v1), v2_(v2), v3_(v3), v4_(v4)
403 template <
typename E2,
typename L2>
404 homogeneous_color_base(homogeneous_color_base<E2, L2, 5>
const& c)
405 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
406 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
407 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
408 , v3_(
gil::at_c<mapping_transform<Layout, L2, 3>::value>(c))
409 , v4_(
gil::at_c<mapping_transform<Layout, L2, 4>::value>(c))
413 template <
typename E2,
typename L2>
414 homogeneous_color_base(homogeneous_color_base<E2, L2, 5>& c)
415 : v0_(
gil::at_c<mapping_transform<Layout, L2, 0>::value>(c))
416 , v1_(
gil::at_c<mapping_transform<Layout, L2, 1>::value>(c))
417 , v2_(
gil::at_c<mapping_transform<Layout, L2, 2>::value>(c))
418 , v3_(
gil::at_c<mapping_transform<Layout, L2, 3>::value>(c))
419 , v4_(
gil::at_c<mapping_transform<Layout, L2, 4>::value>(c))
423 template <
typename P>
424 homogeneous_color_base(P* p,
bool)
425 : v0_(&semantic_at_c<0>(*p))
426 , v1_(&semantic_at_c<1>(*p))
427 , v2_(&semantic_at_c<2>(*p))
428 , v3_(&semantic_at_c<3>(*p))
429 , v4_(&semantic_at_c<4>(*p))
433 template <
typename Ptr>
434 homogeneous_color_base(Ptr
const& ptr, std::ptrdiff_t diff)
435 : v0_(*memunit_advanced(semantic_at_c<0>(ptr), diff))
436 , v1_(*memunit_advanced(semantic_at_c<1>(ptr), diff))
437 , v2_(*memunit_advanced(semantic_at_c<2>(ptr), diff))
438 , v3_(*memunit_advanced(semantic_at_c<3>(ptr), diff))
439 , v4_(*memunit_advanced(semantic_at_c<4>(ptr), diff))
443 auto at(std::integral_constant<int, 0>)
447 auto at(std::integral_constant<int, 0>)
const 451 auto at(std::integral_constant<int, 1>)
455 auto at(std::integral_constant<int, 1>)
const 459 auto at(std::integral_constant<int, 2>)
463 auto at(std::integral_constant<int, 2>)
const 467 auto at(std::integral_constant<int, 3>)
471 auto at(std::integral_constant<int, 3>)
const 475 auto at(std::integral_constant<int, 4>)
479 auto at(std::integral_constant<int, 4>)
const 483 template <
typename Ref>
487 *semantic_at_c<0>(*
this),
488 *semantic_at_c<1>(*
this),
489 *semantic_at_c<2>(*
this),
490 *semantic_at_c<3>(*
this),
491 *semantic_at_c<4>(*
this));
495 Element at_c_dynamic(std::size_t i)
const 515 #if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) 529 template <
typename Element,
typename Layout,
int K>
530 auto dynamic_at_c(homogeneous_color_base<Element,Layout,K>& cb, std::size_t i)
534 return (gil_reinterpret_cast<Element*>(&cb))[i];
537 template <
typename Element,
typename Layout,
int K>
538 auto dynamic_at_c(homogeneous_color_base<Element, Layout, K>
const& cb, std::size_t i)
541 homogeneous_color_base<Element, Layout, K>
545 return (gil_reinterpret_cast_c<const Element*>(&cb))[i];
548 template <
typename Element,
typename Layout,
int K>
549 auto dynamic_at_c(homogeneous_color_base<Element&, Layout, K>
const& cb, std::size_t i)
550 ->
typename element_reference_type
552 homogeneous_color_base<Element&, Layout, K>
556 return cb.at_c_dynamic(i);
559 template <
typename Element,
typename Layout,
int K>
561 homogeneous_color_base<Element const&, Layout, K>
const& cb, std::size_t i)
562 ->
typename element_const_reference_type
564 homogeneous_color_base<Element const&, Layout, K>
568 return cb.at_c_dynamic(i);
573 template <
typename Element,
typename Layout,
int K1,
int K>
574 struct kth_element_type<detail::homogeneous_color_base<Element, Layout, K1>, K>
576 using type = Element;
579 template <
typename Element,
typename Layout,
int K1,
int K>
580 struct kth_element_reference_type<detail::homogeneous_color_base<Element, Layout, K1>, K>
581 : std::add_lvalue_reference<Element>
584 template <
typename Element,
typename Layout,
int K1,
int K>
585 struct kth_element_const_reference_type
587 detail::homogeneous_color_base<Element, Layout, K1>,
590 : std::add_lvalue_reference<typename std::add_const<Element>::type>
595 template <
int K,
typename E,
typename L,
int N>
597 auto at_c(detail::homogeneous_color_base<E, L, N>& p)
598 ->
typename std::add_lvalue_reference<E>::type
600 return p.at(std::integral_constant<int, K>());
605 template <
int K,
typename E,
typename L,
int N>
607 auto at_c(
const detail::homogeneous_color_base<E, L, N>& p)
608 ->
typename std::add_lvalue_reference<typename std::add_const<E>::type>::type
610 return p.at(std::integral_constant<int, K>());
618 template <
typename T>
619 void operator()(T& x, T& y)
const 628 template <
typename E,
typename L,
int N>
631 detail::homogeneous_color_base<E, L, N>& x,
632 detail::homogeneous_color_base<E, L, N>& y)
634 static_for_each(x, y, detail::swap_fn());
auto at_c(const detail::homogeneous_color_base< E, L, N > &p) -> typename std::add_lvalue_reference< typename std::add_const< E >::type >::type
Provides constant access to the K-th element, in physical order.
Definition: color_base.hpp:607
Specifies the return type of the constant element accessor at_c of a homogeneous color base.
Definition: color_base.hpp:41
kth_semantic_element_const_reference_type< ColorBase, K >::type semantic_at_c(const ColorBase &p)
A constant accessor to the K-th semantic element of a color base.
Definition: color_base_algorithm.hpp:133
Specifies the return type of the mutable element accessor at_c of a homogeneous color base.
Definition: color_base.hpp:40
void swap(boost::gil::packed_channel_reference< BF, FB, NB, M > const x, R &y)
swap for packed_channel_reference
Definition: channel.hpp:529