00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef GIL_IMAGE_VIEW_H
00010 #define GIL_IMAGE_VIEW_H
00011
00020
00021 #include "gil_config.hpp"
00022 #include <cstddef>
00023 #include <iterator>
00024 #include "pixel_iterator.hpp"
00025
00026 #ifdef _MSC_VER
00027 #pragma warning(push)
00028 #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)
00029 #endif
00030
00031 ADOBE_GIL_NAMESPACE_BEGIN
00032
00059 template <typename LOC> class pixel_image_iterator;
00060
00061 template <typename LOC>
00062 class image_view {
00063 GIL_CLASS_REQUIRE(LOC, GIL, PixelLocatorConcept);
00064 public:
00065
00066
00067 static const std::size_t num_dimensions=2;
00068 typedef typename LOC::value_type value_type;
00069 typedef typename LOC::pixel_t pixel_t;
00070 typedef typename LOC::reference reference;
00071 typedef typename LOC::coord_t coord_t;
00072 typedef coord_t difference_type;
00073 typedef pixel_t domain_t;
00074 typedef typename LOC::point_t point_t;
00075 typedef LOC locator;
00076 typedef image_view<typename LOC::const_t> const_t;
00077 template <std::size_t D> struct axis {
00078 typedef typename LOC::template axis<D>::coord_t coord_t;
00079 typedef typename LOC::template axis<D>::iterator iterator;
00080 };
00081 typedef pixel_image_iterator<LOC> iterator;
00082 typedef std::reverse_iterator<iterator> reverse_iterator;
00083 typedef std::size_t size_type;
00084
00085
00086 typedef locator xy_locator;
00087 typedef typename xy_locator::x_iterator x_iterator;
00088 typedef typename xy_locator::y_iterator y_iterator;
00089 typedef typename xy_locator::x_coord_t x_coord_t;
00090 typedef typename xy_locator::y_coord_t y_coord_t;
00091
00092
00093 typedef image_view<typename LOC::dynamic_step_t> dynamic_step_t;
00094 typedef typename LOC::channel_t channel_t;
00095 typedef typename LOC::color_space_t color_space_t;
00096 BOOST_STATIC_CONSTANT(int, num_channels=locator::num_channels);
00097
00098 image_view() : _dimensions(0,0) {}
00099 template <typename VIEW> image_view(const VIEW& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
00100
00101 template <typename L2> image_view(const point_t& sz , const L2& loc) : _dimensions(sz), _pixels(loc) {}
00102 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) {}
00103 image_view(const point_t& sz, const x_iterator& x_it, coord_t row_bytes) : _dimensions(sz), _pixels(x_it, row_bytes) {}
00104 image_view(coord_t width, coord_t height, const x_iterator& x_it, coord_t row_bytes) : _dimensions(x_coord_t(width),y_coord_t(height)), _pixels(x_it, row_bytes) {}
00105
00106 template <typename VIEW> image_view& operator=(const VIEW& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
00107 image_view& operator=(const image_view& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
00108
00109 template <typename VIEW> bool operator==(const VIEW& v) const { return pixels()==v.pixels() && dimensions()==v.dimensions(); }
00110 template <typename VIEW> bool operator!=(const VIEW& v) const { return !(*this==v); }
00111
00112 template <typename L2> friend void swap(image_view<L2>& x, image_view<L2>& y);
00113
00114 const point_t& dimensions() const { return _dimensions; }
00115 const locator& pixels() const { return _pixels; }
00116 x_coord_t width() const { return dimensions().x; }
00117 y_coord_t height() const { return dimensions().y; }
00118
00119 difference_type row_bytes() const { return _pixels.row_bytes(); }
00120 difference_type pix_bytestep() const { return _pixels.pix_bytestep(); }
00121
00122
00124 size_type size() const { return width()*height(); }
00125 iterator begin() const { return iterator(_pixels,_dimensions.x); }
00126 iterator end() const { return begin()+size(); }
00127 reverse_iterator rbegin() const { return reverse_iterator(end()); }
00128 reverse_iterator rend() const { return reverse_iterator(begin()); }
00129 reference operator[](difference_type i) const { return begin()[i]; }
00130 iterator at(difference_type i)const { return begin()+i; }
00131 iterator at(const point_t& p) const { return begin()+p.y*width()+p.x; }
00132 iterator at(x_coord_t x, y_coord_t y)const { return begin()+y*width()+x; }
00133
00134
00135
00136
00138 reference operator()(const point_t& p) const { return _pixels(p.x,p.y); }
00139 reference operator()(x_coord_t x, y_coord_t y)const { return _pixels(x,y); }
00140 template <std::size_t D> typename axis<D>::iterator axis_iterator(const point_t& p) const { return _pixels.axis_iterator<D>(p); }
00141 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)); }
00142 locator xy_at(const point_t& p) const { return _pixels+p; }
00143
00144
00145
00147 x_iterator x_at(x_coord_t x, y_coord_t y) const { return _pixels.x_at(x,y); }
00148 x_iterator x_at(const point_t& p) const { return _pixels.x_at(p); }
00149 x_iterator row_begin(y_coord_t y) const { return x_at(0,y); }
00150 x_iterator row_end(y_coord_t y) const { return x_at(width(),y); }
00151
00152
00153
00155 y_iterator y_at(x_coord_t x, y_coord_t y) const { return xy_at(x,y).y(); }
00156 y_iterator y_at(const point_t& p) const { return xy_at(p).y(); }
00157 y_iterator col_begin(x_coord_t x) const { return y_at(x,0); }
00158 y_iterator col_end(x_coord_t x) const { return y_at(x,height()); }
00159
00160
00161 private:
00162 template <typename L2> friend class image_view;
00163
00164 point_t _dimensions;
00165 xy_locator _pixels;
00166 };
00167
00168 template <typename L2>
00169 inline void swap(image_view<L2>& x, image_view<L2>& y) {
00170 std::swap(x._dimensions,y._dimensions);
00171 std::swap(x._pixels, y._pixels);
00172 }
00173
00177
00179
00181 template <typename T> int get_num_channels(const T&) { return T::color_space_t::num_channels; }
00182
00184 template <typename T> typename T::x_coord_t get_width(const T& a) { return a.width(); }
00185
00187 template <typename T> typename T::y_coord_t get_height(const T& a) { return a.height(); }
00188
00190 template <typename T> typename T::point_t get_dimensions(const T& v) { return v.dimensions(); }
00192
00193 ADOBE_GIL_NAMESPACE_END
00194
00195 #ifdef _MSC_VER
00196 #pragma warning(pop)
00197 #endif
00198
00199 #endif