ext/RMagick/rmmain.c in rmagick-1.10.1 vs ext/RMagick/rmmain.c in rmagick-1.11.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmmain.c,v 1.111 2006/02/19 17:12:20 rmagick Exp $ */
+/* $Id: rmmain.c,v 1.118 2006/05/07 21:41:12 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2006 by Timothy P. Hunter
| Name: rmmain.c
| Author: Tim Hunter
| Purpose: Contains all module, class, method declarations.
@@ -41,11 +41,11 @@
int x;
GetExceptionInfo(&exception);
color_ary = GetColorInfoArray(&exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
if (rb_block_given_p())
{
x = 0;
while(color_ary[x])
@@ -84,11 +84,12 @@
ExceptionInfo exception;
GetExceptionInfo(&exception);
color_info_list = GetColorInfoList("*", &number_colors, &exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
+
#endif
if (rb_block_given_p())
{
@@ -172,11 +173,12 @@
// IM 6.1.3 added an exception argument to GetTypeInfoList
ExceptionInfo exception;
GetExceptionInfo(&exception);
type_info = GetTypeInfoList("*", &number_types, &exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
+
#endif
if (rb_block_given_p())
{
for(x = 0; x < number_types; x++)
@@ -205,11 +207,11 @@
volatile VALUE ary;
GetExceptionInfo(&exception);
type_list = GetTypeInfo("*", &exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
// If block, iterate over fonts
if (rb_block_given_p())
{
for (type = (TypeInfo *)type_list; type; type = next)
@@ -305,11 +307,11 @@
#else
// IM 6.1.3 added an exception argument to GetMagickInfoList
GetExceptionInfo(&exception);
magick_info = GetMagickInfoList("*", &number_formats, &exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
#endif
for(x = 0; x < number_formats; x++)
{
rb_hash_aset(formats
@@ -328,11 +330,11 @@
formats = rb_hash_new();
GetExceptionInfo(&exception);
m = (MagickInfo *)GetMagickInfo("*", &exception);
- HANDLE_ERROR
+ CHECK_EXCEPTION()
for ( ; m != NULL; m = m->next)
{
rb_hash_aset(formats, rb_str_new2(m->name), MagickInfo_to_format(m));
}
@@ -340,11 +342,103 @@
return formats;
#endif
}
+
/*
+ Method: Magick.limit_resource(resource[, limit])
+ Purpose: Get/set resource limits. If a limit is specified the old limit
+ is set to the new value. Either way the current/new limit is returned.
+ Notes: Don't support "AreaLimit" because GraphicsMagick doesn't support it.
+*/
+static VALUE
+Magick_limit_resource(int argc, VALUE *argv, VALUE class)
+{
+#if defined(HAVE_GETMAGICKRESOURCELIMIT)
+ volatile VALUE resource, limit;
+ ResourceType res = UndefinedResource;
+ char *str;
+ ID id;
+ unsigned long cur_limit;
+
+ rb_scan_args(argc, argv, "11", &resource, &limit);
+
+ switch (TYPE(resource))
+ {
+ case T_NIL:
+ return class;
+
+ case T_SYMBOL:
+ id = SYM2ID(resource);
+ if (id == rb_intern("memory"))
+ {
+ res = MemoryResource;
+ }
+ else if (id == rb_intern("map"))
+ {
+ res = MapResource;
+ }
+ else if (id == rb_intern("disk"))
+ {
+ res = DiskResource;
+ }
+ else if (id == rb_intern("file"))
+ {
+ res = FileResource;
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "unknown resource: `:%s'", rb_id2name(id));
+ }
+ break;
+
+ default:
+ str = STRING_PTR(resource);
+ if (*str == '\0')
+ {
+ return class;
+ }
+ else if (rm_strcasecmp("memory", str) == 0)
+ {
+ res = MemoryResource;
+ }
+ else if (rm_strcasecmp("map", str) == 0)
+ {
+ res = MapResource;
+ }
+ else if (rm_strcasecmp("disk", str) == 0)
+ {
+ res = DiskResource;
+ }
+ else if (rm_strcasecmp("file", str) == 0)
+ {
+ res = FileResource;
+ }
+ else
+ {
+ rb_raise(rb_eArgError, "unknown resource: `%s'", str);
+ }
+ break;
+ }
+
+ cur_limit = GetMagickResourceLimit(res);
+
+ if (argc > 1)
+ {
+ SetMagickResourceLimit(res, NUM2ULONG(limit));
+ }
+
+ return ULONG2NUM(cur_limit);
+#else
+ rm_not_implemented();
+ return (VALUE)0;
+#endif
+}
+
+
+/*
This is the exit known to ImageMagick. Retrieve the monitor
proc and call it, passing the 3 exit arguments.
*/
static unsigned int
monitor_handler(
@@ -528,10 +622,11 @@
/*-----------------------------------------------------------------------*/
rb_define_module_function(Module_Magick, "colors", Magick_colors, 0);
rb_define_module_function(Module_Magick, "fonts", Magick_fonts, 0);
rb_define_module_function(Module_Magick, "init_formats", Magick_init_formats, 0);
+ rb_define_module_function(Module_Magick, "limit_resource", Magick_limit_resource, -1);
rb_define_module_function(Module_Magick, "set_monitor", Magick_set_monitor, 1);
rb_define_module_function(Module_Magick, "set_cache_threshold", Magick_set_cache_threshold, 1);
rb_define_module_function(Module_Magick, "set_log_event_mask", Magick_set_log_event_mask, -1);
rb_define_module_function(Module_Magick, "set_log_format", Magick_set_log_format, 1);
@@ -657,10 +752,11 @@
rb_define_method(Class_Image, "composite", Image_composite, -1);
rb_define_method(Class_Image, "composite!", Image_composite_bang, -1);
rb_define_method(Class_Image, "composite_affine", Image_composite_affine, 2);
rb_define_method(Class_Image, "compress_colormap!", Image_compress_colormap_bang, 0);
rb_define_method(Class_Image, "contrast", Image_contrast, -1);
+ rb_define_method(Class_Image, "contrast_stretch_channel", Image_contrast_stretch_channel, -1);
rb_define_method(Class_Image, "convolve", Image_convolve, 2);
rb_define_method(Class_Image, "convolve_channel", Image_convolve_channel, -1);
rb_define_method(Class_Image, "copy", Image_copy, 0);
rb_define_method(Class_Image, "crop", Image_crop, -1);
rb_define_method(Class_Image, "crop!", Image_crop_bang, -1);
@@ -799,10 +895,11 @@
rb_define_method(Class_ImageList, "flatten_images", ImageList_flatten_images, 0);
rb_define_method(Class_ImageList, "map", ImageList_map, 2);
rb_define_method(Class_ImageList, "montage", ImageList_montage, 0);
rb_define_method(Class_ImageList, "morph", ImageList_morph, 1);
rb_define_method(Class_ImageList, "mosaic", ImageList_mosaic, 0);
+ rb_define_method(Class_ImageList, "optimize_layers", ImageList_optimize_layers, 1);
rb_define_method(Class_ImageList, "quantize", ImageList_quantize, -1);
rb_define_method(Class_ImageList, "to_blob", ImageList_to_blob, 0);
rb_define_method(Class_ImageList, "write", ImageList_write, 1);
/*-----------------------------------------------------------------------*/
@@ -816,11 +913,11 @@
rb_define_singleton_method(Class_Draw, "new", Draw_new, 0);
#endif
DCL_ATTR_WRITER(Draw, affine)
DCL_ATTR_WRITER(Draw, align)
- DCL_ATTR_WRITER(Draw, border_color)
+ DCL_ATTR_WRITER(Draw, border_color)
DCL_ATTR_WRITER(Draw, decorate)
DCL_ATTR_WRITER(Draw, density)
DCL_ATTR_WRITER(Draw, encoding)
DCL_ATTR_WRITER(Draw, fill)
DCL_ATTR_WRITER(Draw, font)
@@ -1338,10 +1435,26 @@
ENUMERATOR(LineInterlace)
ENUMERATOR(PlaneInterlace)
ENUMERATOR(PartitionInterlace)
END_ENUM
+#if defined(HAVE_COMPAREIMAGELAYERS)
+ DEF_ENUM(MagickLayerMethod)
+ ENUMERATOR(UndefinedLayer)
+ ENUMERATOR(CompareAnyLayer)
+ ENUMERATOR(CompareClearLayer)
+ ENUMERATOR(CompareOverlayLayer)
+ ENUMERATOR(OptimizeLayer)
+ ENUMERATOR(OptimizePlusLayer)
+#if defined(HAVE_COALESCELAYER)
+ // Introduced in IM 6.2.7-0
+ ENUMERATOR(CoalesceLayer)
+ ENUMERATOR(DisposeLayer)
+#endif
+ END_ENUM
+#endif
+
#if defined(HAVE_COMPAREIMAGECHANNELS)
DEF_ENUM(MetricType)
ENUMERATOR(UndefinedMetric)
ENUMERATOR(MeanAbsoluteErrorMetric)
ENUMERATOR(MeanSquaredErrorMetric)
@@ -1660,10 +1773,10 @@
str = rb_str_new2(PACKAGE_STRING);
rb_obj_freeze(str);
rb_define_const(Module_Magick, "Version", str);
sprintf(long_version,
- "This is %s ($Date: 2006/02/19 17:12:20 $) Copyright (C) 2006 by Timothy P. Hunter\n"
+ "This is %s ($Date: 2006/05/07 21:41:12 $) Copyright (C) 2006 by Timothy P. Hunter\n"
"Built with %s\n"
"Built for %s\n"
"Web page: http://rmagick.rubyforge.org\n"
"Email: rmagick@rubyforge.org\n",
PACKAGE_STRING, mgk_version, RUBY_VERSION_STRING);