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#[]=.
-
#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.
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 |
# File 'ext/RMagick/rminfo.c', line 1694
VALUE
Info_initialize(VALUE self)
{
if (rb_block_given_p())
{
// Run the block in self's context
rb_obj_instance_eval(0, NULL, self);
}
return self;
}
|
Class Method Details
.new ⇒ Object
1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 |
# File 'ext/RMagick/rminfo.c', line 1629
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, DestroyImageInfo, 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 |
# 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, 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, 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()
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
}
|
#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.
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 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 |
# File 'ext/RMagick/rminfo.c', line 327
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], 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], 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()
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
1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 |
# File 'ext/RMagick/rminfo.c', line 1513
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
}
|