ruby-libgd 0.3.0 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 310bd931469060390ec5d475ce151934d42afb9e51e3d9ddaa59075c8a4f88db
4
- data.tar.gz: 4d5dcef0cb4eb3556f4aa88733fd541539b49e489b4820469425270662b06b4c
3
+ metadata.gz: d318d5d92026ec9ece18021d3cecef81707d64bfe134856d73f5ee007872ac89
4
+ data.tar.gz: 11b4e17352cd1ff477478297b2a3004f13760dc001b8ac04ee6b6a082feac04e
5
5
  SHA512:
6
- metadata.gz: c3bb2ad496f6764c13c00d25f0e4d30b8b388915f45d16421ae85982148bd2ab0ee6e3abd5e5eba16e155fbeb2d1cd74e71fa509a733b49543f8ba0702a1eea8
7
- data.tar.gz: 1cabca6431ea0b7db31f0341ff63e68420c70b137a3b902b09f7b0bcf86a98d9ce71c3e7e4de67a85d07af47d2c1213e688665333657bc30b0d1ab5c64a55345
6
+ metadata.gz: 4a6719d7ddcc0c9cda1ec061e57a021c5ea729003764e62e19c327ddea77a3160d1f36f6953e8d8c54d6d9e946333347c5093668ea6670a65af468aeb61a3f92
7
+ data.tar.gz: 0c4ba9ea4e0b4faed88aefcebe0164edfc4ab9722113914eeecd024863bedb187c6c4f2936a6822af0ad32b6f41b7d31fcdd781f35fdb1d3114888d8940c1e35
data/ext/gd/arc.o CHANGED
Binary file
data/ext/gd/blit.c CHANGED
@@ -1,10 +1,7 @@
1
1
  /**
2
- - [ ] imagecopy — Copy part of an image
3
2
  - [ ] imagecopymerge — Copy and merge part of an image
4
3
  - [ ] imagecopymergegray — Copy and merge part of an image with gray scale
5
- - [ ] imagecopyresampled — Copy and resize part of an image with resampling
6
- - [ ] imagecopyresized — Copy and resize part of an image
7
- */
4
+ */
8
5
  #include "ruby_gd.h"
9
6
 
10
7
  static VALUE gd_image_copy_merge(
data/ext/gd/blit.o CHANGED
Binary file
data/ext/gd/circle.o CHANGED
Binary file
data/ext/gd/color.o CHANGED
Binary file
data/ext/gd/draw_line.o CHANGED
Binary file
data/ext/gd/ellipse.o CHANGED
Binary file
data/ext/gd/encode.o CHANGED
Binary file
data/ext/gd/fill.o CHANGED
Binary file
data/ext/gd/filter.c CHANGED
@@ -275,18 +275,14 @@ static VALUE gd_image_filter(int argc, VALUE *argv, VALUE self) {
275
275
  }
276
276
  }
277
277
  else if (strcmp(name, "box_blur") == 0) {
278
-
279
278
  if (!gdImageConvolution(wrap->img, kernel_box_blur, 9.0, 0.0)) {
280
279
  rb_raise(rb_eRuntimeError, "box_blur convolution failed");
281
280
  }
282
-
283
281
  }
284
282
  else if (strcmp(name, "gaussian_kernel") == 0) {
285
-
286
283
  if (!gdImageConvolution(wrap->img, kernel_gaussian, 16.0, 0.0)) {
287
284
  rb_raise(rb_eRuntimeError, "gaussian_kernel convolution failed");
288
285
  }
289
-
290
286
  }
291
287
  else if (strcmp(name, "emboss2") == 0) {
292
288
  if (!gdImageConvolution(wrap->img, kernel_emboss2, 1.0, 128.0)) {
data/ext/gd/filter.o CHANGED
Binary file
data/ext/gd/gd.o CHANGED
Binary file
data/ext/gd/gd.so CHANGED
Binary file
data/ext/gd/gif.o CHANGED
Binary file
data/ext/gd/image.c CHANGED
@@ -1,24 +1,42 @@
1
1
  #include "ruby_gd.h"
2
2
 
3
- static VALUE gd_image_initialize(int argc, VALUE *argv, VALUE self) {
3
+ static VALUE gd_image_alloc(VALUE klass) {
4
4
  gd_image_wrapper *wrap;
5
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
6
-
5
+ VALUE obj = TypedData_Make_Struct(klass, gd_image_wrapper, &gd_image_type, wrap);
7
6
  wrap->img = NULL;
7
+ return obj;
8
+ }
9
+
10
+ /* ---------------------------------------------------------
11
+ * Initialize
12
+ * --------------------------------------------------------- */
8
13
 
14
+ static VALUE gd_image_initialize(int argc, VALUE *argv, VALUE self) {
9
15
  if (argc == 0) {
16
+ rb_raise(rb_eArgError, "width and height are required");
10
17
  return self;
11
18
  }
19
+
20
+ gd_image_wrapper *wrap;
21
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
22
+
23
+ wrap->img = NULL;
24
+
12
25
  if (argc != 2) {
13
26
  rb_raise(rb_eArgError, "expected 0 or 2 arguments");
14
27
  }
15
28
 
16
29
  int w = NUM2INT(argv[0]);
17
30
  int h = NUM2INT(argv[1]);
31
+
18
32
  if (w <= 0 || h <= 0)
19
33
  rb_raise(rb_eArgError, "width and height must be positive");
20
34
 
21
35
  wrap->img = gdImageCreateTrueColor(w,h);
36
+
37
+ if (!wrap->img)
38
+ rb_raise(rb_eRuntimeError, "gdImageCreateTrueColor failed");
39
+
22
40
  gdImageSaveAlpha(wrap->img, 1);
23
41
  gdImageAlphaBlending(wrap->img, 0);
24
42
 
@@ -27,12 +45,6 @@ static VALUE gd_image_initialize(int argc, VALUE *argv, VALUE self) {
27
45
 
28
46
  gdImageAlphaBlending(wrap->img, 1);
29
47
 
30
- int t = gdTrueColorAlpha(0,0,0,127);
31
- gdImageFilledRectangle(wrap->img, 0, 0, w-1, h-1, t);
32
-
33
- if (!wrap->img)
34
- rb_raise(rb_eRuntimeError, "gdImageCreateTrueColor failed");
35
-
36
48
  return self;
37
49
  }
38
50
 
@@ -58,7 +70,7 @@ static VALUE gd_image_initialize_true_color(VALUE self, VALUE width, VALUE heigh
58
70
  // Opcional: desactivar el fondo transparente si no lo necesitas
59
71
  gdImageSaveAlpha(wrap->img, 1);
60
72
  gdImageAlphaBlending(wrap->img, 0);
61
-
73
+
62
74
  int t = gdTrueColorAlpha(0,0,0,127);
63
75
  gdImageFilledRectangle(wrap->img, 0,0, w-1, h-1, t);
64
76
 
@@ -66,30 +78,47 @@ static VALUE gd_image_initialize_true_color(VALUE self, VALUE width, VALUE heigh
66
78
  }
67
79
 
68
80
  static VALUE gd_image_s_new_true_color(VALUE klass, VALUE width, VALUE height) {
69
- VALUE obj = rb_class_new_instance(0, NULL, klass);
70
- gd_image_initialize_true_color(obj, width, height);
71
- return obj;
81
+ VALUE img = rb_obj_alloc(klass);
82
+ rb_funcall(img, rb_intern("initialize"), 2, width, height);
83
+ return img;
72
84
  }
73
85
 
74
- static VALUE gd_image_clone(VALUE self) {
75
- gd_image_wrapper *wrap;
76
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
86
+ /* ---------------------------------------------------------
87
+ * initialize_copy (correct way for clone/dup)
88
+ * --------------------------------------------------------- */
77
89
 
78
- if (!wrap->img) rb_raise(rb_eRuntimeError, "cannot clone: image is NULL");
90
+ static VALUE gd_image_initialize_copy(VALUE self, VALUE orig) {
91
+ gd_image_wrapper *src;
92
+ gd_image_wrapper *dst;
79
93
 
80
- gdImagePtr copy = gdImageClone(wrap->img);
81
- if (!copy) rb_raise(rb_eRuntimeError, "gdImageClone failed");
94
+ if (self == orig) return self;
82
95
 
83
- VALUE obj = rb_class_new_instance(0, NULL, CLASS_OF(self));
84
- gd_image_wrapper *w2;
85
- TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, w2);
86
- w2->img = copy;
96
+ TypedData_Get_Struct(orig, gd_image_wrapper, &gd_image_type, src);
97
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
87
98
 
88
- return obj;
99
+ if (!src->img)
100
+ rb_raise(rb_eRuntimeError, "cannot copy: image is NULL");
101
+
102
+ if (dst->img) {
103
+ gdImageDestroy(dst->img);
104
+ dst->img = NULL;
105
+ }
106
+
107
+ dst->img = gdImageClone(src->img);
108
+
109
+ if (!dst->img)
110
+ rb_raise(rb_eRuntimeError, "gdImageClone failed");
111
+
112
+ return self;
89
113
  }
90
114
 
115
+ /* ---------------------------------------------------------
116
+ * Free
117
+ * --------------------------------------------------------- */
118
+
91
119
  static void gd_image_free(void *ptr) {
92
120
  gd_image_wrapper *wrap = (gd_image_wrapper *)ptr;
121
+
93
122
  if (!wrap) return;
94
123
 
95
124
  if (wrap->img) {
@@ -104,17 +133,14 @@ static size_t gd_image_memsize(const void *ptr) {
104
133
 
105
134
  const rb_data_type_t gd_image_type = {
106
135
  "GD::Image",
107
- { 0, gd_image_free, gd_image_memsize, 0 }, // <-- dcompact agregado
136
+ { 0, gd_image_free, gd_image_memsize, },
108
137
  0, 0,
109
138
  RUBY_TYPED_FREE_IMMEDIATELY
110
139
  };
111
140
 
112
- static VALUE gd_image_alloc(VALUE klass) {
113
- gd_image_wrapper *wrap;
114
- VALUE obj = TypedData_Make_Struct(klass, gd_image_wrapper, &gd_image_type, wrap);
115
- wrap->img = NULL;
116
- return obj;
117
- }
141
+ /* ---------------------------------------------------------
142
+ * Image loading
143
+ * --------------------------------------------------------- */
118
144
 
119
145
  static VALUE gd_image_open(VALUE klass, VALUE path) {
120
146
  const char *filename = StringValueCStr(path);
@@ -141,44 +167,44 @@ static VALUE gd_image_open(VALUE klass, VALUE path) {
141
167
  }
142
168
 
143
169
  fclose(f);
144
- if (!img) rb_raise(rb_eRuntimeError, "image decode failed");
145
170
 
146
- VALUE obj = rb_class_new_instance(0, NULL, klass);
171
+ if (!img)
172
+ rb_raise(rb_eRuntimeError, "image decode failed");
173
+
174
+ VALUE obj = rb_obj_alloc(klass);
175
+
147
176
  gd_image_wrapper *wrap;
148
177
  TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, wrap);
178
+
149
179
  wrap->img = img;
150
180
 
151
181
  return obj;
152
182
  }
153
183
 
154
- static VALUE gd_image_alpha_blending(VALUE self, VALUE flag) {
155
- gd_image_wrapper *wrap;
156
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
157
-
158
- gdImageAlphaBlending(wrap->img, RTEST(flag));
159
- return self;
160
- }
161
-
162
- static VALUE gd_image_save_alpha(VALUE self, VALUE flag) {
163
- gd_image_wrapper *wrap;
164
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
165
-
166
- gdImageSaveAlpha(wrap->img, RTEST(flag));
167
- return self;
168
- }
184
+ /* ---------------------------------------------------------
185
+ * Image info
186
+ * --------------------------------------------------------- */
169
187
 
170
188
  static VALUE gd_image_width(VALUE self) {
171
- gd_image_wrapper *wrap;
172
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
173
- return INT2NUM(gdImageSX(wrap->img));
189
+ gd_image_wrapper *wrap;
190
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
191
+ if (!wrap->img)
192
+ rb_raise(rb_eRuntimeError, "image not initialized");
193
+ return INT2NUM(gdImageSX(wrap->img));
174
194
  }
175
195
 
176
196
  static VALUE gd_image_height(VALUE self) {
177
- gd_image_wrapper *wrap;
178
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
179
- return INT2NUM(gdImageSY(wrap->img));
197
+ gd_image_wrapper *wrap;
198
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
199
+ if (!wrap->img)
200
+ rb_raise(rb_eRuntimeError, "image not initialized");
201
+ return INT2NUM(gdImageSY(wrap->img));
180
202
  }
181
203
 
204
+ /* ---------------------------------------------------------
205
+ * Copy operations
206
+ * --------------------------------------------------------- */
207
+
182
208
  static VALUE gd_image_copy (
183
209
  VALUE self, VALUE src,
184
210
  VALUE dx, VALUE dy,
@@ -191,6 +217,9 @@ static VALUE gd_image_copy (
191
217
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
192
218
  TypedData_Get_Struct(src, gd_image_wrapper, &gd_image_type, srcw);
193
219
 
220
+ if (!dst->img) rb_raise(rb_eRuntimeError, "image not initialized");
221
+ if (!srcw->img) rb_raise(rb_eRuntimeError, "source image not initialized");
222
+
194
223
  gdImageCopy(
195
224
  dst->img,
196
225
  srcw->img,
@@ -216,6 +245,9 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
216
245
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
217
246
  TypedData_Get_Struct(src_img, gd_image_wrapper, &gd_image_type, src);
218
247
 
248
+ if (!dst->img) rb_raise(rb_eRuntimeError, "image not initialized");
249
+ if (!src->img) rb_raise(rb_eRuntimeError, "source image not initialized");
250
+
219
251
  int dx = NUM2INT(dst_x);
220
252
  int dy = NUM2INT(dst_y);
221
253
  int sx = NUM2INT(src_x);
@@ -225,9 +257,7 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
225
257
  int dw = NUM2INT(dst_w);
226
258
  int dh = NUM2INT(dst_h);
227
259
 
228
- int do_resample = RTEST(resample);
229
-
230
- if (do_resample) {
260
+ if (RTEST(resample)) {
231
261
  gdImageCopyResampled(
232
262
  dst->img, src->img,
233
263
  dx, dy,
@@ -248,12 +278,34 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
248
278
  return self;
249
279
  }
250
280
 
281
+ /* ---------------------------------------------------------
282
+ * Flags
283
+ * --------------------------------------------------------- */
284
+
285
+ static VALUE gd_image_alpha_blending(VALUE self, VALUE flag) {
286
+ gd_image_wrapper *wrap;
287
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
288
+ if (!wrap->img)
289
+ rb_raise(rb_eRuntimeError, "image not initialized");
290
+ gdImageAlphaBlending(wrap->img, RTEST(flag));
291
+ return self;
292
+ }
293
+
294
+ static VALUE gd_image_save_alpha(VALUE self, VALUE flag) {
295
+ gd_image_wrapper *wrap;
296
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
297
+ if (!wrap->img)
298
+ rb_raise(rb_eRuntimeError, "image not initialized");
299
+ gdImageSaveAlpha(wrap->img, RTEST(flag));
300
+ return self;
301
+ }
302
+
251
303
  static VALUE gd_image_antialias(VALUE self, VALUE flag) {
252
304
  gd_image_wrapper *wrap;
253
305
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
254
306
 
255
307
  if (!wrap->img)
256
- rb_raise(rb_eRuntimeError, "image is NULL");
308
+ rb_raise(rb_eRuntimeError, "image not initialized");
257
309
 
258
310
  if (RTEST(flag)) {
259
311
  int aa = gdTrueColorAlpha(255,255,255,0);
@@ -266,23 +318,31 @@ static VALUE gd_image_antialias(VALUE self, VALUE flag) {
266
318
  return flag;
267
319
  }
268
320
 
321
+ /* ---------------------------------------------------------
322
+ * Class definition
323
+ * --------------------------------------------------------- */
269
324
 
270
325
  void gd_define_image(VALUE mGD) {
326
+
271
327
  VALUE cGDImage = rb_define_class_under(mGD, "Image", rb_cObject);
272
328
 
273
329
  rb_define_alloc_func(cGDImage, gd_image_alloc);
274
330
 
331
+ rb_define_method(cGDImage, "initialize", gd_image_initialize, -1);
332
+ rb_define_method(cGDImage, "initialize_copy", gd_image_initialize_copy, 1);
333
+
275
334
  rb_define_method(cGDImage, "width", gd_image_width, 0);
276
335
  rb_define_method(cGDImage, "height", gd_image_height, 0);
277
- rb_define_method(cGDImage, "initialize", gd_image_initialize, -1);
336
+
278
337
  rb_define_method(cGDImage, "copy_resize", gd_image_copy_resize, -1);
279
338
  rb_define_method(cGDImage, "copy", gd_image_copy, 7);
280
- rb_define_method(cGDImage, "clone", gd_image_clone, 0);
339
+
281
340
  rb_define_singleton_method(cGDImage, "open", gd_image_open, 1);
282
341
  rb_define_singleton_method(cGDImage, "new_true_color", gd_image_s_new_true_color, 2);
342
+
283
343
  rb_define_method(cGDImage, "alpha_blending=", gd_image_alpha_blending, 1);
284
344
  rb_define_method(cGDImage, "save_alpha=", gd_image_save_alpha, 1);
345
+
285
346
  rb_define_method(cGDImage, "antialias=", gd_image_antialias, 1);
286
347
  rb_define_method(cGDImage, "antialias", gd_image_antialias, 1);
287
-
288
348
  }
data/ext/gd/image.o CHANGED
Binary file
data/ext/gd/pixel.o CHANGED
Binary file
data/ext/gd/polygon.o CHANGED
Binary file
data/ext/gd/rectangle.o CHANGED
Binary file
data/ext/gd/text.c CHANGED
@@ -56,7 +56,7 @@ static VALUE gd_image_text_bbox(VALUE self, VALUE text, VALUE opts) {
56
56
  memset(&extra, 0, sizeof(extra));
57
57
 
58
58
  char *err = gdImageStringFTEx(
59
- wrap->img,
59
+ NULL,
60
60
  brect,
61
61
  0, /* no color, we don't draw */
62
62
  font,
data/ext/gd/text.o CHANGED
Binary file
data/ext/gd/transform.o CHANGED
Binary file
data/ext/gd/version.o CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-libgd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Germán Alberto Giménez Silva
@@ -89,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  - !ruby/object:Gem::Version
90
90
  version: '0'
91
91
  requirements: []
92
- rubygems_version: 4.0.3
92
+ rubygems_version: 4.0.10
93
93
  specification_version: 4
94
94
  summary: Native Ruby bindings for libgd
95
95
  test_files: []