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 #include <cstddef>
00040
00041 namespace claw
00042 {
00043 namespace graphic
00044 {
00049 class image
00050 {
00051 public:
00052 typedef rgba_pixel pixel_type;
00053
00058 class scanline : 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 virtual ~image();
00179
00180 unsigned int width() const;
00181 unsigned int height() const;
00182
00183 inline scanline& operator[](unsigned int i);
00184 inline const scanline& operator[](unsigned int i) const;
00185
00186 iterator begin();
00187 iterator end();
00188 const_iterator begin() const;
00189 const_iterator end() const;
00190
00191 void partial_copy( const image& that,
00192 const claw::math::coordinate_2d<int>& pos );
00193
00194 void flip();
00195
00196 void set_size( unsigned int w, unsigned int h );
00197
00198 void load( std::istream& f );
00199
00200 private:
00202 std::vector<scanline> m_data;
00203
00204 };
00205
00206 }
00207 }
00208
00209
00210 #include <claw/impl/image.ipp>
00211
00212 #endif // __CLAW_IMAGE_HPP__