12 #ifndef GIL_IMAGE_VIEW_H
13 #define GIL_IMAGE_VIEW_H
34 namespace boost {
namespace gil {
67 template <
typename Loc>
72 static const std::size_t num_dimensions=2;
73 typedef typename Loc::value_type value_type;
74 typedef typename Loc::reference reference;
75 typedef typename Loc::coord_t coord_t;
76 typedef coord_t difference_type;
77 typedef typename Loc::point_t point_t;
80 template <std::
size_t D>
struct axis {
81 typedef typename Loc::template axis<D>::coord_t coord_t;
82 typedef typename Loc::template axis<D>::iterator
iterator;
85 typedef std::reverse_iterator<iterator> reverse_iterator;
86 typedef std::size_t size_type;
89 typedef locator xy_locator;
90 typedef typename xy_locator::x_iterator x_iterator;
91 typedef typename xy_locator::y_iterator y_iterator;
92 typedef typename xy_locator::x_coord_t x_coord_t;
93 typedef typename xy_locator::y_coord_t y_coord_t;
95 template <
typename Deref>
struct add_deref {
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)); }
101 template <
typename View>
image_view(
const View& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
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) {}
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; }
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); }
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; }
119 bool is_1d_traversable()
const {
return _pixels.is_1d_traversable(width()); }
123 size_type
size()
const {
return width()*height(); }
125 iterator end()
const {
return begin()+(difference_type)
size(); }
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]; }
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; }
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; }
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); }
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()); }
161 template <
typename L2>
friend class image_view;
167 template <
typename L2>
170 swap(x._dimensions,y._dimensions);
171 swap(x._pixels, y._pixels);
178 template <
typename L>
179 struct channel_type<image_view<L> > :
public channel_type<L> {};
181 template <
typename L>
182 struct color_space_type<image_view<L> > :
public color_space_type<L> {};
184 template <
typename L>
185 struct channel_mapping_type<image_view<L> > :
public channel_mapping_type<L> {};
187 template <
typename L>
188 struct is_planar<image_view<L> > :
public is_planar<L> {};
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;
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;
212 template <
typename L>
213 struct transposed_type<image_view<L> > {
214 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:68
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept.
Definition: iterator_from_2d.hpp:52
Returns an MPL integral type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:61
Returns the number of channels of a pixel-based GIL construct.
Definition: gil_concept.hpp:66
pixel step iterator, pixel image iterator and pixel dereference iterator