rmagick 7.1.7 → 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,16 +109,10 @@ 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)
107
- #define QUANTUM2NUM(q) INT2FIX((q)) /**< Quantum -> Ruby Numeric conversion */
115
+ #define QUANTUM2NUM(q) INT2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
108
116
  #define NUM2QUANTUM(n) (Quantum)NUM2UINT((n)) /**< Quantum <- Ruby Numeric conversion */
109
117
  #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
110
118
  #define QUANTUM2NUM(q) UINT2NUM((q)) /**< Quantum -> Ruby Numeric conversion */
@@ -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
@@ -443,7 +470,9 @@ extern const rb_data_type_t rm_kernel_info_data_type;
443
470
  */
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
- #define C_int_to_R_int(attr) INT2FIX(attr) /**< C int -> Ruby int */
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,45 +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_destroyed(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_destroyed(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_destroyed(self); \
482
- }\
483
- rb_check_frozen(self);\
484
- TypedData_Get_Struct(self, klass, data_type, ptr);\
485
- 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;\
486
510
  return val;\
487
511
  }
488
512
 
489
- //! define attribute writer when attribute name is different from the field name
490
- #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) \
491
515
  {\
492
- klass *ptr;\
493
- if (rb_obj_is_kind_of(self, Class_Image) == Qtrue) {\
494
- rm_check_destroyed(self); \
495
- }\
496
- rb_check_frozen(self);\
497
- TypedData_Get_Struct(self, klass, data_type, ptr);\
498
- 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;\
499
520
  return self;\
500
521
  }
501
522
 
@@ -548,6 +569,7 @@ extern "C" {
548
569
 
549
570
  // rmmain.cpp
550
571
  extern void Init_RMagick2(void);
572
+ extern void rm_gc_continue(void);
551
573
 
552
574
 
553
575
  // rmagick.cpp
@@ -586,6 +608,7 @@ ATTR_WRITER(Draw, stroke_width)
586
608
  ATTR_WRITER(Draw, text_antialias)
587
609
  ATTR_WRITER(Draw, tile)
588
610
  ATTR_WRITER(Draw, undercolor)
611
+ extern void rm_draw_init(void);
589
612
  extern VALUE Draw_alloc(VALUE);
590
613
  extern VALUE Draw_annotate(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
591
614
  extern VALUE Draw_composite(int, VALUE *, VALUE);
@@ -628,6 +651,7 @@ ATTR_WRITER(Montage, texture)
628
651
  ATTR_WRITER(Montage, tile)
629
652
  ATTR_WRITER(Montage, title)
630
653
  extern VALUE Montage_initialize(VALUE);
654
+ extern VALUE Montage_init_copy(VALUE, VALUE);
631
655
  extern VALUE Montage_alloc(VALUE);
632
656
  extern VALUE rm_montage_new(void);
633
657
 
@@ -712,13 +736,18 @@ extern VALUE Info_aref(int, VALUE *, VALUE);
712
736
  extern VALUE Info_channel(int, VALUE *, VALUE);
713
737
  extern VALUE Info_undefine(VALUE, VALUE, VALUE);
714
738
  extern VALUE Info_initialize(VALUE);
739
+ extern VALUE Info_init_copy(VALUE, VALUE);
715
740
  extern VALUE rm_info_new(void);
741
+ extern Info *rm_info_get(VALUE);
716
742
  extern DisposeType rm_dispose_to_enum(const char *);
717
743
  extern GravityType rm_gravity_to_enum(const char *);
718
744
 
719
745
  // rmkinfo.cpp
720
746
 
721
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 *);
722
751
 
723
752
  extern VALUE KernelInfo_initialize(VALUE, VALUE);
724
753
  extern VALUE KernelInfo_unity_add(VALUE, VALUE);
@@ -1024,16 +1053,21 @@ extern VALUE Image_white_threshold(int, VALUE *, VALUE);
1024
1053
  extern VALUE Image_write(VALUE, VALUE);
1025
1054
 
1026
1055
  extern VALUE rm_image_new(Image *);
1027
- 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 *);
1028
1060
 
1029
1061
 
1030
1062
  // rmfill.cpp
1031
1063
  extern VALUE GradientFill_alloc(VALUE);
1032
1064
  extern VALUE GradientFill_initialize(VALUE, VALUE, VALUE, VALUE, VALUE, VALUE, VALUE);
1065
+ extern VALUE GradientFill_init_copy(VALUE, VALUE);
1033
1066
  extern VALUE GradientFill_fill(VALUE, VALUE);
1034
1067
 
1035
1068
  extern VALUE TextureFill_alloc(VALUE);
1036
1069
  extern VALUE TextureFill_initialize(VALUE, VALUE);
1070
+ extern VALUE TextureFill_init_copy(VALUE, VALUE);
1037
1071
  extern VALUE TextureFill_fill(VALUE, VALUE);
1038
1072
 
1039
1073
 
@@ -1113,7 +1147,6 @@ extern VALUE Import_ColorInfo(const ColorInfo *);
1113
1147
  extern VALUE Font_to_s(VALUE);
1114
1148
  extern VALUE Pixel_from_MagickPixel(const MagickPixel *);
1115
1149
  extern VALUE Pixel_from_PixelColor(const PixelColor *);
1116
- extern VALUE Pixel_from_PixelPacket(const PixelPacket *);
1117
1150
  extern void Export_PointInfo(PointInfo *, VALUE);
1118
1151
  extern VALUE Import_PointInfo(PointInfo *);
1119
1152
  extern VALUE PrimaryInfo_to_s(VALUE);
@@ -1142,42 +1175,51 @@ extern VALUE ImageMagickError_initialize(int, VALUE *, VALUE);
1142
1175
  extern void *magick_malloc(const size_t);
1143
1176
  extern void *magick_safe_malloc(const size_t, const size_t);
1144
1177
  extern void magick_free(void *);
1145
- extern void *magick_safe_realloc(void *, const size_t, const size_t);
1146
1178
  extern void magick_clone_string(char **, const char *);
1147
1179
  extern Image *rm_acquire_image(ImageInfo *);
1148
1180
  extern VALUE rm_cur_image(VALUE);
1149
1181
  extern VALUE rm_pixelcolor_to_color_name(Image *, PixelColor *);
1182
+ extern VALUE rm_srgb_pixelcolor_to_color_name(Image *, PixelColor *);
1150
1183
  extern VALUE rm_pixelcolor_to_color_name_info(Info *, PixelColor *);
1151
1184
  extern void rm_init_magickpixel(const Image *, MagickPixel *);
1152
1185
  extern void rm_set_magickpixel(MagickPixel *, const char *);
1153
1186
  extern VALUE rm_no_freeze(VALUE) ATTRIBUTE_NORETURN;
1187
+ extern VALUE rm_freeze(VALUE);
1154
1188
  extern int rm_strcasecmp(const char *, const char *);
1155
1189
  extern int rm_strncasecmp(const char *, const char *, size_t);
1156
1190
  extern size_t rm_strnlen_s(const char *, size_t);
1157
1191
  extern bool rm_has_file_reference(const char *);
1158
1192
  extern void rm_check_ary_len(VALUE, long);
1193
+ extern bool rm_check_init_copy(VALUE, VALUE);
1159
1194
  extern VALUE rm_check_ary_type(VALUE ary);
1160
- extern Image *rm_check_destroyed(VALUE);
1195
+ extern Image *rm_check_readable(VALUE);
1196
+ extern Image *rm_check_writable(VALUE);
1161
1197
  extern Image *rm_check_frozen(VALUE);
1162
1198
  extern char *rm_str2cstr(VALUE *, size_t *);
1163
1199
  extern char *rm_path2cstr(VALUE *, size_t *);
1164
1200
  extern int rm_check_num2dbl(VALUE);
1165
1201
  extern double rm_fuzz_to_dbl(VALUE);
1166
1202
  extern Quantum rm_app2quantum(VALUE);
1203
+ #if defined(MAGICKCORE_HDRI_SUPPORT)
1204
+ extern VALUE rm_quantum2num(double);
1205
+ #endif
1167
1206
  extern double rm_percentage(VALUE, double);
1168
1207
  extern double rm_percentage2(VALUE, double, bool);
1169
1208
  extern double rm_str_to_pct(VALUE, bool);
1170
1209
  extern VALUE rm_define_enum_type(const char *);
1171
1210
  extern void rm_write_temp_image(Image *, char *, size_t);
1172
1211
  extern void rm_delete_temp_image(char *);
1212
+ extern bool rm_copy_temp_image(const char *, char *, size_t);
1173
1213
  extern void rm_attr_write(VALUE, VALUE);
1174
1214
  extern const char *rm_get_property(const Image *, const char *);
1175
1215
  extern MagickBooleanType rm_set_property(Image *, const char *, const char *);
1176
1216
  extern void rm_set_user_artifact(Image *, Info *);
1177
- extern void rm_sync_image_options(Image *, Info *);
1217
+ extern void rm_sync_image_options(Image *, Info *, VALUE);
1178
1218
  extern void rm_split(Image *);
1219
+ extern Image *rm_first_image(Image *);
1179
1220
  extern void rm_magick_error(const char *);
1180
1221
  #if defined(IMAGEMAGICK_7)
1222
+ extern void rm_pixelinfo_cmyk_to_rgb(PixelInfo *);
1181
1223
  extern void rm_set_pixelinfo_alpha(PixelInfo *, const MagickRealType);
1182
1224
  #endif
1183
1225
 
@@ -1196,10 +1238,13 @@ typedef enum
1196
1238
 
1197
1239
  extern void rm_check_exception(ExceptionInfo *, Image *, ErrorRetention);
1198
1240
  extern void rm_ensure_result(Image *);
1199
- 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);
1200
1243
  extern VALUE rm_exif_by_entry(Image *);
1201
1244
  extern VALUE rm_exif_by_number(Image *);
1202
- 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);
1203
1248
  extern void rm_fatal_error_handler(const ExceptionType, const char *, const char *) ATTRIBUTE_NORETURN;
1204
1249
  extern void rm_error_handler(const ExceptionType, const char *, const char *);
1205
1250
  extern void rm_warning_handler(const ExceptionType, const char *, const char *);
@@ -1215,4 +1260,6 @@ extern void rm_check_image_exception(Image *, ErrorRetention);
1215
1260
 
1216
1261
  } // extern "C"
1217
1262
 
1263
+ #include "rmagick_gvl.hpp"
1264
+
1218
1265
  #endif