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
20namespace boost { namespace gil {
21
26
30
39template <typename ChannelReference, typename ColorSpace>
40struct 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
54private:
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
59public:
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 // TODO: Enable only for ConstChannelReference
95 template <typename Pixel>
96 planar_pixel_reference(Pixel const& p) : parent_t(p)
97 {
98 check_compatible<Pixel>();
99 }
100
101 // TODO: What is the purpose of returning via const reference?
102 template <typename Pixel>
103 auto operator=(Pixel const& p) const -> planar_pixel_reference const&
104 {
105 check_compatible<Pixel>();
106 static_copy(p, *this);
107 return *this;
108 }
109
110 // PERFORMANCE_CHECK: Is this constructor necessary?
111 template <typename ChannelV, typename Mapping>
113 : parent_t(p)
114 {
115 check_compatible<pixel<ChannelV, layout<ColorSpace, Mapping>>>();
116 }
117
118 // Construct at offset from a given location
119 template <typename ChannelPtr>
121 : parent_t(p, diff)
122 {}
123
124// This overload is necessary for a compiler implementing Core Issue 574
125// to prevent generation of an implicit copy assignment operator (the reason
126// for generating implicit copy assignment operator is that according to
127// Core Issue 574, a cv-qualified assignment operator is not considered
128// "copy assignment operator").
129// EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
130// sure why they did it for a template member function as well.
131#if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
132 const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
133 template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
134#endif
135
136 template <typename Pixel>
137 bool operator==(Pixel const& p) const
138 {
139 check_compatible<Pixel>();
140 return static_equal(*this, p);
141 }
142
143 template <typename Pixel>
144 bool operator!=(Pixel const &p) const { return !(*this == p); }
145
146 auto operator[](std::size_t i) const -> ChannelReference { return this->at_c_dynamic(i); }
147 auto operator->() const -> planar_pixel_reference const* { return this; }
148
149private:
150 template <typename Pixel>
151 static void check_compatible()
152 {
153 gil_function_requires<PixelsCompatibleConcept<Pixel, planar_pixel_reference>>();
154 }
155};
156
158// ColorBasedConcept
160
161template <typename ChannelReference, typename ColorSpace, int K>
162struct kth_element_type<planar_pixel_reference<ChannelReference, ColorSpace>, K>
163{
164 using type = ChannelReference;
165};
166
167template <typename ChannelReference, typename ColorSpace, int K>
168struct kth_element_reference_type
169 <
170 planar_pixel_reference<ChannelReference, ColorSpace>,
171 K
172 >
173{
174 using type = ChannelReference;
175};
176
177template <typename ChannelReference, typename ColorSpace, int K>
178struct kth_element_const_reference_type
179 <
180 planar_pixel_reference<ChannelReference, ColorSpace>,
181 K
182 >
183 : std::add_lvalue_reference<typename std::add_const<ChannelReference>::type>
184{
185 // using type = typename channel_traits<ChannelReference>::const_reference;
186};
187
189// PixelConcept
191
194template <typename ChannelReference, typename ColorSpace>
195struct is_pixel< planar_pixel_reference<ChannelReference, ColorSpace>>
196 : std::true_type
197{};
198
200// HomogeneousPixelBasedConcept
202
205template <typename ChannelReference, typename ColorSpace>
206struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
207 using type = ColorSpace;
208};
209
212template <typename ChannelReference, typename ColorSpace>
213struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
214 using type = typename layout<ColorSpace>::channel_mapping_t;
215};
216
219template <typename ChannelReference, typename ColorSpace>
220struct is_planar<planar_pixel_reference<ChannelReference, ColorSpace>>
221 : std::true_type
222{};
223
226template <typename ChannelReference, typename ColorSpace>
227struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
228 using type = typename channel_traits<ChannelReference>::value_type;
229};
230
231}} // namespace boost::gil
232
233namespace std {
234// We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
235// swap with 'left bias':
236// - swap between proxy and anything
237// - swap between value type and proxy
238// - swap between proxy and proxy
239// Having three overloads allows us to swap between different (but compatible) models of PixelConcept
240
243template <typename CR, typename CS, typename R> inline
245 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
246}
247
250template <typename CR, typename CS> inline
252 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
253}
254
257template <typename CR, typename CS> inline
259 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
260}
261
262} // namespace std
263
264#endif
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:265
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:59
A reference proxy to a planar pixel.
Definition planar_pixel_reference.hpp:46