Class: Magick::Image::Info
- Inherits:
-
Object
- Object
- Magick::Image::Info
- Defined in:
- ext/RMagick/rmmain.c
Instance Method Summary collapse
- #[] ⇒ Object
-
#[]=(*args) ⇒ Object
Call SetImageOption.
-
#channel(*args) ⇒ Object
Set the channels.
-
#define(*args) ⇒ Object
Call SetImageOption.
-
#freeze ⇒ Object
Overrides freeze in classes that can’t be frozen.
-
#initialize ⇒ Object
constructor
If an initializer block is present, run it.
-
#undefine(format, key) ⇒ Object
Undefine image option.
Constructor Details
#initialize ⇒ Object
If an initializer block is present, run it.
Ruby usage:
- @verbatim Info#initialize @endverbatim
2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 |
# File 'ext/RMagick/rminfo.c', line 2580
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.
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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
# File 'ext/RMagick/rminfo.c', line 316
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) sprintf(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) RemoveImageOption(info, ckey);
}
else
{
/* Allow any argument that supports to_s */
value = rm_to_s(value);
value_p = StringValuePtr(value);
(void) RemoveImageOption(info, ckey);
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.
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 |
# File 'ext/RMagick/rminfo.c', line 623
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.
740 741 742 743 744 745 746 747 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 |
# File 'ext/RMagick/rminfo.c', line 740
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) RemoveImageOption(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;
}
|
#freeze ⇒ Object
Overrides freeze in classes that can’t be frozen.
No Ruby usage (internal function)
281 282 283 284 285 286 |
# File 'ext/RMagick/rmutil.c', line 281
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
2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 |
# File 'ext/RMagick/rminfo.c', line 2356
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);
}
sprintf(fkey, "%.60s:%.*s", format_p, (int)(MaxTextExtent-61), key_p);
Data_Get_Struct(self, Info, info);
/* Depending on the IM version, RemoveImageOption returns either */
/* char * or MagickBooleanType. Ignore the return value. */
(void) RemoveImageOption(info, fkey);
return self;
}
|