ruby-gd 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changes +54 -0
- data/GD.c +2602 -0
- data/doc/INSTALL.en +83 -0
- data/doc/INSTALL.ja +91 -0
- data/doc/manual.html +891 -0
- data/doc/manual.rd +969 -0
- data/doc/manual_index.html +146 -0
- data/extconf.rb +79 -0
- data/readme.en +55 -0
- data/readme.ja +74 -0
- data/sample/example.rb +28 -0
- data/sample/gdtestttf.png +0 -0
- data/sample/gdtestttf.rb +62 -0
- data/sample/webpng.rb +111 -0
- metadata +59 -0
data/Changes
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
= Changes from 0.7.3
|
2
|
+
|
3
|
+
* doc/gd-intro_ja.html, doc/imgs/* : removed.
|
4
|
+
* extconf.rb : new option '--enable-gd2_0' added to support for gd-2.0.1(beta).
|
5
|
+
* GD::Image#newTrueColor, GD::Image#colorAllocateAlpha,
|
6
|
+
GD::Image#colorResolveAlpha, GD::Image#colorClosestAlpha,
|
7
|
+
GD::Image#colorExactAlpha, GD::Image#alphaBlending,
|
8
|
+
GD::Image#alpha, GD::Image#trueColor, GD::Image#trueColorAlpha,
|
9
|
+
GD::Image#copyResampled, GD::Image#filledEllipse, GD::Image#filledArc
|
10
|
+
- new methods. They are for the new features of gd-2.0.1(beta).
|
11
|
+
Accordingly, GD#Image.newPalette is an alias for GD::Image#new.
|
12
|
+
* doc/manual.rd: documentation update.
|
13
|
+
|
14
|
+
= Changes from 0.7.2
|
15
|
+
|
16
|
+
* Fixed typos and grammer mistakes in English documents. I thank Neil Conway for
|
17
|
+
sending this patch.
|
18
|
+
|
19
|
+
* GD::Image.stringFT, GD::Image#stringFT: should call gdImageStringFT(), not
|
20
|
+
gdImageStringTTF()!!! I'm sorry. Thanks to YOKOKAWA Takehiro(tac@amris.co.jp).
|
21
|
+
|
22
|
+
* GD::Image#JpegStr, GD::Image#PngStr: new method.
|
23
|
+
Thanks to Colin Steele(colin@webg2.com).
|
24
|
+
|
25
|
+
= Changes from 0.7.1
|
26
|
+
|
27
|
+
* extconf.rb: updated for gd-1.8.4.
|
28
|
+
|
29
|
+
* GD.c: GD::Image.stringFT, GD::Image#stringFT: new methods. Note these methods
|
30
|
+
requires the newest feature of gd-1.8.4.
|
31
|
+
|
32
|
+
* extconf.rb, GD.c: should check GD::Image#colorResolve and GD::Image#stringTTF
|
33
|
+
separately. Thanks to Tosh.
|
34
|
+
|
35
|
+
* GD.c: added new constants GD::GD2_FMT_COMPRESSED, GD::GD2_FMT_RAW.
|
36
|
+
(GD::Image::GD2_FMT_COMPRESSED, etc. is more adequate???)
|
37
|
+
|
38
|
+
* GD.c: rb_str_hex():removed. rb_funcall() is utilized instead. Now works
|
39
|
+
correctly for Ruby-1.4.x.
|
40
|
+
|
41
|
+
* readme.rd: description for GD::Image#gd2 corrected. Thanks to nnakamura.
|
42
|
+
|
43
|
+
* gd-intro_ja.html: copyright notice for some images. updated.
|
44
|
+
|
45
|
+
= Changes from 0.7.0
|
46
|
+
|
47
|
+
* GD.c(GD::Image#colorAllocate, GD::Image#colorExact): the return values
|
48
|
+
conformable to those of the original gd library.
|
49
|
+
|
50
|
+
* GD::Image#colorAllocate, GD::Image#colorResolve, GD::Image#colorClosest,
|
51
|
+
GD::Image#colorClosestHWB, GD::Image#colorExact : allow for the string
|
52
|
+
like "#FF0000"(stands for "red") as an argument.
|
53
|
+
|
54
|
+
* doc/gd_intro-ja.html: corrected and updated. Thanks to Tosh.
|
data/GD.c
ADDED
@@ -0,0 +1,2602 @@
|
|
1
|
+
/*************************************************************
|
2
|
+
|
3
|
+
GD.c - Ruby extension library to use Boutell's gd library.
|
4
|
+
|
5
|
+
Originally written: Yukihiro Matsumoto (matz@ruby-lang.org)
|
6
|
+
|
7
|
+
Current maintainer: Ryuichi Tamura (tam@kais.kyoto-u.ac.jp)
|
8
|
+
|
9
|
+
$Date: 2001/05/30 14:06:40 $
|
10
|
+
$Revision: 1.6.2.3 $
|
11
|
+
**************************************************************/
|
12
|
+
#include "ruby.h"
|
13
|
+
#include "rubyio.h"
|
14
|
+
#include "version.h"
|
15
|
+
|
16
|
+
#include "gd.h"
|
17
|
+
#include "gdfontg.h" /* giant */
|
18
|
+
#include "gdfontl.h" /* large */
|
19
|
+
#include "gdfontmb.h" /* medium bold */
|
20
|
+
#include "gdfonts.h" /* small */
|
21
|
+
#include "gdfontt.h" /* tiny */
|
22
|
+
|
23
|
+
extern VALUE rb_io_binmode(VALUE io);
|
24
|
+
extern gdImagePtr gdImageCreateFromXpm(char* );
|
25
|
+
|
26
|
+
static VALUE mGD, cImage, cFont, cPolygon;
|
27
|
+
|
28
|
+
#ifdef ENABLE_GD_2_0
|
29
|
+
static VALUE
|
30
|
+
is_truecolor(im)
|
31
|
+
gdImagePtr im;
|
32
|
+
{
|
33
|
+
return im->trueColor ? Qtrue : Qfalse;
|
34
|
+
}
|
35
|
+
#endif /* ENABLE_GD_2_0 */
|
36
|
+
|
37
|
+
static void
|
38
|
+
free_img(iptr)
|
39
|
+
gdImagePtr iptr;
|
40
|
+
{
|
41
|
+
if (iptr) {
|
42
|
+
gdImageDestroy(iptr);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
static VALUE
|
47
|
+
img_s_new(klass, w, h)
|
48
|
+
VALUE klass, w, h;
|
49
|
+
{
|
50
|
+
gdImagePtr iptr;
|
51
|
+
|
52
|
+
if (NUM2INT(w)<0 || NUM2INT(h)<0)
|
53
|
+
rb_raise(rb_eArgError, "Negative width/height not allowed");
|
54
|
+
|
55
|
+
iptr = gdImageCreate(NUM2INT(w), NUM2INT(h));
|
56
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
static VALUE
|
61
|
+
img_from_pngfname(klass, fname)
|
62
|
+
VALUE klass, fname;
|
63
|
+
{
|
64
|
+
VALUE f;
|
65
|
+
OpenFile *fptr;
|
66
|
+
gdImagePtr iptr;
|
67
|
+
|
68
|
+
Check_Type(fname, T_STRING);
|
69
|
+
|
70
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
71
|
+
rb_io_binmode(f);
|
72
|
+
GetOpenFile(f, fptr);
|
73
|
+
rb_io_check_readable(fptr);
|
74
|
+
|
75
|
+
iptr = gdImageCreateFromPng(fptr->f);
|
76
|
+
if (!iptr)
|
77
|
+
rb_raise(rb_eArgError, "%s is not a valid PNG File", fptr->path);
|
78
|
+
|
79
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
80
|
+
}
|
81
|
+
|
82
|
+
|
83
|
+
static VALUE
|
84
|
+
img_from_png(klass, f)
|
85
|
+
VALUE klass, f;
|
86
|
+
{
|
87
|
+
OpenFile *fptr;
|
88
|
+
gdImagePtr iptr;
|
89
|
+
|
90
|
+
Check_Type(f, T_FILE);
|
91
|
+
rb_io_binmode(f);
|
92
|
+
GetOpenFile(f, fptr);
|
93
|
+
rb_io_check_readable(fptr);
|
94
|
+
|
95
|
+
iptr = gdImageCreateFromPng(fptr->f);
|
96
|
+
if (!iptr)
|
97
|
+
rb_raise(rb_eArgError, "%s is not a valid PNG File", fptr->path);
|
98
|
+
|
99
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
100
|
+
}
|
101
|
+
|
102
|
+
static VALUE
|
103
|
+
img_from_gdfname(klass, fname)
|
104
|
+
VALUE klass, fname;
|
105
|
+
{
|
106
|
+
VALUE f;
|
107
|
+
OpenFile *fptr;
|
108
|
+
gdImagePtr iptr;
|
109
|
+
|
110
|
+
Check_Type(fname, T_STRING);
|
111
|
+
|
112
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
113
|
+
rb_io_binmode(f);
|
114
|
+
GetOpenFile(f, fptr);
|
115
|
+
rb_io_check_readable(fptr);
|
116
|
+
|
117
|
+
iptr = gdImageCreateFromGd(fptr->f);
|
118
|
+
if (!iptr)
|
119
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd File", fptr->path);
|
120
|
+
|
121
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
122
|
+
}
|
123
|
+
|
124
|
+
static VALUE
|
125
|
+
img_from_gd(klass, f)
|
126
|
+
VALUE klass, f;
|
127
|
+
{
|
128
|
+
OpenFile *fptr;
|
129
|
+
gdImagePtr iptr;
|
130
|
+
|
131
|
+
Check_Type(f, T_FILE);
|
132
|
+
rb_io_binmode(f);
|
133
|
+
GetOpenFile(f, fptr);
|
134
|
+
rb_io_check_readable(fptr);
|
135
|
+
|
136
|
+
iptr = gdImageCreateFromGd(fptr->f);
|
137
|
+
if (!iptr)
|
138
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd File", fptr->path);
|
139
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
140
|
+
}
|
141
|
+
|
142
|
+
static VALUE
|
143
|
+
img_from_gd2fname(klass, fname)
|
144
|
+
VALUE klass, fname;
|
145
|
+
{
|
146
|
+
VALUE f;
|
147
|
+
OpenFile *fptr;
|
148
|
+
gdImagePtr iptr;
|
149
|
+
|
150
|
+
Check_Type(fname, T_STRING);
|
151
|
+
|
152
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
153
|
+
rb_io_binmode(f);
|
154
|
+
GetOpenFile(f, fptr);
|
155
|
+
rb_io_check_readable(fptr);
|
156
|
+
|
157
|
+
iptr = gdImageCreateFromGd2(fptr->f);
|
158
|
+
if (!iptr)
|
159
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path);
|
160
|
+
|
161
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
162
|
+
}
|
163
|
+
|
164
|
+
static VALUE
|
165
|
+
img_from_gd2(klass, f)
|
166
|
+
VALUE klass, f;
|
167
|
+
{
|
168
|
+
OpenFile *fptr;
|
169
|
+
gdImagePtr iptr;
|
170
|
+
|
171
|
+
Check_Type(f, T_FILE);
|
172
|
+
rb_io_binmode(f);
|
173
|
+
GetOpenFile(f, fptr);
|
174
|
+
rb_io_check_readable(fptr);
|
175
|
+
|
176
|
+
iptr = gdImageCreateFromGd2(fptr->f);
|
177
|
+
if (!iptr)
|
178
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path);
|
179
|
+
|
180
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
181
|
+
}
|
182
|
+
|
183
|
+
static VALUE
|
184
|
+
img_from_gd2_partfname(klass, fname, srcx, srcy, w, h)
|
185
|
+
VALUE klass, fname, srcx, srcy, w, h;
|
186
|
+
{
|
187
|
+
VALUE f;
|
188
|
+
OpenFile *fptr;
|
189
|
+
gdImagePtr iptr;
|
190
|
+
|
191
|
+
Check_Type(fname, T_STRING);
|
192
|
+
|
193
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
194
|
+
rb_io_binmode(f);
|
195
|
+
GetOpenFile(f, fptr);
|
196
|
+
rb_io_check_readable(fptr);
|
197
|
+
|
198
|
+
iptr = gdImageCreateFromGd2Part(fptr->f, NUM2INT(srcx),
|
199
|
+
NUM2INT(srcy), NUM2INT(w), NUM2INT(h));
|
200
|
+
if (!iptr)
|
201
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path);
|
202
|
+
|
203
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
204
|
+
}
|
205
|
+
|
206
|
+
static VALUE
|
207
|
+
img_from_gd2_part(klass, f, srcx, srcy, w, h)
|
208
|
+
VALUE klass, f, srcx, srcy, w, h;
|
209
|
+
{
|
210
|
+
OpenFile *fptr;
|
211
|
+
gdImagePtr iptr;
|
212
|
+
|
213
|
+
Check_Type(f, T_FILE);
|
214
|
+
rb_io_binmode(f);
|
215
|
+
GetOpenFile(f, fptr);
|
216
|
+
rb_io_check_readable(fptr);
|
217
|
+
|
218
|
+
iptr = gdImageCreateFromGd2Part(fptr->f, NUM2INT(srcx),
|
219
|
+
NUM2INT(srcy), NUM2INT(w), NUM2INT(h));
|
220
|
+
if (!iptr)
|
221
|
+
rb_raise(rb_eArgError, "%s is not a valid Gd2 File", fptr->path);
|
222
|
+
|
223
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
static VALUE
|
228
|
+
img_from_xbm(klass, f)
|
229
|
+
VALUE klass, f;
|
230
|
+
{
|
231
|
+
OpenFile *fptr;
|
232
|
+
gdImagePtr iptr;
|
233
|
+
|
234
|
+
Check_Type(f, T_FILE);
|
235
|
+
rb_io_binmode(f);
|
236
|
+
GetOpenFile(f, fptr);
|
237
|
+
rb_io_check_readable(fptr);
|
238
|
+
|
239
|
+
iptr = gdImageCreateFromXbm(fptr->f);
|
240
|
+
if (!iptr)
|
241
|
+
rb_raise(rb_eArgError, "%s is not a valid Xbm File", fptr->path);
|
242
|
+
|
243
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
244
|
+
}
|
245
|
+
|
246
|
+
static VALUE
|
247
|
+
img_from_xbmfname(klass, fname)
|
248
|
+
VALUE klass, fname;
|
249
|
+
{
|
250
|
+
VALUE f;
|
251
|
+
OpenFile *fptr;
|
252
|
+
gdImagePtr iptr;
|
253
|
+
|
254
|
+
Check_Type(fname, T_STRING);
|
255
|
+
|
256
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
257
|
+
rb_io_binmode(f);
|
258
|
+
GetOpenFile(f, fptr);
|
259
|
+
rb_io_check_readable(fptr);
|
260
|
+
|
261
|
+
iptr = gdImageCreateFromXbm(fptr->f);
|
262
|
+
if (!iptr)
|
263
|
+
rb_raise(rb_eArgError, "%s is not a valid Xbm File", fptr->path);
|
264
|
+
|
265
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
266
|
+
}
|
267
|
+
|
268
|
+
#ifdef HAVE_GDIMAGECREATEFROMXPM
|
269
|
+
static VALUE
|
270
|
+
img_from_xpm(klass, f)
|
271
|
+
VALUE klass, f;
|
272
|
+
{
|
273
|
+
OpenFile *fptr;
|
274
|
+
gdImagePtr iptr;
|
275
|
+
|
276
|
+
Check_Type(f, T_FILE);
|
277
|
+
rb_io_binmode(f);
|
278
|
+
GetOpenFile(f, fptr);
|
279
|
+
rb_io_check_readable(fptr);
|
280
|
+
|
281
|
+
/* need cast, and the argument is char* type */
|
282
|
+
iptr = (gdImagePtr)gdImageCreateFromXpm(fptr->path);
|
283
|
+
if (!iptr)
|
284
|
+
rb_raise(rb_eArgError, "%s is not a valid XPM File", fptr->path);
|
285
|
+
|
286
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
287
|
+
}
|
288
|
+
|
289
|
+
static VALUE
|
290
|
+
img_from_xpmfname(klass, fname)
|
291
|
+
VALUE klass, fname;
|
292
|
+
{
|
293
|
+
VALUE f;
|
294
|
+
OpenFile *fptr;
|
295
|
+
gdImagePtr iptr;
|
296
|
+
|
297
|
+
Check_Type(fname, T_STRING);
|
298
|
+
|
299
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
300
|
+
rb_io_binmode(f);
|
301
|
+
GetOpenFile(f, fptr);
|
302
|
+
rb_io_check_readable(fptr);
|
303
|
+
|
304
|
+
/* need cast, and the argument is char* type */
|
305
|
+
iptr = (gdImagePtr)gdImageCreateFromXpm(fptr->path);
|
306
|
+
if (!iptr)
|
307
|
+
rb_raise(rb_eArgError, "%s is not a valid XPM File", fptr->path);
|
308
|
+
|
309
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
310
|
+
}
|
311
|
+
|
312
|
+
#endif
|
313
|
+
|
314
|
+
#ifdef HAVE_GDIMAGECREATEFROMJPEG
|
315
|
+
static VALUE
|
316
|
+
img_from_jpeg(klass, f)
|
317
|
+
VALUE klass, f;
|
318
|
+
{
|
319
|
+
OpenFile *fptr;
|
320
|
+
gdImagePtr iptr;
|
321
|
+
|
322
|
+
Check_Type(f, T_FILE);
|
323
|
+
rb_io_binmode(f);
|
324
|
+
GetOpenFile(f, fptr);
|
325
|
+
rb_io_check_readable(fptr);
|
326
|
+
|
327
|
+
iptr = gdImageCreateFromJpeg(fptr->f);
|
328
|
+
if (!iptr)
|
329
|
+
rb_raise(rb_eArgError, "%s is not a valid Jpeg File", fptr->path);
|
330
|
+
|
331
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
332
|
+
}
|
333
|
+
|
334
|
+
static VALUE
|
335
|
+
img_from_jpegfname(klass, fname)
|
336
|
+
VALUE klass, fname;
|
337
|
+
{
|
338
|
+
VALUE f;
|
339
|
+
OpenFile *fptr;
|
340
|
+
gdImagePtr iptr;
|
341
|
+
|
342
|
+
Check_Type(fname, T_STRING);
|
343
|
+
|
344
|
+
f = rb_file_open(STR2CSTR(fname), "r");
|
345
|
+
rb_io_binmode(f);
|
346
|
+
GetOpenFile(f, fptr);
|
347
|
+
rb_io_check_readable(fptr);
|
348
|
+
|
349
|
+
iptr = gdImageCreateFromJpeg(fptr->f);
|
350
|
+
if (!iptr)
|
351
|
+
rb_raise(rb_eArgError, "%s is not a valid Jpeg File", fptr->path);
|
352
|
+
|
353
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
354
|
+
}
|
355
|
+
#endif
|
356
|
+
|
357
|
+
|
358
|
+
static VALUE
|
359
|
+
img_destroy(img)
|
360
|
+
struct RData *img;
|
361
|
+
{
|
362
|
+
if (img->data) {
|
363
|
+
gdImageDestroy((gdImagePtr)img->data);
|
364
|
+
img->data = 0;
|
365
|
+
}
|
366
|
+
return Qnil;
|
367
|
+
}
|
368
|
+
|
369
|
+
static VALUE
|
370
|
+
hex2triplet(hex)
|
371
|
+
VALUE hex;
|
372
|
+
{
|
373
|
+
VALUE rstr, gstr, bstr;
|
374
|
+
VALUE ret_ary;
|
375
|
+
|
376
|
+
Check_Type(hex, T_STRING);
|
377
|
+
|
378
|
+
if (RSTRING(hex)->len != 7)
|
379
|
+
rb_raise(rb_eArgError, "Invalid format: %s", RSTRING(hex)->ptr);
|
380
|
+
|
381
|
+
rstr = rb_str_new(RSTRING(hex)->ptr + 1, 2);
|
382
|
+
gstr = rb_str_new(RSTRING(hex)->ptr + 3, 2);
|
383
|
+
bstr = rb_str_new(RSTRING(hex)->ptr + 5, 2);
|
384
|
+
|
385
|
+
ret_ary = rb_ary_new();
|
386
|
+
|
387
|
+
rb_ary_push(ret_ary, rb_funcall(rstr, rb_intern("hex"), 0));
|
388
|
+
rb_ary_push(ret_ary, rb_funcall(gstr, rb_intern("hex"), 0));
|
389
|
+
rb_ary_push(ret_ary, rb_funcall(bstr, rb_intern("hex"), 0));
|
390
|
+
|
391
|
+
return ret_ary;
|
392
|
+
}
|
393
|
+
|
394
|
+
static VALUE
|
395
|
+
img_color_allocate_tri(img, r, g, b)
|
396
|
+
VALUE img, r, g, b;
|
397
|
+
{
|
398
|
+
gdImagePtr im;
|
399
|
+
int c;
|
400
|
+
|
401
|
+
Data_Get_Struct(img, gdImage, im);
|
402
|
+
c = gdImageColorAllocate(im, NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
403
|
+
|
404
|
+
return INT2FIX(c);
|
405
|
+
}
|
406
|
+
|
407
|
+
static VALUE
|
408
|
+
img_color_allocate_str(img, rgbstr)
|
409
|
+
VALUE img, rgbstr;
|
410
|
+
{
|
411
|
+
gdImagePtr im;
|
412
|
+
int c;
|
413
|
+
VALUE ary;
|
414
|
+
|
415
|
+
Data_Get_Struct(img, gdImage, im);
|
416
|
+
|
417
|
+
ary = hex2triplet(rgbstr);
|
418
|
+
c = gdImageColorAllocate(im,
|
419
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
420
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
421
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
422
|
+
return INT2FIX(c);
|
423
|
+
}
|
424
|
+
|
425
|
+
static VALUE
|
426
|
+
img_color_allocate(argc, argv, img)
|
427
|
+
int argc;
|
428
|
+
VALUE *argv;
|
429
|
+
VALUE img;
|
430
|
+
{
|
431
|
+
int i;
|
432
|
+
VALUE rgbstr, r, g, b, retval;
|
433
|
+
|
434
|
+
if (!(argc == 1 || argc == 3))
|
435
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
436
|
+
|
437
|
+
switch(TYPE(argv[0])) {
|
438
|
+
case T_STRING:
|
439
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
440
|
+
retval = img_color_allocate_str(img, rgbstr);
|
441
|
+
break;
|
442
|
+
case T_FIXNUM:
|
443
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
444
|
+
retval = img_color_allocate_tri(img, r, g, b);
|
445
|
+
break;
|
446
|
+
default:
|
447
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
448
|
+
break;
|
449
|
+
}
|
450
|
+
|
451
|
+
return retval;
|
452
|
+
}
|
453
|
+
|
454
|
+
static VALUE
|
455
|
+
img_color_deallocate(img, color)
|
456
|
+
VALUE img, color;
|
457
|
+
{
|
458
|
+
gdImagePtr im;
|
459
|
+
|
460
|
+
Data_Get_Struct(img, gdImage, im);
|
461
|
+
gdImageColorDeallocate(im, NUM2INT(color));
|
462
|
+
|
463
|
+
return img;
|
464
|
+
}
|
465
|
+
|
466
|
+
#ifdef HAVE_GDIMAGECOLORRESOLVE
|
467
|
+
static VALUE
|
468
|
+
img_color_resolve_tri(img, r, g, b)
|
469
|
+
VALUE img, r, g, b;
|
470
|
+
{
|
471
|
+
gdImagePtr im;
|
472
|
+
int c;
|
473
|
+
|
474
|
+
Data_Get_Struct(img, gdImage, im);
|
475
|
+
c = gdImageColorResolve(im, NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
476
|
+
|
477
|
+
return INT2FIX(c);
|
478
|
+
}
|
479
|
+
|
480
|
+
static VALUE
|
481
|
+
img_color_resolve_str(img, rgbstr)
|
482
|
+
VALUE img, rgbstr;
|
483
|
+
{
|
484
|
+
gdImagePtr im;
|
485
|
+
int c;
|
486
|
+
VALUE ary;
|
487
|
+
|
488
|
+
Data_Get_Struct(img, gdImage, im);
|
489
|
+
|
490
|
+
ary = hex2triplet(rgbstr);
|
491
|
+
c = gdImageColorResolve(im,
|
492
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
493
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
494
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
495
|
+
|
496
|
+
return INT2FIX(c);
|
497
|
+
}
|
498
|
+
|
499
|
+
static VALUE
|
500
|
+
img_color_resolve(argc, argv, img)
|
501
|
+
int argc;
|
502
|
+
VALUE *argv;
|
503
|
+
VALUE img;
|
504
|
+
{
|
505
|
+
int i;
|
506
|
+
VALUE rgbstr, r, g, b, retval;
|
507
|
+
|
508
|
+
if (!(argc == 1 || argc == 3))
|
509
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
510
|
+
|
511
|
+
switch(TYPE(argv[0])) {
|
512
|
+
case T_STRING:
|
513
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
514
|
+
retval = img_color_resolve_str(img, rgbstr);
|
515
|
+
break;
|
516
|
+
case T_FIXNUM:
|
517
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
518
|
+
retval = img_color_resolve_tri(img, r, g, b);
|
519
|
+
break;
|
520
|
+
default:
|
521
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
522
|
+
break;
|
523
|
+
}
|
524
|
+
|
525
|
+
return retval;
|
526
|
+
}
|
527
|
+
|
528
|
+
#endif /* HAVE_GDIMAGECOLORRESOLVE */
|
529
|
+
|
530
|
+
static VALUE
|
531
|
+
img_color_closest_tri(img, r, g, b)
|
532
|
+
VALUE img, r, g, b;
|
533
|
+
{
|
534
|
+
gdImagePtr im;
|
535
|
+
int c;
|
536
|
+
|
537
|
+
Data_Get_Struct(img, gdImage, im);
|
538
|
+
c = gdImageColorClosest(im, NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
539
|
+
|
540
|
+
return INT2FIX(c);
|
541
|
+
}
|
542
|
+
|
543
|
+
static VALUE
|
544
|
+
img_color_closest_str(img, rgbstr)
|
545
|
+
VALUE img, rgbstr;
|
546
|
+
{
|
547
|
+
gdImagePtr im;
|
548
|
+
int c;
|
549
|
+
VALUE ary;
|
550
|
+
|
551
|
+
Data_Get_Struct(img, gdImage, im);
|
552
|
+
|
553
|
+
ary = hex2triplet(rgbstr);
|
554
|
+
c = gdImageColorClosest(im,
|
555
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
556
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
557
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
558
|
+
return INT2FIX(c);
|
559
|
+
}
|
560
|
+
|
561
|
+
static VALUE
|
562
|
+
img_color_closest(argc, argv, img)
|
563
|
+
int argc;
|
564
|
+
VALUE *argv;
|
565
|
+
VALUE img;
|
566
|
+
{
|
567
|
+
int i;
|
568
|
+
VALUE rgbstr, r, g, b, retval;
|
569
|
+
|
570
|
+
if (!(argc == 1 || argc == 3))
|
571
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
572
|
+
|
573
|
+
switch(TYPE(argv[0])) {
|
574
|
+
case T_STRING:
|
575
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
576
|
+
retval = img_color_closest_str(img, rgbstr);
|
577
|
+
break;
|
578
|
+
case T_FIXNUM:
|
579
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
580
|
+
retval = img_color_closest_tri(img, r, g, b);
|
581
|
+
break;
|
582
|
+
default:
|
583
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
584
|
+
break;
|
585
|
+
}
|
586
|
+
|
587
|
+
return retval;
|
588
|
+
}
|
589
|
+
|
590
|
+
extern int gdImageColorClosestHWB(gdImagePtr, int, int, int);
|
591
|
+
|
592
|
+
static VALUE
|
593
|
+
img_color_closestHWB_tri(img, r, g, b)
|
594
|
+
VALUE img, r, g, b;
|
595
|
+
{
|
596
|
+
gdImagePtr im;
|
597
|
+
int c;
|
598
|
+
|
599
|
+
Data_Get_Struct(img, gdImage, im);
|
600
|
+
c = gdImageColorClosestHWB(im, NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
601
|
+
|
602
|
+
return INT2FIX(c);
|
603
|
+
}
|
604
|
+
|
605
|
+
static VALUE
|
606
|
+
img_color_closestHWB_str(img, rgbstr)
|
607
|
+
VALUE img, rgbstr;
|
608
|
+
{
|
609
|
+
gdImagePtr im;
|
610
|
+
int c;
|
611
|
+
VALUE ary;
|
612
|
+
|
613
|
+
Data_Get_Struct(img, gdImage, im);
|
614
|
+
|
615
|
+
ary = hex2triplet(rgbstr);
|
616
|
+
c = gdImageColorClosestHWB(im,
|
617
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
618
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
619
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
620
|
+
return INT2FIX(c);
|
621
|
+
}
|
622
|
+
|
623
|
+
static VALUE
|
624
|
+
img_color_closestHWB(argc, argv, img)
|
625
|
+
int argc;
|
626
|
+
VALUE *argv;
|
627
|
+
VALUE img;
|
628
|
+
{
|
629
|
+
int i;
|
630
|
+
VALUE rgbstr, r, g, b, retval;
|
631
|
+
|
632
|
+
if (!(argc == 1 || argc == 3))
|
633
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
634
|
+
|
635
|
+
switch(TYPE(argv[0])) {
|
636
|
+
case T_STRING:
|
637
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
638
|
+
retval = img_color_closestHWB_str(img, rgbstr);
|
639
|
+
break;
|
640
|
+
case T_FIXNUM:
|
641
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
642
|
+
retval = img_color_closestHWB_tri(img, r, g, b);
|
643
|
+
break;
|
644
|
+
default:
|
645
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
646
|
+
break;
|
647
|
+
}
|
648
|
+
|
649
|
+
return retval;
|
650
|
+
}
|
651
|
+
|
652
|
+
static VALUE
|
653
|
+
img_color_exact_tri(img, r, g, b)
|
654
|
+
VALUE img, r, g, b;
|
655
|
+
{
|
656
|
+
gdImagePtr im;
|
657
|
+
int c;
|
658
|
+
|
659
|
+
Data_Get_Struct(img, gdImage, im);
|
660
|
+
c = gdImageColorExact(im, NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
661
|
+
|
662
|
+
return INT2FIX(c);
|
663
|
+
}
|
664
|
+
|
665
|
+
static VALUE
|
666
|
+
img_color_exact_str(img, rgbstr)
|
667
|
+
VALUE img, rgbstr;
|
668
|
+
{
|
669
|
+
gdImagePtr im;
|
670
|
+
int c;
|
671
|
+
VALUE ary;
|
672
|
+
|
673
|
+
Data_Get_Struct(img, gdImage, im);
|
674
|
+
|
675
|
+
ary = hex2triplet(rgbstr);
|
676
|
+
c = gdImageColorExact(im,
|
677
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
678
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
679
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
680
|
+
return INT2FIX(c);
|
681
|
+
}
|
682
|
+
|
683
|
+
static VALUE
|
684
|
+
img_color_exact(argc, argv, img)
|
685
|
+
int argc;
|
686
|
+
VALUE *argv;
|
687
|
+
VALUE img;
|
688
|
+
{
|
689
|
+
int i;
|
690
|
+
VALUE rgbstr, r, g, b, retval;
|
691
|
+
|
692
|
+
if (!(argc == 1 || argc == 3))
|
693
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
694
|
+
|
695
|
+
switch(TYPE(argv[0])) {
|
696
|
+
case T_STRING:
|
697
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
698
|
+
retval = img_color_exact_str(img, rgbstr);
|
699
|
+
break;
|
700
|
+
case T_FIXNUM:
|
701
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
702
|
+
retval = img_color_exact_tri(img, r, g, b);
|
703
|
+
break;
|
704
|
+
default:
|
705
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
706
|
+
break;
|
707
|
+
}
|
708
|
+
|
709
|
+
return retval;
|
710
|
+
}
|
711
|
+
|
712
|
+
static VALUE
|
713
|
+
img_colors_total(img)
|
714
|
+
VALUE img;
|
715
|
+
{
|
716
|
+
gdImagePtr im;
|
717
|
+
int c;
|
718
|
+
|
719
|
+
Data_Get_Struct(img, gdImage, im);
|
720
|
+
c = gdImageColorsTotal(im);
|
721
|
+
|
722
|
+
return INT2FIX(c);
|
723
|
+
}
|
724
|
+
|
725
|
+
static VALUE
|
726
|
+
img_get_pixel(img, x, y)
|
727
|
+
VALUE img, x, y;
|
728
|
+
{
|
729
|
+
gdImagePtr im;
|
730
|
+
int c;
|
731
|
+
|
732
|
+
Data_Get_Struct(img, gdImage, im);
|
733
|
+
c = gdImageGetPixel(im, NUM2INT(x), NUM2INT(y));
|
734
|
+
|
735
|
+
return INT2FIX(c);
|
736
|
+
}
|
737
|
+
|
738
|
+
static VALUE
|
739
|
+
img_set_pixel(img, x, y, color)
|
740
|
+
VALUE img, x, y, color;
|
741
|
+
{
|
742
|
+
gdImagePtr im;
|
743
|
+
|
744
|
+
Data_Get_Struct(img, gdImage, im);
|
745
|
+
gdImageSetPixel(im, NUM2INT(x), NUM2INT(y), NUM2INT(color));
|
746
|
+
|
747
|
+
return img;
|
748
|
+
}
|
749
|
+
|
750
|
+
static VALUE
|
751
|
+
img_red(img, idx)
|
752
|
+
VALUE img, idx;
|
753
|
+
{
|
754
|
+
gdImagePtr im;
|
755
|
+
int i,c;
|
756
|
+
|
757
|
+
Data_Get_Struct(img, gdImage, im);
|
758
|
+
i = NUM2INT(idx);
|
759
|
+
|
760
|
+
c = gdImageRed(im, i);
|
761
|
+
|
762
|
+
return INT2FIX(c);
|
763
|
+
}
|
764
|
+
|
765
|
+
static VALUE
|
766
|
+
img_green(img, idx)
|
767
|
+
VALUE img, idx;
|
768
|
+
{
|
769
|
+
gdImagePtr im;
|
770
|
+
int i,c;
|
771
|
+
|
772
|
+
Data_Get_Struct(img, gdImage, im);
|
773
|
+
i = NUM2INT(idx);
|
774
|
+
|
775
|
+
c = gdImageGreen(im, i);
|
776
|
+
|
777
|
+
return INT2FIX(c);
|
778
|
+
}
|
779
|
+
|
780
|
+
static VALUE
|
781
|
+
img_blue(img, idx)
|
782
|
+
VALUE img, idx;
|
783
|
+
{
|
784
|
+
gdImagePtr im;
|
785
|
+
int i,c;
|
786
|
+
|
787
|
+
Data_Get_Struct(img, gdImage, im);
|
788
|
+
i = NUM2INT(idx);
|
789
|
+
|
790
|
+
c = gdImageBlue(im, i);
|
791
|
+
|
792
|
+
return INT2FIX(c);
|
793
|
+
}
|
794
|
+
|
795
|
+
static VALUE
|
796
|
+
img_rgb(img, idx)
|
797
|
+
VALUE img, idx;
|
798
|
+
{
|
799
|
+
gdImagePtr im;
|
800
|
+
VALUE ary = rb_ary_new2(3);
|
801
|
+
int i, c;
|
802
|
+
|
803
|
+
Data_Get_Struct(img, gdImage, im);
|
804
|
+
i = NUM2INT(idx);
|
805
|
+
|
806
|
+
c = gdImageRed(im, i);
|
807
|
+
rb_ary_push(ary, INT2FIX(c));
|
808
|
+
c = gdImageGreen(im, i);
|
809
|
+
rb_ary_push(ary, INT2FIX(c));
|
810
|
+
c = gdImageBlue(im, i);
|
811
|
+
rb_ary_push(ary, INT2FIX(c));
|
812
|
+
|
813
|
+
return ary;
|
814
|
+
}
|
815
|
+
|
816
|
+
static VALUE
|
817
|
+
img_transparent(img, idx)
|
818
|
+
VALUE img, idx;
|
819
|
+
{
|
820
|
+
gdImagePtr im;
|
821
|
+
|
822
|
+
Data_Get_Struct(img, gdImage, im);
|
823
|
+
|
824
|
+
gdImageColorTransparent(im, NUM2INT(idx));
|
825
|
+
|
826
|
+
return img;
|
827
|
+
}
|
828
|
+
|
829
|
+
static void
|
830
|
+
image_req(img)
|
831
|
+
VALUE img;
|
832
|
+
{
|
833
|
+
if (!rb_obj_is_kind_of(img, cImage)) {
|
834
|
+
rb_raise(rb_eTypeError, "GD::Image required");
|
835
|
+
}
|
836
|
+
}
|
837
|
+
|
838
|
+
static VALUE
|
839
|
+
img_set_blush(img, brush)
|
840
|
+
VALUE img, brush;
|
841
|
+
{
|
842
|
+
gdImagePtr im, br;
|
843
|
+
|
844
|
+
Data_Get_Struct(img, gdImage, im);
|
845
|
+
image_req(brush);
|
846
|
+
Data_Get_Struct(brush, gdImage, br);
|
847
|
+
gdImageSetBrush(im, br);
|
848
|
+
|
849
|
+
return img;
|
850
|
+
}
|
851
|
+
|
852
|
+
static VALUE
|
853
|
+
img_set_style(argc, argv, img)
|
854
|
+
int argc;
|
855
|
+
VALUE *argv;
|
856
|
+
VALUE img;
|
857
|
+
{
|
858
|
+
gdImagePtr im;
|
859
|
+
int *style;
|
860
|
+
int i;
|
861
|
+
|
862
|
+
Data_Get_Struct(img, gdImage, im);
|
863
|
+
style = ALLOCA_N(int, argc);
|
864
|
+
for (i=0; i<argc; i++) {
|
865
|
+
style[i] = NUM2INT(argv[i]);
|
866
|
+
}
|
867
|
+
|
868
|
+
gdImageSetStyle(im, style, argc);
|
869
|
+
|
870
|
+
return img;
|
871
|
+
}
|
872
|
+
|
873
|
+
static VALUE
|
874
|
+
img_set_tile(img, tile)
|
875
|
+
VALUE img, tile;
|
876
|
+
{
|
877
|
+
gdImagePtr im, ti;
|
878
|
+
|
879
|
+
Data_Get_Struct(img, gdImage, im);
|
880
|
+
image_req(tile);
|
881
|
+
Data_Get_Struct(tile, gdImage, ti);
|
882
|
+
gdImageSetTile(im, ti);
|
883
|
+
|
884
|
+
return img;
|
885
|
+
}
|
886
|
+
|
887
|
+
static VALUE
|
888
|
+
img_line(img, x1, y1, x2, y2, c)
|
889
|
+
VALUE img, x1, y1, x2, y2, c;
|
890
|
+
{
|
891
|
+
gdImagePtr im;
|
892
|
+
|
893
|
+
Data_Get_Struct(img, gdImage, im);
|
894
|
+
gdImageLine(im,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),NUM2INT(c));
|
895
|
+
|
896
|
+
return img;
|
897
|
+
}
|
898
|
+
|
899
|
+
static VALUE
|
900
|
+
img_dashed_line(img, x1, y1, x2, y2, c)
|
901
|
+
VALUE img, x1, y1, x2, y2, c;
|
902
|
+
{
|
903
|
+
gdImagePtr im;
|
904
|
+
|
905
|
+
Data_Get_Struct(img, gdImage, im);
|
906
|
+
gdImageDashedLine(im,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),NUM2INT(c));
|
907
|
+
|
908
|
+
return img;
|
909
|
+
}
|
910
|
+
|
911
|
+
|
912
|
+
static VALUE
|
913
|
+
img_rectangle(img, x1, y1, x2, y2, c)
|
914
|
+
VALUE img, x1, y1, x2, y2, c;
|
915
|
+
{
|
916
|
+
gdImagePtr im;
|
917
|
+
|
918
|
+
Data_Get_Struct(img, gdImage, im);
|
919
|
+
gdImageRectangle(im,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),NUM2INT(c));
|
920
|
+
|
921
|
+
return img;
|
922
|
+
}
|
923
|
+
|
924
|
+
|
925
|
+
static VALUE
|
926
|
+
img_filled_rectangle(img, x1, y1, x2, y2, c)
|
927
|
+
VALUE img, x1, y1, x2, y2, c;
|
928
|
+
{
|
929
|
+
gdImagePtr im;
|
930
|
+
|
931
|
+
Data_Get_Struct(img, gdImage, im);
|
932
|
+
gdImageFilledRectangle(im,NUM2INT(x1),NUM2INT(y1),NUM2INT(x2),NUM2INT(y2),NUM2INT(c));
|
933
|
+
|
934
|
+
return img;
|
935
|
+
}
|
936
|
+
|
937
|
+
static void
|
938
|
+
poly_req(ply)
|
939
|
+
VALUE ply;
|
940
|
+
{
|
941
|
+
if (!rb_obj_is_kind_of(ply, cPolygon) || TYPE(ply) != T_ARRAY) {
|
942
|
+
rb_raise(rb_eTypeError, "GD::Polygon required");
|
943
|
+
}
|
944
|
+
}
|
945
|
+
|
946
|
+
static VALUE
|
947
|
+
img_polygon(img, ply, c)
|
948
|
+
VALUE img;
|
949
|
+
struct RArray *ply;
|
950
|
+
VALUE c;
|
951
|
+
{
|
952
|
+
gdImagePtr im;
|
953
|
+
gdPointPtr pnt;
|
954
|
+
int i, len;
|
955
|
+
|
956
|
+
Data_Get_Struct(img, gdImage, im);
|
957
|
+
|
958
|
+
poly_req(ply);
|
959
|
+
len = ply->len/2;
|
960
|
+
pnt = ALLOCA_N(gdPoint, len);
|
961
|
+
for (i=0; i<len; i++) {
|
962
|
+
pnt[i].x = NUM2INT(ply->ptr[i*2]);
|
963
|
+
pnt[i].y = NUM2INT(ply->ptr[i*2+1]);
|
964
|
+
}
|
965
|
+
|
966
|
+
gdImagePolygon(im, pnt, len, NUM2INT(c));
|
967
|
+
|
968
|
+
return img;
|
969
|
+
}
|
970
|
+
|
971
|
+
static VALUE
|
972
|
+
img_filled_polygon(img, ply, c)
|
973
|
+
VALUE img;
|
974
|
+
struct RArray *ply;
|
975
|
+
VALUE c;
|
976
|
+
{
|
977
|
+
gdImagePtr im;
|
978
|
+
gdPointPtr pnt;
|
979
|
+
int i, len;
|
980
|
+
|
981
|
+
Data_Get_Struct(img, gdImage, im);
|
982
|
+
|
983
|
+
poly_req(ply);
|
984
|
+
len = ply->len/2;
|
985
|
+
pnt = ALLOCA_N(gdPoint, len);
|
986
|
+
for (i=0; i<len; i++) {
|
987
|
+
pnt[i].x = NUM2INT(ply->ptr[i*2]);
|
988
|
+
pnt[i].y = NUM2INT(ply->ptr[i*2+1]);
|
989
|
+
}
|
990
|
+
|
991
|
+
gdImageFilledPolygon(im, pnt, len, NUM2INT(c));
|
992
|
+
|
993
|
+
return img;
|
994
|
+
}
|
995
|
+
|
996
|
+
static VALUE
|
997
|
+
img_arc(img, cx, cy, w, h, s, e, c)
|
998
|
+
VALUE img, cx, cy, w, h, s, e, c;
|
999
|
+
{
|
1000
|
+
gdImagePtr im;
|
1001
|
+
|
1002
|
+
Data_Get_Struct(img, gdImage, im);
|
1003
|
+
gdImageArc(im,NUM2INT(cx),NUM2INT(cy),NUM2INT(w),NUM2INT(h),NUM2INT(s),NUM2INT(e),NUM2INT(c));
|
1004
|
+
|
1005
|
+
return img;
|
1006
|
+
}
|
1007
|
+
|
1008
|
+
static VALUE
|
1009
|
+
img_fill(img, x, y, c)
|
1010
|
+
VALUE img, x, y, c;
|
1011
|
+
{
|
1012
|
+
gdImagePtr im;
|
1013
|
+
|
1014
|
+
Data_Get_Struct(img, gdImage, im);
|
1015
|
+
gdImageFill(im,NUM2INT(x),NUM2INT(y),NUM2INT(c));
|
1016
|
+
|
1017
|
+
return img;
|
1018
|
+
}
|
1019
|
+
|
1020
|
+
static VALUE
|
1021
|
+
img_fill_to_border(img, x, y, b, c)
|
1022
|
+
VALUE img, x, y, b, c;
|
1023
|
+
{
|
1024
|
+
gdImagePtr im;
|
1025
|
+
|
1026
|
+
Data_Get_Struct(img, gdImage, im);
|
1027
|
+
gdImageFillToBorder(im,NUM2INT(x),NUM2INT(y),NUM2INT(b),NUM2INT(c));
|
1028
|
+
|
1029
|
+
return img;
|
1030
|
+
}
|
1031
|
+
|
1032
|
+
static VALUE
|
1033
|
+
img_copy(img, img2, dx, dy, sx, sy, w, h)
|
1034
|
+
VALUE img, img2, dx, dy, sx, sy, w, h;
|
1035
|
+
{
|
1036
|
+
gdImagePtr im, im2;
|
1037
|
+
|
1038
|
+
Data_Get_Struct(img, gdImage, im);
|
1039
|
+
image_req(img2);
|
1040
|
+
Data_Get_Struct(img2, gdImage, im2);
|
1041
|
+
|
1042
|
+
#ifdef ENABLE_GD_2_0
|
1043
|
+
if (is_truecolor(im) && (!is_truecolor(im2))){
|
1044
|
+
rb_raise(rb_eRuntimeError,
|
1045
|
+
"Copying truecolor image to palette image is not permitted");
|
1046
|
+
}
|
1047
|
+
#endif
|
1048
|
+
|
1049
|
+
gdImageCopy(im2, im,
|
1050
|
+
NUM2INT(dx), NUM2INT(dy),
|
1051
|
+
NUM2INT(sx), NUM2INT(sy),
|
1052
|
+
NUM2INT(w),NUM2INT(h));
|
1053
|
+
|
1054
|
+
return img;
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
static VALUE
|
1058
|
+
img_copy_resized(img, img2, dx, dy, sx, sy, dw, dh, sw, sh)
|
1059
|
+
VALUE img, img2, dx, dy, sx, sy, dw, dh, sw, sh;
|
1060
|
+
{
|
1061
|
+
gdImagePtr im, im2;
|
1062
|
+
|
1063
|
+
Data_Get_Struct(img, gdImage, im);
|
1064
|
+
image_req(img2);
|
1065
|
+
Data_Get_Struct(img2, gdImage, im2);
|
1066
|
+
|
1067
|
+
#ifdef ENABLE_GD_2_0
|
1068
|
+
if (is_truecolor(im) && (!is_truecolor(im2))){
|
1069
|
+
rb_raise(rb_eRuntimeError,
|
1070
|
+
"Copying truecolor image to palette image is not permitted");
|
1071
|
+
}
|
1072
|
+
#endif
|
1073
|
+
|
1074
|
+
gdImageCopyResized(im2,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(dw),NUM2INT(dh),NUM2INT(sw),NUM2INT(sh));
|
1075
|
+
|
1076
|
+
return img;
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
static VALUE
|
1080
|
+
img_copy_merge(img, img_dest, dx, dy, sx, sy, w, h, pct)
|
1081
|
+
VALUE img, img_dest, dx, dy, sx, sy, w, h, pct;
|
1082
|
+
{
|
1083
|
+
gdImagePtr im, im_dest;
|
1084
|
+
|
1085
|
+
Data_Get_Struct(img, gdImage, im);
|
1086
|
+
image_req(img_dest);
|
1087
|
+
Data_Get_Struct(img_dest, gdImage, im_dest);
|
1088
|
+
|
1089
|
+
#ifdef ENABLE_GD_2_0
|
1090
|
+
if (is_truecolor(im) && (!is_truecolor(im_dest))){
|
1091
|
+
rb_raise(rb_eRuntimeError,
|
1092
|
+
"Copying truecolor image to palette image is not permitted");
|
1093
|
+
}
|
1094
|
+
#endif
|
1095
|
+
|
1096
|
+
gdImageCopyMerge(im_dest,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(w),NUM2INT(h), NUM2INT(pct));
|
1097
|
+
|
1098
|
+
return img;
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
static VALUE
|
1102
|
+
img_copy_merge_gray(img, img_dest, dx, dy, sx, sy, w, h, pct)
|
1103
|
+
VALUE img, img_dest, dx, dy, sx, sy, w, h, pct;
|
1104
|
+
{
|
1105
|
+
gdImagePtr im, im_dest;
|
1106
|
+
|
1107
|
+
Data_Get_Struct(img, gdImage, im);
|
1108
|
+
image_req(img_dest);
|
1109
|
+
Data_Get_Struct(img_dest, gdImage, im_dest);
|
1110
|
+
|
1111
|
+
#ifdef ENABLE_GD_2_0
|
1112
|
+
if (is_truecolor(im) && (!is_truecolor(im_dest))){
|
1113
|
+
rb_raise(rb_eRuntimeError,
|
1114
|
+
"Copying truecolor image to palette image is not permitted");
|
1115
|
+
}
|
1116
|
+
#endif
|
1117
|
+
|
1118
|
+
gdImageCopyMergeGray(im_dest,im,NUM2INT(dx),NUM2INT(dy),NUM2INT(sx),NUM2INT(sy),NUM2INT(w),NUM2INT(h), NUM2INT(pct));
|
1119
|
+
|
1120
|
+
return img;
|
1121
|
+
}
|
1122
|
+
|
1123
|
+
static VALUE
|
1124
|
+
img_palette_copy(img, img2)
|
1125
|
+
VALUE img, img2;
|
1126
|
+
{
|
1127
|
+
gdImagePtr im, im2;
|
1128
|
+
|
1129
|
+
image_req(img2);
|
1130
|
+
Data_Get_Struct(img, gdImage, im);
|
1131
|
+
Data_Get_Struct(img2, gdImage, im2);
|
1132
|
+
|
1133
|
+
gdImagePaletteCopy(im, im2);
|
1134
|
+
|
1135
|
+
return img;
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
static void
|
1139
|
+
font_req(fnt)
|
1140
|
+
VALUE fnt;
|
1141
|
+
{
|
1142
|
+
if (!rb_obj_is_kind_of(fnt, cFont)) {
|
1143
|
+
rb_raise(rb_eTypeError, "GD::Font required");
|
1144
|
+
}
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
static VALUE
|
1148
|
+
img_string(img, fnt, x, y, str, c)
|
1149
|
+
VALUE img, fnt, x, y, str, c;
|
1150
|
+
{
|
1151
|
+
gdImagePtr im;
|
1152
|
+
gdFontPtr f;
|
1153
|
+
|
1154
|
+
Check_Type(str, T_STRING);
|
1155
|
+
Data_Get_Struct(img, gdImage, im);
|
1156
|
+
font_req(fnt);
|
1157
|
+
Data_Get_Struct(fnt, gdFont, f);
|
1158
|
+
|
1159
|
+
gdImageString(im,f,NUM2INT(x),NUM2INT(y),RSTRING(str)->ptr,NUM2INT(c));
|
1160
|
+
|
1161
|
+
return img;
|
1162
|
+
}
|
1163
|
+
|
1164
|
+
static VALUE
|
1165
|
+
img_string_up(img, fnt, x, y, str, c)
|
1166
|
+
VALUE img, fnt, x, y, str, c;
|
1167
|
+
{
|
1168
|
+
gdImagePtr im;
|
1169
|
+
gdFontPtr f;
|
1170
|
+
|
1171
|
+
Check_Type(str, T_STRING);
|
1172
|
+
Data_Get_Struct(img, gdImage, im);
|
1173
|
+
font_req(fnt);
|
1174
|
+
Data_Get_Struct(fnt, gdFont, f);
|
1175
|
+
|
1176
|
+
gdImageStringUp(im,f,NUM2INT(x),NUM2INT(y),RSTRING(str)->ptr,NUM2INT(c));
|
1177
|
+
|
1178
|
+
return img;
|
1179
|
+
}
|
1180
|
+
|
1181
|
+
|
1182
|
+
#ifdef HAVE_GDIMAGESTRINGTTF
|
1183
|
+
static VALUE
|
1184
|
+
img_s_string_ttf(klass, fgcolor, fontname, ptsize, angle, x, y, string)
|
1185
|
+
VALUE klass, fgcolor, fontname, ptsize, angle, x, y, string;
|
1186
|
+
{
|
1187
|
+
int brect[8], i;
|
1188
|
+
char *msg;
|
1189
|
+
VALUE ary = rb_ary_new2(8);
|
1190
|
+
|
1191
|
+
Check_Type(fontname, T_STRING);
|
1192
|
+
Check_Type(string, T_STRING);
|
1193
|
+
|
1194
|
+
msg = gdImageStringTTF(NULL,
|
1195
|
+
&brect[0],
|
1196
|
+
NUM2INT(fgcolor),
|
1197
|
+
RSTRING(fontname)->ptr,
|
1198
|
+
NUM2DBL(ptsize),
|
1199
|
+
NUM2DBL(angle),
|
1200
|
+
NUM2INT(x),
|
1201
|
+
NUM2INT(y),
|
1202
|
+
RSTRING(string)->ptr);
|
1203
|
+
for (i=0; i<8; i++) {
|
1204
|
+
rb_ary_push(ary, INT2FIX(brect[i]));
|
1205
|
+
}
|
1206
|
+
if (msg) {
|
1207
|
+
return rb_ary_new3(2, rb_str_new2(msg), ary);
|
1208
|
+
} else {
|
1209
|
+
return rb_ary_new3(2, Qnil, ary);
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
|
1213
|
+
static VALUE
|
1214
|
+
img_string_ttf(img, fgcolor, fontname, ptsize, angle, x, y, string)
|
1215
|
+
VALUE img, fgcolor, fontname, ptsize, angle, x, y, string;
|
1216
|
+
{
|
1217
|
+
gdImagePtr im;
|
1218
|
+
int brect[8], i;
|
1219
|
+
char *msg;
|
1220
|
+
VALUE ary = rb_ary_new2(8);
|
1221
|
+
|
1222
|
+
Check_Type(fontname, T_STRING);
|
1223
|
+
Check_Type(string, T_STRING);
|
1224
|
+
|
1225
|
+
Data_Get_Struct(img, gdImage, im);
|
1226
|
+
msg = gdImageStringTTF(im,
|
1227
|
+
&brect[0],
|
1228
|
+
NUM2INT(fgcolor),
|
1229
|
+
RSTRING(fontname)->ptr,
|
1230
|
+
NUM2DBL(ptsize),
|
1231
|
+
NUM2DBL(angle),
|
1232
|
+
NUM2INT(x),
|
1233
|
+
NUM2INT(y),
|
1234
|
+
RSTRING(string)->ptr);
|
1235
|
+
for (i=0; i<8; i++) {
|
1236
|
+
rb_ary_push(ary, INT2FIX(brect[i]));
|
1237
|
+
}
|
1238
|
+
if (msg) {
|
1239
|
+
return rb_ary_new3(2, rb_str_new2(msg), ary);
|
1240
|
+
} else {
|
1241
|
+
return rb_ary_new3(2, Qnil, ary);
|
1242
|
+
}
|
1243
|
+
}
|
1244
|
+
#endif /* HAVE_GDIMAGESTRINGTTF */
|
1245
|
+
|
1246
|
+
#ifdef HAVE_GDIMAGESTRINGFT
|
1247
|
+
static VALUE
|
1248
|
+
img_s_string_ft(klass, fgcolor, fontname, ptsize, angle, x, y, string)
|
1249
|
+
VALUE klass, fgcolor, fontname, ptsize, angle, x, y, string;
|
1250
|
+
{
|
1251
|
+
int brect[8], i;
|
1252
|
+
char *msg;
|
1253
|
+
VALUE ary = rb_ary_new2(8);
|
1254
|
+
|
1255
|
+
Check_Type(fontname, T_STRING);
|
1256
|
+
Check_Type(string, T_STRING);
|
1257
|
+
|
1258
|
+
msg = gdImageStringFT(NULL,
|
1259
|
+
&brect[0],
|
1260
|
+
NUM2INT(fgcolor),
|
1261
|
+
RSTRING(fontname)->ptr,
|
1262
|
+
NUM2DBL(ptsize),
|
1263
|
+
NUM2DBL(angle),
|
1264
|
+
NUM2INT(x),
|
1265
|
+
NUM2INT(y),
|
1266
|
+
RSTRING(string)->ptr);
|
1267
|
+
for (i=0; i<8; i++) {
|
1268
|
+
rb_ary_push(ary, INT2FIX(brect[i]));
|
1269
|
+
}
|
1270
|
+
if (msg) {
|
1271
|
+
return rb_ary_new3(2, rb_str_new2(msg), ary);
|
1272
|
+
} else {
|
1273
|
+
return rb_ary_new3(2, Qnil, ary);
|
1274
|
+
}
|
1275
|
+
}
|
1276
|
+
|
1277
|
+
static VALUE
|
1278
|
+
img_string_ft(img, fgcolor, fontname, ptsize, angle, x, y, string)
|
1279
|
+
VALUE img, fgcolor, fontname, ptsize, angle, x, y, string;
|
1280
|
+
{
|
1281
|
+
gdImagePtr im;
|
1282
|
+
int brect[8], i;
|
1283
|
+
char *msg;
|
1284
|
+
VALUE ary = rb_ary_new2(8);
|
1285
|
+
|
1286
|
+
Check_Type(fontname, T_STRING);
|
1287
|
+
Check_Type(string, T_STRING);
|
1288
|
+
|
1289
|
+
Data_Get_Struct(img, gdImage, im);
|
1290
|
+
msg = gdImageStringFT(im,
|
1291
|
+
&brect[0],
|
1292
|
+
NUM2INT(fgcolor),
|
1293
|
+
RSTRING(fontname)->ptr,
|
1294
|
+
NUM2DBL(ptsize),
|
1295
|
+
NUM2DBL(angle),
|
1296
|
+
NUM2INT(x),
|
1297
|
+
NUM2INT(y),
|
1298
|
+
RSTRING(string)->ptr);
|
1299
|
+
for (i=0; i<8; i++) {
|
1300
|
+
rb_ary_push(ary, INT2FIX(brect[i]));
|
1301
|
+
}
|
1302
|
+
if (msg) {
|
1303
|
+
return rb_ary_new3(2, rb_str_new2(msg), ary);
|
1304
|
+
} else {
|
1305
|
+
return rb_ary_new3(2, Qnil, ary);
|
1306
|
+
}
|
1307
|
+
}
|
1308
|
+
#endif /* HAVE_GDIMAGESTRINGFT */
|
1309
|
+
|
1310
|
+
static VALUE
|
1311
|
+
img_char(img, fnt, x, y, ch, c)
|
1312
|
+
VALUE img, fnt, x, y, ch, c;
|
1313
|
+
{
|
1314
|
+
gdImagePtr im;
|
1315
|
+
gdFontPtr f;
|
1316
|
+
int ci;
|
1317
|
+
|
1318
|
+
Data_Get_Struct(img, gdImage, im);
|
1319
|
+
font_req(fnt);
|
1320
|
+
Data_Get_Struct(fnt, gdFont, f);
|
1321
|
+
|
1322
|
+
if (TYPE(ch) == T_STRING) {
|
1323
|
+
if (RSTRING(ch)->len != 1) {
|
1324
|
+
rb_raise(rb_eArgError, "string must be 1 byte(%d bytes)", RSTRING(ch)->len);
|
1325
|
+
}
|
1326
|
+
ci = RSTRING(ch)->ptr[0];
|
1327
|
+
}
|
1328
|
+
else {
|
1329
|
+
ci = NUM2INT(ch);
|
1330
|
+
}
|
1331
|
+
gdImageChar(im,f,NUM2INT(x),NUM2INT(y),ci,NUM2INT(c));
|
1332
|
+
|
1333
|
+
return img;
|
1334
|
+
}
|
1335
|
+
|
1336
|
+
static VALUE
|
1337
|
+
img_char_up(img, fnt, x, y, ch, c)
|
1338
|
+
VALUE img, fnt, x, y, ch, c;
|
1339
|
+
{
|
1340
|
+
gdImagePtr im;
|
1341
|
+
gdFontPtr f;
|
1342
|
+
int ci;
|
1343
|
+
|
1344
|
+
Data_Get_Struct(img, gdImage, im);
|
1345
|
+
font_req(fnt);
|
1346
|
+
Data_Get_Struct(fnt, gdFont, f);
|
1347
|
+
|
1348
|
+
if (TYPE(ch) == T_STRING) {
|
1349
|
+
if (RSTRING(ch)->len != 1) {
|
1350
|
+
rb_raise(rb_eArgError, "string must be 1 byte(%d bytes)", RSTRING(ch)->len);
|
1351
|
+
}
|
1352
|
+
ci = RSTRING(ch)->ptr[0];
|
1353
|
+
}
|
1354
|
+
else {
|
1355
|
+
ci = NUM2INT(ch);
|
1356
|
+
}
|
1357
|
+
gdImageCharUp(im,f,NUM2INT(x),NUM2INT(y),ci,NUM2INT(c));
|
1358
|
+
|
1359
|
+
return img;
|
1360
|
+
}
|
1361
|
+
|
1362
|
+
static VALUE
|
1363
|
+
img_get_interlace(img)
|
1364
|
+
VALUE img;
|
1365
|
+
{
|
1366
|
+
gdImagePtr im;
|
1367
|
+
|
1368
|
+
Data_Get_Struct(img, gdImage, im);
|
1369
|
+
if (gdImageGetInterlaced(im)) {
|
1370
|
+
return Qtrue;
|
1371
|
+
}
|
1372
|
+
return Qfalse;
|
1373
|
+
}
|
1374
|
+
|
1375
|
+
static VALUE
|
1376
|
+
img_set_interlace(img, val)
|
1377
|
+
{
|
1378
|
+
gdImagePtr im;
|
1379
|
+
|
1380
|
+
Data_Get_Struct(img, gdImage, im);
|
1381
|
+
gdImageInterlace(im, RTEST(val));
|
1382
|
+
|
1383
|
+
return img;
|
1384
|
+
}
|
1385
|
+
|
1386
|
+
static VALUE
|
1387
|
+
img_bounds(img)
|
1388
|
+
VALUE img;
|
1389
|
+
{
|
1390
|
+
gdImagePtr im;
|
1391
|
+
VALUE ary = rb_ary_new2(2);
|
1392
|
+
int i;
|
1393
|
+
|
1394
|
+
Data_Get_Struct(img, gdImage, im);
|
1395
|
+
i = gdImageSX(im);
|
1396
|
+
rb_ary_push(ary, INT2FIX(i));
|
1397
|
+
i = gdImageSY(im);
|
1398
|
+
rb_ary_push(ary, INT2FIX(i));
|
1399
|
+
|
1400
|
+
return ary;
|
1401
|
+
}
|
1402
|
+
|
1403
|
+
|
1404
|
+
static VALUE
|
1405
|
+
img_bounds_safe(img, x, y)
|
1406
|
+
VALUE img, x, y;
|
1407
|
+
{
|
1408
|
+
gdImagePtr im;
|
1409
|
+
|
1410
|
+
Data_Get_Struct(img, gdImage, im);
|
1411
|
+
if ( gdImageBoundsSafe(im, NUM2INT(x), NUM2INT(y)) ) {
|
1412
|
+
return Qtrue;
|
1413
|
+
} else {
|
1414
|
+
return Qfalse;
|
1415
|
+
}
|
1416
|
+
}
|
1417
|
+
|
1418
|
+
static VALUE
|
1419
|
+
img_get_transparent(img)
|
1420
|
+
VALUE img;
|
1421
|
+
{
|
1422
|
+
gdImagePtr im;
|
1423
|
+
|
1424
|
+
Data_Get_Struct(img, gdImage, im);
|
1425
|
+
return INT2NUM(gdImageGetTransparent(im));
|
1426
|
+
}
|
1427
|
+
|
1428
|
+
|
1429
|
+
static VALUE
|
1430
|
+
img_width(img)
|
1431
|
+
VALUE img;
|
1432
|
+
{
|
1433
|
+
gdImagePtr im;
|
1434
|
+
int i;
|
1435
|
+
|
1436
|
+
Data_Get_Struct(img, gdImage, im);
|
1437
|
+
i = gdImageSX(im);
|
1438
|
+
return INT2FIX(i);
|
1439
|
+
}
|
1440
|
+
|
1441
|
+
static VALUE
|
1442
|
+
img_height(img)
|
1443
|
+
VALUE img;
|
1444
|
+
{
|
1445
|
+
gdImagePtr im;
|
1446
|
+
int i;
|
1447
|
+
|
1448
|
+
Data_Get_Struct(img, gdImage, im);
|
1449
|
+
i = gdImageSY(im);
|
1450
|
+
return INT2FIX(i);
|
1451
|
+
}
|
1452
|
+
|
1453
|
+
static VALUE
|
1454
|
+
img_png(img, out)
|
1455
|
+
VALUE img, out;
|
1456
|
+
{
|
1457
|
+
gdImagePtr im;
|
1458
|
+
OpenFile *fptr;
|
1459
|
+
FILE *f;
|
1460
|
+
|
1461
|
+
Data_Get_Struct(img, gdImage, im);
|
1462
|
+
Check_Type(out, T_FILE);
|
1463
|
+
rb_io_binmode(out);
|
1464
|
+
GetOpenFile(out, fptr);
|
1465
|
+
rb_io_check_writable(fptr);
|
1466
|
+
f = (fptr->f2) ? fptr->f2 : fptr->f;
|
1467
|
+
|
1468
|
+
gdImagePng(im, f);
|
1469
|
+
|
1470
|
+
return img;
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
static VALUE
|
1474
|
+
img_png_str(img)
|
1475
|
+
VALUE img;
|
1476
|
+
{
|
1477
|
+
int size;
|
1478
|
+
void *ptr;
|
1479
|
+
gdImagePtr im;
|
1480
|
+
VALUE imageString;
|
1481
|
+
|
1482
|
+
Data_Get_Struct(img, gdImage, im);
|
1483
|
+
ptr = gdImagePngPtr(im, &size);
|
1484
|
+
imageString = rb_str_new(ptr, size);
|
1485
|
+
|
1486
|
+
#ifdef ENABLE_GD_2_0
|
1487
|
+
gdFree(ptr);
|
1488
|
+
#else
|
1489
|
+
free(ptr);
|
1490
|
+
#endif
|
1491
|
+
|
1492
|
+
return imageString;
|
1493
|
+
}
|
1494
|
+
|
1495
|
+
static VALUE
|
1496
|
+
img_gd(img, out)
|
1497
|
+
VALUE img, out;
|
1498
|
+
{
|
1499
|
+
gdImagePtr im;
|
1500
|
+
OpenFile *fptr;
|
1501
|
+
FILE *f;
|
1502
|
+
|
1503
|
+
Data_Get_Struct(img, gdImage, im);
|
1504
|
+
Check_Type(out, T_FILE);
|
1505
|
+
rb_io_binmode(out);
|
1506
|
+
GetOpenFile(out, fptr);
|
1507
|
+
rb_io_check_writable(fptr);
|
1508
|
+
f = (fptr->f2) ? fptr->f2 : fptr->f;
|
1509
|
+
|
1510
|
+
gdImageGd(im, f);
|
1511
|
+
|
1512
|
+
return img;
|
1513
|
+
}
|
1514
|
+
|
1515
|
+
static VALUE
|
1516
|
+
img_gd2(img, out, cs, fmt)
|
1517
|
+
VALUE img, out, cs, fmt;
|
1518
|
+
{
|
1519
|
+
OpenFile *fptr;
|
1520
|
+
gdImagePtr im;
|
1521
|
+
FILE *f;
|
1522
|
+
|
1523
|
+
Check_Type(out, T_FILE);
|
1524
|
+
rb_io_binmode(out);
|
1525
|
+
GetOpenFile(out, fptr);
|
1526
|
+
rb_io_check_writable(fptr);
|
1527
|
+
f = (fptr->f2) ? fptr->f2 : fptr->f;
|
1528
|
+
|
1529
|
+
Data_Get_Struct(img, gdImage, im);
|
1530
|
+
gdImageGd2(im, f, NUM2INT(cs), NUM2INT(fmt));
|
1531
|
+
|
1532
|
+
return img;
|
1533
|
+
}
|
1534
|
+
|
1535
|
+
|
1536
|
+
#ifdef HAVE_GDIMAGECREATEFROMJPEG
|
1537
|
+
static VALUE
|
1538
|
+
img_jpeg(img, out, quality)
|
1539
|
+
VALUE img, out, quality;
|
1540
|
+
{
|
1541
|
+
gdImagePtr im;
|
1542
|
+
OpenFile *fptr;
|
1543
|
+
FILE *f;
|
1544
|
+
|
1545
|
+
Data_Get_Struct(img, gdImage, im);
|
1546
|
+
|
1547
|
+
Check_Type(out, T_FILE);
|
1548
|
+
|
1549
|
+
rb_io_binmode(out);
|
1550
|
+
GetOpenFile(out, fptr);
|
1551
|
+
rb_io_check_writable(fptr);
|
1552
|
+
f = (fptr->f2) ? fptr->f2 : fptr->f;
|
1553
|
+
|
1554
|
+
gdImageJpeg(im, f, FIX2INT(quality));
|
1555
|
+
|
1556
|
+
return img;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
static VALUE
|
1560
|
+
img_jpeg_str(img, quality)
|
1561
|
+
VALUE img, quality;
|
1562
|
+
{
|
1563
|
+
int size;
|
1564
|
+
void *ptr;
|
1565
|
+
gdImagePtr im;
|
1566
|
+
VALUE imageString;
|
1567
|
+
|
1568
|
+
Data_Get_Struct(img, gdImage, im);
|
1569
|
+
ptr = gdImageJpegPtr(im, &size, FIX2INT(quality));
|
1570
|
+
imageString = rb_str_new(ptr, size);
|
1571
|
+
|
1572
|
+
#ifdef ENABLE_GD_2_0
|
1573
|
+
gdFree(ptr);
|
1574
|
+
#else
|
1575
|
+
free(ptr);
|
1576
|
+
#endif
|
1577
|
+
|
1578
|
+
return imageString;
|
1579
|
+
}
|
1580
|
+
#endif
|
1581
|
+
|
1582
|
+
static VALUE
|
1583
|
+
img_wbmp(img, fg, out)
|
1584
|
+
VALUE img, out, fg;
|
1585
|
+
{
|
1586
|
+
gdImagePtr im;
|
1587
|
+
OpenFile *fptr;
|
1588
|
+
FILE *f;
|
1589
|
+
|
1590
|
+
Data_Get_Struct(img, gdImage, im);
|
1591
|
+
|
1592
|
+
Check_Type(out, T_FILE);
|
1593
|
+
|
1594
|
+
rb_io_binmode(out);
|
1595
|
+
GetOpenFile(out, fptr);
|
1596
|
+
rb_io_check_writable(fptr);
|
1597
|
+
f = (fptr->f2) ? fptr->f2 : fptr->f;
|
1598
|
+
|
1599
|
+
gdImageWBMP(im, FIX2INT(fg), f);
|
1600
|
+
|
1601
|
+
return img;
|
1602
|
+
}
|
1603
|
+
|
1604
|
+
/*
|
1605
|
+
*
|
1606
|
+
* Poligon
|
1607
|
+
*
|
1608
|
+
*/
|
1609
|
+
|
1610
|
+
static VALUE
|
1611
|
+
ply_new(klass)
|
1612
|
+
VALUE klass;
|
1613
|
+
{
|
1614
|
+
VALUE self = rb_ary_new();
|
1615
|
+
|
1616
|
+
RBASIC(self)->klass = klass;
|
1617
|
+
return self;
|
1618
|
+
}
|
1619
|
+
|
1620
|
+
static VALUE
|
1621
|
+
ply_add_pt(ply, x, y)
|
1622
|
+
VALUE ply, x, y;
|
1623
|
+
{
|
1624
|
+
/* type check */
|
1625
|
+
NUM2INT(x);
|
1626
|
+
NUM2INT(y);
|
1627
|
+
|
1628
|
+
rb_ary_push(ply, x);
|
1629
|
+
rb_ary_push(ply, y);
|
1630
|
+
return ply;
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
static VALUE
|
1634
|
+
ply_to_pt(ply, dx, dy)
|
1635
|
+
VALUE ply, dx, dy;
|
1636
|
+
{
|
1637
|
+
VALUE x, y;
|
1638
|
+
|
1639
|
+
/* type check */
|
1640
|
+
NUM2INT(dx);
|
1641
|
+
NUM2INT(dy);
|
1642
|
+
|
1643
|
+
if (RARRAY(ply)->len > 0) {
|
1644
|
+
x = rb_ary_entry(ply, RARRAY(ply)->len - 2);
|
1645
|
+
y = rb_ary_entry(ply, RARRAY(ply)->len - 1);
|
1646
|
+
rb_ary_push(ply, INT2NUM(NUM2INT(x) + NUM2INT(dx)));
|
1647
|
+
rb_ary_push(ply, INT2NUM(NUM2INT(y) + NUM2INT(dy)));
|
1648
|
+
} else {
|
1649
|
+
ply_add_pt(ply, dx, dy);
|
1650
|
+
}
|
1651
|
+
return ply;
|
1652
|
+
}
|
1653
|
+
|
1654
|
+
static VALUE
|
1655
|
+
ply_get_pt(ply, idx)
|
1656
|
+
VALUE ply, idx;
|
1657
|
+
{
|
1658
|
+
int i = NUM2INT(idx);
|
1659
|
+
|
1660
|
+
if (RARRAY(ply)->len < idx) return Qnil;
|
1661
|
+
i *= 2;
|
1662
|
+
|
1663
|
+
return rb_assoc_new(rb_ary_entry(ply, i), rb_ary_entry(ply, i+1));
|
1664
|
+
}
|
1665
|
+
|
1666
|
+
static VALUE
|
1667
|
+
ply_set_pt(ply, idx, x, y)
|
1668
|
+
VALUE ply, idx, x, y;
|
1669
|
+
{
|
1670
|
+
int i = NUM2INT(idx)*2;
|
1671
|
+
|
1672
|
+
/* type check */
|
1673
|
+
NUM2INT(x);
|
1674
|
+
NUM2INT(y);
|
1675
|
+
|
1676
|
+
rb_ary_store(ply, i, x);
|
1677
|
+
rb_ary_store(ply, i+1, y);
|
1678
|
+
|
1679
|
+
return ply;
|
1680
|
+
}
|
1681
|
+
|
1682
|
+
static VALUE
|
1683
|
+
ply_delete_pt(ply, idx)
|
1684
|
+
VALUE ply, idx;
|
1685
|
+
{
|
1686
|
+
int i = NUM2INT(idx)*2;
|
1687
|
+
|
1688
|
+
rb_ary_delete_at(ply, INT2FIX(i));
|
1689
|
+
rb_ary_delete_at(ply, INT2FIX(i+1));
|
1690
|
+
|
1691
|
+
return ply;
|
1692
|
+
}
|
1693
|
+
|
1694
|
+
static VALUE
|
1695
|
+
ply_length(ply)
|
1696
|
+
VALUE ply;
|
1697
|
+
{
|
1698
|
+
return INT2FIX(RARRAY(ply)->len / 2);
|
1699
|
+
}
|
1700
|
+
|
1701
|
+
static VALUE
|
1702
|
+
ply_vertices(ply)
|
1703
|
+
struct RArray *ply;
|
1704
|
+
{
|
1705
|
+
int i;
|
1706
|
+
VALUE ary = rb_ary_new2(ply->len/2);
|
1707
|
+
|
1708
|
+
for (i = 0; i<ply->len; i+=2) {
|
1709
|
+
rb_ary_push(ary, rb_assoc_new(ply->ptr[i], ply->ptr[i+1]));
|
1710
|
+
}
|
1711
|
+
return ary;
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
static VALUE
|
1715
|
+
ply_bounds(ply)
|
1716
|
+
struct RArray *ply;
|
1717
|
+
{
|
1718
|
+
int i, l, t, r, b;
|
1719
|
+
int nx, ny;
|
1720
|
+
|
1721
|
+
if (ply->len == 0) {
|
1722
|
+
l = t = r = b = 0;
|
1723
|
+
}
|
1724
|
+
else {
|
1725
|
+
l = r = NUM2INT(ply->ptr[0]);
|
1726
|
+
t = b = NUM2INT(ply->ptr[1]);
|
1727
|
+
}
|
1728
|
+
for (i = 2; i<ply->len; i+=2) {
|
1729
|
+
nx = NUM2INT(ply->ptr[i]);
|
1730
|
+
if (nx < l) l = nx;
|
1731
|
+
if (nx > r) r = nx;
|
1732
|
+
ny = NUM2INT(ply->ptr[i+1]);
|
1733
|
+
if (ny < t) t = ny;
|
1734
|
+
if (ny > b) b = ny;
|
1735
|
+
}
|
1736
|
+
return rb_ary_new3(4, INT2FIX(l), INT2FIX(t), INT2FIX(r), INT2FIX(b));
|
1737
|
+
}
|
1738
|
+
|
1739
|
+
static VALUE
|
1740
|
+
ply_offset(ply, vx, vy)
|
1741
|
+
struct RArray *ply;
|
1742
|
+
VALUE vx, vy;
|
1743
|
+
{
|
1744
|
+
int i, x, y, c;
|
1745
|
+
|
1746
|
+
x = NUM2INT(vx);
|
1747
|
+
y = NUM2INT(vy);
|
1748
|
+
|
1749
|
+
for (i = 0; i<ply->len; i+=2) {
|
1750
|
+
c = NUM2INT(ply->ptr[i]) + x;
|
1751
|
+
ply->ptr[i] = INT2FIX(c);
|
1752
|
+
c = NUM2INT(ply->ptr[i+1]) + y;
|
1753
|
+
ply->ptr[i+1] = INT2FIX(c);
|
1754
|
+
}
|
1755
|
+
|
1756
|
+
return (VALUE)ply;
|
1757
|
+
}
|
1758
|
+
|
1759
|
+
static VALUE
|
1760
|
+
ply_map(argc, argv, ply)
|
1761
|
+
int argc;
|
1762
|
+
VALUE *argv;
|
1763
|
+
struct RArray *ply;
|
1764
|
+
{
|
1765
|
+
VALUE sl, st, sr, sb, dl, dt, dr, db;
|
1766
|
+
int sx, sy, dx, dy;
|
1767
|
+
double xmag, ymag;
|
1768
|
+
int i, c;
|
1769
|
+
|
1770
|
+
i = rb_scan_args(argc,argv,"44",&sl,&st,&sr,&sb, &dl,&dt,&dr,&db);
|
1771
|
+
|
1772
|
+
if (i == 4) {
|
1773
|
+
int i, l, t, r, b;
|
1774
|
+
int nx, ny;
|
1775
|
+
|
1776
|
+
if (ply->len == 0) {
|
1777
|
+
l = t = r = b = 0;
|
1778
|
+
}
|
1779
|
+
else {
|
1780
|
+
l = r = NUM2INT(ply->ptr[0]);
|
1781
|
+
t = b = NUM2INT(ply->ptr[1]);
|
1782
|
+
}
|
1783
|
+
for (i = 2; i<ply->len; i+=2) {
|
1784
|
+
nx = NUM2INT(ply->ptr[i]);
|
1785
|
+
if (nx < l) l = nx;
|
1786
|
+
if (nx > r) r = nx;
|
1787
|
+
ny = NUM2INT(ply->ptr[i+1]);
|
1788
|
+
if (ny < t) t = ny;
|
1789
|
+
if (ny > b) b = ny;
|
1790
|
+
}
|
1791
|
+
sx = l;
|
1792
|
+
sy = t;
|
1793
|
+
dx = NUM2INT(sl);
|
1794
|
+
dy = NUM2INT(st);
|
1795
|
+
xmag = (double)(NUM2INT(sr) - NUM2INT(sl))/(double)(r - l);
|
1796
|
+
ymag = (double)(NUM2INT(sb) - NUM2INT(st))/(double)(b - t);
|
1797
|
+
}
|
1798
|
+
else if (i == 8) {
|
1799
|
+
sx = NUM2INT(sl);
|
1800
|
+
sy = NUM2INT(st);
|
1801
|
+
dx = NUM2INT(dl);
|
1802
|
+
dy = NUM2INT(dt);
|
1803
|
+
xmag = (double)(NUM2INT(dr) - NUM2INT(dl))/
|
1804
|
+
(double)(NUM2INT(sr) - NUM2INT(sl));
|
1805
|
+
ymag = (double)(NUM2INT(db) - NUM2INT(dt))/
|
1806
|
+
(double)(NUM2INT(sb) - NUM2INT(st));
|
1807
|
+
}
|
1808
|
+
else {
|
1809
|
+
rb_raise(rb_eArgError, "wrong # of arguments (%d for 4 or 8)", argc);
|
1810
|
+
}
|
1811
|
+
|
1812
|
+
for (i = 0; i<ply->len; i+=2) {
|
1813
|
+
c = NUM2INT(ply->ptr[i]);
|
1814
|
+
c = (c-sx)*xmag+dx;
|
1815
|
+
ply->ptr[i] = INT2FIX(c);
|
1816
|
+
|
1817
|
+
c = NUM2INT(ply->ptr[i+1]);
|
1818
|
+
c = (c-sy)*ymag+dy;
|
1819
|
+
ply->ptr[i+1] = INT2FIX(c);
|
1820
|
+
}
|
1821
|
+
|
1822
|
+
return (VALUE)ply;
|
1823
|
+
}
|
1824
|
+
|
1825
|
+
static VALUE
|
1826
|
+
ply_transform(ply, a, b, c, d, tx, ty)
|
1827
|
+
VALUE ply, a, b, c, d, tx, ty;
|
1828
|
+
{
|
1829
|
+
int i;
|
1830
|
+
VALUE x, y;
|
1831
|
+
|
1832
|
+
for (i = 0; i < RARRAY(ply)->len / 2; i++) {
|
1833
|
+
/* x = rb_ary_entry(ply, i * 2);
|
1834
|
+
y = rb_ary_entry(ply, i * 2 + 1);*/
|
1835
|
+
x = RARRAY(ply)->ptr[i * 2];
|
1836
|
+
y = RARRAY(ply)->ptr[i * 2 + 1];
|
1837
|
+
ply_set_pt(ply, INT2NUM(i),
|
1838
|
+
INT2NUM(NUM2DBL(a) * NUM2INT(x) + NUM2DBL(c) * NUM2INT(y) + NUM2INT(tx)),
|
1839
|
+
INT2NUM(NUM2DBL(b) * NUM2INT(x) + NUM2DBL(d) * NUM2INT(y) + NUM2INT(ty)));
|
1840
|
+
}
|
1841
|
+
return ply;
|
1842
|
+
}
|
1843
|
+
|
1844
|
+
static VALUE
|
1845
|
+
ply_scale(ply, sx, sy)
|
1846
|
+
VALUE ply, sx, sy;
|
1847
|
+
{
|
1848
|
+
return ply_transform(ply, sx, INT2NUM(0), INT2NUM(0), sy, INT2NUM(0), INT2NUM(0));
|
1849
|
+
}
|
1850
|
+
|
1851
|
+
static VALUE
|
1852
|
+
fnt_create(fnt)
|
1853
|
+
gdFontPtr fnt;
|
1854
|
+
{
|
1855
|
+
return Data_Wrap_Struct(cFont, 0, 0, fnt);
|
1856
|
+
}
|
1857
|
+
|
1858
|
+
static VALUE
|
1859
|
+
fnt_new(name)
|
1860
|
+
char *name;
|
1861
|
+
{
|
1862
|
+
if (strcmp(name, "Giant") == 0) {
|
1863
|
+
return fnt_create(gdFontGiant);
|
1864
|
+
}
|
1865
|
+
if (strcmp(name, "Large") == 0) {
|
1866
|
+
return fnt_create(gdFontLarge);
|
1867
|
+
}
|
1868
|
+
if (strcmp(name, "Medium") == 0) {
|
1869
|
+
return fnt_create(gdFontMediumBold);
|
1870
|
+
}
|
1871
|
+
if (strcmp(name, "Small") == 0) {
|
1872
|
+
return fnt_create(gdFontSmall);
|
1873
|
+
}
|
1874
|
+
if (strcmp(name, "Tiny") == 0) {
|
1875
|
+
return fnt_create(gdFontTiny);
|
1876
|
+
}
|
1877
|
+
rb_raise(rb_eArgError, "undefined font name `%s'", name);
|
1878
|
+
}
|
1879
|
+
|
1880
|
+
static VALUE
|
1881
|
+
fnt_s_new(obj, name)
|
1882
|
+
VALUE obj;
|
1883
|
+
struct RString *name;
|
1884
|
+
{
|
1885
|
+
Check_Type(name, T_STRING);
|
1886
|
+
return fnt_new(name->ptr);
|
1887
|
+
}
|
1888
|
+
|
1889
|
+
static VALUE
|
1890
|
+
fnt_nchars(fnt)
|
1891
|
+
VALUE fnt;
|
1892
|
+
{
|
1893
|
+
gdFontPtr fp;
|
1894
|
+
|
1895
|
+
Data_Get_Struct(fnt,gdFont,fp);
|
1896
|
+
return INT2FIX(fp->nchars);
|
1897
|
+
}
|
1898
|
+
|
1899
|
+
static VALUE
|
1900
|
+
fnt_offset(fnt)
|
1901
|
+
VALUE fnt;
|
1902
|
+
{
|
1903
|
+
gdFontPtr fp;
|
1904
|
+
|
1905
|
+
Data_Get_Struct(fnt,gdFont,fp);
|
1906
|
+
return INT2FIX(fp->offset);
|
1907
|
+
}
|
1908
|
+
|
1909
|
+
static VALUE
|
1910
|
+
fnt_width(fnt)
|
1911
|
+
VALUE fnt;
|
1912
|
+
{
|
1913
|
+
gdFontPtr fp;
|
1914
|
+
|
1915
|
+
Data_Get_Struct(fnt,gdFont,fp);
|
1916
|
+
return INT2FIX(fp->w);
|
1917
|
+
}
|
1918
|
+
|
1919
|
+
static VALUE
|
1920
|
+
fnt_height(fnt)
|
1921
|
+
VALUE fnt;
|
1922
|
+
{
|
1923
|
+
gdFontPtr fp;
|
1924
|
+
|
1925
|
+
Data_Get_Struct(fnt,gdFont,fp);
|
1926
|
+
return INT2FIX(fp->h);
|
1927
|
+
}
|
1928
|
+
|
1929
|
+
/*
|
1930
|
+
*
|
1931
|
+
* gd-2.0.x features : experimental
|
1932
|
+
*
|
1933
|
+
*/
|
1934
|
+
|
1935
|
+
#ifdef ENABLE_GD_2_0
|
1936
|
+
|
1937
|
+
static VALUE
|
1938
|
+
img_s_new_tc(klass, sx, sy)
|
1939
|
+
VALUE klass, sx, sy;
|
1940
|
+
{
|
1941
|
+
gdImagePtr iptr;
|
1942
|
+
|
1943
|
+
if (NUM2INT(sx)<0 || NUM2INT(sy)<0)
|
1944
|
+
rb_raise(rb_eArgError, "Negative width/height not allowed");
|
1945
|
+
|
1946
|
+
iptr = gdImageCreateTrueColor(NUM2INT(sx), NUM2INT(sy));
|
1947
|
+
if (!iptr)
|
1948
|
+
rb_raise(rb_eRuntimeError, "Unable to allocate the new image");
|
1949
|
+
|
1950
|
+
return Data_Wrap_Struct(klass,0,free_img,iptr);
|
1951
|
+
}
|
1952
|
+
|
1953
|
+
static VALUE
|
1954
|
+
img_color_allocate_alpha_tri(img, r, g, b, a)
|
1955
|
+
VALUE img, r, g, b, a;
|
1956
|
+
{
|
1957
|
+
gdImagePtr im;
|
1958
|
+
int c;
|
1959
|
+
|
1960
|
+
Data_Get_Struct(img, gdImage, im);
|
1961
|
+
c = gdImageColorAllocateAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a));
|
1962
|
+
|
1963
|
+
return INT2NUM(c);
|
1964
|
+
}
|
1965
|
+
|
1966
|
+
static VALUE
|
1967
|
+
img_color_allocate_alpha_str(img, rgbstr, a)
|
1968
|
+
VALUE img, rgbstr, a;
|
1969
|
+
{
|
1970
|
+
gdImagePtr im;
|
1971
|
+
int c;
|
1972
|
+
VALUE ary;
|
1973
|
+
|
1974
|
+
Data_Get_Struct(img, gdImage, im);
|
1975
|
+
|
1976
|
+
ary = hex2triplet(rgbstr);
|
1977
|
+
c = gdImageColorAllocateAlpha(im,
|
1978
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
1979
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
1980
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)),
|
1981
|
+
NUM2INT(a));
|
1982
|
+
return INT2NUM(c);
|
1983
|
+
}
|
1984
|
+
|
1985
|
+
static VALUE
|
1986
|
+
img_color_allocate_alpha(argc, argv, img)
|
1987
|
+
int argc;
|
1988
|
+
VALUE *argv;
|
1989
|
+
VALUE img;
|
1990
|
+
{
|
1991
|
+
int i;
|
1992
|
+
VALUE rgbstr, r, g, b, a, retval;
|
1993
|
+
|
1994
|
+
if (!(argc == 2 || argc == 4))
|
1995
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc);
|
1996
|
+
|
1997
|
+
switch(TYPE(argv[0])) {
|
1998
|
+
case T_STRING:
|
1999
|
+
i = rb_scan_args(argc, argv, "20", &rgbstr, &a);
|
2000
|
+
retval = img_color_allocate_alpha_str(img, rgbstr, a);
|
2001
|
+
break;
|
2002
|
+
case T_FIXNUM:
|
2003
|
+
i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a);
|
2004
|
+
retval = img_color_allocate_alpha_tri(img, r, g, b, a);
|
2005
|
+
break;
|
2006
|
+
default:
|
2007
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2008
|
+
break;
|
2009
|
+
}
|
2010
|
+
|
2011
|
+
return retval;
|
2012
|
+
}
|
2013
|
+
|
2014
|
+
|
2015
|
+
static VALUE
|
2016
|
+
img_color_resolve_alpha_tri(img, r, g, b, a)
|
2017
|
+
VALUE img, r, g, b, a;
|
2018
|
+
{
|
2019
|
+
gdImagePtr im;
|
2020
|
+
int c;
|
2021
|
+
|
2022
|
+
Data_Get_Struct(img, gdImage, im);
|
2023
|
+
c = gdImageColorResolveAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a));
|
2024
|
+
|
2025
|
+
return INT2NUM(c);
|
2026
|
+
}
|
2027
|
+
|
2028
|
+
static VALUE
|
2029
|
+
img_color_resolve_alpha_str(img, rgbstr, a)
|
2030
|
+
VALUE img, rgbstr, a;
|
2031
|
+
{
|
2032
|
+
gdImagePtr im;
|
2033
|
+
int c;
|
2034
|
+
VALUE ary;
|
2035
|
+
|
2036
|
+
Data_Get_Struct(img, gdImage, im);
|
2037
|
+
|
2038
|
+
ary = hex2triplet(rgbstr);
|
2039
|
+
c = gdImageColorResolveAlpha(im,
|
2040
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
2041
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
2042
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)),
|
2043
|
+
NUM2INT(a));
|
2044
|
+
return INT2NUM(c);
|
2045
|
+
}
|
2046
|
+
|
2047
|
+
static VALUE
|
2048
|
+
img_color_resolve_alpha(argc, argv, img)
|
2049
|
+
int argc;
|
2050
|
+
VALUE *argv;
|
2051
|
+
VALUE img;
|
2052
|
+
{
|
2053
|
+
int i;
|
2054
|
+
VALUE rgbstr, r, g, b, a, retval;
|
2055
|
+
|
2056
|
+
if (!(argc == 2 || argc == 4))
|
2057
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc);
|
2058
|
+
|
2059
|
+
switch(TYPE(argv[0])) {
|
2060
|
+
case T_STRING:
|
2061
|
+
i = rb_scan_args(argc, argv, "20", &rgbstr, &a);
|
2062
|
+
retval = img_color_resolve_alpha_str(img, rgbstr, a);
|
2063
|
+
break;
|
2064
|
+
case T_FIXNUM:
|
2065
|
+
i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a);
|
2066
|
+
retval = img_color_resolve_alpha_tri(img, r, g, b, a);
|
2067
|
+
break;
|
2068
|
+
default:
|
2069
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2070
|
+
break;
|
2071
|
+
}
|
2072
|
+
|
2073
|
+
return retval;
|
2074
|
+
}
|
2075
|
+
|
2076
|
+
static VALUE
|
2077
|
+
img_color_closest_alpha_tri(img, r, g, b, a)
|
2078
|
+
VALUE img, r, g, b, a;
|
2079
|
+
{
|
2080
|
+
gdImagePtr im;
|
2081
|
+
int c;
|
2082
|
+
|
2083
|
+
Data_Get_Struct(img, gdImage, im);
|
2084
|
+
c = gdImageColorClosestAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a));
|
2085
|
+
|
2086
|
+
return INT2NUM(c);
|
2087
|
+
}
|
2088
|
+
|
2089
|
+
static VALUE
|
2090
|
+
img_color_closest_alpha_str(img, rgbstr, a)
|
2091
|
+
VALUE img, rgbstr, a;
|
2092
|
+
{
|
2093
|
+
gdImagePtr im;
|
2094
|
+
int c;
|
2095
|
+
VALUE ary;
|
2096
|
+
|
2097
|
+
Data_Get_Struct(img, gdImage, im);
|
2098
|
+
|
2099
|
+
ary = hex2triplet(rgbstr);
|
2100
|
+
c = gdImageColorClosestAlpha(im,
|
2101
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
2102
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
2103
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)),
|
2104
|
+
NUM2INT(a));
|
2105
|
+
return INT2NUM(c);
|
2106
|
+
}
|
2107
|
+
|
2108
|
+
static VALUE
|
2109
|
+
img_color_closest_alpha(argc, argv, img)
|
2110
|
+
int argc;
|
2111
|
+
VALUE *argv;
|
2112
|
+
VALUE img;
|
2113
|
+
{
|
2114
|
+
int i;
|
2115
|
+
VALUE rgbstr, r, g, b, a, retval;
|
2116
|
+
|
2117
|
+
if (!(argc == 2 || argc == 4))
|
2118
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc);
|
2119
|
+
|
2120
|
+
switch(TYPE(argv[0])) {
|
2121
|
+
case T_STRING:
|
2122
|
+
i = rb_scan_args(argc, argv, "20", &rgbstr, &a);
|
2123
|
+
retval = img_color_closest_alpha_str(img, rgbstr, a);
|
2124
|
+
break;
|
2125
|
+
case T_FIXNUM:
|
2126
|
+
i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a);
|
2127
|
+
retval = img_color_closest_alpha_tri(img, r, g, b, a);
|
2128
|
+
break;
|
2129
|
+
default:
|
2130
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2131
|
+
break;
|
2132
|
+
}
|
2133
|
+
|
2134
|
+
return retval;
|
2135
|
+
}
|
2136
|
+
|
2137
|
+
|
2138
|
+
static VALUE
|
2139
|
+
img_color_exact_alpha_tri(img, r, g, b, a)
|
2140
|
+
VALUE img, r, g, b, a;
|
2141
|
+
{
|
2142
|
+
gdImagePtr im;
|
2143
|
+
int c;
|
2144
|
+
|
2145
|
+
Data_Get_Struct(img, gdImage, im);
|
2146
|
+
c = gdImageColorExactAlpha(im, NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a));
|
2147
|
+
|
2148
|
+
return INT2NUM(c);
|
2149
|
+
}
|
2150
|
+
|
2151
|
+
static VALUE
|
2152
|
+
img_color_exact_alpha_str(img, rgbstr, a)
|
2153
|
+
VALUE img, rgbstr, a;
|
2154
|
+
{
|
2155
|
+
gdImagePtr im;
|
2156
|
+
int c;
|
2157
|
+
VALUE ary;
|
2158
|
+
|
2159
|
+
Data_Get_Struct(img, gdImage, im);
|
2160
|
+
|
2161
|
+
ary = hex2triplet(rgbstr);
|
2162
|
+
c = gdImageColorExactAlpha(im,
|
2163
|
+
NUM2INT(*(RARRAY(ary)->ptr)),
|
2164
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
2165
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)),
|
2166
|
+
NUM2INT(a));
|
2167
|
+
return INT2NUM(c);
|
2168
|
+
}
|
2169
|
+
|
2170
|
+
static VALUE
|
2171
|
+
img_color_exact_alpha(argc, argv, img)
|
2172
|
+
int argc;
|
2173
|
+
VALUE *argv;
|
2174
|
+
VALUE img;
|
2175
|
+
{
|
2176
|
+
int i;
|
2177
|
+
VALUE rgbstr, r, g, b, a, retval;
|
2178
|
+
|
2179
|
+
if (!(argc == 2 || argc == 4))
|
2180
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc);
|
2181
|
+
|
2182
|
+
switch(TYPE(argv[0])) {
|
2183
|
+
case T_STRING:
|
2184
|
+
i = rb_scan_args(argc, argv, "20", &rgbstr, &a);
|
2185
|
+
retval = img_color_exact_alpha_str(img, rgbstr, a);
|
2186
|
+
break;
|
2187
|
+
case T_FIXNUM:
|
2188
|
+
i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a);
|
2189
|
+
retval = img_color_exact_alpha_tri(img, r, g, b, a);
|
2190
|
+
break;
|
2191
|
+
default:
|
2192
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2193
|
+
break;
|
2194
|
+
}
|
2195
|
+
|
2196
|
+
return retval;
|
2197
|
+
}
|
2198
|
+
|
2199
|
+
static VALUE
|
2200
|
+
img_alpha_blending(img, blending_mode)
|
2201
|
+
VALUE img, blending_mode;
|
2202
|
+
{
|
2203
|
+
gdImagePtr im;
|
2204
|
+
|
2205
|
+
Data_Get_Struct(img, gdImage, im);
|
2206
|
+
gdImageAlphaBlending(im, RTEST(blending_mode));
|
2207
|
+
|
2208
|
+
return img;
|
2209
|
+
}
|
2210
|
+
|
2211
|
+
static VALUE
|
2212
|
+
img_alpha(img, color)
|
2213
|
+
VALUE img, color;
|
2214
|
+
{
|
2215
|
+
gdImagePtr im;
|
2216
|
+
|
2217
|
+
Data_Get_Struct(img, gdImage, im);
|
2218
|
+
return INT2NUM(gdImageAlpha(im, NUM2INT(color)));
|
2219
|
+
}
|
2220
|
+
|
2221
|
+
|
2222
|
+
static VALUE
|
2223
|
+
img_s_truecolor_str(rgbstr)
|
2224
|
+
VALUE rgbstr;
|
2225
|
+
{
|
2226
|
+
int c;
|
2227
|
+
VALUE ary;
|
2228
|
+
ary = hex2triplet(rgbstr);
|
2229
|
+
c = gdTrueColor(NUM2INT(*(RARRAY(ary)->ptr)),
|
2230
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
2231
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)));
|
2232
|
+
|
2233
|
+
return INT2NUM(c);
|
2234
|
+
}
|
2235
|
+
|
2236
|
+
static VALUE
|
2237
|
+
img_s_truecolor_tri(r, g, b)
|
2238
|
+
VALUE r, g, b;
|
2239
|
+
{
|
2240
|
+
int c;
|
2241
|
+
c = gdTrueColor(NUM2INT(r), NUM2INT(g), NUM2INT(b));
|
2242
|
+
|
2243
|
+
return INT2NUM(c);
|
2244
|
+
}
|
2245
|
+
|
2246
|
+
static VALUE
|
2247
|
+
img_s_truecolor(argc, argv, img)
|
2248
|
+
int argc;
|
2249
|
+
VALUE *argv;
|
2250
|
+
VALUE img;
|
2251
|
+
{
|
2252
|
+
int i;
|
2253
|
+
VALUE rgbstr, r, g, b, retval;
|
2254
|
+
|
2255
|
+
if (!(argc == 1 || argc == 3))
|
2256
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (1 or 3 for %d)", argc);
|
2257
|
+
|
2258
|
+
switch(TYPE(argv[0])) {
|
2259
|
+
case T_STRING:
|
2260
|
+
i = rb_scan_args(argc, argv, "10", &rgbstr);
|
2261
|
+
retval = img_s_truecolor_str(rgbstr);
|
2262
|
+
break;
|
2263
|
+
case T_FIXNUM:
|
2264
|
+
i = rb_scan_args(argc, argv, "30", &r, &g, &b);
|
2265
|
+
retval = img_s_truecolor_tri(r, g, b);
|
2266
|
+
break;
|
2267
|
+
default:
|
2268
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2269
|
+
break;
|
2270
|
+
}
|
2271
|
+
|
2272
|
+
return retval;
|
2273
|
+
}
|
2274
|
+
|
2275
|
+
|
2276
|
+
static VALUE
|
2277
|
+
img_s_truecolor_alpha_str(rgbstr, a)
|
2278
|
+
VALUE rgbstr, a;
|
2279
|
+
{
|
2280
|
+
int c;
|
2281
|
+
VALUE ary;
|
2282
|
+
ary = hex2triplet(rgbstr);
|
2283
|
+
c = gdTrueColorAlpha(NUM2INT(*(RARRAY(ary)->ptr)),
|
2284
|
+
NUM2INT(*(RARRAY(ary)->ptr+1)),
|
2285
|
+
NUM2INT(*(RARRAY(ary)->ptr+2)),
|
2286
|
+
NUM2INT(a));
|
2287
|
+
return INT2NUM(c);
|
2288
|
+
}
|
2289
|
+
|
2290
|
+
static VALUE
|
2291
|
+
img_s_truecolor_alpha_tri(r, g, b, a)
|
2292
|
+
VALUE r, g, b, a;
|
2293
|
+
{
|
2294
|
+
int c;
|
2295
|
+
c = gdTrueColorAlpha(NUM2INT(r), NUM2INT(g), NUM2INT(b), NUM2INT(a));
|
2296
|
+
|
2297
|
+
return INT2NUM(c);
|
2298
|
+
}
|
2299
|
+
|
2300
|
+
static VALUE
|
2301
|
+
img_s_truecolor_alpha(argc, argv, img)
|
2302
|
+
int argc;
|
2303
|
+
VALUE *argv;
|
2304
|
+
VALUE img;
|
2305
|
+
{
|
2306
|
+
int i;
|
2307
|
+
VALUE rgbstr, r, g, b, a, retval;
|
2308
|
+
|
2309
|
+
if (!(argc == 2 || argc == 4))
|
2310
|
+
rb_raise(rb_eArgError, "Wrong # of arguments (2 or 4 for %d)", argc);
|
2311
|
+
|
2312
|
+
switch(TYPE(argv[0])) {
|
2313
|
+
case T_STRING:
|
2314
|
+
i = rb_scan_args(argc, argv, "20", &rgbstr, &a);
|
2315
|
+
retval = img_s_truecolor_alpha_str(rgbstr, a);
|
2316
|
+
break;
|
2317
|
+
case T_FIXNUM:
|
2318
|
+
i = rb_scan_args(argc, argv, "40", &r, &g, &b, &a);
|
2319
|
+
retval = img_s_truecolor_alpha_tri(r, g, b, a);
|
2320
|
+
break;
|
2321
|
+
default:
|
2322
|
+
rb_raise(rb_eTypeError, "String or Fixnum expected");
|
2323
|
+
break;
|
2324
|
+
}
|
2325
|
+
return retval;
|
2326
|
+
}
|
2327
|
+
|
2328
|
+
static VALUE
|
2329
|
+
img_copy_resampled(img, img2, dx, dy, sx, sy, dw, dh, sw, sh)
|
2330
|
+
VALUE img, img2, dx, dy, sx, sy, dw, dh, sw, sh;
|
2331
|
+
{
|
2332
|
+
gdImagePtr im, im2;
|
2333
|
+
|
2334
|
+
Data_Get_Struct(img, gdImage, im);
|
2335
|
+
image_req(img2);
|
2336
|
+
Data_Get_Struct(img2, gdImage, im2);
|
2337
|
+
|
2338
|
+
if (is_truecolor(im) && (!is_truecolor(im2))){
|
2339
|
+
rb_raise(rb_eRuntimeError,
|
2340
|
+
"Copying truecolor image to palette image is not permitted");
|
2341
|
+
}
|
2342
|
+
|
2343
|
+
gdImageCopyResampled(im2, im,
|
2344
|
+
NUM2INT(dx), NUM2INT(dy),
|
2345
|
+
NUM2INT(sx), NUM2INT(sy),
|
2346
|
+
NUM2INT(dw), NUM2INT(dh),
|
2347
|
+
NUM2INT(sw), NUM2INT(sh));
|
2348
|
+
return img;
|
2349
|
+
}
|
2350
|
+
|
2351
|
+
static VALUE
|
2352
|
+
img_filled_ellipse(img, cx, cy, w, h, start, end, color)
|
2353
|
+
VALUE img, cx, cy, w, h, start, end, color;
|
2354
|
+
{
|
2355
|
+
gdImagePtr im;
|
2356
|
+
Data_Get_Struct(img, gdImage, im);
|
2357
|
+
gdImageFilledEllipse(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h), NUM2INT(color));
|
2358
|
+
return img;
|
2359
|
+
}
|
2360
|
+
|
2361
|
+
static VALUE
|
2362
|
+
img_filled_arc(img, cx, cy, w, h, start, end, color, style)
|
2363
|
+
VALUE img, cx, cy, w, h, start, end, color, style;
|
2364
|
+
{
|
2365
|
+
gdImagePtr im;
|
2366
|
+
Data_Get_Struct(img, gdImage, im);
|
2367
|
+
gdImageFilledArc(im, NUM2INT(cx), NUM2INT(cy), NUM2INT(w), NUM2INT(h),
|
2368
|
+
NUM2INT(start), NUM2INT(end), NUM2INT(color), NUM2INT(style));
|
2369
|
+
return img;
|
2370
|
+
}
|
2371
|
+
|
2372
|
+
static VALUE
|
2373
|
+
img_is_truecolor_image(img)
|
2374
|
+
VALUE img;
|
2375
|
+
{
|
2376
|
+
gdImagePtr im;
|
2377
|
+
Data_Get_Struct(img, gdImage, im);
|
2378
|
+
|
2379
|
+
return is_truecolor(im);
|
2380
|
+
}
|
2381
|
+
|
2382
|
+
static VALUE
|
2383
|
+
img_is_palette_image(img)
|
2384
|
+
VALUE img;
|
2385
|
+
{
|
2386
|
+
gdImagePtr im;
|
2387
|
+
Data_Get_Struct(img, gdImage, im);
|
2388
|
+
|
2389
|
+
return is_truecolor(im) ? Qfalse : Qtrue;
|
2390
|
+
}
|
2391
|
+
|
2392
|
+
static VALUE
|
2393
|
+
img_to_palette_image(img, dither_flag, max_colors)
|
2394
|
+
VALUE img, dither_flag, max_colors;
|
2395
|
+
{
|
2396
|
+
gdImagePtr im;
|
2397
|
+
Data_Get_Struct(img, gdImage, im);
|
2398
|
+
|
2399
|
+
gdImageTrueColorToPalette(im, dither_flag, FIX2INT(max_colors));
|
2400
|
+
|
2401
|
+
return img;
|
2402
|
+
}
|
2403
|
+
|
2404
|
+
static VALUE
|
2405
|
+
img_set_thickness(img, thickness)
|
2406
|
+
VALUE img, thickness;
|
2407
|
+
{
|
2408
|
+
gdImagePtr im;
|
2409
|
+
Data_Get_Struct(img, gdImage, im);
|
2410
|
+
|
2411
|
+
gdImageSetThickness(im, FIX2INT(thickness));
|
2412
|
+
|
2413
|
+
return img;
|
2414
|
+
}
|
2415
|
+
|
2416
|
+
|
2417
|
+
|
2418
|
+
#endif /* ENABLE_GD_2_0 */
|
2419
|
+
|
2420
|
+
void
|
2421
|
+
Init_GD()
|
2422
|
+
{
|
2423
|
+
mGD = rb_define_module("GD");
|
2424
|
+
cImage = rb_define_class_under(mGD, "Image", rb_cObject);
|
2425
|
+
rb_define_singleton_method(cImage, "new", img_s_new, 2);
|
2426
|
+
rb_define_singleton_method(cImage, "newPalette", img_s_new, 2);
|
2427
|
+
rb_define_singleton_method(cImage, "newFromPng", img_from_png, 1);
|
2428
|
+
rb_define_singleton_method(cImage, "new_from_png", img_from_pngfname, 1);
|
2429
|
+
|
2430
|
+
rb_define_singleton_method(cImage, "newFromXbm", img_from_xbm, 1);
|
2431
|
+
rb_define_singleton_method(cImage, "new_from_xbm", img_from_xbmfname, 1);
|
2432
|
+
|
2433
|
+
rb_define_singleton_method(cImage, "newFromGd", img_from_gd, 1);
|
2434
|
+
rb_define_singleton_method(cImage, "new_from_gd", img_from_gdfname, 1);
|
2435
|
+
|
2436
|
+
#ifdef HAVE_GDIMAGECREATEFROMXPM
|
2437
|
+
rb_define_singleton_method(cImage, "newFromXpm", img_from_xpm, 1);
|
2438
|
+
rb_define_singleton_method(cImage, "new_from_xpm", img_from_xpmfname, 1);
|
2439
|
+
#endif /* HAVE_GDIMAGECREATEFROMXPM */
|
2440
|
+
|
2441
|
+
rb_define_singleton_method(cImage, "newFromGd2", img_from_gd2, 1);
|
2442
|
+
rb_define_singleton_method(cImage, "new_from_gd2", img_from_gd2fname, 1);
|
2443
|
+
|
2444
|
+
rb_define_singleton_method(cImage, "newFromGd2Part", img_from_gd2_part, 5);
|
2445
|
+
rb_define_singleton_method(cImage, "new_from_gd2_Part", img_from_gd2_partfname, 5);
|
2446
|
+
|
2447
|
+
#ifdef HAVE_GDIMAGECREATEFROMJPEG
|
2448
|
+
rb_define_singleton_method(cImage, "newFromJpeg", img_from_jpeg, 1);
|
2449
|
+
rb_define_singleton_method(cImage, "new_from_jpeg", img_from_jpegfname, 1);
|
2450
|
+
#endif /* HAVE_GDIMAGECREATEFROMJPEG */
|
2451
|
+
|
2452
|
+
rb_define_method(cImage, "destroy", img_destroy, 0);
|
2453
|
+
|
2454
|
+
rb_define_method(cImage, "colorAllocate", img_color_allocate, -1);
|
2455
|
+
rb_define_method(cImage, "colorDeallocate", img_color_deallocate, 1);
|
2456
|
+
rb_define_method(cImage, "colorClosest", img_color_closest, -1);
|
2457
|
+
rb_define_method(cImage, "colorClosestHWB", img_color_closestHWB, -1);
|
2458
|
+
rb_define_method(cImage, "colorExact", img_color_exact, -1);
|
2459
|
+
|
2460
|
+
#ifdef HAVE_GDIMAGECOLORRESOLVE
|
2461
|
+
rb_define_method(cImage, "colorResolve", img_color_resolve, -1);
|
2462
|
+
#endif /* HAVE_GDIMAGECOLORRESOLVE */
|
2463
|
+
|
2464
|
+
rb_define_method(cImage, "colorsTotal", img_colors_total, 0);
|
2465
|
+
rb_define_method(cImage, "getPixel", img_get_pixel, 2);
|
2466
|
+
rb_define_method(cImage, "red", img_red, 1);
|
2467
|
+
rb_define_method(cImage, "green", img_green, 1);
|
2468
|
+
rb_define_method(cImage, "blue", img_blue, 1);
|
2469
|
+
rb_define_method(cImage, "rgb", img_rgb, 1);
|
2470
|
+
rb_define_method(cImage, "transparent", img_transparent, 1);
|
2471
|
+
|
2472
|
+
rb_define_method(cImage, "setBrush", img_set_blush, 1);
|
2473
|
+
rb_define_const(mGD, "Brushed", INT2FIX(gdBrushed));
|
2474
|
+
rb_define_method(cImage, "setStyle", img_set_style, -1);
|
2475
|
+
rb_define_const(mGD, "Styled", INT2FIX(gdStyled));
|
2476
|
+
rb_define_const(mGD, "StyledBrushed", INT2FIX(gdStyledBrushed));
|
2477
|
+
rb_define_method(cImage, "setTile", img_set_tile, 1);
|
2478
|
+
rb_define_const(mGD, "Tiled", INT2FIX(gdTiled));
|
2479
|
+
rb_define_const(mGD, "Transparent", INT2FIX(gdTransparent));
|
2480
|
+
|
2481
|
+
rb_define_const(mGD, "GD2_FMT_COMPRESSED", INT2FIX(GD2_FMT_COMPRESSED));
|
2482
|
+
rb_define_const(mGD, "GD2_FMT_RAW", INT2FIX(GD2_FMT_RAW));
|
2483
|
+
|
2484
|
+
rb_define_method(cImage, "setPixel", img_set_pixel, 3);
|
2485
|
+
rb_define_method(cImage, "line", img_line, 5);
|
2486
|
+
rb_define_method(cImage, "dashedLine", img_dashed_line, 5);
|
2487
|
+
rb_define_method(cImage, "rectangle", img_rectangle, 5);
|
2488
|
+
rb_define_method(cImage, "filledRectangle", img_filled_rectangle, 5);
|
2489
|
+
rb_define_method(cImage, "polygon", img_polygon, 2);
|
2490
|
+
rb_define_method(cImage, "filledPolygon", img_filled_polygon, 2);
|
2491
|
+
rb_define_method(cImage, "arc", img_arc, 7);
|
2492
|
+
rb_define_method(cImage, "fill", img_fill, 3);
|
2493
|
+
rb_define_method(cImage, "fillToBorder", img_fill_to_border, 4);
|
2494
|
+
rb_define_method(cImage, "line", img_line, 5);
|
2495
|
+
|
2496
|
+
rb_define_method(cImage, "copy", img_copy, 7);
|
2497
|
+
rb_define_method(cImage, "copyResized", img_copy_resized, 9);
|
2498
|
+
rb_define_method(cImage, "copyMerge", img_copy_merge, 8);
|
2499
|
+
rb_define_method(cImage, "copyMergeGray", img_copy_merge_gray, 8);
|
2500
|
+
rb_define_method(cImage, "paletteCopy", img_palette_copy, 1);
|
2501
|
+
|
2502
|
+
rb_define_method(cImage, "string", img_string, 5);
|
2503
|
+
rb_define_method(cImage, "stringUp", img_string_up, 5);
|
2504
|
+
|
2505
|
+
#ifdef HAVE_GDIMAGESTRINGTTF
|
2506
|
+
rb_define_singleton_method(cImage, "stringTTF", img_s_string_ttf, 7);
|
2507
|
+
rb_define_method(cImage, "stringTTF", img_string_ttf, 7);
|
2508
|
+
#endif
|
2509
|
+
|
2510
|
+
#ifdef HAVE_GDIMAGESTRINGFT
|
2511
|
+
rb_define_singleton_method(cImage, "stringFT", img_s_string_ft, 7);
|
2512
|
+
rb_define_method(cImage, "stringFT", img_string_ft, 7);
|
2513
|
+
#endif
|
2514
|
+
|
2515
|
+
rb_define_method(cImage, "char", img_char, 5);
|
2516
|
+
rb_define_method(cImage, "charUp", img_char_up, 5);
|
2517
|
+
|
2518
|
+
rb_define_method(cImage, "interlace", img_get_interlace, 0);
|
2519
|
+
rb_define_method(cImage, "interlace=", img_set_interlace, 1);
|
2520
|
+
rb_define_method(cImage, "getTransparent", img_get_transparent, 0);
|
2521
|
+
|
2522
|
+
rb_define_method(cImage, "bounds", img_bounds, 0);
|
2523
|
+
rb_define_method(cImage, "boundsSafe", img_bounds_safe, 2);
|
2524
|
+
rb_define_method(cImage, "width", img_width, 0);
|
2525
|
+
rb_define_method(cImage, "height", img_height, 0);
|
2526
|
+
|
2527
|
+
rb_define_method(cImage, "png", img_png, 1);
|
2528
|
+
rb_define_method(cImage, "pngStr", img_png_str, 0);
|
2529
|
+
rb_define_method(cImage, "gd2", img_gd2, 3);
|
2530
|
+
rb_define_method(cImage, "gd", img_gd, 1);
|
2531
|
+
|
2532
|
+
#ifdef HAVE_GDIMAGECREATEFROMJPEG
|
2533
|
+
rb_define_method(cImage, "jpeg", img_jpeg, 2);
|
2534
|
+
rb_define_method(cImage, "jpegStr", img_jpeg_str, 1);
|
2535
|
+
#endif /* HAVE_GDIMAGECREATEFROMJPEG */
|
2536
|
+
|
2537
|
+
rb_define_method(cImage, "wbmp", img_wbmp, 2);
|
2538
|
+
|
2539
|
+
cPolygon = rb_define_class_under(mGD, "Polygon", rb_cObject);
|
2540
|
+
rb_define_singleton_method(cPolygon, "new", ply_new, 0);
|
2541
|
+
|
2542
|
+
rb_define_method(cPolygon, "addPt", ply_add_pt, 2);
|
2543
|
+
rb_define_method(cPolygon, "toPt", ply_to_pt, 2);
|
2544
|
+
rb_define_method(cPolygon, "getPt", ply_get_pt, 1);
|
2545
|
+
rb_define_method(cPolygon, "setPt", ply_set_pt, 3);
|
2546
|
+
rb_define_method(cPolygon, "deletePt", ply_delete_pt, 1);
|
2547
|
+
rb_define_method(cPolygon, "length", ply_length, 0);
|
2548
|
+
rb_define_method(cPolygon, "vertices", ply_vertices, 0);
|
2549
|
+
rb_define_method(cPolygon, "bounds", ply_bounds, 0);
|
2550
|
+
rb_define_method(cPolygon, "offset", ply_offset, 2);
|
2551
|
+
rb_define_method(cPolygon, "map", ply_map, -1);
|
2552
|
+
rb_define_method(cPolygon, "transform", ply_transform, 6);
|
2553
|
+
rb_define_method(cPolygon, "scale", ply_scale, 2);
|
2554
|
+
|
2555
|
+
cFont = rb_define_class_under(mGD, "Font", rb_cObject);
|
2556
|
+
rb_define_singleton_method(cFont, "new", fnt_s_new, 1);
|
2557
|
+
|
2558
|
+
rb_define_const(cFont, "GiantFont", fnt_new("Giant"));
|
2559
|
+
rb_define_const(cFont, "SmallFont", fnt_new("Small"));
|
2560
|
+
rb_define_const(cFont, "LargeFont", fnt_new("Large"));
|
2561
|
+
rb_define_const(cFont, "MediumFont", fnt_new("Medium"));
|
2562
|
+
rb_define_const(cFont, "MediumBoldFont", fnt_new("Medium"));
|
2563
|
+
rb_define_const(cFont, "TinyFont", fnt_new("Tiny"));
|
2564
|
+
|
2565
|
+
rb_define_method(cFont, "nchars", fnt_nchars, 0);
|
2566
|
+
rb_define_method(cFont, "offset", fnt_offset, 0);
|
2567
|
+
rb_define_method(cFont, "width", fnt_width, 0);
|
2568
|
+
rb_define_method(cFont, "height", fnt_height, 0);
|
2569
|
+
|
2570
|
+
#ifdef ENABLE_GD_2_0
|
2571
|
+
|
2572
|
+
rb_define_singleton_method(cImage, "newTrueColor", img_s_new_tc, 2);
|
2573
|
+
rb_define_method(cImage, "colorAllocateAlpha", img_color_allocate_alpha, -1);
|
2574
|
+
rb_define_method(cImage, "colorResolveAlpha", img_color_resolve_alpha, -1);
|
2575
|
+
rb_define_method(cImage, "colorClosestAlpha", img_color_closest_alpha, -1);
|
2576
|
+
rb_define_method(cImage, "colorExactAlpha", img_color_exact_alpha, -1);
|
2577
|
+
rb_define_method(cImage, "alphaBlending=", img_alpha_blending, 1);
|
2578
|
+
rb_define_method(cImage, "alpha", img_alpha, 1);
|
2579
|
+
|
2580
|
+
rb_define_singleton_method(cImage, "trueColor", img_s_truecolor, -1);
|
2581
|
+
rb_define_singleton_method(cImage, "trueColorAlpha", img_s_truecolor_alpha, -1);
|
2582
|
+
|
2583
|
+
rb_define_method(cImage, "copyResampled", img_copy_resampled, 9);
|
2584
|
+
rb_define_method(cImage, "filledEllipse", img_filled_ellipse, 7);
|
2585
|
+
rb_define_method(cImage, "filledArc", img_filled_arc, 8);
|
2586
|
+
rb_define_method(cImage, "is_trueColor?", img_is_truecolor_image, 0);
|
2587
|
+
rb_define_method(cImage, "is_palette?", img_is_palette_image, 0);
|
2588
|
+
rb_define_method(cImage, "to_paletteImage", img_to_palette_image, 2);
|
2589
|
+
rb_define_method(cImage, "thickness=", img_set_thickness, 1);
|
2590
|
+
|
2591
|
+
rb_define_const(mGD, "AlphaTransparent", INT2FIX(gdAlphaTransparent));
|
2592
|
+
rb_define_const(mGD, "AlphaOpaque", INT2FIX(gdAlphaOpaque));
|
2593
|
+
|
2594
|
+
rb_define_const(mGD, "Arc", INT2FIX(gdArc));
|
2595
|
+
rb_define_const(mGD, "Chord", INT2FIX(gdChord));
|
2596
|
+
rb_define_const(mGD, "Pie", INT2FIX(gdPie));
|
2597
|
+
rb_define_const(mGD, "NoFill", INT2FIX(gdNoFill));
|
2598
|
+
rb_define_const(mGD, "Edged", INT2FIX(gdEdged));
|
2599
|
+
|
2600
|
+
#endif /* ENABLE_GD_2_0 */
|
2601
|
+
|
2602
|
+
}
|