• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Directories
  • File List
  • File Members

image.hpp

Go to the documentation of this file.
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-2010 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@yahoo.fr
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       }; // class scanline
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       }; // class base_iterator
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     }; // class image
00211 
00212   } // namespace graphic
00213 } // namespace claw
00214 
00215 namespace std
00216 {
00217   void swap( claw::graphic::image& a, claw::graphic::image& b );
00218 } // namespace std
00219 
00220 // Inline methods
00221 #include <claw/impl/image.ipp>
00222 
00223 #endif // __CLAW_IMAGE_HPP__

Generated on Fri Dec 24 2010 13:18:32 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.2