1 |
/* ***************************************************************************** |
2 |
** $Id: gdpp.h,v 1.2 2007/12/16 21:31:27 kshepherd Exp $ |
3 |
** Initial file written and documented by: |
4 |
** Kevin Shepherd <kshepherd@php.net> December 2007 |
5 |
** of Scarlet Line http://www.scarletline.com/ |
6 |
** with contributions from Torben Nielsen. |
7 |
*******************************************************************************/ |
8 |
/** \file gdpp.h |
9 |
\brief Object Oriented C++ wrappers around libgd functionality. |
10 |
|
11 |
Example usage, convert png to gif: |
12 |
#include <fstream> |
13 |
#include <gdpp.h> |
14 |
|
15 |
std::ifstream in("image.png", std::ios_base::in | std::ios_base::binary ); |
16 |
GD::Image im(in, GD::Png_tag()); |
17 |
if (im.good()) |
18 |
{ |
19 |
std::ofstream out("image.gif", std::ios_base::out | std::ios_base::binary ); |
20 |
im.Gif(out); |
21 |
} |
22 |
*/ |
23 |
#ifdef __cplusplus |
24 |
#ifndef _gdpp_h |
25 |
#define _gdpp_h |
26 |
|
27 |
#include "gd_io_stream.h" |
28 |
#include <string> |
29 |
|
30 |
/// namespace GD:: contains the C++ wrapper classes for libgd |
31 |
/** This namespace is primarily to avoid name clashes, and to |
32 |
contain all of the gd classes within one namespace. |
33 |
It is not recommended to use the "using namespace" directive with this namespace. |
34 |
Example usage: |
35 |
GD::Image im(64, 32, true); // Create a truecolor image 64 pixels wide by 32 pixels high |
36 |
GD::Point pt(10, 8); // The point at x=10, y=8. |
37 |
GD::Size sz(16, 8); // The size width=16, height=8. |
38 |
GD::TrueColor col(0xFF, 0, 0); // The colour red; R=255, G=0, B=0. |
39 |
im.Rectangle(pt, sz, col.Int()); // Draw a red rectangle with top left corner at pt, of size sz. |
40 |
*/ |
41 |
namespace GD |
42 |
{ |
43 |
/** This class GD::Point stores a point in two dimensions, somewhere |
44 |
on the plane of an image. |
45 |
*/ |
46 |
class Point |
47 |
{ |
48 |
public: |
49 |
// Constructors |
50 |
Point(int x, int y) |
51 |
:_x(x), _y(y) {} |
52 |
Point(const Point & p) |
53 |
:_x(p._x), _y(p._y) {} |
54 |
Point() |
55 |
:_x(0), _y(0) {} |
56 |
Point & operator=(const Point & p) |
57 |
{ |
58 |
_x = p._x; |
59 |
_y = p._y; |
60 |
return (* this); |
61 |
} |
62 |
// Accessors |
63 |
int X() const |
64 |
{ return _x; } |
65 |
int Y() const |
66 |
{ return _y; } |
67 |
// Updaters |
68 |
void X(int x) |
69 |
{ _x = x; } |
70 |
void Y(int y) |
71 |
{ _y = y; } |
72 |
void set(int x, int y) |
73 |
{ _x = x; _y = y; } |
74 |
int & lhsX() |
75 |
{ return _x; } |
76 |
int & lhsY() |
77 |
{ return _y; } |
78 |
|
79 |
gdPointPtr as_gdPointPtr() |
80 |
{ return (gdPointPtr) this; } |
81 |
protected: |
82 |
int _x, _y; |
83 |
}; |
84 |
typedef Point * PointPtr; |
85 |
/** This class GD::Size stores length in two dimensions. |
86 |
Giving the size of an area as width and height. |
87 |
*/ |
88 |
class Size |
89 |
{ |
90 |
public: |
91 |
// Constructors |
92 |
Size(int w, int h) |
93 |
:_w(w), _h(h) {} |
94 |
Size(const Size & p) |
95 |
:_w(p._w), _h(p._h) {} |
96 |
Size() |
97 |
:_w(0), _h(0) {} |
98 |
Size & operator=(const Size & p) |
99 |
{ |
100 |
_w = p._w; |
101 |
_h = p._h; |
102 |
return (* this); |
103 |
} |
104 |
// Accessors |
105 |
int W() const |
106 |
{ return _w; } |
107 |
int H() const |
108 |
{ return _h; } |
109 |
// Updaters |
110 |
void W(int w) |
111 |
{ _w = w; } |
112 |
void H(int h) |
113 |
{ _h = h; } |
114 |
void set(int w, int h) |
115 |
{ _w = w; _h = h; } |
116 |
int & lhsW() |
117 |
{ return _w; } |
118 |
int & lhsH() |
119 |
{ return _h; } |
120 |
protected: |
121 |
int _w, _h; |
122 |
}; |
123 |
typedef Size * SizePtr; |
124 |
|
125 |
/** This class GD::TrueColor stores a colour as an RGBA quadruplet. |
126 |
It can also be read as an integer, and in other colour formats. |
127 |
*/ |
128 |
class TrueColor |
129 |
{ |
130 |
public: |
131 |
union as_types |
132 |
{ |
133 |
int as_int; |
134 |
struct uchars |
135 |
{ |
136 |
unsigned char blue, green, red, alpha; |
137 |
} as_uchar; |
138 |
}; |
139 |
TrueColor() |
140 |
{ internal.as_int = 0; } |
141 |
TrueColor(int c) |
142 |
{ internal.as_int = c; } |
143 |
TrueColor(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0) |
144 |
{ |
145 |
internal.as_uchar.alpha = a; |
146 |
internal.as_uchar.red = r; |
147 |
internal.as_uchar.green = g; |
148 |
internal.as_uchar.blue = b; |
149 |
} |
150 |
// Accessors |
151 |
int Int() const |
152 |
{ return internal.as_int; } |
153 |
unsigned char Red() const |
154 |
{ return internal.as_uchar.red; } |
155 |
unsigned char Green() const |
156 |
{ return internal.as_uchar.green; } |
157 |
unsigned char Blue() const |
158 |
{ return internal.as_uchar.blue; } |
159 |
unsigned char Alpha() const |
160 |
{ return internal.as_uchar.alpha; } |
161 |
// Updaters |
162 |
void set(int c) |
163 |
{ internal.as_int = c; } |
164 |
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0) |
165 |
{ |
166 |
internal.as_uchar.alpha = a; |
167 |
internal.as_uchar.red = r; |
168 |
internal.as_uchar.green = g; |
169 |
internal.as_uchar.blue = b; |
170 |
} |
171 |
void Red(unsigned char c) |
172 |
{ internal.as_uchar.red = c; } |
173 |
void Green(unsigned char c) |
174 |
{ internal.as_uchar.green = c; } |
175 |
void Blue(unsigned char c) |
176 |
{ internal.as_uchar.blue = c; } |
177 |
void Alpha(unsigned char c) |
178 |
{ internal.as_uchar.alpha = c; } |
179 |
protected: |
180 |
as_types internal; |
181 |
}; |
182 |
/* The following tags are simply empty structures which are used |
183 |
to tell the compiler which constructor we want when we know |
184 |
the image file format. |
185 |
*/ |
186 |
struct Png_tag {}; |
187 |
struct Gif_tag {}; |
188 |
struct WBMP_tag {}; |
189 |
struct Jpeg_tag {}; |
190 |
struct Gd_tag {}; |
191 |
struct Gd2_tag {}; |
192 |
struct Xbm_tag {}; |
193 |
|
194 |
/** This class GD::Image wraps all of the 'C' libgd functionality |
195 |
for the convenience of C++ users. An instance of this class |
196 |
corresponds to a single image. |
197 |
*/ |
198 |
class BGD_EXPORT_DATA_IMPL Image |
199 |
{ |
200 |
public: |
201 |
/** Construct a null image |
202 |
*/ |
203 |
Image() |
204 |
:im(0) |
205 |
{} |
206 |
/** Construct a blank image, of the given size and colour format type. |
207 |
\param[in] sx Width of the image |
208 |
\param[in] sy Height of the image |
209 |
\param[in] istruecolor Create a true colour image, defaults to false, i.e. create an indexed palette image. |
210 |
*/ |
211 |
Image(int sx, int sy, bool istruecolor = false) |
212 |
:im(0) |
213 |
{ |
214 |
if (istruecolor) |
215 |
CreateTrueColor(sx, sy); |
216 |
else |
217 |
Create(sx, sy); |
218 |
} |
219 |
/** Construct a blank image, of the given size and colour format type. |
220 |
\param[in] s Width and height of the image |
221 |
\param[in] istruecolor Create a true colour image, defaults to false, i.e. create an indexed palette image. |
222 |
*/ |
223 |
Image(const Size & s, bool istruecolor = false) |
224 |
:im(0) |
225 |
{ |
226 |
if (istruecolor) |
227 |
CreateTrueColor(s); |
228 |
else |
229 |
Create(s); |
230 |
} |
231 |
/** Construct an instance of the GD::Image class, given the internal gdImage poimter. |
232 |
Note that gdImageDestroy will be called on the image pointer in the destructor. |
233 |
\param[in] i Pointer to the internal gdImage |
234 |
*/ |
235 |
Image(gdImagePtr i) |
236 |
:im(i) {} |
237 |
/** Copy constructor. Construct an instance of the GD::Image class, |
238 |
by making a copy of the GD::Image provided. |
239 |
\param[in] i Reference to the image to be copied |
240 |
*/ |
241 |
Image(const GD::Image & i) |
242 |
:im(0) |
243 |
{ |
244 |
Copy(i); |
245 |
} |
246 |
/** Construct an image by reading from \p in. This constructor |
247 |
will first attempt to determine the file format. |
248 |
\param[in] in The stream containing the image data |
249 |
*/ |
250 |
Image(std::istream & in) |
251 |
:im(0) { CreateFrom(in); } |
252 |
/** Construct an image by reading from \p in. This constructor |
253 |
will first attempt to determine the file format. |
254 |
\param[in] in An opened FILE * handle to a file containing the image data |
255 |
*/ |
256 |
Image(FILE * in) |
257 |
:im(0) { CreateFrom(in); } |
258 |
/** Construct an image by reading from memory block \p data. This constructor |
259 |
will first attempt to determine the image formatting. |
260 |
\param[in] size The byte count of the memory block |
261 |
\param[in] data Pointer to the memory block |
262 |
*/ |
263 |
Image(int size, void * data) |
264 |
:im(0) { CreateFrom(size, data); } |
265 |
|
266 |
/** Construct an image by reading from \p in. |
267 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
268 |
e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input |
269 |
\param[in] in The stream containing the image data |
270 |
*/ |
271 |
Image(std::istream & in, Png_tag) |
272 |
:im(0) { CreateFromPng(in); } |
273 |
/** Construct an image by reading from \p in. |
274 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
275 |
e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input |
276 |
\param[in] in An opened FILE * handle to a file containing the image data |
277 |
*/ |
278 |
Image(FILE * in, Png_tag) |
279 |
:im(0) { CreateFromPng(in); } |
280 |
/** Construct an image by reading from \p in. |
281 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
282 |
e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input |
283 |
\param[in] in The io context from which to read the image data |
284 |
*/ |
285 |
Image(gdIOCtx * in, Png_tag) |
286 |
:im(0) { CreateFromPng(in); } |
287 |
/** Construct an image by reading from memory block \p data. |
288 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
289 |
e.g. GD::Image img(sz, dat, GD::Png_tag()); // read a png file from dat |
290 |
\param[in] size The byte count of the memory block |
291 |
\param[in] data Pointer to the memory block |
292 |
*/ |
293 |
Image(int size, void * data, Png_tag) |
294 |
:im(0) { CreateFromPng(size, data); } |
295 |
|
296 |
/** Construct an image by reading from \p in. |
297 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
298 |
e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input |
299 |
\param[in] in The stream containing the image data |
300 |
*/ |
301 |
Image(std::istream & in, Gif_tag) |
302 |
:im(0) { CreateFromGif(in); } |
303 |
/** Construct an image by reading from \p in. |
304 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
305 |
e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input |
306 |
\param[in] in An opened FILE * handle to a file containing the image data |
307 |
*/ |
308 |
Image(FILE * in, Gif_tag) |
309 |
:im(0) { CreateFromGif(in); } |
310 |
/** Construct an image by reading from \p in. |
311 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
312 |
e.g. GD::Image img(input, GD::Gif_tag()); // read a gif file from input |
313 |
\param[in] in The io context from which to read the image data |
314 |
*/ |
315 |
Image(gdIOCtx * in, Gif_tag) |
316 |
:im(0) { CreateFromGif(in); } |
317 |
/** Construct an image by reading from memory block \p data. |
318 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
319 |
e.g. GD::Image img(sz, dat, GD::Gif_tag()); // read a gif file from dat |
320 |
\param[in] size The byte count of the memory block |
321 |
\param[in] data Pointer to the memory block |
322 |
*/ |
323 |
Image(int size, void * data, Gif_tag) |
324 |
:im(0) { CreateFromGif(size, data); } |
325 |
|
326 |
/** Construct an image by reading from \p in. |
327 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
328 |
e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input |
329 |
\param[in] in The stream containing the image data |
330 |
*/ |
331 |
Image(std::istream & in, WBMP_tag) |
332 |
:im(0) { CreateFromWBMP(in); } |
333 |
/** Construct an image by reading from \p in. |
334 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
335 |
e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input |
336 |
\param[in] in An opened FILE * handle to a file containing the image data |
337 |
*/ |
338 |
Image(FILE * in, WBMP_tag) |
339 |
:im(0) { CreateFromWBMP(in); } |
340 |
/** Construct an image by reading from \p in. |
341 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
342 |
e.g. GD::Image img(input, GD::WBMP_tag()); // read a monchrome WBMP file from input |
343 |
\param[in] in The io context from which to read the image data |
344 |
*/ |
345 |
Image(gdIOCtx * in, WBMP_tag) |
346 |
:im(0) { CreateFromWBMP(in); } |
347 |
/** Construct an image by reading from memory block \p data. |
348 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
349 |
e.g. GD::Image img(sz, dat, GD::WBMP_tag()); // read a monchrome WBMP file from dat |
350 |
\param[in] size The byte count of the memory block |
351 |
\param[in] data Pointer to the memory block |
352 |
*/ |
353 |
Image(int size, void * data, WBMP_tag) |
354 |
:im(0) { CreateFromWBMP(size, data); } |
355 |
|
356 |
/** Construct an image by reading from \p in. |
357 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
358 |
e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input |
359 |
\param[in] in The stream containing the image data |
360 |
*/ |
361 |
Image(std::istream & in, Jpeg_tag) |
362 |
:im(0) { CreateFromJpeg(in); } |
363 |
/** Construct an image by reading from \p in. |
364 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
365 |
e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input |
366 |
\param[in] in An opened FILE * handle to a file containing the image data |
367 |
*/ |
368 |
Image(FILE * in, Jpeg_tag) |
369 |
:im(0) { CreateFromJpeg(in); } |
370 |
/** Construct an image by reading from \p in. |
371 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
372 |
e.g. GD::Image img(input, GD::Jpeg_tag()); // read a jpeg file from input |
373 |
\param[in] in The io context from which to read the image data |
374 |
*/ |
375 |
Image(gdIOCtx * in, Jpeg_tag) |
376 |
:im(0) { CreateFromJpeg(in); } |
377 |
/** Construct an image by reading from memory block \p data. |
378 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
379 |
e.g. GD::Image img(sz, dat, GD::Jpeg_tag()); // read a jpeg file from dat |
380 |
\param[in] size The byte count of the memory block |
381 |
\param[in] data Pointer to the memory block |
382 |
*/ |
383 |
Image(int size, void * data, Jpeg_tag) |
384 |
:im(0) { CreateFromJpeg(size, data); } |
385 |
|
386 |
/** Construct an image by reading from \p in. |
387 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
388 |
e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input |
389 |
\param[in] in The stream containing the image data |
390 |
*/ |
391 |
Image(std::istream & in, Gd_tag) |
392 |
:im(0) { CreateFromGd(in); } |
393 |
/** Construct an image by reading from \p in. |
394 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
395 |
e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input |
396 |
\param[in] in An opened FILE * handle to a file containing the image data |
397 |
*/ |
398 |
Image(FILE * in, Gd_tag) |
399 |
:im(0) { CreateFromGd(in); } |
400 |
/** Construct an image by reading from \p in. |
401 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
402 |
e.g. GD::Image img(input, GD::Gd_tag()); // read a gd file from input |
403 |
\param[in] in The io context from which to read the image data |
404 |
*/ |
405 |
Image(gdIOCtx * in, Gd_tag) |
406 |
:im(0) { CreateFromGd(in); } |
407 |
/** Construct an image by reading from memory block \p data. |
408 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
409 |
e.g. GD::Image img(sz, dat, GD::Gd_tag()); // read a gd file from dat |
410 |
\param[in] size The byte count of the memory block |
411 |
\param[in] data Pointer to the memory block |
412 |
*/ |
413 |
Image(int size, void * data, Gd_tag) |
414 |
:im(0) { CreateFromGd(size, data); } |
415 |
|
416 |
/** Construct an image by reading from \p in. |
417 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
418 |
e.g. GD::Image img(input, GD::Gd2_tag()); // read a gd2 file from input |
419 |
\param[in] in The stream containing the image data |
420 |
*/ |
421 |
Image(std::istream & in, Gd2_tag) |
422 |
:im(0) { CreateFromGd2(in); } |
423 |
/** Construct an image by reading from \p in. |
424 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
425 |
e.g. GD::Image img(input, GD::Png_tag()); // read a png file from input |
426 |
\param[in] in An opened FILE * handle to a file containing the image data |
427 |
*/ |
428 |
Image(FILE * in, Gd2_tag) |
429 |
:im(0) { CreateFromGd2(in); } |
430 |
/** Construct an image by reading from \p in. |
431 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
432 |
e.g. GD::Image img(input, GD::Gd2_tag()); // read a gd2 file from input |
433 |
\param[in] in The io context from which to read the image data |
434 |
*/ |
435 |
Image(gdIOCtx * in, Gd2_tag) |
436 |
:im(0) { CreateFromGd2(in); } |
437 |
/** Construct an image by reading from memory block \p data. |
438 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
439 |
e.g. GD::Image img(sz, dat, GD::Gd2_tag()); // read a gd2 file from dat |
440 |
\param[in] size The byte count of the memory block |
441 |
\param[in] data Pointer to the memory block |
442 |
*/ |
443 |
Image(int size, void * data, Gd2_tag) |
444 |
:im(0) { CreateFromGd2(size, data); } |
445 |
|
446 |
/** Construct an image by reading from \p in. |
447 |
The tag is an empty struct which simply tells the compiler which image read function to use. |
448 |
e.g. GD::Image img(input, GD::Xbm_tag()); // read an xbm file from input |
449 |
\param[in] in An opened FILE * handle to a file containing the image data |
450 |
*/ |
451 |
Image(FILE * in, Xbm_tag) |
452 |
:im(0) { CreateFromXbm(in); } |
453 |
|
454 |
~Image() |
455 |
{ clear(); } |
456 |
|
457 |
/** Assignment Operator. Make this a copy of the GD::Image provided. |
458 |
\param[in] src Reference to the image to be copied |
459 |
*/ |
460 |
GD::Image & operator=(const GD::Image & src) |
461 |
{ |
462 |
Copy(src); |
463 |
return (* this); |
464 |
} |
465 |
/** Make this an exact copy of the GD::Image provided. Any existing iamge data is discarded. |
466 |
\param[in] src Reference to the image to be copied |
467 |
*/ |
468 |
void Copy(const GD::Image & src) |
469 |
{ |
470 |
int w = src.Width(), h = src.Height(); |
471 |
if (src.IsTrueColor()) |
472 |
CreateTrueColor(w, h); |
473 |
else |
474 |
{ |
475 |
Create(w, h); |
476 |
PaletteCopy(src); |
477 |
} |
478 |
Copy(src, 0, 0, 0, 0, w, h); |
479 |
} |
480 |
/** Check to see if this appears to be a valid image |
481 |
*/ |
482 |
bool good() const |
483 |
{ return (im != 0); } |
484 |
// Creation: |
485 |
/** |
486 |
Create a palette-based image, with no more than 256 colors. |
487 |
\param sx Width of the desired image |
488 |
\param sy Height of the desired image |
489 |
\return true if it worked, else false |
490 |
*/ |
491 |
bool Create(int sx, int sy) |
492 |
{ |
493 |
clear(); |
494 |
return ((im = gdImageCreate(sx, sy)) != 0); |
495 |
} |
496 |
/** |
497 |
Create a truecolor image. |
498 |
\param sx Width of the desired image |
499 |
\param sy Height of the desired image |
500 |
\return true if it worked, else false |
501 |
*/ |
502 |
bool CreateTrueColor(int sx, int sy) |
503 |
{ |
504 |
clear(); |
505 |
return ((im = gdImageCreateTrueColor(sx, sy)) != 0); |
506 |
} |
507 |
/** |
508 |
Create a palette-based image, with no more than 256 colors. |
509 |
\param s Width and height of the desired image |
510 |
\return true if it worked, else false |
511 |
*/ |
512 |
bool Create(const Size & s) |
513 |
{ return Create(s.W(), s.H()); } |
514 |
/** |
515 |
Create a truecolor image. |
516 |
\param s Width and height of the desired image |
517 |
\return true if it worked, else false |
518 |
*/ |
519 |
bool CreateTrueColor(const Size & s) |
520 |
{ return CreateTrueColor(s.W(), s.H()); } |
521 |
// Create, determining the image format from the data |
522 |
/// Read an image from an open FILE * handle, after determining the image format |
523 |
bool CreateFrom(FILE * in); |
524 |
/// Read an image from an open standard library input stream, after determining the image format |
525 |
bool CreateFrom(std::istream & in); |
526 |
/// Read an image from a memory block, after determining the image format |
527 |
bool CreateFrom(int size, void * data); |
528 |
// Png |
529 |
bool CreateFromPng(FILE * in) |
530 |
{ |
531 |
clear(); |
532 |
return ((im = gdImageCreateFromPng(in)) != 0); |
533 |
} |
534 |
bool CreateFromPng(gdIOCtx * in) |
535 |
{ |
536 |
clear(); |
537 |
return ((im = gdImageCreateFromPngCtx(in)) != 0); |
538 |
} |
539 |
bool CreateFromPng(int size, void * data) |
540 |
{ |
541 |
clear(); |
542 |
return ((im = gdImageCreateFromPngPtr(size, data)) != 0); |
543 |
} |
544 |
bool CreateFromPng(std::istream & in) |
545 |
{ |
546 |
clear(); |
547 |
istreamIOCtx _in_ctx(in); |
548 |
return ((im = gdImageCreateFromPngCtx( & _in_ctx)) != 0); |
549 |
} |
550 |
// Gif |
551 |
bool CreateFromGif(FILE * in) |
552 |
{ |
553 |
clear(); |
554 |
return ((im = gdImageCreateFromGif(in)) != 0); |
555 |
} |
556 |
bool CreateFromGif(gdIOCtx * in) |
557 |
{ |
558 |
clear(); |
559 |
return ((im = gdImageCreateFromGifCtx(in)) != 0); |
560 |
} |
561 |
bool CreateFromGif(int size, void * data) |
562 |
{ |
563 |
clear(); |
564 |
return ((im = gdImageCreateFromGifPtr(size, data)) != 0); |
565 |
} |
566 |
bool CreateFromGif(std::istream & in) |
567 |
{ |
568 |
clear(); |
569 |
istreamIOCtx _in_ctx(in); |
570 |
return ((im = gdImageCreateFromGifCtx( & _in_ctx)) != 0); |
571 |
} |
572 |
// WBMP |
573 |
bool CreateFromWBMP(FILE * in) |
574 |
{ |
575 |
clear(); |
576 |
return ((im = gdImageCreateFromWBMP(in)) != 0); |
577 |
} |
578 |
bool CreateFromWBMP(gdIOCtx * in) |
579 |
{ |
580 |
clear(); |
581 |
return ((im = gdImageCreateFromWBMPCtx(in)) != 0); |
582 |
} |
583 |
bool CreateFromWBMP(int size, void * data) |
584 |
{ |
585 |
clear(); |
586 |
return ((im = gdImageCreateFromWBMPPtr(size, data)) != 0); |
587 |
} |
588 |
bool CreateFromWBMP(std::istream & in) |
589 |
{ |
590 |
clear(); |
591 |
istreamIOCtx _in_ctx(in); |
592 |
return ((im = gdImageCreateFromWBMPCtx( & _in_ctx)) != 0); |
593 |
} |
594 |
// Jpeg |
595 |
/** |
596 |
Load a truecolor image from a JPEG format file. |
597 |
Invoke CreateFromJpeg with an already opened |
598 |
pointer to a file containing the desired image. |
599 |
CreateFromJpeg does not close the file. |
600 |
\return true for success, or false if unable to load the image (most often because |
601 |
the file is corrupt or does not contain a JPEG image). |
602 |
You can call Width() and Height() member functions of the image to determine its |
603 |
size. The returned image is always a truecolor image. |
604 |
*/ |
605 |
bool CreateFromJpeg(FILE * in) |
606 |
{ |
607 |
clear(); |
608 |
return ((im = gdImageCreateFromJpeg(in)) != 0); |
609 |
} |
610 |
/** |
611 |
Load a truecolor image from a JPEG format file. |
612 |
Invoke CreateFromJpeg with an already opened |
613 |
pointer to a file containing the desired image. |
614 |
CreateFromJpeg does not close the file. |
615 |
\return true for success, or false if unable to load the image (most often because the file is corrupt or does not contain a JPEG image). |
616 |
You can call Width() and Height() member functions of the image to determine its |
617 |
size. The returned image is always a truecolor image. |
618 |
*/ |
619 |
bool CreateFromJpeg(gdIOCtx * in) |
620 |
{ |
621 |
clear(); |
622 |
return ((im = gdImageCreateFromJpegCtx(in)) != 0); |
623 |
} |
624 |
/** |
625 |
Load a truecolor image from a JPEG format file. |
626 |
Invoke CreateFromJpeg with an already opened |
627 |
pointer to a file containing the desired image. |
628 |
CreateFromJpeg does not close the file. |
629 |
\return true for success, or false if unable to load the image (most often because the file is corrupt or does not contain a JPEG image). |
630 |
You can call Width() and Height() member functions of the image to determine its |
631 |
size. The returned image is always a truecolor image. |
632 |
*/ |
633 |
bool CreateFromJpeg(int size, void * data) |
634 |
{ |
635 |
clear(); |
636 |
return ((im = gdImageCreateFromJpegPtr(size, data)) != 0); |
637 |
} |
638 |
/** |
639 |
Load a truecolor image from a JPEG format file. |
640 |
Invoke CreateFromJpeg with an image file in memory. |
641 |
\return true for success, or false if unable to load the image (most often because the format is corrupt or does not contain a JPEG image). |
642 |
You can call Width() and Height() member functions of the image to determine its |
643 |
size. The returned image is always a truecolor image. |
644 |
*/ |
645 |
bool CreateFromJpeg(std::istream & in) |
646 |
{ |
647 |
clear(); |
648 |
istreamIOCtx _in_ctx(in); |
649 |
return ((im = gdImageCreateFromJpegCtx( & _in_ctx)) != 0); |
650 |
} |
651 |
// Gd |
652 |
bool CreateFromGd(FILE * in) |
653 |
{ |
654 |
clear(); |
655 |
return ((im = gdImageCreateFromGd(in)) != 0); |
656 |
} |
657 |
bool CreateFromGd(gdIOCtx * in) |
658 |
{ |
659 |
clear(); |
660 |
return ((im = gdImageCreateFromGdCtx(in)) != 0); |
661 |
} |
662 |
bool CreateFromGd(int size, void * data) |
663 |
{ |
664 |
clear(); |
665 |
return ((im = gdImageCreateFromGdPtr(size, data)) != 0); |
666 |
} |
667 |
bool CreateFromGd(std::istream & in) |
668 |
{ |
669 |
clear(); |
670 |
istreamIOCtx _in_ctx(in); |
671 |
return ((im = gdImageCreateFromGdCtx( & _in_ctx)) != 0); |
672 |
} |
673 |
// Gd2 |
674 |
bool CreateFromGd2(FILE * in) |
675 |
{ |
676 |
clear(); |
677 |
return ((im = gdImageCreateFromGd2(in)) != 0); |
678 |
} |
679 |
bool CreateFromGd2(gdIOCtx * in) |
680 |
{ |
681 |
clear(); |
682 |
return ((im = gdImageCreateFromGd2Ctx(in)) != 0); |
683 |
} |
684 |
bool CreateFromGd2(int size, void * data) |
685 |
{ |
686 |
clear(); |
687 |
return ((im = gdImageCreateFromGd2Ptr(size, data)) != 0); |
688 |
} |
689 |
bool CreateFromGd2(std::istream & in) |
690 |
{ |
691 |
clear(); |
692 |
istreamIOCtx _in_ctx(in); |
693 |
return ((im = gdImageCreateFromGd2Ctx( & _in_ctx)) != 0); |
694 |
} |
695 |
// Gd2 Part |
696 |
bool CreateFromGd2Part(FILE * in, int srcx, int srcy, int w, int h) |
697 |
{ |
698 |
clear(); |
699 |
return ((im = gdImageCreateFromGd2Part(in, srcx, srcy, w, h)) != 0); |
700 |
} |
701 |
bool CreateFromGd2Part(gdIOCtx * in, int srcx, int srcy, int w, int h) |
702 |
{ |
703 |
clear(); |
704 |
return ((im = gdImageCreateFromGd2PartCtx(in, srcx, srcy, w, h)) != 0); |
705 |
} |
706 |
bool CreateFromGd2Part(int size, void * data, int srcx, int srcy, int w, int h) |
707 |
{ |
708 |
clear(); |
709 |
return ((im = gdImageCreateFromGd2PartPtr(size, data, srcx, srcy, w, h)) != 0); |
710 |
} |
711 |
bool CreateFromGd2Part(std::istream & in, int srcx, int srcy, int w, int h) |
712 |
{ |
713 |
clear(); |
714 |
istreamIOCtx _in_ctx(in); |
715 |
return ((im = gdImageCreateFromGd2PartCtx( & _in_ctx, srcx, srcy, w, h)) != 0); |
716 |
} |
717 |
bool CreateFromGd2Part(FILE * in, const Point & src, const Size & s) |
718 |
{ return CreateFromGd2Part(in, src.X(), src.Y(), s.W(), s.H()); } |
719 |
bool CreateFromGd2Part(gdIOCtx * in, const Point & src, const Size & s) |
720 |
{ return CreateFromGd2Part(in, src.X(), src.Y(), s.W(), s.H()); } |
721 |
bool CreateFromGd2Part(int size, void * data, const Point & src, const Size & s) |
722 |
{ return CreateFromGd2Part(size, data, src.X(), src.Y(), s.W(), s.H()); } |
723 |
bool CreateFromGd2Part(std::istream & in, const Point & src, const Size & s) |
724 |
{ return CreateFromGd2Part(in, src.X(), src.Y(), s.W(), s.H()); } |
725 |
// Xbm |
726 |
bool CreateFromXbm(FILE * in) |
727 |
{ |
728 |
clear(); |
729 |
return ((im = gdImageCreateFromXbm(in)) != 0); |
730 |
} |
731 |
// Xpm |
732 |
bool CreateFromXpm(char * filename) |
733 |
{ |
734 |
clear(); |
735 |
return ((im = gdImageCreateFromXpm(filename)) != 0); |
736 |
} |
737 |
bool CreateFromXpm(std::string & filename) |
738 |
{ return CreateFromXpm((char *)(filename.c_str())); } |
739 |
|
740 |
// Accessors, Updaters & Methods: |
741 |
void SetPixel(int x, int y, int color) |
742 |
{ gdImageSetPixel(im, x, y, color); } |
743 |
void SetPixel(const Point & p, int color) |
744 |
{ SetPixel(p.X(), p.Y(), color); } |
745 |
int GetPixel(int x, int y) const |
746 |
{ return gdImageGetPixel(im, x, y); } |
747 |
int GetPixel(const Point & p) const |
748 |
{ return GetPixel(p.X(), p.Y()); } |
749 |
int GetTrueColorPixel(int x, int y) const |
750 |
{ return gdImageGetTrueColorPixel(im, x, y); } |
751 |
int GetTrueColorPixel(const Point & p) const |
752 |
{ return GetTrueColorPixel(p.X(), p.Y()); } |
753 |
|
754 |
void SetPixel(int x, int y, TrueColor c) |
755 |
{ SetPixel(x, y, c.Int()); } |
756 |
void SetPixel(const Point & p, TrueColor c) |
757 |
{ SetPixel(p.X(), p.Y(), c.Int()); } |
758 |
void GetTrueColorPixel(TrueColor & c, int x, int y) const |
759 |
{ c.set(GetTrueColorPixel(x, y)); } |
760 |
void GetTrueColorPixel(TrueColor & c, const Point & p) const |
761 |
{ c.set(GetTrueColorPixel(p.X(), p.Y())); } |
762 |
|
763 |
void AABlend() |
764 |
{ gdImageAABlend(im); } |
765 |
|
766 |
void Line(int x1, int y1, int x2, int y2, int color) |
767 |
{ gdImageLine(im, x1, y1, x2, y2, color); } |
768 |
void Line(const Point & p1, const Point & p2, int color) |
769 |
{ Line(p1.X(), p1.Y(), p2.X(), p2.Y(), color); } |
770 |
void Rectangle(int x1, int y1, int x2, int y2, int color) |
771 |
{ gdImageRectangle(im, x1, y1, x2, y2, color); } |
772 |
void Rectangle(const Point & p1, const Point & p2, int color) |
773 |
{ Rectangle(p1.X(), p1.Y(), p2.X(), p2.Y(), color); } |
774 |
void Rectangle(const Point & p, const Size & s, int color) |
775 |
{ Rectangle(p.X(), p.Y(), p.X() + s.W(), p.Y() + s.H(), color); } |
776 |
void FilledRectangle(int x1, int y1, int x2, int y2, int color) |
777 |
{ gdImageFilledRectangle(im, x1, y1, x2, y2, color); } |
778 |
void FilledRectangle(const Point & p1, const Point & p2, int color) |
779 |
{ FilledRectangle(p1.X(), p1.Y(), p2.X(), p2.Y(), color); } |
780 |
void FilledRectangle(const Point & p, const Size & s, int color) |
781 |
{ FilledRectangle(p.X(), p.Y(), p.X() + s.W(), p.Y() + s.H(), color); } |
782 |
|
783 |
void SetClip(int x1, int y1, int x2, int y2) |
784 |
{ gdImageSetClip(im, x1, y1, x2, y2); } |
785 |
void SetClip(const Point & p1, const Point & p2) |
786 |
{ SetClip(p1.X(), p1.Y(), p2.X(), p2.Y()); } |
787 |
void SetClip(const Point & p, const Size & s) |
788 |
{ SetClip(p.X(), p.Y(), p.X() + s.W(), p.Y() + s.H()); } |
789 |
void GetClip(int & x1, int & y1, int & x2, int & y2) const |
790 |
{ gdImageGetClip(im, & x1, & y1, & x2, & y2); } |
791 |
void GetClip(Point & p1, Point & p2) const |
792 |
{ GetClip(p1.lhsX(), p1.lhsY(), p2.lhsX(), p2.lhsY()); } |
793 |
void GetClip(Point & p, Size & s) const |
794 |
{ |
795 |
Point p2; |
796 |
GetClip(p.lhsX(), p.lhsY(), p2.lhsX(), p2.lhsY()); |
797 |
s.set(p2.X() - p.X(), p2.Y() - p.Y()); |
798 |
} |
799 |
|
800 |
bool BoundsSafe(int x, int y) const |
801 |
{ return (gdImageBoundsSafe(im, x, y)?true:false); } |
802 |
bool BoundsSafe(const Point & p) const |
803 |
{ return BoundsSafe(p.X(), p.Y()); } |
804 |
|
805 |
void Char(gdFontPtr f, int x, int y, int c, int color) |
806 |
{ gdImageChar(im, f, x, y, c, color); } |
807 |
void CharUp(gdFontPtr f, int x, int y, int c, int color) |
808 |
{ gdImageCharUp(im, f, x, y, c, color); } |
809 |
|
810 |
void Char(gdFontPtr f, const Point & p, int c, int color) |
811 |
{ Char(f, p.X(), p.Y(), c, color); } |
812 |
void CharUp(gdFontPtr f, const Point & p, int c, int color) |
813 |
{ CharUp(f, p.X(), p.Y(), c, color); } |
814 |
|
815 |
void String(gdFontPtr f, int x, int y, unsigned char * s, int color) |
816 |
{ gdImageString(im, f, x, y, (unsigned char *)s, color); } |
817 |
void StringUp(gdFontPtr f, int x, int y, unsigned char * s, int color) |
818 |
{ gdImageStringUp(im, f, x, y, (unsigned char *)s, color); } |
819 |
void String(gdFontPtr f, int x, int y, unsigned short * s, int color) |
820 |
{ gdImageString16(im, f, x, y, (unsigned short *)s, color); } |
821 |
void StringUp(gdFontPtr f, int x, int y, unsigned short * s, int color) |
822 |
{ gdImageStringUp16(im, f, x, y, (unsigned short *)s, color); } |
823 |
void String(gdFontPtr f, int x, int y, char * s, int color) |
824 |
{ gdImageString(im, f, x, y, (unsigned char *)s, color); } |
825 |
void StringUp(gdFontPtr f, int x, int y, char * s, int color) |
826 |
{ gdImageStringUp(im, f, x, y, (unsigned char *)s, color); } |
827 |
void String(gdFontPtr f, int x, int y, const std::string & s, int color) |
828 |
{ String(f, x, y, (char *)s.c_str(), color); } |
829 |
void StringUp(gdFontPtr f, int x, int y, const std::string & s, int color) |
830 |
{ StringUp(f, x, y, (char *)s.c_str(), color); } |
831 |
|
832 |
void String(gdFontPtr f, const Point & p, unsigned char * s, int color) |
833 |
{ String(f, p.X(), p.Y(), (unsigned char *)s, color); } |
834 |
void StringUp(gdFontPtr f, const Point & p, unsigned char * s, int color) |
835 |
{ StringUp(f, p.X(), p.Y(), (unsigned char *)s, color); } |
836 |
void String(gdFontPtr f, const Point & p, unsigned short * s, int color) |
837 |
{ String(f, p.X(), p.Y(), (unsigned short *)s, color); } |
838 |
void StringUp(gdFontPtr f, const Point & p, unsigned short * s, int color) |
839 |
{ StringUp(f, p.X(), p.Y(), (unsigned short *)s, color); } |
840 |
void String(gdFontPtr f, const Point & p, char * s, int color) |
841 |
{ String(f, p.X(), p.Y(), (unsigned char *)s, color); } |
842 |
void StringUp(gdFontPtr f, const Point & p, char * s, int color) |
843 |
{ StringUp(f, p.X(), p.Y(), (unsigned char *)s, color); } |
844 |
void String(gdFontPtr f, const Point & p, const std::string & s, int color) |
845 |
{ String(f, p, (char *)s.c_str(), color); } |
846 |
void StringUp(gdFontPtr f, const Point & p, const std::string & s, int color) |
847 |
{ StringUp(f, p, (char *)s.c_str(), color); } |
848 |
|
849 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
850 |
int x, int y, char * string) |
851 |
{ return gdImageStringFT(im, brect, fg, fontlist, ptsize, angle, x, y, string); } |
852 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
853 |
int x, int y, char * string, gdFTStringExtraPtr strex) |
854 |
{ return gdImageStringFTEx(im, brect, fg, fontlist, ptsize, angle, x, y, string, strex); } |
855 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
856 |
int x, int y, const std::string & string) |
857 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, x, y, (char *)string.c_str()); } |
858 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
859 |
int x, int y, const std::string & string, gdFTStringExtraPtr strex) |
860 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, x, y, (char *)string.c_str(), strex); } |
861 |
|
862 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
863 |
const Point & p, char * string) |
864 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, p.X(), p.Y(), string); } |
865 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
866 |
const Point & p, char * string, gdFTStringExtraPtr strex) |
867 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, p.X(), p.Y(), string, strex); } |
868 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
869 |
const Point & p, const std::string & string) |
870 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, p, (char *)string.c_str()); } |
871 |
char * StringFT(int * brect, int fg, char * fontlist, double ptsize, double angle, |
872 |
const Point & p, const std::string & string, gdFTStringExtraPtr strex) |
873 |
{ return StringFT(brect, fg, fontlist, ptsize, angle, p, (char *)string.c_str(), strex); } |
874 |
|
875 |
void Polygon(gdPointPtr p, int n, int c) |
876 |
{ gdImagePolygon(im, p, n, c); } |
877 |
void OpenPolygon(gdPointPtr p, int n, int c) |
878 |
{ gdImageOpenPolygon(im, p, n, c); } |
879 |
void FilledPolygon(gdPointPtr p, int n, int c) |
880 |
{ gdImageFilledPolygon(im, p, n, c); } |
881 |
|
882 |
void Polygon(PointPtr p, int n, int c) |
883 |
{ Polygon(p->as_gdPointPtr(), n, c); } |
884 |
void OpenPolygon(PointPtr p, int n, int c) |
885 |
{ OpenPolygon(p->as_gdPointPtr(), n, c); } |
886 |
void FilledPolygon(PointPtr p, int n, int c) |
887 |
{ FilledPolygon(p->as_gdPointPtr(), n, c); } |
888 |
|
889 |
int ColorAllocate(int r, int g, int b) |
890 |
{ return gdImageColorAllocate(im, r, g, b); } |
891 |
int ColorAllocate(int r, int g, int b, int a) |
892 |
{ return gdImageColorAllocateAlpha(im, r, g, b, a); } |
893 |
|
894 |
int ColorClosest(int r, int g, int b) const |
895 |
{ return gdImageColorClosest(im, r, g, b); } |
896 |
int ColorClosest(int r, int g, int b, int a) const |
897 |
{ return gdImageColorClosestAlpha(im, r, g, b, a); } |
898 |
int ColorClosestHWB(int r, int g, int b) const |
899 |
{ return gdImageColorClosestHWB(im, r, g, b); } |
900 |
int ColorExact(int r, int g, int b) const |
901 |
{ return gdImageColorExact(im, r, g, b); } |
902 |
int ColorExact(int r, int g, int b, int a) const |
903 |
{ return gdImageColorExactAlpha(im, r, g, b, a); } |
904 |
int ColorResolve(int r, int g, int b) |
905 |
{ return gdImageColorResolve(im, r, g, b); } |
906 |
int ColorResolve(int r, int g, int b, int a) |
907 |
{ return gdImageColorResolveAlpha(im, r, g, b, a); } |
908 |
|
909 |
void ColorDeallocate(int color) |
910 |
{ gdImageColorDeallocate(im, color); } |
911 |
|
912 |
void TrueColorToPalette(int ditherFlag, int colorsWanted) |
913 |
{ gdImageTrueColorToPalette(im, ditherFlag, colorsWanted); } |
914 |
|
915 |
void ColorTransparent(int color) |
916 |
{ gdImageColorTransparent(im, color); } |
917 |
|
918 |
void PaletteCopy(gdImagePtr src) |
919 |
{ gdImagePaletteCopy(im, src); } |
920 |
void PaletteCopy(const GD::Image & src) |
921 |
{ PaletteCopy(src.im); } |
922 |
|
923 |
/** |
924 |
Write out this image in GIF file format to \p out. |
925 |
\param out A FILE * handle |
926 |
*/ |
927 |
void Gif(FILE * out) const |
928 |
{ gdImageGif(im, out); } |
929 |
/** |
930 |
Write out this image in GIF file format to \p out. |
931 |
\param out A gdIOCtx * handle |
932 |
*/ |
933 |
void Gif(gdIOCtx * out) const |
934 |
{ gdImageGifCtx(im, out); } |
935 |
/** |
936 |
Allocate sufficient memory, and write this image, in GIF file format, to that memory. |
937 |
\param size A pointer for the allocated memory |
938 |
\return A pointer to the allocated memory, containing the image GIF file formatted. Caller is responsible for freeing with gdFree(). |
939 |
*/ |
940 |
void * Gif(int * size) const |
941 |
{ return gdImageGifPtr(im, size); } |
942 |
/** |
943 |
Write out this image in GIF file format to \p out. |
944 |
\param out An output stream, already opened. |
945 |
*/ |
946 |
void Gif(std::ostream & out) const |
947 |
{ |
948 |
ostreamIOCtx _out_ctx(out); |
949 |
gdImageGifCtx(im, & _out_ctx); |
950 |
} |
951 |
|
952 |
/** |
953 |
Write out this image in PNG file format to \p out. |
954 |
\param out A FILE * handle |
955 |
*/ |
956 |
void Png(FILE * out) const |
957 |
{ gdImagePng(im, out); } |
958 |
/** |
959 |
Write out this image in PNG file format to \p out. |
960 |
\param out A gdIOCtx * handle |
961 |
*/ |
962 |
void Png(gdIOCtx * out) const |
963 |
{ gdImagePngCtx(im, out); } |
964 |
/** |
965 |
Allocate sufficient memory, and write this image, in PNG file format, to that memory. |
966 |
\param size A pointer for the allocated memory |
967 |
\return A pointer to the allocated memory, containing the image PNG file formatted. Caller is responsible for freeing with gdFree(). |
968 |
*/ |
969 |
void * Png(int * size) const |
970 |
{ return gdImagePngPtr(im, size); } |
971 |
/** |
972 |
Write out this image in PNG file format to \p out. |
973 |
\param out An output stream, already opened. |
974 |
*/ |
975 |
void Png(std::ostream & out) const |
976 |
{ |
977 |
ostreamIOCtx _out_ctx(out); |
978 |
gdImagePngCtx(im, & _out_ctx); |
979 |
} |
980 |
/** |
981 |
Write out this image in PNG file format to \p out. |
982 |
\param out A FILE * handle |
983 |
\param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level |
984 |
*/ |
985 |
void Png(FILE * out, int level) const |
986 |
{ gdImagePngEx(im, out, level); } |
987 |
/** |
988 |
Write out this image in PNG file format to \p out. |
989 |
\param out A gdIOCtx * handle |
990 |
\param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level |
991 |
*/ |
992 |
void Png(gdIOCtx * out, int level) const |
993 |
{ gdImagePngCtxEx(im, out, level); } |
994 |
/** |
995 |
Allocate sufficient memory, and write this image, in PNG file format, to that memory. |
996 |
\param size A pointer for the allocated memory |
997 |
\param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level |
998 |
\return A pointer to the allocated memory, containing the image PNG file formatted. Caller is responsible for freeing with gdFree(). |
999 |
*/ |
1000 |
void * Png(int * size, int level) const |
1001 |
{ return gdImagePngPtrEx(im, size, level); } |
1002 |
/** |
1003 |
Write out this image in PNG file format to \p out. |
1004 |
\param out An output stream, already opened. |
1005 |
\param level The level of compression: 0 == "no compression", 1 == "compressed as quickly as possible" --> 9 == "compressed as much as possible", -1 == zlib default compression level |
1006 |
*/ |
1007 |
void Png(std::ostream & out, int level) const |
1008 |
{ |
1009 |
ostreamIOCtx _out_ctx(out); |
1010 |
gdImagePngCtxEx(im, & _out_ctx, level); |
1011 |
} |
1012 |
|
1013 |
/** |
1014 |
Write out this image in WBMP file format ( black and white only ) to \p out. |
1015 |
\param fg The color index of the foreground. All other pixels considered background. |
1016 |
\param out A FILE * handle |
1017 |
*/ |
1018 |
void WBMP(int fg, FILE * out) const |
1019 |
{ gdImageWBMP(im, fg, out); } |
1020 |
/** |
1021 |
Write out this image in WBMP file format ( black and white only ) to \p out. |
1022 |
\param fg The color index of the foreground. All other pixels considered background. |
1023 |
\param out A gdIOCtx * handle |
1024 |
*/ |
1025 |
void WBMP(int fg, gdIOCtx * out) const |
1026 |
{ gdImageWBMPCtx(im, fg, out); } |
1027 |
/** |
1028 |
Allocate sufficient memory, and write this image, in WBMP file format ( black and white only ), to that memory. |
1029 |
\param size A pointer for the allocated memory |
1030 |
\param fg The color index of the foreground. All other pixels considered background. |
1031 |
\return A pointer to the allocated memory, containing the image WBMP file formatted. Caller is responsible for freeing with gdFree(). |
1032 |
*/ |
1033 |
void * WBMP(int * size, int fg) const |
1034 |
{ return gdImageWBMPPtr(im, size, fg); } |
1035 |
/** |
1036 |
Write out this image in WBMP file format ( black and white only ) to \p out. |
1037 |
\param fg The color index of the foreground. All other pixels considered background. |
1038 |
\param out An output stream, already opened. |
1039 |
*/ |
1040 |
void WBMP(int fg, std::ostream & out) const |
1041 |
{ |
1042 |
ostreamIOCtx _out_ctx(out); |
1043 |
gdImageWBMPCtx(im, fg, & _out_ctx); |
1044 |
} |
1045 |
|
1046 |
/** |
1047 |
Write out this image in JPEG file format to \p out. |
1048 |
\param out A FILE * handle |
1049 |
\param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". |
1050 |
*/ |
1051 |
void Jpeg(FILE * out, int quality = -1) const |
1052 |
{ gdImageJpeg(im, out, quality); } |
1053 |
/** |
1054 |
Write out this image in JPEG file format to \p out. |
1055 |
\param out A gdIOCtx * handle |
1056 |
\param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". |
1057 |
*/ |
1058 |
void Jpeg(gdIOCtx * out, int quality = -1) const |
1059 |
{ gdImageJpegCtx(im, out, quality); } |
1060 |
/** |
1061 |
Allocate sufficient memory, and write this image, in JPEG file format, to that memory. |
1062 |
\param size A pointer for the allocated memory |
1063 |
\param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". |
1064 |
\return A pointer to the allocated memory, containing the image JPEG file formatted. Caller is responsible for freeing with gdFree(). |
1065 |
*/ |
1066 |
void * Jpeg(int * size, int quality = -1) const |
1067 |
{ return gdImageJpegPtr(im, size, quality); } |
1068 |
/** |
1069 |
Write out this image in JPEG file format to \p out. |
1070 |
\param out An output stream, already opened. |
1071 |
\param quality Should be a value in the range 0-95, higher numbers imply both higher quality and larger image size. Default value is -1, indicating "use a sensible default value". |
1072 |
*/ |
1073 |
void Jpeg(std::ostream & out, int quality = -1) const |
1074 |
{ |
1075 |
ostreamIOCtx _out_ctx(out); |
1076 |
gdImageJpegCtx(im, & _out_ctx, quality); |
1077 |
} |
1078 |
|
1079 |
void GifAnimBegin(FILE * out, int GlobalCM, int Loops) const |
1080 |
{ gdImageGifAnimBegin(im, out, GlobalCM, Loops); } |
1081 |
void GifAnimAdd(FILE * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const |
1082 |
{ gdImageGifAnimAdd(im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } |
1083 |
void GifAnimAdd(FILE * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const |
1084 |
{ GifAnimAdd(out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } |
1085 |
inline static void GifAnimEnd(FILE * out) |
1086 |
{ gdImageGifAnimEnd(out); } |
1087 |
void GifAnimBegin(gdIOCtx * out, int GlobalCM, int Loops) const |
1088 |
{ gdImageGifAnimBeginCtx(im, out, GlobalCM, Loops); } |
1089 |
void GifAnimAdd(gdIOCtx * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const |
1090 |
{ gdImageGifAnimAddCtx(im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } |
1091 |
void GifAnimAdd(gdIOCtx * out, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const |
1092 |
{ GifAnimAdd(out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } |
1093 |
inline static void GifAnimEnd(gdIOCtx * out) |
1094 |
{ gdImageGifAnimEndCtx(out); } |
1095 |
void * GifAnimBegin(int * size, int GlobalCM, int Loops) const |
1096 |
{ return gdImageGifAnimBeginPtr(im, size, GlobalCM, Loops); } |
1097 |
void * GifAnimAdd(int * size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, gdImagePtr previm) const |
1098 |
{ return gdImageGifAnimAddPtr(im, size, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm); } |
1099 |
void * GifAnimAdd(int * size, int LocalCM, int LeftOfs, int TopOfs, int Delay, int Disposal, const GD::Image & previm) const |
1100 |
{ return GifAnimAdd(size, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm.im); } |
1101 |
inline static void * GifAnimEnd(int * size) |
1102 |
{ return gdImageGifAnimEndPtr(size); } |
1103 |
|
1104 |
void Gd(FILE * out) const |
1105 |
{ gdImageGd(im, out); } |
1106 |
void Gd(int * size) const |
1107 |
{ gdImageGdPtr(im, size); } |
1108 |
void Gd2(FILE * out, int cs, int fmt) const |
1109 |
{ gdImageGd2(im, out, cs, fmt); } |
1110 |
void Gd2(int cs, int fmt, int * size) const |
1111 |
{ gdImageGd2Ptr(im, cs, fmt, size); } |
1112 |
|
1113 |
void Ellipse(int cx, int cy, int w, int h, int color) |
1114 |
{ gdImageEllipse(im, cx, cy, w, h, color); } |
1115 |
/** |
1116 |
Draw a partial ellipse centered at the given point, with the specified width and height in pixels. |
1117 |
*/ |
1118 |
void FilledArc(int cx, int cy, int w, int h, int s, int e, int color, int style) |
1119 |
{ gdImageFilledArc(im, cx, cy, w, h, s, e, color, style); } |
1120 |
void Arc(int cx, int cy, int w, int h, int s, int e, int color) |
1121 |
{ gdImageArc(im, cx, cy, w, h, s, e, color); } |
1122 |
void FilledEllipse(int cx, int cy, int w, int h, int color) |
1123 |
{ gdImageFilledEllipse(im, cx, cy, w, h, color); } |
1124 |
void FillToBorder(int x, int y, int border, int color) |
1125 |
{ gdImageFillToBorder(im, x, y, border, color); } |
1126 |
void Fill(int x, int y, int color) |
1127 |
{ gdImageFill(im, x, y, color); } |
1128 |
|
1129 |
void Ellipse(const Point & c, const Size & s, int color) |
1130 |
{ Ellipse(c.X(), c.Y(), s.W(), s.H(), color); } |
1131 |
void FilledArc(const Point & c, const Size & si, int s, int e, int color, int style) |
1132 |
{ FilledArc(c.X(), c.Y(), si.W(), si.H(), s, e, color, style); } |
1133 |
void Arc(const Point & c, const Size & si, int s, int e, int color) |
1134 |
{ Arc(c.X(), c.Y(), si.W(), si.H(), s, e, color); } |
1135 |
void FilledEllipse(const Point & c, const Size & s, int color) |
1136 |
{ FilledEllipse(c.X(), c.Y(), s.W(), s.H(), color); } |
1137 |
void FillToBorder(const Point & p, int border, int color) |
1138 |
{ FillToBorder(p.X(), p.Y(), border, color); } |
1139 |
void Fill(const Point & p, int color) |
1140 |
{ Fill(p.X(), p.Y(), color); } |
1141 |
|
1142 |
void Copy(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h) |
1143 |
{ gdImageCopy(im, src, dstX, dstY, srcX, srcY, w, h); } |
1144 |
void CopyMerge(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) |
1145 |
{ gdImageCopyMerge(im, src, dstX, dstY, srcX, srcY, w, h, pct); } |
1146 |
void CopyMergeGray(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) |
1147 |
{ gdImageCopyMergeGray(im, src, dstX, dstY, srcX, srcY, w, h, pct); } |
1148 |
|
1149 |
void CopyResized(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) |
1150 |
{ gdImageCopyResized(im, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } |
1151 |
void CopyResampled(const gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) |
1152 |
{ gdImageCopyResampled(im, src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } |
1153 |
void CopyRotated(const gdImagePtr src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle) |
1154 |
{ gdImageCopyRotated(im, src, dstX, dstY, srcX, srcY, srcWidth, srcHeight, angle); } |
1155 |
|
1156 |
void Copy(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & s) |
1157 |
{ Copy(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H()); } |
1158 |
void CopyMerge(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & s, int pct) |
1159 |
{ CopyMerge(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } |
1160 |
void CopyMergeGray(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & s, int pct) |
1161 |
{ CopyMergeGray(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } |
1162 |
|
1163 |
void CopyResized(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) |
1164 |
{ CopyResized(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } |
1165 |
void CopyResampled(const gdImagePtr src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) |
1166 |
{ CopyResampled(src, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } |
1167 |
void CopyRotated(const gdImagePtr src, double dstX, double dstY, const Point & srcP, const Size & srcS, int angle) |
1168 |
{ CopyRotated(src, dstX, dstY, srcP.X(), srcP.Y(), srcS.W(), srcS.H(), angle); } |
1169 |
|
1170 |
void Copy(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h) |
1171 |
{ Copy(src.im, dstX, dstY, srcX, srcY, w, h); } |
1172 |
void CopyMerge(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) |
1173 |
{ CopyMerge(src.im, dstX, dstY, srcX, srcY, w, h, pct); } |
1174 |
void CopyMergeGray(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int w, int h, int pct) |
1175 |
{ CopyMergeGray(src.im, dstX, dstY, srcX, srcY, w, h, pct); } |
1176 |
|
1177 |
void CopyResized(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) |
1178 |
{ CopyResized(src.im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } |
1179 |
void CopyResampled(const GD::Image & src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) |
1180 |
{ CopyResampled(src.im, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH); } |
1181 |
void CopyRotated(const GD::Image & src, double dstX, double dstY, int srcX, int srcY, int srcWidth, int srcHeight, int angle) |
1182 |
{ CopyRotated(src.im, dstX, dstY, srcX, srcY, srcWidth, srcHeight, angle); } |
1183 |
|
1184 |
void Copy(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s) |
1185 |
{ Copy(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H()); } |
1186 |
void CopyMerge(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s, int pct) |
1187 |
{ CopyMerge(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } |
1188 |
void CopyMergeGray(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & s, int pct) |
1189 |
{ CopyMergeGray(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), s.W(), s.H(), pct); } |
1190 |
|
1191 |
void CopyResized(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) |
1192 |
{ CopyResized(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } |
1193 |
void CopyResampled(const GD::Image & src, const Point & dstP, const Point & srcP, const Size & dstS, const Size & srcS) |
1194 |
{ CopyResampled(src.im, dstP.X(), dstP.Y(), srcP.X(), srcP.Y(), dstS.W(), dstS.H(), srcS.W(), srcS.H()); } |
1195 |
void CopyRotated(const GD::Image & src, double dstX, double dstY, const Point & srcP, const Size & srcS, int angle) |
1196 |
{ CopyRotated(src.im, dstX, dstY, srcP.X(), srcP.Y(), srcS.W(), srcS.H(), angle); } |
1197 |
|
1198 |
void SetBrush(gdImagePtr brush) |
1199 |
{ gdImageSetBrush(im, brush); } |
1200 |
void SetBrush(const GD::Image & brush) |
1201 |
{ SetBrush(brush.im); } |
1202 |
void SetTile(gdImagePtr tile) |
1203 |
{ gdImageSetTile(im, tile); } |
1204 |
void SetTile(const GD::Image & tile) |
1205 |
{ SetTile(tile.im); } |
1206 |
void SetAntiAliased(int c) |
1207 |
{ gdImageSetAntiAliased(im, c); } |
1208 |
void SetAntiAliasedDontBlend(int c, int dont_blend) |
1209 |
{ gdImageSetAntiAliasedDontBlend(im, c, dont_blend); } |
1210 |
void SetStyle(int * style, int noOfPixels) |
1211 |
{ gdImageSetStyle(im, style, noOfPixels); } |
1212 |
void SetThickness(int thickness) |
1213 |
{ gdImageSetThickness(im, thickness); } |
1214 |
|
1215 |
void Interlace(bool interlaceArg) |
1216 |
{ gdImageInterlace(im, interlaceArg?1:0); } |
1217 |
void AlphaBlending(bool alphaBlendingArg) |
1218 |
{ gdImageAlphaBlending(im, alphaBlendingArg?1:0); } |
1219 |
void SaveAlpha(bool saveAlphaArg) |
1220 |
{ gdImageSaveAlpha(im, saveAlphaArg?1:0); } |
1221 |
|
1222 |
bool IsTrueColor() const |
1223 |
{ return (gdImageTrueColor(im)?true:false); } |
1224 |
int SX() const |
1225 |
{ return gdImageSX(im); } |
1226 |
int SY() const |
1227 |
{ return gdImageSY(im); } |
1228 |
int Width() const |
1229 |
{ return SX(); } |
1230 |
int Height() const |
1231 |
{ return SY(); } |
1232 |
void GetSize(Size & s) const |
1233 |
{ s.set(SX(), SY()); } |
1234 |
int ColorsTotal() const |
1235 |
{ return gdImageColorsTotal(im); } |
1236 |
int Red(int color) const |
1237 |
{ return gdImageRed(im, color); } |
1238 |
int Green(int color) const |
1239 |
{ return gdImageGreen(im, color); } |
1240 |
int Blue(int color) const |
1241 |
{ return gdImageBlue(im, color); } |
1242 |
int Alpha(int color) const |
1243 |
{ return gdImageAlpha(im, color); } |
1244 |
int GetTransparent() const |
1245 |
{ return gdImageGetTransparent(im); } |
1246 |
int GetInterlaced() const |
1247 |
{ return gdImageGetInterlaced(im); } |
1248 |
int PalettePixel(int x, int y) const |
1249 |
{ return gdImagePalettePixel(im, x, y); } |
1250 |
int TrueColorPixel(int x, int y) const |
1251 |
{ return gdImageTrueColorPixel(im, x, y); } |
1252 |
|
1253 |
const gdImagePtr GetPtr() const |
1254 |
{ return im; } |
1255 |
|
1256 |
protected: |
1257 |
/// Free the internal image pointer |
1258 |
void clear() |
1259 |
{ |
1260 |
if (im) |
1261 |
gdImageDestroy(im); |
1262 |
im = 0; |
1263 |
} |
1264 |
gdImagePtr im; |
1265 |
}; |
1266 |
} // namespace GD |
1267 |
/// Read in an image from a standard library input stream |
1268 |
std::istream & operator>> (std::istream & in, GD::Image & img); |
1269 |
|
1270 |
#endif /* _gdpp_h */ |
1271 |
#endif /* __cplusplus */ |