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.
@@ -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);
@@ -108,21 +122,25 @@ Montage_alloc(VALUE klass)
108
122
 
109
123
 
110
124
  /**
111
- * Return the Montage struct of an object that is about to be changed.
125
+ * Return the MagickMontage struct of an object that is about to be changed.
112
126
  *
113
127
  * No Ruby usage (internal function)
114
128
  *
115
129
  * @param self the Montage object
116
- * @return the Montage struct
117
- * @throw RuntimeError if an offloaded call is using the Montage
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
118
133
  */
119
- static Montage *
134
+ static MagickMontage *
120
135
  get_writable_montage(VALUE self)
121
136
  {
122
- Montage *montage;
137
+ MagickMontage *montage;
123
138
 
124
- TypedData_Get_Struct(self, Montage, &rm_montage_data_type, montage);
125
- rm_gvl_check_writable(montage);
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);
126
144
  return montage;
127
145
  }
128
146
 
@@ -136,7 +154,7 @@ get_writable_montage(VALUE self)
136
154
  VALUE
137
155
  Montage_background_color_eq(VALUE self, VALUE color)
138
156
  {
139
- Montage *montage;
157
+ MagickMontage *montage;
140
158
 
141
159
  montage = get_writable_montage(self);
142
160
  Color_to_PixelColor(&montage->info->background_color, color);
@@ -153,7 +171,7 @@ Montage_background_color_eq(VALUE self, VALUE color)
153
171
  VALUE
154
172
  Montage_border_color_eq(VALUE self, VALUE color)
155
173
  {
156
- Montage *montage;
174
+ MagickMontage *montage;
157
175
 
158
176
  montage = get_writable_montage(self);
159
177
  Color_to_PixelColor(&montage->info->border_color, color);
@@ -170,7 +188,7 @@ Montage_border_color_eq(VALUE self, VALUE color)
170
188
  VALUE
171
189
  Montage_border_width_eq(VALUE self, VALUE width)
172
190
  {
173
- Montage *montage;
191
+ MagickMontage *montage;
174
192
 
175
193
  montage = get_writable_montage(self);
176
194
  montage->info->border_width = NUM2ULONG(width);
@@ -187,7 +205,7 @@ Montage_border_width_eq(VALUE self, VALUE width)
187
205
  VALUE
188
206
  Montage_compose_eq(VALUE self, VALUE compose)
189
207
  {
190
- Montage *montage;
208
+ MagickMontage *montage;
191
209
 
192
210
  montage = get_writable_montage(self);
193
211
  VALUE_TO_ENUM(compose, montage->compose, CompositeOperator);
@@ -204,7 +222,7 @@ Montage_compose_eq(VALUE self, VALUE compose)
204
222
  VALUE
205
223
  Montage_filename_eq(VALUE self, VALUE filename)
206
224
  {
207
- Montage *montage;
225
+ MagickMontage *montage;
208
226
 
209
227
  montage = get_writable_montage(self);
210
228
  strlcpy(montage->info->filename, StringValueCStr(filename), sizeof(montage->info->filename));
@@ -221,7 +239,7 @@ Montage_filename_eq(VALUE self, VALUE filename)
221
239
  VALUE
222
240
  Montage_fill_eq(VALUE self, VALUE color)
223
241
  {
224
- Montage *montage;
242
+ MagickMontage *montage;
225
243
 
226
244
  montage = get_writable_montage(self);
227
245
  Color_to_PixelColor(&montage->info->fill, color);
@@ -238,7 +256,7 @@ Montage_fill_eq(VALUE self, VALUE color)
238
256
  VALUE
239
257
  Montage_font_eq(VALUE self, VALUE font)
240
258
  {
241
- Montage *montage;
259
+ MagickMontage *montage;
242
260
 
243
261
  montage = get_writable_montage(self);
244
262
  magick_clone_string(&montage->info->font, StringValueCStr(font));
@@ -260,7 +278,7 @@ Montage_font_eq(VALUE self, VALUE font)
260
278
  VALUE
261
279
  Montage_frame_eq(VALUE self, VALUE frame_arg)
262
280
  {
263
- Montage *montage;
281
+ MagickMontage *montage;
264
282
  VALUE frame;
265
283
 
266
284
  montage = get_writable_montage(self);
@@ -287,7 +305,7 @@ Montage_frame_eq(VALUE self, VALUE frame_arg)
287
305
  VALUE
288
306
  Montage_geometry_eq(VALUE self, VALUE geometry_arg)
289
307
  {
290
- Montage *montage;
308
+ MagickMontage *montage;
291
309
  VALUE geometry;
292
310
 
293
311
  montage = get_writable_montage(self);
@@ -309,7 +327,7 @@ Montage_geometry_eq(VALUE self, VALUE geometry_arg)
309
327
  VALUE
310
328
  Montage_gravity_eq(VALUE self, VALUE gravity)
311
329
  {
312
- Montage *montage;
330
+ MagickMontage *montage;
313
331
 
314
332
  montage = get_writable_montage(self);
315
333
  VALUE_TO_ENUM(gravity, montage->info->gravity, GravityType);
@@ -330,6 +348,64 @@ Montage_initialize(VALUE self)
330
348
  }
331
349
 
332
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
+
333
409
  /**
334
410
  * Set matte_color value.
335
411
  *
@@ -339,7 +415,7 @@ Montage_initialize(VALUE self)
339
415
  VALUE
340
416
  Montage_matte_color_eq(VALUE self, VALUE color)
341
417
  {
342
- Montage *montage;
418
+ MagickMontage *montage;
343
419
 
344
420
  montage = get_writable_montage(self);
345
421
  Color_to_PixelColor(&montage->info->matte_color, color);
@@ -356,7 +432,7 @@ Montage_matte_color_eq(VALUE self, VALUE color)
356
432
  VALUE
357
433
  Montage_pointsize_eq(VALUE self, VALUE size)
358
434
  {
359
- Montage *montage;
435
+ MagickMontage *montage;
360
436
 
361
437
  montage = get_writable_montage(self);
362
438
  montage->info->pointsize = NUM2DBL(size);
@@ -373,7 +449,7 @@ Montage_pointsize_eq(VALUE self, VALUE size)
373
449
  VALUE
374
450
  Montage_shadow_eq(VALUE self, VALUE shadow)
375
451
  {
376
- Montage *montage;
452
+ MagickMontage *montage;
377
453
 
378
454
  montage = get_writable_montage(self);
379
455
  montage->info->shadow = (MagickBooleanType) RTEST(shadow);
@@ -390,7 +466,7 @@ Montage_shadow_eq(VALUE self, VALUE shadow)
390
466
  VALUE
391
467
  Montage_stroke_eq(VALUE self, VALUE color)
392
468
  {
393
- Montage *montage;
469
+ MagickMontage *montage;
394
470
 
395
471
  montage = get_writable_montage(self);
396
472
  Color_to_PixelColor(&montage->info->stroke, color);
@@ -408,11 +484,13 @@ Montage_stroke_eq(VALUE self, VALUE color)
408
484
  VALUE
409
485
  Montage_texture_eq(VALUE self, VALUE texture)
410
486
  {
411
- Montage *montage;
487
+ MagickMontage *montage;
412
488
  Image *texture_image;
413
489
  char temp_name[MaxTextExtent];
414
490
 
415
491
  montage = get_writable_montage(self);
492
+ texture = rm_cur_image(texture);
493
+ texture_image = rm_check_readable(texture);
416
494
 
417
495
  // If we had a previously defined temp texture image,
418
496
  // remove it now in preparation for this new one.
@@ -423,9 +501,6 @@ Montage_texture_eq(VALUE self, VALUE texture)
423
501
  montage->info->texture = NULL;
424
502
  }
425
503
 
426
- texture = rm_cur_image(texture);
427
- texture_image = rm_check_readable(texture);
428
-
429
504
  // Write a temp copy of the image & save its name.
430
505
  rm_write_temp_image(texture_image, temp_name, sizeof(temp_name));
431
506
  magick_clone_string(&montage->info->texture, temp_name);
@@ -448,7 +523,7 @@ Montage_texture_eq(VALUE self, VALUE texture)
448
523
  VALUE
449
524
  Montage_tile_eq(VALUE self, VALUE tile_arg)
450
525
  {
451
- Montage *montage;
526
+ MagickMontage *montage;
452
527
  VALUE tile;
453
528
 
454
529
  montage = get_writable_montage(self);
@@ -473,7 +548,7 @@ Montage_tile_eq(VALUE self, VALUE tile_arg)
473
548
  VALUE
474
549
  Montage_title_eq(VALUE self, VALUE title)
475
550
  {
476
- Montage *montage;
551
+ MagickMontage *montage;
477
552
  const char *title_cstr;
478
553
 
479
554
  montage = get_writable_montage(self);