ext/RMagick/rmimage.c in rmagick-1.15.11 vs ext/RMagick/rmimage.c in rmagick-1.15.12
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmimage.c,v 1.192.2.5.2.2 2007/11/25 19:44:18 rmagick Exp $ */
+/* $Id: rmimage.c,v 1.192.2.5.2.4 2007/12/21 15:17:58 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2007 by Timothy P. Hunter
| Name: rmimage.c
| Author: Tim Hunter
| Purpose: Image class method definitions for RMagick
@@ -549,11 +549,11 @@
VALUE
Image_aref(VALUE self, VALUE key_arg)
{
Image *image;
char *key;
- const ImageAttribute *attr;
+ const char *attr;
switch (TYPE(key_arg))
{
case T_NIL:
return Qnil;
@@ -570,12 +570,22 @@
}
break;
}
Data_Get_Struct(self, Image, image);
- attr = GetImageAttribute(image, key);
- return attr ? rb_str_new2(attr->value) : Qnil;
+
+ if (rm_strcasecmp(key, "EXIF:*") == 0)
+ {
+ return rm_exif_by_entry(image);
+ }
+ else if (rm_strcasecmp(key, "EXIF:!") == 0)
+ {
+ return rm_exif_by_number(image);
+ }
+
+ attr = rm_get_property(image, key);
+ return attr ? rb_str_new2(attr) : Qnil;
}
/*
Method: Image#["key"] = attr
Image#[:key] = attr
@@ -595,11 +605,10 @@
VALUE
Image_aset(VALUE self, VALUE key_arg, VALUE attr_arg)
{
Image *image;
char *key, *attr;
- const ImageAttribute *attribute;
unsigned int okay;
rm_check_frozen(self);
attr = attr_arg == Qnil ? NULL : STRING_PTR(attr_arg);
@@ -628,26 +637,28 @@
// Image_properties (below) then check to see if we're
// about to delete the next attribute. If so, change
// the "next" pointer to point to the attribute following
// this one. (No, this isn't thread-safe!)
+#if !defined(HAVE_GETIMAGEPROPERTY) && !defined(HAVE_GETNEXTIMAGEATTRIBUTE)
if (Next_Attribute)
{
- attribute = GetImageAttribute(image, key);
+ const ImageAttribute *attribute = GetImageAttribute(image, key);
if (attribute && attribute == Next_Attribute)
{
Next_Attribute = attribute->next;
}
}
+#endif
// Delete existing value. SetImageAttribute returns False if
// the attribute doesn't exist - we don't care.
- (void) SetImageAttribute(image, key, NULL);
+ (void) rm_set_property(image, key, NULL);
// Set new value
if (attr)
{
- okay = SetImageAttribute(image, key, attr);
+ okay = rm_set_property(image, key, attr);
if (!okay)
{
rb_warning("SetImageAttribute failed (probably out of memory)");
}
}
@@ -9268,10 +9279,11 @@
}
#if defined(HAVE_SETIMAGESTORAGECLASS)
(void) SetImageStorageClass(image, class_type);
#else
+ (void) SyncImage(image);
image->storage_class = class_type;
#endif
return self;
}
@@ -9313,27 +9325,44 @@
}
size = (long)(cols * rows);
rm_check_ary_len(new_pixels, size);
- (void) SetImageType(image, TrueColorType);
+#if defined(HAVE_SETIMAGESTORAGECLASS)
+ okay = SetImageStorageClass(image,DirectClass);
+ rm_check_image_exception(image, RetainOnError);
+ if (!okay)
+ {
+ rb_raise(Class_ImageMagickError, "Can't store pixels. Can't change image storage class.");
+ }
+#else
+ if (image->storage_class == PseudoClass)
+ {
+ SyncImage(image);
+ rm_check_image_exception(image, RetainOnError);
+ image->storage_class = DirectClass;
+ }
+#endif
// Get a pointer to the pixels. Replace the values with the PixelPackets
// from the pixels argument.
pixels = GetImagePixels(image, x, y, cols, rows);
+ rm_check_image_exception(image, RetainOnError);
+
if (pixels)
{
for (n = 0; n < size; n++)
{
new_pixel = rb_ary_entry(new_pixels, n);
Data_Get_Struct(new_pixel, Pixel, pixel);
pixels[n] = *pixel;
}
okay = SyncImagePixels(image);
+ rm_check_image_exception(image, RetainOnError);
if (!okay)
{
- rb_raise(Class_ImageMagickError, "image pixels could not be synced");
+ rb_raise(Class_ImageMagickError, "Can't store pixels. Can't sync image pixels.");
}
}
return self;
}