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.
@@ -18,12 +18,36 @@ const rb_data_type_t rm_montage_data_type = {
18
18
  "Magick::ImageList::Montage",
19
19
  { NULL, Montage_destroy, Montage_memsize, },
20
20
  0, 0,
21
- RUBY_TYPED_FROZEN_SHAREABLE,
21
+ RUBY_TYPED_FROZEN_SHAREABLE | RM_TYPED_FREE_IMMEDIATELY,
22
22
  };
23
23
 
24
24
 
25
25
  /**
26
- * Destroy the MontageInfo struct and free the Montage struct.
26
+ * Delete the texture image of a MontageInfo, and destroy the MontageInfo.
27
+ *
28
+ * No Ruby usage (internal function)
29
+ *
30
+ * @param info the MontageInfo, or NULL
31
+ */
32
+ static void
33
+ destroy_montage_info(MontageInfo *info)
34
+ {
35
+ if (info)
36
+ {
37
+ // If we saved a temporary texture image, delete it now.
38
+ if (info->texture != NULL)
39
+ {
40
+ rm_delete_temp_image(info->texture);
41
+ magick_free(info->texture);
42
+ info->texture = NULL;
43
+ }
44
+ DestroyMontageInfo(info);
45
+ }
46
+ }
47
+
48
+
49
+ /**
50
+ * Destroy the MontageInfo struct and free the MagickMontage struct.
27
51
  *
28
52
  * No Ruby usage (internal function)
29
53
  *
@@ -36,20 +60,10 @@ const rb_data_type_t rm_montage_data_type = {
36
60
  static void
37
61
  Montage_destroy(void *obj)
38
62
  {
39
- Montage *montage = (Montage *)obj;
63
+ MagickMontage *montage = (MagickMontage *)obj;
40
64
 
41
- // If we saved a temporary texture image, delete it now.
42
- if (montage->info && montage->info->texture != NULL)
43
- {
44
- rm_delete_temp_image(montage->info->texture);
45
- magick_free(montage->info->texture);
46
- montage->info->texture = NULL;
47
- }
48
- if (montage->info)
49
- {
50
- DestroyMontageInfo(montage->info);
51
- montage->info = NULL;
52
- }
65
+ destroy_montage_info(montage->info);
66
+ montage->info = NULL;
53
67
  xfree(montage);
54
68
  }
55
69
 
@@ -59,12 +73,12 @@ Montage_destroy(void *obj)
59
73
  *
60
74
  * No Ruby usage (internal function)
61
75
  *
62
- * @param ptr pointer to the Montage object
76
+ * @param ptr pointer to the MagickMontage struct
63
77
  */
64
78
  static size_t
65
79
  Montage_memsize(const void *ptr)
66
80
  {
67
- return sizeof(Montage);
81
+ return sizeof(MagickMontage);
68
82
  }
69
83
 
70
84
 
@@ -77,7 +91,7 @@ VALUE
77
91
  Montage_alloc(VALUE klass)
78
92
  {
79
93
  MontageInfo *montage_info;
80
- Montage *montage;
94
+ MagickMontage *montage;
81
95
  Info *image_info;
82
96
  VALUE montage_obj;
83
97
 
@@ -96,7 +110,7 @@ Montage_alloc(VALUE klass)
96
110
  rb_raise(rb_eNoMemError, "not enough memory to initialize Magick::ImageList::Montage object");
97
111
  }
98
112
 
99
- montage = ALLOC(Montage);
113
+ montage = ZALLOC(MagickMontage);
100
114
  montage->info = montage_info;
101
115
  montage->compose = OverCompositeOp;
102
116
  montage_obj = TypedData_Wrap_Struct(klass, &rm_montage_data_type, montage);
@@ -107,6 +121,30 @@ Montage_alloc(VALUE klass)
107
121
  }
108
122
 
109
123
 
124
+ /**
125
+ * Return the MagickMontage struct of an object that is about to be changed.
126
+ *
127
+ * No Ruby usage (internal function)
128
+ *
129
+ * @param self the Montage object
130
+ * @return the MagickMontage struct
131
+ * @throw FrozenError if the Montage object is frozen
132
+ * @throw RuntimeError if a call in flight is using the Montage object
133
+ */
134
+ static MagickMontage *
135
+ get_writable_montage(VALUE self)
136
+ {
137
+ MagickMontage *montage;
138
+
139
+ // A Montage cannot be frozen through #freeze, but check anyway in case it
140
+ // was frozen another way.
141
+ rb_check_frozen(self);
142
+ TypedData_Get_Struct(self, MagickMontage, &rm_montage_data_type, montage);
143
+ rm_gvl_check_writable(self);
144
+ return montage;
145
+ }
146
+
147
+
110
148
  /**
111
149
  * Set background_color value.
112
150
  *
@@ -116,9 +154,9 @@ Montage_alloc(VALUE klass)
116
154
  VALUE
117
155
  Montage_background_color_eq(VALUE self, VALUE color)
118
156
  {
119
- Montage *montage;
157
+ MagickMontage *montage;
120
158
 
121
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
159
+ montage = get_writable_montage(self);
122
160
  Color_to_PixelColor(&montage->info->background_color, color);
123
161
  return color;
124
162
  }
@@ -133,9 +171,9 @@ Montage_background_color_eq(VALUE self, VALUE color)
133
171
  VALUE
134
172
  Montage_border_color_eq(VALUE self, VALUE color)
135
173
  {
136
- Montage *montage;
174
+ MagickMontage *montage;
137
175
 
138
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
176
+ montage = get_writable_montage(self);
139
177
  Color_to_PixelColor(&montage->info->border_color, color);
140
178
  return color;
141
179
  }
@@ -150,9 +188,9 @@ Montage_border_color_eq(VALUE self, VALUE color)
150
188
  VALUE
151
189
  Montage_border_width_eq(VALUE self, VALUE width)
152
190
  {
153
- Montage *montage;
191
+ MagickMontage *montage;
154
192
 
155
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
193
+ montage = get_writable_montage(self);
156
194
  montage->info->border_width = NUM2ULONG(width);
157
195
  return width;
158
196
  }
@@ -167,9 +205,9 @@ Montage_border_width_eq(VALUE self, VALUE width)
167
205
  VALUE
168
206
  Montage_compose_eq(VALUE self, VALUE compose)
169
207
  {
170
- Montage *montage;
208
+ MagickMontage *montage;
171
209
 
172
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
210
+ montage = get_writable_montage(self);
173
211
  VALUE_TO_ENUM(compose, montage->compose, CompositeOperator);
174
212
  return compose;
175
213
  }
@@ -184,9 +222,9 @@ Montage_compose_eq(VALUE self, VALUE compose)
184
222
  VALUE
185
223
  Montage_filename_eq(VALUE self, VALUE filename)
186
224
  {
187
- Montage *montage;
225
+ MagickMontage *montage;
188
226
 
189
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
227
+ montage = get_writable_montage(self);
190
228
  strlcpy(montage->info->filename, StringValueCStr(filename), sizeof(montage->info->filename));
191
229
  return filename;
192
230
  }
@@ -201,9 +239,9 @@ Montage_filename_eq(VALUE self, VALUE filename)
201
239
  VALUE
202
240
  Montage_fill_eq(VALUE self, VALUE color)
203
241
  {
204
- Montage *montage;
242
+ MagickMontage *montage;
205
243
 
206
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
244
+ montage = get_writable_montage(self);
207
245
  Color_to_PixelColor(&montage->info->fill, color);
208
246
  return color;
209
247
  }
@@ -218,9 +256,9 @@ Montage_fill_eq(VALUE self, VALUE color)
218
256
  VALUE
219
257
  Montage_font_eq(VALUE self, VALUE font)
220
258
  {
221
- Montage *montage;
259
+ MagickMontage *montage;
222
260
 
223
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
261
+ montage = get_writable_montage(self);
224
262
  magick_clone_string(&montage->info->font, StringValueCStr(font));
225
263
 
226
264
  return font;
@@ -240,10 +278,10 @@ Montage_font_eq(VALUE self, VALUE font)
240
278
  VALUE
241
279
  Montage_frame_eq(VALUE self, VALUE frame_arg)
242
280
  {
243
- Montage *montage;
281
+ MagickMontage *montage;
244
282
  VALUE frame;
245
283
 
246
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
284
+ montage = get_writable_montage(self);
247
285
  frame = rb_String(frame_arg);
248
286
  magick_clone_string(&montage->info->frame, StringValueCStr(frame));
249
287
 
@@ -267,10 +305,10 @@ Montage_frame_eq(VALUE self, VALUE frame_arg)
267
305
  VALUE
268
306
  Montage_geometry_eq(VALUE self, VALUE geometry_arg)
269
307
  {
270
- Montage *montage;
308
+ MagickMontage *montage;
271
309
  VALUE geometry;
272
310
 
273
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
311
+ montage = get_writable_montage(self);
274
312
  geometry = rb_String(geometry_arg);
275
313
  magick_clone_string(&montage->info->geometry, StringValueCStr(geometry));
276
314
 
@@ -289,9 +327,9 @@ Montage_geometry_eq(VALUE self, VALUE geometry_arg)
289
327
  VALUE
290
328
  Montage_gravity_eq(VALUE self, VALUE gravity)
291
329
  {
292
- Montage *montage;
330
+ MagickMontage *montage;
293
331
 
294
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
332
+ montage = get_writable_montage(self);
295
333
  VALUE_TO_ENUM(gravity, montage->info->gravity, GravityType);
296
334
  return gravity;
297
335
  }
@@ -310,6 +348,64 @@ Montage_initialize(VALUE self)
310
348
  }
311
349
 
312
350
 
351
+ /**
352
+ * Initialize clone, dup methods.
353
+ *
354
+ * @param orig the original object
355
+ * @return [Magick::ImageList::Montage] self
356
+ */
357
+ VALUE
358
+ Montage_init_copy(VALUE self, VALUE orig)
359
+ {
360
+ MagickMontage *copy, *original;
361
+ MontageInfo *info;
362
+ char texture[MaxTextExtent];
363
+ bool has_texture = false;
364
+
365
+ if (!rm_check_init_copy(self, orig))
366
+ {
367
+ return self;
368
+ }
369
+ rm_gvl_check_writable(self);
370
+ rm_gvl_check_readable(orig);
371
+ TypedData_Get_Struct(orig, MagickMontage, &rm_montage_data_type, original);
372
+ TypedData_Get_Struct(self, MagickMontage, &rm_montage_data_type, copy);
373
+
374
+ // The texture names a temporary image that the copy must own by itself.
375
+ if (original->info->texture)
376
+ {
377
+ has_texture = rm_copy_temp_image(original->info->texture, texture, sizeof(texture));
378
+ }
379
+
380
+ // Copy in place what CloneMontageInfo copies, since it leaks its default geometry.
381
+ info = copy->info;
382
+ magick_clone_string(&info->geometry, original->info->geometry);
383
+ magick_clone_string(&info->tile, original->info->tile);
384
+ magick_clone_string(&info->title, original->info->title);
385
+ magick_clone_string(&info->frame, original->info->frame);
386
+ magick_clone_string(&info->font, original->info->font);
387
+ if (info->texture)
388
+ {
389
+ rm_delete_temp_image(info->texture);
390
+ }
391
+ magick_clone_string(&info->texture, has_texture ? texture : NULL);
392
+ info->pointsize = original->info->pointsize;
393
+ info->border_width = original->info->border_width;
394
+ info->shadow = original->info->shadow;
395
+ info->fill = original->info->fill;
396
+ info->stroke = original->info->stroke;
397
+ info->background_color = original->info->background_color;
398
+ info->border_color = original->info->border_color;
399
+ info->matte_color = original->info->matte_color;
400
+ info->gravity = original->info->gravity;
401
+ CopyMagickString(info->filename, original->info->filename, sizeof(info->filename));
402
+ info->debug = IsEventLogging();
403
+ copy->compose = original->compose;
404
+
405
+ return self;
406
+ }
407
+
408
+
313
409
  /**
314
410
  * Set matte_color value.
315
411
  *
@@ -319,9 +415,9 @@ Montage_initialize(VALUE self)
319
415
  VALUE
320
416
  Montage_matte_color_eq(VALUE self, VALUE color)
321
417
  {
322
- Montage *montage;
418
+ MagickMontage *montage;
323
419
 
324
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
420
+ montage = get_writable_montage(self);
325
421
  Color_to_PixelColor(&montage->info->matte_color, color);
326
422
  return color;
327
423
  }
@@ -336,9 +432,9 @@ Montage_matte_color_eq(VALUE self, VALUE color)
336
432
  VALUE
337
433
  Montage_pointsize_eq(VALUE self, VALUE size)
338
434
  {
339
- Montage *montage;
435
+ MagickMontage *montage;
340
436
 
341
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
437
+ montage = get_writable_montage(self);
342
438
  montage->info->pointsize = NUM2DBL(size);
343
439
  return size;
344
440
  }
@@ -353,9 +449,9 @@ Montage_pointsize_eq(VALUE self, VALUE size)
353
449
  VALUE
354
450
  Montage_shadow_eq(VALUE self, VALUE shadow)
355
451
  {
356
- Montage *montage;
452
+ MagickMontage *montage;
357
453
 
358
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
454
+ montage = get_writable_montage(self);
359
455
  montage->info->shadow = (MagickBooleanType) RTEST(shadow);
360
456
  return shadow;
361
457
  }
@@ -370,9 +466,9 @@ Montage_shadow_eq(VALUE self, VALUE shadow)
370
466
  VALUE
371
467
  Montage_stroke_eq(VALUE self, VALUE color)
372
468
  {
373
- Montage *montage;
469
+ MagickMontage *montage;
374
470
 
375
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
471
+ montage = get_writable_montage(self);
376
472
  Color_to_PixelColor(&montage->info->stroke, color);
377
473
  return color;
378
474
  }
@@ -388,11 +484,13 @@ Montage_stroke_eq(VALUE self, VALUE color)
388
484
  VALUE
389
485
  Montage_texture_eq(VALUE self, VALUE texture)
390
486
  {
391
- Montage *montage;
487
+ MagickMontage *montage;
392
488
  Image *texture_image;
393
489
  char temp_name[MaxTextExtent];
394
490
 
395
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
491
+ montage = get_writable_montage(self);
492
+ texture = rm_cur_image(texture);
493
+ texture_image = rm_check_readable(texture);
396
494
 
397
495
  // If we had a previously defined temp texture image,
398
496
  // remove it now in preparation for this new one.
@@ -403,9 +501,6 @@ Montage_texture_eq(VALUE self, VALUE texture)
403
501
  montage->info->texture = NULL;
404
502
  }
405
503
 
406
- texture = rm_cur_image(texture);
407
- texture_image = rm_check_destroyed(texture);
408
-
409
504
  // Write a temp copy of the image & save its name.
410
505
  rm_write_temp_image(texture_image, temp_name, sizeof(temp_name));
411
506
  magick_clone_string(&montage->info->texture, temp_name);
@@ -428,10 +523,10 @@ Montage_texture_eq(VALUE self, VALUE texture)
428
523
  VALUE
429
524
  Montage_tile_eq(VALUE self, VALUE tile_arg)
430
525
  {
431
- Montage *montage;
526
+ MagickMontage *montage;
432
527
  VALUE tile;
433
528
 
434
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
529
+ montage = get_writable_montage(self);
435
530
  tile = rb_String(tile_arg);
436
531
  magick_clone_string(&montage->info->tile, StringValueCStr(tile));
437
532
 
@@ -453,10 +548,10 @@ Montage_tile_eq(VALUE self, VALUE tile_arg)
453
548
  VALUE
454
549
  Montage_title_eq(VALUE self, VALUE title)
455
550
  {
456
- Montage *montage;
551
+ MagickMontage *montage;
457
552
  const char *title_cstr;
458
553
 
459
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
554
+ montage = get_writable_montage(self);
460
555
  title_cstr = StringValueCStr(title);
461
556
 
462
557
  if (rm_has_file_reference(title_cstr))