Class: Magick::Image::Info
- Inherits:
-
Object
- Object
- Magick::Image::Info
- Defined in:
- ext/RMagick/rmmain.c
Instance Method Summary collapse
- #[] ⇒ Object
-
#[]=(*args) ⇒ Object
Method: Info[format, key] = value Purpose: Call SetImageOption Note: Essentially the same function as Info#define but paired with Info#[]= If the value is nil it is equivalent to #undefine.
-
#channel(*args) ⇒ Object
Method: Info#channel(channel [, channel…]) Purpose: Set the channels Thanks: Douglas Sellers.
-
#define(*args) ⇒ Object
Method: Info#define(format, key[, value]) Purpose: Call SetImageOption Note: The only method in Info that is not an attribute accessor.
- #freeze ⇒ Object
-
#initialize ⇒ Object
constructor
Method: Info#initialize Purpose: If an initializer block is present, run it.
-
#undefine(format, key) ⇒ Object
Method: Info#undefine Purpose: Undefine image option.
Constructor Details
#initialize ⇒ Object
Method: Info#initialize Purpose: If an initializer block is present, run it.
1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 |
# File 'ext/RMagick/rminfo.c', line 1759
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
Method: Info[format, key] = value Purpose: Call SetImageOption Note: Essentially the same function as Info#define but paired with Info#[]=
If the value is nil it is equivalent to #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.
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
# File 'ext/RMagick/rminfo.c', line 233
VALUE
Info_aset(int argc, VALUE *argv, VALUE self)
{
Info *info;
volatile 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;
}
}
return self;
}
|
#channel(*args) ⇒ Object
Method: Info#channel(channel [, channel…]) Purpose: Set the channels Thanks: Douglas Sellers
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'ext/RMagick/rminfo.c', line 441
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
Method: Info#define(format, key[, value]) Purpose: Call SetImageOption Note: The only method in Info that is not an
attribute accessor.
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'ext/RMagick/rminfo.c', line 527
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;
volatile 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;
}
return self;
}
|
#freeze ⇒ Object
#undefine(format, key) ⇒ Object
Method: Info#undefine Purpose: Undefine image option
1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 |
# File 'ext/RMagick/rminfo.c', line 1595
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;
}
|