Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #ifndef __CLAW_IMAGE_HPP__
00031 #define __CLAW_IMAGE_HPP__
00032
00033 #include <claw/pixel.hpp>
00034 #include <claw/math.hpp>
00035
00036 #include <vector>
00037 #include <iterator>
00038 #include <iostream>
00039
00040 namespace claw
00041 {
00042 namespace graphic
00043 {
00048 class image
00049 {
00050 public:
00051 typedef rgba_pixel pixel_type;
00052
00057 class scanline:
00058 private std::vector<pixel_type>
00059 {
00060 friend class image;
00061
00062 public:
00064 typedef std::vector<pixel_type> super;
00065
00067 typedef super::value_type value_type;
00068
00070 typedef super::reference reference;
00071
00073 typedef super::const_reference const_reference;
00074
00076 typedef super::iterator iterator;
00077
00079 typedef super::const_iterator const_iterator;
00080
00082 typedef super::size_type size_type;
00083
00084 public:
00085 iterator begin();
00086 iterator end();
00087
00088 const_iterator begin() const;
00089 const_iterator end() const;
00090
00091 inline reference operator[](unsigned int i);
00092 inline const_reference operator[](unsigned int i) const;
00093
00094 size_type size() const;
00095
00096 };
00097
00098 public:
00103 template<typename Image, typename Pixel>
00104 class base_iterator:
00105 public std::iterator<std::random_access_iterator_tag, Pixel>
00106 {
00107 private:
00109 typedef Image image_type;
00110
00112 typedef Pixel pixel_type;
00113
00115 typedef base_iterator<image_type, pixel_type> self_type;
00116
00117 public:
00118 typedef pixel_type value_type;
00119 typedef pixel_type& reference;
00120 typedef pixel_type* pointer;
00121 typedef ptrdiff_t difference_type;
00122
00123 typedef std::random_access_iterator_tag iterator_category;
00124
00125 public:
00126 inline base_iterator();
00127 inline base_iterator( image_type& owner, unsigned int x=0,
00128 unsigned int y = 0 );
00129
00130 inline bool operator==( const self_type& that ) const;
00131 inline bool operator!=( const self_type& that ) const;
00132 inline bool operator<( const self_type& that ) const;
00133 inline bool operator>( const self_type& that ) const;
00134 inline bool operator<=( const self_type& that ) const;
00135 inline bool operator>=( const self_type& that ) const;
00136
00137 inline self_type& operator+=( int n );
00138 inline self_type& operator-=( int n );
00139
00140 inline self_type operator+( int n ) const;
00141 inline self_type operator-( int n ) const;
00142
00143 template<typename ImageT, typename PixelT>
00144 friend inline self_type operator+( int n, const self_type& self );
00145
00146 inline difference_type operator-( const self_type& that ) const;
00147
00148 inline self_type& operator++();
00149 inline self_type operator++(int);
00150 inline self_type& operator--();
00151 inline self_type operator--(int);
00152
00153 inline reference operator*() const;
00154 inline pointer operator->() const;
00155
00156 inline reference operator[]( int n ) const;
00157
00158 private:
00159 bool is_final() const;
00160
00161 private:
00163 image_type* m_owner;
00164
00166 math::coordinate_2d<unsigned int> m_pos;
00167
00168 };
00169
00170 public:
00171 typedef base_iterator<image, pixel_type> iterator;
00172 typedef base_iterator<const image, const pixel_type> const_iterator;
00173
00174 public:
00175 image();
00176 image( unsigned int w, unsigned int h );
00177 image( std::istream& f );
00178
00179 void swap( image& that );
00180
00181 unsigned int width() const;
00182 unsigned int height() const;
00183
00184 inline scanline& operator[](unsigned int i);
00185 inline const scanline& operator[](unsigned int i) const;
00186
00187 iterator begin();
00188 iterator end();
00189 const_iterator begin() const;
00190 const_iterator end() const;
00191
00192 void merge( const image& that );
00193 void merge
00194 ( const image& that, const math::coordinate_2d<int>& pos );
00195
00196 void partial_copy
00197 ( const image& that, const math::coordinate_2d<int>& pos );
00198
00199 void flip();
00200 void fill( const math::rectangle<int> r, const pixel_type& c );
00201
00202 void set_size( unsigned int w, unsigned int h );
00203
00204 void load( std::istream& f );
00205
00206 private:
00208 std::vector<scanline> m_data;
00209
00210 };
00211
00212 }
00213 }
00214
00215 namespace std
00216 {
00217 void swap( claw::graphic::image& a, claw::graphic::image& b );
00218 }
00219
00220
00221 #include <claw/impl/image.ipp>
00222
00223 #endif // __CLAW_IMAGE_HPP__