rmagick 5.4.4 → 6.0.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.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/ImageMagick6/devcontainer.json +1 -1
  3. data/.devcontainer/devcontainer.json +1 -1
  4. data/.github/workflows/ci.yml +41 -31
  5. data/.gitignore +1 -0
  6. data/.rubocop.yml +36 -9
  7. data/.rubocop_todo.yml +369 -187
  8. data/CHANGELOG.md +77 -0
  9. data/Gemfile +14 -0
  10. data/README.md +3 -3
  11. data/Rakefile +12 -1
  12. data/before_install_linux.sh +1 -11
  13. data/before_install_osx.sh +5 -7
  14. data/ext/RMagick/extconf.rb +58 -68
  15. data/ext/RMagick/rmagick.h +7 -12
  16. data/ext/RMagick/rmdraw.cpp +10 -20
  17. data/ext/RMagick/rmfill.cpp +4 -4
  18. data/ext/RMagick/rmilist.cpp +10 -2
  19. data/ext/RMagick/rmimage.cpp +342 -344
  20. data/ext/RMagick/rminfo.cpp +22 -21
  21. data/ext/RMagick/rmkinfo.cpp +5 -18
  22. data/ext/RMagick/rmmain.cpp +42 -91
  23. data/ext/RMagick/rmmontage.cpp +5 -5
  24. data/ext/RMagick/rmpixel.cpp +3 -3
  25. data/ext/RMagick/rmutil.cpp +58 -89
  26. data/lib/rmagick/version.rb +3 -3
  27. data/lib/rmagick.rb +1 -1
  28. data/lib/rmagick_internal.rb +111 -103
  29. data/lib/rvg/container.rb +3 -3
  30. data/lib/rvg/embellishable.rb +7 -3
  31. data/lib/rvg/misc.rb +15 -15
  32. data/lib/rvg/rvg.rb +6 -6
  33. data/lib/rvg/stretchable.rb +2 -2
  34. data/lib/rvg/stylable.rb +2 -2
  35. data/lib/rvg/transformable.rb +1 -1
  36. data/lib/rvg/units.rb +1 -0
  37. data/rmagick.gemspec +2 -15
  38. data/sig/rmagick/_draw_common_methods.rbs +64 -0
  39. data/sig/rmagick/_image_common_methods.rbs +387 -0
  40. data/sig/rmagick/draw.rbs +38 -0
  41. data/sig/rmagick/draw_attribute.rbs +28 -0
  42. data/sig/rmagick/enum.rbs +820 -0
  43. data/sig/rmagick/error.rbs +11 -0
  44. data/sig/rmagick/fill.rbs +21 -0
  45. data/sig/rmagick/geometry.rbs +14 -0
  46. data/sig/rmagick/image.rbs +196 -0
  47. data/sig/rmagick/image_list.rbs +183 -0
  48. data/sig/rmagick/iptc.rbs +101 -0
  49. data/sig/rmagick/kernel_info.rbs +12 -0
  50. data/sig/rmagick/optional_method_arguments.rbs +10 -0
  51. data/sig/rmagick/pixel.rbs +46 -0
  52. data/sig/rmagick/struct.rbs +90 -0
  53. data/sig/rmagick.rbs +43 -0
  54. data/sig/rvg/clippath.rbs +34 -0
  55. data/sig/rvg/container.rbs +78 -0
  56. data/sig/rvg/deep_equal.rbs +48 -0
  57. data/sig/rvg/describable.rbs +30 -0
  58. data/sig/rvg/embellishable.rbs +226 -0
  59. data/sig/rvg/misc.rbs +145 -0
  60. data/sig/rvg/paint.rbs +55 -0
  61. data/sig/rvg/pathdata.rbs +77 -0
  62. data/sig/rvg/rvg.rbs +125 -0
  63. data/sig/rvg/stretchable.rbs +56 -0
  64. data/sig/rvg/stylable.rbs +66 -0
  65. data/sig/rvg/text.rbs +118 -0
  66. data/sig/rvg/transformable.rbs +59 -0
  67. data/sig/rvg/units.rbs +33 -0
  68. metadata +38 -134
@@ -21,6 +21,11 @@
21
21
  static VALUE rescue_not_str(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN;
22
22
  static void handle_exception(ExceptionInfo *, Image *, ErrorRetention);
23
23
 
24
+ #if defined(IMAGEMAGICK_7)
25
+ DEFINE_GVL_STUB3(TransformImageColorspace, Image *, const ColorspaceType, ExceptionInfo *);
26
+ #else
27
+ DEFINE_GVL_STUB2(TransformImageColorspace, Image *, const ColorspaceType);
28
+ #endif
24
29
 
25
30
  DEFINE_GVL_STUB5(CloneImage, const Image *, const size_t, const size_t, const MagickBooleanType, ExceptionInfo *);
26
31
 
@@ -360,49 +365,22 @@ rescue_not_str(VALUE arg, VALUE raised_exc ATTRIBUTE_UNUSED)
360
365
  *
361
366
  * @param arg the argument
362
367
  * @param max the maximum allowed value
368
+ * @param only_positive Accept whether only positive numbers?
363
369
  * @return a double
364
370
  */
365
371
  double
366
- rm_percentage(VALUE arg, double max)
372
+ rm_percentage2(VALUE arg, double max, bool only_positive)
367
373
  {
368
374
  double pct;
369
- char *end;
370
375
 
371
376
  if (!rm_check_num2dbl(arg))
372
377
  {
373
- char *pct_str;
374
- long pct_long;
375
-
376
- arg = rb_rescue(RESCUE_FUNC(rb_str_to_str), arg, RESCUE_EXCEPTION_HANDLER_FUNC(rescue_not_str), arg);
377
- pct_str = StringValueCStr(arg);
378
- errno = 0;
379
- pct_long = strtol(pct_str, &end, 10);
380
- if (errno == ERANGE)
381
- {
382
- rb_raise(rb_eRangeError, "`%s' out of range", pct_str);
383
- }
384
- if (*end != '\0' && *end != '%')
385
- {
386
- rb_raise(rb_eArgError, "expected percentage, got `%s'", pct_str);
387
- }
388
-
389
- if (*end == '%' && pct_long != 0)
390
- {
391
- pct = (((double)pct_long) / 100.0) * max;
392
- }
393
- else
394
- {
395
- pct = (double) pct_long;
396
- }
397
- if (pct < 0.0)
398
- {
399
- rb_raise(rb_eArgError, "percentages may not be negative (got `%s')", pct_str);
400
- }
378
+ pct = rm_str_to_pct(arg, only_positive) * max;
401
379
  }
402
380
  else
403
381
  {
404
382
  pct = NUM2DBL(arg);
405
- if (pct < 0.0)
383
+ if (pct < 0.0 && only_positive)
406
384
  {
407
385
  rb_raise(rb_eArgError, "percentages may not be negative (got `%g')", pct);
408
386
  }
@@ -412,6 +390,24 @@ rm_percentage(VALUE arg, double max)
412
390
  }
413
391
 
414
392
 
393
+ /**
394
+ * Return a double between 0.0 and max (the second argument), inclusive. If the
395
+ * argument is a number convert to a Float object, otherwise it's supposed to be
396
+ * a string in the form * "NN%". Convert to a number and then to a Float.
397
+ *
398
+ * No Ruby usage (internal function)
399
+ *
400
+ * @param arg the argument
401
+ * @param max the maximum allowed value
402
+ * @return a double
403
+ */
404
+ double
405
+ rm_percentage(VALUE arg, double max)
406
+ {
407
+ return rm_percentage2(arg, max, true);
408
+ }
409
+
410
+
415
411
  /**
416
412
  * Return 0 if rb_num2dbl doesn't raise an exception.
417
413
  *
@@ -464,10 +460,11 @@ rm_check_num2dbl(VALUE obj)
464
460
  * No Ruby usage (internal function)
465
461
  *
466
462
  * @param str the string
463
+ * @param only_positive Accept whether only positive numbers?
467
464
  * @return a double
468
465
  */
469
466
  double
470
- rm_str_to_pct(VALUE str)
467
+ rm_str_to_pct(VALUE str, bool only_positive)
471
468
  {
472
469
  long pct;
473
470
  char *pct_str, *end;
@@ -485,7 +482,7 @@ rm_str_to_pct(VALUE str)
485
482
  {
486
483
  rb_raise(rb_eArgError, "expected percentage, got `%s'", pct_str);
487
484
  }
488
- if (pct < 0L)
485
+ if (pct < 0L && only_positive)
489
486
  {
490
487
  rb_raise(rb_eArgError, "percentages may not be negative (got `%s')", pct_str);
491
488
  }
@@ -508,45 +505,7 @@ rm_str_to_pct(VALUE str)
508
505
  double
509
506
  rm_fuzz_to_dbl(VALUE fuzz_arg)
510
507
  {
511
- double fuzz;
512
- char *end;
513
-
514
- if (!rm_check_num2dbl(fuzz_arg))
515
- {
516
- char *fuzz_str;
517
-
518
- // Convert to string, issue error message if failure.
519
- fuzz_arg = rb_rescue(RESCUE_FUNC(rb_str_to_str), fuzz_arg, RESCUE_EXCEPTION_HANDLER_FUNC(rescue_not_str), fuzz_arg);
520
- fuzz_str = StringValueCStr(fuzz_arg);
521
- errno = 0;
522
- fuzz = strtod(fuzz_str, &end);
523
- if (errno == ERANGE)
524
- {
525
- rb_raise(rb_eRangeError, "`%s' out of range", fuzz_str);
526
- }
527
- if(*end == '%')
528
- {
529
- if (fuzz < 0.0)
530
- {
531
- rb_raise(rb_eArgError, "percentages may not be negative (got `%s')", fuzz_str);
532
- }
533
- fuzz = (fuzz * QuantumRange) / 100.0;
534
- }
535
- else if(*end != '\0')
536
- {
537
- rb_raise(rb_eArgError, "expected percentage, got `%s'", fuzz_str);
538
- }
539
- }
540
- else
541
- {
542
- fuzz = NUM2DBL(fuzz_arg);
543
- if (fuzz < 0.0)
544
- {
545
- rb_raise(rb_eArgError, "fuzz may not be negative (got `%g')", fuzz);
546
- }
547
- }
548
-
549
- return fuzz;
508
+ return rm_percentage(fuzz_arg, QuantumRange);
550
509
  }
551
510
 
552
511
 
@@ -635,23 +594,27 @@ rm_cur_image(VALUE img)
635
594
  VALUE
636
595
  rm_pixelcolor_to_color_name(Image *image, PixelColor *color)
637
596
  {
638
- PixelColor pp;
639
- char name[MaxTextExtent];
640
- ExceptionInfo *exception;
597
+ MagickPixel mpp;
598
+ char tuple[MaxTextExtent];
641
599
 
642
- exception = AcquireExceptionInfo();
643
-
644
- pp = *color;
645
600
  #if defined(IMAGEMAGICK_7)
646
- pp.depth = MAGICKCORE_QUANTUM_DEPTH;
647
- pp.colorspace = image->colorspace;
601
+ mpp = *color;
602
+ mpp.alpha_trait = BlendPixelTrait;
603
+ mpp.colorspace = image->colorspace;
604
+ #else
605
+ rm_init_magickpixel(image, &mpp);
606
+ mpp.red = GetPixelRed(color);
607
+ mpp.green = GetPixelGreen(color);
608
+ mpp.blue = GetPixelBlue(color);
609
+ mpp.opacity = GetPixelOpacity(color);
610
+ mpp.index = (MagickRealType) 0.0;
611
+ mpp.matte = MagickTrue;
648
612
  #endif
613
+ mpp.depth = image->depth;
649
614
 
650
- QueryColorname(image, &pp, X11Compliance, name, exception);
651
- CHECK_EXCEPTION();
652
- DestroyExceptionInfo(exception);
615
+ GetColorTuple(&mpp, MagickTrue, tuple);
653
616
 
654
- return rb_str_new2(name);
617
+ return rb_str_new2(tuple);
655
618
  }
656
619
 
657
620
 
@@ -1102,13 +1065,14 @@ void rm_sync_image_options(Image *image, Info *info)
1102
1065
  {
1103
1066
  #if defined(IMAGEMAGICK_7)
1104
1067
  exception = AcquireExceptionInfo();
1105
- SetImageColorspace(image, info->colorspace, exception);
1106
- // We should not throw an exception in this method because we will
1107
- // leak memory in the place where this method is called. And that is
1108
- // why the exception is being ignored here.
1068
+ GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace, exception };
1069
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args);
1070
+ CHECK_EXCEPTION();
1109
1071
  DestroyExceptionInfo(exception);
1110
1072
  #else
1111
- SetImageColorspace(image, info->colorspace);
1073
+ GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace };
1074
+ CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args);
1075
+ rm_check_image_exception(image, RetainOnError);
1112
1076
  #endif
1113
1077
  }
1114
1078
 
@@ -1262,6 +1226,11 @@ void rm_sync_image_options(Image *image, Info *info)
1262
1226
  }
1263
1227
 
1264
1228
  copy_options(image, info);
1229
+
1230
+ #if defined(IMAGEMAGICK_7)
1231
+ // The value of info->compression is referenced when saving the image in ImageMagick 7.
1232
+ info->compression = image->compression;
1233
+ #endif
1265
1234
  }
1266
1235
 
1267
1236
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Magick
4
- VERSION = '5.4.4'
5
- MIN_RUBY_VERSION = '2.3.0'
6
- MIN_IM_VERSION = '6.7.7'
4
+ VERSION = '6.0.0'
5
+ MIN_RUBY_VERSION = '3.0.0'
6
+ MIN_IM_VERSION = '6.8.9'
7
7
  end
data/lib/rmagick.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'rmagick_internal.rb'
3
+ require 'rmagick_internal'