Chris@16
|
1 /*
|
Chris@16
|
2 Copyright 2005-2007 Adobe Systems Incorporated
|
Chris@16
|
3
|
Chris@16
|
4 Use, modification and distribution are subject to the Boost Software License,
|
Chris@16
|
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt).
|
Chris@16
|
7
|
Chris@16
|
8 See http://stlab.adobe.com/gil for most recent version including documentation.
|
Chris@16
|
9 */
|
Chris@16
|
10
|
Chris@16
|
11 /*************************************************************************************************/
|
Chris@16
|
12
|
Chris@16
|
13 #ifndef GIL_PLANAR_REF_H
|
Chris@16
|
14 #define GIL_PLANAR_REF_H
|
Chris@16
|
15
|
Chris@16
|
16 ////////////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
17 /// \file
|
Chris@16
|
18 /// \brief planar pixel reference class
|
Chris@16
|
19 /// \author Lubomir Bourdev and Hailin Jin \n
|
Chris@16
|
20 /// Adobe Systems Incorporated
|
Chris@16
|
21 /// \date 2005-2007 \n Last updated on September 28, 2006
|
Chris@16
|
22 ///
|
Chris@16
|
23 ////////////////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/mpl/range_c.hpp>
|
Chris@16
|
26 #include "gil_config.hpp"
|
Chris@16
|
27 #include "gil_concept.hpp"
|
Chris@16
|
28 #include "color_base.hpp"
|
Chris@16
|
29 #include "channel.hpp"
|
Chris@16
|
30 #include "pixel.hpp"
|
Chris@16
|
31 #include "planar_pixel_iterator.hpp"
|
Chris@16
|
32
|
Chris@16
|
33 namespace boost { namespace gil {
|
Chris@16
|
34
|
Chris@16
|
35 /// \defgroup ColorBaseModelPlanarRef planar_pixel_reference
|
Chris@16
|
36 /// \ingroup ColorBaseModel
|
Chris@16
|
37 /// \brief A homogeneous color base whose element is a channel reference. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
|
Chris@16
|
38 /// This class is used as a reference proxy to a planar pixel.
|
Chris@16
|
39
|
Chris@16
|
40 /// \defgroup PixelModelPlanarRef planar_pixel_reference
|
Chris@16
|
41 /// \ingroup PixelModel
|
Chris@16
|
42 /// \brief A reference proxy to a planar pixel. Models HomogeneousColorBaseConcept, HomogeneousPixelConcept.
|
Chris@16
|
43
|
Chris@16
|
44
|
Chris@16
|
45 /// \ingroup PixelModelPlanarRef ColorBaseModelPlanarRef PixelBasedModel
|
Chris@16
|
46 /// \brief A reference proxy to a planar pixel. Models: HomogeneousColorBaseConcept, HomogeneousPixelConcept
|
Chris@16
|
47 ///
|
Chris@16
|
48 /// A reference to a planar pixel is a proxy class containing references to each of the corresponding channels.
|
Chris@16
|
49 ///
|
Chris@16
|
50 template <typename ChannelReference, typename ColorSpace> // ChannelReference is a channel reference (const or mutable)
|
Chris@16
|
51 struct planar_pixel_reference
|
Chris@16
|
52 : public detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> {
|
Chris@16
|
53 typedef detail::homogeneous_color_base<ChannelReference,layout<ColorSpace>,mpl::size<ColorSpace>::value> parent_t;
|
Chris@16
|
54 private:
|
Chris@16
|
55 // These three are only defined for homogeneous pixels
|
Chris@16
|
56 typedef typename channel_traits<ChannelReference>::value_type channel_t;
|
Chris@16
|
57 typedef typename channel_traits<ChannelReference>::const_reference channel_const_reference;
|
Chris@16
|
58 public:
|
Chris@16
|
59 BOOST_STATIC_CONSTANT(bool, is_mutable = channel_traits<ChannelReference>::is_mutable);
|
Chris@16
|
60 typedef pixel<channel_t,layout<ColorSpace> > value_type;
|
Chris@16
|
61 typedef planar_pixel_reference reference;
|
Chris@16
|
62 typedef planar_pixel_reference<channel_const_reference,ColorSpace> const_reference;
|
Chris@16
|
63
|
Chris@16
|
64 planar_pixel_reference(ChannelReference v0, ChannelReference v1) : parent_t(v0,v1) {}
|
Chris@16
|
65 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2) : parent_t(v0,v1,v2) {}
|
Chris@16
|
66 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3) : parent_t(v0,v1,v2,v3) {}
|
Chris@16
|
67 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4) : parent_t(v0,v1,v2,v3,v4) {}
|
Chris@16
|
68 planar_pixel_reference(ChannelReference v0, ChannelReference v1, ChannelReference v2, ChannelReference v3, ChannelReference v4, ChannelReference v5) : parent_t(v0,v1,v2,v3,v4,v5) {}
|
Chris@16
|
69
|
Chris@16
|
70 template <typename P> planar_pixel_reference(const P& p) : parent_t(p) { check_compatible<P>();}
|
Chris@16
|
71
|
Chris@16
|
72 // PERFORMANCE_CHECK: Is this constructor necessary?
|
Chris@16
|
73 template <typename ChannelV, typename Mapping>
|
Chris@16
|
74 planar_pixel_reference(pixel<ChannelV,layout<ColorSpace,Mapping> >& p) : parent_t(p) { check_compatible<pixel<ChannelV,layout<ColorSpace,Mapping> > >();}
|
Chris@16
|
75
|
Chris@16
|
76 // Construct at offset from a given location
|
Chris@16
|
77 template <typename ChannelPtr> planar_pixel_reference(const planar_pixel_iterator<ChannelPtr,ColorSpace>& p, std::ptrdiff_t diff) : parent_t(p,diff) {}
|
Chris@16
|
78
|
Chris@16
|
79 const planar_pixel_reference& operator=(const planar_pixel_reference& p) const { static_copy(p,*this); return *this; }
|
Chris@16
|
80 template <typename P> const planar_pixel_reference& operator=(const P& p) const { check_compatible<P>(); static_copy(p,*this); return *this; }
|
Chris@16
|
81
|
Chris@16
|
82 // This overload is necessary for a compiler implementing Core Issue 574
|
Chris@16
|
83 // to prevent generation of an implicit copy assignment operator (the reason
|
Chris@16
|
84 // for generating implicit copy assignment operator is that according to
|
Chris@16
|
85 // Core Issue 574, a cv-qualified assignment operator is not considered
|
Chris@16
|
86 // "copy assignment operator").
|
Chris@16
|
87 // EDG implemented Core Issue 574 starting with EDG Version 3.8. I'm not
|
Chris@16
|
88 // sure why they did it for a template member function as well.
|
Chris@16
|
89 #if BOOST_WORKAROUND(__HP_aCC, >= 61700) || BOOST_WORKAROUND(__INTEL_COMPILER, >= 1000)
|
Chris@16
|
90 const planar_pixel_reference& operator=(const planar_pixel_reference& p) { static_copy(p,*this); return *this; }
|
Chris@16
|
91 template <typename P> const planar_pixel_reference& operator=(const P& p) { check_compatible<P>(); static_copy(p,*this); return *this; }
|
Chris@16
|
92 #endif
|
Chris@16
|
93
|
Chris@16
|
94 template <typename P> bool operator==(const P& p) const { check_compatible<P>(); return static_equal(*this,p); }
|
Chris@16
|
95 template <typename P> bool operator!=(const P& p) const { return !(*this==p); }
|
Chris@16
|
96
|
Chris@16
|
97 ChannelReference operator[](std::size_t i) const { return this->at_c_dynamic(i); }
|
Chris@16
|
98
|
Chris@16
|
99 const planar_pixel_reference* operator->() const { return this; }
|
Chris@16
|
100 private:
|
Chris@16
|
101 template <typename Pixel> static void check_compatible() { gil_function_requires<PixelsCompatibleConcept<Pixel,planar_pixel_reference> >(); }
|
Chris@16
|
102 };
|
Chris@16
|
103
|
Chris@16
|
104 /////////////////////////////
|
Chris@16
|
105 // ColorBasedConcept
|
Chris@16
|
106 /////////////////////////////
|
Chris@16
|
107
|
Chris@16
|
108 template <typename ChannelReference, typename ColorSpace, int K>
|
Chris@16
|
109 struct kth_element_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
|
Chris@16
|
110 typedef ChannelReference type;
|
Chris@16
|
111 };
|
Chris@16
|
112
|
Chris@16
|
113 template <typename ChannelReference, typename ColorSpace, int K>
|
Chris@16
|
114 struct kth_element_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K> {
|
Chris@16
|
115 typedef ChannelReference type;
|
Chris@16
|
116 };
|
Chris@16
|
117
|
Chris@16
|
118 template <typename ChannelReference, typename ColorSpace, int K>
|
Chris@16
|
119 struct kth_element_const_reference_type<planar_pixel_reference<ChannelReference,ColorSpace>, K>
|
Chris@16
|
120 : public add_reference<typename add_const<ChannelReference>::type>
|
Chris@16
|
121 {
|
Chris@16
|
122 // typedef typename channel_traits<ChannelReference>::const_reference type;
|
Chris@16
|
123 };
|
Chris@16
|
124
|
Chris@16
|
125 /////////////////////////////
|
Chris@16
|
126 // PixelConcept
|
Chris@16
|
127 /////////////////////////////
|
Chris@16
|
128
|
Chris@16
|
129 /// \brief Metafunction predicate that flags planar_pixel_reference as a model of PixelConcept. Required by PixelConcept
|
Chris@16
|
130 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
131 template <typename ChannelReference, typename ColorSpace>
|
Chris@16
|
132 struct is_pixel< planar_pixel_reference<ChannelReference,ColorSpace> > : public mpl::true_{};
|
Chris@16
|
133
|
Chris@16
|
134 /////////////////////////////
|
Chris@16
|
135 // HomogeneousPixelBasedConcept
|
Chris@16
|
136 /////////////////////////////
|
Chris@16
|
137
|
Chris@16
|
138 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
|
Chris@16
|
139 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
140 template <typename ChannelReference, typename ColorSpace>
|
Chris@16
|
141 struct color_space_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
|
Chris@16
|
142 typedef ColorSpace type;
|
Chris@16
|
143 };
|
Chris@16
|
144
|
Chris@16
|
145 /// \brief Specifies the color space type of a planar pixel reference. Required by PixelBasedConcept
|
Chris@16
|
146 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
147 template <typename ChannelReference, typename ColorSpace>
|
Chris@16
|
148 struct channel_mapping_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
|
Chris@16
|
149 typedef typename layout<ColorSpace>::channel_mapping_t type;
|
Chris@16
|
150 };
|
Chris@16
|
151
|
Chris@16
|
152 /// \brief Specifies that planar_pixel_reference represents a planar construct. Required by PixelBasedConcept
|
Chris@16
|
153 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
154 template <typename ChannelReference, typename ColorSpace>
|
Chris@16
|
155 struct is_planar<planar_pixel_reference<ChannelReference,ColorSpace> > : mpl::true_ {};
|
Chris@16
|
156
|
Chris@16
|
157 /// \brief Specifies the color space type of a planar pixel reference. Required by HomogeneousPixelBasedConcept
|
Chris@16
|
158 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
159 template <typename ChannelReference, typename ColorSpace>
|
Chris@16
|
160 struct channel_type<planar_pixel_reference<ChannelReference,ColorSpace> > {
|
Chris@16
|
161 typedef typename channel_traits<ChannelReference>::value_type type;
|
Chris@16
|
162 };
|
Chris@16
|
163
|
Chris@16
|
164 } } // namespace boost::gil
|
Chris@16
|
165
|
Chris@16
|
166 namespace std {
|
Chris@16
|
167 // We are forced to define swap inside std namespace because on some platforms (Visual Studio 8) STL calls swap qualified.
|
Chris@16
|
168 // swap with 'left bias':
|
Chris@16
|
169 // - swap between proxy and anything
|
Chris@16
|
170 // - swap between value type and proxy
|
Chris@16
|
171 // - swap between proxy and proxy
|
Chris@16
|
172 // Having three overloads allows us to swap between different (but compatible) models of PixelConcept
|
Chris@16
|
173
|
Chris@16
|
174 /// \brief swap for planar_pixel_reference
|
Chris@16
|
175 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
176 template <typename CR, typename CS, typename R> inline
|
Chris@16
|
177 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, R& y) {
|
Chris@16
|
178 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
|
Chris@16
|
179 }
|
Chris@16
|
180
|
Chris@16
|
181
|
Chris@16
|
182 /// \brief swap for planar_pixel_reference
|
Chris@16
|
183 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
184 template <typename CR, typename CS> inline
|
Chris@16
|
185 void swap(typename boost::gil::planar_pixel_reference<CR,CS>::value_type& x, const boost::gil::planar_pixel_reference<CR,CS> y) {
|
Chris@16
|
186 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
|
Chris@16
|
187 }
|
Chris@16
|
188
|
Chris@16
|
189
|
Chris@16
|
190 /// \brief swap for planar_pixel_reference
|
Chris@16
|
191 /// \ingroup PixelModelPlanarRef
|
Chris@16
|
192 template <typename CR, typename CS> inline
|
Chris@16
|
193 void swap(const boost::gil::planar_pixel_reference<CR,CS> x, const boost::gil::planar_pixel_reference<CR,CS> y) {
|
Chris@16
|
194 boost::gil::swap_proxy<typename boost::gil::planar_pixel_reference<CR,CS>::value_type>(x,y);
|
Chris@16
|
195 }
|
Chris@16
|
196 } // namespace std
|
Chris@16
|
197
|
Chris@16
|
198 #endif
|