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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +164 -0
- data/README.md +12 -0
- data/Rakefile +1 -0
- data/ext/RMagick/extconf.rb +6 -2
- data/ext/RMagick/rmagick.cpp +55 -58
- data/ext/RMagick/rmagick.h +103 -56
- data/ext/RMagick/rmagick_gvl.cpp +1394 -0
- data/ext/RMagick/rmagick_gvl.h +4 -2
- data/ext/RMagick/rmagick_gvl.hpp +105 -0
- data/ext/RMagick/rmdraw.cpp +702 -294
- data/ext/RMagick/rmenum.cpp +59 -19
- data/ext/RMagick/rmfill.cpp +138 -47
- data/ext/RMagick/rmilist.cpp +387 -183
- data/ext/RMagick/rmimage.cpp +3554 -1711
- data/ext/RMagick/rminfo.cpp +305 -143
- data/ext/RMagick/rmkinfo.cpp +106 -29
- data/ext/RMagick/rmmain.cpp +744 -571
- data/ext/RMagick/rmmontage.cpp +151 -56
- data/ext/RMagick/rmpixel.cpp +115 -112
- data/ext/RMagick/rmstruct.cpp +147 -98
- data/ext/RMagick/rmutil.cpp +432 -93
- data/lib/rmagick/version.rb +1 -1
- data/lib/rmagick_internal.rb +82 -21
- data/lib/rvg/rvg.rb +1 -1
- data/sig/rmagick/_image_common_methods.rbs +1 -1
- data/sig/rmagick/enum.rbs +2 -0
- data/sig/rmagick/image.rbs +1 -0
- data/sig/rmagick/image_list.rbs +1 -0
- data/sig/rmagick/optional_method_arguments.rbs +1 -1
- metadata +4 -2
data/ext/RMagick/rmdraw.cpp
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
#include "rmagick.h"
|
|
13
13
|
#include "float.h"
|
|
14
|
+
#include "ruby/ractor.h"
|
|
14
15
|
|
|
15
16
|
static void Draw_compact(void *drawptr);
|
|
16
17
|
static void Draw_mark(void *);
|
|
@@ -19,6 +20,12 @@ static size_t Draw_memsize(const void *);
|
|
|
19
20
|
static VALUE new_DrawOptions(void);
|
|
20
21
|
static VALUE get_type_metrics(int, VALUE *, VALUE, gvl_function_t);
|
|
21
22
|
|
|
23
|
+
#if defined(HAVE_RB_RACTOR_LOCAL_STORAGE_VALUE_NEWKEY)
|
|
24
|
+
static rb_ractor_local_key_t dummy_img_key;
|
|
25
|
+
#else
|
|
26
|
+
static VALUE dummy_img = Qnil;
|
|
27
|
+
#endif
|
|
28
|
+
|
|
22
29
|
const rb_data_type_t rm_draw_data_type = {
|
|
23
30
|
"Magick::Draw",
|
|
24
31
|
{
|
|
@@ -28,7 +35,7 @@ const rb_data_type_t rm_draw_data_type = {
|
|
|
28
35
|
Draw_compact,
|
|
29
36
|
},
|
|
30
37
|
0, 0,
|
|
31
|
-
RUBY_TYPED_FROZEN_SHAREABLE,
|
|
38
|
+
RUBY_TYPED_FROZEN_SHAREABLE | RM_TYPED_FREE_IMMEDIATELY,
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
|
|
@@ -48,7 +55,7 @@ DEFINE_GVL_STUB3(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
|
|
|
48
55
|
|
|
49
56
|
|
|
50
57
|
/**
|
|
51
|
-
* Fetch the
|
|
58
|
+
* Fetch the MagickDraw struct and ensure it has been initialized (draw->info != NULL).
|
|
52
59
|
*
|
|
53
60
|
* Draw_alloc() leaves draw->info NULL until #initialize runs, so a Draw obtained
|
|
54
61
|
* via .allocate (or a subclass whose #initialize skips super) would otherwise
|
|
@@ -57,15 +64,15 @@ DEFINE_GVL_STUB3(GetTypeMetrics, Image *, const DrawInfo *, TypeMetric *);
|
|
|
57
64
|
* No Ruby usage (internal function)
|
|
58
65
|
*
|
|
59
66
|
* @param self the Draw object
|
|
60
|
-
* @return the initialized
|
|
67
|
+
* @return the initialized MagickDraw struct
|
|
61
68
|
* @throw RuntimeError if the Draw object has not been initialized
|
|
62
69
|
*/
|
|
63
|
-
static
|
|
70
|
+
static MagickDraw *
|
|
64
71
|
get_draw(VALUE self)
|
|
65
72
|
{
|
|
66
|
-
|
|
73
|
+
MagickDraw *draw;
|
|
67
74
|
|
|
68
|
-
TypedData_Get_Struct(self,
|
|
75
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
69
76
|
if (!draw->info)
|
|
70
77
|
{
|
|
71
78
|
rb_raise(rb_eRuntimeError, "%s has not been initialized", rb_obj_classname(self));
|
|
@@ -74,6 +81,28 @@ get_draw(VALUE self)
|
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Get the MagickDraw struct of a Draw object for a method that changes it.
|
|
86
|
+
*
|
|
87
|
+
* No Ruby usage (internal function)
|
|
88
|
+
*
|
|
89
|
+
* @param self the Draw object
|
|
90
|
+
* @return the initialized MagickDraw struct
|
|
91
|
+
* @throw FrozenError if the Draw object is frozen
|
|
92
|
+
* @throw RuntimeError if a call in flight is using the Draw object
|
|
93
|
+
*/
|
|
94
|
+
static MagickDraw *
|
|
95
|
+
get_writable_draw(VALUE self)
|
|
96
|
+
{
|
|
97
|
+
MagickDraw *draw;
|
|
98
|
+
|
|
99
|
+
rb_check_frozen(self);
|
|
100
|
+
draw = get_draw(self);
|
|
101
|
+
rm_gvl_check_writable(self);
|
|
102
|
+
return draw;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
77
106
|
/**
|
|
78
107
|
* Set the affine matrix from an {Magick::AffineMatrix}.
|
|
79
108
|
*
|
|
@@ -83,11 +112,13 @@ get_draw(VALUE self)
|
|
|
83
112
|
VALUE
|
|
84
113
|
Draw_affine_eq(VALUE self, VALUE matrix)
|
|
85
114
|
{
|
|
86
|
-
|
|
115
|
+
MagickDraw *draw;
|
|
116
|
+
AffineMatrix affine;
|
|
87
117
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
118
|
+
get_writable_draw(self);
|
|
119
|
+
Export_AffineMatrix(&affine, matrix);
|
|
120
|
+
draw = get_writable_draw(self);
|
|
121
|
+
draw->info->affine = affine;
|
|
91
122
|
return matrix;
|
|
92
123
|
}
|
|
93
124
|
|
|
@@ -101,10 +132,9 @@ Draw_affine_eq(VALUE self, VALUE matrix)
|
|
|
101
132
|
VALUE
|
|
102
133
|
Draw_align_eq(VALUE self, VALUE align)
|
|
103
134
|
{
|
|
104
|
-
|
|
135
|
+
MagickDraw *draw;
|
|
105
136
|
|
|
106
|
-
|
|
107
|
-
draw = get_draw(self);
|
|
137
|
+
draw = get_writable_draw(self);
|
|
108
138
|
VALUE_TO_ENUM(align, draw->info->align, AlignType);
|
|
109
139
|
return align;
|
|
110
140
|
}
|
|
@@ -119,10 +149,9 @@ Draw_align_eq(VALUE self, VALUE align)
|
|
|
119
149
|
VALUE
|
|
120
150
|
Draw_decorate_eq(VALUE self, VALUE decorate)
|
|
121
151
|
{
|
|
122
|
-
|
|
152
|
+
MagickDraw *draw;
|
|
123
153
|
|
|
124
|
-
|
|
125
|
-
draw = get_draw(self);
|
|
154
|
+
draw = get_writable_draw(self);
|
|
126
155
|
VALUE_TO_ENUM(decorate, draw->info->decorate, DecorationType);
|
|
127
156
|
return decorate;
|
|
128
157
|
}
|
|
@@ -137,11 +166,13 @@ Draw_decorate_eq(VALUE self, VALUE decorate)
|
|
|
137
166
|
VALUE
|
|
138
167
|
Draw_density_eq(VALUE self, VALUE density)
|
|
139
168
|
{
|
|
140
|
-
|
|
169
|
+
MagickDraw *draw;
|
|
170
|
+
char *value;
|
|
141
171
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
172
|
+
get_writable_draw(self);
|
|
173
|
+
value = StringValueCStr(density);
|
|
174
|
+
draw = get_writable_draw(self);
|
|
175
|
+
magick_clone_string(&draw->info->density, value);
|
|
145
176
|
|
|
146
177
|
return density;
|
|
147
178
|
}
|
|
@@ -156,11 +187,13 @@ Draw_density_eq(VALUE self, VALUE density)
|
|
|
156
187
|
VALUE
|
|
157
188
|
Draw_encoding_eq(VALUE self, VALUE encoding)
|
|
158
189
|
{
|
|
159
|
-
|
|
190
|
+
MagickDraw *draw;
|
|
191
|
+
char *value;
|
|
160
192
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
193
|
+
get_writable_draw(self);
|
|
194
|
+
value = StringValueCStr(encoding);
|
|
195
|
+
draw = get_writable_draw(self);
|
|
196
|
+
magick_clone_string(&draw->info->encoding, value);
|
|
164
197
|
|
|
165
198
|
return encoding;
|
|
166
199
|
}
|
|
@@ -175,53 +208,97 @@ Draw_encoding_eq(VALUE self, VALUE encoding)
|
|
|
175
208
|
VALUE
|
|
176
209
|
Draw_fill_eq(VALUE self, VALUE fill)
|
|
177
210
|
{
|
|
178
|
-
|
|
211
|
+
MagickDraw *draw;
|
|
212
|
+
PixelColor color;
|
|
179
213
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
214
|
+
get_writable_draw(self);
|
|
215
|
+
Color_to_PixelColor(&color, fill);
|
|
216
|
+
draw = get_writable_draw(self);
|
|
217
|
+
draw->info->fill = color;
|
|
183
218
|
return fill;
|
|
184
219
|
}
|
|
185
220
|
|
|
186
221
|
|
|
187
222
|
/**
|
|
188
|
-
*
|
|
223
|
+
* Call get_writable_draw under rb_protect.
|
|
189
224
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
* @
|
|
193
|
-
* @
|
|
194
|
-
* @see #tile=
|
|
225
|
+
* No Ruby usage (internal function)
|
|
226
|
+
*
|
|
227
|
+
* @param self this object
|
|
228
|
+
* @return the MagickDraw struct
|
|
195
229
|
*/
|
|
196
|
-
VALUE
|
|
197
|
-
|
|
230
|
+
static VALUE
|
|
231
|
+
writable_draw(VALUE self)
|
|
198
232
|
{
|
|
199
|
-
|
|
233
|
+
return (VALUE)get_writable_draw(self);
|
|
234
|
+
}
|
|
200
235
|
|
|
201
|
-
rb_check_frozen(self);
|
|
202
|
-
draw = get_draw(self);
|
|
203
236
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Set the fill or stroke pattern to a copy of an image.
|
|
239
|
+
*
|
|
240
|
+
* No Ruby usage (internal function)
|
|
241
|
+
*
|
|
242
|
+
* @param self this object
|
|
243
|
+
* @param pattern the image or imagelist, or nil
|
|
244
|
+
* @param stroke whether to set the stroke pattern instead of the fill pattern
|
|
245
|
+
* @return the image the pattern was copied from, or nil
|
|
246
|
+
*/
|
|
247
|
+
static VALUE
|
|
248
|
+
set_pattern(VALUE self, VALUE pattern, bool stroke)
|
|
249
|
+
{
|
|
250
|
+
MagickDraw *draw;
|
|
251
|
+
Image *copy = NULL;
|
|
252
|
+
Image **slot;
|
|
253
|
+
int state;
|
|
210
254
|
|
|
255
|
+
get_writable_draw(self);
|
|
211
256
|
if (!NIL_P(pattern))
|
|
212
257
|
{
|
|
213
|
-
Image *image;
|
|
214
|
-
|
|
215
258
|
pattern = rm_cur_image(pattern);
|
|
216
|
-
image = rm_check_destroyed(pattern);
|
|
217
259
|
// Do not trace creation
|
|
218
|
-
|
|
260
|
+
copy = rm_copy_image(rm_check_readable(pattern), pattern);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
draw = (MagickDraw *)rb_protect(writable_draw, self, &state);
|
|
264
|
+
if (state)
|
|
265
|
+
{
|
|
266
|
+
if (copy)
|
|
267
|
+
{
|
|
268
|
+
DestroyImage(copy);
|
|
269
|
+
}
|
|
270
|
+
rb_jump_tag(state);
|
|
219
271
|
}
|
|
220
272
|
|
|
273
|
+
// DestroyDrawInfo destroys the clone
|
|
274
|
+
slot = stroke ? &draw->info->stroke_pattern : &draw->info->fill_pattern;
|
|
275
|
+
if (*slot)
|
|
276
|
+
{
|
|
277
|
+
// Do not trace destruction
|
|
278
|
+
DestroyImage(*slot);
|
|
279
|
+
}
|
|
280
|
+
*slot = copy;
|
|
281
|
+
|
|
221
282
|
return pattern;
|
|
222
283
|
}
|
|
223
284
|
|
|
224
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Accept an image as a fill pattern.
|
|
288
|
+
*
|
|
289
|
+
* @param pattern [Magick::Image, Magick::ImageList] Either an imagelist or an image. If an
|
|
290
|
+
* imagelist, uses the current image.
|
|
291
|
+
* @return [Magick::Image] the given pattern image
|
|
292
|
+
* @see #stroke_pattern=
|
|
293
|
+
* @see #tile=
|
|
294
|
+
*/
|
|
295
|
+
VALUE
|
|
296
|
+
Draw_fill_pattern_eq(VALUE self, VALUE pattern)
|
|
297
|
+
{
|
|
298
|
+
return set_pattern(self, pattern, false);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
225
302
|
/**
|
|
226
303
|
* Set the font name.
|
|
227
304
|
*
|
|
@@ -231,11 +308,13 @@ Draw_fill_pattern_eq(VALUE self, VALUE pattern)
|
|
|
231
308
|
VALUE
|
|
232
309
|
Draw_font_eq(VALUE self, VALUE font)
|
|
233
310
|
{
|
|
234
|
-
|
|
311
|
+
MagickDraw *draw;
|
|
312
|
+
char *value;
|
|
235
313
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
314
|
+
get_writable_draw(self);
|
|
315
|
+
value = StringValueCStr(font);
|
|
316
|
+
draw = get_writable_draw(self);
|
|
317
|
+
magick_clone_string(&draw->info->font, value);
|
|
239
318
|
|
|
240
319
|
return font;
|
|
241
320
|
}
|
|
@@ -250,11 +329,13 @@ Draw_font_eq(VALUE self, VALUE font)
|
|
|
250
329
|
VALUE
|
|
251
330
|
Draw_font_family_eq(VALUE self, VALUE family)
|
|
252
331
|
{
|
|
253
|
-
|
|
332
|
+
MagickDraw *draw;
|
|
333
|
+
char *value;
|
|
254
334
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
335
|
+
get_writable_draw(self);
|
|
336
|
+
value = StringValueCStr(family);
|
|
337
|
+
draw = get_writable_draw(self);
|
|
338
|
+
magick_clone_string(&draw->info->family, value);
|
|
258
339
|
|
|
259
340
|
return family;
|
|
260
341
|
}
|
|
@@ -269,10 +350,9 @@ Draw_font_family_eq(VALUE self, VALUE family)
|
|
|
269
350
|
VALUE
|
|
270
351
|
Draw_font_stretch_eq(VALUE self, VALUE stretch)
|
|
271
352
|
{
|
|
272
|
-
|
|
353
|
+
MagickDraw *draw;
|
|
273
354
|
|
|
274
|
-
|
|
275
|
-
draw = get_draw(self);
|
|
355
|
+
draw = get_writable_draw(self);
|
|
276
356
|
VALUE_TO_ENUM(stretch, draw->info->stretch, StretchType);
|
|
277
357
|
return stretch;
|
|
278
358
|
}
|
|
@@ -287,10 +367,9 @@ Draw_font_stretch_eq(VALUE self, VALUE stretch)
|
|
|
287
367
|
VALUE
|
|
288
368
|
Draw_font_style_eq(VALUE self, VALUE style)
|
|
289
369
|
{
|
|
290
|
-
|
|
370
|
+
MagickDraw *draw;
|
|
291
371
|
|
|
292
|
-
|
|
293
|
-
draw = get_draw(self);
|
|
372
|
+
draw = get_writable_draw(self);
|
|
294
373
|
VALUE_TO_ENUM(style, draw->info->style, StyleType);
|
|
295
374
|
return style;
|
|
296
375
|
}
|
|
@@ -306,11 +385,10 @@ Draw_font_style_eq(VALUE self, VALUE style)
|
|
|
306
385
|
VALUE
|
|
307
386
|
Draw_font_weight_eq(VALUE self, VALUE weight)
|
|
308
387
|
{
|
|
309
|
-
|
|
388
|
+
MagickDraw *draw;
|
|
310
389
|
size_t w;
|
|
311
390
|
|
|
312
|
-
|
|
313
|
-
draw = get_draw(self);
|
|
391
|
+
draw = get_writable_draw(self);
|
|
314
392
|
|
|
315
393
|
if (FIXNUM_P(weight))
|
|
316
394
|
{
|
|
@@ -373,10 +451,9 @@ Draw_font_weight_eq(VALUE self, VALUE weight)
|
|
|
373
451
|
VALUE
|
|
374
452
|
Draw_gravity_eq(VALUE self, VALUE grav)
|
|
375
453
|
{
|
|
376
|
-
|
|
454
|
+
MagickDraw *draw;
|
|
377
455
|
|
|
378
|
-
|
|
379
|
-
draw = get_draw(self);
|
|
456
|
+
draw = get_writable_draw(self);
|
|
380
457
|
VALUE_TO_ENUM(grav, draw->info->gravity, GravityType);
|
|
381
458
|
|
|
382
459
|
return grav;
|
|
@@ -392,11 +469,13 @@ Draw_gravity_eq(VALUE self, VALUE grav)
|
|
|
392
469
|
VALUE
|
|
393
470
|
Draw_kerning_eq(VALUE self, VALUE kerning)
|
|
394
471
|
{
|
|
395
|
-
|
|
472
|
+
MagickDraw *draw;
|
|
473
|
+
double value;
|
|
396
474
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
draw
|
|
475
|
+
get_writable_draw(self);
|
|
476
|
+
value = NUM2DBL(kerning);
|
|
477
|
+
draw = get_writable_draw(self);
|
|
478
|
+
draw->info->kerning = value;
|
|
400
479
|
return kerning;
|
|
401
480
|
}
|
|
402
481
|
|
|
@@ -410,11 +489,13 @@ Draw_kerning_eq(VALUE self, VALUE kerning)
|
|
|
410
489
|
VALUE
|
|
411
490
|
Draw_interline_spacing_eq(VALUE self, VALUE spacing)
|
|
412
491
|
{
|
|
413
|
-
|
|
492
|
+
MagickDraw *draw;
|
|
493
|
+
double value;
|
|
414
494
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
draw
|
|
495
|
+
get_writable_draw(self);
|
|
496
|
+
value = NUM2DBL(spacing);
|
|
497
|
+
draw = get_writable_draw(self);
|
|
498
|
+
draw->info->interline_spacing = value;
|
|
418
499
|
return spacing;
|
|
419
500
|
}
|
|
420
501
|
|
|
@@ -428,11 +509,13 @@ Draw_interline_spacing_eq(VALUE self, VALUE spacing)
|
|
|
428
509
|
VALUE
|
|
429
510
|
Draw_interword_spacing_eq(VALUE self, VALUE spacing)
|
|
430
511
|
{
|
|
431
|
-
|
|
512
|
+
MagickDraw *draw;
|
|
513
|
+
double value;
|
|
432
514
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
draw
|
|
515
|
+
get_writable_draw(self);
|
|
516
|
+
value = NUM2DBL(spacing);
|
|
517
|
+
draw = get_writable_draw(self);
|
|
518
|
+
draw->info->interword_spacing = value;
|
|
436
519
|
return spacing;
|
|
437
520
|
}
|
|
438
521
|
|
|
@@ -446,11 +529,12 @@ Draw_interword_spacing_eq(VALUE self, VALUE spacing)
|
|
|
446
529
|
* - Returns Qnil if there is no image
|
|
447
530
|
*
|
|
448
531
|
* @param image the Image to convert
|
|
532
|
+
* @param owner the Draw object that holds image
|
|
449
533
|
* @return Ruby string representation of image
|
|
450
534
|
* @see str_to_image
|
|
451
535
|
*/
|
|
452
536
|
static VALUE
|
|
453
|
-
image_to_str(Image *image)
|
|
537
|
+
image_to_str(Image *image, VALUE owner)
|
|
454
538
|
{
|
|
455
539
|
VALUE dimg = Qnil;
|
|
456
540
|
|
|
@@ -460,12 +544,23 @@ image_to_str(Image *image)
|
|
|
460
544
|
size_t length;
|
|
461
545
|
Info *info;
|
|
462
546
|
ExceptionInfo *exception;
|
|
547
|
+
Image *copy;
|
|
463
548
|
|
|
549
|
+
// Writing the pattern changes it, and a frozen Draw may be shared with
|
|
550
|
+
// other Ractors.
|
|
551
|
+
copy = rm_copy_image(image, owner);
|
|
464
552
|
info = CloneImageInfo(NULL);
|
|
465
553
|
exception = AcquireExceptionInfo();
|
|
466
|
-
|
|
467
|
-
blob = (unsigned char
|
|
554
|
+
DECLARE_GVL_CALL(call, ImageToBlob, info, copy, &length, exception);
|
|
555
|
+
blob = call.keep_thread().destroy(copy).release(info).release(exception).free_result().run<unsigned char *>();
|
|
556
|
+
DestroyImage(copy);
|
|
468
557
|
DestroyImageInfo(info);
|
|
558
|
+
if (blob && exception->severity >= ErrorException)
|
|
559
|
+
{
|
|
560
|
+
magick_free((void*)blob);
|
|
561
|
+
blob = NULL;
|
|
562
|
+
length = 0;
|
|
563
|
+
}
|
|
469
564
|
CHECK_EXCEPTION();
|
|
470
565
|
DestroyExceptionInfo(exception);
|
|
471
566
|
dimg = rb_str_new((char *)blob, (long)length);
|
|
@@ -504,11 +599,12 @@ Image *str_to_image(VALUE str)
|
|
|
504
599
|
|
|
505
600
|
info = CloneImageInfo(NULL);
|
|
506
601
|
exception = AcquireExceptionInfo();
|
|
507
|
-
|
|
508
|
-
image = (
|
|
602
|
+
DECLARE_GVL_CALL(call, BlobToImage, info, RSTRING_PTR(str), (size_t)RSTRING_LEN(str), exception);
|
|
603
|
+
image = call.keep_thread().release(info).release(exception).run<Image *>();
|
|
509
604
|
DestroyImageInfo(info);
|
|
510
|
-
|
|
605
|
+
rm_check_exception(exception, image, DestroyOnError);
|
|
511
606
|
DestroyExceptionInfo(exception);
|
|
607
|
+
image = rm_first_image(image);
|
|
512
608
|
}
|
|
513
609
|
|
|
514
610
|
RB_GC_GUARD(str);
|
|
@@ -517,6 +613,21 @@ Image *str_to_image(VALUE str)
|
|
|
517
613
|
}
|
|
518
614
|
|
|
519
615
|
|
|
616
|
+
/**
|
|
617
|
+
* Copy the primitives of a Draw so that changing the copy leaves the Draw alone.
|
|
618
|
+
*
|
|
619
|
+
* No Ruby usage (internal function)
|
|
620
|
+
*
|
|
621
|
+
* @param primitives the primitives, or 0 if there are none
|
|
622
|
+
* @return a copy of the String, or primitives itself if it is not a String
|
|
623
|
+
*/
|
|
624
|
+
static VALUE
|
|
625
|
+
copy_primitives(VALUE primitives)
|
|
626
|
+
{
|
|
627
|
+
return RB_TYPE_P(primitives, T_STRING) ? rb_str_dup(primitives) : primitives;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
|
|
520
631
|
/**
|
|
521
632
|
* Dump custom marshal for Draw objects.
|
|
522
633
|
*
|
|
@@ -533,7 +644,7 @@ Image *str_to_image(VALUE str)
|
|
|
533
644
|
VALUE
|
|
534
645
|
Draw_marshal_dump(VALUE self)
|
|
535
646
|
{
|
|
536
|
-
|
|
647
|
+
MagickDraw *draw;
|
|
537
648
|
VALUE ddraw;
|
|
538
649
|
|
|
539
650
|
draw = get_draw(self);
|
|
@@ -552,8 +663,8 @@ Draw_marshal_dump(VALUE self)
|
|
|
552
663
|
rb_hash_aset(ddraw, CSTR2SYM("fill"), Pixel_from_PixelColor(&draw->info->fill));
|
|
553
664
|
rb_hash_aset(ddraw, CSTR2SYM("stroke"), Pixel_from_PixelColor(&draw->info->stroke));
|
|
554
665
|
rb_hash_aset(ddraw, CSTR2SYM("stroke_width"), rb_float_new(draw->info->stroke_width));
|
|
555
|
-
rb_hash_aset(ddraw, CSTR2SYM("fill_pattern"), image_to_str(draw->info->fill_pattern));
|
|
556
|
-
rb_hash_aset(ddraw, CSTR2SYM("stroke_pattern"), image_to_str(draw->info->stroke_pattern));
|
|
666
|
+
rb_hash_aset(ddraw, CSTR2SYM("fill_pattern"), image_to_str(draw->info->fill_pattern, self));
|
|
667
|
+
rb_hash_aset(ddraw, CSTR2SYM("stroke_pattern"), image_to_str(draw->info->stroke_pattern, self));
|
|
557
668
|
rb_hash_aset(ddraw, CSTR2SYM("stroke_antialias"), draw->info->stroke_antialias ? Qtrue : Qfalse);
|
|
558
669
|
rb_hash_aset(ddraw, CSTR2SYM("text_antialias"), draw->info->text_antialias ? Qtrue : Qfalse);
|
|
559
670
|
rb_hash_aset(ddraw, CSTR2SYM("decorate"), INT2FIX(draw->info->decorate));
|
|
@@ -575,14 +686,83 @@ Draw_marshal_dump(VALUE self)
|
|
|
575
686
|
#endif
|
|
576
687
|
rb_hash_aset(ddraw, CSTR2SYM("kerning"), rb_float_new(draw->info->kerning));
|
|
577
688
|
rb_hash_aset(ddraw, CSTR2SYM("interword_spacing"), rb_float_new(draw->info->interword_spacing));
|
|
689
|
+
rb_hash_aset(ddraw, CSTR2SYM("interline_spacing"), rb_float_new(draw->info->interline_spacing));
|
|
578
690
|
|
|
579
691
|
// Non-DrawInfo fields
|
|
580
|
-
rb_hash_aset(ddraw, CSTR2SYM("primitives"), draw->primitives);
|
|
692
|
+
rb_hash_aset(ddraw, CSTR2SYM("primitives"), copy_primitives(draw->primitives));
|
|
581
693
|
|
|
582
694
|
return ddraw;
|
|
583
695
|
}
|
|
584
696
|
|
|
585
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Replace a string of a DrawInfo with a dumped value.
|
|
700
|
+
*
|
|
701
|
+
* No Ruby usage (internal function)
|
|
702
|
+
*
|
|
703
|
+
* @param field the string to replace
|
|
704
|
+
* @param obj the dumped value, or nil for no string
|
|
705
|
+
*/
|
|
706
|
+
static void
|
|
707
|
+
load_string(char **field, VALUE obj)
|
|
708
|
+
{
|
|
709
|
+
if (NIL_P(obj))
|
|
710
|
+
{
|
|
711
|
+
magick_clone_string(field, NULL);
|
|
712
|
+
}
|
|
713
|
+
else
|
|
714
|
+
{
|
|
715
|
+
VALUE str = rb_String(obj);
|
|
716
|
+
magick_clone_string(field, StringValueCStr(str));
|
|
717
|
+
RB_GC_GUARD(str);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Move the values that Draw#marshal_load loads from one DrawInfo to another.
|
|
724
|
+
*
|
|
725
|
+
* No Ruby usage (internal function)
|
|
726
|
+
*
|
|
727
|
+
* @param info the DrawInfo of the Draw
|
|
728
|
+
* @param loaded the loaded values, which get the old strings and patterns of info
|
|
729
|
+
*/
|
|
730
|
+
static void
|
|
731
|
+
move_loaded_values(DrawInfo *info, DrawInfo *loaded)
|
|
732
|
+
{
|
|
733
|
+
std::swap(info->geometry, loaded->geometry);
|
|
734
|
+
info->affine = loaded->affine;
|
|
735
|
+
info->gravity = loaded->gravity;
|
|
736
|
+
info->fill = loaded->fill;
|
|
737
|
+
info->stroke = loaded->stroke;
|
|
738
|
+
info->stroke_width = loaded->stroke_width;
|
|
739
|
+
std::swap(info->fill_pattern, loaded->fill_pattern);
|
|
740
|
+
std::swap(info->stroke_pattern, loaded->stroke_pattern);
|
|
741
|
+
info->stroke_antialias = loaded->stroke_antialias;
|
|
742
|
+
info->text_antialias = loaded->text_antialias;
|
|
743
|
+
info->decorate = loaded->decorate;
|
|
744
|
+
std::swap(info->font, loaded->font);
|
|
745
|
+
std::swap(info->family, loaded->family);
|
|
746
|
+
info->style = loaded->style;
|
|
747
|
+
info->stretch = loaded->stretch;
|
|
748
|
+
info->weight = loaded->weight;
|
|
749
|
+
std::swap(info->encoding, loaded->encoding);
|
|
750
|
+
info->pointsize = loaded->pointsize;
|
|
751
|
+
std::swap(info->density, loaded->density);
|
|
752
|
+
info->align = loaded->align;
|
|
753
|
+
info->undercolor = loaded->undercolor;
|
|
754
|
+
info->clip_units = loaded->clip_units;
|
|
755
|
+
#if defined(IMAGEMAGICK_7)
|
|
756
|
+
info->alpha = loaded->alpha;
|
|
757
|
+
#else
|
|
758
|
+
info->opacity = loaded->opacity;
|
|
759
|
+
#endif
|
|
760
|
+
info->kerning = loaded->kerning;
|
|
761
|
+
info->interword_spacing = loaded->interword_spacing;
|
|
762
|
+
info->interline_spacing = loaded->interline_spacing;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
|
|
586
766
|
/**
|
|
587
767
|
* Load the marshalled object
|
|
588
768
|
*
|
|
@@ -592,65 +772,98 @@ Draw_marshal_dump(VALUE self)
|
|
|
592
772
|
VALUE
|
|
593
773
|
Draw_marshal_load(VALUE self, VALUE ddraw)
|
|
594
774
|
{
|
|
595
|
-
|
|
596
|
-
|
|
775
|
+
MagickDraw *draw, *loaded;
|
|
776
|
+
DrawInfo *info;
|
|
777
|
+
VALUE loaded_obj, primitives, val;
|
|
778
|
+
bool has_interline_spacing;
|
|
597
779
|
|
|
598
|
-
|
|
780
|
+
rb_check_frozen(self);
|
|
781
|
+
rm_gvl_check_writable(self);
|
|
782
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
599
783
|
|
|
600
784
|
Check_Type(ddraw, T_HASH);
|
|
601
785
|
|
|
602
|
-
|
|
786
|
+
loaded_obj = DrawOptions_alloc(Class_DrawOptions);
|
|
787
|
+
TypedData_Get_Struct(loaded_obj, MagickDraw, &rm_draw_data_type, loaded);
|
|
788
|
+
loaded->info = CloneDrawInfo(NULL, (DrawInfo *) NULL);
|
|
789
|
+
if (!loaded->info)
|
|
603
790
|
{
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
image_info = CloneImageInfo(NULL);
|
|
607
|
-
draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
|
|
608
|
-
DestroyImageInfo(image_info);
|
|
791
|
+
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
609
792
|
}
|
|
610
|
-
|
|
793
|
+
info = loaded->info;
|
|
794
|
+
|
|
795
|
+
load_string(&info->geometry, rb_hash_aref(ddraw, CSTR2SYM("geometry")));
|
|
611
796
|
|
|
612
797
|
val = rb_hash_aref(ddraw, CSTR2SYM("affine"));
|
|
613
|
-
Export_AffineMatrix(&
|
|
798
|
+
Export_AffineMatrix(&info->affine, val);
|
|
614
799
|
|
|
615
|
-
|
|
800
|
+
info->gravity = (GravityType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("gravity")));
|
|
616
801
|
|
|
617
802
|
val = rb_hash_aref(ddraw, CSTR2SYM("fill"));
|
|
618
|
-
Color_to_PixelColor(&
|
|
803
|
+
Color_to_PixelColor(&info->fill, val);
|
|
619
804
|
|
|
620
805
|
val = rb_hash_aref(ddraw, CSTR2SYM("stroke"));
|
|
621
|
-
Color_to_PixelColor(&
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
806
|
+
Color_to_PixelColor(&info->stroke, val);
|
|
807
|
+
|
|
808
|
+
info->stroke_width = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("stroke_width")));
|
|
809
|
+
info->fill_pattern = str_to_image(rb_hash_aref(ddraw, CSTR2SYM("fill_pattern")));
|
|
810
|
+
info->stroke_pattern = str_to_image(rb_hash_aref(ddraw, CSTR2SYM("stroke_pattern")));
|
|
811
|
+
info->stroke_antialias = (MagickBooleanType)RTEST(rb_hash_aref(ddraw, CSTR2SYM("stroke_antialias")));
|
|
812
|
+
info->text_antialias = (MagickBooleanType)RTEST(rb_hash_aref(ddraw, CSTR2SYM("text_antialias")));
|
|
813
|
+
info->decorate = (DecorationType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("decorate")));
|
|
814
|
+
load_string(&info->font, rb_hash_aref(ddraw, CSTR2SYM("font")));
|
|
815
|
+
load_string(&info->family, rb_hash_aref(ddraw, CSTR2SYM("family")));
|
|
816
|
+
|
|
817
|
+
info->style = (StyleType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("style")));
|
|
818
|
+
info->stretch = (StretchType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("stretch")));
|
|
819
|
+
info->weight = NUM2ULONG(rb_hash_aref(ddraw, CSTR2SYM("weight")));
|
|
820
|
+
load_string(&info->encoding, rb_hash_aref(ddraw, CSTR2SYM("encoding")));
|
|
821
|
+
info->pointsize = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("pointsize")));
|
|
822
|
+
load_string(&info->density, rb_hash_aref(ddraw, CSTR2SYM("density")));
|
|
823
|
+
info->align = (AlignType) FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("align")));
|
|
639
824
|
|
|
640
825
|
val = rb_hash_aref(ddraw, CSTR2SYM("undercolor"));
|
|
641
|
-
Color_to_PixelColor(&
|
|
826
|
+
Color_to_PixelColor(&info->undercolor, val);
|
|
642
827
|
|
|
643
|
-
|
|
828
|
+
info->clip_units = (ClipPathUnits)FIX2INT(rb_hash_aref(ddraw, CSTR2SYM("clip_units")));
|
|
644
829
|
#if defined(IMAGEMAGICK_7)
|
|
645
|
-
|
|
830
|
+
info->alpha = APP2QUANTUM(rb_hash_aref(ddraw, CSTR2SYM("alpha")));
|
|
646
831
|
#else
|
|
647
|
-
|
|
832
|
+
info->opacity = APP2QUANTUM(rb_hash_aref(ddraw, CSTR2SYM("opacity")));
|
|
648
833
|
#endif
|
|
649
|
-
|
|
650
|
-
|
|
834
|
+
info->kerning = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("kerning")));
|
|
835
|
+
info->interword_spacing = NUM2DBL(rb_hash_aref(ddraw, CSTR2SYM("interword_spacing")));
|
|
836
|
+
val = rb_hash_lookup2(ddraw, CSTR2SYM("interline_spacing"), Qundef);
|
|
837
|
+
has_interline_spacing = val != Qundef;
|
|
838
|
+
if (has_interline_spacing)
|
|
839
|
+
{
|
|
840
|
+
info->interline_spacing = NUM2DBL(val);
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
primitives = copy_primitives(rb_hash_aref(ddraw, CSTR2SYM("primitives")));
|
|
651
844
|
|
|
652
|
-
|
|
845
|
+
// Converting the values runs Ruby code, and loading a pattern releases
|
|
846
|
+
// the GVL, so other code can freeze self or start a call that uses it.
|
|
847
|
+
rb_check_frozen(self);
|
|
848
|
+
rm_gvl_check_writable(self);
|
|
849
|
+
if (draw->info)
|
|
850
|
+
{
|
|
851
|
+
if (!has_interline_spacing)
|
|
852
|
+
{
|
|
853
|
+
info->interline_spacing = draw->info->interline_spacing;
|
|
854
|
+
}
|
|
855
|
+
move_loaded_values(draw->info, info);
|
|
856
|
+
DestroyDrawInfo(info);
|
|
857
|
+
}
|
|
858
|
+
else
|
|
859
|
+
{
|
|
860
|
+
draw->info = info;
|
|
861
|
+
}
|
|
862
|
+
loaded->info = NULL;
|
|
863
|
+
draw->primitives = primitives;
|
|
653
864
|
|
|
865
|
+
RB_GC_GUARD(loaded_obj);
|
|
866
|
+
RB_GC_GUARD(primitives);
|
|
654
867
|
RB_GC_GUARD(val);
|
|
655
868
|
|
|
656
869
|
return self;
|
|
@@ -666,11 +879,13 @@ Draw_marshal_load(VALUE self, VALUE ddraw)
|
|
|
666
879
|
VALUE
|
|
667
880
|
Draw_pointsize_eq(VALUE self, VALUE pointsize)
|
|
668
881
|
{
|
|
669
|
-
|
|
882
|
+
MagickDraw *draw;
|
|
883
|
+
double value;
|
|
670
884
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
draw
|
|
885
|
+
get_writable_draw(self);
|
|
886
|
+
value = NUM2DBL(pointsize);
|
|
887
|
+
draw = get_writable_draw(self);
|
|
888
|
+
draw->info->pointsize = value;
|
|
674
889
|
return pointsize;
|
|
675
890
|
}
|
|
676
891
|
|
|
@@ -684,14 +899,14 @@ Draw_pointsize_eq(VALUE self, VALUE pointsize)
|
|
|
684
899
|
VALUE
|
|
685
900
|
Draw_rotation_eq(VALUE self, VALUE deg)
|
|
686
901
|
{
|
|
687
|
-
|
|
902
|
+
MagickDraw *draw;
|
|
688
903
|
double degrees;
|
|
689
904
|
AffineMatrix affine, current;
|
|
690
905
|
|
|
691
|
-
|
|
692
|
-
draw = get_draw(self);
|
|
693
|
-
|
|
906
|
+
get_writable_draw(self);
|
|
694
907
|
degrees = NUM2DBL(deg);
|
|
908
|
+
draw = get_writable_draw(self);
|
|
909
|
+
|
|
695
910
|
if (fabs(degrees) > DBL_EPSILON)
|
|
696
911
|
{
|
|
697
912
|
current = draw->info->affine;
|
|
@@ -722,11 +937,13 @@ Draw_rotation_eq(VALUE self, VALUE deg)
|
|
|
722
937
|
VALUE
|
|
723
938
|
Draw_stroke_eq(VALUE self, VALUE stroke)
|
|
724
939
|
{
|
|
725
|
-
|
|
940
|
+
MagickDraw *draw;
|
|
941
|
+
PixelColor color;
|
|
726
942
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
943
|
+
get_writable_draw(self);
|
|
944
|
+
Color_to_PixelColor(&color, stroke);
|
|
945
|
+
draw = get_writable_draw(self);
|
|
946
|
+
draw->info->stroke = color;
|
|
730
947
|
return stroke;
|
|
731
948
|
}
|
|
732
949
|
|
|
@@ -742,30 +959,7 @@ Draw_stroke_eq(VALUE self, VALUE stroke)
|
|
|
742
959
|
VALUE
|
|
743
960
|
Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
|
|
744
961
|
{
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
rb_check_frozen(self);
|
|
748
|
-
draw = get_draw(self);
|
|
749
|
-
|
|
750
|
-
if (draw->info->stroke_pattern != NULL)
|
|
751
|
-
{
|
|
752
|
-
// Do not trace destruction
|
|
753
|
-
DestroyImage(draw->info->stroke_pattern);
|
|
754
|
-
draw->info->stroke_pattern = NULL;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
if (!NIL_P(pattern))
|
|
758
|
-
{
|
|
759
|
-
Image *image;
|
|
760
|
-
|
|
761
|
-
// DestroyDrawInfo destroys the clone
|
|
762
|
-
pattern = rm_cur_image(pattern);
|
|
763
|
-
image = rm_check_destroyed(pattern);
|
|
764
|
-
// Do not trace creation
|
|
765
|
-
draw->info->stroke_pattern = rm_clone_image(image);
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
return pattern;
|
|
962
|
+
return set_pattern(self, pattern, true);
|
|
769
963
|
}
|
|
770
964
|
|
|
771
965
|
|
|
@@ -778,11 +972,13 @@ Draw_stroke_pattern_eq(VALUE self, VALUE pattern)
|
|
|
778
972
|
VALUE
|
|
779
973
|
Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
|
|
780
974
|
{
|
|
781
|
-
|
|
975
|
+
MagickDraw *draw;
|
|
976
|
+
double value;
|
|
782
977
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
draw
|
|
978
|
+
get_writable_draw(self);
|
|
979
|
+
value = NUM2DBL(stroke_width);
|
|
980
|
+
draw = get_writable_draw(self);
|
|
981
|
+
draw->info->stroke_width = value;
|
|
786
982
|
return stroke_width;
|
|
787
983
|
}
|
|
788
984
|
|
|
@@ -796,10 +992,9 @@ Draw_stroke_width_eq(VALUE self, VALUE stroke_width)
|
|
|
796
992
|
VALUE
|
|
797
993
|
Draw_text_antialias_eq(VALUE self, VALUE text_antialias)
|
|
798
994
|
{
|
|
799
|
-
|
|
995
|
+
MagickDraw *draw;
|
|
800
996
|
|
|
801
|
-
|
|
802
|
-
draw = get_draw(self);
|
|
997
|
+
draw = get_writable_draw(self);
|
|
803
998
|
draw->info->text_antialias = (MagickBooleanType) RTEST(text_antialias);
|
|
804
999
|
return text_antialias;
|
|
805
1000
|
}
|
|
@@ -827,11 +1022,13 @@ Draw_tile_eq(VALUE self, VALUE image)
|
|
|
827
1022
|
VALUE
|
|
828
1023
|
Draw_undercolor_eq(VALUE self, VALUE undercolor)
|
|
829
1024
|
{
|
|
830
|
-
|
|
1025
|
+
MagickDraw *draw;
|
|
1026
|
+
PixelColor color;
|
|
831
1027
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1028
|
+
get_writable_draw(self);
|
|
1029
|
+
Color_to_PixelColor(&color, undercolor);
|
|
1030
|
+
draw = get_writable_draw(self);
|
|
1031
|
+
draw->info->undercolor = color;
|
|
835
1032
|
return undercolor;
|
|
836
1033
|
}
|
|
837
1034
|
|
|
@@ -845,7 +1042,7 @@ struct Draw_annotate_args
|
|
|
845
1042
|
VALUE x_arg;
|
|
846
1043
|
VALUE y_arg;
|
|
847
1044
|
VALUE text;
|
|
848
|
-
|
|
1045
|
+
MagickDraw *draw;
|
|
849
1046
|
AffineMatrix keep;
|
|
850
1047
|
#if defined(IMAGEMAGICK_7)
|
|
851
1048
|
ExceptionInfo *exception;
|
|
@@ -853,6 +1050,89 @@ struct Draw_annotate_args
|
|
|
853
1050
|
};
|
|
854
1051
|
|
|
855
1052
|
|
|
1053
|
+
// A DrawInfo whose patterns to copy, and an object that the caller uses after
|
|
1054
|
+
// the copies
|
|
1055
|
+
struct CopyPatterns_Args
|
|
1056
|
+
{
|
|
1057
|
+
DrawInfo *info;
|
|
1058
|
+
VALUE held;
|
|
1059
|
+
};
|
|
1060
|
+
|
|
1061
|
+
|
|
1062
|
+
// Give a pattern that CloneDrawInfo shared a pixel cache of its own
|
|
1063
|
+
static void
|
|
1064
|
+
copy_pattern(Image **pattern, VALUE held)
|
|
1065
|
+
{
|
|
1066
|
+
if (*pattern)
|
|
1067
|
+
{
|
|
1068
|
+
Image *copy = rm_copy_image(*pattern, Qnil, held);
|
|
1069
|
+
|
|
1070
|
+
DestroyImage(*pattern);
|
|
1071
|
+
*pattern = copy;
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
|
|
1076
|
+
static VALUE
|
|
1077
|
+
copy_patterns(VALUE arg)
|
|
1078
|
+
{
|
|
1079
|
+
struct CopyPatterns_Args *args = (struct CopyPatterns_Args *)arg;
|
|
1080
|
+
|
|
1081
|
+
copy_pattern(&args->info->fill_pattern, args->held);
|
|
1082
|
+
copy_pattern(&args->info->stroke_pattern, args->held);
|
|
1083
|
+
return Qnil;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
|
|
1087
|
+
// Copy the DrawInfo of a Draw for a call that draws. A frozen Draw may be
|
|
1088
|
+
// shared with other Ractors, whose calls would read the pixel cache of a
|
|
1089
|
+
// pattern through its default nexus at once.
|
|
1090
|
+
static DrawInfo *
|
|
1091
|
+
clone_draw_info(VALUE self, const MagickDraw *draw, VALUE image_arg)
|
|
1092
|
+
{
|
|
1093
|
+
DrawInfo *info = CloneDrawInfo(NULL, draw->info);
|
|
1094
|
+
int state = 0;
|
|
1095
|
+
|
|
1096
|
+
if (OBJ_FROZEN(self))
|
|
1097
|
+
{
|
|
1098
|
+
struct CopyPatterns_Args args = { info, image_arg };
|
|
1099
|
+
|
|
1100
|
+
rb_protect(copy_patterns, (VALUE)&args, &state);
|
|
1101
|
+
if (state)
|
|
1102
|
+
{
|
|
1103
|
+
DestroyDrawInfo(info);
|
|
1104
|
+
rb_jump_tag(state);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
return info;
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
|
|
1111
|
+
// Mark a Draw for a call. The copy of its DrawInfo shares the pixel caches of
|
|
1112
|
+
// its patterns, which ImageMagick reads through a working area that only one
|
|
1113
|
+
// call can use, so a call that may use them takes the Draw for itself.
|
|
1114
|
+
static rm_gvl_call &
|
|
1115
|
+
mark_draw(rm_gvl_call &call, VALUE obj, const MagickDraw *draw)
|
|
1116
|
+
{
|
|
1117
|
+
if (draw->info->fill_pattern || draw->info->stroke_pattern)
|
|
1118
|
+
{
|
|
1119
|
+
return call.update(obj);
|
|
1120
|
+
}
|
|
1121
|
+
return call.read(obj);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
|
|
1125
|
+
// Change back the affine matrix that the block of Draw#annotate may have changed
|
|
1126
|
+
static void
|
|
1127
|
+
restore_affine(struct Draw_annotate_args *annotate)
|
|
1128
|
+
{
|
|
1129
|
+
if (memcmp(&annotate->draw->info->affine, &annotate->keep, sizeof(annotate->keep)) != 0)
|
|
1130
|
+
{
|
|
1131
|
+
annotate->draw->info->affine = annotate->keep;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
|
|
856
1136
|
/**
|
|
857
1137
|
* Release what annotate_body acquired and restore the affine matrix.
|
|
858
1138
|
*
|
|
@@ -866,11 +1146,8 @@ static VALUE
|
|
|
866
1146
|
annotate_ensure(VALUE arg)
|
|
867
1147
|
{
|
|
868
1148
|
struct Draw_annotate_args *annotate = (struct Draw_annotate_args *)arg;
|
|
869
|
-
Draw *draw = annotate->draw;
|
|
870
1149
|
|
|
871
|
-
|
|
872
|
-
draw->info->text = NULL;
|
|
873
|
-
draw->info->affine = annotate->keep;
|
|
1150
|
+
restore_affine(annotate);
|
|
874
1151
|
|
|
875
1152
|
#if defined(IMAGEMAGICK_7)
|
|
876
1153
|
if (annotate->exception)
|
|
@@ -897,8 +1174,9 @@ static VALUE
|
|
|
897
1174
|
annotate_body(VALUE arg)
|
|
898
1175
|
{
|
|
899
1176
|
struct Draw_annotate_args *annotate = (struct Draw_annotate_args *)arg;
|
|
900
|
-
|
|
1177
|
+
MagickDraw *draw = annotate->draw;
|
|
901
1178
|
Image *image;
|
|
1179
|
+
DrawInfo *info;
|
|
902
1180
|
unsigned long width, height;
|
|
903
1181
|
long x, y;
|
|
904
1182
|
char geometry_str[100];
|
|
@@ -930,23 +1208,28 @@ annotate_body(VALUE arg)
|
|
|
930
1208
|
snprintf(geometry_str, sizeof(geometry_str), "%lux%lu%+ld%+ld", width, height, x, y);
|
|
931
1209
|
}
|
|
932
1210
|
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
// Store in Draw structure. The text is drawn as given: it is not run
|
|
1211
|
+
// Store in the MagickDraw struct. The text is drawn as given: it is not run
|
|
936
1212
|
// through InterpretImageProperties(), so a `%[...]` or `%x` escape in it is
|
|
937
1213
|
// not expanded. Everything those escapes provide is available directly from
|
|
938
1214
|
// Ruby -- Image#columns, Image#filename, Image#artifact and so on.
|
|
1215
|
+
annotate->text = rb_str_new_frozen(StringValue(annotate->text));
|
|
939
1216
|
embed_text = StringValueCStr(annotate->text);
|
|
940
1217
|
image = rm_check_frozen(annotate->image_arg);
|
|
941
|
-
|
|
1218
|
+
rm_gvl_check_readable(annotate->self);
|
|
1219
|
+
|
|
1220
|
+
info = clone_draw_info(annotate->self, draw, annotate->image_arg);
|
|
1221
|
+
restore_affine(annotate);
|
|
1222
|
+
magick_clone_string(&info->geometry, geometry_str);
|
|
1223
|
+
magick_clone_string(&info->text, embed_text);
|
|
942
1224
|
|
|
943
1225
|
#if defined(IMAGEMAGICK_7)
|
|
944
1226
|
annotate->exception = AcquireExceptionInfo();
|
|
945
|
-
|
|
1227
|
+
DECLARE_GVL_CALL(call, AnnotateImage, image, info, annotate->exception);
|
|
946
1228
|
#else
|
|
947
|
-
|
|
1229
|
+
DECLARE_GVL_CALL(call, AnnotateImage, image, info);
|
|
948
1230
|
#endif
|
|
949
|
-
|
|
1231
|
+
mark_draw(call.update(annotate->image_arg), annotate->self, draw).release(info).run<void>();
|
|
1232
|
+
DestroyDrawInfo(info);
|
|
950
1233
|
|
|
951
1234
|
#if defined(IMAGEMAGICK_7)
|
|
952
1235
|
exception = annotate->exception;
|
|
@@ -991,6 +1274,7 @@ VALUE Draw_annotate(
|
|
|
991
1274
|
// Save the affine matrix in case it is modified by
|
|
992
1275
|
// Draw#rotation=
|
|
993
1276
|
annotate.draw = get_draw(self);
|
|
1277
|
+
rm_gvl_check_readable(self);
|
|
994
1278
|
annotate.keep = annotate.draw->info->affine;
|
|
995
1279
|
|
|
996
1280
|
annotate.self = self;
|
|
@@ -1039,7 +1323,7 @@ VALUE Draw_annotate(
|
|
|
1039
1323
|
VALUE
|
|
1040
1324
|
Draw_composite(int argc, VALUE *argv, VALUE self)
|
|
1041
1325
|
{
|
|
1042
|
-
|
|
1326
|
+
MagickDraw *draw;
|
|
1043
1327
|
const char *op;
|
|
1044
1328
|
double x, y, width, height;
|
|
1045
1329
|
CompositeOperator composite_op;
|
|
@@ -1057,7 +1341,7 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
|
|
|
1057
1341
|
|
|
1058
1342
|
// Retrieve the image to composite
|
|
1059
1343
|
image = rm_cur_image(argv[4]);
|
|
1060
|
-
comp_img =
|
|
1344
|
+
comp_img = rm_check_readable(image);
|
|
1061
1345
|
|
|
1062
1346
|
x = NUM2DBL(argv[0]);
|
|
1063
1347
|
y = NUM2DBL(argv[1]);
|
|
@@ -1076,16 +1360,19 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
|
|
|
1076
1360
|
rb_raise(rb_eArgError, "unknown composite operator (%d)", composite_op);
|
|
1077
1361
|
}
|
|
1078
1362
|
|
|
1079
|
-
|
|
1363
|
+
rb_check_frozen(self);
|
|
1364
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
1365
|
+
comp_img = rm_check_readable(image);
|
|
1080
1366
|
|
|
1081
1367
|
// Create a temp copy of the composite image
|
|
1082
1368
|
rm_write_temp_image(comp_img, name, sizeof(name));
|
|
1083
1369
|
|
|
1084
1370
|
// Add the temp filename to the filename array.
|
|
1085
1371
|
// Use Magick storage since we need to keep the list around
|
|
1086
|
-
// until
|
|
1372
|
+
// until the last Draw object that refers to it is freed.
|
|
1087
1373
|
tmpfile_name = (struct TmpFile_Name *)magick_malloc(sizeof(struct TmpFile_Name) + rm_strnlen_s(name, sizeof(name)));
|
|
1088
1374
|
strcpy(tmpfile_name->name, name);
|
|
1375
|
+
tmpfile_name->refs = 1;
|
|
1089
1376
|
tmpfile_name->next = draw->tmpfile_ary;
|
|
1090
1377
|
draw->tmpfile_ary = tmpfile_name;
|
|
1091
1378
|
|
|
@@ -1112,8 +1399,10 @@ Draw_composite(int argc, VALUE *argv, VALUE self)
|
|
|
1112
1399
|
VALUE
|
|
1113
1400
|
Draw_draw(VALUE self, VALUE image_arg)
|
|
1114
1401
|
{
|
|
1115
|
-
|
|
1402
|
+
MagickDraw *draw;
|
|
1116
1403
|
Image *image;
|
|
1404
|
+
DrawInfo *info;
|
|
1405
|
+
char *primitive;
|
|
1117
1406
|
#if defined(IMAGEMAGICK_7)
|
|
1118
1407
|
ExceptionInfo *exception;
|
|
1119
1408
|
#endif
|
|
@@ -1122,24 +1411,25 @@ Draw_draw(VALUE self, VALUE image_arg)
|
|
|
1122
1411
|
image = rm_check_frozen(image_arg);
|
|
1123
1412
|
|
|
1124
1413
|
draw = get_draw(self);
|
|
1414
|
+
rm_gvl_check_readable(self);
|
|
1125
1415
|
if (draw->primitives == 0)
|
|
1126
1416
|
{
|
|
1127
1417
|
rb_raise(rb_eArgError, "nothing to draw");
|
|
1128
1418
|
}
|
|
1419
|
+
primitive = StringValueCStr(draw->primitives);
|
|
1129
1420
|
|
|
1130
|
-
|
|
1131
|
-
magick_clone_string(&
|
|
1421
|
+
info = clone_draw_info(self, draw, image_arg);
|
|
1422
|
+
magick_clone_string(&info->primitive, primitive);
|
|
1132
1423
|
|
|
1133
1424
|
#if defined(IMAGEMAGICK_7)
|
|
1134
1425
|
exception = AcquireExceptionInfo();
|
|
1135
|
-
|
|
1426
|
+
DECLARE_GVL_CALL(call, DrawImage, image, info, exception);
|
|
1427
|
+
call.release(exception);
|
|
1136
1428
|
#else
|
|
1137
|
-
|
|
1429
|
+
DECLARE_GVL_CALL(call, DrawImage, image, info);
|
|
1138
1430
|
#endif
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
magick_free(draw->info->primitive);
|
|
1142
|
-
draw->info->primitive = NULL;
|
|
1431
|
+
mark_draw(call.update(image_arg), self, draw).release(info).run<void>();
|
|
1432
|
+
DestroyDrawInfo(info);
|
|
1143
1433
|
|
|
1144
1434
|
#if defined(IMAGEMAGICK_7)
|
|
1145
1435
|
CHECK_EXCEPTION();
|
|
@@ -1208,6 +1498,54 @@ Draw_get_multiline_type_metrics(
|
|
|
1208
1498
|
}
|
|
1209
1499
|
|
|
1210
1500
|
|
|
1501
|
+
/**
|
|
1502
|
+
* Release a reference to a list of temporary images, and delete the images
|
|
1503
|
+
* that no other Draw object refers to.
|
|
1504
|
+
*
|
|
1505
|
+
* No Ruby usage (internal function)
|
|
1506
|
+
*
|
|
1507
|
+
* @param tmpfile_name the first entry of the list
|
|
1508
|
+
*/
|
|
1509
|
+
static void
|
|
1510
|
+
release_tmpfiles(struct TmpFile_Name *tmpfile_name)
|
|
1511
|
+
{
|
|
1512
|
+
while (tmpfile_name && --tmpfile_name->refs == 0)
|
|
1513
|
+
{
|
|
1514
|
+
struct TmpFile_Name *next = tmpfile_name->next;
|
|
1515
|
+
|
|
1516
|
+
rm_delete_temp_image(tmpfile_name->name);
|
|
1517
|
+
magick_free(tmpfile_name);
|
|
1518
|
+
tmpfile_name = next;
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
|
|
1522
|
+
|
|
1523
|
+
/**
|
|
1524
|
+
* Replace the DrawInfo of a Draw with another one.
|
|
1525
|
+
*
|
|
1526
|
+
* - A setter can keep a pointer into the DrawInfo while it calls Ruby code,
|
|
1527
|
+
* so the DrawInfo keeps its address and takes the contents of info.
|
|
1528
|
+
*
|
|
1529
|
+
* No Ruby usage (internal function)
|
|
1530
|
+
*
|
|
1531
|
+
* @param draw the MagickDraw struct
|
|
1532
|
+
* @param info the new DrawInfo, which this function destroys or keeps
|
|
1533
|
+
*/
|
|
1534
|
+
static void
|
|
1535
|
+
replace_draw_info(MagickDraw *draw, DrawInfo *info)
|
|
1536
|
+
{
|
|
1537
|
+
if (draw->info)
|
|
1538
|
+
{
|
|
1539
|
+
std::swap(*draw->info, *info);
|
|
1540
|
+
DestroyDrawInfo(info);
|
|
1541
|
+
}
|
|
1542
|
+
else
|
|
1543
|
+
{
|
|
1544
|
+
draw->info = info;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
|
|
1211
1549
|
/**
|
|
1212
1550
|
* Initialize clone, dup methods.
|
|
1213
1551
|
*
|
|
@@ -1216,21 +1554,52 @@ Draw_get_multiline_type_metrics(
|
|
|
1216
1554
|
*/
|
|
1217
1555
|
VALUE Draw_init_copy(VALUE self, VALUE orig)
|
|
1218
1556
|
{
|
|
1219
|
-
|
|
1557
|
+
MagickDraw *copy, *original;
|
|
1558
|
+
DrawInfo *info;
|
|
1559
|
+
struct TmpFile_Name *tmpfile_ary;
|
|
1560
|
+
int state = 0;
|
|
1220
1561
|
|
|
1221
|
-
|
|
1222
|
-
|
|
1562
|
+
if (!rm_check_init_copy(self, orig))
|
|
1563
|
+
{
|
|
1564
|
+
return self;
|
|
1565
|
+
}
|
|
1566
|
+
rm_gvl_check_writable(self);
|
|
1567
|
+
rm_gvl_check_readable(orig);
|
|
1568
|
+
TypedData_Get_Struct(orig, MagickDraw, &rm_draw_data_type, original);
|
|
1569
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, copy);
|
|
1223
1570
|
|
|
1224
|
-
|
|
1225
|
-
if (!
|
|
1571
|
+
info = CloneDrawInfo(NULL, original->info);
|
|
1572
|
+
if (!info)
|
|
1226
1573
|
{
|
|
1227
1574
|
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
1228
1575
|
}
|
|
1576
|
+
struct CopyPatterns_Args args = { info, orig };
|
|
1577
|
+
rb_protect(copy_patterns, (VALUE)&args, &state);
|
|
1578
|
+
if (state)
|
|
1579
|
+
{
|
|
1580
|
+
DestroyDrawInfo(info);
|
|
1581
|
+
rb_jump_tag(state);
|
|
1582
|
+
}
|
|
1583
|
+
// Copying the patterns releases the GVL, so other code can freeze self or
|
|
1584
|
+
// start a call that uses it meanwhile.
|
|
1585
|
+
if (OBJ_FROZEN(self) || rm_gvl_in_use(self))
|
|
1586
|
+
{
|
|
1587
|
+
DestroyDrawInfo(info);
|
|
1588
|
+
rb_check_frozen(self);
|
|
1589
|
+
rm_gvl_check_writable(self);
|
|
1590
|
+
}
|
|
1591
|
+
replace_draw_info(copy, info);
|
|
1592
|
+
copy->shadow_color = original->shadow_color;
|
|
1229
1593
|
|
|
1230
|
-
|
|
1594
|
+
copy->primitives = copy_primitives(original->primitives);
|
|
1595
|
+
|
|
1596
|
+
tmpfile_ary = copy->tmpfile_ary;
|
|
1597
|
+
copy->tmpfile_ary = original->tmpfile_ary;
|
|
1598
|
+
if (copy->tmpfile_ary)
|
|
1231
1599
|
{
|
|
1232
|
-
copy->
|
|
1600
|
+
copy->tmpfile_ary->refs++;
|
|
1233
1601
|
}
|
|
1602
|
+
release_tmpfiles(tmpfile_ary);
|
|
1234
1603
|
|
|
1235
1604
|
return self;
|
|
1236
1605
|
}
|
|
@@ -1244,14 +1613,19 @@ VALUE Draw_init_copy(VALUE self, VALUE orig)
|
|
|
1244
1613
|
VALUE
|
|
1245
1614
|
Draw_initialize(VALUE self)
|
|
1246
1615
|
{
|
|
1247
|
-
|
|
1616
|
+
MagickDraw *draw, *draw_options;
|
|
1248
1617
|
VALUE options;
|
|
1249
1618
|
|
|
1250
|
-
|
|
1619
|
+
rb_check_frozen(self);
|
|
1620
|
+
rm_gvl_check_writable(self);
|
|
1621
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
1251
1622
|
|
|
1252
1623
|
options = new_DrawOptions();
|
|
1253
|
-
TypedData_Get_Struct(options,
|
|
1254
|
-
|
|
1624
|
+
TypedData_Get_Struct(options, MagickDraw, &rm_draw_data_type, draw_options);
|
|
1625
|
+
// The block of Draw.new runs in new_DrawOptions.
|
|
1626
|
+
rb_check_frozen(self);
|
|
1627
|
+
rm_gvl_check_writable(self);
|
|
1628
|
+
replace_draw_info(draw, draw_options->info);
|
|
1255
1629
|
draw_options->info = NULL;
|
|
1256
1630
|
|
|
1257
1631
|
RB_GC_GUARD(options);
|
|
@@ -1269,10 +1643,10 @@ Draw_initialize(VALUE self)
|
|
|
1269
1643
|
VALUE
|
|
1270
1644
|
Draw_inspect(VALUE self)
|
|
1271
1645
|
{
|
|
1272
|
-
|
|
1646
|
+
MagickDraw *draw;
|
|
1273
1647
|
|
|
1274
|
-
TypedData_Get_Struct(self,
|
|
1275
|
-
return draw->primitives ? draw->primitives : rb_str_new2("(no primitives defined)");
|
|
1648
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
1649
|
+
return draw->primitives ? copy_primitives(draw->primitives) : rb_str_new2("(no primitives defined)");
|
|
1276
1650
|
}
|
|
1277
1651
|
|
|
1278
1652
|
|
|
@@ -1283,11 +1657,10 @@ Draw_inspect(VALUE self)
|
|
|
1283
1657
|
*/
|
|
1284
1658
|
VALUE Draw_alloc(VALUE klass)
|
|
1285
1659
|
{
|
|
1286
|
-
|
|
1660
|
+
MagickDraw *draw;
|
|
1287
1661
|
VALUE draw_obj;
|
|
1288
1662
|
|
|
1289
|
-
draw =
|
|
1290
|
-
memset(draw, 0, sizeof(Draw));
|
|
1663
|
+
draw = ZALLOC(MagickDraw);
|
|
1291
1664
|
draw_obj = TypedData_Wrap_Struct(klass, &rm_draw_data_type, draw);
|
|
1292
1665
|
|
|
1293
1666
|
RB_GC_GUARD(draw_obj);
|
|
@@ -1305,11 +1678,12 @@ VALUE Draw_alloc(VALUE klass)
|
|
|
1305
1678
|
VALUE
|
|
1306
1679
|
Draw_primitive(VALUE self, VALUE primitive)
|
|
1307
1680
|
{
|
|
1308
|
-
|
|
1681
|
+
MagickDraw *draw;
|
|
1309
1682
|
|
|
1310
1683
|
rb_check_frozen(self);
|
|
1311
1684
|
StringValue(primitive);
|
|
1312
|
-
|
|
1685
|
+
rb_check_frozen(self);
|
|
1686
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw);
|
|
1313
1687
|
|
|
1314
1688
|
if (draw->primitives == (VALUE)0)
|
|
1315
1689
|
{
|
|
@@ -1329,12 +1703,12 @@ Draw_primitive(VALUE self, VALUE primitive)
|
|
|
1329
1703
|
*
|
|
1330
1704
|
* No Ruby usage (internal function)
|
|
1331
1705
|
*
|
|
1332
|
-
* @param drawptr pointer to a
|
|
1706
|
+
* @param drawptr pointer to a MagickDraw struct
|
|
1333
1707
|
*/
|
|
1334
1708
|
static void
|
|
1335
1709
|
Draw_compact(void *drawptr)
|
|
1336
1710
|
{
|
|
1337
|
-
|
|
1711
|
+
MagickDraw *draw = (MagickDraw *)drawptr;
|
|
1338
1712
|
|
|
1339
1713
|
if (draw->primitives != (VALUE)0)
|
|
1340
1714
|
{
|
|
@@ -1347,12 +1721,12 @@ Draw_compact(void *drawptr)
|
|
|
1347
1721
|
*
|
|
1348
1722
|
* No Ruby usage (internal function)
|
|
1349
1723
|
*
|
|
1350
|
-
* @param drawptr pointer to a
|
|
1724
|
+
* @param drawptr pointer to a MagickDraw struct
|
|
1351
1725
|
*/
|
|
1352
1726
|
static void
|
|
1353
1727
|
Draw_mark(void *drawptr)
|
|
1354
1728
|
{
|
|
1355
|
-
|
|
1729
|
+
MagickDraw *draw = (MagickDraw *)drawptr;
|
|
1356
1730
|
|
|
1357
1731
|
if (draw->primitives != (VALUE)0)
|
|
1358
1732
|
{
|
|
@@ -1366,12 +1740,12 @@ Draw_mark(void *drawptr)
|
|
|
1366
1740
|
*
|
|
1367
1741
|
* No Ruby usage (internal function)
|
|
1368
1742
|
*
|
|
1369
|
-
* @param drawptr pointer to a
|
|
1743
|
+
* @param drawptr pointer to a MagickDraw struct
|
|
1370
1744
|
*/
|
|
1371
1745
|
static void
|
|
1372
1746
|
Draw_destroy(void *drawptr)
|
|
1373
1747
|
{
|
|
1374
|
-
|
|
1748
|
+
MagickDraw *draw = (MagickDraw *)drawptr;
|
|
1375
1749
|
|
|
1376
1750
|
if (draw->info)
|
|
1377
1751
|
{
|
|
@@ -1379,16 +1753,7 @@ Draw_destroy(void *drawptr)
|
|
|
1379
1753
|
draw->info = NULL;
|
|
1380
1754
|
}
|
|
1381
1755
|
|
|
1382
|
-
|
|
1383
|
-
while (draw->tmpfile_ary)
|
|
1384
|
-
{
|
|
1385
|
-
struct TmpFile_Name *tmpfile_name;
|
|
1386
|
-
|
|
1387
|
-
tmpfile_name = draw->tmpfile_ary;
|
|
1388
|
-
draw->tmpfile_ary = draw->tmpfile_ary->next;
|
|
1389
|
-
rm_delete_temp_image(tmpfile_name->name);
|
|
1390
|
-
magick_free(tmpfile_name);
|
|
1391
|
-
}
|
|
1756
|
+
release_tmpfiles(draw->tmpfile_ary);
|
|
1392
1757
|
|
|
1393
1758
|
xfree(drawptr);
|
|
1394
1759
|
}
|
|
@@ -1398,12 +1763,12 @@ Draw_destroy(void *drawptr)
|
|
|
1398
1763
|
*
|
|
1399
1764
|
* No Ruby usage (internal function)
|
|
1400
1765
|
*
|
|
1401
|
-
* @param
|
|
1766
|
+
* @param drawptr pointer to the MagickDraw struct
|
|
1402
1767
|
*/
|
|
1403
1768
|
static size_t
|
|
1404
1769
|
Draw_memsize(const void *drawptr)
|
|
1405
1770
|
{
|
|
1406
|
-
return sizeof(
|
|
1771
|
+
return sizeof(MagickDraw);
|
|
1407
1772
|
}
|
|
1408
1773
|
|
|
1409
1774
|
/**
|
|
@@ -1431,11 +1796,10 @@ new_DrawOptions(void)
|
|
|
1431
1796
|
VALUE
|
|
1432
1797
|
DrawOptions_alloc(VALUE klass)
|
|
1433
1798
|
{
|
|
1434
|
-
|
|
1799
|
+
MagickDraw *draw_options;
|
|
1435
1800
|
VALUE draw_options_obj;
|
|
1436
1801
|
|
|
1437
|
-
draw_options =
|
|
1438
|
-
memset(draw_options, 0, sizeof(Draw));
|
|
1802
|
+
draw_options = ZALLOC(MagickDraw);
|
|
1439
1803
|
draw_options_obj = TypedData_Wrap_Struct(klass, &rm_draw_data_type, draw_options);
|
|
1440
1804
|
|
|
1441
1805
|
RB_GC_GUARD(draw_options_obj);
|
|
@@ -1452,14 +1816,18 @@ DrawOptions_alloc(VALUE klass)
|
|
|
1452
1816
|
VALUE
|
|
1453
1817
|
DrawOptions_initialize(VALUE self)
|
|
1454
1818
|
{
|
|
1455
|
-
|
|
1819
|
+
MagickDraw *draw_options;
|
|
1820
|
+
DrawInfo *info;
|
|
1456
1821
|
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1822
|
+
rb_check_frozen(self);
|
|
1823
|
+
rm_gvl_check_writable(self);
|
|
1824
|
+
TypedData_Get_Struct(self, MagickDraw, &rm_draw_data_type, draw_options);
|
|
1825
|
+
info = AcquireDrawInfo();
|
|
1826
|
+
if (!info)
|
|
1460
1827
|
{
|
|
1461
1828
|
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
1462
1829
|
}
|
|
1830
|
+
replace_draw_info(draw_options, info);
|
|
1463
1831
|
|
|
1464
1832
|
if (rb_block_given_p())
|
|
1465
1833
|
{
|
|
@@ -1483,12 +1851,11 @@ PolaroidOptions_alloc(VALUE klass)
|
|
|
1483
1851
|
{
|
|
1484
1852
|
VALUE polaroid_obj;
|
|
1485
1853
|
ImageInfo *image_info;
|
|
1486
|
-
|
|
1854
|
+
MagickDraw *draw;
|
|
1487
1855
|
|
|
1488
1856
|
image_info = CloneImageInfo(NULL);
|
|
1489
1857
|
|
|
1490
|
-
draw =
|
|
1491
|
-
memset(draw, 0, sizeof(*draw));
|
|
1858
|
+
draw = ZALLOC(MagickDraw);
|
|
1492
1859
|
|
|
1493
1860
|
draw->info = CloneDrawInfo(image_info, (DrawInfo *) NULL);
|
|
1494
1861
|
(void) DestroyImageInfo(image_info);
|
|
@@ -1511,11 +1878,11 @@ PolaroidOptions_alloc(VALUE klass)
|
|
|
1511
1878
|
VALUE
|
|
1512
1879
|
PolaroidOptions_initialize(VALUE self)
|
|
1513
1880
|
{
|
|
1514
|
-
|
|
1881
|
+
MagickDraw *draw;
|
|
1515
1882
|
ExceptionInfo *exception;
|
|
1516
1883
|
|
|
1517
1884
|
// Default shadow color
|
|
1518
|
-
draw =
|
|
1885
|
+
draw = get_writable_draw(self);
|
|
1519
1886
|
|
|
1520
1887
|
exception = AcquireExceptionInfo();
|
|
1521
1888
|
QueryColorCompliance("gray75", AllCompliance, &draw->shadow_color, exception);
|
|
@@ -1556,11 +1923,13 @@ rm_polaroid_new(void)
|
|
|
1556
1923
|
VALUE
|
|
1557
1924
|
PolaroidOptions_shadow_color_eq(VALUE self, VALUE shadow)
|
|
1558
1925
|
{
|
|
1559
|
-
|
|
1926
|
+
MagickDraw *draw;
|
|
1927
|
+
PixelColor color;
|
|
1560
1928
|
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1929
|
+
get_writable_draw(self);
|
|
1930
|
+
Color_to_PixelColor(&color, shadow);
|
|
1931
|
+
draw = get_writable_draw(self);
|
|
1932
|
+
draw->shadow_color = color;
|
|
1564
1933
|
return shadow;
|
|
1565
1934
|
}
|
|
1566
1935
|
|
|
@@ -1574,53 +1943,84 @@ PolaroidOptions_shadow_color_eq(VALUE self, VALUE shadow)
|
|
|
1574
1943
|
VALUE
|
|
1575
1944
|
PolaroidOptions_border_color_eq(VALUE self, VALUE border)
|
|
1576
1945
|
{
|
|
1577
|
-
|
|
1946
|
+
MagickDraw *draw;
|
|
1947
|
+
PixelColor color;
|
|
1578
1948
|
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1949
|
+
get_writable_draw(self);
|
|
1950
|
+
Color_to_PixelColor(&color, border);
|
|
1951
|
+
draw = get_writable_draw(self);
|
|
1952
|
+
draw->info->border_color = color;
|
|
1582
1953
|
return border;
|
|
1583
1954
|
}
|
|
1584
1955
|
|
|
1585
1956
|
|
|
1586
1957
|
/**
|
|
1587
|
-
* Create
|
|
1958
|
+
* Create the image that get_type_metrics measures on when no image is given.
|
|
1588
1959
|
*
|
|
1589
1960
|
* No Ruby usage (internal function)
|
|
1590
1961
|
*
|
|
1591
|
-
* @
|
|
1592
|
-
* @return the newly allocated dummy
|
|
1962
|
+
* @return the image
|
|
1593
1963
|
*/
|
|
1594
1964
|
static VALUE
|
|
1595
|
-
|
|
1965
|
+
new_dummy_tm_img(void)
|
|
1596
1966
|
{
|
|
1597
|
-
|
|
1598
|
-
|
|
1967
|
+
Info *info;
|
|
1968
|
+
Image *image;
|
|
1599
1969
|
|
|
1600
|
-
|
|
1970
|
+
info = CloneImageInfo(NULL);
|
|
1971
|
+
if (!info)
|
|
1601
1972
|
{
|
|
1602
|
-
|
|
1603
|
-
|
|
1973
|
+
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
1974
|
+
}
|
|
1975
|
+
image = rm_acquire_image(info);
|
|
1976
|
+
DestroyImageInfo(info);
|
|
1604
1977
|
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
DestroyImageInfo(info);
|
|
1978
|
+
if (!image)
|
|
1979
|
+
{
|
|
1980
|
+
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
1981
|
+
}
|
|
1982
|
+
return rm_image_new(image);
|
|
1983
|
+
}
|
|
1612
1984
|
|
|
1613
|
-
if (!image)
|
|
1614
|
-
{
|
|
1615
|
-
rb_raise(rb_eNoMemError, "not enough memory to continue");
|
|
1616
|
-
}
|
|
1617
|
-
dummy_img = rm_image_new(image);
|
|
1618
1985
|
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1986
|
+
/**
|
|
1987
|
+
* Set up where get_type_metrics keeps the image it measures on when no image
|
|
1988
|
+
* is given.
|
|
1989
|
+
*
|
|
1990
|
+
* No Ruby usage (internal function)
|
|
1991
|
+
*/
|
|
1992
|
+
void
|
|
1993
|
+
rm_draw_init(void)
|
|
1994
|
+
{
|
|
1995
|
+
#if defined(HAVE_RB_RACTOR_LOCAL_STORAGE_VALUE_NEWKEY)
|
|
1996
|
+
dummy_img_key = rb_ractor_local_storage_value_newkey();
|
|
1997
|
+
#else
|
|
1998
|
+
rb_gc_register_address(&dummy_img);
|
|
1999
|
+
dummy_img = new_dummy_tm_img();
|
|
2000
|
+
#endif
|
|
2001
|
+
}
|
|
2002
|
+
|
|
2003
|
+
|
|
2004
|
+
/**
|
|
2005
|
+
* Get the image that get_type_metrics measures on when no image is given,
|
|
2006
|
+
* creating it once in each Ractor.
|
|
2007
|
+
*
|
|
2008
|
+
* No Ruby usage (internal function)
|
|
2009
|
+
*
|
|
2010
|
+
* @return the image
|
|
2011
|
+
*/
|
|
2012
|
+
static VALUE
|
|
2013
|
+
get_dummy_tm_img(void)
|
|
2014
|
+
{
|
|
2015
|
+
#if defined(HAVE_RB_RACTOR_LOCAL_STORAGE_VALUE_NEWKEY)
|
|
2016
|
+
VALUE dummy_img;
|
|
1622
2017
|
|
|
1623
|
-
|
|
2018
|
+
if (!rb_ractor_local_storage_value_lookup(dummy_img_key, &dummy_img))
|
|
2019
|
+
{
|
|
2020
|
+
dummy_img = new_dummy_tm_img();
|
|
2021
|
+
rb_ractor_local_storage_value_set(dummy_img_key, dummy_img);
|
|
2022
|
+
}
|
|
2023
|
+
#endif
|
|
1624
2024
|
|
|
1625
2025
|
return dummy_img;
|
|
1626
2026
|
}
|
|
@@ -1649,7 +2049,8 @@ static VALUE
|
|
|
1649
2049
|
get_type_metrics(int argc, VALUE *argv, VALUE self, gvl_function_t fp)
|
|
1650
2050
|
{
|
|
1651
2051
|
Image *image;
|
|
1652
|
-
|
|
2052
|
+
MagickDraw *draw;
|
|
2053
|
+
DrawInfo *info;
|
|
1653
2054
|
VALUE t;
|
|
1654
2055
|
VALUE text_arg = Qnil;
|
|
1655
2056
|
TypeMetric metrics;
|
|
@@ -1665,13 +2066,15 @@ get_type_metrics(int argc, VALUE *argv, VALUE self, gvl_function_t fp)
|
|
|
1665
2066
|
case 1: // use default image
|
|
1666
2067
|
text_arg = argv[0];
|
|
1667
2068
|
text = rm_str2cstr(&text_arg, &text_l);
|
|
1668
|
-
|
|
2069
|
+
t = get_dummy_tm_img();
|
|
2070
|
+
image = rm_check_readable(t);
|
|
1669
2071
|
break;
|
|
1670
2072
|
case 2:
|
|
1671
2073
|
t = rm_cur_image(argv[0]);
|
|
1672
|
-
image =
|
|
2074
|
+
image = rm_check_readable(t);
|
|
1673
2075
|
text_arg = argv[1];
|
|
1674
2076
|
text = rm_str2cstr(&text_arg, &text_l);
|
|
2077
|
+
image = rm_check_readable(t);
|
|
1675
2078
|
break; // okay
|
|
1676
2079
|
default:
|
|
1677
2080
|
rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc);
|
|
@@ -1684,20 +2087,25 @@ get_type_metrics(int argc, VALUE *argv, VALUE self, gvl_function_t fp)
|
|
|
1684
2087
|
}
|
|
1685
2088
|
|
|
1686
2089
|
draw = get_draw(self);
|
|
2090
|
+
rm_gvl_check_readable(self);
|
|
1687
2091
|
// Measured as given: see the comment in Draw_annotate().
|
|
1688
|
-
|
|
2092
|
+
info = CloneDrawInfo(NULL, draw->info);
|
|
2093
|
+
magick_clone_string(&info->text, text);
|
|
1689
2094
|
|
|
1690
2095
|
#if defined(IMAGEMAGICK_7)
|
|
1691
2096
|
exception = AcquireExceptionInfo();
|
|
1692
|
-
|
|
2097
|
+
DECLARE_GVL_CALL_FP(call, get_type_metrics, fp, image, info, &metrics, exception);
|
|
2098
|
+
call.release(exception);
|
|
1693
2099
|
#else
|
|
1694
|
-
|
|
2100
|
+
DECLARE_GVL_CALL_FP(call, get_type_metrics, fp, image, info, &metrics);
|
|
1695
2101
|
#endif
|
|
1696
|
-
|
|
2102
|
+
if (argc == 2)
|
|
2103
|
+
{
|
|
2104
|
+
call.read(t);
|
|
2105
|
+
}
|
|
2106
|
+
void *ret = mark_draw(call, self, draw).release(info).run<void *>();
|
|
1697
2107
|
okay = static_cast<MagickBooleanType>(reinterpret_cast<intptr_t &>(ret));
|
|
1698
|
-
|
|
1699
|
-
magick_free(draw->info->text);
|
|
1700
|
-
draw->info->text = NULL;
|
|
2108
|
+
DestroyDrawInfo(info);
|
|
1701
2109
|
|
|
1702
2110
|
if (!okay)
|
|
1703
2111
|
{
|