gmagick 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +38 -0
- data/ext/gmagick/depend +1 -0
- data/ext/gmagick/extconf.rb +13 -0
- data/ext/gmagick/gmagick.h +112 -0
- data/ext/gmagick/gmdrawing.c +345 -0
- data/ext/gmagick/gmimage.c +346 -0
- data/ext/gmagick/gminit.c +97 -0
- data/ext/gmagick/gmpixel.c +82 -0
- data/ext/gmagick/gmutil.c +62 -0
- data/gmagick.gemspec +26 -0
- data/lib/gmagick.rb +6 -0
- data/lib/gmagick/version.rb +3 -0
- data/spec/files/src/dice.png +0 -0
- data/spec/files/src/earth.gif +0 -0
- data/spec/files/src/flower.jpg +0 -0
- data/spec/gmagick_spec.rb +496 -0
- data/spec/spec_helper.rb +40 -0
- metadata +115 -0
@@ -0,0 +1,346 @@
|
|
1
|
+
#include "gmagick.h"
|
2
|
+
|
3
|
+
void
|
4
|
+
gmi_free(GmImage *ptr)
|
5
|
+
{
|
6
|
+
if (ptr != (GmImage *)NULL) {
|
7
|
+
if (ptr->wand != (MagickWand *)NULL) {
|
8
|
+
DestroyMagickWand(ptr->wand);
|
9
|
+
}
|
10
|
+
ruby_xfree(ptr);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
gmi_alloc(VALUE klass) {
|
16
|
+
GmImage *ptr = ALLOC(GmImage);
|
17
|
+
ptr->wand = (MagickWand *)NULL;
|
18
|
+
return Data_Wrap_Struct(klass, 0, gmi_free, ptr);
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Document-method: new
|
23
|
+
*
|
24
|
+
* call-seq:
|
25
|
+
* Gmagick::Image.new -> image
|
26
|
+
* Gmagick::Image.new(path) -> image
|
27
|
+
*
|
28
|
+
* Create a GraphicsMagick Object
|
29
|
+
*
|
30
|
+
* [+path+]
|
31
|
+
* image file path
|
32
|
+
*
|
33
|
+
* Examples:
|
34
|
+
*
|
35
|
+
* # Make image object
|
36
|
+
* Gmagick::Image.new
|
37
|
+
*
|
38
|
+
* # Make image object with path
|
39
|
+
* Gmagick::Image.new(path)
|
40
|
+
*
|
41
|
+
*/
|
42
|
+
VALUE
|
43
|
+
gmi_initialize(int argc, VALUE *argv, VALUE self) {
|
44
|
+
if (argc > 1) {
|
45
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
46
|
+
}
|
47
|
+
volatile GmImage *gmImage;
|
48
|
+
Data_Get_Struct(self, GmImage, gmImage);
|
49
|
+
gmImage->wand = NewMagickWand();
|
50
|
+
if (argc > 0) {
|
51
|
+
gmi_read_image(self, argv[0]);
|
52
|
+
}
|
53
|
+
return Qnil;
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE
|
57
|
+
gmi_read_image(VALUE self, VALUE path_arg) {
|
58
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
59
|
+
char *path = StringValuePtr(path_arg);
|
60
|
+
if (NULL == wand) {
|
61
|
+
puts("null");
|
62
|
+
}
|
63
|
+
MagickPassFail status = MagickReadImage(wand, path);
|
64
|
+
gum_check_image_exception(wand, status);
|
65
|
+
MagickSetImageFilename(wand, path);
|
66
|
+
return Qnil;
|
67
|
+
}
|
68
|
+
|
69
|
+
VALUE
|
70
|
+
gmi_write_image(int argc, VALUE *argv, VALUE self) {
|
71
|
+
if (argc > 1) {
|
72
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
73
|
+
}
|
74
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
75
|
+
char* path;
|
76
|
+
if (argc > 0) {
|
77
|
+
path = StringValuePtr(argv[0]);
|
78
|
+
} else {
|
79
|
+
path = MagickGetImageFilename(wand);
|
80
|
+
if (NULL == path) {
|
81
|
+
rb_raise(rb_eRuntimeError, "filename never setted");
|
82
|
+
}
|
83
|
+
}
|
84
|
+
MagickPassFail status = MagickWriteImage(wand, path);
|
85
|
+
gum_check_image_exception(wand, status);
|
86
|
+
return Qnil;
|
87
|
+
}
|
88
|
+
|
89
|
+
VALUE
|
90
|
+
gmi_get_width(VALUE self) {
|
91
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
92
|
+
return LONG2NUM(MagickGetImageWidth(wand));
|
93
|
+
}
|
94
|
+
|
95
|
+
VALUE
|
96
|
+
gmi_get_height(VALUE self) {
|
97
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
98
|
+
return LONG2NUM(MagickGetImageHeight(wand));
|
99
|
+
}
|
100
|
+
|
101
|
+
VALUE
|
102
|
+
gmi_get_format(VALUE self) {
|
103
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
104
|
+
return rb_str_new2(MagickGetImageFormat(wand));
|
105
|
+
}
|
106
|
+
|
107
|
+
VALUE
|
108
|
+
gmi_get_depth(VALUE self) {
|
109
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
110
|
+
return LONG2NUM(MagickGetImageDepth(wand));
|
111
|
+
}
|
112
|
+
|
113
|
+
VALUE
|
114
|
+
gmi_get_colors(VALUE self) {
|
115
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
116
|
+
return LONG2NUM(MagickGetImageColors(wand));
|
117
|
+
}
|
118
|
+
|
119
|
+
VALUE
|
120
|
+
gmi_get_resolution(VALUE self) {
|
121
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
122
|
+
double x;
|
123
|
+
double y;
|
124
|
+
MagickPassFail status = MagickGetImageResolution(wand, &x, &y);
|
125
|
+
gum_check_image_exception(wand, status);
|
126
|
+
VALUE ary = rb_ary_new2(2);
|
127
|
+
rb_ary_push(ary, DBL2NUM(x));
|
128
|
+
rb_ary_push(ary, DBL2NUM(y));
|
129
|
+
return ary;
|
130
|
+
}
|
131
|
+
|
132
|
+
VALUE
|
133
|
+
gmi_get_number_images(VALUE self) {
|
134
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
135
|
+
return LONG2NUM(MagickGetNumberImages(wand));
|
136
|
+
}
|
137
|
+
|
138
|
+
VALUE
|
139
|
+
gmi_read_image_blob(VALUE self, VALUE blob_arg) {
|
140
|
+
MagickWand *wand = gmu_get_image_wand(self);
|
141
|
+
unsigned char *blob;
|
142
|
+
long length;
|
143
|
+
Image* image;
|
144
|
+
|
145
|
+
blob = (unsigned char *)gmu_str2cstr(blob_arg, &length);
|
146
|
+
MagickPassFail status = MagickReadImageBlob(wand, blob, length);
|
147
|
+
gum_check_image_exception(wand, status);
|
148
|
+
return Qnil;
|
149
|
+
}
|
150
|
+
|
151
|
+
VALUE
|
152
|
+
gmi_write_image_blob(VALUE self) {
|
153
|
+
MagickWand *image = gmu_get_image_wand(self);
|
154
|
+
unsigned char *blob;
|
155
|
+
size_t length;
|
156
|
+
VALUE result;
|
157
|
+
|
158
|
+
blob = MagickWriteImageBlob(image, &length);
|
159
|
+
result = rb_str_new((char *)blob, (long)length);
|
160
|
+
MagickRelinquishMemory(blob);
|
161
|
+
return result;
|
162
|
+
}
|
163
|
+
|
164
|
+
VALUE
|
165
|
+
gmi_resize(int argc, VALUE *argv, VALUE self) {
|
166
|
+
if (argc < 2 || argc > 4) {
|
167
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 4)", argc);
|
168
|
+
}
|
169
|
+
long width = NUM2LONG(argv[0]);
|
170
|
+
long height = NUM2LONG(argv[1]);
|
171
|
+
int filter = argc > 2 ? NUM2INT(argv[2]) : 0;
|
172
|
+
double blur = argc > 3 ? NUM2DBL(argv[3]) : 1.0;
|
173
|
+
|
174
|
+
MagickWand *image = gmu_get_image_wand(self);
|
175
|
+
MagickPassFail status = MagickResizeImage(image, width, height, filter, blur);
|
176
|
+
gum_check_image_exception(image, status);
|
177
|
+
return Qnil;
|
178
|
+
}
|
179
|
+
|
180
|
+
VALUE
|
181
|
+
gmi_rotate(VALUE self, VALUE pixel_arg, VALUE degree_arg) {
|
182
|
+
MagickWand *image = gmu_get_image_wand(self);
|
183
|
+
PixelWand *pixel = gmu_get_pixel_string_or_pixel(pixel_arg);
|
184
|
+
double degree = NUM2DBL(degree_arg);
|
185
|
+
MagickPassFail status = MagickRotateImage(image, pixel, degree);
|
186
|
+
gmu_clear_pixel_string_or_pixel(pixel_arg, pixel);
|
187
|
+
gum_check_image_exception(image, status);
|
188
|
+
return Qnil;
|
189
|
+
}
|
190
|
+
|
191
|
+
VALUE
|
192
|
+
gmi_draw(VALUE self, VALUE drawing_arg)
|
193
|
+
{
|
194
|
+
MagickWand *image = gmu_get_image_wand(self);
|
195
|
+
DrawingWand *drawing = gmu_get_drawing_wand(drawing_arg);
|
196
|
+
MagickPassFail status = MagickDrawImage(image, drawing);
|
197
|
+
gum_check_image_exception(image, status);
|
198
|
+
return Qnil;
|
199
|
+
}
|
200
|
+
|
201
|
+
VALUE
|
202
|
+
gmi_resample(int argc, VALUE *argv, VALUE self) {
|
203
|
+
if (argc < 2 || argc > 4) {
|
204
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 4)", argc);
|
205
|
+
}
|
206
|
+
long x = NUM2LONG(argv[0]);
|
207
|
+
long y = NUM2LONG(argv[1]);
|
208
|
+
int filter = argc > 2 ? NUM2INT(argv[2]) : 0;
|
209
|
+
double blur = argc > 3 ? NUM2DBL(argv[3]) : 1.0;
|
210
|
+
|
211
|
+
MagickWand *image = gmu_get_image_wand(self);
|
212
|
+
MagickPassFail status = MagickResampleImage(image, x, y, filter, blur);
|
213
|
+
gum_check_image_exception(image, status);
|
214
|
+
return Qnil;
|
215
|
+
}
|
216
|
+
|
217
|
+
VALUE
|
218
|
+
gmi_flip(VALUE self) {
|
219
|
+
MagickWand *image = gmu_get_image_wand(self);
|
220
|
+
MagickPassFail status = MagickFlipImage(image);
|
221
|
+
gum_check_image_exception(image, status);
|
222
|
+
return Qnil;
|
223
|
+
}
|
224
|
+
|
225
|
+
VALUE
|
226
|
+
gmi_flop(VALUE self) {
|
227
|
+
MagickWand *image = gmu_get_image_wand(self);
|
228
|
+
MagickPassFail status = MagickFlopImage(image);
|
229
|
+
gum_check_image_exception(image, status);
|
230
|
+
return Qnil;
|
231
|
+
}
|
232
|
+
|
233
|
+
VALUE
|
234
|
+
gmi_crop(VALUE self, VALUE width_arg, VALUE height_arg, VALUE x_arg, VALUE y_arg) {
|
235
|
+
MagickWand *image = gmu_get_image_wand(self);
|
236
|
+
unsigned long width = NUM2LONG(width_arg);
|
237
|
+
unsigned long height = NUM2LONG(height_arg);
|
238
|
+
long x = NUM2LONG(x_arg);
|
239
|
+
long y = NUM2LONG(y_arg);
|
240
|
+
MagickPassFail status = MagickCropImage(image, width, height, x, y);
|
241
|
+
gum_check_image_exception(image, status);
|
242
|
+
return Qnil;
|
243
|
+
}
|
244
|
+
|
245
|
+
VALUE
|
246
|
+
gmi_set_format(VALUE self, VALUE format_arg) {
|
247
|
+
MagickWand *image = gmu_get_image_wand(self);
|
248
|
+
char *format = StringValuePtr(format_arg);
|
249
|
+
MagickPassFail status = MagickSetImageFormat(image, format);
|
250
|
+
gum_check_image_exception(image, status);
|
251
|
+
return Qnil;
|
252
|
+
}
|
253
|
+
|
254
|
+
VALUE
|
255
|
+
gmi_border(VALUE self, VALUE pixel_arg, VALUE width_arg, VALUE height_arg) {
|
256
|
+
MagickWand *image = gmu_get_image_wand(self);
|
257
|
+
PixelWand *pixel = gmu_get_pixel_string_or_pixel(pixel_arg);
|
258
|
+
unsigned long width = NUM2LONG(width_arg);
|
259
|
+
unsigned long height = NUM2LONG(height_arg);
|
260
|
+
MagickPassFail status = MagickBorderImage(image, pixel, width, height);
|
261
|
+
gmu_clear_pixel_string_or_pixel(pixel_arg, pixel);
|
262
|
+
gum_check_image_exception(image, status);
|
263
|
+
return Qnil;
|
264
|
+
}
|
265
|
+
|
266
|
+
VALUE
|
267
|
+
gmi_frame(VALUE self, VALUE pixel_arg, VALUE width_arg, VALUE height_arg, VALUE inner_arg, VALUE outer_arg) {
|
268
|
+
MagickWand *image = gmu_get_image_wand(self);
|
269
|
+
PixelWand *pixel = gmu_get_pixel_string_or_pixel(pixel_arg);
|
270
|
+
unsigned long width = NUM2LONG(width_arg);
|
271
|
+
unsigned long height = NUM2LONG(height_arg);
|
272
|
+
long inner = NUM2LONG(inner_arg);
|
273
|
+
long outer = NUM2LONG(outer_arg);
|
274
|
+
MagickPassFail status = MagickFrameImage(image, pixel, width, height, inner, outer);
|
275
|
+
gmu_clear_pixel_string_or_pixel(pixel_arg, pixel);
|
276
|
+
gum_check_image_exception(image, status);
|
277
|
+
return Qnil;
|
278
|
+
}
|
279
|
+
|
280
|
+
VALUE
|
281
|
+
gmi_blur(VALUE self, VALUE radius_arg, VALUE sigma_arg) {
|
282
|
+
MagickWand *image = gmu_get_image_wand(self);
|
283
|
+
double radius = NUM2DBL(radius_arg);
|
284
|
+
double sigma = NUM2DBL(sigma_arg);
|
285
|
+
MagickPassFail status = MagickBlurImage(image, radius, sigma);
|
286
|
+
gum_check_image_exception(image, status);
|
287
|
+
return Qnil;
|
288
|
+
}
|
289
|
+
|
290
|
+
VALUE
|
291
|
+
gmi_swirl(VALUE self, VALUE degree_arg) {
|
292
|
+
MagickWand *image = gmu_get_image_wand(self);
|
293
|
+
double degree = NUM2DBL(degree_arg);
|
294
|
+
MagickPassFail status = MagickSwirlImage(image, degree);
|
295
|
+
gum_check_image_exception(image, status);
|
296
|
+
return Qnil;
|
297
|
+
}
|
298
|
+
|
299
|
+
VALUE
|
300
|
+
gmi_charcoal(VALUE self, VALUE radius_arg, VALUE sigma_arg) {
|
301
|
+
MagickWand *image = gmu_get_image_wand(self);
|
302
|
+
double radius = NUM2DBL(radius_arg);
|
303
|
+
double sigma = NUM2DBL(sigma_arg);
|
304
|
+
MagickPassFail status = MagickCharcoalImage(image, radius, sigma);
|
305
|
+
gum_check_image_exception(image, status);
|
306
|
+
return Qnil;
|
307
|
+
}
|
308
|
+
|
309
|
+
VALUE
|
310
|
+
gmi_oil_paint(VALUE self, VALUE radius_arg) {
|
311
|
+
MagickWand *image = gmu_get_image_wand(self);
|
312
|
+
double radius = NUM2DBL(radius_arg);
|
313
|
+
MagickPassFail status = MagickOilPaintImage(image, radius);
|
314
|
+
gum_check_image_exception(image, status);
|
315
|
+
return Qnil;
|
316
|
+
}
|
317
|
+
|
318
|
+
VALUE
|
319
|
+
gmi_cycle_colormap(VALUE self, VALUE displace_arg) {
|
320
|
+
MagickWand *image = gmu_get_image_wand(self);
|
321
|
+
long displace = NUM2LONG(displace_arg);
|
322
|
+
MagickPassFail status = MagickCycleColormapImage(image, displace);
|
323
|
+
gum_check_image_exception(image, status);
|
324
|
+
return Qnil;
|
325
|
+
}
|
326
|
+
|
327
|
+
VALUE
|
328
|
+
gmi_solarize(VALUE self, VALUE threshold_arg) {
|
329
|
+
MagickWand *image = gmu_get_image_wand(self);
|
330
|
+
double threshold = NUM2DBL(threshold_arg);
|
331
|
+
MagickPassFail status = MagickSolarizeImage(image, threshold);
|
332
|
+
gum_check_image_exception(image, status);
|
333
|
+
return Qnil;
|
334
|
+
}
|
335
|
+
|
336
|
+
VALUE
|
337
|
+
gmi_shear(VALUE self, VALUE pixel_arg, VALUE x_arg, VALUE y_arg) {
|
338
|
+
MagickWand *image = gmu_get_image_wand(self);
|
339
|
+
PixelWand *pixel = gmu_get_pixel_string_or_pixel(pixel_arg);
|
340
|
+
double x = NUM2DBL(x_arg);
|
341
|
+
double y = NUM2DBL(y_arg);
|
342
|
+
MagickPassFail status = MagickShearImage(image, pixel, x, y);
|
343
|
+
gmu_clear_pixel_string_or_pixel(pixel_arg, pixel);
|
344
|
+
gum_check_image_exception(image, status);
|
345
|
+
return Qnil;
|
346
|
+
}
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#include "gmagick.h"
|
2
|
+
|
3
|
+
VALUE Module_Gmagick;
|
4
|
+
VALUE Class_Image;
|
5
|
+
VALUE Class_Pixel;
|
6
|
+
VALUE Class_Drawing;
|
7
|
+
|
8
|
+
ID id_new;
|
9
|
+
|
10
|
+
void
|
11
|
+
Init_gmagickn(){
|
12
|
+
InitializeMagick(NULL);
|
13
|
+
|
14
|
+
Module_Gmagick = rb_define_module("Gmagick");
|
15
|
+
Class_Image = rb_define_class_under(Module_Gmagick, "Image", rb_cObject);
|
16
|
+
rb_define_alloc_func(Class_Image, gmi_alloc);
|
17
|
+
rb_define_private_method(Class_Image, "initialize", gmi_initialize, -1);
|
18
|
+
rb_define_method(Class_Image, "read", gmi_read_image, 1);
|
19
|
+
rb_define_method(Class_Image, "write", gmi_write_image, -1);
|
20
|
+
rb_define_method(Class_Image, "width", gmi_get_width, 0);
|
21
|
+
rb_define_method(Class_Image, "height", gmi_get_height, 0);
|
22
|
+
rb_define_method(Class_Image, "format", gmi_get_format, 0);
|
23
|
+
rb_define_method(Class_Image, "depth", gmi_get_depth, 0);
|
24
|
+
rb_define_method(Class_Image, "colors", gmi_get_colors, 0);
|
25
|
+
rb_define_method(Class_Image, "resolution", gmi_get_resolution, 0);
|
26
|
+
rb_define_method(Class_Image, "count", gmi_get_number_images, 0);
|
27
|
+
rb_define_method(Class_Image, "read_blob", gmi_read_image_blob, 1);
|
28
|
+
rb_define_method(Class_Image, "write_blob", gmi_write_image_blob, 0);
|
29
|
+
rb_define_method(Class_Image, "resize", gmi_resize, -1);
|
30
|
+
rb_define_method(Class_Image, "rotate", gmi_rotate, 2);
|
31
|
+
rb_define_method(Class_Image, "draw", gmi_draw, 1);
|
32
|
+
rb_define_method(Class_Image, "resample", gmi_resample, -1);
|
33
|
+
rb_define_method(Class_Image, "flip", gmi_flip, 0);
|
34
|
+
rb_define_method(Class_Image, "flop", gmi_flop, 0);
|
35
|
+
rb_define_method(Class_Image, "crop", gmi_crop, 4);
|
36
|
+
rb_define_method(Class_Image, "format=", gmi_set_format, 1);
|
37
|
+
rb_define_method(Class_Image, "border", gmi_border, 3);
|
38
|
+
rb_define_method(Class_Image, "frame", gmi_frame, 5);
|
39
|
+
rb_define_method(Class_Image, "blur", gmi_blur, 2);
|
40
|
+
rb_define_method(Class_Image, "swirl", gmi_swirl, 1);
|
41
|
+
rb_define_method(Class_Image, "charcoal", gmi_charcoal, 2);
|
42
|
+
rb_define_method(Class_Image, "oil_paint", gmi_oil_paint, 1);
|
43
|
+
rb_define_method(Class_Image, "cycle_colormap", gmi_cycle_colormap, 1);
|
44
|
+
rb_define_method(Class_Image, "solarize", gmi_solarize, 1);
|
45
|
+
rb_define_method(Class_Image, "shear", gmi_shear, 3);
|
46
|
+
|
47
|
+
Class_Pixel = rb_define_class_under(Module_Gmagick, "Pixel", rb_cObject);
|
48
|
+
rb_define_alloc_func(Class_Pixel, gmp_alloc);
|
49
|
+
rb_define_private_method(Class_Pixel, "initialize", gmp_initialize, -1);
|
50
|
+
rb_define_method(Class_Pixel, "color=", gmp_set_color, 1);
|
51
|
+
rb_define_method(Class_Pixel, "color", gmp_get_color, 0);
|
52
|
+
rb_define_method(Class_Pixel, "color_count=", gmp_set_color_count, 1);
|
53
|
+
rb_define_method(Class_Pixel, "color_count", gmp_get_color_count, 0);
|
54
|
+
|
55
|
+
Class_Drawing = rb_define_class_under(Module_Gmagick, "Drawing", rb_cObject);
|
56
|
+
rb_define_alloc_func(Class_Drawing, gmd_alloc);
|
57
|
+
rb_define_private_method(Class_Drawing, "initialize", gmd_initialize, 0);
|
58
|
+
rb_define_method(Class_Drawing, "annotation", gmd_annotation, 3);
|
59
|
+
rb_define_method(Class_Drawing, "arc", gmd_arc, 6);
|
60
|
+
rb_define_method(Class_Drawing, "circle", gmd_circle, 4);
|
61
|
+
rb_define_method(Class_Drawing, "ellipse", gmd_ellipse, -1);
|
62
|
+
rb_define_method(Class_Drawing, "line", gmd_line, 4);
|
63
|
+
rb_define_method(Class_Drawing, "point", gmd_point, 2);
|
64
|
+
rb_define_method(Class_Drawing, "rectangle", gmd_rectangle, 4);
|
65
|
+
rb_define_method(Class_Drawing, "rotate", gmd_rotate, 1);
|
66
|
+
rb_define_method(Class_Drawing, "scale", gmd_scale, 2);
|
67
|
+
rb_define_method(Class_Drawing, "fill_color=", gmd_set_fill_color, 1);
|
68
|
+
rb_define_method(Class_Drawing, "fill_color", gmd_get_fill_color, 0);
|
69
|
+
rb_define_method(Class_Drawing, "fill_opacity=", gmd_set_fill_opacity, 1);
|
70
|
+
rb_define_method(Class_Drawing, "fill_opacity", gmd_get_fill_opacity, 0);
|
71
|
+
rb_define_method(Class_Drawing, "font=", gmd_set_font, 1);
|
72
|
+
rb_define_method(Class_Drawing, "font", gmd_get_font, 0);
|
73
|
+
rb_define_method(Class_Drawing, "font_family=", gmd_set_font_family, 1);
|
74
|
+
rb_define_method(Class_Drawing, "font_family", gmd_get_font_family, 0);
|
75
|
+
rb_define_method(Class_Drawing, "font_size=", gmd_set_font_size, 1);
|
76
|
+
rb_define_method(Class_Drawing, "font_size", gmd_get_font_size, 0);
|
77
|
+
rb_define_method(Class_Drawing, "font_stretch=", gmd_set_font_stretch, 1);
|
78
|
+
rb_define_method(Class_Drawing, "font_stretch", gmd_get_font_stretch, 0);
|
79
|
+
rb_define_method(Class_Drawing, "font_style=", gmd_set_font_style, 1);
|
80
|
+
rb_define_method(Class_Drawing, "font_style", gmd_get_font_style, 0);
|
81
|
+
rb_define_method(Class_Drawing, "font_weight=", gmd_set_font_weight, 1);
|
82
|
+
rb_define_method(Class_Drawing, "font_weight", gmd_get_font_weight, 0);
|
83
|
+
rb_define_method(Class_Drawing, "round_rectangle", gmd_round_rectangle, 6);
|
84
|
+
rb_define_method(Class_Drawing, "stroke_color=", gmd_set_stroke_color, 1);
|
85
|
+
rb_define_method(Class_Drawing, "stroke_color", gmd_get_stroke_color, 0);
|
86
|
+
rb_define_method(Class_Drawing, "stroke_opacity=", gmd_set_stroke_opacity, 1);
|
87
|
+
rb_define_method(Class_Drawing, "stroke_opacity", gmd_get_stroke_opacity, 0);
|
88
|
+
rb_define_method(Class_Drawing, "stroke_width=", gmd_set_stroke_width, 1);
|
89
|
+
rb_define_method(Class_Drawing, "stroke_width", gmd_get_stroke_width, 0);
|
90
|
+
rb_define_method(Class_Drawing, "text_decoration=", gmd_set_text_decoration, 1);
|
91
|
+
rb_define_method(Class_Drawing, "text_decoration", gmd_get_text_decoration, 0);
|
92
|
+
rb_define_method(Class_Drawing, "text_encoding=", gmd_set_text_encoding, 1);
|
93
|
+
rb_define_method(Class_Drawing, "text_encoding", gmd_get_text_encoding, 0);
|
94
|
+
|
95
|
+
|
96
|
+
id_new = rb_intern("new");
|
97
|
+
}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#include "gmagick.h"
|
2
|
+
|
3
|
+
void
|
4
|
+
gmp_free(GmPixel *ptr)
|
5
|
+
{
|
6
|
+
if (ptr != (GmPixel *)NULL) {
|
7
|
+
if (ptr->wand != (PixelWand *)NULL) {
|
8
|
+
DestroyPixelWand(ptr->wand);
|
9
|
+
}
|
10
|
+
ruby_xfree(ptr);
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
VALUE
|
15
|
+
gmp_alloc(VALUE klass) {
|
16
|
+
GmPixel *ptr = ALLOC(GmPixel);
|
17
|
+
ptr->wand = (PixelWand *)NULL;
|
18
|
+
return Data_Wrap_Struct(klass, 0, gmp_free, ptr);
|
19
|
+
}
|
20
|
+
|
21
|
+
/*
|
22
|
+
* Document-method: new
|
23
|
+
*
|
24
|
+
* call-seq:
|
25
|
+
* Gmagick::Pixel.new -> pixel
|
26
|
+
* Gmagick::Pixel.new(color) -> pixel
|
27
|
+
*
|
28
|
+
* Create a GraphicsMagick Object
|
29
|
+
*
|
30
|
+
* [+color+]
|
31
|
+
* initialize color
|
32
|
+
*
|
33
|
+
* Examples:
|
34
|
+
*
|
35
|
+
* # Make pixel object
|
36
|
+
* Gmagick::Pixel.new
|
37
|
+
*
|
38
|
+
* # Make pixel object with color
|
39
|
+
* Gmagick::Pixel.new("#000000")
|
40
|
+
*
|
41
|
+
*/
|
42
|
+
VALUE
|
43
|
+
gmp_initialize(int argc, VALUE *argv, VALUE self) {
|
44
|
+
volatile GmPixel *ptr;
|
45
|
+
Data_Get_Struct(self, GmPixel, ptr);
|
46
|
+
ptr->wand = NewPixelWand();
|
47
|
+
if (argc > 1) {
|
48
|
+
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc);
|
49
|
+
}
|
50
|
+
if (argc > 0) {
|
51
|
+
gmp_set_color(self, argv[0]);
|
52
|
+
}
|
53
|
+
return Qnil;
|
54
|
+
}
|
55
|
+
|
56
|
+
VALUE
|
57
|
+
gmp_set_color(VALUE self, VALUE color_arg) {
|
58
|
+
char *color = StringValuePtr(color_arg);
|
59
|
+
PixelWand *pixel = gmu_get_pixel_wand(self);
|
60
|
+
PixelSetColor(pixel, color);
|
61
|
+
return Qnil;
|
62
|
+
}
|
63
|
+
|
64
|
+
VALUE
|
65
|
+
gmp_get_color(VALUE self) {
|
66
|
+
PixelWand *pixel = gmu_get_pixel_wand(self);
|
67
|
+
return rb_str_new2(PixelGetColorAsString(pixel));
|
68
|
+
}
|
69
|
+
|
70
|
+
VALUE
|
71
|
+
gmp_set_color_count(VALUE self, VALUE color_count_arg) {
|
72
|
+
unsigned long color_count = NUM2LONG(color_count_arg);
|
73
|
+
PixelWand *pixel = gmu_get_pixel_wand(self);
|
74
|
+
PixelSetColorCount(pixel, color_count);
|
75
|
+
return Qnil;
|
76
|
+
}
|
77
|
+
|
78
|
+
VALUE
|
79
|
+
gmp_get_color_count(VALUE self) {
|
80
|
+
PixelWand *pixel = gmu_get_pixel_wand(self);
|
81
|
+
return LONG2NUM(PixelGetColorCount(pixel));
|
82
|
+
}
|