Class: Magick::Image::Info

Inherits:
Object
  • Object
show all
Defined in:
ext/RMagick/rmmain.c

Instance Method Summary collapse

Constructor Details

#initializeObject

If an initializer block is present, run it.

Ruby usage:

- @verbatim Info#initialize @endverbatim

Parameters:

  • self

    this object



2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
# File 'ext/RMagick/rminfo.c', line 2636

VALUE
Info_initialize(VALUE self)
{
    if (rb_block_given_p())
    {
        // Run the block in self's context
        (void) rb_obj_instance_eval(0, NULL, self);
    }
    return self;
}

Instance Method Details

#[]Object

#[]=(*args) ⇒ Object

Call SetImageOption

Ruby usage:

- @verbatim Info[format, key]= @endverbatim
- @verbatim Info[key]= @endverbatim

Notes:

- Essentially the same function as Info_define but paired with Info_aref
- If the value is nil it is equivalent to Info_undefine.
- The 2 argument form is the original form. Added support for a single
  argument after ImageMagick started using Set/GetImageOption for options
  that aren't represented by fields in the ImageInfo structure.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • self

See Also:

  • Info_aref
  • Info_define
  • Info_undefine


333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
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
# File 'ext/RMagick/rminfo.c', line 333

VALUE
Info_aset(int argc, VALUE *argv, VALUE self)
{
    Info *info;
    VALUE value;
    char *format_p, *key_p, *value_p = NULL;
    long format_l, key_l;
    char ckey[MaxTextExtent];
    unsigned int okay;


    Data_Get_Struct(self, Info, info);

    switch (argc)
    {
        case 3:
            format_p = rm_str2cstr(argv[0], &format_l);
            key_p = rm_str2cstr(argv[1], &key_l);

            if (format_l > MAX_FORMAT_LEN || format_l+key_l > MaxTextExtent-1)
            {
                rb_raise(rb_eArgError, "%.60s:%.1024s not defined - too long", format_p, key_p);
            }

            (void) snprintf(ckey, sizeof(ckey), "%.60s:%.*s", format_p, (int)(sizeof(ckey)-MAX_FORMAT_LEN), key_p);

            value = argv[2];
            break;

        case 2:
            strncpy(ckey, StringValuePtr(argv[0]), sizeof(ckey)-1);
            ckey[sizeof(ckey)-1] = '\0';

            value = argv[1];
            break;

        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
            break;
    }

    if (NIL_P(value))
    {
        (void) DeleteImageOption(info, ckey);
    }
    else
    {
        /* Allow any argument that supports to_s */
        value = rm_to_s(value);
        value_p = StringValuePtr(value);

        okay = SetImageOption(info, ckey, value_p);
        if (!okay)
        {
            rb_warn("`%s' not defined - SetImageOption failed.", ckey);
            return Qnil;
        }
    }

    RB_GC_GUARD(value);

    return self;
}

#channel(*args) ⇒ Object

Set the channels

Ruby usage:

- @verbatim Info#channel @endverbatim
- @verbatim Info#channel(channel) @endverbatim
- @verbatim Info#channel(channel, ...) @endverbatim

Notes:

- Default channel is AllChannels
- Thanks to Douglas Sellers.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • self



631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'ext/RMagick/rminfo.c', line 631

VALUE
Info_channel(int argc, VALUE *argv, VALUE self)
{
    Info *info;
    ChannelType channels;

    channels = extract_channels(&argc, argv);

    // Ensure all arguments consumed.
    if (argc > 0)
    {
        raise_ChannelType_error(argv[argc-1]);
    }

    Data_Get_Struct(self, Info, info);

    info->channel = channels;
    return self;
}

#define(*args) ⇒ Object

Call SetImageOption

Ruby usage:

- @verbatim Info#define(format, key) @endverbatim
- @verbatim Info#define(format, key, value) @endverbatim

Notes:

- Default value is the empty string
- This is the only method in Info that is not an attribute accessor.

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • self



748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
# File 'ext/RMagick/rminfo.c', line 748

VALUE
Info_define(int argc, VALUE *argv, VALUE self)
{
    Info *info;
    char *format, *key;
    const char *value = "";
    long format_l, key_l;
    char ckey[100];
    unsigned int okay;
    VALUE fmt_arg;

    Data_Get_Struct(self, Info, info);

    switch (argc)
    {
        case 3:
            /* Allow any argument that supports to_s */
            fmt_arg = rb_String(argv[2]);
            value = (const char *)StringValuePtr(fmt_arg);
        case 2:
            key = rm_str2cstr(argv[1], &key_l);
            format = rm_str2cstr(argv[0], &format_l);
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
    }

    if (2 + format_l + key_l > (long)sizeof(ckey))
    {
        rb_raise(rb_eArgError, "%.20s:%.20s not defined - format or key too long", format, key);
    }
    (void) sprintf(ckey, "%s:%s", format, key);

    (void) DeleteImageOption(info, ckey);
    okay = SetImageOption(info, ckey, value);
    if (!okay)
    {
        rb_warn("%.20s=\"%.78s\" not defined - SetImageOption failed.", ckey, value);
        return Qnil;
    }

    RB_GC_GUARD(fmt_arg);

    return self;
}

#freezeObject

Overrides freeze in classes that can’t be frozen.

No Ruby usage (internal function)

Parameters:

  • obj

    the object of the class to override

Returns:

  • 0



302
303
304
305
306
307
# File 'ext/RMagick/rmutil.c', line 302

VALUE
rm_no_freeze(VALUE obj)
{
    rb_raise(rb_eTypeError, "can't freeze %s", rb_class2name(CLASS_OF(obj)));
    return (VALUE)0;
}

#undefine(format, key) ⇒ Object

Undefine image option.

Ruby usage:

- @verbatim Info#undefine(format,key) @endverbatim

Parameters:

  • self

    this object

  • format

    the format

  • key

    the key

Returns:

  • self



2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
# File 'ext/RMagick/rminfo.c', line 2403

VALUE
Info_undefine(VALUE self, VALUE format, VALUE key)
{
    Info *info;
    char *format_p, *key_p;
    long format_l, key_l;
    char fkey[MaxTextExtent];

    format_p = rm_str2cstr(format, &format_l);
    key_p = rm_str2cstr(key, &key_l);

    if (format_l > MAX_FORMAT_LEN || format_l + key_l > MaxTextExtent)
    {
        rb_raise(rb_eArgError, "can't undefine %.60s:%.1024s - too long", format_p, key_p);
    }

    snprintf(fkey, sizeof(fkey), "%.60s:%.*s", format_p, (int)(MaxTextExtent-61), key_p);

    Data_Get_Struct(self, Info, info);
    (void) DeleteImageOption(info, fkey);

    return self;
}