Claw
1.7.3
|
00001 /* 00002 CLAW - a C++ Library Absolutely Wonderful 00003 00004 CLAW is a free library without any particular aim but being useful to 00005 anyone. 00006 00007 Copyright (C) 2005-2011 Julien Jorge 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 contact: julien.jorge@gamned.org 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: 00053 typedef rgba_pixel pixel_type; 00054 00059 class scanline: 00060 private std::vector<pixel_type> 00061 { 00062 friend class image; 00063 00064 public: 00066 typedef std::vector<pixel_type> super; 00067 00069 typedef super::value_type value_type; 00070 00072 typedef super::reference reference; 00073 00075 typedef super::const_reference const_reference; 00076 00078 typedef super::iterator iterator; 00079 00081 typedef super::const_iterator const_iterator; 00082 00084 typedef super::size_type size_type; 00085 00086 public: 00087 iterator begin(); 00088 iterator end(); 00089 00090 const_iterator begin() const; 00091 const_iterator end() const; 00092 00093 inline reference operator[](unsigned int i); 00094 inline const_reference operator[](unsigned int i) const; 00095 00096 size_type size() const; 00097 00098 }; // class scanline 00099 00100 public: 00105 template<typename Image, typename Pixel> 00106 class base_iterator: 00107 public std::iterator<std::random_access_iterator_tag, Pixel> 00108 { 00109 private: 00111 typedef Image image_type; 00112 00114 typedef Pixel pixel_type; 00115 00117 typedef base_iterator<image_type, pixel_type> self_type; 00118 00119 public: 00121 typedef pixel_type value_type; 00122 00125 typedef pixel_type& reference; 00126 00129 typedef pixel_type* pointer; 00130 00132 typedef ptrdiff_t difference_type; 00133 00135 typedef std::random_access_iterator_tag iterator_category; 00136 00137 public: 00138 inline base_iterator(); 00139 inline base_iterator( image_type& owner, unsigned int x=0, 00140 unsigned int y = 0 ); 00141 00142 inline bool operator==( const self_type& that ) const; 00143 inline bool operator!=( const self_type& that ) const; 00144 inline bool operator<( const self_type& that ) const; 00145 inline bool operator>( const self_type& that ) const; 00146 inline bool operator<=( const self_type& that ) const; 00147 inline bool operator>=( const self_type& that ) const; 00148 00149 inline self_type& operator+=( int n ); 00150 inline self_type& operator-=( int n ); 00151 00152 inline self_type operator+( int n ) const; 00153 inline self_type operator-( int n ) const; 00154 00161 template<typename ImageT, typename PixelT> 00162 friend inline self_type operator+( int n, const self_type& self ); 00163 00164 inline difference_type operator-( const self_type& that ) const; 00165 00166 inline self_type& operator++(); 00167 inline self_type operator++(int); 00168 inline self_type& operator--(); 00169 inline self_type operator--(int); 00170 00171 inline reference operator*() const; 00172 inline pointer operator->() const; 00173 00174 inline reference operator[]( int n ) const; 00175 00176 private: 00177 bool is_final() const; 00178 00179 private: 00181 image_type* m_owner; 00182 00184 math::coordinate_2d<unsigned int> m_pos; 00185 00186 }; // class base_iterator 00187 00188 public: 00195 typedef base_iterator<image, pixel_type> iterator; 00196 00203 typedef base_iterator<const image, const pixel_type> const_iterator; 00204 00205 public: 00206 image(); 00207 image( unsigned int w, unsigned int h ); 00208 image( std::istream& f ); 00209 00210 void swap( image& that ); 00211 00212 unsigned int width() const; 00213 unsigned int height() const; 00214 00215 inline scanline& operator[](unsigned int i); 00216 inline const scanline& operator[](unsigned int i) const; 00217 00218 iterator begin(); 00219 iterator end(); 00220 const_iterator begin() const; 00221 const_iterator end() const; 00222 00223 void merge( const image& that ); 00224 void merge 00225 ( const image& that, const math::coordinate_2d<int>& pos ); 00226 00227 void partial_copy 00228 ( const image& that, const math::coordinate_2d<int>& pos ); 00229 00230 void flip(); 00231 void fill( const math::rectangle<int> r, const pixel_type& c ); 00232 00233 void set_size( unsigned int w, unsigned int h ); 00234 00235 void load( std::istream& f ); 00236 00237 private: 00239 std::vector<scanline> m_data; 00240 00241 }; // class image 00242 00243 } // namespace graphic 00244 } // namespace claw 00245 00246 namespace std 00247 { 00248 void swap( claw::graphic::image& a, claw::graphic::image& b ); 00249 } // namespace std 00250 00251 // Inline methods 00252 #include <claw/impl/image.ipp> 00253 00254 #endif // __CLAW_IMAGE_HPP__