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 
39 template <typename ChannelReference, typename ColorSpace>
40 struct planar_pixel_reference : detail::homogeneous_color_base
41  <
42  ChannelReference,
43  layout<ColorSpace>,
44  mp11::mp_size<ColorSpace>::value
45  >
46 {
47  using parent_t =detail::homogeneous_color_base
48  <
49  ChannelReference,
51  mp11::mp_size<ColorSpace>::value
52  >;
53 
54 private:
55  // These three are only defined for homogeneous pixels
56  using channel_t = typename channel_traits<ChannelReference>::value_type;
57  using channel_const_reference = typename channel_traits<ChannelReference>::const_reference;
58 
59 public:
60  static constexpr bool is_mutable = channel_traits<ChannelReference>::is_mutable;
64 
65  planar_pixel_reference(ChannelReference v0, ChannelReference v1)
66  : parent_t(v0, v1)
67  {}
68 
69  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2)
70  : parent_t(v0, v1, v2)
71  {}
72 
73  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3)
74  : parent_t(v0, v1, v2, v3)
75  {}
76 
77  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4)
78  : parent_t(v0, v1, v2, v3, v4)
79  {}
80 
81  planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5)
82  : parent_t(v0, v1, v2, v3, v4, v5)
83  {}
84 
85  planar_pixel_reference(planar_pixel_reference const& p) : parent_t(p) {}
86 
87  // TODO: What is the purpose of returning via const reference?
88  auto operator=(planar_pixel_reference const& p) const -> planar_pixel_reference const&
89  {
90  static_copy(p, *this);
91  return *this;
92  }
93 
94  template <typename Pixel>
95  planar_pixel_reference(Pixel const& p) : parent_t(p)
96  {
97  check_compatible<Pixel>();
98  }
99 
100  // TODO: What is the purpose of returning via const reference?
101  template <typename Pixel>
102  auto operator=(Pixel const& p) const -> planar_pixel_reference const&
103  {
104  check_compatible<Pixel>();
105  static_copy(p, *this);
106  return *this;
107  }
108 
109  // PERFORMANCE_CHECK: Is this constructor necessary?
110  template <typename ChannelV, typename Mapping>
112  : parent_t(p)
113  {
114  check_compatible<pixel<ChannelV, layout<ColorSpace, Mapping>>>();
115  }
116 
117  // Construct at offset from a given location
118  template <typename ChannelPtr>
120  : parent_t(p, diff)
121  {}
122 
123 // This overload is necessary for a compiler implementing Core Issue 574
124 // to prevent generation of an implicit copy assignment operator (the reason
125 // for generating implicit copy assignment operator is that according to
126 // Core Issue 574, a cv-qualified assignment operator is not considered
127 // "copy assignment operator").
128 // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
129 // sure why they did it for a template member function as well.
130 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
131  const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
132  template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
133 #endif
134 
135  template <typename Pixel>
136  bool operator==(Pixel const& p) const
137  {
138  check_compatible<Pixel>();
139  return static_equal(*this, p);
140  }
141 
142  template <typename Pixel>
143  bool operator!=(Pixel const &p) const { return !(*this == p); }
144 
145  auto operator[](std::size_t i) const -> ChannelReference { return this->at_c_dynamic(i); }
146  auto operator->() const -> planar_pixel_reference const* { return this; }
147 
148 private:
149  template <typename Pixel>
150  static void check_compatible()
151  {
152  gil_function_requires<PixelsCompatibleConcept<Pixel, planar_pixel_reference>>();
153  }
154 };
155 
157 // ColorBasedConcept
159 
160 template <typename ChannelReference, typename ColorSpace, int K>
161 struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
162 {
163  using type = ChannelReference;
164 };
165 
166 template <typename ChannelReference, typename ColorSpace, int K>
167 struct kth_element_reference_type
168  <
169  planar_pixel_reference<ChannelReference, ColorSpace>,
170  K
171  >
172 {
173  using type = ChannelReference;
174 };
175 
176 template <typename ChannelReference, typename ColorSpace, int K>
177 struct kth_element_const_reference_type
178  <
179  planar_pixel_reference<ChannelReference, ColorSpace>,
180  K
181  >
182  : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
183 {
184  // using type = typename channel_traits<ChannelReference>::const_reference;
185 };
186 
188 // PixelConcept
190 
193 template <typename ChannelReference, typename ColorSpace>
194 struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
195  : std::true_type
196 {};
197 
199 // HomogeneousPixelBasedConcept
201 
204 template <typename ChannelReference, typename ColorSpace>
205 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
206  using type = ColorSpace;
207 };
208 
211 template <typename ChannelReference, typename ColorSpace>
212 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
213  using type = typename layout<ColorSpace>::channel_mapping_t;
214 };
215 
218 template <typename ChannelReference, typename ColorSpace>
219 struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
220  : std::true_type
221 {};
222 
225 template <typename ChannelReference, typename ColorSpace>
226 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
227  using type = typename channel_traits<ChannelReference>::value_type;
228 };
229 
230 }} // namespace boost::gil
231 
232 namespace std {
233 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
234 // swap with 'left bias':
235 // - swap between proxy and anything
236 // - swap between value type and proxy
237 // - swap between proxy and proxy
238 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
239 
242 template <typename CR, typename CS, typename R> inline
244  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
245 }
246 
249 template <typename CR, typename CS> inline
251  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
252 }
253 
256 template <typename CR, typename CS> inline
258  boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
259 }
260 
261 } // namespace std
262 
263 #endif
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:257
defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE)
Definition: algorithm.hpp:36
Definition: color_convert.hpp:31
Represents a color space and ordering of channels in memory.
Definition: utilities.hpp:268
Represents a pixel value (a container of channels). Models: HomogeneousColorBaseValueConcept,...
Definition: pixel.hpp:106
An iterator over planar pixels. Models HomogeneousColorBaseConcept, PixelIteratorConcept,...
Definition: planar_pixel_iterator.hpp:58
A reference proxy to a planar pixel.
Definition: planar_pixel_reference.hpp:46