rmagick 7.2.0 → 7.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.
@@ -19,6 +19,13 @@
19
19
  // Therefore, it includes the header in advance.
20
20
  #include "ruby/defines.h"
21
21
 
22
+ #include <atomic>
23
+ // rmimage.cpp uses it. It must come before the min and max macros below.
24
+ #if defined(__APPLE__) || defined(__FreeBSD__)
25
+ #include <mutex>
26
+ #endif
27
+ #include <utility>
28
+
22
29
  extern "C" {
23
30
  #include <assert.h>
24
31
  #include <stdio.h>
@@ -70,6 +77,13 @@ extern "C" {
70
77
 
71
78
  #include "extconf.h"
72
79
 
80
+ #if defined(HAVE_MALLOC_USABLE_SIZE) || defined(HAVE_MALLOC_SIZE) || defined(HAVE__MSIZE)
81
+ #define RM_USE_MALLOC 1
82
+ #define RM_TYPED_FREE_IMMEDIATELY RUBY_TYPED_FREE_IMMEDIATELY
83
+ #else
84
+ #define RM_TYPED_FREE_IMMEDIATELY 0
85
+ #endif
86
+
73
87
  #if defined(IMAGEMAGICK_7)
74
88
  #include "MagickCore/MagickCore.h"
75
89
  #include "MagickCore/magick-config.h"
@@ -95,12 +109,6 @@ extern "C" {
95
109
  #define ATTRIBUTE_NORETURN
96
110
  #endif
97
111
 
98
- //! Trace new image creation in bang methods
99
- #define UPDATE_DATA_PTR(_obj_, _new_) \
100
- do { \
101
- DATA_PTR(_obj_) = (void *)(_new_); \
102
- } while(0)
103
-
104
112
 
105
113
  // Handle Quantum <-> Ruby Numeric object conversion
106
114
  #if (MAGICKCORE_QUANTUM_DEPTH == 8 || MAGICKCORE_QUANTUM_DEPTH == 16)
@@ -115,6 +123,10 @@ extern "C" {
115
123
  #else
116
124
  #error Specified MAGICKCORE_QUANTUM_DEPTH is not supported.
117
125
  #endif
126
+ #if defined(MAGICKCORE_HDRI_SUPPORT)
127
+ #undef QUANTUM2NUM
128
+ #define QUANTUM2NUM(q) rm_quantum2num((q)) /**< HDRI Quantum -> Ruby Integer conversion */
129
+ #endif
118
130
  //! Convert user-supplied objects to Quantum
119
131
  #define APP2QUANTUM(n) rm_app2quantum((n))
120
132
 
@@ -141,18 +153,6 @@ extern "C" {
141
153
  #define CSTR2SYM(s) ID2SYM(rb_intern(s))
142
154
  //! Convert a C string to a Ruby String, or nil if the ptr is NULL
143
155
  #define MAGICK_STRING_TO_OBJ(f) (f) ? rb_str_new2(f) : Qnil
144
- /**
145
- * Copy the C string in a Ruby String object to ImageMagick memory, or set the
146
- * pointer to NULL if the object is nil.
147
- */
148
- #define OBJ_TO_MAGICK_STRING(f, obj) \
149
- if ((obj) != Qnil)\
150
- {\
151
- VALUE str = rb_String(obj);\
152
- magick_clone_string(&f, StringValueCStr(str));\
153
- }\
154
- else\
155
- f = NULL;
156
156
 
157
157
 
158
158
  #define MagickLibSubversion MagickLibAddendum
@@ -194,18 +194,44 @@ typedef ImageInfo Info; /**< Make type name match class name */
194
194
  #define IMAGEMAGICK_6 1
195
195
  #endif
196
196
 
197
+ //! Offloaded calls that use an object, which only rmagick_gvl.cpp reads
198
+ typedef std::atomic<uint64_t> rm_offload_state_t;
199
+
200
+ //! Image class.
201
+ typedef struct
202
+ {
203
+ Image *image; /**< the ImageMagick image, or NULL after Image#destroy! */
204
+ rm_offload_state_t offload; /**< the offload state */
205
+ } MagickImage;
206
+
207
+ //! Info class.
208
+ typedef struct
209
+ {
210
+ Info *info; /**< the ImageInfo */
211
+ rm_offload_state_t offload; /**< the offload state */
212
+ } MagickImageInfo;
213
+
214
+ //! KernelInfo class.
215
+ typedef struct
216
+ {
217
+ KernelInfo *kernel; /**< the KernelInfo, or NULL before KernelInfo#initialize */
218
+ rm_offload_state_t offload; /**< the offload state */
219
+ } MagickKernelInfo;
220
+
197
221
  //! Montage
198
222
  typedef struct
199
223
  {
200
224
  CompositeOperator compose; /**< compose operator */
201
225
  MontageInfo *info; /**< montage info */
202
- } Montage;
226
+ rm_offload_state_t offload; /**< the offload state */
227
+ } MagickMontage;
203
228
 
204
229
  // Draw
205
230
  //! tmp filename linked list
206
231
  struct TmpFile_Name
207
232
  {
208
233
  struct TmpFile_Name *next; /**< the next tmp filename */
234
+ std::atomic<size_t> refs; /**< the number of Draw objects and list entries that refer to it */
209
235
  char name[1]; /**< expandable char array for this filename */
210
236
  };
211
237
 
@@ -216,7 +242,8 @@ typedef struct
216
242
  VALUE primitives; /**< the primitive string */
217
243
  struct TmpFile_Name *tmpfile_ary; /**< the tmp filenames */
218
244
  PixelColor shadow_color; /**< PolaroidOptions#shadow_color */
219
- } Draw; // make the type match the class name
245
+ rm_offload_state_t offload; /**< the offload state */
246
+ } MagickDraw;
220
247
 
221
248
  // Enum
222
249
  //! enumerator over Magick ids
@@ -444,6 +471,8 @@ extern const rb_data_type_t rm_kernel_info_data_type;
444
471
  #define C_boolean_to_R_boolean(attr) (attr) ? Qtrue : Qfalse /**< C boolean -> Ruby boolean */
445
472
  #define R_boolean_to_C_boolean(attr) (MagickBooleanType)RTEST(attr) /**< C boolean <- Ruby boolean */
446
473
  #define C_int_to_R_int(attr) INT2NUM(attr) /**< C int -> Ruby int */
474
+ //! Quantum -> Ruby Integer
475
+ #define C_Quantum_to_R_Quantum(attr) QUANTUM2NUM(attr)
447
476
  #define R_int_to_C_int(attr) NUM2INT(attr) /**< C int <- Ruby int */
448
477
  #define C_long_to_R_long(attr) LONG2NUM(attr) /**< C long -> Ruby long */
449
478
  #define R_long_to_C_long(attr) NUM2LONG(attr) /**< C long <- Ruby long */
@@ -457,47 +486,37 @@ extern const rb_data_type_t rm_kernel_info_data_type;
457
486
  #define IMPLEMENT_TYPED_ATTR_READER(klass, attr, type, data_type) \
458
487
  {\
459
488
  klass *ptr;\
460
- if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
461
- rm_check_readable(self); \
462
- }\
463
489
  TypedData_Get_Struct(self, klass, data_type, ptr);\
464
490
  return C_##type##_to_R_##type(ptr->attr);\
465
491
  }
466
492
 
467
- //! define attribute reader when attribute name is different from the field name
468
- #define IMPLEMENT_TYPED_ATTR_READERF(klass, attr, field, type, data_type) \
493
+ //! define attribute reader of Image when attribute name is different from the field name
494
+ #define IMPLEMENT_IMAGE_ATTR_READERF(attr, field, type) \
469
495
  {\
470
- klass *ptr;\
471
- rm_check_readable(self); \
472
- TypedData_Get_Struct(self, klass, data_type, ptr);\
473
- return C_##type##_to_R_##type(ptr->field);\
496
+ Image *image = rm_check_readable(self);\
497
+ return C_##type##_to_R_##type(image->field);\
474
498
  }
475
499
 
476
- //! define attribute writer
477
- #define IMPLEMENT_TYPED_ATTR_WRITER(klass, attr, type, data_type) \
500
+ //! define attribute reader of Image
501
+ #define IMPLEMENT_IMAGE_ATTR_READER(attr, type) IMPLEMENT_IMAGE_ATTR_READERF(attr, attr, type)
502
+
503
+ //! define attribute writer of Image
504
+ #define IMPLEMENT_IMAGE_ATTR_WRITER(attr, type) \
478
505
  {\
479
- klass *ptr;\
480
- if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
481
- rm_check_readable(self); \
482
- }\
483
- rb_check_frozen(self);\
484
- TypedData_Get_Struct(self, klass, data_type, ptr);\
485
- rm_gvl_check_writable(ptr);\
486
- ptr->attr = R_##type##_to_C_##type(val);\
506
+ rm_check_frozen(self);\
507
+ auto value = R_##type##_to_C_##type(val);\
508
+ Image *image = rm_check_frozen(self);\
509
+ image->attr = value;\
487
510
  return val;\
488
511
  }
489
512
 
490
- //! define attribute writer when attribute name is different from the field name
491
- #define IMPLEMENT_TYPED_ATTR_WRITERF(klass, attr, field, type, data_type) \
513
+ //! define attribute writer of Image when attribute name is different from the field name
514
+ #define IMPLEMENT_IMAGE_ATTR_WRITERF(attr, field, type) \
492
515
  {\
493
- klass *ptr;\
494
- if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
495
- rm_check_readable(self); \
496
- }\
497
- rb_check_frozen(self);\
498
- TypedData_Get_Struct(self, klass, data_type, ptr);\
499
- rm_gvl_check_writable(ptr);\
500
- ptr->field = R_##type##_to_C_##type(val);\
516
+ rm_check_frozen(self);\
517
+ auto value = R_##type##_to_C_##type(val);\
518
+ Image *image = rm_check_frozen(self);\
519
+ image->field = value;\
501
520
  return self;\
502
521
  }
503
522
 
@@ -550,6 +569,7 @@ extern "C" {
550
569
 
551
570
  // rmmain.cpp
552
571
  extern void Init_RMagick2(void);
572
+ extern void rm_gc_continue(void);
553
573
 
554
574
 
555
575
  // rmagick.cpp
@@ -588,6 +608,7 @@ ATTR_WRITER(Draw, stroke_width)
588
608
  ATTR_WRITER(Draw, text_antialias)
589
609
  ATTR_WRITER(Draw, tile)
590
610
  ATTR_WRITER(Draw, undercolor)
611
+ extern void rm_draw_init(void);
591
612
  extern VALUE Draw_alloc(VALUE);
592
613
  extern VALUE Draw_annotate(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
593
614
  extern VALUE Draw_composite(int, VALUE *, VALUE);
@@ -630,6 +651,7 @@ ATTR_WRITER(Montage, texture)
630
651
  ATTR_WRITER(Montage, tile)
631
652
  ATTR_WRITER(Montage, title)
632
653
  extern VALUE Montage_initialize(VALUE);
654
+ extern VALUE Montage_init_copy(VALUE, VALUE);
633
655
  extern VALUE Montage_alloc(VALUE);
634
656
  extern VALUE rm_montage_new(void);
635
657
 
@@ -714,13 +736,18 @@ extern VALUE Info_aref(int, VALUE *, VALUE);
714
736
  extern VALUE Info_channel(int, VALUE *, VALUE);
715
737
  extern VALUE Info_undefine(VALUE, VALUE, VALUE);
716
738
  extern VALUE Info_initialize(VALUE);
739
+ extern VALUE Info_init_copy(VALUE, VALUE);
717
740
  extern VALUE rm_info_new(void);
741
+ extern Info *rm_info_get(VALUE);
718
742
  extern DisposeType rm_dispose_to_enum(const char *);
719
743
  extern GravityType rm_gravity_to_enum(const char *);
720
744
 
721
745
  // rmkinfo.cpp
722
746
 
723
747
  extern VALUE KernelInfo_alloc(VALUE);
748
+ extern KernelInfo *rm_kernel_info_get(VALUE);
749
+ extern KernelInfo *rm_check_kernel_info(VALUE);
750
+ extern void rm_kernel_info_set(VALUE, KernelInfo *);
724
751
 
725
752
  extern VALUE KernelInfo_initialize(VALUE, VALUE);
726
753
  extern VALUE KernelInfo_unity_add(VALUE, VALUE);
@@ -1026,16 +1053,21 @@ extern VALUE Image_white_threshold(int, VALUE *, VALUE);
1026
1053
  extern VALUE Image_write(VALUE, VALUE);
1027
1054
 
1028
1055
  extern VALUE rm_image_new(Image *);
1029
- extern void rm_image_destroy(void *);
1056
+ extern VALUE rm_image_wrap(Image *);
1057
+ extern Image *rm_image_get(VALUE);
1058
+ extern void rm_image_set(VALUE, Image *);
1059
+ extern void rm_image_destroy(Image *);
1030
1060
 
1031
1061
 
1032
1062
  // rmfill.cpp
1033
1063
  extern VALUE GradientFill_alloc(VALUE);
1034
1064
  extern VALUE GradientFill_initialize(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
1065
+ extern VALUE GradientFill_init_copy(VALUE, VALUE);
1035
1066
  extern VALUE GradientFill_fill(VALUE, VALUE);
1036
1067
 
1037
1068
  extern VALUE TextureFill_alloc(VALUE);
1038
1069
  extern VALUE TextureFill_initialize(VALUE, VALUE);
1070
+ extern VALUE TextureFill_init_copy(VALUE, VALUE);
1039
1071
  extern VALUE TextureFill_fill(VALUE, VALUE);
1040
1072
 
1041
1073
 
@@ -1115,7 +1147,6 @@ extern VALUE Import_ColorInfo(const ColorInfo *);
1115
1147
  extern VALUE Font_to_s(VALUE);
1116
1148
  extern VALUE Pixel_from_MagickPixel(const MagickPixel *);
1117
1149
  extern VALUE Pixel_from_PixelColor(const PixelColor *);
1118
- extern VALUE Pixel_from_PixelPacket(const PixelPacket *);
1119
1150
  extern void Export_PointInfo(PointInfo *, VALUE);
1120
1151
  extern VALUE Import_PointInfo(PointInfo *);
1121
1152
  extern VALUE PrimaryInfo_to_s(VALUE);
@@ -1144,20 +1175,22 @@ extern VALUE ImageMagickError_initialize(int, VALUE *, VALUE);
1144
1175
  extern void *magick_malloc(const size_t);
1145
1176
  extern void *magick_safe_malloc(const size_t, const size_t);
1146
1177
  extern void magick_free(void *);
1147
- extern void *magick_safe_realloc(void *, const size_t, const size_t);
1148
1178
  extern void magick_clone_string(char **, const char *);
1149
1179
  extern Image *rm_acquire_image(ImageInfo *);
1150
1180
  extern VALUE rm_cur_image(VALUE);
1151
1181
  extern VALUE rm_pixelcolor_to_color_name(Image *, PixelColor *);
1182
+ extern VALUE rm_srgb_pixelcolor_to_color_name(Image *, PixelColor *);
1152
1183
  extern VALUE rm_pixelcolor_to_color_name_info(Info *, PixelColor *);
1153
1184
  extern void rm_init_magickpixel(const Image *, MagickPixel *);
1154
1185
  extern void rm_set_magickpixel(MagickPixel *, const char *);
1155
1186
  extern VALUE rm_no_freeze(VALUE) ATTRIBUTE_NORETURN;
1187
+ extern VALUE rm_freeze(VALUE);
1156
1188
  extern int rm_strcasecmp(const char *, const char *);
1157
1189
  extern int rm_strncasecmp(const char *, const char *, size_t);
1158
1190
  extern size_t rm_strnlen_s(const char *, size_t);
1159
1191
  extern bool rm_has_file_reference(const char *);
1160
1192
  extern void rm_check_ary_len(VALUE, long);
1193
+ extern bool rm_check_init_copy(VALUE, VALUE);
1161
1194
  extern VALUE rm_check_ary_type(VALUE ary);
1162
1195
  extern Image *rm_check_readable(VALUE);
1163
1196
  extern Image *rm_check_writable(VALUE);
@@ -1167,20 +1200,26 @@ extern char *rm_path2cstr(VALUE *, size_t *);
1167
1200
  extern int rm_check_num2dbl(VALUE);
1168
1201
  extern double rm_fuzz_to_dbl(VALUE);
1169
1202
  extern Quantum rm_app2quantum(VALUE);
1203
+ #if defined(MAGICKCORE_HDRI_SUPPORT)
1204
+ extern VALUE rm_quantum2num(double);
1205
+ #endif
1170
1206
  extern double rm_percentage(VALUE, double);
1171
1207
  extern double rm_percentage2(VALUE, double, bool);
1172
1208
  extern double rm_str_to_pct(VALUE, bool);
1173
1209
  extern VALUE rm_define_enum_type(const char *);
1174
1210
  extern void rm_write_temp_image(Image *, char *, size_t);
1175
1211
  extern void rm_delete_temp_image(char *);
1212
+ extern bool rm_copy_temp_image(const char *, char *, size_t);
1176
1213
  extern void rm_attr_write(VALUE, VALUE);
1177
1214
  extern const char *rm_get_property(const Image *, const char *);
1178
1215
  extern MagickBooleanType rm_set_property(Image *, const char *, const char *);
1179
1216
  extern void rm_set_user_artifact(Image *, Info *);
1180
- extern void rm_sync_image_options(Image *, Info *);
1217
+ extern void rm_sync_image_options(Image *, Info *, VALUE);
1181
1218
  extern void rm_split(Image *);
1219
+ extern Image *rm_first_image(Image *);
1182
1220
  extern void rm_magick_error(const char *);
1183
1221
  #if defined(IMAGEMAGICK_7)
1222
+ extern void rm_pixelinfo_cmyk_to_rgb(PixelInfo *);
1184
1223
  extern void rm_set_pixelinfo_alpha(PixelInfo *, const MagickRealType);
1185
1224
  #endif
1186
1225
 
@@ -1199,10 +1238,13 @@ typedef enum
1199
1238
 
1200
1239
  extern void rm_check_exception(ExceptionInfo *, Image *, ErrorRetention);
1201
1240
  extern void rm_ensure_result(Image *);
1202
- extern Image *rm_clone_image(Image *);
1241
+ extern Image *rm_clone_image(Image *, VALUE, VALUE held = Qnil, bool changes = false);
1242
+ extern Image *rm_copy_image(Image *, VALUE, VALUE held = Qnil, bool changes = false);
1203
1243
  extern VALUE rm_exif_by_entry(Image *);
1204
1244
  extern VALUE rm_exif_by_number(Image *);
1205
- extern void rm_get_optional_arguments(VALUE);
1245
+ extern VALUE rm_get_optional_arguments(VALUE);
1246
+ extern MagickBooleanType rm_set_optional_arguments(Image *, VALUE);
1247
+ extern MagickBooleanType rm_restore_optional_arguments(Image *, Image *, VALUE);
1206
1248
  extern void rm_fatal_error_handler(const ExceptionType, const char *, const char *) ATTRIBUTE_NORETURN;
1207
1249
  extern void rm_error_handler(const ExceptionType, const char *, const char *);
1208
1250
  extern void rm_warning_handler(const ExceptionType, const char *, const char *);