ext/RMagick/rmimage.c in rmagick-1.11.0 vs ext/RMagick/rmimage.c in rmagick-1.11.1

- old
+ new

@@ -1,6 +1,6 @@ -/* $Id: rmimage.c,v 1.145 2006/05/07 21:41:12 rmagick Exp $ */ +/* $Id: rmimage.c,v 1.146 2006/05/27 21:05:59 rmagick Exp $ */ /*============================================================================\ | Copyright (C) 2006 by Timothy P. Hunter | Name: rmimage.c | Author: Tim Hunter | Purpose: Image class method definitions for RMagick @@ -68,10 +68,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = AdaptiveThresholdImage(image, width, height, offset, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -92,10 +95,13 @@ VALUE_TO_ENUM(noise, noise_type, NoiseType); GetExceptionInfo(&exception); new_image = AddNoiseImage(image, noise_type, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -131,10 +137,13 @@ channels &= ~OpacityChannel; GetExceptionInfo(&exception); new_image = AddNoiseImageChannel(image, channels, noise_type, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else @@ -161,10 +170,13 @@ AffineMatrix_to_AffineMatrix(&matrix, affine); GetExceptionInfo(&exception); new_image = AffineTransformImage(image, &matrix, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -447,10 +459,13 @@ } GetExceptionInfo(&exception); new_image = BlurImageChannel(image, channels, radius, sigma, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -499,10 +514,13 @@ Color_to_PixelPacket(&image->border_color, color); GetExceptionInfo(&exception); new_image = BorderImage(image, &rect, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { new_image->border_color = old_border; @@ -580,10 +598,12 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); box = GetImageBoundingBox(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return Rectangle_from_RectangleInfo(&box); } /* @@ -639,11 +659,10 @@ // If an error occurs, IM will call our error handler and we raise an exception. image = XImportImage(image_info, &ximage_info); rm_check_image_exception(image, DestroyOnError); rm_ensure_result(image); - return rm_image_new(image); #else rm_not_implemented(); return (VALUE)0; #endif @@ -784,10 +803,12 @@ GetExceptionInfo(&exception); channel_depth = GetImageChannelDepth(image, channels, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return ULONG2NUM(channel_depth); #else rm_not_implemented(); return (VALUE)0; #endif @@ -826,10 +847,12 @@ GetExceptionInfo(&exception); (void) GetImageChannelExtrema(image, channels, &min, &max, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + ary = rb_ary_new2(2); rb_ary_store(ary, 0, ULONG2NUM(min)); rb_ary_store(ary, 1, ULONG2NUM(max)); return ary; @@ -863,10 +886,11 @@ GetExceptionInfo(&exception); (void) GetImageStatistics(image, &stats, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); ary = rb_ary_new2(2); switch(channel) { case RedChannel: @@ -931,10 +955,12 @@ GetExceptionInfo(&exception); (void) GetImageChannelMean(image, channels, &mean, &stddev, &exception); CHECK_EXCEPTION() + 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)); return ary; @@ -968,10 +994,12 @@ GetExceptionInfo(&exception); (void) GetImageStatistics(image, &stats, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + ary = rb_ary_new2(2); switch(channel) { case RedChannel: case CyanChannel: @@ -1157,10 +1185,12 @@ GetExceptionInfo(&exception); histogram = GetColorHistogram(image, &colors, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + hash = rb_hash_new(); for (x = 0; x < colors; x++) { pixel = Pixel_from_PixelPacket(&histogram[x].pixel); rb_hash_aset(hash, pixel, ULONG2NUM(histogram[x].count)); @@ -1210,10 +1240,11 @@ { RelinquishMagickMemory(histogram); rm_check_exception(&exception, dc_copy, DestroyOnError); } + DestroyExceptionInfo(&exception); hash = rb_hash_new(); for (x = 0; x < colors; x++) { pixel = Pixel_from_PixelPacket(&histogram[x].pixel); @@ -1517,10 +1548,13 @@ } GetExceptionInfo(&exception); new_image = ColorizeImage(image, opacity, target, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -1731,13 +1765,15 @@ , channels , metric_type , &distortion , &exception); rm_check_exception(&exception, difference_image, DestroyOnError); - rm_ensure_result(difference_image); + DestroyExceptionInfo(&exception); + rm_ensure_result(difference_image); + ary = rb_ary_new2(2); rb_ary_store(ary, 0, rm_image_new(difference_image)); rb_ary_store(ary, 1, rb_float_new(distortion)); return ary; @@ -2132,10 +2168,11 @@ #else image = ConstituteImage(width, height, map, stg_type, (void *)pixels.v, &exception); rm_check_exception(&exception, image, DestroyOnError); #endif + DestroyExceptionInfo(&exception); DestroyConstitute(); xfree((void *)pixels.v); return rm_image_new(image); @@ -2268,25 +2305,29 @@ ExceptionInfo exception; Data_Get_Struct(self, Image, image); order = NUM2UINT(order_arg); - kernel = (volatile double *)ALLOC_N(double, order*order); rm_check_ary_len(kernel_arg, order*order); // Convert the kernel array argument to an array of doubles + + kernel = (volatile double *)ALLOC_N(double, order*order); for (x = 0; x < order*order; x++) { kernel[x] = NUM2DBL(rb_ary_entry(kernel_arg, x)); } GetExceptionInfo(&exception); new_image = ConvolveImage(image, order, (double *)kernel, &exception); xfree((double *)kernel); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -2339,10 +2380,13 @@ GetExceptionInfo(&exception); new_image = ConvolveImageChannel(image, channels, order, (double *)kernel, &exception); xfree((double *)kernel); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -2403,15 +2447,13 @@ */ VALUE Image_cycle_colormap(VALUE self, VALUE amount) { Image *image, *new_image; - ExceptionInfo exception; int amt; Data_Get_Struct(self, Image, image); - GetExceptionInfo(&exception); new_image = rm_clone_image(image); amt = NUM2INT(amount); (void) CycleColormapImage(new_image, amt); // No need to check for an error @@ -2522,10 +2564,12 @@ GetExceptionInfo(&exception); depth = GetImageDepth(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return INT2FIX(depth); } DEF_ATTR_ACCESSOR(Image, delay, ulong) @@ -2546,10 +2590,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = DespeckleImage(image, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -2657,10 +2704,12 @@ goto exit; } CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + // Convert the pixel data to the appropriate Ruby type if (stg_type == FIX_STG_TYPE) { for (n = 0; n < npixels; n++) { @@ -2765,10 +2814,12 @@ GetExceptionInfo(&exception); (void) GetImageChannelDistortion(image, reconstruct, channels , metric, &distortion, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return rb_float_new(distortion); #else rm_not_implemented(); return (VALUE)0; #endif @@ -2805,10 +2856,12 @@ // Free ImageInfo first - error handling may raise an exception DestroyImageInfo(info); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + if (!blob) { rb_raise(rb_eNoMemError, "not enough memory to continue"); } @@ -2919,10 +2972,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = EdgeImage(image, radius, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -2961,10 +3017,13 @@ } GetExceptionInfo(&exception); new_image = (effector)(image, radius, sigma, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -3023,10 +3082,13 @@ GetExceptionInfo(&exception); new_image = EnhanceImage(image, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -3045,10 +3107,12 @@ new_image = rm_clone_image(image); (void) EqualizeImage(new_image); rm_check_image_exception(new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); } /* Method: Image#erase! @@ -3137,14 +3201,17 @@ okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, IntegerPixel, (void *)pixels, &exception); if (!okay) { xfree((unsigned int *)pixels); CHECK_EXCEPTION() + // Should never get here... rb_raise(rb_eStandardError, "ExportImagePixels failed with no explanation."); } + DestroyExceptionInfo(&exception); + ary = rb_ary_new2(npixels); for (n = 0; n < npixels; n++) { Quantum p = ScaleLongToQuantum(pixels[n]); rb_ary_push(ary, UINT2NUM(p)); @@ -3258,14 +3325,17 @@ if (!okay) { // Let GC have the string buffer. rb_str_resize(string, 0); CHECK_EXCEPTION() + // Should never get here... rb_raise(rb_eStandardError, "ExportImagePixels failed with no explanation."); } + DestroyExceptionInfo(&exception); + return string; #else rm_not_implemented(); return (VALUE)0; @@ -3366,10 +3436,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = (flipflopper)(image, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -3460,10 +3533,12 @@ mgk = STRING_PTR(magick); m = GetMagickInfo(mgk, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + if (!m) { rb_raise(rb_eArgError, "unknown format: %s", mgk); } @@ -3541,10 +3616,13 @@ } GetExceptionInfo(&exception); new_image = FrameImage(image, &frame_info, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -3570,10 +3648,13 @@ Data_Get_Struct(info_obj, Info, info); GetExceptionInfo(&exception); images = BlobToImage(info, blob, (size_t)length, &exception); rm_check_exception(&exception, images, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(images); return array_from_images(images); } @@ -3742,10 +3823,12 @@ Data_Get_Struct(self, Image, image); new_image = GaussianBlurImageChannel(image, channels, radius, sigma, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; @@ -3830,10 +3913,12 @@ // to change the pixels but I don't want to make "pixels" const. GetExceptionInfo(&exception); pixels = (PixelPacket *)AcquireImagePixels(image, x, y, columns, rows, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + // If the function failed, return a 0-length array. if (!pixels) { return rb_ary_new(); } @@ -3870,10 +3955,12 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); pixel = AcquireOnePixel(image, NUM2LONG(x), NUM2LONG(y), &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return Pixel_from_PixelPacket(&pixel); } #endif /* @@ -3892,10 +3979,12 @@ GetExceptionInfo(&exception); r = IsGrayImage(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return r ? Qtrue : Qfalse; } /* Method: Image#grayscale_pseudo_class @@ -3961,10 +4050,12 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = ImplodeImage(image, amount, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -4633,10 +4724,13 @@ length -= offsetof(DumpedImage,magick) + mi.len; image = BlobToImage(info, blob, (size_t) length, &exception); DestroyImageInfo(info); rm_check_exception(&exception, image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(image); return rm_image_new(image); } @@ -4659,10 +4753,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = (magnifier)(image, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -4834,10 +4931,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = MedianFilterImage(image, radius, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -4988,10 +5088,12 @@ GetExceptionInfo(&exception); r = IsMonochromeImage(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return r ? Qtrue : Qfalse; } /* Method: Image#montage, montage= @@ -5051,10 +5153,13 @@ } GetExceptionInfo(&exception); new_image = MotionBlurImage(image, radius, sigma, angle, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5383,10 +5488,12 @@ GetExceptionInfo(&exception); n = (unsigned long) GetNumberColors(image, NULL, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return ULONG2NUM(n); } DEF_ATTR_ACCESSOR(Image, offset, long) @@ -5414,10 +5521,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = OilPaintImage(image, radius, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -5466,10 +5576,12 @@ GetExceptionInfo(&exception); r = IsOpaqueImage(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return r ? Qtrue : Qfalse; } /* Method: Image#ordered_dither(order=2) @@ -5520,10 +5632,12 @@ #else (void) RandomChannelThresholdImage(new_image, "all", thresholds, &exception); #endif rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); } /* Method: Image#orientation @@ -5588,10 +5702,12 @@ GetExceptionInfo(&exception); r = IsPaletteImage(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return r ? Qtrue : Qfalse; } /* Method: Image.ping(file) @@ -5651,10 +5767,12 @@ { GetExceptionInfo(&exception); old_color = *AcquireImagePixels(image, x, y, 1, 1, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + // PseudoClass if (image->storage_class == PseudoClass) { IndexPacket *indexes = GetIndexes(image); old_color = image->colormap[*indexes]; @@ -5803,10 +5921,13 @@ VALUE_TO_ENUM(preview, preview_type, PreviewType); Data_Get_Struct(self, Image, image); new_image = PreviewImage(image, preview_type, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -5967,10 +6088,12 @@ GetExceptionInfo(&exception); (void) QuantumOperatorImage(image, channel, qop, rvalue, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return self; #elif defined(HAVE_EVALUATEIMAGECHANNEL) Image *image; QuantumExpressionOperator operator; @@ -6040,10 +6163,12 @@ GetExceptionInfo(&exception); (void) EvaluateImageChannel(image, channel, operator, rvalue, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return self; #else rm_not_implemented(); return (VALUE)0; @@ -6109,10 +6234,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = RadialBlurImage(image, NUM2DBL(angle), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -6159,10 +6287,12 @@ GetExceptionInfo(&exception); (void) RandomChannelThresholdImage(new_image, channel, thresholds, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; #endif @@ -6212,10 +6342,12 @@ GetExceptionInfo(&exception); (void) RandomThresholdImageChannel(new_image, channels, thresholds, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; @@ -6251,11 +6383,11 @@ case 1: rect.width = NUM2ULONG(argv[0]); case 0: break; default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)"); + rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc); break; } Data_Get_Struct(self, Image, image); @@ -6336,10 +6468,12 @@ GetExceptionInfo(&exception); images = (reader)(info, &exception); rm_check_exception(&exception, images, DestroyOnError); + DestroyExceptionInfo(&exception); + return array_from_images(images); } /* @@ -6395,10 +6529,12 @@ images = BlobToImage(info, blob, blob_l, &exception); magick_free((void *)blob); rm_check_exception(&exception, images, DestroyOnError); + DestroyExceptionInfo(&exception); + return array_from_images(images); } /* @@ -6441,10 +6577,12 @@ GetExceptionInfo(&exception); new_image = ReduceNoiseImage(image, NUM2DBL(radius), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); } /* Method: Image#rendering_intent= @@ -6537,10 +6675,13 @@ } GetExceptionInfo(&exception); new_image = ResizeImage(image, columns, rows, filter, blur, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -6577,10 +6718,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = RollImage(image, NUM2LONG(x_offset), NUM2LONG(y_offset), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -6600,10 +6744,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = RotateImage(image, NUM2DBL(degrees), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -6715,10 +6862,13 @@ } GetExceptionInfo(&exception); new_image = (scaler)(image, columns, rows, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -6786,10 +6936,13 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); } new_image = SepiaToneImage(image, threshold, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -6970,10 +7123,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = ShadeImage(image, shading, azimuth, elevation, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7026,10 +7182,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = ShadowImage(image, opacity, sigma, x_offset, y_offset, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -7085,10 +7244,12 @@ GetExceptionInfo(&exception); (void) SharpenImageChannel(new_image, channels, radius, sigma, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); #else rm_not_implemented(); return (VALUE)0; #endif @@ -7142,10 +7303,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = ShearImage(image, NUM2DBL(x_shear), NUM2DBL(y_shear), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7345,10 +7509,13 @@ image->background_color = color; new_image = SpliceImage(image, &rectangle, &exception); image->background_color = old_color; rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else @@ -7385,10 +7552,12 @@ new_image = SpreadImage(image, radius, &exception); rm_check_exception(&exception, new_image, DestroyOnError); rm_ensure_result(new_image); + DestroyExceptionInfo(&exception); + return rm_image_new(new_image); } DEF_ATTR_ACCESSOR(Image, start_loop, bool) @@ -7409,10 +7578,12 @@ GetExceptionInfo(&exception); (void) GetImageStatistics(image, &stats, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return Statistics_new(&stats); #else rm_not_implemented(); return (VALUE)0; #endif @@ -7446,10 +7617,13 @@ image->offset = NUM2LONG(offset); GetExceptionInfo(&exception); new_image = SteganoImage(image, watermark, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7477,10 +7651,13 @@ Data_Get_Struct(offset_image, Image, offset); GetExceptionInfo(&exception); new_image = StereoImage(image, offset, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7631,10 +7808,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = SwirlImage(image, NUM2DBL(degrees), &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -7837,10 +8017,13 @@ } GetExceptionInfo(&exception); new_image = ThumbnailImage(image, columns, rows, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -8001,10 +8184,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = TintImage(image, opacity, *tint, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -8077,10 +8263,12 @@ } blob = ImageToBlob(info, image, &length, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + if (length == 0 || !blob) { return Qnil; } @@ -8115,10 +8303,12 @@ name[0] = '\0'; (void) QueryColorname(image, pixel, AllCompliance, name, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return rb_str_new2(name); } /* @@ -8196,10 +8386,13 @@ geometry = GetImageBoundingBox(image, &exception); CHECK_EXCEPTION() new_image = CropImage(image, &geometry, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image; @@ -8258,10 +8451,12 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); type = GetImageType(image, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + return ImageType_new(type); } /* @@ -8359,10 +8554,13 @@ 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); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -8392,10 +8590,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = UnsharpMaskImageChannel(image, channels, radius, sigma, amount , threshold, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else rm_not_implemented(); @@ -8442,10 +8643,13 @@ GetExceptionInfo(&exception); new_image = VignetteImage(image, radius, sigma, horz_radius, vert_radius, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); #else @@ -8519,10 +8723,13 @@ Data_Get_Struct(self, Image, image); GetExceptionInfo(&exception); new_image = WaveImage(image, amplitude, wavelength, &exception); rm_check_exception(&exception, new_image, DestroyOnError); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); return rm_image_new(new_image); } @@ -8589,10 +8796,12 @@ GetExceptionInfo(&exception); (void) SetImageInfo(info, True, &exception); CHECK_EXCEPTION() + DestroyExceptionInfo(&exception); + if (*info->magick == '\0') { return Qnil; } info->file = NULL; @@ -8808,9 +9017,12 @@ 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); + + DestroyExceptionInfo(&exception); + rm_ensure_result(new_image); if (bang) { DATA_PTR(self) = new_image;