Generic Image Library: image_view.hpp Source File

###  | #  |

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

image_view.hpp
Go to the documentation of this file.
1 /*
2 Copyright 2005-2007 Adobe Systems Incorporated
3
4 Use, modification and distribution are subject to the Boost Software License,
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt).
7
8 See http://opensource.adobe.com/gil for most recent version including documentation.
9 */
10 /*************************************************************************************************/
11
12 #ifndef GIL_IMAGE_VIEW_H
13 #define GIL_IMAGE_VIEW_H
14
23
24 #include <cstddef>
25 #include <iterator>
26 #include "gil_config.hpp"
27 #include "iterator_from_2d.hpp"
28
29 //#ifdef _MSC_VER
30 //#pragma warning(push)
31 //#pragma warning(disable : 4244) // conversion from 'gil::image<V,Alloc>::coord_t' to 'int', possible loss of data (visual studio compiler doesn't realize that the two types are the same)
32 //#endif
33
34 namespace boost { namespace gil {
35
67 template <typename Loc> // Models 2D Pixel Locator
68 class image_view {
69 public:
70
71 // typedefs required by ConstRandomAccessNDImageViewConcept
72 static const std::size_t num_dimensions=2;
73 typedef typename Loc::value_type value_type;
74 typedef typename Loc::reference reference; // result of dereferencing
75 typedef typename Loc::coord_t coord_t; // 1D difference type (same for all dimensions)
76 typedef coord_t difference_type; // result of operator-(1d_iterator,1d_iterator)
77 typedef typename Loc::point_t point_t;
78 typedef Loc locator;
79 typedef image_view<typename Loc::const_t> const_t; // same as this type, but over const values
80 template <std::size_t D> struct axis {
81 typedef typename Loc::template axis<D>::coord_t coord_t; // difference_type along each dimension
82 typedef typename Loc::template axis<D>::iterator iterator; // 1D iterator type along each dimension
83 };
84 typedef iterator_from_2d<Loc> iterator; // 1D iterator type for each pixel left-to-right inside top-to-bottom
85 typedef std::reverse_iterator<iterator> reverse_iterator;
86 typedef std::size_t size_type;
87
88 // typedefs required by ConstRandomAccess2DImageViewConcept
89 typedef locator xy_locator;
90 typedef typename xy_locator::x_iterator x_iterator; // pixel iterator along a row
91 typedef typename xy_locator::y_iterator y_iterator; // pixel iterator along a column
92 typedef typename xy_locator::x_coord_t x_coord_t;
93 typedef typename xy_locator::y_coord_t y_coord_t;
94
95 template <typename Deref> struct add_deref {
96 typedef image_view<typename Loc::template add_deref<Deref>::type> type;
97 static type make(const image_view<Loc>& iv, const Deref& d) { return type(iv.dimensions(), Loc::template add_deref<Deref>::make(iv.pixels(),d)); }
98 };
99
100 image_view() : _dimensions(0,0) {}
101 template <typename View> image_view(const View& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
102
103 template <typename L2> image_view(const point_t& sz , const L2& loc) : _dimensions(sz), _pixels(loc) {}
104 template <typename L2> image_view(coord_t width, coord_t height, const L2& loc) : _dimensions(x_coord_t(width),y_coord_t(height)), _pixels(loc) {}
105
106 template <typename View> image_view& operator=(const View& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
107 image_view& operator=(const image_view& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
108
109 template <typename View> bool operator==(const View& v) const { return pixels()==v.pixels() && dimensions()==v.dimensions(); }
110 template <typename View> bool operator!=(const View& v) const { return !(*this==v); }
111
112 template <typename L2> friend void swap(image_view<L2>& x, image_view<L2>& y);
113
114 const point_t& dimensions() const { return _dimensions; }
115 const locator& pixels() const { return _pixels; }
116 x_coord_t width() const { return dimensions().x; }
117 y_coord_t height() const { return dimensions().y; }
118 std::size_t num_channels() const { return gil::num_channels<value_type>::value; }
119 bool is_1d_traversable() const { return _pixels.is_1d_traversable(width()); }
120
121 //\{@
123 size_type size() const { return width()*height(); }
124 iterator begin() const { return iterator(_pixels,_dimensions.x); }
125 iterator end() const { return begin()+(difference_type)size(); } // potential performance problem!
126 reverse_iterator rbegin() const { return reverse_iterator(end()); }
127 reverse_iterator rend() const { return reverse_iterator(begin()); }
128 reference operator[](difference_type i) const { return begin()[i]; } // potential performance problem!
129 iterator at(difference_type i)const { return begin()+i; }
130 iterator at(const point_t& p) const { return begin()+p.y*width()+p.x; }
131 iterator at(x_coord_t x, y_coord_t y)const { return begin()+y*width()+x; }
132
133 //\}@
134
135 //\{@
137 reference operator()(const point_t& p) const { return _pixels(p.x,p.y); }
138 reference operator()(x_coord_t x, y_coord_t y)const { return _pixels(x,y); }
139 template <std::size_t D> typename axis<D>::iterator axis_iterator(const point_t& p) const { return _pixels.axis_iterator<D>(p); }
140 xy_locator xy_at(x_coord_t x, y_coord_t y) const { return _pixels+point_t(x_coord_t(x),y_coord_t(y)); }
141 locator xy_at(const point_t& p) const { return _pixels+p; }
142 //\}@
143
144 //\{@
146 x_iterator x_at(x_coord_t x, y_coord_t y) const { return _pixels.x_at(x,y); }
147 x_iterator x_at(const point_t& p) const { return _pixels.x_at(p); }
148 x_iterator row_begin(y_coord_t y) const { return x_at(0,y); }
149 x_iterator row_end(y_coord_t y) const { return x_at(width(),y); }
150 //\}@
151
152 //\{@
154 y_iterator y_at(x_coord_t x, y_coord_t y) const { return xy_at(x,y).y(); }
155 y_iterator y_at(const point_t& p) const { return xy_at(p).y(); }
156 y_iterator col_begin(x_coord_t x) const { return y_at(x,0); }
157 y_iterator col_end(x_coord_t x) const { return y_at(x,height()); }
158 //\}@
159
160 private:
161 template <typename L2> friend class image_view;
162
163 point_t _dimensions;
164 xy_locator _pixels;
165 };
166
167 template <typename L2>
168 inline void swap(image_view<L2>& x, image_view<L2>& y) {
169 using std::swap;
170 swap(x._dimensions,y._dimensions);
171 swap(x._pixels, y._pixels); // TODO: Extend further
172 }
173
175 // PixelBasedConcept
177
178 template <typename L>
179 struct channel_type<image_view<L> > : public channel_type<L> {};
180
181 template <typename L>
182 struct color_space_type<image_view<L> > : public color_space_type<L> {};
183
184 template <typename L>
185 struct channel_mapping_type<image_view<L> > : public channel_mapping_type<L> {};
186
187 template <typename L>
188 struct is_planar<image_view<L> > : public is_planar<L> {};
189
191 // HasDynamicXStepTypeConcept
193
194 template <typename L>
195 struct dynamic_x_step_type<image_view<L> > {
196 typedef image_view<typename dynamic_x_step_type<L>::type> type;
197 };
198
200 // HasDynamicYStepTypeConcept
202
203 template <typename L>
204 struct dynamic_y_step_type<image_view<L> > {
205 typedef image_view<typename dynamic_y_step_type<L>::type> type;
206 };
207
209 // HasTransposedTypeConcept
211
212 template <typename L>
213 struct transposed_type<image_view<L> > {
214 typedef image_view<typename transposed_type<L>::type> type;
215 };
216
217 } } // namespace boost::gil
218
219 //#ifdef _MSC_VER
220 //#pragma warning(pop)
221 //#endif
222
223 #endif
boost::gil::image_view
A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept.
Definition: image_view.hpp:68
boost::gil::iterator_from_2d
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept.
Definition: iterator_from_2d.hpp:52
gil_config.hpp
GIL configuration file.
boost::gil::size
Returns an MPL integral type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:61
boost::gil::num_channels
Returns the number of channels of a pixel-based GIL construct.
Definition: gil_concept.hpp:66
iterator_from_2d.hpp
pixel step iterator, pixel image iterator and pixel dereference iterator