annotate DEPENDENCIES/generic/include/boost/gil/image_view.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 /*
Chris@16 2 Copyright 2005-2007 Adobe Systems Incorporated
Chris@16 3
Chris@16 4 Use, modification and distribution are subject to the Boost Software License,
Chris@16 5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 6 http://www.boost.org/LICENSE_1_0.txt).
Chris@16 7
Chris@16 8 See http://opensource.adobe.com/gil for most recent version including documentation.
Chris@16 9 */
Chris@16 10 /*************************************************************************************************/
Chris@16 11
Chris@16 12 #ifndef GIL_IMAGE_VIEW_H
Chris@16 13 #define GIL_IMAGE_VIEW_H
Chris@16 14
Chris@16 15 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 16 /// \file
Chris@16 17 /// \brief image view class
Chris@16 18 /// \author Lubomir Bourdev and Hailin Jin \n
Chris@16 19 /// Adobe Systems Incorporated
Chris@16 20 /// \date 2005-2007 \n Last updated on February 12, 2007
Chris@16 21 ///
Chris@16 22 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 23
Chris@16 24 #include <cstddef>
Chris@16 25 #include <iterator>
Chris@16 26 #include "gil_config.hpp"
Chris@16 27 #include "iterator_from_2d.hpp"
Chris@16 28
Chris@16 29 //#ifdef _MSC_VER
Chris@16 30 //#pragma warning(push)
Chris@16 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)
Chris@16 32 //#endif
Chris@16 33
Chris@16 34 namespace boost { namespace gil {
Chris@16 35
Chris@16 36 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 37 /// \class image_view
Chris@16 38 /// \ingroup ImageViewModel PixelBasedModel
Chris@16 39 /// \brief A lightweight object that interprets memory as a 2D array of pixels. Models ImageViewConcept,PixelBasedConcept,HasDynamicXStepTypeConcept,HasDynamicYStepTypeConcept,HasTransposedTypeConcept
Chris@16 40 ///
Chris@16 41 /// Image view consists of a pixel 2D locator (defining the mechanism for navigating in 2D)
Chris@16 42 /// and the image dimensions.
Chris@16 43 ///
Chris@16 44 /// Image views to images are what ranges are to STL containers. They are lightweight objects,
Chris@16 45 /// that don't own the pixels. It is the user's responsibility that the underlying data remains
Chris@16 46 /// valid for the lifetime of the image view.
Chris@16 47 ///
Chris@16 48 /// Similar to iterators and ranges, constness of views does not extend to constness of pixels.
Chris@16 49 /// A const \p image_view does not allow changing its location in memory (resizing, moving) but does
Chris@16 50 /// not prevent one from changing the pixels. The latter requires an image view whose value_type
Chris@16 51 /// is const.
Chris@16 52 ///
Chris@16 53 /// Images have interfaces consistent with STL 1D random access containers, so they can be used
Chris@16 54 /// directly in STL algorithms like:
Chris@16 55 /// \code
Chris@16 56 /// std::fill(img.begin(), img.end(), red_pixel);
Chris@16 57 /// \endcode
Chris@16 58 ///
Chris@16 59 /// In addition, horizontal, vertical and 2D random access iterators are provided.
Chris@16 60 ///
Chris@16 61 /// Note also that \p image_view does not require that its element type be a pixel. It could be
Chris@16 62 /// instantiated with a locator whose \p value_type models only \p Regular. In this case the image
Chris@16 63 /// view models the weaker RandomAccess2DImageViewConcept, and does not model PixelBasedConcept.
Chris@16 64 /// Many generic algorithms don't require the elements to be pixels.
Chris@16 65 ///
Chris@16 66 ////////////////////////////////////////////////////////////////////////////////////////
Chris@16 67 template <typename Loc> // Models 2D Pixel Locator
Chris@16 68 class image_view {
Chris@16 69 public:
Chris@16 70
Chris@16 71 // typedefs required by ConstRandomAccessNDImageViewConcept
Chris@16 72 static const std::size_t num_dimensions=2;
Chris@16 73 typedef typename Loc::value_type value_type;
Chris@16 74 typedef typename Loc::reference reference; // result of dereferencing
Chris@16 75 typedef typename Loc::coord_t coord_t; // 1D difference type (same for all dimensions)
Chris@16 76 typedef coord_t difference_type; // result of operator-(1d_iterator,1d_iterator)
Chris@16 77 typedef typename Loc::point_t point_t;
Chris@16 78 typedef Loc locator;
Chris@16 79 typedef image_view<typename Loc::const_t> const_t; // same as this type, but over const values
Chris@16 80 template <std::size_t D> struct axis {
Chris@16 81 typedef typename Loc::template axis<D>::coord_t coord_t; // difference_type along each dimension
Chris@16 82 typedef typename Loc::template axis<D>::iterator iterator; // 1D iterator type along each dimension
Chris@16 83 };
Chris@16 84 typedef iterator_from_2d<Loc> iterator; // 1D iterator type for each pixel left-to-right inside top-to-bottom
Chris@16 85 typedef std::reverse_iterator<iterator> reverse_iterator;
Chris@16 86 typedef std::size_t size_type;
Chris@16 87
Chris@16 88 // typedefs required by ConstRandomAccess2DImageViewConcept
Chris@16 89 typedef locator xy_locator;
Chris@16 90 typedef typename xy_locator::x_iterator x_iterator; // pixel iterator along a row
Chris@16 91 typedef typename xy_locator::y_iterator y_iterator; // pixel iterator along a column
Chris@16 92 typedef typename xy_locator::x_coord_t x_coord_t;
Chris@16 93 typedef typename xy_locator::y_coord_t y_coord_t;
Chris@16 94
Chris@16 95 template <typename Deref> struct add_deref {
Chris@16 96 typedef image_view<typename Loc::template add_deref<Deref>::type> type;
Chris@16 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)); }
Chris@16 98 };
Chris@16 99
Chris@16 100 image_view() : _dimensions(0,0) {}
Chris@16 101 template <typename View> image_view(const View& iv) : _dimensions(iv.dimensions()), _pixels(iv.pixels()) {}
Chris@16 102
Chris@16 103 template <typename L2> image_view(const point_t& sz , const L2& loc) : _dimensions(sz), _pixels(loc) {}
Chris@16 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) {}
Chris@16 105
Chris@16 106 template <typename View> image_view& operator=(const View& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
Chris@16 107 image_view& operator=(const image_view& iv) { _pixels=iv.pixels(); _dimensions=iv.dimensions(); return *this; }
Chris@16 108
Chris@16 109 template <typename View> bool operator==(const View& v) const { return pixels()==v.pixels() && dimensions()==v.dimensions(); }
Chris@16 110 template <typename View> bool operator!=(const View& v) const { return !(*this==v); }
Chris@16 111
Chris@16 112 template <typename L2> friend void swap(image_view<L2>& x, image_view<L2>& y);
Chris@16 113
Chris@16 114 const point_t& dimensions() const { return _dimensions; }
Chris@16 115 const locator& pixels() const { return _pixels; }
Chris@16 116 x_coord_t width() const { return dimensions().x; }
Chris@16 117 y_coord_t height() const { return dimensions().y; }
Chris@16 118 std::size_t num_channels() const { return gil::num_channels<value_type>::value; }
Chris@16 119 bool is_1d_traversable() const { return _pixels.is_1d_traversable(width()); }
Chris@16 120
Chris@16 121 //\{@
Chris@16 122 /// \name 1D navigation
Chris@16 123 size_type size() const { return width()*height(); }
Chris@16 124 iterator begin() const { return iterator(_pixels,_dimensions.x); }
Chris@16 125 iterator end() const { return begin()+(difference_type)size(); } // potential performance problem!
Chris@16 126 reverse_iterator rbegin() const { return reverse_iterator(end()); }
Chris@16 127 reverse_iterator rend() const { return reverse_iterator(begin()); }
Chris@16 128 reference operator[](difference_type i) const { return begin()[i]; } // potential performance problem!
Chris@16 129 iterator at(difference_type i)const { return begin()+i; }
Chris@16 130 iterator at(const point_t& p) const { return begin()+p.y*width()+p.x; }
Chris@16 131 iterator at(x_coord_t x, y_coord_t y)const { return begin()+y*width()+x; }
Chris@16 132
Chris@16 133 //\}@
Chris@16 134
Chris@16 135 //\{@
Chris@16 136 /// \name 2-D navigation
Chris@16 137 reference operator()(const point_t& p) const { return _pixels(p.x,p.y); }
Chris@16 138 reference operator()(x_coord_t x, y_coord_t y)const { return _pixels(x,y); }
Chris@16 139 template <std::size_t D> typename axis<D>::iterator axis_iterator(const point_t& p) const { return _pixels.axis_iterator<D>(p); }
Chris@16 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)); }
Chris@16 141 locator xy_at(const point_t& p) const { return _pixels+p; }
Chris@16 142 //\}@
Chris@16 143
Chris@16 144 //\{@
Chris@16 145 /// \name X navigation
Chris@16 146 x_iterator x_at(x_coord_t x, y_coord_t y) const { return _pixels.x_at(x,y); }
Chris@16 147 x_iterator x_at(const point_t& p) const { return _pixels.x_at(p); }
Chris@16 148 x_iterator row_begin(y_coord_t y) const { return x_at(0,y); }
Chris@16 149 x_iterator row_end(y_coord_t y) const { return x_at(width(),y); }
Chris@16 150 //\}@
Chris@16 151
Chris@16 152 //\{@
Chris@16 153 /// \name Y navigation
Chris@16 154 y_iterator y_at(x_coord_t x, y_coord_t y) const { return xy_at(x,y).y(); }
Chris@16 155 y_iterator y_at(const point_t& p) const { return xy_at(p).y(); }
Chris@16 156 y_iterator col_begin(x_coord_t x) const { return y_at(x,0); }
Chris@16 157 y_iterator col_end(x_coord_t x) const { return y_at(x,height()); }
Chris@16 158 //\}@
Chris@16 159
Chris@16 160 private:
Chris@16 161 template <typename L2> friend class image_view;
Chris@16 162
Chris@16 163 point_t _dimensions;
Chris@16 164 xy_locator _pixels;
Chris@16 165 };
Chris@16 166
Chris@16 167 template <typename L2>
Chris@16 168 inline void swap(image_view<L2>& x, image_view<L2>& y) {
Chris@16 169 using std::swap;
Chris@16 170 swap(x._dimensions,y._dimensions);
Chris@16 171 swap(x._pixels, y._pixels); // TODO: Extend further
Chris@16 172 }
Chris@16 173
Chris@16 174 /////////////////////////////
Chris@16 175 // PixelBasedConcept
Chris@16 176 /////////////////////////////
Chris@16 177
Chris@16 178 template <typename L>
Chris@16 179 struct channel_type<image_view<L> > : public channel_type<L> {};
Chris@16 180
Chris@16 181 template <typename L>
Chris@16 182 struct color_space_type<image_view<L> > : public color_space_type<L> {};
Chris@16 183
Chris@16 184 template <typename L>
Chris@16 185 struct channel_mapping_type<image_view<L> > : public channel_mapping_type<L> {};
Chris@16 186
Chris@16 187 template <typename L>
Chris@16 188 struct is_planar<image_view<L> > : public is_planar<L> {};
Chris@16 189
Chris@16 190 /////////////////////////////
Chris@16 191 // HasDynamicXStepTypeConcept
Chris@16 192 /////////////////////////////
Chris@16 193
Chris@16 194 template <typename L>
Chris@16 195 struct dynamic_x_step_type<image_view<L> > {
Chris@16 196 typedef image_view<typename dynamic_x_step_type<L>::type> type;
Chris@16 197 };
Chris@16 198
Chris@16 199 /////////////////////////////
Chris@16 200 // HasDynamicYStepTypeConcept
Chris@16 201 /////////////////////////////
Chris@16 202
Chris@16 203 template <typename L>
Chris@16 204 struct dynamic_y_step_type<image_view<L> > {
Chris@16 205 typedef image_view<typename dynamic_y_step_type<L>::type> type;
Chris@16 206 };
Chris@16 207
Chris@16 208 /////////////////////////////
Chris@16 209 // HasTransposedTypeConcept
Chris@16 210 /////////////////////////////
Chris@16 211
Chris@16 212 template <typename L>
Chris@16 213 struct transposed_type<image_view<L> > {
Chris@16 214 typedef image_view<typename transposed_type<L>::type> type;
Chris@16 215 };
Chris@16 216
Chris@16 217 } } // namespace boost::gil
Chris@16 218
Chris@16 219 //#ifdef _MSC_VER
Chris@16 220 //#pragma warning(pop)
Chris@16 221 //#endif
Chris@16 222
Chris@16 223 #endif