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/rmenum.cpp
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
#include "rmagick.h"
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
#define
|
|
15
|
+
#define ENUMERATORS_IVAR "@enumerators"
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
static VALUE Enum_type_values(VALUE);
|
|
@@ -24,7 +24,7 @@ const rb_data_type_t rm_enum_data_type = {
|
|
|
24
24
|
"Magick::Enum",
|
|
25
25
|
{ NULL, rm_enum_free, rm_enum_memsize, },
|
|
26
26
|
0, 0,
|
|
27
|
-
RUBY_TYPED_FROZEN_SHAREABLE,
|
|
27
|
+
RUBY_TYPED_FROZEN_SHAREABLE | RUBY_TYPED_FREE_IMMEDIATELY,
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
|
|
@@ -43,9 +43,9 @@ rm_define_enum_type(const char *tag)
|
|
|
43
43
|
|
|
44
44
|
klass = rb_define_class_under(Module_Magick, tag, Class_Enum);\
|
|
45
45
|
|
|
46
|
-
rb_define_singleton_method(klass, "values",
|
|
47
|
-
rb_define_method(klass, "initialize",
|
|
48
|
-
rb_define_method(klass, "inspect",
|
|
46
|
+
rb_define_singleton_method(klass, "values", Enum_type_values, 0);
|
|
47
|
+
rb_define_method(klass, "initialize", Enum_type_initialize, 2);
|
|
48
|
+
rb_define_method(klass, "inspect", Enum_type_inspect, 0);
|
|
49
49
|
return klass;
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -84,6 +84,12 @@ rm_enum_to_cstr(VALUE enum_type)
|
|
|
84
84
|
MagickEnum *magick_enum;
|
|
85
85
|
|
|
86
86
|
TypedData_Get_Struct(enum_type, MagickEnum, &rm_enum_data_type, magick_enum);
|
|
87
|
+
// An Enum made with allocate but never initialized has no symbol (id 0),
|
|
88
|
+
// and rb_id2name would return NULL.
|
|
89
|
+
if (magick_enum->id == 0)
|
|
90
|
+
{
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
87
93
|
return rb_id2name(magick_enum->id);
|
|
88
94
|
}
|
|
89
95
|
|
|
@@ -157,15 +163,29 @@ Enum_case_eq(VALUE self, VALUE other)
|
|
|
157
163
|
* @param sym [Symbol] the symbol as enum name
|
|
158
164
|
* @param val [Numeric] the value for enum
|
|
159
165
|
* @return [Magick::Enum] self
|
|
166
|
+
* @raise [FrozenError] if the Enum is already initialized
|
|
160
167
|
*/
|
|
161
168
|
VALUE
|
|
162
169
|
Enum_initialize(VALUE self, VALUE sym, VALUE val)
|
|
163
170
|
{
|
|
164
171
|
MagickEnum *magick_enum;
|
|
172
|
+
ID id;
|
|
173
|
+
int value;
|
|
174
|
+
|
|
175
|
+
// Convert both arguments first, so that a failing conversion leaves the
|
|
176
|
+
// Enum uninitialized.
|
|
177
|
+
id = rb_to_id(sym); /* convert symbol to ID */
|
|
178
|
+
value = NUM2INT(val);
|
|
165
179
|
|
|
166
180
|
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
|
|
167
|
-
|
|
168
|
-
|
|
181
|
+
// An Enum is frozen from the start and shared between Ractors, so it must
|
|
182
|
+
// not be initialized again.
|
|
183
|
+
if (magick_enum->id != 0)
|
|
184
|
+
{
|
|
185
|
+
rb_error_frozen_object(self);
|
|
186
|
+
}
|
|
187
|
+
magick_enum->id = id;
|
|
188
|
+
magick_enum->val = value;
|
|
169
189
|
|
|
170
190
|
return self;
|
|
171
191
|
}
|
|
@@ -240,7 +260,7 @@ Enum_bitwise_or(VALUE self, VALUE other)
|
|
|
240
260
|
TypedData_Get_Struct(other, MagickEnum, &rm_enum_data_type, other_enum);
|
|
241
261
|
TypedData_Get_Struct(new_enum, MagickEnum, &rm_enum_data_type, new_enum_data);
|
|
242
262
|
|
|
243
|
-
new_enum_data->id = rb_to_id(rb_sprintf("%s|%s",
|
|
263
|
+
new_enum_data->id = rb_to_id(rb_sprintf("%s|%s", rm_enum_to_cstr(self), rm_enum_to_cstr(other)));
|
|
244
264
|
new_enum_data->val = self_enum->val | other_enum->val;
|
|
245
265
|
|
|
246
266
|
return new_enum;
|
|
@@ -258,6 +278,27 @@ Enum_to_s(VALUE self)
|
|
|
258
278
|
}
|
|
259
279
|
|
|
260
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Get the Enum subclass that keeps the values of a class derived from it.
|
|
283
|
+
*
|
|
284
|
+
* No Ruby usage (internal function)
|
|
285
|
+
*
|
|
286
|
+
* @param klass the Enum subclass or a class derived from it
|
|
287
|
+
* @return the Enum subclass
|
|
288
|
+
*/
|
|
289
|
+
static VALUE
|
|
290
|
+
enum_type_class(VALUE klass)
|
|
291
|
+
{
|
|
292
|
+
VALUE super;
|
|
293
|
+
|
|
294
|
+
while ((super = rb_class_superclass(klass)) != Class_Enum)
|
|
295
|
+
{
|
|
296
|
+
klass = super;
|
|
297
|
+
}
|
|
298
|
+
return klass;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
261
302
|
/**
|
|
262
303
|
* Initialize method for all Enum subclasses.
|
|
263
304
|
*
|
|
@@ -269,19 +310,17 @@ VALUE
|
|
|
269
310
|
Enum_type_initialize(VALUE self, VALUE sym, VALUE val)
|
|
270
311
|
{
|
|
271
312
|
VALUE super_argv[2];
|
|
272
|
-
VALUE enumerators;
|
|
313
|
+
VALUE klass, enumerators;
|
|
273
314
|
|
|
274
315
|
super_argv[0] = sym;
|
|
275
316
|
super_argv[1] = val;
|
|
276
317
|
rb_call_super(2, (const VALUE *)super_argv);
|
|
277
318
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
enumerators = rb_cv_get(CLASS_OF(self), ENUMERATORS_CLASS_VAR);
|
|
319
|
+
klass = enum_type_class(CLASS_OF(self));
|
|
320
|
+
enumerators = rb_iv_get(klass, ENUMERATORS_IVAR);
|
|
321
|
+
enumerators = NIL_P(enumerators) ? rb_ary_new() : rb_ary_dup(enumerators);
|
|
284
322
|
rb_ary_push(enumerators, self);
|
|
323
|
+
rb_iv_set(klass, ENUMERATORS_IVAR, rb_ary_freeze(enumerators));
|
|
285
324
|
|
|
286
325
|
RB_GC_GUARD(enumerators);
|
|
287
326
|
|
|
@@ -301,7 +340,7 @@ Enum_type_inspect(VALUE self)
|
|
|
301
340
|
MagickEnum *magick_enum;
|
|
302
341
|
|
|
303
342
|
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
|
|
304
|
-
snprintf(str, sizeof(str), "%.48s=%d",
|
|
343
|
+
snprintf(str, sizeof(str), "%.48s=%d", rm_enum_to_cstr(self), magick_enum->val);
|
|
305
344
|
|
|
306
345
|
return rb_str_new2(str);
|
|
307
346
|
}
|
|
@@ -322,11 +361,12 @@ Enum_type_inspect(VALUE self)
|
|
|
322
361
|
static VALUE
|
|
323
362
|
Enum_type_values(VALUE klass)
|
|
324
363
|
{
|
|
325
|
-
VALUE enumerators, copy;
|
|
364
|
+
VALUE enumerators, copy = Qnil;
|
|
326
365
|
VALUE rv;
|
|
327
366
|
int x;
|
|
328
367
|
|
|
329
|
-
enumerators =
|
|
368
|
+
enumerators = rb_iv_get(enum_type_class(klass), ENUMERATORS_IVAR);
|
|
369
|
+
enumerators = rm_check_ary_type(enumerators);
|
|
330
370
|
|
|
331
371
|
if (rb_block_given_p())
|
|
332
372
|
{
|
|
@@ -371,7 +411,7 @@ Enum_find(VALUE klass, int val)
|
|
|
371
411
|
MagickEnum *magick_enum;
|
|
372
412
|
int x;
|
|
373
413
|
|
|
374
|
-
enumerators =
|
|
414
|
+
enumerators = rb_iv_get(klass, ENUMERATORS_IVAR);
|
|
375
415
|
enumerators = rm_check_ary_type(enumerators);
|
|
376
416
|
|
|
377
417
|
for (x = 0; x < RARRAY_LEN(enumerators); x++)
|
data/ext/RMagick/rmfill.cpp
CHANGED
|
@@ -25,26 +25,26 @@ typedef struct
|
|
|
25
25
|
double y2; /**< y position of second point */
|
|
26
26
|
PixelColor start_color; /**< the start color */
|
|
27
27
|
PixelColor stop_color; /**< the stop color */
|
|
28
|
-
}
|
|
28
|
+
} MagickGradientFill;
|
|
29
29
|
|
|
30
30
|
/** Data associated with a TextureFill */
|
|
31
31
|
typedef struct
|
|
32
32
|
{
|
|
33
33
|
Image *texture; /**< the texture */
|
|
34
|
-
}
|
|
34
|
+
} MagickTextureFill;
|
|
35
35
|
|
|
36
36
|
const rb_data_type_t rm_gradient_fill_data_type = {
|
|
37
37
|
"Magick::GradientFill",
|
|
38
38
|
{ NULL, GradientFill_free, GradientFill_memsize, },
|
|
39
39
|
0, 0,
|
|
40
|
-
RUBY_TYPED_FROZEN_SHAREABLE,
|
|
40
|
+
RUBY_TYPED_FROZEN_SHAREABLE | RUBY_TYPED_FREE_IMMEDIATELY,
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const rb_data_type_t rm_texture_fill_data_type = {
|
|
44
44
|
"Magick::TextureFill",
|
|
45
45
|
{ NULL, TextureFill_free, TextureFill_memsize, },
|
|
46
46
|
0, 0,
|
|
47
|
-
RUBY_TYPED_FROZEN_SHAREABLE,
|
|
47
|
+
RUBY_TYPED_FROZEN_SHAREABLE | RM_TYPED_FREE_IMMEDIATELY,
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
|
|
@@ -70,12 +70,12 @@ GradientFill_free(void *fill)
|
|
|
70
70
|
*
|
|
71
71
|
* No Ruby usage (internal function)
|
|
72
72
|
*
|
|
73
|
-
* @param ptr pointer to the
|
|
73
|
+
* @param ptr pointer to the MagickGradientFill struct
|
|
74
74
|
*/
|
|
75
75
|
static size_t
|
|
76
76
|
GradientFill_memsize(const void *ptr)
|
|
77
77
|
{
|
|
78
|
-
return sizeof(
|
|
78
|
+
return sizeof(MagickGradientFill);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
|
|
@@ -87,9 +87,9 @@ GradientFill_memsize(const void *ptr)
|
|
|
87
87
|
VALUE
|
|
88
88
|
GradientFill_alloc(VALUE klass)
|
|
89
89
|
{
|
|
90
|
-
|
|
90
|
+
MagickGradientFill *fill;
|
|
91
91
|
|
|
92
|
-
return TypedData_Make_Struct(klass,
|
|
92
|
+
return TypedData_Make_Struct(klass, MagickGradientFill, &rm_gradient_fill_data_type, fill);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
|
|
@@ -114,9 +114,9 @@ GradientFill_initialize(
|
|
|
114
114
|
VALUE start_color,
|
|
115
115
|
VALUE stop_color)
|
|
116
116
|
{
|
|
117
|
-
|
|
117
|
+
MagickGradientFill *fill;
|
|
118
118
|
|
|
119
|
-
TypedData_Get_Struct(self,
|
|
119
|
+
TypedData_Get_Struct(self, MagickGradientFill, &rm_gradient_fill_data_type, fill);
|
|
120
120
|
|
|
121
121
|
fill->x1 = NUM2DBL(x1);
|
|
122
122
|
fill->y1 = NUM2DBL(y1);
|
|
@@ -128,12 +128,36 @@ GradientFill_initialize(
|
|
|
128
128
|
return self;
|
|
129
129
|
}
|
|
130
130
|
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Initialize clone, dup methods.
|
|
134
|
+
*
|
|
135
|
+
* @param orig the original object
|
|
136
|
+
* @return [Magick::GradientFill] self
|
|
137
|
+
*/
|
|
138
|
+
VALUE
|
|
139
|
+
GradientFill_init_copy(VALUE self, VALUE orig)
|
|
140
|
+
{
|
|
141
|
+
MagickGradientFill *copy, *original;
|
|
142
|
+
|
|
143
|
+
if (!rm_check_init_copy(self, orig))
|
|
144
|
+
{
|
|
145
|
+
return self;
|
|
146
|
+
}
|
|
147
|
+
TypedData_Get_Struct(orig, MagickGradientFill, &rm_gradient_fill_data_type, original);
|
|
148
|
+
TypedData_Get_Struct(self, MagickGradientFill, &rm_gradient_fill_data_type, copy);
|
|
149
|
+
*copy = *original;
|
|
150
|
+
|
|
151
|
+
return self;
|
|
152
|
+
}
|
|
153
|
+
|
|
131
154
|
/**
|
|
132
155
|
* Do a gradient that radiates from a point.
|
|
133
156
|
*
|
|
134
157
|
* No Ruby usage (internal function)
|
|
135
158
|
*
|
|
136
159
|
* @param image the image on which to do the gradient
|
|
160
|
+
* @param image_obj the Image object that holds image
|
|
137
161
|
* @param x0 x position of the point
|
|
138
162
|
* @param y0 y position of the point
|
|
139
163
|
* @param start_color the start color
|
|
@@ -142,6 +166,7 @@ GradientFill_initialize(
|
|
|
142
166
|
static void
|
|
143
167
|
point_fill(
|
|
144
168
|
Image *image,
|
|
169
|
+
VALUE image_obj,
|
|
145
170
|
double x0,
|
|
146
171
|
double y0,
|
|
147
172
|
PixelColor *start_color,
|
|
@@ -191,8 +216,8 @@ point_fill(
|
|
|
191
216
|
#endif
|
|
192
217
|
}
|
|
193
218
|
|
|
194
|
-
|
|
195
|
-
|
|
219
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
220
|
+
call.update(image_obj).keep_thread().release(exception).run<void>();
|
|
196
221
|
CHECK_EXCEPTION();
|
|
197
222
|
}
|
|
198
223
|
|
|
@@ -206,6 +231,7 @@ point_fill(
|
|
|
206
231
|
* No Ruby usage (internal function)
|
|
207
232
|
*
|
|
208
233
|
* @param image the image on which to do the gradient
|
|
234
|
+
* @param image_obj the Image object that holds image
|
|
209
235
|
* @param x1 x position of the vertical line
|
|
210
236
|
* @param start_color the start color
|
|
211
237
|
* @param stop_color the stop color
|
|
@@ -213,6 +239,7 @@ point_fill(
|
|
|
213
239
|
static void
|
|
214
240
|
vertical_fill(
|
|
215
241
|
Image *image,
|
|
242
|
+
VALUE image_obj,
|
|
216
243
|
double x1,
|
|
217
244
|
PixelColor *start_color,
|
|
218
245
|
PixelColor *stop_color)
|
|
@@ -261,8 +288,8 @@ vertical_fill(
|
|
|
261
288
|
row_pixels += GetPixelChannels(image);
|
|
262
289
|
}
|
|
263
290
|
|
|
264
|
-
|
|
265
|
-
|
|
291
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
292
|
+
call.update(image_obj).keep_thread().release(exception).run<void>();
|
|
266
293
|
CHECK_EXCEPTION();
|
|
267
294
|
}
|
|
268
295
|
|
|
@@ -295,8 +322,8 @@ vertical_fill(
|
|
|
295
322
|
|
|
296
323
|
memcpy(row_pixels, master, image->columns * sizeof(PixelPacket));
|
|
297
324
|
|
|
298
|
-
|
|
299
|
-
|
|
325
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
326
|
+
call.update(image_obj).keep_thread().free_buffer(master).release(exception).run<void>();
|
|
300
327
|
if (rm_should_raise_exception(exception, RetainExceptionRetention))
|
|
301
328
|
{
|
|
302
329
|
xfree((void *)master);
|
|
@@ -316,6 +343,7 @@ vertical_fill(
|
|
|
316
343
|
* No Ruby usage (internal function)
|
|
317
344
|
*
|
|
318
345
|
* @param image the image on which to do the gradient
|
|
346
|
+
* @param image_obj the Image object that holds image
|
|
319
347
|
* @param y1 y position of the horizontal line
|
|
320
348
|
* @param start_color the start color
|
|
321
349
|
* @param stop_color the stop color
|
|
@@ -323,6 +351,7 @@ vertical_fill(
|
|
|
323
351
|
static void
|
|
324
352
|
horizontal_fill(
|
|
325
353
|
Image *image,
|
|
354
|
+
VALUE image_obj,
|
|
326
355
|
double y1,
|
|
327
356
|
PixelColor *start_color,
|
|
328
357
|
PixelColor *stop_color)
|
|
@@ -369,8 +398,8 @@ horizontal_fill(
|
|
|
369
398
|
row_pixels += GetPixelChannels(image);
|
|
370
399
|
}
|
|
371
400
|
|
|
372
|
-
|
|
373
|
-
|
|
401
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
402
|
+
call.update(image_obj).keep_thread().release(exception).run<void>();
|
|
374
403
|
CHECK_EXCEPTION();
|
|
375
404
|
}
|
|
376
405
|
|
|
@@ -402,8 +431,8 @@ horizontal_fill(
|
|
|
402
431
|
|
|
403
432
|
memcpy(col_pixels, master, image->rows * sizeof(PixelPacket));
|
|
404
433
|
|
|
405
|
-
|
|
406
|
-
|
|
434
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
435
|
+
call.update(image_obj).keep_thread().free_buffer(master).release(exception).run<void>();
|
|
407
436
|
if (rm_should_raise_exception(exception, RetainExceptionRetention))
|
|
408
437
|
{
|
|
409
438
|
xfree((void *)master);
|
|
@@ -424,6 +453,7 @@ horizontal_fill(
|
|
|
424
453
|
* No Ruby usage (internal function)
|
|
425
454
|
*
|
|
426
455
|
* @param image the image on which to do the gradient
|
|
456
|
+
* @param image_obj the Image object that holds image
|
|
427
457
|
* @param x1 x position of the start of the diagonal line
|
|
428
458
|
* @param y1 y position of the start of the diagonal line
|
|
429
459
|
* @param x2 x position of the end of the diagonal line
|
|
@@ -434,6 +464,7 @@ horizontal_fill(
|
|
|
434
464
|
static void
|
|
435
465
|
v_diagonal_fill(
|
|
436
466
|
Image *image,
|
|
467
|
+
VALUE image_obj,
|
|
437
468
|
double x1,
|
|
438
469
|
double y1,
|
|
439
470
|
double x2,
|
|
@@ -514,8 +545,8 @@ v_diagonal_fill(
|
|
|
514
545
|
#endif
|
|
515
546
|
}
|
|
516
547
|
|
|
517
|
-
|
|
518
|
-
|
|
548
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
549
|
+
call.update(image_obj).keep_thread().release(exception).run<void>();
|
|
519
550
|
CHECK_EXCEPTION();
|
|
520
551
|
}
|
|
521
552
|
|
|
@@ -529,6 +560,7 @@ v_diagonal_fill(
|
|
|
529
560
|
* No Ruby usage (internal function)
|
|
530
561
|
*
|
|
531
562
|
* @param image the image on which to do the gradient
|
|
563
|
+
* @param image_obj the Image object that holds image
|
|
532
564
|
* @param x1 x position of the start of the diagonal line
|
|
533
565
|
* @param y1 y position of the start of the diagonal line
|
|
534
566
|
* @param x2 x position of the end of the diagonal line
|
|
@@ -539,6 +571,7 @@ v_diagonal_fill(
|
|
|
539
571
|
static void
|
|
540
572
|
h_diagonal_fill(
|
|
541
573
|
Image *image,
|
|
574
|
+
VALUE image_obj,
|
|
542
575
|
double x1,
|
|
543
576
|
double y1,
|
|
544
577
|
double x2,
|
|
@@ -621,8 +654,8 @@ h_diagonal_fill(
|
|
|
621
654
|
#endif
|
|
622
655
|
}
|
|
623
656
|
|
|
624
|
-
|
|
625
|
-
|
|
657
|
+
DECLARE_GVL_CALL(call, SyncAuthenticPixels, image, exception);
|
|
658
|
+
call.update(image_obj).keep_thread().release(exception).run<void>();
|
|
626
659
|
CHECK_EXCEPTION();
|
|
627
660
|
}
|
|
628
661
|
|
|
@@ -639,13 +672,14 @@ h_diagonal_fill(
|
|
|
639
672
|
VALUE
|
|
640
673
|
GradientFill_fill(VALUE self, VALUE image_obj)
|
|
641
674
|
{
|
|
642
|
-
|
|
675
|
+
MagickGradientFill *fill;
|
|
643
676
|
Image *image;
|
|
644
677
|
PixelColor start_color, stop_color;
|
|
645
678
|
double x1, y1, x2, y2; // points on the line
|
|
646
679
|
|
|
647
|
-
TypedData_Get_Struct(self,
|
|
648
|
-
|
|
680
|
+
TypedData_Get_Struct(self, MagickGradientFill, &rm_gradient_fill_data_type, fill);
|
|
681
|
+
image_obj = rm_cur_image(image_obj);
|
|
682
|
+
image = rm_check_frozen(image_obj);
|
|
649
683
|
|
|
650
684
|
x1 = fill->x1;
|
|
651
685
|
y1 = fill->y1;
|
|
@@ -659,20 +693,20 @@ GradientFill_fill(VALUE self, VALUE image_obj)
|
|
|
659
693
|
// If the x1,y1 and x2,y2 points are essentially the same
|
|
660
694
|
if (fabs(y2-y1) < 0.5)
|
|
661
695
|
{
|
|
662
|
-
point_fill(image, x1, y1, &start_color, &stop_color);
|
|
696
|
+
point_fill(image, image_obj, x1, y1, &start_color, &stop_color);
|
|
663
697
|
}
|
|
664
698
|
|
|
665
699
|
// A vertical line is a special case.
|
|
666
700
|
else
|
|
667
701
|
{
|
|
668
|
-
vertical_fill(image, x1, &start_color, &stop_color);
|
|
702
|
+
vertical_fill(image, image_obj, x1, &start_color, &stop_color);
|
|
669
703
|
}
|
|
670
704
|
}
|
|
671
705
|
|
|
672
706
|
// A horizontal line is a special case.
|
|
673
707
|
else if (fabs(y2-y1) < 0.5)
|
|
674
708
|
{
|
|
675
|
-
horizontal_fill(image, y1, &start_color, &stop_color);
|
|
709
|
+
horizontal_fill(image, image_obj, y1, &start_color, &stop_color);
|
|
676
710
|
}
|
|
677
711
|
|
|
678
712
|
// This is the general case - a diagonal line. If the line is more horizontal
|
|
@@ -684,14 +718,16 @@ GradientFill_fill(VALUE self, VALUE image_obj)
|
|
|
684
718
|
double diagonal = ((double)image->rows)/image->columns;
|
|
685
719
|
if (fabs(m) <= diagonal)
|
|
686
720
|
{
|
|
687
|
-
v_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
|
|
721
|
+
v_diagonal_fill(image, image_obj, x1, y1, x2, y2, &start_color, &stop_color);
|
|
688
722
|
}
|
|
689
723
|
else
|
|
690
724
|
{
|
|
691
|
-
h_diagonal_fill(image, x1, y1, x2, y2, &start_color, &stop_color);
|
|
725
|
+
h_diagonal_fill(image, image_obj, x1, y1, x2, y2, &start_color, &stop_color);
|
|
692
726
|
}
|
|
693
727
|
}
|
|
694
728
|
|
|
729
|
+
RB_GC_GUARD(image_obj);
|
|
730
|
+
|
|
695
731
|
return self;
|
|
696
732
|
}
|
|
697
733
|
|
|
@@ -709,7 +745,7 @@ GradientFill_fill(VALUE self, VALUE image_obj)
|
|
|
709
745
|
static void
|
|
710
746
|
TextureFill_free(void *fill_obj)
|
|
711
747
|
{
|
|
712
|
-
|
|
748
|
+
MagickTextureFill *fill = (MagickTextureFill *)fill_obj;
|
|
713
749
|
|
|
714
750
|
// Do not trace destruction
|
|
715
751
|
if (fill->texture)
|
|
@@ -725,12 +761,12 @@ TextureFill_free(void *fill_obj)
|
|
|
725
761
|
*
|
|
726
762
|
* No Ruby usage (internal function)
|
|
727
763
|
*
|
|
728
|
-
* @param ptr pointer to the
|
|
764
|
+
* @param ptr pointer to the MagickTextureFill struct
|
|
729
765
|
*/
|
|
730
766
|
static size_t
|
|
731
767
|
TextureFill_memsize(const void *ptr)
|
|
732
768
|
{
|
|
733
|
-
return sizeof(
|
|
769
|
+
return sizeof(MagickTextureFill);
|
|
734
770
|
}
|
|
735
771
|
|
|
736
772
|
|
|
@@ -742,8 +778,34 @@ TextureFill_memsize(const void *ptr)
|
|
|
742
778
|
VALUE
|
|
743
779
|
TextureFill_alloc(VALUE klass)
|
|
744
780
|
{
|
|
745
|
-
|
|
746
|
-
return TypedData_Make_Struct(klass,
|
|
781
|
+
MagickTextureFill *fill;
|
|
782
|
+
return TypedData_Make_Struct(klass, MagickTextureFill, &rm_texture_fill_data_type, fill);
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
/**
|
|
786
|
+
* Replace the texture of a TextureFill with a copy made for it.
|
|
787
|
+
*
|
|
788
|
+
* No Ruby usage (internal function)
|
|
789
|
+
*
|
|
790
|
+
* @param self the TextureFill object
|
|
791
|
+
* @param fill the MagickTextureFill struct of self
|
|
792
|
+
* @param texture the new texture, which is destroyed if self is frozen
|
|
793
|
+
*/
|
|
794
|
+
static void
|
|
795
|
+
replace_texture(VALUE self, MagickTextureFill *fill, Image *texture)
|
|
796
|
+
{
|
|
797
|
+
// Making the copy releases the GVL, so other code can freeze self meanwhile.
|
|
798
|
+
if (OBJ_FROZEN(self))
|
|
799
|
+
{
|
|
800
|
+
DestroyImage(texture);
|
|
801
|
+
rb_error_frozen_object(self);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
if (fill->texture)
|
|
805
|
+
{
|
|
806
|
+
DestroyImage(fill->texture);
|
|
807
|
+
}
|
|
808
|
+
fill->texture = texture;
|
|
747
809
|
}
|
|
748
810
|
|
|
749
811
|
/**
|
|
@@ -756,25 +818,50 @@ TextureFill_alloc(VALUE klass)
|
|
|
756
818
|
VALUE
|
|
757
819
|
TextureFill_initialize(VALUE self, VALUE texture_arg)
|
|
758
820
|
{
|
|
759
|
-
|
|
821
|
+
MagickTextureFill *fill;
|
|
760
822
|
Image *texture;
|
|
761
823
|
VALUE texture_image;
|
|
762
824
|
|
|
763
|
-
|
|
825
|
+
rb_check_frozen(self);
|
|
826
|
+
TypedData_Get_Struct(self, MagickTextureFill, &rm_texture_fill_data_type, fill);
|
|
764
827
|
|
|
765
828
|
texture_image = rm_cur_image(texture_arg);
|
|
766
829
|
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
ReferenceImage(texture);
|
|
770
|
-
|
|
771
|
-
fill->texture = texture;
|
|
830
|
+
texture = rm_copy_image(rm_check_readable(texture_image), texture_image);
|
|
831
|
+
replace_texture(self, fill, texture);
|
|
772
832
|
|
|
773
833
|
RB_GC_GUARD(texture_image);
|
|
774
834
|
|
|
775
835
|
return self;
|
|
776
836
|
}
|
|
777
837
|
|
|
838
|
+
/**
|
|
839
|
+
* Initialize clone, dup methods.
|
|
840
|
+
*
|
|
841
|
+
* @param orig the original object
|
|
842
|
+
* @return [Magick::TextureFill] self
|
|
843
|
+
*/
|
|
844
|
+
VALUE
|
|
845
|
+
TextureFill_init_copy(VALUE self, VALUE orig)
|
|
846
|
+
{
|
|
847
|
+
MagickTextureFill *copy, *original;
|
|
848
|
+
|
|
849
|
+
if (!rm_check_init_copy(self, orig))
|
|
850
|
+
{
|
|
851
|
+
return self;
|
|
852
|
+
}
|
|
853
|
+
TypedData_Get_Struct(orig, MagickTextureFill, &rm_texture_fill_data_type, original);
|
|
854
|
+
TypedData_Get_Struct(self, MagickTextureFill, &rm_texture_fill_data_type, copy);
|
|
855
|
+
if (!original->texture)
|
|
856
|
+
{
|
|
857
|
+
rb_raise(rb_eRuntimeError, "%s has not been initialized", rb_obj_classname(orig));
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
replace_texture(self, copy, rm_copy_image(original->texture, orig));
|
|
861
|
+
|
|
862
|
+
return self;
|
|
863
|
+
}
|
|
864
|
+
|
|
778
865
|
/**
|
|
779
866
|
* Call TextureFill with the texture specified when this fill object was
|
|
780
867
|
* created.
|
|
@@ -785,14 +872,18 @@ TextureFill_initialize(VALUE self, VALUE texture_arg)
|
|
|
785
872
|
VALUE
|
|
786
873
|
TextureFill_fill(VALUE self, VALUE image_obj)
|
|
787
874
|
{
|
|
788
|
-
|
|
875
|
+
MagickTextureFill *fill;
|
|
789
876
|
Image *image;
|
|
790
877
|
#if defined(IMAGEMAGICK_7)
|
|
791
878
|
ExceptionInfo *exception;
|
|
792
879
|
#endif
|
|
793
880
|
|
|
794
|
-
image =
|
|
795
|
-
TypedData_Get_Struct(self,
|
|
881
|
+
image = rm_check_frozen(rm_cur_image(image_obj));
|
|
882
|
+
TypedData_Get_Struct(self, MagickTextureFill, &rm_texture_fill_data_type, fill);
|
|
883
|
+
if (!fill->texture)
|
|
884
|
+
{
|
|
885
|
+
rb_raise(rb_eRuntimeError, "%s has not been initialized", rb_obj_classname(self));
|
|
886
|
+
}
|
|
796
887
|
|
|
797
888
|
#if defined(IMAGEMAGICK_7)
|
|
798
889
|
exception = AcquireExceptionInfo();
|