Boost GIL


planar_pixel_reference.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_PLANAR_PIXEL_REFERENCE_HPP
9 #define BOOST_GIL_PLANAR_PIXEL_REFERENCE_HPP
10 
11 #include <boost/gil/channel.hpp>
12 #include <boost/gil/color_base.hpp>
13 #include <boost/gil/concepts.hpp>
14 #include <boost/gil/pixel.hpp>
15 #include <boost/gil/planar_pixel_iterator.hpp>
16 #include <boost/gil/detail/mp11.hpp>
17 
18 #include <type_traits>
19 
20 namespace boost { namespace gil {
21 
26 
30 
31 
37 template <typename ChannelReference, typename ColorSpace> // ChannelReference is a channel reference (const or mutable)
38 struct planar_pixel_reference : detail::homogeneous_color_base
39  <
40  ChannelReference,
41  layout<ColorSpace>,
42  mp11::mp_size<ColorSpace>::value
43  >
44 {
45  using parent_t =detail::homogeneous_color_base
46  <
47  ChannelReference,
48  layout<ColorSpace>,
49  mp11::mp_size<ColorSpace>::value
50  >;
51 
52 private:
53  // These three are only defined for homogeneous pixels
54  using channel_t = typename channel_traits<ChannelReference>::value_type;
55  using channel_const_reference = typename channel_traits<ChannelReference>::const_reference;
56 
57 public:
58  static constexpr bool is_mutable = channel_traits<ChannelReference>::is_mutable;
59  using value_type = pixel<channel_t,layout<ColorSpace>>;
60  using reference = planar_pixel_reference<ChannelReference, ColorSpace>;
61  using const_reference = planar_pixel_reference<channel_const_reference,ColorSpace>;
62 
63  planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {}
64  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {}
65  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {}
66 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {}
67  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
68 
69  template <typename P> planar_pixel_reference(const P& p) : parent_t(p) { check_compatible<P>();}
70 
71  // PERFORMANCE_CHECK: Is this constructor necessary?
72  template <typename ChannelV, typename Mapping>
73  planar_pixel_reference(pixel<ChannelV,layout<ColorSpace,Mapping> >& p) : parent_t(p) { check_compatible<pixel<ChannelV,layout<ColorSpace,Mapping> > >();}
74 
75  // Construct at offset from a given location
76  template <typename ChannelPtr> planar_pixel_reference(const planar_pixel_iterator<ChannelPtr,ColorSpace>& p, std::ptrdiff_t diff) : parent_t(p,diff) {}
77 
78  const planar_pixel_reference& operator=(const planar_pixel_reference& p) const { static_copy(p,*this); return *this; }
79  template <typename P> const planar_pixel_reference& operator=(const P& p) const { check_compatible<P>(); static_copy(p,*this); return *this; }
80 
81 // This overload is necessary for a compiler implementing Core Issue 574
82 // to prevent generation of an implicit copy assignment operator (the reason
83 // for generating implicit copy assignment operator is that according to
84 // Core Issue 574, a cv-qualified assignment operator is not considered
85 // "copy assignment operator").
86 // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
87 // sure why they did it for a template member function as well.
88 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
89  const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
90  template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
91 #endif
92 
93  template <typename P> bool operator==(const P& p) const { check_compatible<P>(); return static_equal(*this,p); }
94  template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
95 
96  ChannelReference operator[](std::size_t i) const { return this->at_c_dynamic(i); }
97 
98  const planar_pixel_reference* operator->() const { return this; }
99 private:
100  template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,planar_pixel_reference> >(); }
101 };
102 
104 // ColorBasedConcept
106 
107 template <typename ChannelReference, typename ColorSpace, int K>
108 struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
109 {
110  using type = ChannelReference;
111 };
112 
113 template <typename ChannelReference, typename ColorSpace, int K>
114 struct kth_element_reference_type
115  <
116  planar_pixel_reference<ChannelReference, ColorSpace>,
117  K
118  >
119 {
120  using type = ChannelReference;
121 };
122 
123 template <typename ChannelReference, typename ColorSpace, int K>
124 struct kth_element_const_reference_type
125  <
126  planar_pixel_reference<ChannelReference, ColorSpace>,
127  K
128  >
129  : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
130 {
131  // using type = typename channel_traits<ChannelReference>::const_reference;
132 };
133 
135 // PixelConcept
137 
140 template <typename ChannelReference, typename ColorSpace>
141 struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
142  : std::true_type
143 {};
144 
146 // HomogeneousPixelBasedConcept
148 
151 template <typename ChannelReference, typename ColorSpace>
152 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
153  using type = ColorSpace;
154 };
155 
158 template <typename ChannelReference, typename ColorSpace>
159 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
160  using type = typename layout<ColorSpace>::channel_mapping_t;
161 };
162 
165 template <typename ChannelReference, typename ColorSpace>
166 struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
167  : std::true_type
168 {};
169 
172 template <typename ChannelReference, typename ColorSpace>
173 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
174  using type = typename channel_traits<ChannelReference>::value_type;
175 };
176 
177 }} // namespace boost::gil
178 
179 namespace std {
180 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
181 // swap with 'left bias':
182 // - swap between proxy and anything
183 // - swap between value type and proxy
184 // - swap between proxy and proxy
185 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
186 
189 template <typename CR, typename CS, typename R> inline
191  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
192 }
193 
196 template <typename CR, typename CS> inline
198  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
199 }
200 
203 template <typename CR, typename CS> inline
205  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
206 }
207 
208 } // namespace std
209 
210 #endif
A reference proxy to a planar pixel. Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept.
Definition: metafunctions.hpp:25
Definition: algorithm.hpp:30
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept, PixelValueConcept, HomogeneousPixelBasedConcept.
Definition: metafunctions.hpp:23
Definition: algorithm.hpp:133
Definition: color_convert.hpp:31
void swap(const boost::gil::planar_pixel_reference< CR, CS > x, const boost::gil::planar_pixel_reference< CR, CS > y)
swap for planar_pixel_reference
Definition: planar_pixel_reference.hpp:204