ext/RMagick/rmimage.c in rmagick-2.13.3 vs ext/RMagick/rmimage.c in rmagick-2.13.4

- old
+ new

@@ -20,11 +20,11 @@ /** Method that magnifies an image */ typedef Image *(magnifier_t)(const Image *, ExceptionInfo *); /** Method that reads an image */ typedef Image *(reader_t)(const Info *, ExceptionInfo *); /** Method that scales an image */ -typedef Image *(scaler_t)(const Image *, const unsigned long, const unsigned long, ExceptionInfo *); +typedef Image *(scaler_t)(const Image *, const size_t, const size_t, ExceptionInfo *); /** Method that computes threshold on an image */ typedef MagickBooleanType (thresholder_t)(Image *, const char *); /** Method that transforms an image */ typedef Image *(xformer_t)(const Image *, const RectangleInfo *, ExceptionInfo *); @@ -60,11 +60,11 @@ , Image *fp(const Image *, const double, const double, ExceptionInfo *)) { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -77,16 +77,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (fp)(image, radius, sigma, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = (fp)(image, radius, sigma, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -109,11 +109,11 @@ , Image *fp(const Image *, const ChannelType, const double, const double, ExceptionInfo *)) { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -128,16 +128,16 @@ default: raise_ChannelType_error(argv[argc-1]); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (fp)(image, channels, radius, sigma, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = (fp)(image, channels, radius, sigma, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -211,11 +211,11 @@ Image_adaptive_resize(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; unsigned long rows, columns; double scale_val, drows, dcols; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -241,15 +241,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } - GetExceptionInfo(&exception); - new_image = AdaptiveResizeImage(image, columns, rows, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = AdaptiveResizeImage(image, columns, rows, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -324,11 +324,11 @@ Image_adaptive_threshold(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; unsigned long width = 3, height = 3; long offset = 0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -342,15 +342,15 @@ break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc); } - GetExceptionInfo(&exception); - new_image = AdaptiveThresholdImage(image, width, height, offset, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = AdaptiveThresholdImage(image, width, height, offset, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -407,21 +407,21 @@ VALUE Image_add_noise(VALUE self, VALUE noise) { Image *image, *new_image; NoiseType noise_type; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); VALUE_TO_ENUM(noise, noise_type, NoiseType); - GetExceptionInfo(&exception); - new_image = AddNoiseImage(image, noise_type, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = AddNoiseImage(image, noise_type, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -445,11 +445,11 @@ VALUE Image_add_noise_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; NoiseType noise_type; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -464,15 +464,15 @@ } VALUE_TO_ENUM(argv[0], noise_type, NoiseType); channels &= ~OpacityChannel; - GetExceptionInfo(&exception); - new_image = AddNoiseImageChannel(image, channels, noise_type, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = AddNoiseImageChannel(image, channels, noise_type, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -492,11 +492,11 @@ Image_add_profile(VALUE self, VALUE name) { // ImageMagick code based on the code for the "-profile" option in mogrify.c Image *image, *profile_image; ImageInfo *info; - ExceptionInfo exception; + ExceptionInfo *exception; char *profile_name; char *profile_filename = NULL; long profile_filename_l = 0; const StringInfo *profile; @@ -516,15 +516,15 @@ info->profile = (void *)CloneStringInfo(profile); } strncpy(info->filename, profile_filename, min((size_t)profile_filename_l, sizeof(info->filename))); info->filename[MaxTextExtent-1] = '\0'; - GetExceptionInfo(&exception); - profile_image = ReadImage(info, &exception); + exception = AcquireExceptionInfo(); + profile_image = ReadImage(info, exception); (void) DestroyImageInfo(info); - rm_check_exception(&exception, profile_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + rm_check_exception(exception, profile_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(profile_image); ResetImageProfileIterator(profile_image); profile_name = GetNextImageProfile(profile_image); while (profile_name) @@ -689,23 +689,23 @@ */ VALUE Image_affine_transform(VALUE self, VALUE affine) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; AffineMatrix matrix; image = rm_check_destroyed(self); // Convert Magick::AffineMatrix to AffineMatrix structure. Export_AffineMatrix(&matrix, affine); - GetExceptionInfo(&exception); - new_image = AffineTransformImage(image, &matrix, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = AffineTransformImage(image, &matrix, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -845,19 +845,19 @@ */ static VALUE crisscross(int bang, VALUE self, Image *fp(const Image *, ExceptionInfo *)) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (fp)(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = (fp)(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -1721,11 +1721,11 @@ Image_blue_shift(int argc, VALUE *argv, VALUE self) { #if defined(HAVE_BLUESHIFTIMAGE) Image *image, *new_image; double factor = 1.5; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -1737,14 +1737,14 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } - GetExceptionInfo(&exception); - new_image = BlueShiftImage(image, factor, &exception); + exception = AcquireExceptionInfo(); + new_image = BlueShiftImage(image, factor, exception); CHECK_EXCEPTION(); - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; @@ -1780,11 +1780,11 @@ */ VALUE Image_blur_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; double radius = 0.0, sigma = 1.0; image = rm_check_destroyed(self); @@ -1801,15 +1801,15 @@ break; default: raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); - new_image = BlurImageChannel(image, channels, radius, sigma, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = BlurImageChannel(image, channels, radius, sigma, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -1858,11 +1858,11 @@ static VALUE border(int bang, VALUE self, VALUE width, VALUE height, VALUE color) { Image *image, *new_image; PixelPacket old_border; - ExceptionInfo exception; + ExceptionInfo *exception; RectangleInfo rect; Data_Get_Struct(self, Image, image); memset(&rect, 0, sizeof(rect)); @@ -1871,15 +1871,15 @@ // Save current border color - we'll want to restore it afterwards. old_border = image->border_color; Color_to_PixelPacket(&image->border_color, color); - GetExceptionInfo(&exception); - new_image = BorderImage(image, &rect, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = BorderImage(image, &rect, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -1987,18 +1987,18 @@ VALUE Image_bounding_box(VALUE self) { Image *image; RectangleInfo box; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - box = GetImageBoundingBox(image, &exception); + exception = AcquireExceptionInfo(); + box = GetImageBoundingBox(image, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return Import_RectangleInfo(&box); } @@ -2188,27 +2188,27 @@ Image_channel_depth(int argc, VALUE *argv, VALUE self) { Image *image; ChannelType channels; unsigned long channel_depth; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); // Ensure all arguments consumed. if (argc > 0) { raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - channel_depth = GetImageChannelDepth(image, channels, &exception); + channel_depth = GetImageChannelDepth(image, channels, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return ULONG2NUM(channel_depth); } @@ -2235,12 +2235,12 @@ VALUE Image_channel_extrema(int argc, VALUE *argv, VALUE self) { Image *image; ChannelType channels; - ExceptionInfo exception; - unsigned long min, max; + ExceptionInfo *exception; + size_t min, max; volatile VALUE ary; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -2249,15 +2249,15 @@ if (argc > 0) { raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); - (void) GetImageChannelExtrema(image, channels, &min, &max, &exception); + exception = AcquireExceptionInfo(); + (void) GetImageChannelExtrema(image, channels, &min, &max, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); ary = rb_ary_new2(2); rb_ary_store(ary, 0, ULONG2NUM(min)); rb_ary_store(ary, 1, ULONG2NUM(max)); @@ -2283,11 +2283,11 @@ VALUE Image_channel_mean(int argc, VALUE *argv, VALUE self) { Image *image; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; double mean, stddev; volatile VALUE ary; image = rm_check_destroyed(self); @@ -2297,15 +2297,15 @@ if (argc > 0) { raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); - (void) GetImageChannelMean(image, channels, &mean, &stddev, &exception); + exception = AcquireExceptionInfo(); + (void) GetImageChannelMean(image, channels, &mean, &stddev, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); ary = rb_ary_new2(2); rb_ary_store(ary, 0, rb_float_new(mean)); rb_ary_store(ary, 1, rb_float_new(stddev)); @@ -2504,13 +2504,13 @@ VALUE Image_color_histogram(VALUE self) { Image *image, *dc_copy = NULL; volatile VALUE hash, pixel; - unsigned long x, colors; + size_t x, colors; ColorPacket *histogram; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); // If image not DirectClass make a DirectClass copy. if (image->storage_class != DirectClass) @@ -2521,28 +2521,28 @@ dc_copy->colormap = NULL; dc_copy->storage_class = DirectClass; image = dc_copy; } - GetExceptionInfo(&exception); - histogram = GetImageHistogram(image, &colors, &exception); + exception = AcquireExceptionInfo(); + histogram = GetImageHistogram(image, &colors, exception); if (histogram == NULL) { if (dc_copy) { (void) DestroyImage(dc_copy); } rb_raise(rb_eNoMemError, "not enough memory to continue"); } - if (exception.severity != UndefinedException) + if (exception->severity != UndefinedException) { (void) RelinquishMagickMemory(histogram); - rm_check_exception(&exception, dc_copy, DestroyOnError); + rm_check_exception(exception, dc_copy, DestroyOnError); } - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); hash = rb_hash_new(); for (x = 0; x < colors; x++) { pixel = Pixel_from_PixelPacket(&histogram[x].pixel); @@ -2579,22 +2579,22 @@ set_profile(VALUE self, const char *name, VALUE profile) { Image *image, *profile_image; ImageInfo *info; const MagickInfo *m; - ExceptionInfo exception; + ExceptionInfo *exception; char *profile_name; char *profile_blob; long profile_length; const StringInfo *profile_data; image = rm_check_frozen(self); profile_blob = rm_str2cstr(profile, &profile_length); - GetExceptionInfo(&exception); - m = GetMagickInfo(name, &exception); + exception = AcquireExceptionInfo(); + m = GetMagickInfo(name, exception); CHECK_EXCEPTION() info = CloneImageInfo(NULL); if (!info) { @@ -2602,14 +2602,14 @@ } strncpy(info->magick, m->name, MaxTextExtent); info->magick[MaxTextExtent-1] = '\0'; - profile_image = BlobToImage(info, profile_blob, (size_t)profile_length, &exception); + profile_image = BlobToImage(info, profile_blob, (size_t)profile_length, exception); (void) DestroyImageInfo(info); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); ResetImageProfileIterator(profile_image); profile_name = GetNextImageProfile(profile_image); while (profile_name) { @@ -2808,11 +2808,11 @@ { Image *image, *new_image; double red, green, blue, matte; char opacity[50]; PixelPacket target; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); if (argc == 4) { @@ -2834,15 +2834,15 @@ else { rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc); } - GetExceptionInfo(&exception); - new_image = ColorizeImage(image, opacity, target, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ColorizeImage(image, opacity, target, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -3036,11 +3036,11 @@ */ VALUE Image_combine(int argc, VALUE *argv, VALUE self) { ChannelType channel = 0; Image *image, *images = NULL, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; self = self; // defeat "unreferenced argument" message switch (argc) { @@ -3080,14 +3080,14 @@ if (channel == 0) { rb_raise(rb_eArgError, "no images to combine"); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); ReverseImageList(&images); - new_image = CombineImages(images, channel, &exception); - rm_check_exception(&exception, images, RetainOnError); + new_image = CombineImages(images, channel, exception); + rm_check_exception(exception, images, RetainOnError); rm_split(images); rm_ensure_result(new_image); return rm_image_new(new_image); @@ -3127,11 +3127,11 @@ Image *image, *r_image, *difference_image; double distortion; volatile VALUE ary, ref; MetricType metric_type; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -3149,20 +3149,20 @@ ref = rm_cur_image(argv[0]); r_image = rm_check_destroyed(ref); VALUE_TO_ENUM(argv[1], metric_type, MetricType); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); difference_image = CompareImageChannels(image , r_image , channels , metric_type , &distortion - , &exception); - rm_check_exception(&exception, difference_image, DestroyOnError); + , exception); + rm_check_exception(exception, difference_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(difference_image); ary = rb_ary_new2(2); rb_ary_store(ary, 0, rm_image_new(difference_image)); @@ -3826,11 +3826,11 @@ VALUE Image_constitute(VALUE class, VALUE width_arg, VALUE height_arg , VALUE map_arg, VALUE pixels_arg) { Image *image; - ExceptionInfo exception; + ExceptionInfo *exception; volatile VALUE pixel, pixel0; unsigned long width, height; long x, npixels; char *map; long map_l; @@ -3911,11 +3911,11 @@ { pixels.i[x] = NUM2QUANTUM(pixel); } } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // This is based on ConstituteImage in IM 5.5.7 image = AcquireImage(NULL); if (!image) { @@ -3930,12 +3930,14 @@ (void) ImportImagePixels(image, 0, 0, width, height, map, stg_type, (const void *)pixels.v); xfree(pixels.v); rm_check_image_exception(image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); +#if defined(HAVE_DESTROYCONSTITUTE) || defined(HAVE_CONSTITUTECOMPONENTTERMINUS) DestroyConstitute(); +#endif return rm_image_new(image); } /** @@ -4103,11 +4105,11 @@ Image_convolve(VALUE self, VALUE order_arg, VALUE kernel_arg) { Image *image, *new_image; double *kernel; unsigned int x, order; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); order = NUM2UINT(order_arg); @@ -4120,17 +4122,17 @@ for (x = 0; x < order*order; x++) { kernel[x] = NUM2DBL(rb_ary_entry(kernel_arg, (long)x)); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = ConvolveImage((const Image *)image, order, (double *)kernel, &exception); + new_image = ConvolveImage((const Image *)image, order, (double *)kernel, exception); xfree((void *)kernel); - rm_check_exception(&exception, new_image, DestroyOnError); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -4155,11 +4157,11 @@ Image *image, *new_image; double *kernel; volatile VALUE ary; unsigned int x, order; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -4184,17 +4186,17 @@ for (x = 0; x < order*order; x++) { kernel[x] = NUM2DBL(rb_ary_entry(ary, (long)x)); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = ConvolveImageChannel(image, channels, order, kernel, &exception); + new_image = ConvolveImageChannel(image, channels, order, kernel, exception); xfree((void *)kernel); - rm_check_exception(&exception, new_image, DestroyOnError); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -4422,28 +4424,28 @@ Image_decipher(VALUE self, VALUE passphrase) { #if defined(HAVE_ENCIPHERIMAGE) Image *image, *new_image; char *pf; - ExceptionInfo exception; + ExceptionInfo *exception; MagickBooleanType okay; image = rm_check_destroyed(self); pf = StringValuePtr(passphrase); // ensure passphrase is a string - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); - okay = DecipherImage(new_image, pf, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + okay = DecipherImage(new_image, pf, exception); + rm_check_exception(exception, new_image, DestroyOnError); if (!okay) { new_image = DestroyImage(new_image); rb_raise(rb_eRuntimeError, "DecipherImage failed for unknown reason."); } - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); return rm_image_new(new_image); #else self = self; passphrase = passphrase; @@ -4573,19 +4575,19 @@ VALUE Image_depth(VALUE self) { Image *image; unsigned long depth = 0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - depth = GetImageDepth(image, &exception); + depth = GetImageDepth(image, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return INT2FIX(depth); } @@ -4612,11 +4614,11 @@ #if defined(HAVE_DESKEWIMAGE) Image *image, *new_image; double threshold = 40.0 * QuantumRange / 100.0; unsigned long width; char auto_crop_width[20]; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -4632,16 +4634,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } - GetExceptionInfo(&exception); - new_image = DeskewImage(image, threshold, &exception); + exception = AcquireExceptionInfo(); + new_image = DeskewImage(image, threshold, exception); CHECK_EXCEPTION() rm_ensure_result(new_image); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); #else self = self; // defeat "unused parameter" message argv = argv; @@ -4664,19 +4666,19 @@ */ VALUE Image_despeckle(VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = DespeckleImage(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = DespeckleImage(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -4864,11 +4866,11 @@ volatile VALUE pixels_ary; StorageType stg_type = QuantumPixel; char *map; long mapL; MagickBooleanType okay; - ExceptionInfo exception; + ExceptionInfo *exception; volatile union { Quantum *i; double *f; void *v; @@ -4899,21 +4901,21 @@ // Create the Ruby array for the pixels. Return this even if ExportImagePixels fails. pixels_ary = rb_ary_new(); Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); - okay = ExportImagePixels(image, x, y, columns, rows, map, stg_type, (void *)pixels.v, &exception); + exception = AcquireExceptionInfo(); + okay = ExportImagePixels(image, x, y, columns, rows, map, stg_type, (void *)pixels.v, exception); if (!okay) { goto exit; } CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); // Convert the pixel data to the appropriate Ruby type if (stg_type == QuantumPixel) { for (n = 0; n < npixels; n++) @@ -5100,11 +5102,11 @@ volatile VALUE pts; unsigned long n, npoints; DistortImageMethod distortion_method; double *points; MagickBooleanType bestfit = MagickFalse; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); rm_get_optional_arguments(self); switch (argc) @@ -5129,15 +5131,15 @@ for (n = 0; n < npoints; n++) { points[n] = NUM2DBL(rb_ary_entry(pts, n)); } - GetExceptionInfo(&exception); - new_image = DistortImage(image, distortion_method, npoints, points, bestfit, &exception); + exception = AcquireExceptionInfo(); + new_image = DistortImage(image, distortion_method, npoints, points, bestfit, exception); xfree(points); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5161,11 +5163,11 @@ VALUE Image_distortion_channel(int argc, VALUE *argv, VALUE self) { Image *image, *reconstruct; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; MetricType metric; volatile VALUE rec; double distortion; image = rm_check_destroyed(self); @@ -5180,16 +5182,16 @@ } rec = rm_cur_image(argv[0]); reconstruct = rm_check_destroyed(rec); VALUE_TO_ENUM(argv[1], metric, MetricType); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); (void) GetImageChannelDistortion(image, reconstruct, channels - , metric, &distortion, &exception); + , metric, &distortion, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rb_float_new(distortion); } @@ -5214,11 +5216,11 @@ ImageInfo *info; void *blob; size_t length; DumpedImage mi; volatile VALUE str; - ExceptionInfo exception; + ExceptionInfo *exception; depth = depth; // Suppress "never referenced" message from icc image = rm_check_destroyed(self); @@ -5227,19 +5229,19 @@ { rb_raise(rb_eNoMemError, "not enough memory to continue"); } strcpy(info->magick, image->magick); - GetExceptionInfo(&exception); - blob = ImageToBlob(info, image, &length, &exception); + exception = AcquireExceptionInfo(); + blob = ImageToBlob(info, image, &length, exception); // Free ImageInfo first - error handling may raise an exception (void) DestroyImageInfo(info); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); if (!blob) { rb_raise(rb_eNoMemError, "not enough memory to continue"); } @@ -5354,11 +5356,11 @@ VALUE Image_edge(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double radius = 0.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 1: @@ -5368,16 +5370,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = EdgeImage(image, radius, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = EdgeImage(image, radius, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5396,11 +5398,11 @@ */ static VALUE effect_image(VALUE self, int argc, VALUE *argv, effector_t effector) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; double radius = 0.0, sigma = 1.0; image = rm_check_destroyed(self); switch (argc) @@ -5419,15 +5421,15 @@ if (sigma == 0.0) { rb_raise(rb_eArgError, "sigma must be != 0.0"); } - GetExceptionInfo(&exception); - new_image = (effector)(image, radius, sigma, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = (effector)(image, radius, sigma, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5472,28 +5474,28 @@ Image_encipher(VALUE self, VALUE passphrase) { #if defined(HAVE_ENCIPHERIMAGE) Image *image, *new_image; char *pf; - ExceptionInfo exception; + ExceptionInfo *exception; MagickBooleanType okay; image = rm_check_destroyed(self); pf = StringValuePtr(passphrase); // ensure passphrase is a string - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); - okay = EncipherImage(new_image, pf, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + okay = EncipherImage(new_image, pf, exception); + rm_check_exception(exception, new_image, DestroyOnError); if (!okay) { new_image = DestroyImage(new_image); rb_raise(rb_eRuntimeError, "EncipherImage failed for unknown reason."); } - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); return rm_image_new(new_image); #else self = self; passphrase = passphrase; @@ -5550,19 +5552,19 @@ */ VALUE Image_enhance(VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = EnhanceImage(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = EnhanceImage(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5579,20 +5581,20 @@ */ VALUE Image_equalize(VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); (void) EqualizeImage(new_image); rm_check_image_exception(new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -5615,11 +5617,11 @@ VALUE Image_equalize_channel(int argc, VALUE *argv, VALUE self) { #if defined(HAVE_EQUALIZEIMAGECHANNEL) Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); if (argc > 0) @@ -5627,16 +5629,16 @@ raise_ChannelType_error(argv[argc-1]); } new_image = rm_clone_image(image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); (void) EqualizeImageChannel(new_image, channels); rm_check_image_exception(new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); #else argc = argc; argv = argv; @@ -5695,24 +5697,24 @@ static VALUE excerpt(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height) { Image *image, *new_image; RectangleInfo rect; - ExceptionInfo exception; + ExceptionInfo *exception; memset(&rect,'\0', sizeof(rect)); rect.x = NUM2LONG(x); rect.y = NUM2LONG(y); rect.width = NUM2ULONG(width); rect.height = NUM2ULONG(height); Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); - new_image = ExcerptImage(image, &rect, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - DestroyExceptionInfo(&exception); + exception = AcquireExceptionInfo(); + new_image = ExcerptImage(image, &rect, exception); + rm_check_exception(exception, new_image, DestroyOnError); + DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { UPDATE_DATA_PTR(self, new_image); @@ -5806,11 +5808,11 @@ long n, npixels; unsigned int okay; const char *map = "RGB"; Quantum *pixels; volatile VALUE ary; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); cols = image->columns; rows = image->rows; @@ -5847,23 +5849,23 @@ if (!pixels) // app recovered from exception { return rb_ary_new2(0L); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, QuantumPixel, (void *)pixels, &exception); + okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, QuantumPixel, (void *)pixels, exception); if (!okay) { xfree((void *)pixels); CHECK_EXCEPTION() // Should never get here... rm_magick_error("ExportImagePixels failed with no explanation.", NULL); } - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); ary = rb_ary_new2(npixels); for (n = 0; n < npixels; n++) { (void) rb_ary_push(ary, QUANTUM2NUM(pixels[n])); @@ -5896,11 +5898,11 @@ Image_extent(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; RectangleInfo geometry; long height, width; - ExceptionInfo exception; + ExceptionInfo *exception; (void) rm_check_destroyed(self); if (argc < 2 || argc > 4) { @@ -5934,15 +5936,15 @@ } } Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = ExtentImage(image, &geometry, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + new_image = ExtentImage(image, &geometry, exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5982,11 +5984,11 @@ unsigned int okay; const char *map = "RGB"; StorageType type = CharPixel; volatile VALUE string; char *str; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); cols = image->columns; rows = image->rows; @@ -6053,24 +6055,24 @@ // Get a pointer to the buffer. string = rb_str_new2(""); (void) rb_str_resize(string, (long)(sz * npixels)); str = StringValuePtr(string); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, type, (void *)str, &exception); + okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, type, (void *)str, exception); if (!okay) { // Let GC have the string buffer. (void) rb_str_resize(string, 0); CHECK_EXCEPTION() // Should never get here... rm_magick_error("ExportImagePixels failed with no explanation.", NULL); } - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return string; } @@ -6194,12 +6196,12 @@ VALUE Image_find_similar_region(int argc, VALUE *argv, VALUE self) { Image *image, *target; volatile VALUE region, targ; - long x = 0L, y = 0L; - ExceptionInfo exception; + ssize_t x = 0L, y = 0L; + ExceptionInfo *exception; unsigned int okay; image = rm_check_destroyed(self); switch (argc) @@ -6215,14 +6217,14 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 3)", argc); break; } - GetExceptionInfo(&exception); - okay = IsImageSimilar(image, target, &x, &y, &exception); + exception = AcquireExceptionInfo(); + okay = IsImageSimilar(image, target, &x, &y, exception); CHECK_EXCEPTION(); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); if (!okay) { return Qnil; } @@ -6251,19 +6253,19 @@ */ static VALUE flipflop(int bang, VALUE self, flipper_t flipflopper) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (flipflopper)(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = (flipflopper)(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -6379,20 +6381,20 @@ VALUE Image_format(VALUE self) { Image *image; const MagickInfo *magick_info; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); if (*image->magick) { // Deliberately ignore the exception info! - GetExceptionInfo(&exception); - magick_info = GetMagickInfo(image->magick, &exception); - (void) DestroyExceptionInfo(&exception); + exception = AcquireExceptionInfo(); + magick_info = GetMagickInfo(image->magick, exception); + (void) DestroyExceptionInfo(exception); return magick_info ? rb_str_new2(magick_info->name) : Qnil; } return Qnil; } @@ -6412,21 +6414,21 @@ Image_format_eq(VALUE self, VALUE magick) { Image *image; const MagickInfo *m; char *mgk; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_frozen(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); mgk = StringValuePtr(magick); - m = GetMagickInfo(mgk, &exception); + m = GetMagickInfo(mgk, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); if (!m) { rb_raise(rb_eArgError, "unknown format: %s", mgk); } @@ -6475,11 +6477,11 @@ */ VALUE Image_frame(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; FrameInfo frame_info; image = rm_check_destroyed(self); frame_info.width = image->columns + 50; @@ -6510,15 +6512,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 7)", argc); break; } - GetExceptionInfo(&exception); - new_image = FrameImage(image, &frame_info, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = FrameImage(image, &frame_info, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -6538,11 +6540,11 @@ Image_from_blob(VALUE class, VALUE blob_arg) { Image *images; Info *info; volatile VALUE info_obj; - ExceptionInfo exception; + ExceptionInfo *exception; void *blob; long length; class = class; // defeat gcc message blob_arg = blob_arg; // defeat gcc message @@ -6551,15 +6553,15 @@ // Get a new Info object - run the parm block if supplied info_obj = rm_info_new(); Data_Get_Struct(info_obj, Info, info); - GetExceptionInfo(&exception); - images = BlobToImage(info, blob, (size_t)length, &exception); - rm_check_exception(&exception, images, DestroyOnError); + exception = AcquireExceptionInfo(); + images = BlobToImage(info, blob, (size_t)length, exception); + rm_check_exception(exception, images, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(images); rm_set_user_artifact(images, info); return array_from_images(images); @@ -6590,11 +6592,11 @@ MagickFunction function; unsigned long n, nparms; volatile double *parameters; double *parms; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); // The number of parameters depends on the function. @@ -6642,16 +6644,16 @@ for (n = 0; n < nparms; n++) { parms[n] = NUM2DBL(argv[n]); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); - (void) FunctionImageChannel(new_image, channels, function, nparms, parms, &exception); + (void) FunctionImageChannel(new_image, channels, function, nparms, parms, exception); (void) xfree(parms); - rm_check_exception(&exception, new_image, DestroyOnError); - DestroyExceptionInfo(&exception); + rm_check_exception(exception, new_image, DestroyOnError); + DestroyExceptionInfo(exception); return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; @@ -6854,11 +6856,11 @@ VALUE Image_gaussian_blur_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; double radius = 0.0, sigma = 1.0; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -6875,15 +6877,15 @@ break; default: raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); - new_image = GaussianBlurImageChannel(image, channels, radius, sigma, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = GaussianBlurImageChannel(image, channels, radius, sigma, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -6962,11 +6964,11 @@ VALUE Image_get_pixels(VALUE self, VALUE x_arg, VALUE y_arg, VALUE cols_arg, VALUE rows_arg) { Image *image; const PixelPacket *pixels; - ExceptionInfo exception; + ExceptionInfo *exception; long x, y; unsigned long columns, rows; long size, n; VALUE pixel_ary; @@ -6982,19 +6984,19 @@ , columns, rows, x, y); } // Cast AcquireImagePixels to get rid of the const qualifier. We're not going // to change the pixels but I don't want to make "pixels" const. - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); #if defined(HAVE_GETVIRTUALPIXELS) - pixels = GetVirtualPixels(image, x, y, columns, rows, &exception); + pixels = GetVirtualPixels(image, x, y, columns, rows, exception); #else - pixels = AcquireImagePixels(image, x, y, columns, rows, &exception); + pixels = AcquireImagePixels(image, x, y, columns, rows, exception); #endif CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); // If the function failed, return a 0-length array. if (!pixels) { return rb_ary_new(); @@ -7025,17 +7027,17 @@ */ static VALUE has_attribute(VALUE self, MagickBooleanType (attr_test)(const Image *, ExceptionInfo *)) { Image *image; - ExceptionInfo exception; + ExceptionInfo *exception; MagickBooleanType r; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - r = (attr_test)(image, &exception); + r = (attr_test)(image, exception); CHECK_EXCEPTION() return r ? Qtrue : Qfalse; } @@ -7093,11 +7095,11 @@ VALUE Image_implode(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double amount = 0.50; - ExceptionInfo exception; + ExceptionInfo *exception; switch (argc) { case 1: amount = NUM2DBL(argv[0]); @@ -7106,15 +7108,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); } image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = ImplodeImage(image, amount, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + new_image = ImplodeImage(image, amount, exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7710,11 +7712,11 @@ { #if defined(HAVE_LEVELIMAGECOLORS) || defined(HAVE_LEVELCOLORSIMAGECHANNEL) Image *image, *new_image; MagickPixelPacket black_color, white_color; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; MagickBooleanType invert = MagickTrue; MagickBooleanType status; image = rm_check_destroyed(self); @@ -7730,30 +7732,30 @@ Color_to_MagickPixelPacket(image, &black_color, argv[0]); break; case 1: Color_to_MagickPixelPacket(image, &black_color, argv[0]); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); GetMagickPixelPacket(image, &white_color); - (void) QueryMagickColor("white", &white_color, &exception); + (void) QueryMagickColor("white", &white_color, exception); CHECK_EXCEPTION() - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); case 0: - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); GetMagickPixelPacket(image, &white_color); - (void) QueryMagickColor("white", &white_color, &exception); + (void) QueryMagickColor("white", &white_color, exception); CHECK_EXCEPTION() GetMagickPixelPacket(image, &black_color); - (void) QueryMagickColor("black", &black_color, &exception); + (void) QueryMagickColor("black", &black_color, exception); CHECK_EXCEPTION() - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); break; default: raise_ChannelType_error(argv[argc-1]); break; @@ -7915,11 +7917,11 @@ #if defined(HAVE_LIQUIDRESCALEIMAGE) Image *image, *new_image; unsigned long cols, rows; double delta_x = 0.0; double rigidity = 0.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -7934,14 +7936,14 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 4)", argc); break; } - GetExceptionInfo(&exception); - new_image = LiquidRescaleImage(image, cols, rows, delta_x, rigidity, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - DestroyExceptionInfo(&exception); + exception = AcquireExceptionInfo(); + new_image = LiquidRescaleImage(image, cols, rows, delta_x, rigidity, exception); + rm_check_exception(exception, new_image, DestroyOnError); + DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); #else argc = argc; // defeat "unused parameter" messages @@ -7971,11 +7973,11 @@ Image__load(VALUE class, VALUE str) { Image *image; ImageInfo *info; DumpedImage mi; - ExceptionInfo exception; + ExceptionInfo *exception; char *blob; long length; class = class; // Suppress "never referenced" message from icc @@ -8016,20 +8018,20 @@ } memcpy(info->magick, ((DumpedImage *)blob)->magick, mi.len); info->magick[mi.len] = '\0'; - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); blob += offsetof(DumpedImage,magick) + mi.len; length -= offsetof(DumpedImage,magick) + mi.len; - image = BlobToImage(info, blob, (size_t) length, &exception); + image = BlobToImage(info, blob, (size_t) length, exception); (void) DestroyImageInfo(info); - rm_check_exception(&exception, image, DestroyOnError); + rm_check_exception(exception, image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(image); return rm_image_new(image); } @@ -8048,19 +8050,19 @@ static VALUE magnify(int bang, VALUE self, magnifier_t magnifier) { Image *image; Image *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (magnifier)(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = (magnifier)(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -8132,16 +8134,17 @@ Image *image, *new_image; Image *map; volatile VALUE map_obj, map_arg; unsigned int dither = MagickFalse; - image = rm_check_destroyed(self); - #if defined(HAVE_REMAPIMAGE) + QuantizeInfo quantize_info; rb_warning("Image#map is deprecated. Use Image#remap instead"); #endif + image = rm_check_destroyed(self); + switch (argc) { case 2: dither = RTEST(argv[1]); case 1: @@ -8154,11 +8157,17 @@ new_image = rm_clone_image(image); map_obj = rm_cur_image(map_arg); map = rm_check_destroyed(map_obj); +#if defined(HAVE_REMAPIMAGE) + GetQuantizeInfo(&quantize_info); + quantize_info.dither=dither; + (void) RemapImage(&quantize_info, new_image, map); +#else (void) MapImage(new_image, map, dither); +#endif rm_check_image_exception(new_image, DestroyOnError); return rm_image_new(new_image); } @@ -8178,11 +8187,11 @@ Image *image; Info *info; unsigned char *blob; size_t length; VALUE ary; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); info = CloneImageInfo(NULL); if (!info) @@ -8198,17 +8207,17 @@ else { rb_ary_store(ary, 0, Qnil); } - GetExceptionInfo(&exception); - blob = ImageToBlob(info, image, &length, &exception); + exception = AcquireExceptionInfo(); + blob = ImageToBlob(info, image, &length, exception); // Destroy info before raising an exception DestroyImageInfo(info); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rb_ary_store(ary, 1, rb_str_new((char *)blob, (long)length)); magick_free((void*)blob); return ary; @@ -8229,32 +8238,32 @@ Image_marshal_load(VALUE self, VALUE ary) { VALUE blob, filename; Info *info; Image *image; - ExceptionInfo exception; + 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); + exception = AcquireExceptionInfo(); if (filename != Qnil) { strcpy(info->filename, RSTRING_PTR(filename)); } - image = BlobToImage(info, RSTRING_PTR(blob), RSTRING_LEN(blob), &exception); + image = BlobToImage(info, RSTRING_PTR(blob), RSTRING_LEN(blob), exception); // Destroy info before raising an exception DestroyImageInfo(info); CHECK_EXCEPTION(); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); UPDATE_DATA_PTR(self, image); return self; } @@ -8273,19 +8282,19 @@ */ static VALUE get_image_mask(Image *image) { Image *mask; - ExceptionInfo exception; + ExceptionInfo *exception; - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // The returned clip mask is a clone, ours to keep. - mask = GetImageClipMask(image, &exception); - rm_check_exception(&exception, mask, DestroyOnError); + mask = GetImageClipMask(image, exception); + rm_check_exception(exception, mask, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return mask ? rm_image_new(mask) : Qnil; } @@ -8337,11 +8346,11 @@ volatile VALUE mask; Image *image, *mask_image, *resized_image; Image *clip_mask; long x, y; PixelPacket *q; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); if (argc == 0) { return get_image_mask(image); @@ -8361,29 +8370,29 @@ clip_mask = rm_clone_image(mask_image); // Resize if necessary if (clip_mask->columns != image->columns || clip_mask->rows != image->rows) { - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); resized_image = ResizeImage(clip_mask, image->columns, image->rows - , UndefinedFilter, 0.0, &exception); - rm_check_exception(&exception, resized_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + , UndefinedFilter, 0.0, exception); + rm_check_exception(exception, resized_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(resized_image); (void) DestroyImage(clip_mask); clip_mask = resized_image; } // The following section is copied from mogrify.c (6.2.8-8) #if defined(HAVE_SYNCAUTHENTICPIXELS) - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); #endif for (y = 0; y < (long) clip_mask->rows; y++) { #if defined(HAVE_GETAUTHENTICPIXELS) - q = GetAuthenticPixels(clip_mask, 0, y, clip_mask->columns, 1, &exception); - rm_check_exception(&exception, clip_mask, DestroyOnError); + q = GetAuthenticPixels(clip_mask, 0, y, clip_mask->columns, 1, exception); + rm_check_exception(exception, clip_mask, DestroyOnError); #else q = GetImagePixels(clip_mask, 0, y, clip_mask->columns, 1); rm_check_image_exception(clip_mask, DestroyOnError); #endif if (!q) @@ -8401,19 +8410,19 @@ q->blue = q->opacity; q += 1; } #if defined(HAVE_SYNCAUTHENTICPIXELS) - SyncAuthenticPixels(clip_mask, &exception); - rm_check_exception(&exception, clip_mask, DestroyOnError); + SyncAuthenticPixels(clip_mask, exception); + rm_check_exception(exception, clip_mask, DestroyOnError); #else SyncImagePixels(clip_mask); rm_check_image_exception(clip_mask, DestroyOnError); #endif } #if defined(HAVE_SYNCAUTHENTICPIXELS) - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); #endif SetImageStorageClass(clip_mask, DirectClass); rm_check_image_exception(clip_mask, DestroyOnError); @@ -8634,11 +8643,11 @@ VALUE Image_median_filter(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double radius = 0.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 1: @@ -8648,17 +8657,20 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); +#if defined(HAVE_STATISTICIMAGE) + new_image = StatisticImage(image, MedianStatistic, (size_t)radius, (size_t)radius, exception); +#else + new_image = MedianFilterImage(image, radius, exception); +#endif + rm_check_exception(exception, new_image, DestroyOnError); - new_image = MedianFilterImage(image, radius, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); - (void) DestroyExceptionInfo(&exception); - rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -8887,11 +8899,11 @@ { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; double angle = 0.0; - ExceptionInfo exception; + ExceptionInfo *exception; switch (argc) { case 3: angle = NUM2DBL(argv[2]); @@ -8911,15 +8923,15 @@ rb_raise(rb_eArgError, "sigma must be != 0.0"); } Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); - new_image = (fp)(image, radius, sigma, angle, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = (fp)(image, radius, sigma, angle, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -9265,20 +9277,20 @@ */ VALUE Image_number_colors(VALUE self) { Image *image; - ExceptionInfo exception; + ExceptionInfo *exception; unsigned long n = 0; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - n = (unsigned long) GetNumberColors(image, NULL, &exception); + n = (unsigned long) GetNumberColors(image, NULL, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return ULONG2NUM(n); } @@ -9303,11 +9315,11 @@ VALUE Image_oil_paint(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double radius = 3.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 1: @@ -9317,16 +9329,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = OilPaintImage(image, radius, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = OilPaintImage(image, radius, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -9514,11 +9526,11 @@ Image_ordered_dither(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; int order; const char *threshold_map = "2x2"; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); if (argc > 1) { @@ -9548,17 +9560,17 @@ } } new_image = rm_clone_image(image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // ImageMagick >= 6.2.9 - (void) OrderedPosterizeImage(new_image, threshold_map, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + (void) OrderedPosterizeImage(new_image, threshold_map, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -9769,11 +9781,11 @@ VALUE Image_pixel_color(int argc, VALUE *argv, VALUE self) { Image *image; PixelPacket old_color, new_color, *pixel; - ExceptionInfo exception; + ExceptionInfo *exception; long x, y; unsigned int set = False; MagickBooleanType okay; memset(&old_color, 0, sizeof(old_color)); @@ -9799,19 +9811,19 @@ y = NUM2LONG(argv[1]); // Get the color of a pixel if (!set) { - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); #if defined(HAVE_GETVIRTUALPIXELS) - old_color = *GetVirtualPixels(image, x, y, 1, 1, &exception); + old_color = *GetVirtualPixels(image, x, y, 1, 1, exception); #else - old_color = *AcquireImagePixels(image, x, y, 1, 1, &exception); + old_color = *AcquireImagePixels(image, x, y, 1, 1, exception); #endif CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); // PseudoClass if (image->storage_class == PseudoClass) { #if defined(HAVE_GETAUTHENTICINDEXQUEUE) @@ -9847,15 +9859,15 @@ } } #if defined(HAVE_GETAUTHENTICPIXELS) || defined(HAVE_SYNCAUTHENTICPIXELS) - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); #endif #if defined(HAVE_GETAUTHENTICPIXELS) - pixel = GetAuthenticPixels(image, x, y, 1, 1, &exception); + pixel = GetAuthenticPixels(image, x, y, 1, 1, exception); CHECK_EXCEPTION() #else pixel = GetImagePixels(image, x, y, 1, 1); rm_check_image_exception(image, RetainOnError); #endif @@ -9869,19 +9881,19 @@ } } *pixel = new_color; #if defined(HAVE_SYNCAUTHENTICPIXELS) - SyncAuthenticPixels(image, &exception); + SyncAuthenticPixels(image, exception); CHECK_EXCEPTION() #else SyncImagePixels(image); rm_check_image_exception(image, RetainOnError); #endif #if defined(HAVE_GETAUTHENTICPIXELS) || defined(HAVE_SYNCAUTHENTICPIXELS) - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); #endif return Pixel_from_PixelPacket(&old_color); } @@ -9948,11 +9960,11 @@ { Image *image, *clone, *new_image; volatile VALUE options; double angle = -5.0; Draw *draw; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -9970,16 +9982,16 @@ clone = rm_clone_image(image); clone->background_color = draw->shadow_color; clone->border_color = draw->info->border_color; - GetExceptionInfo(&exception); - new_image = PolaroidImage(clone, draw->info, angle, &exception); - rm_check_exception(&exception, clone, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = PolaroidImage(clone, draw->info, angle, exception); + rm_check_exception(exception, clone, DestroyOnError); (void) DestroyImage(clone); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -10044,20 +10056,20 @@ VALUE Image_preview(VALUE self, VALUE preview) { Image *image, *new_image; PreviewType preview_type; - ExceptionInfo exception; + ExceptionInfo *exception; - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); image = rm_check_destroyed(self); VALUE_TO_ENUM(preview, preview_type, PreviewType); - new_image = PreviewImage(image, preview_type, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = PreviewImage(image, preview_type, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -10157,11 +10169,11 @@ Image *image; QuantumExpressionOperator operator; MagickEvaluateOperator qop; double rvalue; ChannelType channel; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); // The default channel is AllChannels channel = AllChannels; @@ -10295,15 +10307,15 @@ qop = AddModulusEvaluateOperator; break; #endif } - GetExceptionInfo(&exception); - (void) EvaluateImageChannel(image, channel, qop, rvalue, &exception); + exception = AcquireExceptionInfo(); + (void) EvaluateImageChannel(image, channel, qop, rvalue, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return self; } @@ -10387,19 +10399,23 @@ */ VALUE Image_radial_blur(VALUE self, VALUE angle) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = RadialBlurImage(image, NUM2DBL(angle), &exception); - rm_check_exception(&exception, new_image, DestroyOnError); +#if defined(HAVE_ROTATIONALBLURIMAGE) + new_image = RotationalBlurImage(image, NUM2DBL(angle), exception); +#else + new_image = RadialBlurImage(image, NUM2DBL(angle), exception); +#endif + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -10424,11 +10440,11 @@ */ VALUE Image_radial_blur_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -10440,16 +10456,19 @@ else if (argc > 1) { raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = RadialBlurImageChannel(image, channels, NUM2DBL(argv[0]), &exception); - - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); +#if defined(HAVE_ROTATIONALBLURIMAGECHANNEL) + new_image = RotationalBlurImageChannel(image, channels, NUM2DBL(argv[0]), exception); +#else + new_image = RadialBlurImageChannel(image, channels, NUM2DBL(argv[0]), exception); +#endif + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -10475,11 +10494,11 @@ { Image *image, *new_image; ChannelType channels; char *thresholds; volatile VALUE geom_str; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -10497,16 +10516,16 @@ geom_str = rm_to_s(argv[0]); thresholds = StringValuePtr(geom_str); new_image = rm_clone_image(image); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - (void) RandomThresholdImageChannel(new_image, channels, thresholds, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + (void) RandomThresholdImageChannel(new_image, channels, thresholds, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -10626,11 +10645,11 @@ char *filename; long filename_l; Info *info; volatile VALUE info_obj; Image *images; - ExceptionInfo exception; + ExceptionInfo *exception; class = class; // defeat gcc message // Create a new Info structure for this read/ping info_obj = rm_info_new(); @@ -10655,16 +10674,16 @@ memcpy(info->filename, filename, (size_t)filename_l); info->filename[filename_l] = '\0'; SetImageInfoFile(info, NULL); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - images = (reader)(info, &exception); - rm_check_exception(&exception, images, DestroyOnError); + images = (reader)(info, exception); + rm_check_exception(exception, images, DestroyOnError); rm_set_user_artifact(images, info); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return array_from_images(images); } @@ -10683,14 +10702,18 @@ { Image *image, *new_image; unsigned long order; long x, len; double *matrix; - ExceptionInfo exception; + ExceptionInfo *exception; +#if defined(HAVE_COLORMATRIXIMAGE) + KernelInfo *kernel_info; +#endif + image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // Allocate color matrix from Ruby's memory len = RARRAY_LEN(color_matrix); matrix = ALLOC_N(double, len); @@ -10700,15 +10723,27 @@ } order = (unsigned long)sqrt((double)(len + 1.0)); // RecolorImage sets the ExceptionInfo and returns a NULL image if an error occurs. - new_image = RecolorImage(image, order, matrix, &exception); +#if defined(HAVE_COLORMATRIXIMAGE) + kernel_info = AcquireKernelInfo("1"); + if (kernel_info == (KernelInfo *) NULL) + return((Image *) NULL); + kernel_info->width = order; + kernel_info->height = order; + kernel_info->values = (double *) matrix; + new_image = ColorMatrixImage(image, kernel_info, exception); + kernel_info->values = (double *) NULL; + kernel_info = DestroyKernelInfo(kernel_info); +#else + new_image = RecolorImage(image, order, matrix, exception); +#endif xfree((void *)matrix); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -10736,11 +10771,11 @@ ImageInfo *info; char *image_data; long x, image_data_l; unsigned char *blob; size_t blob_l; - ExceptionInfo exception; + ExceptionInfo *exception; self = self; // defeat gcc message image_data = rm_str2cstr(content, &image_data_l); @@ -10763,23 +10798,23 @@ if (blob_l == 0) { rb_raise(rb_eArgError, "can't decode image"); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // Create a new Info structure for this read. About the // only useful attribute that can be set is `format'. info_obj = rm_info_new(); Data_Get_Struct(info_obj, Info, info); - images = BlobToImage(info, blob, blob_l, &exception); + images = BlobToImage(info, blob, blob_l, exception); magick_free((void *)blob); - rm_check_exception(&exception, images, DestroyOnError); + rm_check_exception(exception, images, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_set_user_artifact(images, info); return array_from_images(images); } @@ -10824,19 +10859,23 @@ */ VALUE Image_reduce_noise(VALUE self, VALUE radius) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - new_image = ReduceNoiseImage(image, NUM2DBL(radius), &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); +#if defined(HAVE_STATISTICIMAGE) + new_image = StatisticImage(image, NonpeakStatistic, (size_t)radius, (size_t)radius, exception); +#else + new_image = ReduceNoiseImage(image, NUM2DBL(radius), exception); +#endif + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -10937,10 +10976,156 @@ return self; } /** + * Resample image to specified horizontal resolution, vertical resolution, + * filter and blur factor. + * + * No Ruby usage (internal function) + * + * @param bang whether the bang (!) version of the method was called + * @param argc number of input arguments + * @param argv array of input arguments + * @param self this object + * @return self if bang, otherwise a new image + * @see Image_resample + * @see Image_resample_bang + */ +static VALUE +resample(int bang, int argc, VALUE *argv, VALUE self) +{ + Image *image, *new_image; + FilterTypes filter; + double x_resolution, y_resolution, blur; + double width, height; + ExceptionInfo *exception; + + Data_Get_Struct(self, Image, image); + + // Set up defaults + filter = image->filter; + blur = image->blur; + x_resolution = 72.0; + y_resolution = 72.0; + + switch (argc) + { + case 4: + blur = NUM2DBL(argv[3]); + case 3: + VALUE_TO_ENUM(argv[2], filter, FilterTypes); + case 2: + y_resolution = NUM2DBL(argv[1]); + if (y_resolution < 0.0) + { + rb_raise(rb_eArgError, "invalid y_resolution value (%lf given)", y_resolution); + } + case 1: + x_resolution = NUM2DBL(argv[0]); + if (x_resolution < 0.0) + { + rb_raise(rb_eArgError, "invalid x_resolution value (%lf given)", x_resolution); + } + if (argc == 1) + { + y_resolution = x_resolution; + } + width = (x_resolution * image->columns / + (image->x_resolution == 0.0 ? 72.0 : image->x_resolution) + 0.5); + height = (y_resolution * image->rows / + (image->y_resolution == 0.0 ? 72.0 : image->y_resolution) + 0.5); + if (width > (double)ULONG_MAX || height > (double)ULONG_MAX) + { + rb_raise(rb_eRangeError, "resampled image too big"); + } + break; + case 0: + break; + default: + rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc); + break; + } + + exception = AcquireExceptionInfo(); + new_image = ResampleImage(image, x_resolution, y_resolution, filter, blur, exception); + rm_check_exception(exception, new_image, DestroyOnError); + + (void) DestroyExceptionInfo(exception); + + rm_ensure_result(new_image); + + if (bang) + { + UPDATE_DATA_PTR(self, new_image); + (void) rm_image_destroy(image); + return self; + } + return rm_image_new(new_image); +} + +/** + * Resample image to specified horizontal resolution, vertical resolution, + * filter and blur factor. + * + * Ruby usage: + * - @verbatim Image#resample @endverbatim + * - @verbatim Image#resample(resolution) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution, filter) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution, filter, blur) @endverbatim + * + * Notes: + * - Default filter is image->filter + * - Default blur is image->blur + * + * @param argc number of input arguments + * @param argv array of input arguments + * @param self this object + * @return a new image + * @see resample + * @see Image_resample_bang + */ +VALUE +Image_resample(int argc, VALUE *argv, VALUE self) +{ + (void) rm_check_destroyed(self); + return resample(False, argc, argv, self); +} + + +/** + * Resample image to specified horizontal resolution, vertical resolution, + * filter and blur factor. + * + * Ruby usage: + * - @verbatim Image#resample @endverbatim + * - @verbatim Image#resample(resolution) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution, filter) @endverbatim + * - @verbatim Image#resample(x_resolution, y_resolution, filter, blur) @endverbatim + * + * Notes: + * - Default filter is image->filter + * - Default blur is image->blur + * + * @param argc number of input arguments + * @param argv array of input arguments + * @param self this object + * @return a new image + * @see resample + * @see Image_resample + */ +VALUE +Image_resample_bang(int argc, VALUE *argv, VALUE self) +{ + (void) rm_check_frozen(self); + return resample(True, argc, argv, self); +} + + +/** * Scale an image to the desired dimensions using the specified filter and blur * factor. * * No Ruby usage (internal function) * @@ -10958,11 +11143,11 @@ Image *image, *new_image; double scale_arg; FilterTypes filter; unsigned long rows, columns; double blur, drows, dcols; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); // Set up defaults filter = image->filter; @@ -11002,15 +11187,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 4)", argc); break; } - GetExceptionInfo(&exception); - new_image = ResizeImage(image, columns, rows, filter, blur, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ResizeImage(image, columns, rows, filter, blur, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -11093,19 +11278,19 @@ */ VALUE Image_roll(VALUE self, VALUE x_offset, VALUE y_offset) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - new_image = RollImage(image, NUM2LONG(x_offset), NUM2LONG(y_offset), &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = RollImage(image, NUM2LONG(x_offset), NUM2LONG(y_offset), exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -11129,11 +11314,11 @@ { Image *image, *new_image; double degrees; char *arrow; long arrow_l; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); switch (argc) { @@ -11157,16 +11342,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = RotateImage(image, degrees, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = RotateImage(image, degrees, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -11358,11 +11543,11 @@ scale(int bang, int argc, VALUE *argv, VALUE self, scaler_t scaler) { Image *image, *new_image; unsigned long columns, rows; double scale_arg, drows, dcols; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); switch (argc) { @@ -11392,15 +11577,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } - GetExceptionInfo(&exception); - new_image = (scaler)(image, columns, rows, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = (scaler)(image, columns, rows, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -11445,11 +11630,11 @@ Image_selective_blur_channel(int argc, VALUE *argv, VALUE self) { #if defined(HAVE_SELECTIVEBLURIMAGECHANNEL) Image *image, *new_image; double radius, sigma, threshold; - ExceptionInfo exception; + ExceptionInfo *exception; ChannelType channels; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); if (argc > 3) @@ -11465,14 +11650,14 @@ // threshold is either a floating-point number or a string in the form "NN%". // Either way it's supposed to represent a percentage of the QuantumRange. threshold = rm_percentage(argv[2],1.0) * QuantumRange; - GetExceptionInfo(&exception); - new_image = SelectiveBlurImageChannel(image, channels, radius, sigma, threshold, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + exception = AcquireExceptionInfo(); + new_image = SelectiveBlurImageChannel(image, channels, radius, sigma, threshold, exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); #else @@ -11534,25 +11719,25 @@ VALUE Image_separate(int argc, VALUE *argv, VALUE self) { Image *image, *new_images; ChannelType channels = 0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); // All arguments are ChannelType enums if (argc > 0) { raise_ChannelType_error(argv[argc-1]); } - GetExceptionInfo(&exception); - new_images = SeparateImages(image, channels, &exception); - rm_check_exception(&exception, new_images, DestroyOnError); - DestroyExceptionInfo(&exception); + exception = AcquireExceptionInfo(); + new_images = SeparateImages(image, channels, exception); + rm_check_exception(exception, new_images, DestroyOnError); + DestroyExceptionInfo(exception); rm_ensure_result(new_images); return rm_imagelist_from_images(new_images); } @@ -11575,11 +11760,11 @@ VALUE Image_sepiatone(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double threshold = (double) QuantumRange; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -11590,15 +11775,15 @@ break; default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); } - GetExceptionInfo(&exception); - new_image = SepiaToneImage(image, threshold, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = SepiaToneImage(image, threshold, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -11774,11 +11959,11 @@ Image_shade(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double azimuth = 30.0, elevation = 30.0; unsigned int shading=MagickFalse; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 3: @@ -11792,15 +11977,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc); break; } - GetExceptionInfo(&exception); - new_image = ShadeImage(image, shading, azimuth, elevation, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ShadeImage(image, shading, azimuth, elevation, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -11837,11 +12022,11 @@ Image *image, *new_image; double opacity = 100.0; double sigma = 4.0; long x_offset = 4L; long y_offset = 4L; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 4: @@ -11864,15 +12049,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc); break; } - GetExceptionInfo(&exception); - new_image = ShadowImage(image, opacity, sigma, x_offset, y_offset, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ShadowImage(image, opacity, sigma, x_offset, y_offset, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -11925,11 +12110,11 @@ VALUE Image_sharpen_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; ChannelType channels; - ExceptionInfo exception; + ExceptionInfo *exception; double radius = 0.0, sigma = 1.0; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -11948,15 +12133,15 @@ raise_ChannelType_error(argv[argc-1]); } new_image = rm_clone_image(image); - GetExceptionInfo(&exception); - (void) SharpenImageChannel(new_image, channels, radius, sigma, &exception); + exception = AcquireExceptionInfo(); + (void) SharpenImageChannel(new_image, channels, radius, sigma, exception); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12017,19 +12202,19 @@ */ VALUE Image_shear(VALUE self, VALUE x_shear, VALUE y_shear) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -12324,11 +12509,11 @@ SparseColorMethod method; int n, exp; double * volatile args; ChannelType channels; MagickPixelPacket pp; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); n = argc; channels = extract_channels(&argc, argv); @@ -12385,12 +12570,12 @@ { args[x++] = pp.opacity / QuantumRange; } } - GetExceptionInfo(&exception); - new_image = SparseColorImage(image, channels, method, nargs, args, &exception); + exception = AcquireExceptionInfo(); + new_image = SparseColorImage(image, channels, method, nargs, args, exception); xfree(args); CHECK_EXCEPTION(); rm_ensure_result(new_image); return rm_image_new(new_image); @@ -12428,11 +12613,11 @@ Image_splice(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; PixelPacket color, old_color; RectangleInfo rectangle; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -12452,21 +12637,21 @@ rectangle.x = NUM2LONG(argv[0]); rectangle.y = NUM2LONG(argv[1]); rectangle.width = NUM2ULONG(argv[2]); rectangle.height = NUM2ULONG(argv[3]); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // Swap in color for the duration of this call. old_color = image->background_color; image->background_color = color; - new_image = SpliceImage(image, &rectangle, &exception); + new_image = SpliceImage(image, &rectangle, exception); image->background_color = old_color; - rm_check_exception(&exception, new_image, DestroyOnError); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -12490,11 +12675,11 @@ VALUE Image_spread(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double radius = 3.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 1: @@ -12504,16 +12689,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } - GetExceptionInfo(&exception); - new_image = SpreadImage(image, radius, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = SpreadImage(image, radius, exception); + rm_check_exception(exception, new_image, DestroyOnError); rm_ensure_result(new_image); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12536,24 +12721,24 @@ Image_stegano(VALUE self, VALUE watermark_image, VALUE offset) { Image *image, *new_image; volatile VALUE wm_image; Image *watermark; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); wm_image = rm_cur_image(watermark_image); watermark = rm_check_destroyed(wm_image); image->offset = NUM2LONG(offset); - GetExceptionInfo(&exception); - new_image = SteganoImage(image, watermark, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = SteganoImage(image, watermark, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -12575,22 +12760,22 @@ Image_stereo(VALUE self, VALUE offset_image_arg) { Image *image, *new_image; volatile VALUE offset_image; Image *offset; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); offset_image = rm_cur_image(offset_image_arg); offset = rm_check_destroyed(offset_image); - GetExceptionInfo(&exception); - new_image = StereoImage(image, offset, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = StereoImage(image, offset, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -12713,16 +12898,16 @@ // Get a pointer to the pixels. Replace the values with the PixelPackets // from the pixels argument. { #if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_GETAUTHENTICPIXELS) - ExceptionInfo exception; - GetExceptionInfo(&exception); + ExceptionInfo *exception; + exception = AcquireExceptionInfo(); #endif #if defined(HAVE_GETAUTHENTICPIXELS) - pixels = GetAuthenticPixels(image, x, y, cols, rows, &exception); + pixels = GetAuthenticPixels(image, x, y, cols, rows, exception); CHECK_EXCEPTION() #else pixels = GetImagePixels(image, x, y, cols, rows); rm_check_image_exception(image, RetainOnError); #endif @@ -12734,20 +12919,20 @@ new_pixel = rb_ary_entry(new_pixels, n); Data_Get_Struct(new_pixel, Pixel, pixel); pixels[n] = *pixel; } #if defined(HAVE_SYNCAUTHENTICPIXELS) - SyncAuthenticPixels(image, &exception); + SyncAuthenticPixels(image, exception); CHECK_EXCEPTION() #else SyncImagePixels(image); rm_check_image_exception(image, RetainOnError); #endif } #if defined(HAVE_SYNCAUTHENTICPIXELS) || defined(HAVE_GETAUTHENTICPIXELS) - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); #endif } return self; } @@ -12786,19 +12971,19 @@ */ VALUE Image_swirl(VALUE self, VALUE degrees) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - new_image = SwirlImage(image, NUM2DBL(degrees), &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = SwirlImage(image, NUM2DBL(degrees), exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -13027,11 +13212,11 @@ thumbnail(int bang, int argc, VALUE *argv, VALUE self) { Image *image, *new_image; unsigned long columns, rows; double scale_arg, drows, dcols; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); switch (argc) { @@ -13061,15 +13246,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } - GetExceptionInfo(&exception); - new_image = ThumbnailImage(image, columns, rows, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = ThumbnailImage(image, columns, rows, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) { @@ -13188,11 +13373,11 @@ Image *image, *new_image; Pixel *tint; double red_pct_opaque, green_pct_opaque, blue_pct_opaque; double alpha_pct_opaque = 1.0; char opacity[50]; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { @@ -13234,16 +13419,16 @@ #endif "%g,%g,%g,%g", red_pct_opaque*100.0, green_pct_opaque*100.0 , blue_pct_opaque*100.0, alpha_pct_opaque*100.0); Data_Get_Struct(argv[0], Pixel, tint); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = TintImage(image, opacity, *tint, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = TintImage(image, opacity, *tint, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -13270,11 +13455,11 @@ const MagickInfo *magick_info; volatile VALUE info_obj; volatile VALUE blob_str; void *blob = NULL; size_t length = 2048; // Do what Magick++ does - ExceptionInfo exception; + ExceptionInfo *exception; // The user can specify the depth (8 or 16, if the format supports // both) and the image format by setting the depth and format // values in the info parm block. info_obj = rm_info_new(); @@ -13287,25 +13472,25 @@ { (void) SetImageDepth(image, info->depth); rm_check_image_exception(image, RetainOnError); } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); if (*info->magick) { - (void) SetImageInfo(info, MagickTrue, &exception); + (void) SetImageInfo(info, MagickTrue, exception); CHECK_EXCEPTION() if (*info->magick == '\0') { return Qnil; } strncpy(image->magick, info->magick, sizeof(info->magick)-1); } // Fix #2844 - libjpeg exits when image is 0x0 - magick_info = GetMagickInfo(image->magick, &exception); + magick_info = GetMagickInfo(image->magick, exception); CHECK_EXCEPTION() if (magick_info) { if ( (!rm_strcasecmp(magick_info->name, "JPEG") @@ -13317,14 +13502,14 @@ } } rm_sync_image_options(image, info); - blob = ImageToBlob(info, image, &length, &exception); + blob = ImageToBlob(info, image, &length, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); if (length == 0 || !blob) { return Qnil; } @@ -13354,26 +13539,26 @@ VALUE Image_to_color(VALUE self, VALUE pixel_arg) { Image *image; Pixel *pixel; - ExceptionInfo exception; + ExceptionInfo *exception; char name[MaxTextExtent]; image = rm_check_destroyed(self); Data_Get_Struct(pixel_arg, Pixel, pixel); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); // QueryColorname returns False if the color represented by the PixelPacket // doesn't have a "real" name, just a sequence of hex digits. We don't care // about that. name[0] = '\0'; - (void) QueryColorname(image, pixel, AllCompliance, name, &exception); + (void) QueryColorname(image, pixel, AllCompliance, name, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rb_str_new2(name); } @@ -13681,11 +13866,11 @@ */ static VALUE trimmer(int bang, int argc, VALUE *argv, VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; int reset_page = 0; switch (argc) { case 1: @@ -13697,15 +13882,15 @@ break; } Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); - new_image = TrimImage(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = TrimImage(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (reset_page) { @@ -13820,18 +14005,18 @@ */ VALUE Image_image_type(VALUE self) { Image *image; ImageType type; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); - type = GetImageType(image, &exception); + exception = AcquireExceptionInfo(); + type = GetImageType(image, exception); CHECK_EXCEPTION() - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return ImageType_new(type); } @@ -13903,18 +14088,18 @@ */ VALUE Image_unique_colors(VALUE self) { Image *image, *new_image; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = UniqueImageColors(image, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + new_image = UniqueImageColors(image, exception); + rm_check_exception(exception, new_image, DestroyOnError); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -14072,21 +14257,21 @@ VALUE Image_unsharp_mask(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double radius = 0.0, sigma = 1.0, amount = 1.0, threshold = 0.05; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold); - GetExceptionInfo(&exception); - new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -14121,27 +14306,27 @@ Image_unsharp_mask_channel(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; ChannelType channels; double radius = 0.0, sigma = 1.0, amount = 1.0, threshold = 0.05; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); if (argc > 4) { raise_ChannelType_error(argv[argc-1]); } unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); new_image = UnsharpMaskImageChannel(image, channels, radius, sigma, amount - , threshold, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + , threshold, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -14173,11 +14358,11 @@ Image_vignette(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; long horz_radius, vert_radius; double radius = 0.0, sigma = 10.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); horz_radius = (long)(image->columns * 0.10 + 0.5); vert_radius = (long)(image->rows * 0.10 + 0.5); @@ -14197,16 +14382,16 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc); break; } - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = VignetteImage(image, radius, sigma, horz_radius, vert_radius, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + new_image = VignetteImage(image, radius, sigma, horz_radius, vert_radius, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -14356,11 +14541,11 @@ VALUE Image_wave(int argc, VALUE *argv, VALUE self) { Image *image, *new_image; double amplitude = 25.0, wavelength = 150.0; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 2: @@ -14372,15 +14557,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 2)", argc); break; } - GetExceptionInfo(&exception); - new_image = WaveImage(image, amplitude, wavelength, &exception); - rm_check_exception(&exception, new_image, DestroyOnError); + exception = AcquireExceptionInfo(); + new_image = WaveImage(image, amplitude, wavelength, exception); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -14423,11 +14608,11 @@ long x, y, max_rows; double initial = 0.5; double rate = 1.0; double opacity, step; const char *func; - ExceptionInfo exception; + ExceptionInfo *exception; image = rm_check_destroyed(self); switch (argc) { case 2: @@ -14466,20 +14651,20 @@ max_rows = (long)image->rows; step = 0.0; } - GetExceptionInfo(&exception); - flip_image = FlipImage(image, &exception); + exception = AcquireExceptionInfo(); + flip_image = FlipImage(image, exception); CHECK_EXCEPTION(); geometry.x = 0; geometry.y = 0; geometry.width = image->columns; geometry.height = max_rows; - reflection = CropImage(flip_image, &geometry, &exception); + reflection = CropImage(flip_image, &geometry, exception); DestroyImage(flip_image); CHECK_EXCEPTION(); (void) SetImageStorageClass(reflection, DirectClass); @@ -14496,27 +14681,27 @@ opacity = TransparentOpacity; } #if defined(HAVE_GETVIRTUALPIXELS) - p = GetVirtualPixels(reflection, 0, y, image->columns, 1, &exception); + p = GetVirtualPixels(reflection, 0, y, image->columns, 1, exception); #else - p = AcquireImagePixels(reflection, 0, y, image->columns, 1, &exception); + p = AcquireImagePixels(reflection, 0, y, image->columns, 1, exception); #endif - rm_check_exception(&exception, reflection, DestroyOnError); + rm_check_exception(exception, reflection, DestroyOnError); if (!p) { func = "AcquireImagePixels"; goto error; } #if defined(HAVE_QUEUEAUTHENTICPIXELS) - q = QueueAuthenticPixels(reflection, 0, y, image->columns, 1, &exception); + q = QueueAuthenticPixels(reflection, 0, y, image->columns, 1, exception); #else q = SetImagePixels(reflection, 0, y, image->columns, 1); #endif - rm_check_exception(&exception, reflection, DestroyOnError); + rm_check_exception(exception, reflection, DestroyOnError); if (!q) { func = "SetImagePixels"; goto error; } @@ -14528,26 +14713,26 @@ q[x].opacity = max(q[x].opacity, (Quantum)opacity); } #if defined(HAVE_SYNCAUTHENTICPIXELS) - SyncAuthenticPixels(reflection, &exception); - rm_check_exception(&exception, reflection, DestroyOnError); + SyncAuthenticPixels(reflection, exception); + rm_check_exception(exception, reflection, DestroyOnError); #else SyncImagePixels(reflection); rm_check_image_exception(reflection, DestroyOnError); #endif opacity += step; } - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); return rm_image_new(reflection); error: - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); (void) DestroyImage(reflection); rb_raise(rb_eRuntimeError, "%s failed on row %lu", func, y); return(VALUE)0; } @@ -14589,11 +14774,11 @@ void add_format_prefix(Info *info, VALUE file) { char *filename; long filename_l; const MagickInfo *magick_info, *magick_info2; - ExceptionInfo exception; + ExceptionInfo *exception; char magic[MaxTextExtent]; size_t magic_l; size_t prefix_l; char *p; @@ -14617,23 +14802,23 @@ { memset(magic, '\0', sizeof(magic)); magic_l = p - filename; memcpy(magic, filename, magic_l); - GetExceptionInfo(&exception); - magick_info = GetMagickInfo(magic, &exception); + exception = AcquireExceptionInfo(); + magick_info = GetMagickInfo(magic, exception); CHECK_EXCEPTION(); - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); if (magick_info && magick_info->module) { // We have to compare the module names because some formats have // more than one name. JPG and JPEG, for example. - GetExceptionInfo(&exception); - magick_info2 = GetMagickInfo(info->magick, &exception); + exception = AcquireExceptionInfo(); + magick_info2 = GetMagickInfo(info->magick, exception); CHECK_EXCEPTION(); - DestroyExceptionInfo(&exception); + DestroyExceptionInfo(exception); if (magick_info2->module && strcmp(magick_info->module, magick_info2->module) != 0) { rb_raise(rb_eRuntimeError , "filename prefix `%s' conflicts with output format `%s'" @@ -14692,12 +14877,18 @@ OpenFile *fptr; // Ensure file is open - raise error if not GetOpenFile(file, fptr); rb_io_check_writable(fptr); +#if defined(_WIN32) + add_format_prefix(info, fptr->pathv); + strcpy(image->filename, info->filename); + SetImageInfoFile(info, NULL); +#else SetImageInfoFile(info, GetWriteFile(fptr)); memset(image->filename, 0, sizeof(image->filename)); +#endif } else { add_format_prefix(info, file); strcpy(image->filename, info->filename); @@ -14928,26 +15119,26 @@ static VALUE xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, xformer_t xformer) { Image *image, *new_image; RectangleInfo rect; - ExceptionInfo exception; + ExceptionInfo *exception; Data_Get_Struct(self, Image, image); rect.x = NUM2LONG(x); rect.y = NUM2LONG(y); rect.width = NUM2ULONG(width); rect.height = NUM2ULONG(height); - GetExceptionInfo(&exception); + exception = AcquireExceptionInfo(); - new_image = (xformer)(image, &rect, &exception); + new_image = (xformer)(image, &rect, exception); // An exception can occur in either the old or the new images rm_check_image_exception(image, RetainOnError); - rm_check_exception(&exception, new_image, DestroyOnError); + rm_check_exception(exception, new_image, DestroyOnError); - (void) DestroyExceptionInfo(&exception); + (void) DestroyExceptionInfo(exception); rm_ensure_result(new_image); if (bang) {