Claw 1.7.3
image.hpp
Go to the documentation of this file.
1/*
2 CLAW - a C++ Library Absolutely Wonderful
3
4 CLAW is a free library without any particular aim but being useful to
5 anyone.
6
7 Copyright (C) 2005-2011 Julien Jorge
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
23 contact: julien.jorge@gamned.org
24*/
30#ifndef __CLAW_IMAGE_HPP__
31#define __CLAW_IMAGE_HPP__
32
33#include <claw/pixel.hpp>
34#include <claw/math.hpp>
35
36#include <vector>
37#include <iterator>
38#include <iostream>
39#include <cstddef>
40
41namespace claw
42{
43 namespace graphic
44 {
49 class image
50 {
51 public:
54
59 class scanline:
60 private std::vector<pixel_type>
61 {
62 friend class image;
63
64 public:
66 typedef std::vector<pixel_type> super;
67
69 typedef super::value_type value_type;
70
72 typedef super::reference reference;
73
75 typedef super::const_reference const_reference;
76
78 typedef super::iterator iterator;
79
81 typedef super::const_iterator const_iterator;
82
84 typedef super::size_type size_type;
85
86 public:
88 iterator end();
89
90 const_iterator begin() const;
91 const_iterator end() const;
92
93 inline reference operator[](unsigned int i);
94 inline const_reference operator[](unsigned int i) const;
95
96 size_type size() const;
97
98 }; // class scanline
99
100 public:
105 template<typename Image, typename Pixel>
107 {
108 private:
110 typedef Image image_type;
111
113 typedef Pixel pixel_type;
114
117
118 public:
120 typedef pixel_type value_type;
121
124 typedef pixel_type& reference;
125
128 typedef pixel_type* pointer;
129
131 typedef ptrdiff_t difference_type;
132
134 typedef std::random_access_iterator_tag iterator_category;
135
136 public:
138 inline base_iterator( image_type& owner, unsigned int x=0,
139 unsigned int y = 0 );
140
141 inline bool operator==( const self_type& that ) const;
142 inline bool operator!=( const self_type& that ) const;
143 inline bool operator<( const self_type& that ) const;
144 inline bool operator>( const self_type& that ) const;
145 inline bool operator<=( const self_type& that ) const;
146 inline bool operator>=( const self_type& that ) const;
147
148 inline self_type& operator+=( int n );
149 inline self_type& operator-=( int n );
150
151 inline self_type operator+( int n ) const;
152 inline self_type operator-( int n ) const;
153
160 template<typename ImageT, typename PixelT>
161 friend inline self_type operator+( int n, const self_type& self );
162
163 inline difference_type operator-( const self_type& that ) const;
164
165 inline self_type& operator++();
166 inline self_type operator++(int);
167 inline self_type& operator--();
168 inline self_type operator--(int);
169
170 inline reference operator*() const;
171 inline pointer operator->() const;
172
173 inline reference operator[]( int n ) const;
174
175 private:
176 bool is_final() const;
177
178 private:
180 image_type* m_owner;
181
184
185 }; // class base_iterator
186
187 public:
195
203
204 public:
205 image();
206 image( unsigned int w, unsigned int h );
207 image( std::istream& f );
208
209 void swap( image& that );
210
211 unsigned int width() const;
212 unsigned int height() const;
213
214 inline scanline& operator[](unsigned int i);
215 inline const scanline& operator[](unsigned int i) const;
216
217 iterator begin();
218 iterator end();
219 const_iterator begin() const;
220 const_iterator end() const;
221
222 void merge( const image& that );
223 void merge
224 ( const image& that, const math::coordinate_2d<int>& pos );
225
226 void partial_copy
227 ( const image& that, const math::coordinate_2d<int>& pos );
228
229 void flip();
230 void fill( const math::rectangle<int> r, const pixel_type& c );
231
232 void set_size( unsigned int w, unsigned int h );
233
234 void load( std::istream& f );
235
236 private:
238 std::vector<scanline> m_data;
239
240 }; // class image
241
242 } // namespace graphic
243} // namespace claw
244
245namespace std
246{
247 void swap( claw::graphic::image& a, claw::graphic::image& b );
248} // namespace std
249
250// Inline methods
251#include <claw/impl/image.ipp>
252
253#endif // __CLAW_IMAGE_HPP__
Base class for iterators on an image.
Definition image.hpp:107
self_type & operator+=(int n)
Move the iterator.
Definition image.ipp:178
bool operator<=(const self_type &that) const
Tell if the current iterator is before an other, or on the same address.
Definition image.ipp:152
self_type operator+(int n) const
Get an iterator at a specific distance of the current iterator.
Definition image.ipp:231
bool operator>(const self_type &that) const
Tell if the current iterator is after an other.
Definition image.ipp:138
self_type operator++(int)
Postincrement.
Definition image.ipp:323
self_type & operator-=(int n)
Move the iterator.
Definition image.ipp:203
self_type & operator++()
Preincrement.
Definition image.ipp:302
pointer operator->() const
Get a pointer on the pointed pixel.
Definition image.ipp:384
base_iterator(image_type &owner, unsigned int x=0, unsigned int y=0)
Constructor, from an image.
Definition image.ipp:77
self_type operator-(int n) const
Get an iterator at a specific distance of the current iterator.
Definition image.ipp:245
bool operator==(const self_type &that) const
Tell if two iterator point to the same address.
Definition image.ipp:91
reference operator*() const
Get a reference on the pointed pixel.
Definition image.ipp:371
self_type operator--(int)
Postdecrement.
Definition image.ipp:358
bool operator<(const self_type &that) const
Tell if the current iterator is before an other.
Definition image.ipp:122
bool operator!=(const self_type &that) const
Tell if two iterator points to different addresses.
Definition image.ipp:109
friend self_type operator+(int n, const self_type &self)
Get an iterator at a specific distance of the current iterator.
reference operator[](int n) const
Get a pixel, using the iterator like an array.
Definition image.ipp:398
self_type & operator--()
Predecrement.
Definition image.ipp:336
difference_type operator-(const self_type &that) const
Get the distance between two iterators.
Definition image.ipp:277
bool operator>=(const self_type &that) const
Tell if the current iterator is after an other, or on the same address.
Definition image.ipp:166
One line in the image.
Definition image.hpp:61
super::value_type value_type
The type of the pixels.
Definition image.hpp:69
super::size_type size_type
An unsigned integral type.
Definition image.hpp:84
iterator begin()
Get an iterator on the first pixel.
Definition image.cpp:54
iterator end()
Get en iterator past the last pixel.
Definition image.cpp:63
super::reference reference
Reference to a pixel..
Definition image.hpp:72
reference operator[](unsigned int i)
Get a pixel from the line.
Definition image.ipp:38
super::const_reference const_reference
Const reference to a pixel.
Definition image.hpp:75
super::iterator iterator
Iterator in the line.
Definition image.hpp:78
std::vector< pixel_type > super
The type of the parent class.
Definition image.hpp:66
super::const_iterator const_iterator
Const iterator in the line.
Definition image.hpp:81
size_type size() const
Get the length of the line.
Definition image.cpp:93
A class to deal with images.
Definition image.hpp:50
void flip()
Set the image upside down.
Definition image.cpp:301
void partial_copy(const image &that, const math::coordinate_2d< int > &pos)
Copy an image on the current image.
Definition image.cpp:272
unsigned int height() const
Gets image's height.
Definition image.cpp:159
rgba_pixel pixel_type
The type representing the colors of the pixels in the image.
Definition image.hpp:53
scanline & operator[](unsigned int i)
Gets a line of the image.
Definition image.ipp:429
void set_size(unsigned int w, unsigned int h)
Set a new size to the image.
Definition image.cpp:363
unsigned int width() const
Gets image's width.
Definition image.cpp:147
void merge(const image &that)
Merge an image on the current image.
Definition image.cpp:205
void fill(const math::rectangle< int > r, const pixel_type &c)
Fill an area of the image with a given color.
Definition image.cpp:314
iterator end()
Get an iterator pointing just past the last pixel.
Definition image.cpp:177
void swap(image &that)
Swap the content of two images.
Definition image.cpp:138
image()
Constructor. Creates an image without datas.
Definition image.cpp:106
void load(std::istream &f)
Read the image from a stream.
Definition image.cpp:381
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:202
base_iterator< image, pixel_type > iterator
The type of the iterator on the pixels of the image.
Definition image.hpp:194
iterator begin()
Get an iterator pointing on the first pixel.
Definition image.cpp:168
Coordinates in a two dimensional space.
A class representing a rectangle by his x,y coordinates, width and height.
Definition rectangle.hpp:52
Inline methods for the claw::graphic::image class.
Some mathematical structures and functions.
Everything about image structures and processing.
Definition bitmap.hpp:43
This is the main namespace.
Definition algorithm.hpp:34
Representation of a pixel in image processing.