8 #ifndef BOOST_GIL_IMAGE_VIEW_HPP 9 #define BOOST_GIL_IMAGE_VIEW_HPP 11 #include <boost/gil/dynamic_step.hpp> 12 #include <boost/gil/iterator_from_2d.hpp> 17 namespace boost {
namespace gil {
50 template <
typename Loc>
55 static const std::size_t num_dimensions=2;
56 using value_type =
typename Loc::value_type;
57 using reference =
typename Loc::reference;
58 using coord_t =
typename Loc::coord_t;
59 using difference_type = coord_t;
60 using point_t =
typename Loc::point_t;
63 template <std::
size_t D>
struct axis
65 using coord_t =
typename Loc::template axis<D>::coord_t;
66 using iterator =
typename Loc::template axis<D>::iterator;
70 using const_reference =
typename const_t::reference;
71 using pointer =
typename std::iterator_traits<iterator>::pointer;
72 using reverse_iterator = std::reverse_iterator<iterator>;
73 using size_type = std::size_t;
76 using xy_locator = locator;
77 using x_iterator =
typename xy_locator::x_iterator;
78 using y_iterator =
typename xy_locator::y_iterator;
79 using x_coord_t =
typename xy_locator::x_coord_t;
80 using y_coord_t =
typename xy_locator::y_coord_t;
82 template <
typename Deref>
struct add_deref
87 return type(iv.dimensions(), Loc::template add_deref<Deref>::make(iv.pixels(),d));
92 template <
typename View>
image_view(
const View& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
94 template <
typename L2>
image_view(
const point_t& sz ,
const L2& loc) : _dimensions(sz), _pixels(loc) {}
95 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) {}
97 template <
typename View>
image_view& operator=(
const View& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions();
return *
this; }
98 image_view& operator=(
const image_view& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions();
return *
this; }
100 template <
typename View>
bool operator==(
const View& v)
const {
return pixels()==v.pixels() && dimensions()==v.dimensions(); }
101 template <
typename View>
bool operator!=(
const View& v)
const {
return !(*
this==v); }
120 bool empty()
const {
return !(width() > 0 && height() > 0); }
126 reference
front()
const {
return *begin(); }
132 reference
back()
const {
return *rbegin(); }
134 const point_t& dimensions()
const {
return _dimensions; }
135 const locator& pixels()
const {
return _pixels; }
136 x_coord_t width()
const {
return dimensions().x; }
137 y_coord_t height()
const {
return dimensions().y; }
139 bool is_1d_traversable()
const {
return _pixels.is_1d_traversable(width()); }
143 size_type
size()
const {
return width()*height(); }
145 iterator end()
const {
return begin()+(difference_type)
size(); }
146 reverse_iterator rbegin()
const {
return reverse_iterator(end()); }
147 reverse_iterator rend()
const {
return reverse_iterator(begin()); }
148 reference operator[](difference_type i)
const {
return begin()[i]; }
149 iterator at(difference_type i)
const {
return begin()+i; }
150 iterator at(
const point_t& p)
const {
return begin()+p.y*width()+p.x; }
151 iterator at(x_coord_t x, y_coord_t y)
const {
return begin()+y*width()+x; }
157 reference operator()(
const point_t& p)
const {
return _pixels(p.x,p.y); }
158 reference operator()(x_coord_t x, y_coord_t y)
const {
return _pixels(x,y); }
159 template <std::
size_t D>
typename axis<D>::iterator axis_iterator(
const point_t& p)
const {
return _pixels.template axis_iterator<D>(p); }
160 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)); }
161 locator xy_at(
const point_t& p)
const {
return _pixels+p; }
166 x_iterator x_at(x_coord_t x, y_coord_t y)
const {
return _pixels.x_at(x,y); }
167 x_iterator x_at(
const point_t& p)
const {
return _pixels.x_at(p); }
168 x_iterator row_begin(y_coord_t y)
const {
return x_at(0,y); }
169 x_iterator row_end(y_coord_t y)
const {
return x_at(width(),y); }
174 y_iterator y_at(x_coord_t x, y_coord_t y)
const {
return xy_at(x,y).y(); }
175 y_iterator y_at(
const point_t& p)
const {
return xy_at(p).y(); }
176 y_iterator col_begin(x_coord_t x)
const {
return y_at(x,0); }
177 y_iterator col_end(x_coord_t x)
const {
return y_at(x,height()); }
181 template <
typename L2>
friend class image_view;
187 template <
typename L2>
190 swap(x._dimensions,y._dimensions);
191 swap(x._pixels, y._pixels);
198 template <
typename L>
201 template <
typename L>
202 struct color_space_type<image_view<L> > :
public color_space_type<L> {};
204 template <
typename L>
205 struct channel_mapping_type<image_view<L> > :
public channel_mapping_type<L> {};
207 template <
typename L>
208 struct is_planar<image_view<L> > :
public is_planar<L> {};
214 template <
typename L>
223 template <
typename L>
232 template <
typename L>
Definition: algorithm.hpp:30
A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept.
Definition: image_view.hpp:51
void swap(const boost::gil::packed_channel_reference< BF, FB, NB, M > x, R &y)
swap for packed_channel_reference
Definition: channel.hpp:485
Provides 1D random-access navigation to the pixels of the image. Models: PixelIteratorConcept, PixelBasedConcept, HasDynamicXStepTypeConcept.
Definition: iterator_from_2d.hpp:42
reference back() const
Returns a reference to the last element in raster order.
Definition: image_view.hpp:132
void swap(image_view< Loc > &other)
Exchanges the elements of the current view with those of other in constant time.
Definition: image_view.hpp:110
Definition: image_view_factory.hpp:37
reference front() const
Returns a reference to the first element in raster order.
Definition: image_view.hpp:126
Base template for types that model HasDynamicYStepTypeConcept.
Definition: dynamic_step.hpp:21
bool empty() const
Returns true if the view has no elements, false otherwise.
Definition: image_view.hpp:120
Definition: color_convert.hpp:30
Returns an MPL integral type specifying the number of elements in a color base.
Definition: color_base_algorithm.hpp:46
Returns the number of channels of a pixel-based GIL construct.
Definition: locator.hpp:38
Base template for types that model HasDynamicXStepTypeConcept.
Definition: dynamic_step.hpp:17