12 #ifndef BOOST_GIL_IMAGE_VIEW_HPP
13 #define BOOST_GIL_IMAGE_VIEW_HPP
35 namespace boost {
namespace gil {
68 template <
typename Loc>
73 static const std::size_t num_dimensions=2;
74 typedef typename Loc::value_type value_type;
75 typedef typename Loc::reference reference;
76 typedef typename Loc::coord_t coord_t;
77 typedef coord_t difference_type;
78 typedef typename Loc::point_t point_t;
81 template <std::
size_t D>
struct axis {
82 typedef typename Loc::template axis<D>::coord_t coord_t;
83 typedef typename Loc::template axis<D>::iterator
iterator;
86 typedef std::reverse_iterator<iterator> reverse_iterator;
87 typedef std::size_t size_type;
90 typedef locator xy_locator;
91 typedef typename xy_locator::x_iterator x_iterator;
92 typedef typename xy_locator::y_iterator y_iterator;
93 typedef typename xy_locator::x_coord_t x_coord_t;
94 typedef typename xy_locator::y_coord_t y_coord_t;
96 template <
typename Deref>
struct add_deref {
98 static type make(
const image_view<Loc>& iv,
const Deref& d) {
return type(iv.dimensions(), Loc::template add_deref<Deref>::make(iv.pixels(),d)); }
102 template <
typename View>
image_view(
const View& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
104 template <
typename L2>
image_view(
const point_t& sz ,
const L2& loc) : _dimensions(sz), _pixels(loc) {}
105 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) {}
107 template <
typename View>
image_view& operator=(
const View& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions();
return *
this; }
108 image_view& operator=(
const image_view& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions();
return *
this; }
110 template <
typename View>
bool operator==(
const View& v)
const {
return pixels()==v.pixels() && dimensions()==v.dimensions(); }
111 template <
typename View>
bool operator!=(
const View& v)
const {
return !(*
this==v); }
115 const point_t& dimensions()
const {
return _dimensions; }
116 const locator& pixels()
const {
return _pixels; }
117 x_coord_t width()
const {
return dimensions().x; }
118 y_coord_t height()
const {
return dimensions().y; }
120 bool is_1d_traversable()
const {
return _pixels.is_1d_traversable(width()); }
124 size_type
size()
const {
return width()*height(); }
126 iterator end()
const {
return begin()+(difference_type)
size(); }
127 reverse_iterator rbegin()
const {
return reverse_iterator(end()); }
128 reverse_iterator rend()
const {
return reverse_iterator(begin()); }
129 reference operator[](difference_type i)
const {
return begin()[i]; }
130 iterator at(difference_type i)
const {
return begin()+i; }
131 iterator at(
const point_t& p)
const {
return begin()+p.y*width()+p.x; }
132 iterator at(x_coord_t x, y_coord_t y)
const {
return begin()+y*width()+x; }
138 reference operator()(
const point_t& p)
const {
return _pixels(p.x,p.y); }
139 reference operator()(x_coord_t x, y_coord_t y)
const {
return _pixels(x,y); }
140 template <std::
size_t D>
typename axis<D>::iterator axis_iterator(
const point_t& p)
const {
return _pixels.axis_iterator<D>(p); }
141 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)); }
142 locator xy_at(
const point_t& p)
const {
return _pixels+p; }
147 x_iterator x_at(x_coord_t x, y_coord_t y)
const {
return _pixels.x_at(x,y); }
148 x_iterator x_at(
const point_t& p)
const {
return _pixels.x_at(p); }
149 x_iterator row_begin(y_coord_t y)
const {
return x_at(0,y); }
150 x_iterator row_end(y_coord_t y)
const {
return x_at(width(),y); }
155 y_iterator y_at(x_coord_t x, y_coord_t y)
const {
return xy_at(x,y).y(); }
156 y_iterator y_at(
const point_t& p)
const {
return xy_at(p).y(); }
157 y_iterator col_begin(x_coord_t x)
const {
return y_at(x,0); }
158 y_iterator col_end(x_coord_t x)
const {
return y_at(x,height()); }
162 template <
typename L2>
friend class image_view;
168 template <
typename L2>
171 swap(x._dimensions,y._dimensions);
172 swap(x._pixels, y._pixels);
179 template <
typename L>
180 struct channel_type<image_view<L> > :
public channel_type<L> {};
182 template <
typename L>
183 struct color_space_type<image_view<L> > :
public color_space_type<L> {};
185 template <
typename L>
186 struct channel_mapping_type<image_view<L> > :
public channel_mapping_type<L> {};
188 template <
typename L>
189 struct is_planar<image_view<L> > :
public is_planar<L> {};
195 template <
typename L>
196 struct dynamic_x_step_type<image_view<L> > {
197 typedef image_view<typename dynamic_x_step_type<L>::type> type;
204 template <
typename L>
205 struct dynamic_y_step_type<image_view<L> > {
206 typedef image_view<typename dynamic_y_step_type<L>::type> type;
213 template <
typename L>
214 struct transposed_type<image_view<L> > {
215 typedef image_view<typename transposed_type<L>::type> type;
A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept.
Definition: image_view.hpp:69
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept.
Definition: iterator_from_2d.hpp:54
Returns an MPL integral type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:60
Returns the number of channels of a pixel-based GIL construct.
Definition: concept.hpp:68
pixel step iterator, pixel image iterator and pixel dereference iterator