ext/RMagick/rmimage.c in rmagick-2.8.0 vs ext/RMagick/rmimage.c in rmagick-2.9.0
- old
+ new
@@ -1,6 +1,6 @@
-/* $Id: rmimage.c,v 1.334 2008/12/04 23:50:23 rmagick Exp $ */
+/* $Id: rmimage.c,v 1.343 2009/01/12 23:08:35 rmagick Exp $ */
/*============================================================================\
| Copyright (C) 2008 by Timothy P. Hunter
| Name: rmimage.c
| Author: Tim Hunter
| Purpose: Image class method definitions for RMagick
@@ -582,11 +582,11 @@
AffineMatrix matrix;
image = rm_check_destroyed(self);
// Convert Magick::AffineMatrix to AffineMatrix structure.
- AffineMatrix_to_AffineMatrix(&matrix, affine);
+ Export_AffineMatrix(&matrix, affine);
GetExceptionInfo(&exception);
new_image = AffineTransformImage(image, &matrix, &exception);
rm_check_exception(&exception, new_image, DestroyOnError);
@@ -827,11 +827,11 @@
*/
VALUE
Image_background_color(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return PixelPacket_to_Color_Name(image, &image->background_color);
+ return rm_pixelpacket_to_color_name(image, &image->background_color);
}
/*
Method: Image#background_color=
@@ -1436,11 +1436,11 @@
*/
VALUE
Image_border_color(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return PixelPacket_to_Color_Name(image, &image->border_color);
+ return rm_pixelpacket_to_color_name(image, &image->border_color);
}
/*
Method: Image#border_color=
@@ -1471,11 +1471,11 @@
box = GetImageBoundingBox(image, &exception);
CHECK_EXCEPTION()
(void) DestroyExceptionInfo(&exception);
- return Rectangle_from_RectangleInfo(&box);
+ return Import_RectangleInfo(&box);
}
/*
Method: Image.capture(silent=false,
@@ -1785,11 +1785,11 @@
*/
VALUE
Image_chromaticity_eq(VALUE self, VALUE chroma)
{
Image *image = rm_check_frozen(self);
- ChromaticityInfo_to_ChromaticityInfo(&image->chromaticity, chroma);
+ Export_ChromaticityInfo(&image->chromaticity, chroma);
return self;
}
/*
@@ -2215,11 +2215,11 @@
if (idx > image->colors-1)
{
rb_raise(rb_eIndexError, "index out of range");
}
- return PixelPacket_to_Color_Name(image, &image->colormap[idx]);
+ return rm_pixelpacket_to_color_name(image, &image->colormap[idx]);
}
// This is a "set" operation. Things are different.
rb_check_frozen(self);
@@ -2255,11 +2255,11 @@
// Save the current color so we can return it. Set the new color.
color = image->colormap[idx];
image->colormap[idx] = new_color;
- return PixelPacket_to_Color_Name(image, &color);
+ return rm_pixelpacket_to_color_name(image, &color);
}
DEF_ATTR_READER(Image, colors, ulong)
/*
@@ -2659,11 +2659,11 @@
image = rm_check_destroyed(self);
composite_image = rm_check_destroyed(source);
new_image = rm_clone_image(image);
- AffineMatrix_to_AffineMatrix(&affine, affine_matrix);
+ Export_AffineMatrix(&affine, affine_matrix);
(void) DrawAffineImage(new_image, composite_image, &affine);
rm_check_image_exception(new_image, DestroyOnError);
return rm_image_new(new_image);
}
@@ -4049,11 +4049,13 @@
strcpy(mi.magick, image->magick);
mi.len = (unsigned char) min((size_t)UCHAR_MAX, strlen(mi.magick));
// Concatenate the blob onto the header & return the result
str = rb_str_new((char *)&mi, (long)(mi.len+offsetof(DumpedImage,magick)));
- return rb_str_cat(str, (char *)blob, (long)length);
+ str = rb_str_buf_cat(str, (char *)blob, (long)length);
+ magick_free((void*)blob);
+ return str;
}
/*
Method: Image#dup
@@ -4700,19 +4702,19 @@
*/
VALUE
Image_extract_info(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return Rectangle_from_RectangleInfo(&image->extract_info);
+ return Import_RectangleInfo(&image->extract_info);
}
VALUE
Image_extract_info_eq(VALUE self, VALUE rect)
{
Image *image = rm_check_frozen(self);
- Rectangle_to_RectangleInfo(&image->extract_info, rect);
+ Export_RectangleInfo(&image->extract_info, rect);
return self;
}
DEF_ATTR_READER(Image, filename, str)
@@ -6254,10 +6256,98 @@
return rm_image_new(new_image);
}
/*
+ Method: Image#marshal_dump
+ Purpose: Support Marshal.dump >= 1.8
+ Returns: [img.filename, img.to_blob]
+*/
+VALUE
+Image_marshal_dump(VALUE self)
+{
+ Image *image;
+ Info *info;
+ unsigned char *blob;
+ size_t length;
+ VALUE ary;
+ ExceptionInfo exception;
+
+ image = rm_check_destroyed(self);
+
+ info = CloneImageInfo(NULL);
+ if (!info)
+ {
+ rb_raise(rb_eNoMemError, "not enough memory to initialize Info object");
+ }
+
+ ary = rb_ary_new2(2);
+ if (image->filename)
+ {
+ rb_ary_store(ary, 0, rb_str_new2(image->filename));
+ }
+ else
+ {
+ rb_ary_store(ary, 0, Qnil);
+ }
+
+ GetExceptionInfo(&exception);
+ blob = ImageToBlob(info, image, &length, &exception);
+
+ // Destroy info before raising an exception
+ DestroyImageInfo(info);
+ CHECK_EXCEPTION()
+ (void) DestroyExceptionInfo(&exception);
+
+ rb_ary_store(ary, 1, rb_str_new((char *)blob, (long)length));
+ magick_free((void*)blob);
+
+ return ary;
+}
+
+
+/*
+ Method: Image#marshal_load
+ Purpose: Support Marshal.load >= 1.8
+ Notes: On entry, ary is the array returned from marshal_dump.
+*/
+VALUE
+Image_marshal_load(VALUE self, VALUE ary)
+{
+ VALUE blob, filename;
+ Info *info;
+ Image *image;
+ ExceptionInfo exception;
+
+ info = CloneImageInfo(NULL);
+ if (!info)
+ {
+ rb_raise(rb_eNoMemError, "not enough memory to initialize Info object");
+ }
+
+ filename = rb_ary_shift(ary);
+ blob = rb_ary_shift(ary);
+
+ GetExceptionInfo(&exception);
+ if (filename != Qnil)
+ {
+ strcpy(info->filename, RSTRING_PTR(filename));
+ }
+ image = BlobToImage(info, RSTRING_PTR(blob), RSTRING_LEN(blob), &exception);
+
+ // Destroy info before raising an exception
+ DestroyImageInfo(info);
+ CHECK_EXCEPTION();
+ (void) DestroyExceptionInfo(&exception);
+
+ UPDATE_DATA_PTR(self, image);
+
+ return self;
+}
+
+
+/*
Static: get_image_mask
Purpose: Return the image's clip mask, or nil if it doesn't have a clip
mask.
Notes: Distinguish from Image#clip_mask
*/
@@ -6439,11 +6529,11 @@
*/
VALUE
Image_matte_color(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return PixelPacket_to_Color_Name(image, &image->matte_color);
+ return rm_pixelpacket_to_color_name(image, &image->matte_color);
}
/*
Method: Image#matte_color=
Purpose: Set the matte color
@@ -7279,11 +7369,11 @@
*/
VALUE
Image_page(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return Rectangle_from_RectangleInfo(&image->page);
+ return Import_RectangleInfo(&image->page);
}
/*
Method: Image#page=
@@ -7291,11 +7381,11 @@
*/
VALUE
Image_page_eq(VALUE self, VALUE rect)
{
Image *image = rm_check_frozen(self);
- Rectangle_to_RectangleInfo(&image->page, rect);
+ Export_RectangleInfo(&image->page, rect);
return self;
}
/*
@@ -7762,10 +7852,75 @@
#if defined(HAVE_ENUM_POWEVALUATEOPERATOR)
case PowQuantumOperator:
qop = PowEvaluateOperator;
break;
#endif
+#if defined(HAVE_ENUM_LOGEVALUATEOPERATOR)
+ case LogQuantumOperator:
+ qop = LogEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_THRESHOLDEVALUATEOPERATOR)
+ case ThresholdQuantumOperator:
+ qop = ThresholdEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_THRESHOLDBLACKEVALUATEOPERATOR)
+ case ThresholdBlackQuantumOperator:
+ qop = ThresholdBlackEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_THRESHOLDWHITEEVALUATEOPERATOR)
+ case ThresholdWhiteQuantumOperator:
+ qop = ThresholdWhiteEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_GAUSSIANNOISEEVALUATEOPERATOR)
+ case GaussianNoiseQuantumOperator:
+ qop = GaussianNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_IMPULSENOISEEVALUATEOPERATOR)
+ case ImpulseNoiseQuantumOperator:
+ qop = ImpulseNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_LAPLACIANNOISEEVALUATEOPERATOR)
+ case LaplacianNoiseQuantumOperator:
+ qop = LaplacianNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_MULTIPLICATIVENOISEEVALUATEOPERATOR)
+ case MultiplicativeNoiseQuantumOperator:
+ qop = MultiplicativeNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_POISSONNOISEEVALUATEOPERATOR)
+ case PoissonNoiseQuantumOperator:
+ qop = PoissonNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_UNIFORMNOISEEVALUATEOPERATOR)
+ case UniformNoiseQuantumOperator:
+ qop = UniformNoiseEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_COSINEEVALUATEOPERATOR)
+ case CosineQuantumOperator:
+ qop = CosineEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_SINEEVALUATEOPERATOR)
+ case SineQuantumOperator:
+ qop = SineEvaluateOperator;
+ break;
+#endif
+#if defined(HAVE_ENUM_ADDMODULUSEVALUATEOPERATOR)
+ case AddModulusQuantumOperator:
+ qop = AddModulusEvaluateOperator;
+ break;
+#endif
}
GetExceptionInfo(&exception);
(void) EvaluateImageChannel(image, channel, qop, rvalue, &exception);
CHECK_EXCEPTION()
@@ -10260,10 +10415,11 @@
}
return rm_image_new(new_image);
#else
rm_not_implemented();
+ return (VALUE)0;
argc = argc;
argv = argv;
self = self;
#endif
}
@@ -10275,10 +10431,10 @@
*/
VALUE
Image_transparent_color(VALUE self)
{
Image *image = rm_check_destroyed(self);
- return PixelPacket_to_Color_Name(image, &image->transparent_color);
+ return rm_pixelpacket_to_color_name(image, &image->transparent_color);
}
/*
Method: Image#transparent_color=