claw 1.8.2
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 : public std::iterator<std::random_access_iterator_tag, Pixel>
109 {
110 private:
112 typedef Image image_type;
113
115 typedef Pixel pixel_type;
116
119
120 public:
122 typedef pixel_type value_type;
123
126 typedef pixel_type& reference;
127
130 typedef pixel_type* pointer;
131
133 typedef ptrdiff_t difference_type;
134
136 typedef std::random_access_iterator_tag iterator_category;
137
138 public:
139 inline base_iterator();
140 inline base_iterator(image_type& owner, unsigned int x = 0,
141 unsigned int y = 0);
142
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 inline bool operator>=(const self_type& that) const;
149
150 inline self_type& operator+=(int n);
151 inline self_type& operator-=(int n);
152
153 inline self_type operator+(int n) const;
154 inline self_type operator-(int n) const;
155
162 template <typename ImageT, typename PixelT>
163 friend inline self_type operator+(int n, const self_type& self);
164
165 inline difference_type operator-(const self_type& that) const;
166
167 inline self_type& operator++();
168 inline self_type operator++(int);
169 inline self_type& operator--();
170 inline self_type operator--(int);
171
172 inline reference operator*() const;
173 inline pointer operator->() const;
174
175 inline reference operator[](int n) const;
176
177 private:
178 bool is_final() const;
179
180 private:
182 image_type* m_owner;
183
186
187 }; // class base_iterator
188
189 public:
197
205
206 public:
207 image();
208 image(unsigned int w, unsigned int h);
209 image(std::istream& f);
210
211 void swap(image& that);
212
213 unsigned int width() const;
214 unsigned int height() const;
215
216 inline scanline& operator[](unsigned int i);
217 inline const scanline& operator[](unsigned int i) const;
218
219 iterator begin();
220 iterator end();
221 const_iterator begin() const;
222 const_iterator end() const;
223
224 void merge(const image& that);
225 void merge(const image& that, const math::coordinate_2d<int>& pos);
226
227 void partial_copy(const image& that,
228 const math::coordinate_2d<int>& pos);
229
230 void flip();
231 void fill(const math::rectangle<int> r, const pixel_type& c);
232
233 void set_size(unsigned int w, unsigned int h);
234
235 void load(std::istream& f);
236
237 private:
239 std::vector<scanline> m_data;
240
241 }; // class image
242
243 }
244}
245
246namespace std
247{
249}
250
251// Inline methods
252#include <claw/graphic/image.ipp>
253
254#endif // __CLAW_IMAGE_HPP__
Base class for iterators on an image.
Definition image.hpp:109
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
pixel_type & reference
The type of the references to the values accesssed by the iterator.
Definition image.hpp:126
bool operator>(const self_type &that) const
Tell if the current iterator is after an other.
Definition image.ipp:138
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
self_type operator-(int n) const
Get an iterator at a specific distance of the current iterator.
Definition image.ipp:245
pixel_type * pointer
The type of the pointers to the values accesssed by the iterator.
Definition image.hpp:130
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
bool operator<(const self_type &that) const
Tell if the current iterator is before an other.
Definition image.ipp:122
ptrdiff_t difference_type
The type of the distance between two iterators.
Definition image.hpp:133
std::random_access_iterator_tag iterator_category
The type of this category.
Definition image.hpp:136
bool operator!=(const self_type &that) const
Tell if two iterator points to different addresses.
Definition image.ipp:109
pixel_type value_type
The type of the values accessed by the iterator.
Definition image.hpp:122
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
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::iterator iterator
Iterator in the line.
Definition image.hpp:79
super::const_reference const_reference
Const reference to a pixel.
Definition image.hpp:76
super::const_iterator const_iterator
Const iterator in the line.
Definition image.hpp:82
super::reference reference
Reference to a pixel..
Definition image.hpp:73
super::value_type value_type
The type of the pixels.
Definition image.hpp:70
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
std::vector< pixel_type > super
The type of the parent class.
Definition image.hpp:67
reference operator[](unsigned int i)
Get a pixel from the line.
Definition image.ipp:38
super::size_type size_type
An unsigned integral type.
Definition image.hpp:85
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
rgba_pixel pixel_type
The type representing the colors of the pixels in the image.
Definition image.hpp:55
base_iterator< const image, const pixel_type > const_iterator
The type of the iterator to access constant pixels.
Definition image.hpp:204
unsigned int height() const
Gets image's height.
Definition image.cpp:141
base_iterator< image, pixel_type > iterator
The type of the iterator on the pixels of the image.
Definition image.hpp:196
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
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.
This is the main namespace.
Representation of a pixel in image processing.