ext/RMagick/rmutil.c in rmagick-2.7.0 vs ext/RMagick/rmutil.c in rmagick-2.7.1
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmutil.c,v 1.163 2008/09/25 23:25:36 rmagick Exp $ */
+/* $Id: rmutil.c,v 1.170 2008/11/01 22:27:05 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmutil.c
| Author: Tim Hunter
| Purpose: Utility functions for RMagick
@@ -675,11 +675,11 @@
}
Data_Get_Struct(self, Pixel, pixel);
info = CloneImageInfo(NULL);
- image = AllocateImage(info);
+ image = AcquireImage(info);
image->depth = depth;
image->matte = matte;
(void) DestroyImageInfo(info);
GetMagickPixelPacket(image, &mpp);
@@ -939,11 +939,11 @@
if (!info)
{
rb_raise(rb_eNoMemError, "not enough memory to continue");
}
- image = AllocateImage(info);
+ image = AcquireImage(info);
// Delete Info now in case we have to raise an exception
(void) DestroyImageInfo(info);
if (!image)
@@ -1295,11 +1295,11 @@
Info *my_info;
volatile VALUE color_name;
my_info = info ? info : CloneImageInfo(NULL);
- image = AllocateImage(info);
+ image = AcquireImage(info);
image->matte = MagickFalse;
color_name = PixelPacket_to_Color_Name(image, color);
(void) DestroyImage(image);
if (!info)
{
@@ -2560,11 +2560,11 @@
name = rb_str_new2(ti->name);
family = rb_str_new2(ti->family);
style = StyleType_new(ti->style);
stretch = StretchType_new(ti->stretch);
- weight = UINT2NUM(ti->weight);
+ weight = ULONG2NUM(ti->weight);
description = ti->description ? rb_str_new2(ti->description) : Qnil;
encoding = ti->encoding ? rb_str_new2(ti->encoding) : Qnil;
foundry = ti->foundry ? rb_str_new2(ti->foundry) : Qnil;
format = ti->format ? rb_str_new2(ti->format) : Qnil;
@@ -3371,10 +3371,38 @@
#endif
}
/*
+ Function: rm_set_user_artifact
+ Purpose: If a "user" option is present in the Info, assign its value to
+ a "user" artifact in each image.
+*/
+void rm_set_user_artifact(Image *images, Info *info)
+{
+#if defined(HAVE_SETIMAGEARTIFACT)
+ Image *image;
+ const char *value;
+
+ value = GetImageOption(info, "user");
+ if (value)
+ {
+ image = GetFirstImageInList(images);
+ while (image)
+ {
+ (void) SetImageArtifact(image, "user", value);
+ image = GetNextImageInList(image);
+ }
+ }
+#else
+ images = images;
+ info = info;
+#endif
+}
+
+
+/*
Function: rm_get_optional_arguments
Purpose: Collect optional method arguments via Magick::OptionalMethodArguments
Notes: Creates an instance of Magick::OptionalMethodArguments, then yields
to a block in the context of the instance.
*/
@@ -3765,9 +3793,62 @@
{
return;
}
handle_exception(exception, imglist, retention);
+}
+
+
+
+/*
+ * Extern: rm_warning_handler
+ * Purpose: called from ImageMagick for a warning
+*/
+void
+rm_warning_handler(const ExceptionType severity, const char *reason, const char *description)
+{
+ ExceptionType dummy;
+
+ rb_warning("RMagick: %s: `%s'", reason, description);
+ dummy = severity;
+ dummy = dummy;
+}
+
+
+/*
+ * Extern: rm_error_handler
+ * Purpose: called from ImageMagick for a error
+*/
+void
+rm_error_handler(const ExceptionType severity, const char *reason, const char *description)
+{
+ char msg[500];
+ int len;
+ ExceptionType dummy;
+
+ memset(msg, 0, sizeof(msg));
+#if defined(HAVE_SNPRINTF)
+ len = snprintf(msg, sizeof(msg), "%s: `%s'", reason, description);
+#else
+ len = sprintf(msg, "%.250s: `%.240s'", reason, description);
+#endif
+ msg[len] = '\0';
+
+ rm_magick_error(msg, NULL);
+ dummy = severity;
+ dummy = dummy;
+}
+
+
+/*
+ * Extern: rm_fatal_error_handler
+ * Purpose: called from ImageMagick for a fatal error
+*/
+void
+rm_fatal_error_handler(const ExceptionType severity, const char *reason, const char *description)
+{
+ rb_raise(Class_FatalImageMagickError, GetLocaleExceptionMessage(severity, reason));
+ description = description;
}
/*
* Static: handle_exception