• 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-2008 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 : private std::vector<pixel_type>
00058       {
00059         friend class image;
00060 
00061       public:
00063         typedef std::vector<pixel_type> super;
00064 
00066         typedef super::value_type value_type;
00067 
00069         typedef super::reference reference;
00070 
00072         typedef super::const_reference const_reference;
00073 
00075         typedef super::iterator iterator;
00076 
00078         typedef super::const_iterator const_iterator;
00079 
00081         typedef super::size_type size_type;
00082 
00083       public:
00084         iterator begin();
00085         iterator end();
00086 
00087         const_iterator begin() const;
00088         const_iterator end() const;
00089 
00090         inline reference operator[](unsigned int i);
00091         inline const_reference operator[](unsigned int i) const;
00092 
00093         size_type size() const;
00094 
00095       }; // class scanline
00096 
00097     public:
00102       template<typename Image, typename Pixel>
00103       class base_iterator
00104         : public std::iterator<std::random_access_iterator_tag, Pixel>
00105       {
00106       private:
00108         typedef Image image_type;
00109 
00111         typedef Pixel pixel_type;
00112 
00114         typedef base_iterator<image_type, pixel_type> self_type;
00115 
00116       public:
00117         typedef pixel_type value_type;
00118         typedef pixel_type& reference;
00119         typedef pixel_type* pointer;
00120         typedef ptrdiff_t difference_type;
00121 
00122         typedef std::random_access_iterator_tag iterator_category;
00123 
00124       public:
00125         inline base_iterator();
00126         inline base_iterator( image_type& owner, unsigned int x=0,
00127                               unsigned int y = 0 );
00128 
00129         inline bool operator==( const self_type& that ) const;
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 
00136         inline self_type& operator+=( int n );
00137         inline self_type& operator-=( int n );
00138 
00139         inline self_type operator+( int n ) const;
00140         inline self_type operator-( int n ) const;
00141 
00142         template<typename ImageT, typename PixelT>
00143         friend inline self_type operator+( int n, const self_type& self );
00144 
00145         inline difference_type operator-( const self_type& that ) const;
00146 
00147         inline self_type& operator++();
00148         inline self_type  operator++(int);
00149         inline self_type& operator--();
00150         inline self_type  operator--(int);
00151 
00152         inline reference operator*() const;
00153         inline pointer   operator->() const;
00154 
00155         inline reference operator[]( int n ) const;
00156 
00157       private:
00158         bool is_final() const;
00159 
00160       private:
00162         image_type* m_owner;
00163 
00165         math::coordinate_2d<unsigned int> m_pos;
00166 
00167       }; // class base_iterator
00168 
00169     public:
00170       typedef base_iterator<image, pixel_type> iterator;
00171       typedef base_iterator<const image, const pixel_type> const_iterator;
00172 
00173     public:
00174       image();
00175       image( unsigned int w, unsigned int h );
00176       image( std::istream& f );
00177       virtual ~image();
00178 
00179       unsigned int width() const;
00180       unsigned int height() const;
00181 
00182       inline scanline& operator[](unsigned int i);
00183       inline const scanline& operator[](unsigned int i) const;
00184 
00185       iterator begin();
00186       iterator end();
00187       const_iterator begin() const;
00188       const_iterator end() const;
00189 
00190       void partial_copy( const image& that,
00191                          const claw::math::coordinate_2d<int>& pos );
00192 
00193       void flip();
00194 
00195       void set_size( unsigned int w, unsigned int h );
00196 
00197       void load( std::istream& f );
00198 
00199     private:
00201       std::vector<scanline> m_data;
00202         
00203     }; // class image
00204 
00205   } // namespace graphic
00206 } // namespace claw
00207 
00208 // Inline methods
00209 #include <claw/impl/image.ipp>
00210 
00211 #endif // __CLAW_IMAGE_HPP__

Generated on Wed Sep 29 2010 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.7.1