claw 1.9.0
 
Loading...
Searching...
No Matches
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@stuff-o-matic.com
24*/
30#ifndef __CLAW_IMAGE_HPP__
31#define __CLAW_IMAGE_HPP__
32
34
35#include <claw/math.hpp>
36
37#include <cstddef>
38#include <iostream>
39#include <iterator>
40#include <vector>
41
42namespace claw
43{
44 namespace graphic
45 {
50 class image
51 {
52 public:
56
61 class scanline : private std::vector<pixel_type>
62 {
63 friend class image;
64
65 public:
67 typedef std::vector<pixel_type> super;
68
70 typedef super::value_type value_type;
71
73 typedef super::reference reference;
74
76 typedef super::const_reference const_reference;
77
79 typedef super::iterator iterator;
80
82 typedef super::const_iterator const_iterator;
83
85 typedef super::size_type size_type;
86
87 public:
89 iterator end();
90
91 const_iterator begin() const;
92 const_iterator end() const;
93
94 inline reference operator[](unsigned int i);
95 inline const_reference operator[](unsigned int i) const;
96
97 size_type size() const;
98
99 }; // class scanline
100
101 public:
106 template <typename Image, typename Pixel>
108 {
109 private:
111 typedef Image image_type;
112
114 typedef Pixel pixel_type;
115
118
119 public:
121 typedef pixel_type value_type;
122
125 typedef pixel_type& reference;
126
129 typedef pixel_type* pointer;
130
132 typedef ptrdiff_t difference_type;
133
135 typedef std::random_access_iterator_tag iterator_category;
136
137 public:
139 inline base_iterator(image_type& owner, unsigned int x = 0,
140 unsigned int y = 0);
141
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 inline bool operator>=(const self_type& that) const;
148
149 inline self_type& operator+=(int n);
150 inline self_type& operator-=(int n);
151
152 inline self_type operator+(int n) const;
153 inline self_type operator-(int n) const;
154
161 template <typename ImageT, typename PixelT>
162 friend inline self_type operator+(int n, const self_type& self);
163
164 inline difference_type operator-(const self_type& that) const;
165
166 inline self_type& operator++();
167 inline self_type operator++(int);
168 inline self_type& operator--();
169 inline self_type operator--(int);
170
171 inline reference operator*() const;
172 inline pointer operator->() const;
173
174 inline reference operator[](int n) const;
175
176 private:
177 bool is_final() const;
178
179 private:
181 image_type* m_owner;
182
185
186 }; // class base_iterator
187
188 public:
196
204
205 public:
206 image();
207 image(unsigned int w, unsigned int h);
208 image(std::istream& f);
209
210 void swap(image& that);
211
212 unsigned int width() const;
213 unsigned int height() const;
214
215 inline scanline& operator[](unsigned int i);
216 inline const scanline& operator[](unsigned int i) const;
217
218 iterator begin();
219 iterator end();
220 const_iterator begin() const;
221 const_iterator end() const;
222
223 void merge(const image& that);
224 void merge(const image& that, const math::coordinate_2d<int>& pos);
225
226 void partial_copy(const image& that,
227 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 }
243}
244
245namespace std
246{
248}
249
250// Inline methods
251#include <claw/graphic/image.ipp>
252
253#endif // __CLAW_IMAGE_HPP__
Base class for iterators on an image.
Definition image.hpp:108
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:62
super::value_type value_type
The type of the pixels.
Definition image.hpp:70
super::size_type size_type
An unsigned integral type.
Definition image.hpp:85
iterator begin()
Get an iterator on the first pixel.
Definition image.cpp:51
iterator end()
Get en iterator past the last pixel.
Definition image.cpp:59
super::reference reference
Reference to a pixel..
Definition image.hpp:73
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:76
super::iterator iterator
Iterator in the line.
Definition image.hpp:79
std::vector< pixel_type > super
The type of the parent class.
Definition image.hpp:67
super::const_iterator const_iterator
Const iterator in the line.
Definition image.hpp:82
size_type size() const
Get the length of the line.
Definition image.cpp:86
A class to deal with images.
Definition image.hpp:51
void flip()
Set the image upside down.
Definition image.cpp:275
void partial_copy(const image &that, const math::coordinate_2d< int > &pos)
Copy an image on the current image.
Definition image.cpp:245
unsigned int height() const
Gets image's height.
Definition image.cpp:141
rgba_pixel pixel_type
The type representing the colors of the pixels in the image.
Definition image.hpp:55
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:333
unsigned int width() const
Gets image's width.
Definition image.cpp:130
void merge(const image &that)
Merge an image on the current image.
Definition image.cpp:182
void fill(const math::rectangle< int > r, const pixel_type &c)
Fill an area of the image with a given color.
Definition image.cpp:286
iterator end()
Get an iterator pointing just past the last pixel.
Definition image.cpp:157
void swap(image &that)
Swap the content of two images.
Definition image.cpp:122
image()
Constructor. Creates an image without datas.
Definition image.cpp:95
void load(std::istream &f)
Read the image from a stream.
Definition image.cpp:350
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:203
base_iterator< image, pixel_type > iterator
The type of the iterator on the pixels of the image.
Definition image.hpp:195
iterator begin()
Get an iterator pointing on the first pixel.
Definition image.cpp:149
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 claw.hpp:58
This is the main namespace.
Representation of a pixel in image processing.