ext/RMagick/rmutil.c in rmagick-4.0.0 vs ext/RMagick/rmutil.c in rmagick-4.1.0.rc1
- old
+ new
@@ -624,11 +624,22 @@
* @return the created image
*/
Image *
rm_acquire_image(ImageInfo *info)
{
+#if defined(IMAGEMAGICK_7)
+ Image *new_image;
+ ExceptionInfo *exception;
+
+ exception = AcquireExceptionInfo();
+ new_image = AcquireImage(info, exception);
+ CHECK_EXCEPTION()
+ (void) DestroyExceptionInfo(exception);
+ return new_image;
+#else
return AcquireImage(info);
+#endif
}
/**
* Send the "cur_image" method to the object. If 'img' is an ImageList, then
@@ -658,16 +669,23 @@
* @see rm_pixelcolor_to_color_name_info
*/
VALUE
rm_pixelcolor_to_color_name(Image *image, PixelColor *color)
{
+ PixelColor pp;
char name[MaxTextExtent];
ExceptionInfo *exception;
exception = AcquireExceptionInfo();
- (void) QueryColorname(image, color, X11Compliance, name, exception);
+ pp = *color;
+#if defined(IMAGEMAGICK_7)
+ pp.depth = MAGICKCORE_QUANTUM_DEPTH;
+ pp.colorspace = image->colorspace;
+#endif
+
+ (void) QueryColorname(image, &pp, X11Compliance, name, exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(exception);
return rb_str_new2(name);
}
@@ -699,11 +717,16 @@
if (!image)
{
rb_raise(rb_eNoMemError, "not enough memory to continue.");
}
+#if defined(IMAGEMAGICK_7)
+ image->alpha_trait = UndefinedPixelTrait;
+#else
image->matte = MagickFalse;
+#endif
+
color_name = rm_pixelcolor_to_color_name(image, color);
(void) DestroyImage(image);
return color_name;
}
@@ -717,11 +740,15 @@
* @param pp the MagickPixel
*/
void
rm_init_magickpixel(const Image *image, MagickPixel *pp)
{
+#if defined(IMAGEMAGICK_7)
+ GetPixelInfo(image, pp);
+#else
GetMagickPixelPacket(image, pp);
+#endif
}
/**
* Initializes the MagickPixel structure to the specified color.
*
@@ -734,11 +761,16 @@
rm_set_magickpixel(MagickPixel *pp, const char *color)
{
ExceptionInfo *exception;
exception = AcquireExceptionInfo();
+
+#if defined(IMAGEMAGICK_7)
+ (void) QueryColorCompliance(color, AllCompliance, pp, exception);
+#else
(void) QueryMagickColor(color, pp, exception);
+#endif
// This exception is ignored because the color comes from places where we control
// the value and it is very unlikely that an exception will be thrown.
(void) DestroyExceptionInfo(exception);
}
@@ -920,11 +952,22 @@
* @return the property value
*/
const char *
rm_get_property(const Image *img, const char *property)
{
+#if defined(IMAGEMAGICK_7)
+ const char *result;
+ ExceptionInfo *exception;
+
+ exception = AcquireExceptionInfo();
+ result = GetImageProperty(img, property, exception);
+ CHECK_EXCEPTION()
+ (void) DestroyExceptionInfo(exception);
+ return result;
+#else
return GetImageProperty(img, property);
+#endif
}
/**
* Backport SetImageProperty for pre-6.3.1 versions of ImageMagick.
@@ -937,11 +980,22 @@
* @return true if successful, otherwise false
*/
MagickBooleanType
rm_set_property(Image *image, const char *property, const char *value)
{
+#if defined(IMAGEMAGICK_7)
+ ExceptionInfo *exception;
+ MagickBooleanType okay;
+
+ exception = AcquireExceptionInfo();
+ okay = SetImageProperty(image, property, value, exception);
+ CHECK_EXCEPTION()
+ (void) DestroyExceptionInfo(exception);
+ return okay;
+#else
return SetImageProperty(image, property, value);
+#endif
}
/**
* If a "user" option is present in the Info, assign its value to a "user"
@@ -1044,10 +1098,13 @@
void rm_sync_image_options(Image *image, Info *info)
{
MagickStatusType flags;
GeometryInfo geometry_info;
const char *option;
+#if defined(IMAGEMAGICK_7)
+ ExceptionInfo *exception;
+#endif
// The option strings will be set only when their attribute values were
// set in the optional argument block.
option = GetImageOption(info,"background");
if (option)
@@ -1061,11 +1118,20 @@
image->border_color = info->border_color;
}
if (info->colorspace != UndefinedColorspace)
{
+#if defined(IMAGEMAGICK_7)
+ exception = AcquireExceptionInfo();
+ SetImageColorspace(image, info->colorspace, exception);
+ // We should not throw an exception in this method because we will
+ // leak memory in the place where this method is called. And that is
+ // why the exception is being ignored here.
+ (void) DestroyExceptionInfo(exception);
+#else
SetImageColorspace(image, info->colorspace);
+#endif
}
if (info->compression != UndefinedCompression)
{
image->compression = info->compression;
@@ -1078,15 +1144,24 @@
}
if (info->density)
{
flags = ParseGeometry(info->density, &geometry_info);
+#if defined(IMAGEMAGICK_7)
+ image->resolution.x = geometry_info.rho;
+ image->resolution.y = geometry_info.sigma;
+#else
image->x_resolution = geometry_info.rho;
image->y_resolution = geometry_info.sigma;
+#endif
if ((flags & SigmaValue) == 0)
{
+#if defined(IMAGEMAGICK_7)
+ image->resolution.y = image->resolution.x;
+#else
image->y_resolution = image->x_resolution;
+#endif
}
}
if (info->depth != 0)
{
@@ -1172,21 +1247,31 @@
{
case PixelsPerInchResolution:
{
if (info->units == PixelsPerCentimeterResolution)
{
+#if defined(IMAGEMAGICK_7)
+ image->resolution.x /= 2.54;
+ image->resolution.y /= 2.54;
+#else
image->x_resolution /= 2.54;
image->y_resolution /= 2.54;
+#endif
}
break;
}
case PixelsPerCentimeterResolution:
{
if (info->units == PixelsPerInchResolution)
{
+#if defined(IMAGEMAGICK_7)
+ image->resolution.x *= 2.54;
+ image->resolution.y *= 2.54;
+#else
image->x_resolution *= 2.54;
image->y_resolution *= 2.54;
+#endif
}
break;
}
default:
break;
@@ -1217,12 +1302,20 @@
{
const char *property, *value;
char *str;
size_t len = 0, property_l, value_l;
VALUE v;
+#if defined(IMAGEMAGICK_7)
+ ExceptionInfo *exception;
+ exception = AcquireExceptionInfo();
+ (void) GetImageProperty(image, "exif:*", exception);
+ CHECK_EXCEPTION()
+#else
(void) GetImageProperty(image, "exif:*");
+#endif
+
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
// Measure the exif properties and values
while (property)
@@ -1234,11 +1327,16 @@
if (len > 0)
{
len += 1; // there will be a \n between property=value entries
}
len += property_l - 5;
- value = GetImageProperty(image,property);
+#if defined(IMAGEMAGICK_7)
+ value = GetImageProperty(image, property, exception);
+ CHECK_EXCEPTION()
+#else
+ value = GetImageProperty(image, property);
+#endif
if (value)
{
// add 1 for the = between property and value
len += 1 + strlen(value);
}
@@ -1246,12 +1344,16 @@
property = GetNextImageProperty(image);
}
if (len == 0)
{
+#if defined(IMAGEMAGICK_7)
+ (void) DestroyExceptionInfo(exception);
+#endif
return Qnil;
}
+
str = xmalloc(len);
len = 0;
// Copy the exif properties and values into the string.
ResetImagePropertyIterator(image);
@@ -1266,11 +1368,20 @@
{
str[len++] = '\n';
}
memcpy(str+len, property+5, property_l-5);
len += property_l - 5;
- value = GetImageProperty(image,property);
+#if defined(IMAGEMAGICK_7)
+ value = GetImageProperty(image, property, exception);
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
+ {
+ xfree(str);
+ rm_raise_exception(exception);
+ }
+#else
+ value = GetImageProperty(image, property);
+#endif
if (value)
{
value_l = strlen(value);
str[len++] = '=';
memcpy(str+len, value, value_l);
@@ -1278,10 +1389,14 @@
}
}
property = GetNextImageProperty(image);
}
+#if defined(IMAGEMAGICK_7)
+ (void) DestroyExceptionInfo(exception);
+#endif
+
v = rb_str_new(str, len);
xfree(str);
RB_GC_GUARD(v);
@@ -1306,12 +1421,19 @@
{
const char *property, *value;
char *str;
size_t len = 0, property_l, value_l;
VALUE v;
+#if defined(IMAGEMAGICK_7)
+ ExceptionInfo *exception;
+ exception = AcquireExceptionInfo();
+ (void) GetImageProperty(image, "exif:!", exception);
+ CHECK_EXCEPTION()
+#else
(void) GetImageProperty(image, "exif:!");
+#endif
ResetImagePropertyIterator(image);
property = GetNextImageProperty(image);
// Measure the exif properties and values
while (property)
@@ -1323,11 +1445,16 @@
if (len > 0)
{
len += 1; // there will be a \n between property=value entries
}
len += property_l;
- value = GetImageProperty(image,property);
+#if defined(IMAGEMAGICK_7)
+ value = GetImageProperty(image, property, exception);
+ CHECK_EXCEPTION()
+#else
+ value = GetImageProperty(image, property);
+#endif
if (value)
{
// add 1 for the = between property and value
len += 1 + strlen(value);
}
@@ -1335,12 +1462,16 @@
property = GetNextImageProperty(image);
}
if (len == 0)
{
+#if defined(IMAGEMAGICK_7)
+ (void) DestroyExceptionInfo(exception);
+#endif
return Qnil;
}
+
str = xmalloc(len);
len = 0;
// Copy the exif properties and values into the string.
ResetImagePropertyIterator(image);
@@ -1355,11 +1486,20 @@
{
str[len++] = '\n';
}
memcpy(str+len, property, property_l);
len += property_l;
- value = GetImageProperty(image,property);
+#if defined(IMAGEMAGICK_7)
+ value = GetImageProperty(image, property, exception);
+ if (rm_should_raise_exception(exception, RetainExceptionRetention))
+ {
+ xfree(str);
+ rm_raise_exception(exception);
+ }
+#else
+ value = GetImageProperty(image, property);
+#endif
if (value)
{
value_l = strlen(value);
str[len++] = '=';
memcpy(str+len, value, value_l);
@@ -1367,10 +1507,14 @@
}
}
property = GetNextImageProperty(image);
}
+#if defined(IMAGEMAGICK_7)
+ (void) DestroyExceptionInfo(exception);
+#endif
+
v = rb_str_new(str, len);
xfree(str);
RB_GC_GUARD(v);
@@ -1549,10 +1693,11 @@
(void) RemoveFirstImageFromList(&image);
}
}
+#if defined(IMAGEMAGICK_6)
/**
* If an ExceptionInfo struct in a list of images indicates a warning, issue a
* warning message. If an ExceptionInfo struct indicates an error, raise an
* exception and optionally destroy the images.
*
@@ -1598,9 +1743,10 @@
rm_check_exception(exception, imglist, retention);
}
(void) DestroyExceptionInfo(exception);
}
+#endif
#define ERROR_MSG_SIZE 1024
/**
* Formats the exception into the message buffer