rmagick 4.2.2 → 5.4.4

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +14 -0
  3. data/.devcontainer/ImageMagick6/devcontainer.json +11 -0
  4. data/.devcontainer/devcontainer.json +11 -0
  5. data/.devcontainer/setup-repo.sh +10 -0
  6. data/.devcontainer/setup-user.sh +45 -0
  7. data/.editorconfig +1 -1
  8. data/.github/workflows/ci.yml +59 -24
  9. data/.gitignore +3 -0
  10. data/.rubocop_todo.yml +0 -1
  11. data/.yardopts +1 -1
  12. data/CHANGELOG.md +131 -0
  13. data/README.md +12 -17
  14. data/Rakefile +53 -81
  15. data/before_install_linux.sh +4 -4
  16. data/before_install_osx.sh +7 -6
  17. data/ext/RMagick/extconf.rb +94 -45
  18. data/ext/RMagick/{rmagick.c → rmagick.cpp} +19 -22
  19. data/ext/RMagick/rmagick.h +90 -60
  20. data/ext/RMagick/rmagick_gvl.h +224 -0
  21. data/ext/RMagick/{rmdraw.c → rmdraw.cpp} +160 -146
  22. data/ext/RMagick/{rmenum.c → rmenum.cpp} +69 -50
  23. data/ext/RMagick/{rmfill.c → rmfill.cpp} +81 -20
  24. data/ext/RMagick/{rmilist.c → rmilist.cpp} +184 -93
  25. data/ext/RMagick/{rmimage.c → rmimage.cpp} +1276 -731
  26. data/ext/RMagick/{rminfo.c → rminfo.cpp} +119 -131
  27. data/ext/RMagick/{rmkinfo.c → rmkinfo.cpp} +41 -16
  28. data/ext/RMagick/rmmain.cpp +1957 -0
  29. data/ext/RMagick/{rmmontage.c → rmmontage.cpp} +49 -28
  30. data/ext/RMagick/{rmpixel.c → rmpixel.cpp} +109 -84
  31. data/ext/RMagick/{rmstruct.c → rmstruct.cpp} +12 -12
  32. data/ext/RMagick/{rmutil.c → rmutil.cpp} +52 -91
  33. data/lib/rmagick/version.rb +3 -1
  34. data/lib/rmagick.rb +2 -0
  35. data/lib/rmagick_internal.rb +9 -48
  36. data/lib/rvg/rvg.rb +2 -2
  37. data/rmagick.gemspec +8 -7
  38. metadata +54 -23
  39. data/.codeclimate.yml +0 -63
  40. data/deprecated/RMagick.rb +0 -6
  41. data/ext/RMagick/rmmain.c +0 -1951
@@ -5,8 +5,8 @@
5
5
  *
6
6
  * Changes since Nov. 2009 copyright © by Benjamin Thomas and Omer Bar-or
7
7
  *
8
- * @file rmilist.c
9
- * @version $Id: rmilist.c,v 1.94 2009/12/20 02:33:33 baror Exp $
8
+ * @file rmilist.cpp
9
+ * @version $Id: rmilist.cpp,v 1.94 2009/12/20 02:33:33 baror Exp $
10
10
  * @author Tim Hunter
11
11
  ******************************************************************************/
12
12
 
@@ -20,7 +20,39 @@ static void imagelist_push(VALUE, VALUE);
20
20
  static VALUE ImageList_new(void);
21
21
 
22
22
 
23
+ DEFINE_GVL_STUB3(AppendImages, const Image *, const MagickBooleanType, ExceptionInfo *);
24
+ DEFINE_GVL_STUB5(CloneImage, const Image *, const size_t, const size_t, const MagickBooleanType, ExceptionInfo *);
25
+ DEFINE_GVL_STUB2(CloneImageList, const Image *, ExceptionInfo *);
26
+ DEFINE_GVL_STUB2(CoalesceImages, const Image *, ExceptionInfo *);
27
+ DEFINE_GVL_STUB2(DisposeImages, const Image *, ExceptionInfo *);
28
+ DEFINE_GVL_STUB3(EvaluateImages, const Image *, const MagickEvaluateOperator, ExceptionInfo *);
29
+ DEFINE_GVL_STUB4(ImagesToBlob, const ImageInfo *, Image *, size_t *, ExceptionInfo *);
30
+ DEFINE_GVL_STUB3(MergeImageLayers, Image *, const LayerMethod, ExceptionInfo *);
31
+ DEFINE_GVL_STUB3(MontageImages, const Image *, const MontageInfo *, ExceptionInfo *);
32
+ DEFINE_GVL_STUB3(MorphImages, const Image *, const size_t, ExceptionInfo *);
33
+ DEFINE_GVL_STUB2(OptimizeImageLayers, const Image *, ExceptionInfo *);
34
+ DEFINE_GVL_STUB2(OptimizePlusImageLayers, const Image *, ExceptionInfo *);
35
+ #if defined(IMAGEMAGICK_7)
36
+ DEFINE_GVL_STUB3(AnimateImages, const ImageInfo *, Image *, ExceptionInfo *);
37
+ DEFINE_GVL_STUB3(CombineImages, const Image *, const ColorspaceType, ExceptionInfo *);
38
+ DEFINE_GVL_STUB3(CompareImagesLayers, const Image *, const LayerMethod, ExceptionInfo *);
39
+ DEFINE_GVL_STUB3(QuantizeImages, const QuantizeInfo *, Image *, ExceptionInfo *);
40
+ DEFINE_GVL_STUB4(RemapImages, const QuantizeInfo *, Image *, const Image *, ExceptionInfo *);
41
+ DEFINE_GVL_STUB3(WriteImage, const ImageInfo *, Image *, ExceptionInfo *);
42
+ #else
43
+ DEFINE_GVL_STUB2(AnimateImages, const ImageInfo *, Image *);
44
+ DEFINE_GVL_STUB3(CombineImages, const Image *, const ChannelType, ExceptionInfo *);
45
+ DEFINE_GVL_STUB3(CompareImageLayers, const Image *, const ImageLayerMethod, ExceptionInfo *);
46
+ DEFINE_GVL_STUB2(DeconstructImages, const Image *, ExceptionInfo *);
47
+ DEFINE_GVL_STUB2(QuantizeImages, const QuantizeInfo *, Image *);
48
+ DEFINE_GVL_STUB3(RemapImages, const QuantizeInfo *, Image *, const Image *);
49
+ DEFINE_GVL_STUB2(WriteImage, const ImageInfo *, Image *);
50
+ #endif
23
51
 
52
+ DEFINE_GVL_VOID_STUB6(CompositeLayers, Image *, const CompositeOperator, Image *, const ssize_t, const ssize_t, ExceptionInfo *);
53
+ DEFINE_GVL_VOID_STUB2(OptimizeImageTransparency, const Image *, ExceptionInfo *);
54
+ DEFINE_GVL_VOID_STUB2(RemoveDuplicateLayers, Image **, ExceptionInfo *);
55
+ DEFINE_GVL_VOID_STUB2(RemoveZeroDelayLayers, Image **, ExceptionInfo *);
24
56
 
25
57
 
26
58
  /**
@@ -72,15 +104,17 @@ ImageList_animate(int argc, VALUE *argv, VALUE self)
72
104
  }
73
105
  }
74
106
 
75
- Data_Get_Struct(info_obj, Info, info);
107
+ TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info);
76
108
  #if defined(IMAGEMAGICK_7)
77
109
  exception = AcquireExceptionInfo();
78
- AnimateImages(info, images, exception);
110
+ GVL_STRUCT_TYPE(AnimateImages) args = { info, images, exception };
111
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AnimateImages), &args);
79
112
  rm_split(images);
80
113
  CHECK_EXCEPTION();
81
114
  DestroyExceptionInfo(exception);
82
115
  #else
83
- AnimateImages(info, images);
116
+ GVL_STRUCT_TYPE(AnimateImages) args = { info, images };
117
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AnimateImages), &args);
84
118
  rm_split(images);
85
119
  rm_check_image_exception(images, RetainOnError);
86
120
  #endif
@@ -101,7 +135,7 @@ VALUE
101
135
  ImageList_append(VALUE self, VALUE stack_arg)
102
136
  {
103
137
  Image *images, *new_image;
104
- unsigned int stack;
138
+ MagickBooleanType stack;
105
139
  ExceptionInfo *exception;
106
140
 
107
141
  // Convert the image array to an image sequence.
@@ -109,10 +143,11 @@ ImageList_append(VALUE self, VALUE stack_arg)
109
143
 
110
144
  // If stack == true, stack rectangular images top-to-bottom,
111
145
  // otherwise left-to-right.
112
- stack = RTEST(stack_arg);
146
+ stack = (MagickBooleanType)RTEST(stack_arg);
113
147
 
114
148
  exception = AcquireExceptionInfo();
115
- new_image = AppendImages(images, stack, exception);
149
+ GVL_STRUCT_TYPE(AppendImages) args = { images, stack, exception };
150
+ new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AppendImages), &args);
116
151
  rm_split(images);
117
152
  rm_check_exception(exception, new_image, DestroyOnError);
118
153
  DestroyExceptionInfo(exception);
@@ -136,8 +171,8 @@ ImageList_average(VALUE self)
136
171
  images = images_from_imagelist(self);
137
172
 
138
173
  exception = AcquireExceptionInfo();
139
- new_image = EvaluateImages(images, MeanEvaluateOperator, exception);
140
-
174
+ GVL_STRUCT_TYPE(EvaluateImages) args = { images, MeanEvaluateOperator, exception };
175
+ new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EvaluateImages), &args);
141
176
  rm_split(images);
142
177
  rm_check_exception(exception, new_image, DestroyOnError);
143
178
  DestroyExceptionInfo(exception);
@@ -164,7 +199,8 @@ ImageList_coalesce(VALUE self)
164
199
  images = images_from_imagelist(self);
165
200
 
166
201
  exception = AcquireExceptionInfo();
167
- new_images = CoalesceImages(images, exception);
202
+ GVL_STRUCT_TYPE(CoalesceImages) args = { images, exception };
203
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CoalesceImages), &args);
168
204
  rm_split(images);
169
205
  rm_check_exception(exception, new_images, DestroyOnError);
170
206
  DestroyExceptionInfo(exception);
@@ -224,20 +260,20 @@ VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
224
260
  {
225
261
  case 5:
226
262
  if (colorspace == CMYKColorspace)
227
- channel |= AlphaChannel;
263
+ channel = (ChannelType)(channel | AlphaChannel);
228
264
  else
229
265
  rb_raise(rb_eArgError, "invalid number of images in this image list");
230
266
  case 4:
231
267
  if (colorspace == CMYKColorspace)
232
- channel |= IndexChannel;
268
+ channel = (ChannelType)(channel | IndexChannel);
233
269
  else
234
- channel |= AlphaChannel;
270
+ channel = (ChannelType)(channel | AlphaChannel);
235
271
  case 3:
236
- channel |= GreenChannel;
237
- channel |= BlueChannel;
272
+ channel = (ChannelType)(channel | GreenChannel);
273
+ channel = (ChannelType)(channel | BlueChannel);
238
274
  break;
239
275
  case 2:
240
- channel |= AlphaChannel;
276
+ channel = (ChannelType)(channel | AlphaChannel);
241
277
  break;
242
278
  case 1:
243
279
  break;
@@ -252,10 +288,11 @@ VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
252
288
  #if defined(IMAGEMAGICK_6)
253
289
  old_colorspace = images->colorspace;
254
290
  SetImageColorspace(images, colorspace);
255
- new_image = CombineImages(images, channel, exception);
291
+ GVL_STRUCT_TYPE(CombineImages) args = { images, channel, exception };
256
292
  #else
257
- new_image = CombineImages(images, colorspace, exception);
293
+ GVL_STRUCT_TYPE(CombineImages) args = { images, colorspace, exception };
258
294
  #endif
295
+ new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CombineImages), &args);
259
296
 
260
297
  rm_split(images);
261
298
  #if defined(IMAGEMAGICK_6)
@@ -274,10 +311,10 @@ VALUE ImageList_combine(int argc, VALUE *argv, VALUE self)
274
311
  * @overload composite_layers(images)
275
312
  * @param images [Magick::ImageList] the source images
276
313
  *
277
- * @overload composite_layers(images, operator)
314
+ * @overload composite_layers(images, composite_op)
278
315
  * - Default operator is {Magick::OverCompositeOp}
279
316
  * @param images [Magick::ImageList] the source images
280
- * @param operator [Magick::CompositeOperator] the operator
317
+ * @param composite_op [Magick::CompositeOperator] the operator
281
318
  *
282
319
  * @return [Magick::ImageList] a new imagelist
283
320
  */
@@ -287,13 +324,13 @@ ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
287
324
  VALUE source_images;
288
325
  Image *dest, *source, *new_images;
289
326
  RectangleInfo geometry;
290
- CompositeOperator operator = OverCompositeOp;
327
+ CompositeOperator composite_op = OverCompositeOp;
291
328
  ExceptionInfo *exception;
292
329
 
293
330
  switch (argc)
294
331
  {
295
332
  case 2:
296
- VALUE_TO_ENUM(argv[1], operator, CompositeOperator);
333
+ VALUE_TO_ENUM(argv[1], composite_op, CompositeOperator);
297
334
  case 1:
298
335
  source_images = argv[0];
299
336
  break;
@@ -319,7 +356,8 @@ ImageList_composite_layers(int argc, VALUE *argv, VALUE self)
319
356
  new_images->gravity, &geometry);
320
357
 
321
358
  exception = AcquireExceptionInfo();
322
- CompositeLayers(new_images, operator, source, geometry.x, geometry.y, exception);
359
+ GVL_STRUCT_TYPE(CompositeLayers) args = { new_images, composite_op, source, geometry.x, geometry.y, exception };
360
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeLayers), &args);
323
361
  rm_split(source);
324
362
  rm_check_exception(exception, new_images, DestroyOnError);
325
363
  DestroyExceptionInfo(exception);
@@ -345,9 +383,11 @@ ImageList_deconstruct(VALUE self)
345
383
  images = images_from_imagelist(self);
346
384
  exception = AcquireExceptionInfo();
347
385
  #if defined(IMAGEMAGICK_7)
348
- new_images = CompareImagesLayers(images, CompareAnyLayer, exception);
386
+ GVL_STRUCT_TYPE(CompareImagesLayers) args = { images, CompareAnyLayer, exception };
387
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImagesLayers), &args);
349
388
  #else
350
- new_images = DeconstructImages(images, exception);
389
+ GVL_STRUCT_TYPE(DeconstructImages) args = { images, exception };
390
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DeconstructImages), &args);
351
391
  #endif
352
392
  rm_split(images);
353
393
  rm_check_exception(exception, new_images, DestroyOnError);
@@ -374,7 +414,7 @@ ImageList_display(VALUE self)
374
414
 
375
415
  // Create a new Info object to use with this call
376
416
  info_obj = rm_info_new();
377
- Data_Get_Struct(info_obj, Info, info);
417
+ TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info);
378
418
 
379
419
  // Convert the images array to an images sequence.
380
420
  images = images_from_imagelist(self);
@@ -410,7 +450,8 @@ ImageList_flatten_images(VALUE self)
410
450
  images = images_from_imagelist(self);
411
451
  exception = AcquireExceptionInfo();
412
452
 
413
- new_image = MergeImageLayers(images, FlattenLayer, exception);
453
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, FlattenLayer, exception };
454
+ new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
414
455
 
415
456
  rm_split(images);
416
457
  rm_check_exception(exception, new_image, DestroyOnError);
@@ -428,8 +469,8 @@ ImageList_flatten_images(VALUE self)
428
469
  * @overload montage
429
470
  * Creates {Magick::ImageList::Montage} object, yields to block
430
471
  * if present in {Magick::ImageList::Montage} object's scope.
431
- * @yield []
432
- *
472
+ * @yield [Magick::ImageList::Montage]
473
+ *
433
474
  * @return [Magick::ImageList] a new image list
434
475
  */
435
476
  VALUE
@@ -440,23 +481,14 @@ ImageList_montage(VALUE self)
440
481
  Image *new_images, *images;
441
482
  ExceptionInfo *exception;
442
483
 
443
- // Create a new instance of the Magick::Montage class
484
+ // Create a new instance of the Magick::ImageList::Montage class
444
485
  montage_obj = rm_montage_new();
445
486
  if (rb_block_given_p())
446
487
  {
447
- // Run the block in the instance's context, allowing the app to modify the
448
- // object's attributes.
449
- if (rb_proc_arity(rb_block_proc()) == 0)
450
- {
451
- rb_obj_instance_eval(0, NULL, montage_obj);
452
- }
453
- else
454
- {
455
- rb_yield(montage_obj);
456
- }
488
+ rb_yield(montage_obj);
457
489
  }
458
490
 
459
- Data_Get_Struct(montage_obj, Montage, montage);
491
+ TypedData_Get_Struct(montage_obj, Montage, &rm_montage_data_type, montage);
460
492
 
461
493
  images = images_from_imagelist(self);
462
494
 
@@ -475,7 +507,8 @@ ImageList_montage(VALUE self)
475
507
  exception = AcquireExceptionInfo();
476
508
 
477
509
  // MontageImage can return more than one image.
478
- new_images = MontageImages(images, montage->info, exception);
510
+ GVL_STRUCT_TYPE(MontageImages) args = { images, montage->info, exception };
511
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MontageImages), &args);
479
512
  rm_split(images);
480
513
  rm_check_exception(exception, new_images, DestroyOnError);
481
514
  DestroyExceptionInfo(exception);
@@ -499,19 +532,20 @@ ImageList_morph(VALUE self, VALUE nimages)
499
532
  {
500
533
  Image *images, *new_images;
501
534
  ExceptionInfo *exception;
502
- long number_images;
535
+ size_t number_images;
503
536
 
504
537
 
505
538
  // Use a signed long so we can test for a negative argument.
506
- number_images = NUM2LONG(nimages);
507
- if (number_images <= 0)
539
+ if (NUM2LONG(nimages) <= 0)
508
540
  {
509
541
  rb_raise(rb_eArgError, "number of intervening images must be > 0");
510
542
  }
511
543
 
544
+ number_images = NUM2LONG(nimages);
512
545
  images = images_from_imagelist(self);
513
546
  exception = AcquireExceptionInfo();
514
- new_images = MorphImages(images, (unsigned long)number_images, exception);
547
+ GVL_STRUCT_TYPE(MorphImages) args = { images, number_images, exception };
548
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MorphImages), &args);
515
549
  rm_split(images);
516
550
  rm_check_exception(exception, new_images, DestroyOnError);
517
551
  DestroyExceptionInfo(exception);
@@ -534,7 +568,8 @@ ImageList_mosaic(VALUE self)
534
568
  images = images_from_imagelist(self);
535
569
 
536
570
  exception = AcquireExceptionInfo();
537
- new_image = MergeImageLayers(images, MosaicLayer, exception);
571
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, MosaicLayer, exception };
572
+ new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
538
573
 
539
574
  rm_split(images);
540
575
  rm_check_exception(exception, new_image, DestroyOnError);
@@ -568,22 +603,37 @@ ImageList_optimize_layers(VALUE self, VALUE method)
568
603
  switch (mthd)
569
604
  {
570
605
  case CoalesceLayer:
571
- new_images = CoalesceImages(images, exception);
606
+ {
607
+ GVL_STRUCT_TYPE(CoalesceImages) args = { images, exception };
608
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CoalesceImages), &args);
609
+ }
572
610
  break;
573
611
  case DisposeLayer:
574
- new_images = DisposeImages(images, exception);
612
+ {
613
+ GVL_STRUCT_TYPE(DisposeImages) args = { images, exception };
614
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DisposeImages), &args);
615
+ }
575
616
  break;
576
617
  case OptimizeTransLayer:
577
- new_images = clone_imagelist(images);
578
- OptimizeImageTransparency(new_images, exception);
618
+ {
619
+ new_images = clone_imagelist(images);
620
+ GVL_STRUCT_TYPE(OptimizeImageTransparency) args = { new_images, exception };
621
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OptimizeImageTransparency), &args);
622
+ }
579
623
  break;
580
624
  case RemoveDupsLayer:
581
- new_images = clone_imagelist(images);
582
- RemoveDuplicateLayers(&new_images, exception);
625
+ {
626
+ new_images = clone_imagelist(images);
627
+ GVL_STRUCT_TYPE(RemoveDuplicateLayers) args = { &new_images, exception };
628
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemoveDuplicateLayers), &args);
629
+ }
583
630
  break;
584
631
  case RemoveZeroLayer:
585
- new_images = clone_imagelist(images);
586
- RemoveZeroDelayLayers(&new_images, exception);
632
+ {
633
+ new_images = clone_imagelist(images);
634
+ GVL_STRUCT_TYPE(RemoveZeroDelayLayers) args = { &new_images, exception };
635
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemoveZeroDelayLayers), &args);
636
+ }
587
637
  break;
588
638
  case CompositeLayer:
589
639
  rm_split(images);
@@ -592,50 +642,81 @@ ImageList_optimize_layers(VALUE self, VALUE method)
592
642
  break;
593
643
  // In 6.3.4-ish, OptimizeImageLayer replaced OptimizeLayer
594
644
  case OptimizeImageLayer:
595
- new_images = OptimizeImageLayers(images, exception);
645
+ {
646
+ GVL_STRUCT_TYPE(OptimizeImageLayers) args = { images, exception };
647
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OptimizeImageLayers), &args);
648
+ }
596
649
  break;
597
650
  // and OptimizeLayer became a "General Purpose, GIF Animation Optimizer" (ref. mogrify.c)
598
651
  case OptimizeLayer:
599
- new_images = CoalesceImages(images, exception);
600
- rm_split(images);
601
- rm_check_exception(exception, new_images, DestroyOnError);
602
- new_images2 = OptimizeImageLayers(new_images, exception);
603
- DestroyImageList(new_images);
604
- rm_check_exception(exception, new_images2, DestroyOnError);
605
- new_images = new_images2;
606
- OptimizeImageTransparency(new_images, exception);
607
- rm_check_exception(exception, new_images, DestroyOnError);
608
- // mogrify supports -dither here. We don't.
609
- GetQuantizeInfo(&quantize_info);
652
+ {
653
+ GVL_STRUCT_TYPE(CoalesceImages) args_CoalesceImages = { images, exception };
654
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CoalesceImages), &args_CoalesceImages);
655
+ rm_split(images);
656
+ rm_check_exception(exception, new_images, DestroyOnError);
657
+
658
+ GVL_STRUCT_TYPE(OptimizeImageLayers) args_OptimizeImageLayers = { new_images, exception };
659
+ new_images2 = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OptimizeImageLayers), &args_OptimizeImageLayers);
660
+ DestroyImageList(new_images);
661
+ rm_check_exception(exception, new_images2, DestroyOnError);
662
+
663
+ new_images = new_images2;
664
+ GVL_STRUCT_TYPE(OptimizeImageTransparency) args_OptimizeImageTransparency = { new_images, exception };
665
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OptimizeImageTransparency), &args_OptimizeImageTransparency);
666
+ rm_check_exception(exception, new_images, DestroyOnError);
667
+ // mogrify supports -dither here. We don't.
668
+ GetQuantizeInfo(&quantize_info);
610
669
  #if defined(IMAGEMAGICK_7)
611
- RemapImages(&quantize_info, new_images, NULL, exception);
670
+ GVL_STRUCT_TYPE(RemapImages) args_RemapImages = { &quantize_info, new_images, NULL, exception };
612
671
  #else
613
- RemapImages(&quantize_info, new_images, NULL);
672
+ GVL_STRUCT_TYPE(RemapImages) args_RemapImages = { &quantize_info, new_images, NULL };
614
673
  #endif
674
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemapImages), &args_RemapImages);
675
+
676
+ }
615
677
  break;
616
678
  case OptimizePlusLayer:
617
- new_images = OptimizePlusImageLayers(images, exception);
679
+ {
680
+ GVL_STRUCT_TYPE(OptimizePlusImageLayers) args = { images, exception };
681
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OptimizePlusImageLayers), &args);
682
+ }
618
683
  break;
619
684
  case CompareAnyLayer:
620
685
  case CompareClearLayer:
621
686
  case CompareOverlayLayer:
687
+ {
622
688
  #if defined(IMAGEMAGICK_7)
623
- new_images = CompareImagesLayers(images, mthd, exception);
689
+ GVL_STRUCT_TYPE(CompareImagesLayers) args = { images, mthd, exception };
690
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImagesLayers), &args);
624
691
  #else
625
- new_images = CompareImageLayers(images, mthd, exception);
692
+ GVL_STRUCT_TYPE(CompareImageLayers) args = { images, mthd, exception };
693
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImageLayers), &args);
626
694
  #endif
695
+ }
627
696
  break;
628
697
  case MosaicLayer:
629
- new_images = MergeImageLayers(images, mthd, exception);
698
+ {
699
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, mthd, exception };
700
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
701
+ }
630
702
  break;
631
703
  case FlattenLayer:
632
- new_images = MergeImageLayers(images, mthd, exception);
704
+ {
705
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, mthd, exception };
706
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
707
+ }
633
708
  break;
634
709
  case MergeLayer:
635
- new_images = MergeImageLayers(images, mthd, exception);
710
+ {
711
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, mthd, exception };
712
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
713
+ }
636
714
  break;
637
715
  case TrimBoundsLayer:
638
- new_images = MergeImageLayers(images, mthd, exception);
716
+ {
717
+ GVL_STRUCT_TYPE(MergeImageLayers) args = { images, mthd, exception };
718
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MergeImageLayers), &args);
719
+ }
639
720
  break;
640
721
  default:
641
722
  rm_split(images);
@@ -833,7 +914,8 @@ clone_imagelist(Image *images)
833
914
  {
834
915
  Image *clone;
835
916
 
836
- clone = CloneImage(image, 0, 0, MagickTrue, exception);
917
+ GVL_STRUCT_TYPE(CloneImage) args = { image, 0, 0, MagickTrue, exception };
918
+ clone = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CloneImage), &args);
837
919
  rm_check_exception(exception, new_imagelist, DestroyOnError);
838
920
  AppendImageToList(&new_imagelist, clone);
839
921
  image = GetNextImageInList(image);
@@ -888,7 +970,7 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
888
970
  if (rb_obj_is_kind_of(argv[2], Class_DitherMethod))
889
971
  {
890
972
  VALUE_TO_ENUM(argv[2], quantize_info.dither_method, DitherMethod);
891
- quantize_info.dither = quantize_info.dither_method != NoDitherMethod;
973
+ quantize_info.dither = (MagickBooleanType)(quantize_info.dither_method != NoDitherMethod);
892
974
  }
893
975
  else
894
976
  {
@@ -910,17 +992,19 @@ ImageList_quantize(int argc, VALUE *argv, VALUE self)
910
992
  // Convert image array to image sequence, clone image sequence.
911
993
  images = images_from_imagelist(self);
912
994
  exception = AcquireExceptionInfo();
913
- new_images = CloneImageList(images, exception);
995
+ GVL_STRUCT_TYPE(CloneImageList) args_CloneImageList = { images, exception };
996
+ new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CloneImageList), &args_CloneImageList);
914
997
  rm_split(images);
915
998
  rm_check_exception(exception, new_images, DestroyOnError);
916
999
 
917
1000
  rm_ensure_result(new_images);
918
1001
 
919
1002
  #if defined(IMAGEMAGICK_7)
920
- QuantizeImages(&quantize_info, new_images, exception);
1003
+ GVL_STRUCT_TYPE(QuantizeImages) args_QuantizeImages = { &quantize_info, new_images, exception };
921
1004
  #else
922
- QuantizeImages(&quantize_info, new_images);
1005
+ GVL_STRUCT_TYPE(QuantizeImages) args_QuantizeImages = { &quantize_info, new_images };
923
1006
  #endif
1007
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(QuantizeImages), &args_QuantizeImages);
924
1008
  rm_check_exception(exception, new_images, DestroyOnError);
925
1009
  DestroyExceptionInfo(exception);
926
1010
 
@@ -987,12 +1071,14 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
987
1071
 
988
1072
  #if defined(IMAGEMAGICK_7)
989
1073
  exception = AcquireExceptionInfo();
990
- RemapImages(&quantize_info, images, remap_image, exception);
1074
+ GVL_STRUCT_TYPE(RemapImages) args = { &quantize_info, images, remap_image, exception };
1075
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemapImages), &args);
991
1076
  rm_split(images);
992
1077
  CHECK_EXCEPTION();
993
1078
  DestroyExceptionInfo(exception);
994
1079
  #else
995
- RemapImages(&quantize_info, images, remap_image);
1080
+ GVL_STRUCT_TYPE(RemapImages) args = { &quantize_info, images, remap_image };
1081
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemapImages), &args);
996
1082
  rm_split(images);
997
1083
  rm_check_image_exception(images, RetainOnError);
998
1084
  #endif
@@ -1008,7 +1094,7 @@ ImageList_remap(int argc, VALUE *argv, VALUE self)
1008
1094
  *
1009
1095
  * @overload to_blob
1010
1096
  * Runs an info parm block if present - the user can specify the image format and depth
1011
- * @yield []
1097
+ * @yield [Magick::Image::Info]
1012
1098
  *
1013
1099
  * @return [String] the blob
1014
1100
  */
@@ -1024,7 +1110,7 @@ ImageList_to_blob(VALUE self)
1024
1110
  ExceptionInfo *exception;
1025
1111
 
1026
1112
  info_obj = rm_info_new();
1027
- Data_Get_Struct(info_obj, Info, info);
1113
+ TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info);
1028
1114
 
1029
1115
  // Convert the images array to an images sequence.
1030
1116
  images = images_from_imagelist(self);
@@ -1051,7 +1137,8 @@ ImageList_to_blob(VALUE self)
1051
1137
  // can happen is that there's only one image or the format
1052
1138
  // doesn't support multi-image files.
1053
1139
  info->adjoin = MagickTrue;
1054
- blob = ImagesToBlob(info, images, &length, exception);
1140
+ GVL_STRUCT_TYPE(ImagesToBlob) args = { info, images, &length, exception };
1141
+ blob = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImagesToBlob), &args);
1055
1142
  if (blob && exception->severity >= ErrorException)
1056
1143
  {
1057
1144
  magick_free((void*)blob);
@@ -1068,7 +1155,7 @@ ImageList_to_blob(VALUE self)
1068
1155
  return Qnil;
1069
1156
  }
1070
1157
 
1071
- blob_str = rb_str_new(blob, (long)length);
1158
+ blob_str = rb_str_new((const char *)blob, (long)length);
1072
1159
  magick_free((void*)blob);
1073
1160
 
1074
1161
  RB_GC_GUARD(info_obj);
@@ -1097,7 +1184,7 @@ ImageList_write(VALUE self, VALUE file)
1097
1184
  ExceptionInfo *exception;
1098
1185
 
1099
1186
  info_obj = rm_info_new();
1100
- Data_Get_Struct(info_obj, Info, info);
1187
+ TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info);
1101
1188
 
1102
1189
 
1103
1190
  if (TYPE(file) == T_FILE)
@@ -1106,8 +1193,10 @@ ImageList_write(VALUE self, VALUE file)
1106
1193
 
1107
1194
  // Ensure file is open - raise error if not
1108
1195
  GetOpenFile(file, fptr);
1196
+ rb_io_check_writable(fptr);
1197
+
1198
+ add_format_prefix(info, rm_io_path(file));
1109
1199
  #if defined(_WIN32)
1110
- add_format_prefix(info, fptr->pathv);
1111
1200
  SetImageInfoFile(info, NULL);
1112
1201
  #else
1113
1202
  SetImageInfoFile(info, rb_io_stdio_file(fptr));
@@ -1142,7 +1231,7 @@ ImageList_write(VALUE self, VALUE file)
1142
1231
  #endif
1143
1232
 
1144
1233
  // Tell WriteImage if we want a multi-images file.
1145
- if (imagelist_length(self) > 1L && GetMagickAdjoin(m))
1234
+ if (imagelist_length(self) > 1L && m && GetMagickAdjoin(m))
1146
1235
  {
1147
1236
  info->adjoin = MagickTrue;
1148
1237
  }
@@ -1151,10 +1240,12 @@ ImageList_write(VALUE self, VALUE file)
1151
1240
  {
1152
1241
  rm_sync_image_options(img, info);
1153
1242
  #if defined(IMAGEMAGICK_7)
1154
- WriteImage(info, img, exception);
1243
+ GVL_STRUCT_TYPE(WriteImage) args = { info, img, exception };
1244
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(WriteImage), &args);
1155
1245
  rm_check_exception(exception, img, RetainOnError);
1156
1246
  #else
1157
- WriteImage(info, img);
1247
+ GVL_STRUCT_TYPE(WriteImage) args = { info, img };
1248
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(WriteImage), &args);
1158
1249
  // images will be split before raising an exception
1159
1250
  rm_check_image_exception(images, RetainOnError);
1160
1251
  #endif