Module: Magick

Defined in:
lib/rvg/rvg.rb,
lib/RMagick.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/misc.rb,
lib/rvg/text.rb,
lib/rvg/paint.rb,
lib/rvg/units.rb,
lib/rvg/clippath.rb,
lib/rvg/pathdata.rb,
lib/rvg/stylable.rb,
lib/rvg/container.rb,
lib/rvg/deep_equal.rb,
lib/rvg/describable.rb,
lib/rvg/stretchable.rb,
lib/rvg/embellishable.rb,
lib/rvg/transformable.rb,
ext/RMagick/rmmain.c

Overview

– $Id: transformable.rb,v 1.3 2007/01/20 17:39:50 rmagick Exp $ Copyright © 2007 Timothy P. Hunter ++

Defined Under Namespace

Modules: IPTC Classes: Draw, Enum, Geometry, GeometryValue, GradientFill, HatchFill, Image, ImageList, ImageMagickError, Pixel, RVG, TextureFill

Constant Summary collapse

PercentGeometry =
GeometryValue.new(:PercentGeometry, 1)
AspectGeometry =
GeometryValue.new(:AspectGeometry, 2)
LessGeometry =
GeometryValue.new(:LessGeometry, 3)
GreaterGeometry =
GeometryValue.new(:GreaterGeometry, 4)
AreaGeometry =
GeometryValue.new(:AreaGeometry, 5)
MaxRGB =

Miscellaneous constants

INT2FIX(MaxRGB)
QuantumDepth =
INT2FIX(QuantumDepth)
AlphaChannel =
_enum
DefaultChannels =
_enum
HueChannel =
_enum
LuminosityChannel =
_enum
SaturationChannel =
_enum
UndefinedGravity =
_enum
AffineMatrix =
Class_AffineMatrix
Statistics =
Class_Statistics
Primary =
Class_Primary
Chromaticity =
Class_Chromaticity
Color =
Class_Color
Point =
Class_Point
Rectangle =
Class_Rectangle
Segment =
Class_Segment
Font =
Class_Font
TypeMetric =
Class_TypeMetric
Magick_version =
str
Version =
str
Long_version =
str
@@formats =
nil

Class Method Summary collapse

Class Method Details

.colorsObject

Method: Magick::colors [ { |colorinfo| } ] Purpose: If called with the optional block, iterates over the colors,

otherwise returns an array of Magick::Color objects

Notes: There are 3 implementations



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'ext/RMagick/rmmain.c', line 34

VALUE
Magick_colors(VALUE class)
{
#if defined(HAVE_GETCOLORINFOARRAY) // GraphicsMagick
    ColorInfo **color_ary;
    ExceptionInfo exception;
    volatile VALUE ary;
    int x;

    GetExceptionInfo(&exception);

    color_ary = GetColorInfoArray(&exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);


    if (rb_block_given_p())
    {
        x = 0;
        while(color_ary[x])
        {
            rb_yield(Color_from_ColorInfo(color_ary[x]));
            x += 1;
        }
        magick_free(color_ary);
        return class;
    }
    else
    {
        ary = rb_ary_new();

        x = 0;
        while (color_ary[x])
        {
            rb_ary_push(ary, Color_from_ColorInfo(color_ary[x]));
            x += 1;
        }
        magick_free(color_ary);
        return ary;
    }

#elif defined(HAVE_GETCOLORINFOLIST)    // ImageMagick 6.0.0

    const ColorInfo **color_info_list;
    unsigned long number_colors, x;
    volatile VALUE ary;

#if defined(HAVE_OLD_GETCOLORINFOLIST)
    color_info_list = GetColorInfoList("*", &number_colors);

#else
    // IM 6.1.3 added an exception parm to GetColorInfoList
    ExceptionInfo exception;

    GetExceptionInfo(&exception);

    color_info_list = GetColorInfoList("*", &number_colors, &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

#endif


    if (rb_block_given_p())
    {
        for(x = 0; x < number_colors; x++)
        {
            (void) rb_yield(Color_from_ColorInfo(color_info_list[x]));
        }
        magick_free(color_info_list);
        return class;
    }
    else
    {
        ary = rb_ary_new2((long) number_colors);
        for(x = 0; x < number_colors; x++)
        {
            (void) rb_ary_push(ary, Color_from_ColorInfo(color_info_list[x]));
        }

        magick_free(color_info_list);
        return ary;
    }

#else   // ImageMagick < 6.0.0

    const ColorInfo *color_list;
    ColorInfo *color;
    ExceptionInfo exception;
    volatile VALUE ary, el;

    GetExceptionInfo(&exception);

    color_list = GetColorInfo("*", &exception);
    (void) DestroyExceptionInfo(&exception);

    // The order of the colors list can change in mid-iteration,
    // so the only way we can guarantee a single pass thru the list
    // is to copy the elements into an array without returning to
    // IM. So, we always create a Ruby array and either return it
    // or iterate over it.
    ary = rb_ary_new();
    for (color = (ColorInfo *)color_list; color; color = color->next)
    {
        rb_ary_push(ary, Color_from_ColorInfo(color));
    }

    // If block, iterate over colors
    if (rb_block_given_p())
    {
        while ((el = rb_ary_shift(ary)) != Qnil)
        {
            rb_yield(el);
        }
        return class;
    }
    else
    {
        return ary;
    }

#endif
}

.fontsObject

Method: Magick::fonts [ { |fontinfo| } ] Purpose: If called with the optional block, iterates over the fonts,

otherwise returns an array of Magick::Font objects


163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'ext/RMagick/rmmain.c', line 163

VALUE
Magick_fonts(VALUE class)
{
#if defined(HAVE_GETTYPEINFOLIST)   // ImageMagick 6.0.0

    const TypeInfo **type_info;
    unsigned long number_types, x;
    volatile VALUE ary;

#if defined(HAVE_OLD_GETTYPEINFOLIST)
    type_info = GetTypeInfoList("*", &number_types);

#else
    // IM 6.1.3 added an exception argument to GetTypeInfoList
    ExceptionInfo exception;

    GetExceptionInfo(&exception);
    type_info = GetTypeInfoList("*", &number_types, &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

#endif

    if (rb_block_given_p())
    {
        for(x = 0; x < number_types; x++)
        {
            (void) rb_yield(Font_from_TypeInfo((TypeInfo *)type_info[x]));
        }
        magick_free(type_info);
        return class;
    }
    else
    {
        ary = rb_ary_new2((long)number_types);
        for(x = 0; x < number_types; x++)
        {
            (void) rb_ary_push(ary, Font_from_TypeInfo((TypeInfo *)type_info[x]));
        }
        magick_free(type_info);
        return ary;
    }

#else

    const TypeInfo *type_list;
    TypeInfo *type, *next;
    ExceptionInfo exception;
    volatile VALUE ary;

    GetExceptionInfo(&exception);

    type_list = GetTypeInfo("*", &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

    // If block, iterate over fonts
    if (rb_block_given_p())
    {
        for (type = (TypeInfo *)type_list; type; type = next)
        {
            next = type->next;  // Protect against recursive calls to GetTypeInfo
            if (! type->stealth)
            {
                rb_yield(Font_from_TypeInfo(type));
            }
        }

        return class;
    }
    else
    {
        ary = rb_ary_new();
        for (type = (TypeInfo *)type_list; type; type = type->next)
        {
            rb_ary_push(ary, Font_from_TypeInfo(type));
        }
        return ary;
    }

#endif
}

.formats(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/RMagick.rb', line 16

def Magick.formats(&block)
    @@formats ||= Magick.init_formats
    if block_given?
        @@formats.each { |k,v| yield(k,v) }
        self
    else
        @@formats
    end
end

.init_formatsObject



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'ext/RMagick/rmmain.c', line 275

VALUE
Magick_init_formats(VALUE class)
{
#if defined(HAVE_GETMAGICKINFOARRAY)    // GraphicsMagick

    MagickInfo *magick_info, *m;
    volatile VALUE formats;
    ExceptionInfo exception;

    class = class;      // defeat "never referenced" message from icc

    formats = rb_hash_new();

    GetExceptionInfo(&exception);
    magick_info = (MagickInfo *)GetMagickInfoArray(&exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

    for(m = magick_info; m != NULL; m = m->next)
    {
        rb_hash_aset(formats, rb_str_new2(m->name), MagickInfo_to_format(m));
    }

    magick_free(magick_info);
    return formats;

#elif defined(HAVE_GETMAGICKINFOLIST)    // ImageMagick 6.0.0

    const MagickInfo **magick_info;
    unsigned long number_formats, x;
    volatile VALUE formats;
#if !defined(HAVE_OLD_GETMAGICKINFOLIST)
    ExceptionInfo exception;
#endif

    class = class;      // defeat "never referenced" message from icc
    formats = rb_hash_new();

#if defined(HAVE_OLD_GETMAGICKINFOLIST)
    magick_info = GetMagickInfoList("*", &number_formats);

#else
    // IM 6.1.3 added an exception argument to GetMagickInfoList
    GetExceptionInfo(&exception);
    magick_info = GetMagickInfoList("*", &number_formats, &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

#endif

    for(x = 0; x < number_formats; x++)
    {
        (void) rb_hash_aset(formats
                          , rb_str_new2(magick_info[x]->name)
                          , MagickInfo_to_format((MagickInfo *)magick_info[x]));
    }
    return formats;

#else

    MagickInfo *m;
    volatile VALUE formats;
    ExceptionInfo exception;

    class = class;      // defeat "never referenced" message from icc

    formats = rb_hash_new();

    GetExceptionInfo(&exception);
    m = (MagickInfo *)GetMagickInfo("*", &exception);
    CHECK_EXCEPTION()
    (void) DestroyExceptionInfo(&exception);

    for ( ; m != NULL; m = m->next)
    {
        rb_hash_aset(formats, rb_str_new2(m->name), MagickInfo_to_format(m));
    }

    return formats;

#endif
}

.limit_resource(*args) ⇒ Object

Method: Magick.limit_resource(resource[, limit]) Purpose: Get/set resource limits. If a limit is specified the old limit

is set to the new value. Either way the current/new limit is returned.

Notes: Don’t support “AreaLimit” because GraphicsMagick doesn’t support it.



365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'ext/RMagick/rmmain.c', line 365

static VALUE
Magick_limit_resource(int argc, VALUE *argv, VALUE class)
{
#if defined(HAVE_GETMAGICKRESOURCELIMIT)
    volatile VALUE resource, limit;
    ResourceType res = UndefinedResource;
    char *str;
    ID id;
    unsigned long cur_limit;

    rb_scan_args(argc, argv, "11", &resource, &limit);

    switch (TYPE(resource))
    {
        case T_NIL:
            return class;

        case T_SYMBOL:
            id = (ID)SYM2ID(resource);
            if (id == rb_intern("memory"))
            {
                res = MemoryResource;
            }
            else if (id == rb_intern("map"))
            {
                res = MapResource;
            }
            else if (id == rb_intern("disk"))
            {
                res = DiskResource;
            }
            else if (id == rb_intern("file"))
            {
                res = FileResource;
            }
            else
            {
                rb_raise(rb_eArgError, "unknown resource: `:%s'", rb_id2name(id));
            }
            break;

        default:
            str = STRING_PTR(resource);
            if (*str == '\0')
            {
                return class;
            }
            else if (rm_strcasecmp("memory", str) == 0)
            {
                res = MemoryResource;
            }
            else if (rm_strcasecmp("map", str) == 0)
            {
                res = MapResource;
            }
            else if (rm_strcasecmp("disk", str) == 0)
            {
                res = DiskResource;
            }
            else if (rm_strcasecmp("file", str) == 0)
            {
                res = FileResource;
            }
            else
            {
                rb_raise(rb_eArgError, "unknown resource: `%s'", str);
            }
            break;
    }

    cur_limit = GetMagickResourceLimit(res);

    if (argc > 1)
    {
        (void) SetMagickResourceLimit(res, NUM2ULONG(limit));
    }

    return ULONG2NUM(cur_limit);
#else
    rm_not_implemented();
    return (VALUE)0;
#endif
}

.set_cache_threshold(threshold) ⇒ Object

Method Magick.set_cache_threshold(megabytes) Purpose: sets the amount of free memory allocated for the

pixel cache.  Once this threshold is exceeded, all
subsequent pixels cache operations are to/from disk.

Notes: singleton method

Pre-5.5.1 this method called the SetCacheThreshold
function, which is deprecated in 5.5.1.


531
532
533
534
535
536
537
538
# File 'ext/RMagick/rmmain.c', line 531

static VALUE
Magick_set_cache_threshold(VALUE class, VALUE threshold)
{
    unsigned long thrshld = NUM2ULONG(threshold);
    (void) SetMagickResourceLimit(MemoryResource,thrshld);
    (void) SetMagickResourceLimit(MapResource,2*thrshld);
    return class;
}

.set_log_event_mask(*args) ⇒ Object

Method: Magick.set_log_event_mask(event,…) -> Magick Notes: “event” is one of “all”, “annotate”, “blob”, “cache”,

"coder", "configure", "deprecate", "locale", "none",
"render", "transform", "user", "x11". Multiple events
can be specified. Event names may be capitalized.


547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'ext/RMagick/rmmain.c', line 547

static VALUE
Magick_set_log_event_mask(int argc, VALUE *argv, VALUE class)
{
    int x;

    if (argc == 0)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (at least 1 required)");
    }
    for (x = 0; x < argc; x++)
    {
        (void) SetLogEventMask(STRING_PTR(argv[x]));
    }
    return class;
}

.set_log_format(format) ⇒ Object

Method: Magick.set_log_format(format) -> Magick Notes: Format is a string containing one or more of:

%t  - current time
%r  - elapsed time
%u  - user time
%p  - pid
%m  - module (source file name)
%f  - function name
%l  - line number
%d  - event domain (one of the events listed above)
%e  - event name
Plus other characters, including \n, etc.


577
578
579
580
581
582
# File 'ext/RMagick/rmmain.c', line 577

static VALUE
Magick_set_log_format(VALUE class, VALUE format)
{
    SetLogFormat(STRING_PTR(format));
    return class;
}

.set_monitor(monitor) ⇒ Object

Method: Magick.set_monitor(&monitor) Purpose: Establish MagickMonitor exit Notes: use nil argument to turn off monitoring



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'ext/RMagick/rmmain.c', line 486

static VALUE
Magick_set_monitor(VALUE class, VALUE monitor)
{

    // 1st time: establish ID, define @@__MAGICK_MONITOR__
    // class variable, stow monitor VALUE in it.
    if (!Magick_Monitor)
    {
        Magick_Monitor = rb_intern(MAGICK_MONITOR_CVAR);
        rb_define_class_variable(Module_Magick, MAGICK_MONITOR_CVAR, monitor);

#if defined(HAVE_SETIMAGEPROGRESSMONITOR)
        rb_warning("Magick.set_monitor is deprecated; use Image#monitor= or Image::Info#monitor= instead.");
#endif

    }

    // If nil, turn off monitoring.
    if (monitor == Qnil)
    {
        (void) SetMonitorHandler(NULL);
    }
    else
    // Otherwise, store monitor in @@__MAGICK_MONITOR__
    {
        // 1.8.0 deletes rb_cvar_declare and adds another
        // parm to rb_cvar_set - if rb_cvar_declare is
        // available, use the 3-parm version of rb_cvar_set.
        RUBY18(rb_cvar_set(Module_Magick, Magick_Monitor, monitor, 0);)
        RUBY16(rb_cvar_set(Module_Magick, Magick_Monitor, monitor);)
        (void) SetMonitorHandler((MonitorHandler)&monitor_handler);
    }

    return class;
}