ruby-libgd 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 310bd931469060390ec5d475ce151934d42afb9e51e3d9ddaa59075c8a4f88db
4
- data.tar.gz: 4d5dcef0cb4eb3556f4aa88733fd541539b49e489b4820469425270662b06b4c
3
+ metadata.gz: 12ec2b7cee7423c19cf4573b065068ea7503ab69411969866c98bde8013af909
4
+ data.tar.gz: 0f1d9c044ca898bfa02cebc4c0e10bdb8894fb08cf9e6c48bf4a2f02da46fb3f
5
5
  SHA512:
6
- metadata.gz: c3bb2ad496f6764c13c00d25f0e4d30b8b388915f45d16421ae85982148bd2ab0ee6e3abd5e5eba16e155fbeb2d1cd74e71fa509a733b49543f8ba0702a1eea8
7
- data.tar.gz: 1cabca6431ea0b7db31f0341ff63e68420c70b137a3b902b09f7b0bcf86a98d9ce71c3e7e4de67a85d07af47d2c1213e688665333657bc30b0d1ab5c64a55345
6
+ metadata.gz: b173710ef6a9bd66c964dfddded870406e8f9b833c4fcb5bba4a09dace6a92790ebb56ebc45dbb59c2b96dc7d66878965930dcf7e29c237755d548c0397455a5
7
+ data.tar.gz: d61159864c2ed251d0e072fc3951ad7a8ab3a7ba505cf584bd6e9390e3c0b0f94f76dbcc7452940caf62de4dabbf84f0e853fdb9b846d6a7b614cbd0280982f9
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
+ }
8
9
 
10
+ /* ---------------------------------------------------------
11
+ * Initialize
12
+ * --------------------------------------------------------- */
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,69 +45,45 @@ 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
 
39
- static VALUE gd_image_initialize_true_color(VALUE self, VALUE width, VALUE height) {
40
- gd_image_wrapper *wrap;
41
- TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
51
+ /* ---------------------------------------------------------
52
+ * initialize_copy (correct way for clone/dup)
53
+ * --------------------------------------------------------- */
42
54
 
43
- if (wrap->img) {
44
- gdImageDestroy(wrap->img);
45
- }
46
-
47
- int w = NUM2INT(width);
48
- int h = NUM2INT(height);
49
- if (w <= 0 || h <= 0) {
50
- rb_raise(rb_eArgError, "width and height must be positive");
51
- }
52
-
53
- wrap->img = gdImageCreateTrueColor(w, h);
54
- if (!wrap->img) {
55
- rb_raise(rb_eRuntimeError, "failed to create true color image");
56
- }
55
+ static VALUE gd_image_initialize_copy(VALUE self, VALUE orig) {
56
+ gd_image_wrapper *src;
57
+ gd_image_wrapper *dst;
57
58
 
58
- // Opcional: desactivar el fondo transparente si no lo necesitas
59
- gdImageSaveAlpha(wrap->img, 1);
60
- gdImageAlphaBlending(wrap->img, 0);
61
-
62
- int t = gdTrueColorAlpha(0,0,0,127);
63
- gdImageFilledRectangle(wrap->img, 0,0, w-1, h-1, t);
59
+ if (self == orig) return self;
64
60
 
65
- return self;
66
- }
67
-
68
- 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;
72
- }
61
+ TypedData_Get_Struct(orig, gd_image_wrapper, &gd_image_type, src);
62
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
73
63
 
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);
64
+ if (!src->img)
65
+ rb_raise(rb_eRuntimeError, "cannot copy: image is NULL");
77
66
 
78
- if (!wrap->img) rb_raise(rb_eRuntimeError, "cannot clone: image is NULL");
67
+ if (dst->img) {
68
+ gdImageDestroy(dst->img);
69
+ dst->img = NULL;
70
+ }
79
71
 
80
- gdImagePtr copy = gdImageClone(wrap->img);
81
- if (!copy) rb_raise(rb_eRuntimeError, "gdImageClone failed");
72
+ dst->img = gdImageClone(src->img);
82
73
 
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;
74
+ if (!dst->img)
75
+ rb_raise(rb_eRuntimeError, "gdImageClone failed");
87
76
 
88
- return obj;
77
+ return self;
89
78
  }
90
79
 
80
+ /* ---------------------------------------------------------
81
+ * Free
82
+ * --------------------------------------------------------- */
83
+
91
84
  static void gd_image_free(void *ptr) {
92
85
  gd_image_wrapper *wrap = (gd_image_wrapper *)ptr;
86
+
93
87
  if (!wrap) return;
94
88
 
95
89
  if (wrap->img) {
@@ -104,17 +98,14 @@ static size_t gd_image_memsize(const void *ptr) {
104
98
 
105
99
  const rb_data_type_t gd_image_type = {
106
100
  "GD::Image",
107
- { 0, gd_image_free, gd_image_memsize, 0 }, // <-- dcompact agregado
101
+ { 0, gd_image_free, gd_image_memsize, },
108
102
  0, 0,
109
103
  RUBY_TYPED_FREE_IMMEDIATELY
110
104
  };
111
105
 
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
- }
106
+ /* ---------------------------------------------------------
107
+ * Image loading
108
+ * --------------------------------------------------------- */
118
109
 
119
110
  static VALUE gd_image_open(VALUE klass, VALUE path) {
120
111
  const char *filename = StringValueCStr(path);
@@ -141,44 +132,44 @@ static VALUE gd_image_open(VALUE klass, VALUE path) {
141
132
  }
142
133
 
143
134
  fclose(f);
144
- if (!img) rb_raise(rb_eRuntimeError, "image decode failed");
145
135
 
146
- VALUE obj = rb_class_new_instance(0, NULL, klass);
136
+ if (!img)
137
+ rb_raise(rb_eRuntimeError, "image decode failed");
138
+
139
+ VALUE obj = rb_obj_alloc(klass);
140
+
147
141
  gd_image_wrapper *wrap;
148
142
  TypedData_Get_Struct(obj, gd_image_wrapper, &gd_image_type, wrap);
143
+
149
144
  wrap->img = img;
150
145
 
151
146
  return obj;
152
147
  }
153
148
 
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
- }
149
+ /* ---------------------------------------------------------
150
+ * Image info
151
+ * --------------------------------------------------------- */
169
152
 
170
153
  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));
154
+ gd_image_wrapper *wrap;
155
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
156
+ if (!wrap->img)
157
+ rb_raise(rb_eRuntimeError, "image not initialized");
158
+ return INT2NUM(gdImageSX(wrap->img));
174
159
  }
175
160
 
176
161
  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));
162
+ gd_image_wrapper *wrap;
163
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
164
+ if (!wrap->img)
165
+ rb_raise(rb_eRuntimeError, "image not initialized");
166
+ return INT2NUM(gdImageSY(wrap->img));
180
167
  }
181
168
 
169
+ /* ---------------------------------------------------------
170
+ * Copy operations
171
+ * --------------------------------------------------------- */
172
+
182
173
  static VALUE gd_image_copy (
183
174
  VALUE self, VALUE src,
184
175
  VALUE dx, VALUE dy,
@@ -191,6 +182,9 @@ static VALUE gd_image_copy (
191
182
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
192
183
  TypedData_Get_Struct(src, gd_image_wrapper, &gd_image_type, srcw);
193
184
 
185
+ if (!dst->img) rb_raise(rb_eRuntimeError, "image not initialized");
186
+ if (!srcw->img) rb_raise(rb_eRuntimeError, "source image not initialized");
187
+
194
188
  gdImageCopy(
195
189
  dst->img,
196
190
  srcw->img,
@@ -216,6 +210,9 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
216
210
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, dst);
217
211
  TypedData_Get_Struct(src_img, gd_image_wrapper, &gd_image_type, src);
218
212
 
213
+ if (!dst->img) rb_raise(rb_eRuntimeError, "image not initialized");
214
+ if (!src->img) rb_raise(rb_eRuntimeError, "source image not initialized");
215
+
219
216
  int dx = NUM2INT(dst_x);
220
217
  int dy = NUM2INT(dst_y);
221
218
  int sx = NUM2INT(src_x);
@@ -225,9 +222,7 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
225
222
  int dw = NUM2INT(dst_w);
226
223
  int dh = NUM2INT(dst_h);
227
224
 
228
- int do_resample = RTEST(resample);
229
-
230
- if (do_resample) {
225
+ if (RTEST(resample)) {
231
226
  gdImageCopyResampled(
232
227
  dst->img, src->img,
233
228
  dx, dy,
@@ -248,12 +243,34 @@ static VALUE gd_image_copy_resize(int argc, VALUE *argv, VALUE self) {
248
243
  return self;
249
244
  }
250
245
 
246
+ /* ---------------------------------------------------------
247
+ * Flags
248
+ * --------------------------------------------------------- */
249
+
250
+ static VALUE gd_image_alpha_blending(VALUE self, VALUE flag) {
251
+ gd_image_wrapper *wrap;
252
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
253
+ if (!wrap->img)
254
+ rb_raise(rb_eRuntimeError, "image not initialized");
255
+ gdImageAlphaBlending(wrap->img, RTEST(flag));
256
+ return self;
257
+ }
258
+
259
+ static VALUE gd_image_save_alpha(VALUE self, VALUE flag) {
260
+ gd_image_wrapper *wrap;
261
+ TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
262
+ if (!wrap->img)
263
+ rb_raise(rb_eRuntimeError, "image not initialized");
264
+ gdImageSaveAlpha(wrap->img, RTEST(flag));
265
+ return self;
266
+ }
267
+
251
268
  static VALUE gd_image_antialias(VALUE self, VALUE flag) {
252
269
  gd_image_wrapper *wrap;
253
270
  TypedData_Get_Struct(self, gd_image_wrapper, &gd_image_type, wrap);
254
271
 
255
272
  if (!wrap->img)
256
- rb_raise(rb_eRuntimeError, "image is NULL");
273
+ rb_raise(rb_eRuntimeError, "image not initialized");
257
274
 
258
275
  if (RTEST(flag)) {
259
276
  int aa = gdTrueColorAlpha(255,255,255,0);
@@ -266,23 +283,30 @@ static VALUE gd_image_antialias(VALUE self, VALUE flag) {
266
283
  return flag;
267
284
  }
268
285
 
286
+ /* ---------------------------------------------------------
287
+ * Class definition
288
+ * --------------------------------------------------------- */
269
289
 
270
290
  void gd_define_image(VALUE mGD) {
291
+
271
292
  VALUE cGDImage = rb_define_class_under(mGD, "Image", rb_cObject);
272
293
 
273
294
  rb_define_alloc_func(cGDImage, gd_image_alloc);
274
295
 
296
+ rb_define_method(cGDImage, "initialize", gd_image_initialize, -1);
297
+ rb_define_method(cGDImage, "initialize_copy", gd_image_initialize_copy, 1);
298
+
275
299
  rb_define_method(cGDImage, "width", gd_image_width, 0);
276
300
  rb_define_method(cGDImage, "height", gd_image_height, 0);
277
- rb_define_method(cGDImage, "initialize", gd_image_initialize, -1);
301
+
278
302
  rb_define_method(cGDImage, "copy_resize", gd_image_copy_resize, -1);
279
303
  rb_define_method(cGDImage, "copy", gd_image_copy, 7);
280
- rb_define_method(cGDImage, "clone", gd_image_clone, 0);
304
+
281
305
  rb_define_singleton_method(cGDImage, "open", gd_image_open, 1);
282
- rb_define_singleton_method(cGDImage, "new_true_color", gd_image_s_new_true_color, 2);
306
+
283
307
  rb_define_method(cGDImage, "alpha_blending=", gd_image_alpha_blending, 1);
284
308
  rb_define_method(cGDImage, "save_alpha=", gd_image_save_alpha, 1);
309
+
285
310
  rb_define_method(cGDImage, "antialias=", gd_image_antialias, 1);
286
311
  rb_define_method(cGDImage, "antialias", gd_image_antialias, 1);
287
-
288
312
  }
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.1
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: []