Class: Magick::Image::Info
- Inherits:
-
Object
- Object
- Magick::Image::Info
- Defined in:
- ext/RMagick/rmmain.c
Class Method Summary collapse
Instance Method Summary collapse
- #[] ⇒ Object
-
#[]=(format, key, value) ⇒ Object
Method: Info[format, key] = value Purpose: Call AddDefinitions (GM) or SetImageOption (IM) Note: Essentially the same function as Info#define but paired with Info#[]=.
-
#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 AddDefinitions (GM) or SetImageOption (IM) 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.
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 |
# File 'ext/RMagick/rminfo.c', line 1869
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;
}
|
Class Method Details
.new ⇒ Object
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 |
# File 'ext/RMagick/rminfo.c', line 1804
VALUE
Info_new(VALUE class)
{
Info *info;
volatile VALUE new_obj;
info = CloneImageInfo(NULL);
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to initialize Info object");
}
new_obj = Data_Wrap_Struct(class, NULL, destroy_Info, info);
rb_obj_call_init(new_obj, 0, NULL);
return new_obj;
}
|
Instance Method Details
#[] ⇒ Object
#[]=(format, key, value) ⇒ Object
Method: Info[format, key] = value Purpose: Call AddDefinitions (GM) or SetImageOption (IM) Note: Essentially the same function as Info#define but paired
with Info#[]=
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 157 158 |
# File 'ext/RMagick/rminfo.c', line 78
VALUE
Info_aset(VALUE self, VALUE format, VALUE key, VALUE value)
{
#if defined(HAVE_SETIMAGEOPTION)
Info *info;
char *format_p, *key_p, *value_p = "";
long format_l, key_l;
char ckey[MaxTextExtent];
unsigned int okay;
Data_Get_Struct(self, Info, info);
format_p = STRING_PTR_LEN(format, format_l);
key_p = STRING_PTR_LEN(key, key_l);
/* Allow any argument that supports to_s */
value = rb_funcall(value, rm_ID_to_s, 0);
value_p = STRING_PTR(value);
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);
okay = SetImageOption(info, ckey, value_p);
if (!okay)
{
rb_warn("%.60s:%.1024s not defined - SetImageOption failed.", format_p, key_p);
return Qnil;
}
return self;
#elif defined(HAVE_ADDDEFINITIONS)
Info *info;
char *format_p, *key_p, *value_p = NULL;
long format_l, key_l, value_l = 0;
unsigned int okay;
ExceptionInfo exception;
char definitions[MaxTextExtent*2];/* Make this buffer longer than the buffer used */
/* for SetImageOptions since AddDefinitions cats */
/* the value onto the format:key pair. */
Data_Get_Struct(self, Info, info);
format_p = STRING_PTR_LEN(format, format_l);
key_p = STRING_PTR_LEN(key, key_l);
value = rb_funcall(value, rm_ID_to_s, 0);
value_p = STRING_PTR_LEN(value, value_l);
if ((3 + format_l + key_l + value_l) > sizeof(definitions))
{
rb_raise(rb_eArgError, "%.60s:%.1024s not defined - too long", format_p, key_p);
}
(void)sprintf(definitions, "%s:%s=", format_p, key_p);
if (value_l > 0)
{
strcat(definitions, value_p);
}
GetExceptionInfo(&exception);
okay = AddDefinitions(info, definitions, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
if (!okay)
{
rb_warn("%.60s:%.1024s not defined - AddDefinitions failed.", format_p, key_p);
return Qnil;
}
return self;
#else
rm_not_implemented();
return (VALUE)0;
#endif
}
|
#channel(*args) ⇒ Object
Method: Info#channel(channel [, channel…]) Purpose: Set the channels Thanks: Douglas Sellers
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'ext/RMagick/rminfo.c', line 271
VALUE
Info_channel(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_IMAGEINFO_CHANNEL)
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;
#else
rm_not_implemented();
return (VALUE)0;
#endif
}
|
#define(*args) ⇒ Object
Method: Info#define(format, key[, value]) Purpose: Call AddDefinitions (GM) or SetImageOption (IM) Note: The only method in Info that is not an
attribute accessor.
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 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 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'ext/RMagick/rminfo.c', line 362
VALUE
Info_define(int argc, VALUE *argv, VALUE self)
{
#if defined(HAVE_SETIMAGEOPTION)
Info *info;
char *format, *key, *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_funcall(argv[2], rm_ID_to_s, 0);
value = STRING_PTR(fmt_arg);
case 2:
key = STRING_PTR_LEN(argv[1], key_l);
format = STRING_PTR_LEN(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 > sizeof(ckey))
{
rb_raise(rb_eArgError, "%.20s:%.20s not defined - format or key too long", format, key);
}
(void) sprintf(ckey, "%s:%s", format, key);
okay = SetImageOption(info, ckey, value);
if (!okay)
{
rb_warn("%.20s=\"%.78s\" not defined - SetImageOption failed.", ckey, value);
return Qnil;
}
return self;
#elif defined(HAVE_ADDDEFINITIONS)
Info *info;
char *format, *key, *value = NULL;
long format_l, key_l, value_l = 0;
unsigned int okay;
volatile VALUE fmt_arg;
ExceptionInfo exception;
char definitions[200]; /* Make this buffer longer than the buffer used */
/* for SetImageOptions since AddDefinitions cats */
/* the value onto the format:key pair. */
Data_Get_Struct(self, Info, info);
switch(argc)
{
case 3:
/* Allow any argument that supports to_s */
fmt_arg = rb_funcall(argv[2], rm_ID_to_s, 0);
value = STRING_PTR_LEN(fmt_arg, value_l);
/* Fall through */
case 2:
key = STRING_PTR_LEN(argv[1], key_l);
format = STRING_PTR_LEN(argv[0], format_l);
break;
default:
rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 or 3)", argc);
break;
}
if ((3 + format_l + key_l + value_l) > sizeof(definitions))
{
rb_raise(rb_eArgError, "%.20s:%.20s not defined - too long", format, key);
}
(void)sprintf(definitions, "%s:%s=", format, key);
if (value)
{
strcat(definitions, value);
}
GetExceptionInfo(&exception);
okay = AddDefinitions(info, definitions, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
if (!okay)
{
rb_warn("%.*s not defined - AddDefinitions failed.", sizeof(definitions), definitions);
return Qnil;
}
return self;
#else
rm_not_implemented();
return (VALUE)0;
#endif
}
|
#freeze ⇒ Object
#undefine(format, key) ⇒ Object
Method: Info#undefine Purpose: Undefine image option
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 |
# File 'ext/RMagick/rminfo.c', line 1667
VALUE
Info_undefine(VALUE self, VALUE format, VALUE key)
{
#if defined(HAVE_SETIMAGEOPTION)
Info *info;
char *format_p, *key_p;
long format_l, key_l;
char fkey[MaxTextExtent];
format_p = STRING_PTR_LEN(format, format_l);
key_p = STRING_PTR_LEN(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;
#elif defined(HAVE_ADDDEFINITIONS)
Info *info;
unsigned int okay;
char *format_p, *key_p;
long format_l, key_l;
char fkey[MaxTextExtent];
format_p = STRING_PTR_LEN(format, format_l);
key_p = STRING_PTR_LEN(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, MaxTextExtent-61, key_p);
Data_Get_Struct(self, Info, info);
okay = RemoveDefinitions(info, fkey);
if (!okay)
{
rb_raise(rb_eArgError, "no such key: `%s'", fkey);
}
return self;
#else
rm_not_implemented();
return (VALUE)0;
#endif
}
|