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