rmagick 4.2.2 → 5.3.0

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.
data/ext/RMagick/rmdraw.c CHANGED
@@ -13,17 +13,43 @@
13
13
  #include "rmagick.h"
14
14
  #include "float.h"
15
15
 
16
- static void mark_Draw(void *);
17
- static void destroy_Draw(void *);
16
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
17
+ static void Draw_compact(void *drawptr);
18
+ #endif
19
+ static void Draw_mark(void *);
20
+ static void Draw_destroy(void *);
21
+ static size_t Draw_memsize(const void *);
18
22
  static VALUE new_DrawOptions(void);
23
+ static VALUE get_type_metrics(int, VALUE *, VALUE, gvl_function_t);
24
+
25
+ const rb_data_type_t rm_draw_data_type = {
26
+ "Magick::Draw",
27
+ {
28
+ Draw_mark,
29
+ Draw_destroy,
30
+ Draw_memsize,
31
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
32
+ Draw_compact,
33
+ #endif
34
+ },
35
+ 0, 0,
36
+ RUBY_TYPED_FROZEN_SHAREABLE,
37
+ };
38
+
19
39
 
20
- /** Method that gets type metrics */
40
+ DEFINE_GVL_STUB4(BlobToImage, const ImageInfo *, const void *, const size_t, ExceptionInfo *);
41
+ DEFINE_GVL_STUB4(ImageToBlob, const ImageInfo *, Image *, size_t *, ExceptionInfo *);
21
42
  #if defined(IMAGEMAGICK_7)
22
- typedef MagickBooleanType (get_type_metrics_func_t)(Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
43
+ DEFINE_GVL_STUB3(AnnotateImage, Image *, const DrawInfo *, ExceptionInfo *);
44
+ DEFINE_GVL_STUB3(DrawImage, Image *, const DrawInfo *, ExceptionInfo *);
45
+ DEFINE_GVL_STUB4(GetMultilineTypeMetrics, Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
46
+ DEFINE_GVL_STUB4(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *, ExceptionInfo *);
23
47
  #else
24
- typedef MagickBooleanType (get_type_metrics_func_t)(Image *, const DrawInfo *, TypeMetric *);
48
+ DEFINE_GVL_STUB2(AnnotateImage, Image *, const DrawInfo *);
49
+ DEFINE_GVL_STUB2(DrawImage, Image *, const DrawInfo *);
50
+ DEFINE_GVL_STUB3(GetMultilineTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
51
+ DEFINE_GVL_STUB3(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
25
52
  #endif
26
- static VALUE get_type_metrics(int, VALUE *, VALUE, get_type_metrics_func_t);
27
53
 
28
54
 
29
55
  /**
@@ -38,7 +64,7 @@ Draw_affine_eq(VALUE self, VALUE matrix)
38
64
  Draw *draw;
39
65
 
40
66
  rb_check_frozen(self);
41
- Data_Get_Struct(self, Draw, draw);
67
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
42
68
  Export_AffineMatrix(&draw->info->affine, matrix);
43
69
  return matrix;
44
70
  }
@@ -56,7 +82,7 @@ Draw_align_eq(VALUE self, VALUE align)
56
82
  Draw *draw;
57
83
 
58
84
  rb_check_frozen(self);
59
- Data_Get_Struct(self, Draw, draw);
85
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
60
86
  VALUE_TO_ENUM(align, draw->info->align, AlignType);
61
87
  return align;
62
88
  }
@@ -74,7 +100,7 @@ Draw_decorate_eq(VALUE self, VALUE decorate)
74
100
  Draw *draw;
75
101
 
76
102
  rb_check_frozen(self);
77
- Data_Get_Struct(self, Draw, draw);
103
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
78
104
  VALUE_TO_ENUM(decorate, draw->info->decorate, DecorationType);
79
105
  return decorate;
80
106
  }
@@ -92,7 +118,7 @@ Draw_density_eq(VALUE self, VALUE density)
92
118
  Draw *draw;
93
119
 
94
120
  rb_check_frozen(self);
95
- Data_Get_Struct(self, Draw, draw);
121
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
96
122
  magick_clone_string(&draw->info->density, StringValueCStr(density));
97
123
 
98
124
  return density;
@@ -111,7 +137,7 @@ Draw_encoding_eq(VALUE self, VALUE encoding)
111
137
  Draw *draw;
112
138
 
113
139
  rb_check_frozen(self);
114
- Data_Get_Struct(self, Draw, draw);
140
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
115
141
  magick_clone_string(&draw->info->encoding, StringValueCStr(encoding));
116
142
 
117
143
  return encoding;
@@ -130,7 +156,7 @@ Draw_fill_eq(VALUE self, VALUE fill)
130
156
  Draw *draw;
131
157
 
132
158
  rb_check_frozen(self);
133
- Data_Get_Struct(self, Draw, draw);
159
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
134
160
  Color_to_PixelColor(&draw->info->fill, fill);
135
161
  return fill;
136
162
  }
@@ -151,7 +177,7 @@ Draw_fill_pattern_eq(VALUE self, VALUE pattern)
151
177
  Draw *draw;
152
178
 
153
179
  rb_check_frozen(self);
154
- Data_Get_Struct(self, Draw, draw);
180
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
155
181
 
156
182
  if (draw->info->fill_pattern != NULL)
157
183
  {
@@ -186,7 +212,7 @@ Draw_font_eq(VALUE self, VALUE font)
186
212
  Draw *draw;
187
213
 
188
214
  rb_check_frozen(self);
189
- Data_Get_Struct(self, Draw, draw);
215
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
190
216
  magick_clone_string(&draw->info->font, StringValueCStr(font));
191
217
 
192
218
  return font;
@@ -205,7 +231,7 @@ Draw_font_family_eq(VALUE self, VALUE family)
205
231
  Draw *draw;
206
232
 
207
233
  rb_check_frozen(self);
208
- Data_Get_Struct(self, Draw, draw);
234
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
209
235
  magick_clone_string(&draw->info->family, StringValueCStr(family));
210
236
 
211
237
  return family;
@@ -224,7 +250,7 @@ Draw_font_stretch_eq(VALUE self, VALUE stretch)
224
250
  Draw *draw;
225
251
 
226
252
  rb_check_frozen(self);
227
- Data_Get_Struct(self, Draw, draw);
253
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
228
254
  VALUE_TO_ENUM(stretch, draw->info->stretch, StretchType);
229
255
  return stretch;
230
256
  }
@@ -242,7 +268,7 @@ Draw_font_style_eq(VALUE self, VALUE style)
242
268
  Draw *draw;
243
269
 
244
270
  rb_check_frozen(self);
245
- Data_Get_Struct(self, Draw, draw);
271
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
246
272
  VALUE_TO_ENUM(style, draw->info->style, StyleType);
247
273
  return style;
248
274
  }
@@ -262,7 +288,7 @@ Draw_font_weight_eq(VALUE self, VALUE weight)
262
288
  size_t w;
263
289
 
264
290
  rb_check_frozen(self);
265
- Data_Get_Struct(self, Draw, draw);
291
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
266
292
 
267
293
  if (FIXNUM_P(weight))
268
294
  {
@@ -328,7 +354,7 @@ Draw_gravity_eq(VALUE self, VALUE grav)
328
354
  Draw *draw;
329
355
 
330
356
  rb_check_frozen(self);
331
- Data_Get_Struct(self, Draw, draw);
357
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
332
358
  VALUE_TO_ENUM(grav, draw->info->gravity, GravityType);
333
359
 
334
360
  return grav;
@@ -347,7 +373,7 @@ Draw_kerning_eq(VALUE self, VALUE kerning)
347
373
  Draw *draw;
348
374
 
349
375
  rb_check_frozen(self);
350
- Data_Get_Struct(self, Draw, draw);
376
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
351
377
  draw->info->kerning = NUM2DBL(kerning);
352
378
  return kerning;
353
379
  }
@@ -365,7 +391,7 @@ Draw_interline_spacing_eq(VALUE self, VALUE spacing)
365
391
  Draw *draw;
366
392
 
367
393
  rb_check_frozen(self);
368
- Data_Get_Struct(self, Draw, draw);
394
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
369
395
  draw->info->interline_spacing = NUM2DBL(spacing);
370
396
  return spacing;
371
397
  }
@@ -383,7 +409,7 @@ Draw_interword_spacing_eq(VALUE self, VALUE spacing)
383
409
  Draw *draw;
384
410
 
385
411
  rb_check_frozen(self);
386
- Data_Get_Struct(self, Draw, draw);
412
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
387
413
  draw->info->interword_spacing = NUM2DBL(spacing);
388
414
  return spacing;
389
415
  }
@@ -415,7 +441,8 @@ image_to_str(Image *image)
415
441
 
416
442
  info = CloneImageInfo(NULL);
417
443
  exception = AcquireExceptionInfo();
418
- blob = ImageToBlob(info, image, &length, exception);
444
+ GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception };
445
+ blob = (unsigned char *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args);
419
446
  DestroyImageInfo(info);
420
447
  CHECK_EXCEPTION();
421
448
  DestroyExceptionInfo(exception);
@@ -453,7 +480,8 @@ Image *str_to_image(VALUE str)
453
480
 
454
481
  info = CloneImageInfo(NULL);
455
482
  exception = AcquireExceptionInfo();
456
- image = BlobToImage(info, RSTRING_PTR(str), RSTRING_LEN(str), exception);
483
+ GVL_STRUCT_TYPE(BlobToImage) args = { info, RSTRING_PTR(str), RSTRING_LEN(str), exception };
484
+ image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args);
457
485
  DestroyImageInfo(info);
458
486
  CHECK_EXCEPTION();
459
487
  DestroyExceptionInfo(exception);
@@ -482,7 +510,7 @@ Draw_marshal_dump(VALUE self)
482
510
  Draw *draw;
483
511
  VALUE ddraw;
484
512
 
485
- Data_Get_Struct(self, Draw, draw);
513
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
486
514
 
487
515
  // Raise an exception if the Draw has a non-NULL gradient or element_reference field
488
516
  if (draw->info->element_reference.type != UndefinedReference
@@ -493,31 +521,17 @@ Draw_marshal_dump(VALUE self)
493
521
 
494
522
  ddraw = rb_hash_new();
495
523
 
496
- // rb_hash_aset(ddraw, CSTR2SYM("primitive"), MAGICK_STRING_TO_OBJ(draw->info->primitive)); internal
497
- // rb_hash_aset(ddraw, CSTR2SYM("geometry"), MAGICK_STRING_TO_OBJ(draw->info->geometry)); set by "text" primitive
498
- // rb_hash_aset(ddraw, CSTR2SYM("viewbox"), Import_RectangleInfo(&draw->info->viewbox)); internal
499
524
  rb_hash_aset(ddraw, CSTR2SYM("affine"), Import_AffineMatrix(&draw->info->affine));
500
525
  rb_hash_aset(ddraw, CSTR2SYM("gravity"), INT2FIX(draw->info->gravity));
501
526
  rb_hash_aset(ddraw, CSTR2SYM("fill"), Pixel_from_PixelColor(&draw->info->fill));
502
527
  rb_hash_aset(ddraw, CSTR2SYM("stroke"), Pixel_from_PixelColor(&draw->info->stroke));
503
528
  rb_hash_aset(ddraw, CSTR2SYM("stroke_width"), rb_float_new(draw->info->stroke_width));
504
- // rb_hash_aset(ddraw, CSTR2SYM("gradient"), Qnil); // not used yet
505
529
  rb_hash_aset(ddraw, CSTR2SYM("fill_pattern"), image_to_str(draw->info->fill_pattern));
506
- rb_hash_aset(ddraw, CSTR2SYM("tile"), Qnil); // deprecated
507
530
  rb_hash_aset(ddraw, CSTR2SYM("stroke_pattern"), image_to_str(draw->info->stroke_pattern));
508
531
  rb_hash_aset(ddraw, CSTR2SYM("stroke_antialias"), draw->info->stroke_antialias ? Qtrue : Qfalse);
509
532
  rb_hash_aset(ddraw, CSTR2SYM("text_antialias"), draw->info->text_antialias ? Qtrue : Qfalse);
510
- // rb_hash_aset(ddraw, CSTR2SYM("fill_rule"), INT2FIX(draw->info->fill_rule)); internal
511
- // rb_hash_aset(ddraw, CSTR2SYM("linecap"), INT2FIX(draw->info->linecap));
512
- // rb_hash_aset(ddraw, CSTR2SYM("linejoin"), INT2FIX(draw->info->linejoin));
513
- // rb_hash_aset(ddraw, CSTR2SYM("miterlimit"), ULONG2NUM(draw->info->miterlimit));
514
- // rb_hash_aset(ddraw, CSTR2SYM("dash_offset"), rb_float_new(draw->info->dash_offset));
515
533
  rb_hash_aset(ddraw, CSTR2SYM("decorate"), INT2FIX(draw->info->decorate));
516
- // rb_hash_aset(ddraw, CSTR2SYM("compose"), INT2FIX(draw->info->compose)); set via "image" primitive
517
- // rb_hash_aset(ddraw, CSTR2SYM("text"), MAGICK_STRING_TO_OBJ(draw->info->text)); set via "text" primitive
518
- // rb_hash_aset(ddraw, CSTR2SYM("face"), Qnil); internal
519
534
  rb_hash_aset(ddraw, CSTR2SYM("font"), MAGICK_STRING_TO_OBJ(draw->info->font));
520
- // rb_hash_aset(ddraw, CSTR2SYM("metrics"), Qnil); internal
521
535
  rb_hash_aset(ddraw, CSTR2SYM("family"), MAGICK_STRING_TO_OBJ(draw->info->family));
522
536
  rb_hash_aset(ddraw, CSTR2SYM("style"), INT2FIX(draw->info->style));
523
537
  rb_hash_aset(ddraw, CSTR2SYM("stretch"), INT2FIX(draw->info->stretch));
@@ -527,26 +541,17 @@ Draw_marshal_dump(VALUE self)
527
541
  rb_hash_aset(ddraw, CSTR2SYM("density"), MAGICK_STRING_TO_OBJ(draw->info->density));
528
542
  rb_hash_aset(ddraw, CSTR2SYM("align"), INT2FIX(draw->info->align));
529
543
  rb_hash_aset(ddraw, CSTR2SYM("undercolor"), Pixel_from_PixelColor(&draw->info->undercolor));
530
- // rb_hash_aset(ddraw, CSTR2SYM("border_color"), Pixel_from_PixelColor(&draw->info->border_color)); Montage and Polaroid
531
- // rb_hash_aset(ddraw, CSTR2SYM("server_name"), MAGICK_STRING_TO_OBJ(draw->info->server_name));
532
- // rb_hash_aset(ddraw, CSTR2SYM("dash_pattern"), dash_pattern_to_array(draw->info->dash_pattern)); internal
533
- // rb_hash_aset(ddraw, CSTR2SYM("clip_mask"), MAGICK_STRING_TO_OBJ(draw->info->clip_mask)); internal
534
- // rb_hash_aset(ddraw, CSTR2SYM("bounds"), Import_SegmentInfo(&draw->info->bounds)); internal
535
544
  rb_hash_aset(ddraw, CSTR2SYM("clip_units"), INT2FIX(draw->info->clip_units));
536
545
  #if defined(IMAGEMAGICK_7)
537
546
  rb_hash_aset(ddraw, CSTR2SYM("alpha"), QUANTUM2NUM(draw->info->alpha));
538
547
  #else
539
548
  rb_hash_aset(ddraw, CSTR2SYM("opacity"), QUANTUM2NUM(draw->info->opacity));
540
549
  #endif
541
- // rb_hash_aset(ddraw, CSTR2SYM("render"), draw->info->render ? Qtrue : Qfalse); internal
542
- // rb_hash_aset(ddraw, CSTR2SYM("element_reference"), Qnil); // not used yet
543
- // rb_hash_aset(ddraw, CSTR2SYM("debug"), draw->info->debug ? Qtrue : Qfalse);
544
550
  rb_hash_aset(ddraw, CSTR2SYM("kerning"), rb_float_new(draw->info->kerning));
545
551
  rb_hash_aset(ddraw, CSTR2SYM("interword_spacing"), rb_float_new(draw->info->interword_spacing));
546
552
 
547
553
  // Non-DrawInfo fields
548
554
  rb_hash_aset(ddraw, CSTR2SYM("primitives"), draw->primitives);
549
- // rb_hash_aset(ddraw, CSTR2SYM("shadow_color"), Pixel_from_PixelColor(&draw->shadow_color)); Polaroid-only
550
555
 
551
556
  return ddraw;
552
557
  }
@@ -564,21 +569,18 @@ Draw_marshal_load(VALUE self, VALUE ddraw)
564
569
  Draw *draw;
565
570
  VALUE val;
566
571
 
567
- Data_Get_Struct(self, Draw, draw);
568
-
572
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
573
+
569
574
  if (draw->info == NULL)
570
575
  {
571
576
  ImageInfo *image_info;
572
577
 
573
578
  image_info = CloneImageInfo(NULL);
574
579
  draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
575
- DestroyImageInfo(image_info);
580
+ DestroyImageInfo(image_info);
576
581
  }
577
582
  OBJ_TO_MAGICK_STRING(draw->info->geometry, rb_hash_aref(ddraw, CSTR2SYM("geometry")));
578
583
 
579
- //val = rb_hash_aref(ddraw, CSTR2SYM("viewbox"));
580
- //Export_RectangleInfo(&draw->info->viewbox, val);
581
-
582
584
  val = rb_hash_aref(ddraw, CSTR2SYM("affine"));
583
585
  Export_AffineMatrix(&draw->info->affine, val);
584
586
 
@@ -639,7 +641,7 @@ Draw_pointsize_eq(VALUE self, VALUE pointsize)
639
641
  Draw *draw;
640
642
 
641
643
  rb_check_frozen(self);
642
- Data_Get_Struct(self, Draw, draw);
644
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
643
645
  draw->info->pointsize = NUM2DBL(pointsize);
644
646
  return pointsize;
645
647
  }
@@ -659,7 +661,7 @@ Draw_rotation_eq(VALUE self, VALUE deg)
659
661
  AffineMatrix affine, current;
660
662
 
661
663
  rb_check_frozen(self);
662
- Data_Get_Struct(self, Draw, draw);
664
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
663
665
 
664
666
  degrees = NUM2DBL(deg);
665
667
  if (fabs(degrees) > DBL_EPSILON)
@@ -695,7 +697,7 @@ Draw_stroke_eq(VALUE self, VALUE stroke)
695
697
  Draw *draw;
696
698
 
697
699
  rb_check_frozen(self);
698
- Data_Get_Struct(self, Draw, draw);
700
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
699
701
  Color_to_PixelColor(&draw->info->stroke, stroke);
700
702
  return stroke;
701
703
  }
@@ -715,7 +717,7 @@ Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
715
717
  Draw *draw;
716
718
 
717
719
  rb_check_frozen(self);
718
- Data_Get_Struct(self, Draw, draw);
720
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
719
721
 
720
722
  if (draw->info->stroke_pattern != NULL)
721
723
  {
@@ -751,7 +753,7 @@ Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
751
753
  Draw *draw;
752
754
 
753
755
  rb_check_frozen(self);
754
- Data_Get_Struct(self, Draw, draw);
756
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
755
757
  draw->info->stroke_width = NUM2DBL(stroke_width);
756
758
  return stroke_width;
757
759
  }
@@ -769,7 +771,7 @@ Draw_text_antialias_eq(VALUE self, VALUE text_antialias)
769
771
  Draw *draw;
770
772
 
771
773
  rb_check_frozen(self);
772
- Data_Get_Struct(self, Draw, draw);
774
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
773
775
  draw->info->text_antialias = (MagickBooleanType) RTEST(text_antialias);
774
776
  return text_antialias;
775
777
  }
@@ -800,7 +802,7 @@ Draw_undercolor_eq(VALUE self, VALUE undercolor)
800
802
  Draw *draw;
801
803
 
802
804
  rb_check_frozen(self);
803
- Data_Get_Struct(self, Draw, draw);
805
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
804
806
  Color_to_PixelColor(&draw->info->undercolor, undercolor);
805
807
  return undercolor;
806
808
  }
@@ -843,7 +845,7 @@ VALUE Draw_annotate(
843
845
 
844
846
  // Save the affine matrix in case it is modified by
845
847
  // Draw#rotation=
846
- Data_Get_Struct(self, Draw, draw);
848
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
847
849
  keep = draw->info->affine;
848
850
 
849
851
  image_arg = rm_cur_image(image_arg);
@@ -853,15 +855,7 @@ VALUE Draw_annotate(
853
855
  // allowing the app a chance to modify the object's attributes
854
856
  if (rb_block_given_p())
855
857
  {
856
- if (rb_proc_arity(rb_block_proc()) == 0)
857
- {
858
- // Run the block in self's context
859
- rb_obj_instance_eval(0, NULL, self);
860
- }
861
- else
862
- {
863
- rb_yield(self);
864
- }
858
+ rb_yield(self);
865
859
  }
866
860
 
867
861
  // Translate & store in Draw structure
@@ -909,10 +903,11 @@ VALUE Draw_annotate(
909
903
  magick_clone_string(&draw->info->geometry, geometry_str);
910
904
 
911
905
  #if defined(IMAGEMAGICK_7)
912
- AnnotateImage(image, draw->info, exception);
906
+ GVL_STRUCT_TYPE(AnnotateImage) args = { image, draw->info, exception };
913
907
  #else
914
- AnnotateImage(image, draw->info);
908
+ GVL_STRUCT_TYPE(AnnotateImage) args = { image, draw->info };
915
909
  #endif
910
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AnnotateImage), &args);
916
911
 
917
912
  magick_free(draw->info->text);
918
913
  draw->info->text = NULL;
@@ -972,7 +967,7 @@ Draw_clone(VALUE self)
972
967
  * @param image [Magick::Image, Magick::ImageList] Either an imagelist or an image. If an
973
968
  * imagelist, uses the current image.
974
969
  * @param operator [Magick::CompositeOperator] the operator
975
- *
970
+ *
976
971
  * @return [Magick::Draw] self
977
972
  */
978
973
  VALUE
@@ -1015,7 +1010,7 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
1015
1010
  rb_raise(rb_eArgError, "unknown composite operator (%d)", cop);
1016
1011
  }
1017
1012
 
1018
- Data_Get_Struct(self, Draw, draw);
1013
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1019
1014
 
1020
1015
  // Create a temp copy of the composite image
1021
1016
  rm_write_temp_image(comp_img, name, sizeof(name));
@@ -1060,7 +1055,7 @@ Draw_draw(VALUE self, VALUE image_arg)
1060
1055
  image_arg = rm_cur_image(image_arg);
1061
1056
  image = rm_check_frozen(image_arg);
1062
1057
 
1063
- Data_Get_Struct(self, Draw, draw);
1058
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1064
1059
  if (draw->primitives == 0)
1065
1060
  {
1066
1061
  rb_raise(rb_eArgError, "nothing to draw");
@@ -1071,10 +1066,11 @@ Draw_draw(VALUE self, VALUE image_arg)
1071
1066
 
1072
1067
  #if defined(IMAGEMAGICK_7)
1073
1068
  exception = AcquireExceptionInfo();
1074
- DrawImage(image, draw->info, exception);
1069
+ GVL_STRUCT_TYPE(DrawImage) args = { image, draw->info, exception };
1075
1070
  #else
1076
- DrawImage(image, draw->info);
1071
+ GVL_STRUCT_TYPE(DrawImage) args = { image, draw->info };
1077
1072
  #endif
1073
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DrawImage), &args);
1078
1074
 
1079
1075
  magick_free(draw->info->primitive);
1080
1076
  draw->info->primitive = NULL;
@@ -1105,7 +1101,7 @@ Draw_dup(VALUE self)
1105
1101
 
1106
1102
  draw = ALLOC(Draw);
1107
1103
  memset(draw, 0, sizeof(Draw));
1108
- dup = Data_Wrap_Struct(CLASS_OF(self), mark_Draw, destroy_Draw, draw);
1104
+ dup = TypedData_Wrap_Struct(CLASS_OF(self), &rm_draw_data_type, draw);
1109
1105
  RB_GC_GUARD(dup);
1110
1106
 
1111
1107
  return rb_funcall(dup, rm_ID_initialize_copy, 1, self);
@@ -1135,7 +1131,7 @@ Draw_get_type_metrics(
1135
1131
  VALUE *argv,
1136
1132
  VALUE self)
1137
1133
  {
1138
- return get_type_metrics(argc, argv, self, GetTypeMetrics);
1134
+ return get_type_metrics(argc, argv, self, GVL_FUNC(GetTypeMetrics));
1139
1135
  }
1140
1136
 
1141
1137
 
@@ -1162,7 +1158,7 @@ Draw_get_multiline_type_metrics(
1162
1158
  VALUE *argv,
1163
1159
  VALUE self)
1164
1160
  {
1165
- return get_type_metrics(argc, argv, self, GetMultilineTypeMetrics);
1161
+ return get_type_metrics(argc, argv, self, GVL_FUNC(GetMultilineTypeMetrics));
1166
1162
  }
1167
1163
 
1168
1164
 
@@ -1176,8 +1172,8 @@ VALUE Draw_init_copy(VALUE self, VALUE orig)
1176
1172
  {
1177
1173
  Draw *copy, *original;
1178
1174
 
1179
- Data_Get_Struct(orig, Draw, original);
1180
- Data_Get_Struct(self, Draw, copy);
1175
+ TypedData_Get_Struct(orig, Draw, &rm_draw_data_type, original);
1176
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, copy);
1181
1177
 
1182
1178
  copy->info = CloneDrawInfo(NULL, original->info);
1183
1179
  if (!copy->info)
@@ -1205,10 +1201,10 @@ Draw_initialize(VALUE self)
1205
1201
  Draw *draw, *draw_options;
1206
1202
  VALUE options;
1207
1203
 
1208
- Data_Get_Struct(self, Draw, draw);
1204
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1209
1205
 
1210
1206
  options = new_DrawOptions();
1211
- Data_Get_Struct(options, Draw, draw_options);
1207
+ TypedData_Get_Struct(options, Draw, &rm_draw_data_type, draw_options);
1212
1208
  draw->info = draw_options->info;
1213
1209
  draw_options->info = NULL;
1214
1210
 
@@ -1229,7 +1225,7 @@ Draw_inspect(VALUE self)
1229
1225
  {
1230
1226
  Draw *draw;
1231
1227
 
1232
- Data_Get_Struct(self, Draw, draw);
1228
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1233
1229
  return draw->primitives ? draw->primitives : rb_str_new2("(no primitives defined)");
1234
1230
  }
1235
1231
 
@@ -1246,7 +1242,7 @@ VALUE Draw_alloc(VALUE class)
1246
1242
 
1247
1243
  draw = ALLOC(Draw);
1248
1244
  memset(draw, 0, sizeof(Draw));
1249
- draw_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw);
1245
+ draw_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw);
1250
1246
 
1251
1247
  RB_GC_GUARD(draw_obj);
1252
1248
 
@@ -1266,7 +1262,7 @@ Draw_primitive(VALUE self, VALUE primitive)
1266
1262
  Draw *draw;
1267
1263
 
1268
1264
  rb_check_frozen(self);
1269
- Data_Get_Struct(self, Draw, draw);
1265
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1270
1266
 
1271
1267
  if (draw->primitives == (VALUE)0)
1272
1268
  {
@@ -1274,13 +1270,32 @@ Draw_primitive(VALUE self, VALUE primitive)
1274
1270
  }
1275
1271
  else
1276
1272
  {
1277
- draw->primitives = rb_str_concat(draw->primitives, rb_str_new2("\n"));
1273
+ draw->primitives = rb_str_plus(draw->primitives, rb_str_new2("\n"));
1278
1274
  draw->primitives = rb_str_concat(draw->primitives, primitive);
1279
1275
  }
1280
1276
 
1281
1277
  return self;
1282
1278
  }
1283
1279
 
1280
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
1281
+ /**
1282
+ * Compact the objects.
1283
+ *
1284
+ * No Ruby usage (internal function)
1285
+ *
1286
+ * @param drawptr pointer to a Draw object
1287
+ */
1288
+ static void
1289
+ Draw_compact(void *drawptr)
1290
+ {
1291
+ Draw *draw = (Draw *)drawptr;
1292
+
1293
+ if (draw->primitives != (VALUE)0)
1294
+ {
1295
+ draw->primitives = rb_gc_location(draw->primitives);
1296
+ }
1297
+ }
1298
+ #endif
1284
1299
 
1285
1300
  /**
1286
1301
  * Mark referenced objects.
@@ -1290,13 +1305,17 @@ Draw_primitive(VALUE self, VALUE primitive)
1290
1305
  * @param drawptr pointer to a Draw object
1291
1306
  */
1292
1307
  static void
1293
- mark_Draw(void *drawptr)
1308
+ Draw_mark(void *drawptr)
1294
1309
  {
1295
1310
  Draw *draw = (Draw *)drawptr;
1296
1311
 
1297
1312
  if (draw->primitives != (VALUE)0)
1298
1313
  {
1314
+ #ifdef HAVE_RB_GC_MARK_MOVABLE
1315
+ rb_gc_mark_movable(draw->primitives);
1316
+ #else
1299
1317
  rb_gc_mark(draw->primitives);
1318
+ #endif
1300
1319
  }
1301
1320
  }
1302
1321
 
@@ -1309,7 +1328,7 @@ mark_Draw(void *drawptr)
1309
1328
  * @param drawptr pointer to a Draw object
1310
1329
  */
1311
1330
  static void
1312
- destroy_Draw(void *drawptr)
1331
+ Draw_destroy(void *drawptr)
1313
1332
  {
1314
1333
  Draw *draw = (Draw *)drawptr;
1315
1334
 
@@ -1333,6 +1352,18 @@ destroy_Draw(void *drawptr)
1333
1352
  xfree(drawptr);
1334
1353
  }
1335
1354
 
1355
+ /**
1356
+ * Get Draw object size.
1357
+ *
1358
+ * No Ruby usage (internal function)
1359
+ *
1360
+ * @param infoptr pointer to the Draw object
1361
+ */
1362
+ static size_t
1363
+ Draw_memsize(const void *drawptr)
1364
+ {
1365
+ return sizeof(Draw);
1366
+ }
1336
1367
 
1337
1368
  /**
1338
1369
  * Allocate & initialize a DrawOptions object.
@@ -1364,7 +1395,7 @@ DrawOptions_alloc(VALUE class)
1364
1395
 
1365
1396
  draw_options = ALLOC(Draw);
1366
1397
  memset(draw_options, 0, sizeof(Draw));
1367
- draw_options_obj = Data_Wrap_Struct(class, mark_Draw, destroy_Draw, draw_options);
1398
+ draw_options_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw_options);
1368
1399
 
1369
1400
  RB_GC_GUARD(draw_options_obj);
1370
1401
 
@@ -1382,26 +1413,16 @@ DrawOptions_initialize(VALUE self)
1382
1413
  {
1383
1414
  Draw *draw_options;
1384
1415
 
1385
- Data_Get_Struct(self, Draw, draw_options);
1416
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw_options);
1386
1417
  draw_options->info = AcquireDrawInfo();
1387
1418
  if (!draw_options->info)
1388
1419
  {
1389
1420
  rb_raise(rb_eNoMemError, "not enough memory to continue");
1390
1421
  }
1391
1422
 
1392
- GetDrawInfo(NULL, draw_options->info);
1393
-
1394
1423
  if (rb_block_given_p())
1395
1424
  {
1396
- if (rb_proc_arity(rb_block_proc()) == 0)
1397
- {
1398
- // Run the block in self's context
1399
- rb_obj_instance_eval(0, NULL, self);
1400
- }
1401
- else
1402
- {
1403
- rb_yield(self);
1404
- }
1425
+ rb_yield(self);
1405
1426
  }
1406
1427
 
1407
1428
  return self;
@@ -1431,7 +1452,7 @@ PolaroidOptions_alloc(VALUE class)
1431
1452
  draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
1432
1453
  (void) DestroyImageInfo(image_info);
1433
1454
 
1434
- polaroid_obj = Data_Wrap_Struct(class, NULL, destroy_Draw, draw);
1455
+ polaroid_obj = TypedData_Wrap_Struct(class, &rm_draw_data_type, draw);
1435
1456
 
1436
1457
  RB_GC_GUARD(polaroid_obj);
1437
1458
 
@@ -1453,7 +1474,7 @@ PolaroidOptions_initialize(VALUE self)
1453
1474
  ExceptionInfo *exception;
1454
1475
 
1455
1476
  // Default shadow color
1456
- Data_Get_Struct(self, Draw, draw);
1477
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1457
1478
 
1458
1479
  exception = AcquireExceptionInfo();
1459
1480
  QueryColorCompliance("gray75", AllCompliance, &draw->shadow_color, exception);
@@ -1464,15 +1485,7 @@ PolaroidOptions_initialize(VALUE self)
1464
1485
 
1465
1486
  if (rb_block_given_p())
1466
1487
  {
1467
- if (rb_proc_arity(rb_block_proc()) == 0)
1468
- {
1469
- // Run the block in self's context
1470
- rb_obj_instance_eval(0, NULL, self);
1471
- }
1472
- else
1473
- {
1474
- rb_yield(self);
1475
- }
1488
+ rb_yield(self);
1476
1489
  }
1477
1490
 
1478
1491
  return self;
@@ -1505,7 +1518,7 @@ PolaroidOptions_shadow_color_eq(VALUE self, VALUE shadow)
1505
1518
  Draw *draw;
1506
1519
 
1507
1520
  rb_check_frozen(self);
1508
- Data_Get_Struct(self, Draw, draw);
1521
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1509
1522
  Color_to_PixelColor(&draw->shadow_color, shadow);
1510
1523
  return shadow;
1511
1524
  }
@@ -1523,7 +1536,7 @@ PolaroidOptions_border_color_eq(VALUE self, VALUE border)
1523
1536
  Draw *draw;
1524
1537
 
1525
1538
  rb_check_frozen(self);
1526
- Data_Get_Struct(self, Draw, draw);
1539
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1527
1540
  Color_to_PixelColor(&draw->info->border_color, border);
1528
1541
  return border;
1529
1542
  }
@@ -1572,6 +1585,9 @@ get_dummy_tm_img(VALUE klass)
1572
1585
  }
1573
1586
 
1574
1587
 
1588
+ // aliases for common use of structure types; GetMultilineTypeMetrics, GetTypeMetrics
1589
+ typedef GVL_STRUCT_TYPE(GetTypeMetrics) GVL_STRUCT_TYPE(get_type_metrics);
1590
+
1575
1591
  /**
1576
1592
  * Call a get-type-metrics function.
1577
1593
  *
@@ -1589,11 +1605,7 @@ get_dummy_tm_img(VALUE klass)
1589
1605
  * @see Draw_get_multiline_type_metrics
1590
1606
  */
1591
1607
  static VALUE
1592
- get_type_metrics(
1593
- int argc,
1594
- VALUE *argv,
1595
- VALUE self,
1596
- get_type_metrics_func_t getter)
1608
+ get_type_metrics(int argc, VALUE *argv, VALUE self, gvl_function_t fp)
1597
1609
  {
1598
1610
  Image *image;
1599
1611
  Draw *draw;
@@ -1601,7 +1613,7 @@ get_type_metrics(
1601
1613
  TypeMetric metrics;
1602
1614
  char *text = NULL;
1603
1615
  long text_l;
1604
- unsigned int okay;
1616
+ MagickBooleanType okay;
1605
1617
  #if defined(IMAGEMAGICK_7)
1606
1618
  ExceptionInfo *exception;
1607
1619
  #endif
@@ -1610,7 +1622,7 @@ get_type_metrics(
1610
1622
  {
1611
1623
  case 1: // use default image
1612
1624
  text = rm_str2cstr(argv[0], &text_l);
1613
- Data_Get_Struct(get_dummy_tm_img(CLASS_OF(self)), Image, image);
1625
+ TypedData_Get_Struct(get_dummy_tm_img(CLASS_OF(self)), Image, &rm_image_data_type, image);
1614
1626
  break;
1615
1627
  case 2:
1616
1628
  t = rm_cur_image(argv[0]);
@@ -1627,7 +1639,7 @@ get_type_metrics(
1627
1639
  rb_raise(rb_eArgError, "no text to measure");
1628
1640
  }
1629
1641
 
1630
- Data_Get_Struct(self, Draw, draw);
1642
+ TypedData_Get_Struct(self, Draw, &rm_draw_data_type, draw);
1631
1643
  #if defined(IMAGEMAGICK_7)
1632
1644
  exception = AcquireExceptionInfo();
1633
1645
  draw->info->text = InterpretImageProperties(NULL, image, text, exception);
@@ -1651,10 +1663,11 @@ get_type_metrics(
1651
1663
  }
1652
1664
 
1653
1665
  #if defined(IMAGEMAGICK_7)
1654
- okay = (*getter)(image, draw->info, &metrics, exception);
1666
+ GVL_STRUCT_TYPE(get_type_metrics) args = { image, draw->info, &metrics, exception };
1655
1667
  #else
1656
- okay = (*getter)(image, draw->info, &metrics);
1668
+ GVL_STRUCT_TYPE(get_type_metrics) args = { image, draw->info, &metrics };
1657
1669
  #endif
1670
+ okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(fp, &args);
1658
1671
 
1659
1672
  magick_free(draw->info->text);
1660
1673
  draw->info->text = NULL;