Claw
1.7.3
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
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
41
namespace
claw
42
{
43
namespace
graphic
44
{
49
class
image
50
{
51
public
:
53
typedef
rgba_pixel
pixel_type
;
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
:
87
iterator
begin
();
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>
106
class
base_iterator
:
107
public
std::iterator<std::random_access_iterator_tag, Pixel>
108
{
109
private
:
111
typedef
Image image_type;
112
114
typedef
Pixel pixel_type;
115
117
typedef
base_iterator<image_type, pixel_type>
self_type
;
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
:
138
inline
base_iterator
();
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
184
math::coordinate_2d<unsigned int>
m_pos;
185
186
};
// class base_iterator
187
188
public
:
195
typedef
base_iterator<image, pixel_type>
iterator
;
196
203
typedef
base_iterator<const image, const pixel_type>
const_iterator
;
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
225
(
const
image
& that,
const
math::coordinate_2d<int>
& pos );
226
227
void
partial_copy
228
(
const
image
& that,
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
}
// namespace graphic
244
}
// namespace claw
245
246
namespace
std
247
{
248
void
swap(
claw::graphic::image
& a,
claw::graphic::image
& b );
249
}
// namespace std
250
251
// Inline methods
252
#include <
claw/impl/image.ipp
>
253
254
#endif // __CLAW_IMAGE_HPP__
Generated on Thu Mar 14 2013 22:09:24 for Claw by
1.8.1.2