ext/RMagick/rmimage.c in rmagick-5.0.0 vs ext/RMagick/rmimage.c in rmagick-5.1.0

- old
+ new

@@ -27,49 +27,280 @@ #ifndef magick_module #define magick_module module #endif -/** Method that effects an image */ -typedef Image *(effector_t)(const Image *, const double, const double, ExceptionInfo *); -/** Method that flips an image */ -typedef Image *(flipper_t)(const Image *, ExceptionInfo *); -/** 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 size_t, const size_t, ExceptionInfo *); -/** Method that computes threshold on an image */ -#if defined(IMAGEMAGICK_7) - typedef MagickBooleanType (auto_channel_t)(Image *, ExceptionInfo *exception); - typedef Image *(channel_method_t)(const Image *, const double, const double, ExceptionInfo *); - typedef MagickBooleanType (thresholder_t)(Image *, const char *, ExceptionInfo *); -#else - typedef MagickBooleanType (auto_channel_t)(Image *, const ChannelType); - typedef Image *(channel_method_t)(const Image *, const ChannelType, const double, const double, ExceptionInfo *); - typedef MagickBooleanType (thresholder_t)(Image *, const char *); - #define IsEquivalentImage IsImageSimilar - #define OrderedDitherImage OrderedPosterizeImage -#endif -/** Method that transforms an image */ -typedef Image *(xformer_t)(const Image *, const RectangleInfo *, ExceptionInfo *); - static VALUE cropper(int, int, VALUE *, VALUE); -static VALUE effect_image(VALUE, int, VALUE *, effector_t); -static VALUE flipflop(int, VALUE, flipper_t); -static VALUE rd_image(VALUE, VALUE, reader_t); +static VALUE effect_image(VALUE, int, VALUE *, gvl_function_t); +static VALUE flipflop(int, VALUE, gvl_function_t); +static VALUE rd_image(VALUE, VALUE, gvl_function_t); static VALUE rotate(int, int, VALUE *, VALUE); -static VALUE scale(int, int, VALUE *, VALUE, scaler_t); -static VALUE threshold_image(int, VALUE *, VALUE, thresholder_t); -static VALUE xform_image(int, VALUE, VALUE, VALUE, VALUE, VALUE, xformer_t); +static VALUE scale(int, int, VALUE *, VALUE, gvl_function_t); +static VALUE threshold_image(int, VALUE *, VALUE, gvl_function_t); +static VALUE xform_image(int, VALUE, VALUE, VALUE, VALUE, VALUE, gvl_function_t); static VALUE array_from_images(Image *); static VALUE file_arg_rescue(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN; +static size_t rm_image_memsize(const void *img); +const rb_data_type_t rm_image_data_type = { + "Magick::Image", + { NULL, rm_image_destroy, rm_image_memsize, }, + 0, 0, + RUBY_TYPED_FROZEN_SHAREABLE, +}; + static const char *BlackPointCompensationKey = "PROFILE:black-point-compensation"; +DEFINE_GVL_STUB4(AdaptiveBlurImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(AdaptiveResizeImage, const Image *, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB4(AdaptiveSharpenImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(AdaptiveThresholdImage, const Image *, const size_t, const size_t, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(AffineTransformImage, const Image *, const AffineMatrix *, ExceptionInfo *); +DEFINE_GVL_STUB2(Base64Decode, const char *, size_t *); +DEFINE_GVL_STUB4(BlobToImage, const ImageInfo *, const void *, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB3(BlueShiftImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(BlurImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(CharcoalImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(ChopImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(ColorMatrixImage, const Image *, const KernelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(CropImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(DecipherImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB3(DeskewImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(DespeckleImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB6(DistortImage, const Image *, DistortMethod, const size_t, const double *, MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB3(EdgeImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(EmbossImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(EncipherImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB2(EnhanceImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(ExcerptImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB9(ExportImagePixels, const Image *, const ssize_t, const ssize_t, const size_t, const size_t, const char *, const StorageType, void *, ExceptionInfo *); +DEFINE_GVL_STUB3(ExtentImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB2(FlipImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(FlopImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(GaussianBlurImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB6(GetAuthenticPixels, Image *, const ssize_t, const ssize_t, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB2(GetImageDepth, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(GetImageHistogram, const Image *, size_t *, ExceptionInfo *); +DEFINE_GVL_STUB3(GetNumberColors, const Image *, FILE *, ExceptionInfo *); +DEFINE_GVL_STUB6(GetVirtualPixels, const Image *, const ssize_t, const ssize_t, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB4(ImageToBlob, const ImageInfo *, Image *, size_t *, ExceptionInfo *); +DEFINE_GVL_STUB6(LiquidRescaleImage, const Image *, const size_t, const size_t, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(MagnifyImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(MinifyImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB5(MotionBlurImage, const Image *, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(PingImage, const ImageInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(PreviewImage, const Image *, const PreviewType, ExceptionInfo *); +DEFINE_GVL_STUB2(ReadImage, const ImageInfo *, ExceptionInfo *); +DEFINE_GVL_STUB4(RollImage, const Image *, const ssize_t, const ssize_t, ExceptionInfo *); +DEFINE_GVL_STUB3(RotateImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(SampleImage, const Image *, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB4(ScaleImage, const Image *, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB3(SepiaToneImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(ShadeImage, const Image *, const MagickBooleanType, const double, const double,ExceptionInfo *); +DEFINE_GVL_STUB6(ShadowImage, const Image *, const double, const double, const ssize_t, const ssize_t, ExceptionInfo *); +DEFINE_GVL_STUB4(SharpenImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(ShaveImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB4(ShearImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(SketchImage, const Image *, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(SpliceImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB5(StatisticImage, const Image *, const StatisticType, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB3(SteganoImage, const Image *, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(StereoImage, const Image *, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(SyncAuthenticPixels, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(ThumbnailImage, const Image *, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB2(TransposeImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(TransverseImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(TrimImage, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(UniqueImageColors, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB6(UnsharpMaskImage, const Image *, const double, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB6(VignetteImage, const Image *, const double, const double, const ssize_t, const ssize_t, ExceptionInfo *); +#if defined(IMAGEMAGICK_7) +DEFINE_GVL_STUB4(AddNoiseImage, const Image *, const NoiseType, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(AutoGammaImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB2(AutoLevelImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(BilevelImage, Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(BlackThresholdImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB4(BorderImage, const Image *, const RectangleInfo *, const CompositeOperator, ExceptionInfo *); +DEFINE_GVL_STUB4(ClutImage, Image *, const Image *, const PixelInterpolateMethod, ExceptionInfo *); +DEFINE_GVL_STUB4(ColorizeImage, const Image *, const char *, const PixelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB5(CompareImages, Image *, const Image *, const MetricType, double *, ExceptionInfo *); +DEFINE_GVL_STUB7(CompositeImage, Image *, const Image *, const CompositeOperator, const MagickBooleanType, const ssize_t, const ssize_t, ExceptionInfo *); +DEFINE_GVL_STUB2(CompressImageColormap, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(ContrastStretchImage, Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(ConvolveImage, const Image *, const KernelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(CycleColormapImage, Image *, const ssize_t, ExceptionInfo *); +DEFINE_GVL_STUB4(DrawAffineImage, Image *, const Image *, const AffineMatrix *, ExceptionInfo *); +DEFINE_GVL_STUB2(EqualizeImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(EvaluateImage, Image *, const MagickEvaluateOperator, const double, ExceptionInfo *); +DEFINE_GVL_STUB7(FloodfillPaintImage, Image *, const DrawInfo *, const PixelInfo *, const ssize_t, const ssize_t, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB4(FrameImage, const Image *, const FrameInfo *, const CompositeOperator, ExceptionInfo *); +DEFINE_GVL_STUB5(FunctionImage, Image *, const MagickFunction, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB3(FxImage, const Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB3(GammaImage, Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(GetImageDistortion, Image *, const Image *, const MetricType, double *, ExceptionInfo *); +DEFINE_GVL_STUB3(GetImageEntropy, const Image *, double *, ExceptionInfo *); +DEFINE_GVL_STUB4(GetImageExtrema, const Image *, size_t *, size_t *, ExceptionInfo *); +DEFINE_GVL_STUB3(GetImageMask, const Image *, const PixelMask, ExceptionInfo *); +DEFINE_GVL_STUB4(GetImageMean, const Image *, double *, double *, ExceptionInfo *); +DEFINE_GVL_STUB4(ImplodeImage, const Image *, const double, const PixelInterpolateMethod, ExceptionInfo *); +DEFINE_GVL_STUB9(ImportImagePixels, Image *, const ssize_t, const ssize_t, const size_t, const size_t, const char *, const StorageType, const void *, ExceptionInfo *); +DEFINE_GVL_STUB5(IsEquivalentImage, const Image *, const Image *, ssize_t *, ssize_t *, ExceptionInfo *); +DEFINE_GVL_STUB5(LevelImage, Image *, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(LevelImageColors, Image *, const PixelInfo *, const PixelInfo *, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB5(LevelizeImage, Image *, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(LinearStretchImage, Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(ModulateImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB5(MorphologyImage, const Image *, const MorphologyMethod, const ssize_t, const KernelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(NegateImage, Image *, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB2(NormalizeImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(OilPaintImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(OpaquePaintImage, Image *, const PixelInfo *, const PixelInfo *, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB3(OrderedDitherImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB6(PolaroidImage, const Image *, const DrawInfo *, const char *, const double, const PixelInterpolateMethod, ExceptionInfo *); +DEFINE_GVL_STUB4(PosterizeImage, Image *, const size_t, const DitherMethod, ExceptionInfo *); +DEFINE_GVL_STUB5(ProfileImage, Image *, const char *, const void *, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB3(QuantizeImage, const QuantizeInfo *, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(RaiseImage, Image *, const RectangleInfo *, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB4(RandomThresholdImage, Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(RemapImage, const QuantizeInfo *, Image *, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB5(ResampleImage, const Image *, const double, const double, const FilterType, ExceptionInfo *); +DEFINE_GVL_STUB5(ResizeImage, const Image *, const size_t, const size_t, const FilterType, ExceptionInfo *); +DEFINE_GVL_STUB6(SegmentImage, Image *, const ColorspaceType, const MagickBooleanType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(SelectiveBlurImage, const Image *, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(SeparateImage, const Image *, const ChannelType, ExceptionInfo *); +DEFINE_GVL_STUB2(SeparateImages, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(SetImageAlphaChannel, Image *, const AlphaChannelOption, ExceptionInfo *); +DEFINE_GVL_STUB2(SetImageBackgroundColor, Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(SetImageDepth, Image *, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB4(SetImageExtent, Image *, const size_t, const size_t, ExceptionInfo *); +DEFINE_GVL_STUB4(SetImageMask, Image *, const PixelMask, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(SetImageStorageClass, Image *, const ClassType, ExceptionInfo *); +DEFINE_GVL_STUB5(SigmoidalContrastImage, Image *, const MagickBooleanType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(SignatureImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(SolarizeImage, Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(SparseColorImage, const Image *, const SparseColorMethod, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB4(SpreadImage, const Image *, const PixelInterpolateMethod, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(SwirlImage, const Image *, double, const PixelInterpolateMethod, ExceptionInfo *); +DEFINE_GVL_STUB2(SyncImage, Image *, ExceptionInfo *); +DEFINE_GVL_STUB4(TintImage, const Image *, const char *, const PixelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(TransformImageColorspace, Image *, const ColorspaceType, ExceptionInfo *); +DEFINE_GVL_STUB5(TransparentPaintImage, Image *, const PixelInfo *, const Quantum, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB6(TransparentPaintImageChroma, Image *, const PixelInfo *, const PixelInfo *, const Quantum, const MagickBooleanType, ExceptionInfo *); +DEFINE_GVL_STUB5(WaveImage, const Image *, const double, const double, const PixelInterpolateMethod, ExceptionInfo *); +DEFINE_GVL_STUB3(WhiteThresholdImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB3(WriteImage, const ImageInfo *, Image *, ExceptionInfo *); +#else +DEFINE_GVL_STUB5(AdaptiveBlurImageChannel, const Image *, const ChannelType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(AdaptiveSharpenImageChannel, const Image *, const ChannelType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(AddNoiseImage, const Image *, const NoiseType, ExceptionInfo *); +DEFINE_GVL_STUB4(AddNoiseImageChannel, const Image *, const ChannelType, const NoiseType, ExceptionInfo *); +DEFINE_GVL_STUB2(AutoGammaImageChannel, Image *, const ChannelType); +DEFINE_GVL_STUB2(AutoLevelImageChannel,Image *, const ChannelType); +DEFINE_GVL_STUB3(BilevelImageChannel, Image *, const ChannelType,const double); +DEFINE_GVL_STUB2(BlackThresholdImage, Image *, const char *); +DEFINE_GVL_STUB5(BlurImageChannel, const Image *, const ChannelType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(BorderImage, const Image *, const RectangleInfo *, ExceptionInfo *); +DEFINE_GVL_STUB3(ClutImageChannel, Image *, const ChannelType, const Image *); +DEFINE_GVL_STUB4(ColorizeImage, const Image *, const char *, const PixelPacket, ExceptionInfo *); +DEFINE_GVL_STUB6(CompareImageChannels, Image *, const Image *, const ChannelType, const MetricType, double *, ExceptionInfo *); +DEFINE_GVL_STUB5(CompositeImage, Image *, const CompositeOperator, const Image *, const ssize_t, const ssize_t); +DEFINE_GVL_STUB6(CompositeImageChannel, Image *, const ChannelType, const CompositeOperator, const Image *, const ssize_t, const ssize_t); +DEFINE_GVL_STUB1(CompressImageColormap, Image *); +DEFINE_GVL_STUB4(ContrastStretchImageChannel, Image *, const ChannelType, const double, const double); +DEFINE_GVL_STUB4(ConvolveImage, const Image *, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB5(ConvolveImageChannel, const Image *, const ChannelType, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB2(CycleColormapImage, Image *, const ssize_t); +DEFINE_GVL_STUB3(DrawAffineImage, Image *, const Image *, const AffineMatrix *); +DEFINE_GVL_STUB1(EqualizeImage, Image *); +DEFINE_GVL_STUB2(EqualizeImageChannel, Image *, const ChannelType); +DEFINE_GVL_STUB5(EvaluateImageChannel, Image *, const ChannelType, const MagickEvaluateOperator, const double, ExceptionInfo *); +DEFINE_GVL_STUB7(FloodfillPaintImage, Image *, const ChannelType, const DrawInfo *, const MagickPixelPacket *, const ssize_t, const ssize_t, const MagickBooleanType); +DEFINE_GVL_STUB3(FrameImage, const Image *, const FrameInfo *, ExceptionInfo *); +DEFINE_GVL_STUB6(FunctionImageChannel, Image *, const ChannelType, const MagickFunction, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB4(FxImageChannel, const Image *, const ChannelType, const char *, ExceptionInfo *); +DEFINE_GVL_STUB3(GammaImageChannel, Image *, const ChannelType, const double); +DEFINE_GVL_STUB5(GaussianBlurImageChannel, const Image *, const ChannelType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(GetImageChannelDepth, const Image *, const ChannelType, ExceptionInfo *); +DEFINE_GVL_STUB6(GetImageChannelDistortion, Image *, const Image *, const ChannelType, const MetricType, double *, ExceptionInfo *); +DEFINE_GVL_STUB5(GetImageChannelExtrema, const Image *, const ChannelType, size_t *, size_t *, ExceptionInfo *); +DEFINE_GVL_STUB5(GetImageChannelMean, const Image *, const ChannelType, double *, double *, ExceptionInfo *); +DEFINE_GVL_STUB2(GetImageClipMask, const Image *, ExceptionInfo *); +DEFINE_GVL_STUB3(ImplodeImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB8(ImportImagePixels, Image *, const ssize_t, const ssize_t, const size_t,const size_t,const char *, const StorageType, const void *); +DEFINE_GVL_STUB5(IsImageSimilar, const Image *, const Image *, ssize_t *, ssize_t *, ExceptionInfo *); +DEFINE_GVL_STUB2(IsImagesEqual, Image *, const Image *); +DEFINE_GVL_STUB5(LevelColorsImageChannel, Image *, const ChannelType, const MagickPixelPacket *, const MagickPixelPacket *, const MagickBooleanType); +DEFINE_GVL_STUB2(LevelImage, Image *, const char *); +DEFINE_GVL_STUB5(LevelImageChannel, Image *, const ChannelType, const double, const double, const double); +DEFINE_GVL_STUB5(LevelizeImageChannel, Image *, const ChannelType, const double, const double, const double); +DEFINE_GVL_STUB3(LinearStretchImage, Image *, const double, const double); +DEFINE_GVL_STUB2(ModulateImage, Image *, const char *); +DEFINE_GVL_STUB6(MorphologyImageChannel, const Image *, const ChannelType, const MorphologyMethod, const ssize_t, const KernelInfo *, ExceptionInfo *); +DEFINE_GVL_STUB2(NegateImage, Image *, const MagickBooleanType); +DEFINE_GVL_STUB3(NegateImageChannel, Image *, const ChannelType, const MagickBooleanType); +DEFINE_GVL_STUB1(NormalizeImage, Image *); +DEFINE_GVL_STUB2(NormalizeImageChannel, Image *, const ChannelType); +DEFINE_GVL_STUB3(OilPaintImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(OpaquePaintImageChannel, Image *, const ChannelType, const MagickPixelPacket *, const MagickPixelPacket *, const MagickBooleanType); +DEFINE_GVL_STUB3(OrderedPosterizeImage, Image *, const char *, ExceptionInfo *); +DEFINE_GVL_STUB4(PolaroidImage, const Image *, const DrawInfo *, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(PosterizeImage, Image *, const size_t, const MagickBooleanType); +DEFINE_GVL_STUB5(ProfileImage, Image *, const char *, const void *, const size_t, const MagickBooleanType); +DEFINE_GVL_STUB2(QuantizeImage, const QuantizeInfo *, Image *); +DEFINE_GVL_STUB3(RaiseImage, Image *, const RectangleInfo *, const MagickBooleanType); +DEFINE_GVL_STUB4(RandomThresholdImageChannel, Image *, const ChannelType, const char *, ExceptionInfo *); +DEFINE_GVL_STUB3(RemapImage, const QuantizeInfo *, Image *, const Image *); +DEFINE_GVL_STUB6(ResampleImage, const Image *, const double, const double, const FilterTypes, const double, ExceptionInfo *); +DEFINE_GVL_STUB6(ResizeImage, const Image *, const size_t, const size_t, const FilterTypes, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(SegmentImage, Image *, const ColorspaceType, const MagickBooleanType, const double, const double); +DEFINE_GVL_STUB6(SelectiveBlurImageChannel, const Image *, const ChannelType, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(SeparateImageChannel, Image *, const ChannelType); +DEFINE_GVL_STUB3(SeparateImages, const Image *, const ChannelType, ExceptionInfo *); +DEFINE_GVL_STUB2(SetImageAlphaChannel, Image *, const AlphaChannelType); +DEFINE_GVL_STUB1(SetImageBackgroundColor, Image *); +DEFINE_GVL_STUB3(SetImageChannelDepth, Image *, const ChannelType, const size_t); +DEFINE_GVL_STUB2(SetImageClipMask, Image *, const Image *); +DEFINE_GVL_STUB2(SetImageDepth, Image *, const size_t); +DEFINE_GVL_STUB3(SetImageExtent, Image *, const size_t, const size_t); +DEFINE_GVL_STUB2(SetImageMask, Image *, const Image *); +DEFINE_GVL_STUB2(SetImageStorageClass, Image *, const ClassType); +DEFINE_GVL_STUB5(SharpenImageChannel, const Image *, const ChannelType, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB5(SigmoidalContrastImageChannel, Image *, const ChannelType, const MagickBooleanType, const double, const double); +DEFINE_GVL_STUB1(SignatureImage, Image *); +DEFINE_GVL_STUB2(SolarizeImage, Image *, const double); +DEFINE_GVL_STUB6(SparseColorImage, const Image *, const ChannelType, const SparseColorMethod, const size_t, const double *, ExceptionInfo *); +DEFINE_GVL_STUB3(SpreadImage, const Image *, const double, ExceptionInfo *); +DEFINE_GVL_STUB3(SwirlImage, const Image *, double, ExceptionInfo *); +DEFINE_GVL_STUB1(SyncImage, Image *); +DEFINE_GVL_STUB4(TintImage, const Image *, const char *, const PixelPacket, ExceptionInfo *); +DEFINE_GVL_STUB2(TransformImageColorspace, Image *, const ColorspaceType); +DEFINE_GVL_STUB4(TransparentPaintImage, Image *, const MagickPixelPacket *, const Quantum, const MagickBooleanType); +DEFINE_GVL_STUB5(TransparentPaintImageChroma, Image *, const MagickPixelPacket *, const MagickPixelPacket *, const Quantum, const MagickBooleanType); +DEFINE_GVL_STUB7(UnsharpMaskImageChannel, const Image *, const ChannelType, const double, const double, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB4(WaveImage, const Image *, const double, const double, ExceptionInfo *); +DEFINE_GVL_STUB2(WhiteThresholdImage, Image *, const char *); +DEFINE_GVL_STUB2(WriteImage, const ImageInfo *, Image *); +#endif + +#if defined(HAVE_GETIMAGECHANNELENTROPY) +DEFINE_GVL_STUB4(GetImageChannelEntropy, const Image *, const ChannelType, double *, ExceptionInfo *); +#endif + +#if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9) +DEFINE_GVL_STUB3(RotationalBlurImage, const Image *, const double, ExceptionInfo *); +#else +DEFINE_GVL_STUB3(RadialBlurImage, const Image *, const double, ExceptionInfo *); +#endif + +#if defined(IMAGEMAGICK_7) +#elif defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9) +DEFINE_GVL_STUB4(RotationalBlurImageChannel, const Image *, const ChannelType, const double, ExceptionInfo *); +#else +DEFINE_GVL_STUB4(RadialBlurImageChannel, const Image *, const ChannelType, const double, ExceptionInfo *); +#endif + /** * Returns the alpha value from the hash. * * No Ruby usage (internal function) * @@ -96,10 +327,13 @@ return APP2QUANTUM(alpha); } +// aliases for common use of structure types; AdaptiveBlurImage, AdaptiveSharpenImage +typedef GVL_STRUCT_TYPE(AdaptiveBlurImage) GVL_STRUCT_TYPE(adaptive_method); + /** * Call Adaptive(Blur|Sharpen)Image. * * No Ruby usage (internal function) * @@ -108,12 +342,11 @@ * @param self this object * @param fp pointer to the function to call * @return a new image */ static VALUE -adaptive_method(int argc, VALUE *argv, VALUE self, - Image *fp(const Image *, const double, const double, ExceptionInfo *)) +adaptive_method(int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; ExceptionInfo *exception; @@ -133,18 +366,25 @@ break; } exception = AcquireExceptionInfo(); - new_image = (fp)(image, radius, sigma, exception); + GVL_STRUCT_TYPE(adaptive_method) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } +// aliases for common use of structure types; AdaptiveBlurImage, AdaptiveSharpenImage, AdaptiveBlurImageChannel, AdaptiveSharpenImageChannel +#if defined(IMAGEMAGICK_7) +typedef GVL_STRUCT_TYPE(AdaptiveBlurImage) GVL_STRUCT_TYPE(adaptive_channel_method); +#else +typedef GVL_STRUCT_TYPE(AdaptiveBlurImageChannel) GVL_STRUCT_TYPE(adaptive_channel_method); +#endif /** * Call Adaptive(Blur|Sharpen)ImageChannel. * * No Ruby usage (internal function) @@ -154,11 +394,11 @@ * @param self this object * @param fp pointer to the function to call * @return a new image */ static VALUE -adaptive_channel_method(int argc, VALUE *argv, VALUE self, channel_method_t fp) +adaptive_channel_method(int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; ExceptionInfo *exception; @@ -182,15 +422,17 @@ exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = (fp)(image, radius, sigma, exception); + GVL_STRUCT_TYPE(adaptive_channel_method) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = (fp)(image, channels, radius, sigma, exception); + GVL_STRUCT_TYPE(adaptive_channel_method) args = { image, channels, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -210,15 +452,14 @@ * @return [Magick::Image] a new image */ VALUE Image_adaptive_blur(int argc, VALUE *argv, VALUE self) { - return adaptive_method(argc, argv, self, AdaptiveBlurImage); + return adaptive_method(argc, argv, self, GVL_FUNC(AdaptiveBlurImage)); } - /** * The same as {Magick::Image#adaptive_blur} except only the specified channels are blurred. * * @overload adaptive_blur_channel(radius = 0.0, sigma = 1.0, channel = Magick::AllChannels) * @param radius [Float] The radius of the Gaussian in pixels, not counting the center pixel. @@ -234,13 +475,13 @@ */ VALUE Image_adaptive_blur_channel(int argc, VALUE *argv, VALUE self) { #if defined(IMAGEMAGICK_7) - return adaptive_channel_method(argc, argv, self, AdaptiveBlurImage); + return adaptive_channel_method(argc, argv, self, GVL_FUNC(AdaptiveBlurImage)); #else - return adaptive_channel_method(argc, argv, self, AdaptiveBlurImageChannel); + return adaptive_channel_method(argc, argv, self, GVL_FUNC(AdaptiveBlurImageChannel)); #endif } /** @@ -292,19 +533,19 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } exception = AcquireExceptionInfo(); - new_image = AdaptiveResizeImage(image, columns, rows, exception); + GVL_STRUCT_TYPE(AdaptiveResizeImage) args = { image, columns, rows, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AdaptiveResizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } - /** * Adaptively sharpens the image by sharpening more intensely near image edges and less intensely * far from edges. * * The {Magick::Image#adaptive_sharpen} method sharpens the image with a Gaussian operator of the @@ -319,15 +560,14 @@ * @return [Magick::Image] a new image */ VALUE Image_adaptive_sharpen(int argc, VALUE *argv, VALUE self) { - return adaptive_method(argc, argv, self, AdaptiveSharpenImage); + return adaptive_method(argc, argv, self, GVL_FUNC(AdaptiveSharpenImage)); } - /** * The same as {Magick::Image#adaptive_sharpen} except only the specified channels are sharpened. * * @overload adaptive_sharpen_channel(radius = 0.0, sigma = 1.0, channel = Magick::AllChannels) * @param radius [Float] The radius of the Gaussian in pixels, not counting the center pixel. @@ -343,18 +583,17 @@ */ VALUE Image_adaptive_sharpen_channel(int argc, VALUE *argv, VALUE self) { #if defined(IMAGEMAGICK_7) - return adaptive_channel_method(argc, argv, self, AdaptiveSharpenImage); + return adaptive_channel_method(argc, argv, self, GVL_FUNC(AdaptiveSharpenImage)); #else - return adaptive_channel_method(argc, argv, self, AdaptiveSharpenImageChannel); + return adaptive_channel_method(argc, argv, self, GVL_FUNC(AdaptiveSharpenImageChannel)); #endif } - /** * Selects an individual threshold for each pixel based on the range of intensity values in its * local neighborhood. This allows for thresholding of an image whose global intensity histogram * doesn't contain distinctive peaks. * @@ -387,11 +626,12 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc); } exception = AcquireExceptionInfo(); - new_image = AdaptiveThresholdImage(image, width, height, offset, exception); + GVL_STRUCT_TYPE(AdaptiveThresholdImage) args = { image, width, height, offset, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AdaptiveThresholdImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -426,21 +666,25 @@ #if defined(IMAGEMAGICK_7) clip_mask = rm_clone_image(mask_image); exception = AcquireExceptionInfo(); - NegateImage(clip_mask, MagickFalse, exception); + GVL_STRUCT_TYPE(NegateImage) args_NegateImage = { clip_mask, MagickFalse, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args_NegateImage); rm_check_exception(exception, clip_mask, DestroyOnError); - SetImageMask(image, CompositePixelMask, clip_mask, exception); + GVL_STRUCT_TYPE(SetImageMask) args_SetImageMask = { image, CompositePixelMask, clip_mask, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args_SetImageMask); DestroyImage(clip_mask); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else // Delete any previously-existing mask image. // Store a clone of the new mask image. - SetImageMask(image, mask_image); - NegateImage(image->mask, MagickFalse); + GVL_STRUCT_TYPE(SetImageMask) args_SetImageMask = { image, mask_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args_SetImageMask); + GVL_STRUCT_TYPE(NegateImage) args_NegateImage = { image->mask, MagickFalse }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args_NegateImage); // Since both Set and GetImageMask clone the mask image I don't see any // way to negate the mask without referencing it directly. Sigh. #endif @@ -465,14 +709,15 @@ VALUE_TO_ENUM(noise, noise_type, NoiseType); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = AddNoiseImage(image, noise_type, 1.0, exception); + GVL_STRUCT_TYPE(AddNoiseImage) args = { image, noise_type, 1.0, exception }; #else - new_image = AddNoiseImage(image, noise_type, exception); + GVL_STRUCT_TYPE(AddNoiseImage) args = { image, noise_type, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AddNoiseImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -515,14 +760,16 @@ channels &= ~OpacityChannel; exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = AddNoiseImage(image, noise_type, 1.0, exception); + GVL_STRUCT_TYPE(AddNoiseImage) args = { image, noise_type, 1.0, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AddNoiseImage), &args); END_CHANNEL_MASK(new_image); #else - new_image = AddNoiseImageChannel(image, channels, noise_type, exception); + GVL_STRUCT_TYPE(AddNoiseImageChannel) args = { image, channels, noise_type, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AddNoiseImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -576,14 +823,16 @@ { profile = GetImageProfile(profile_image, profile_name); if (profile) { #if defined(IMAGEMAGICK_7) - ProfileImage(image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), exception); + GVL_STRUCT_TYPE(ProfileImage) args = { image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(exception, RetainExceptionRetention)) #else - ProfileImage(image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), MagickFalse); + GVL_STRUCT_TYPE(ProfileImage) args = { image, profile_name, GetStringInfoDatum(profile), GetStringInfoLength(profile), MagickFalse }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(&image->exception, RetainExceptionRetention)) #endif { break; } @@ -650,15 +899,17 @@ image = rm_check_frozen(self); VALUE_TO_ENUM(argv[0], alpha, AlphaChannelOption); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageAlphaChannel(image, alpha, exception); + GVL_STRUCT_TYPE(SetImageAlphaChannel) args = { image, alpha, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageAlphaChannel), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageAlphaChannel(image, alpha); + GVL_STRUCT_TYPE(SetImageAlphaChannel) args = { image, alpha }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageAlphaChannel), &args); rm_check_image_exception(image, RetainOnError); #endif return argv[0]; } @@ -699,11 +950,12 @@ // Convert Magick::AffineMatrix to AffineMatrix structure. Export_AffineMatrix(&matrix, affine); exception = AcquireExceptionInfo(); - new_image = AffineTransformImage(image, &matrix, exception); + GVL_STRUCT_TYPE(AffineTransformImage) args = { image, &matrix, exception }; + new_image = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(AffineTransformImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -821,10 +1073,13 @@ } return self; } +// aliases for common use of structure types; TransposeImage, TransverseImage +typedef GVL_STRUCT_TYPE(TransposeImage) GVL_STRUCT_TYPE(crisscross); + /** * Handle #transverse, #transform methods. * * No Ruby usage (internal function) * @@ -832,19 +1087,20 @@ * @param self this object * @param fp the transverse/transform method to call * @return self if bang, otherwise a new image */ static VALUE -crisscross(int bang, VALUE self, Image *fp(const Image *, ExceptionInfo *)) +crisscross(int bang, VALUE self, gvl_function_t fp) { Image *image, *new_image; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = (fp)(image, exception); + GVL_STRUCT_TYPE(crisscross) args = { image, exception }; + new_image = CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -857,10 +1113,16 @@ return rm_image_new(new_image); } +// aliases for common use of structure types; AutoGammaImage, AutoLevelImage, AutoGammaImageChannel, AutoLevelImageChannel +#if defined(IMAGEMAGICK_7) +typedef GVL_STRUCT_TYPE(AutoGammaImage) GVL_STRUCT_TYPE(auto_channel); +#else +typedef GVL_STRUCT_TYPE(AutoGammaImageChannel) GVL_STRUCT_TYPE(auto_channel); +#endif /** * Handle #auto_gamma_channel, #auto_level_channel methods. * * No Ruby usage (internal function) @@ -870,11 +1132,11 @@ * @param self this object * @param fp the channel method to call * @return a new image */ static VALUE -auto_channel(int argc, VALUE *argv, VALUE self, auto_channel_t fp) +auto_channel(int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; ChannelType channels; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; @@ -891,16 +1153,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - (fp)(new_image, exception); + GVL_STRUCT_TYPE(auto_channel) args = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(fp, &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - (fp)(new_image, channels); + GVL_STRUCT_TYPE(auto_channel) args = { new_image, channels }; + CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -919,13 +1183,13 @@ */ VALUE Image_auto_gamma_channel(int argc, VALUE *argv, VALUE self) { #if defined(IMAGEMAGICK_7) - return auto_channel(argc, argv, self, AutoGammaImage); + return auto_channel(argc, argv, self, GVL_FUNC(AutoGammaImage)); #else - return auto_channel(argc, argv, self, AutoGammaImageChannel); + return auto_channel(argc, argv, self, GVL_FUNC(AutoGammaImageChannel)); #endif } /** @@ -941,13 +1205,13 @@ */ VALUE Image_auto_level_channel(int argc, VALUE *argv, VALUE self) { #if defined(IMAGEMAGICK_7) - return auto_channel(argc, argv, self, AutoLevelImage); + return auto_channel(argc, argv, self, GVL_FUNC(AutoLevelImage)); #else - return auto_channel(argc, argv, self, AutoLevelImageChannel); + return auto_channel(argc, argv, self, GVL_FUNC(AutoLevelImageChannel)); #endif } /** @@ -966,38 +1230,38 @@ { Image *image; VALUE new_image; VALUE degrees[1]; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); switch (image->orientation) { case TopRightOrientation: - new_image = flipflop(bang, self, FlopImage); + new_image = flipflop(bang, self, GVL_FUNC(FlopImage)); break; case BottomRightOrientation: degrees[0] = rb_float_new(180.0); new_image = rotate(bang, 1, degrees, self); break; case BottomLeftOrientation: - new_image = flipflop(bang, self, FlipImage); + new_image = flipflop(bang, self, GVL_FUNC(FlipImage)); break; case LeftTopOrientation: - new_image = crisscross(bang, self, TransposeImage); + new_image = crisscross(bang, self, GVL_FUNC(TransposeImage)); break; case RightTopOrientation: degrees[0] = rb_float_new(90.0); new_image = rotate(bang, 1, degrees, self); break; case RightBottomOrientation: - new_image = crisscross(bang, self, TransverseImage); + new_image = crisscross(bang, self, GVL_FUNC(TransverseImage)); break; case LeftBottomOrientation: degrees[0] = rb_float_new(270.0); new_image = rotate(bang, 1, degrees, self); @@ -1007,11 +1271,11 @@ return bang ? Qnil : Image_copy(self); break; } - Data_Get_Struct(new_image, Image, image); + TypedData_Get_Struct(new_image, Image, &rm_image_data_type, image); image->orientation = TopLeftOrientation; RB_GC_GUARD(new_image); return new_image; @@ -1226,16 +1490,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - BilevelImage(new_image, threshold, exception); + GVL_STRUCT_TYPE(BilevelImage) args = { new_image, threshold, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - BilevelImageChannel(new_image, channels, threshold); + GVL_STRUCT_TYPE(BilevelImageChannel) args = { new_image, channels, threshold }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -1318,11 +1584,11 @@ * @see Image#white_threshold */ VALUE Image_black_threshold(int argc, VALUE *argv, VALUE self) { - return threshold_image(argc, argv, self, BlackThresholdImage); + return threshold_image(argc, argv, self, GVL_FUNC(BlackThresholdImage)); } /** * Compute offsets using the gravity to determine what the offsets are relative @@ -1628,15 +1894,17 @@ SetImageArtifact(new_image, "compose:args", geometry); // 6.9 appears to get this info from canvas (dest) image #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - CompositeImage(new_image, overlay, op, MagickTrue, x_off, y_off, exception); + GVL_STRUCT_TYPE(CompositeImage) args = { new_image, overlay, op, MagickTrue, x_off, y_off, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - CompositeImage(new_image, op, overlay, x_off, y_off); + GVL_STRUCT_TYPE(CompositeImage) args = { new_image, op, overlay, x_off, y_off }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); @@ -1739,11 +2007,12 @@ break; } exception = AcquireExceptionInfo(); - new_image = BlueShiftImage(image, factor, exception); + GVL_STRUCT_TYPE(BlueShiftImage) args = { image, factor, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlueShiftImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -1791,15 +2060,17 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = BlurImage(image, radius, sigma, exception); + GVL_STRUCT_TYPE(BlurImage) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlurImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = BlurImageChannel(image, channels, radius, sigma, exception); + GVL_STRUCT_TYPE(BlurImageChannel) args = { image, channels, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlurImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -1815,11 +2086,11 @@ * @return [Magick::Image] a new image */ VALUE Image_blur_image(int argc, VALUE *argv, VALUE self) { - return effect_image(self, argc, argv, BlurImage); + return effect_image(self, argc, argv, GVL_FUNC(BlurImage)); } /** * Surrounds the image with a border of the specified width, height, and named @@ -1842,11 +2113,11 @@ Image *image, *new_image; PixelColor old_border; ExceptionInfo *exception; RectangleInfo rect; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); memset(&rect, 0, sizeof(rect)); rect.width = NUM2UINT(width); rect.height = NUM2UINT(height); @@ -1854,14 +2125,15 @@ old_border = image->border_color; Color_to_PixelColor(&image->border_color, color); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = BorderImage(image, &rect, image->compose, exception); + GVL_STRUCT_TYPE(BorderImage) args = { image, &rect, image->compose, exception }; #else - new_image = BorderImage(image, &rect, exception); + GVL_STRUCT_TYPE(BorderImage) args = { image, &rect, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BorderImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -2031,11 +2303,11 @@ // Set info->filename = "root", window ID number or window name, // or nothing to do an interactive capture // Set info->server_name to the server name // Also info->colorspace, depth, dither, interlace, type info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, image_info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, image_info); // If an error occurs, IM will call our error handler and we raise an exception. #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); new_image = XImportImage(image_info, &ximage_info, exception); @@ -2142,16 +2414,18 @@ VALUE_TO_ENUM(channel_arg, channel, ChannelType); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - new_image = SeparateImage(image, channel, exception); + GVL_STRUCT_TYPE(SeparateImage) args = { image, channel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SeparateImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else new_image = rm_clone_image(image); - SeparateImageChannel(new_image, channel); + GVL_STRUCT_TYPE(SeparateImageChannel) args = { new_image, channel }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SeparateImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); @@ -2172,11 +2446,11 @@ VALUE Image_channel_depth(int argc, VALUE *argv, VALUE self) { Image *image; ChannelType channels; - unsigned long channel_depth; + size_t channel_depth; ExceptionInfo *exception; image = rm_check_destroyed(self); channels = extract_channels(&argc, argv); @@ -2188,14 +2462,16 @@ exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - channel_depth = GetImageDepth(image, exception); + GVL_STRUCT_TYPE(GetImageDepth) args = { image, exception }; + channel_depth = (size_t)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageDepth), &args); END_CHANNEL_MASK(image); #else - channel_depth = GetImageChannelDepth(image, channels, exception); + GVL_STRUCT_TYPE(GetImageChannelDepth) args = { image, channels, exception }; + channel_depth = (size_t)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelDepth), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -2235,14 +2511,16 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - GetImageExtrema(image, &min, &max, exception); + GVL_STRUCT_TYPE(GetImageExtrema) args = { image, &min, &max, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageExtrema), &args); END_CHANNEL_MASK(image); #else - GetImageChannelExtrema(image, channels, &min, &max, exception); + GVL_STRUCT_TYPE(GetImageChannelExtrema) args = { image, channels, &min, &max, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelExtrema), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -2288,14 +2566,16 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - GetImageMean(image, &mean, &stddev, exception); + GVL_STRUCT_TYPE(GetImageMean) args = { image, &mean, &stddev, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageMean), &args); END_CHANNEL_MASK(image); #else - GetImageChannelMean(image, channels, &mean, &stddev, exception); + GVL_STRUCT_TYPE(GetImageChannelMean) args = { image, channels, &mean, &stddev, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelMean), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -2340,14 +2620,16 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - GetImageEntropy(image, &entropy, exception); + GVL_STRUCT_TYPE(GetImageEntropy) args = { image, &entropy, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageEntropy), &args); END_CHANNEL_MASK(image); #else - GetImageChannelEntropy(image, channels, &entropy, exception); + GVL_STRUCT_TYPE(GetImageChannelEntropy) args = { image, channels, &entropy, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelEntropy), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -2375,11 +2657,11 @@ * @return [Magick::Image] a new image */ VALUE Image_charcoal(int argc, VALUE *argv, VALUE self) { - return effect_image(self, argc, argv, CharcoalImage); + return effect_image(self, argc, argv, GVL_FUNC(CharcoalImage)); } /** * Raises {Magick::DestroyedImageError} if the image has been destroyed. Returns nil otherwise. @@ -2406,11 +2688,11 @@ */ VALUE Image_chop(VALUE self, VALUE x, VALUE y, VALUE width, VALUE height) { rm_check_destroyed(self); - return xform_image(False, self, x, y, width, height, ChopImage); + return xform_image(False, self, x, y, width, height, GVL_FUNC(ChopImage)); } /** * Return the red, green, blue, and white-point chromaticity values as a {Magick::Chromaticity}. @@ -2511,21 +2793,23 @@ else { rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or more)", argc); } - Data_Get_Struct(argv[0], Image, clut); + TypedData_Get_Struct(argv[0], Image, &rm_image_data_type, clut); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(image, channels); - okay = ClutImage(image, clut, image->interpolate, exception); + GVL_STRUCT_TYPE(ClutImage) args = { image, clut, image->interpolate, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ClutImage), &args); END_CHANNEL_MASK(image); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - okay = ClutImageChannel(image, channels, clut); + GVL_STRUCT_TYPE(ClutImageChannel) args = { image, channels, clut }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ClutImageChannel), &args); rm_check_image_exception(image, RetainOnError); rm_check_image_exception(clut, RetainOnError); #endif if (!okay) { @@ -2562,18 +2846,20 @@ // If image not DirectClass make a DirectClass copy. if (image->storage_class != DirectClass) { dc_copy = rm_clone_image(image); #if defined(IMAGEMAGICK_7) - SetImageStorageClass(dc_copy, DirectClass, exception); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { dc_copy, DirectClass, exception }; #else - SetImageStorageClass(dc_copy, DirectClass); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { dc_copy, DirectClass }; #endif + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); image = dc_copy; } - histogram = GetImageHistogram(image, &colors, exception); + GVL_STRUCT_TYPE(GetImageHistogram) args = { image, &colors, exception }; + histogram = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageHistogram), &args); if (histogram == NULL) { if (dc_copy) { @@ -2663,11 +2949,12 @@ rb_raise(rb_eNoMemError, "not enough memory to continue"); } strlcpy(info->magick, m->name, sizeof(info->magick)); - profile_image = BlobToImage(info, profile_blob, (size_t)profile_length, exception); + GVL_STRUCT_TYPE(BlobToImage) args = { info, profile_blob, (size_t)profile_length, exception }; + profile_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args); DestroyImageInfo(info); CHECK_EXCEPTION(); ResetImageProfileIterator(profile_image); profile_name = GetNextImageProfile(profile_image); @@ -2675,14 +2962,16 @@ { /* Hack for versions of ImageMagick where the meta coder would change the iptc profile into an 8bim profile */ if (rm_strcasecmp("8bim", profile_name) == 0 && rm_strcasecmp("iptc", name) == 0) { #if defined(IMAGEMAGICK_7) - ProfileImage(image, name, profile_blob, profile_length, exception); + GVL_STRUCT_TYPE(ProfileImage) args = { image, name, profile_blob, profile_length, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(exception, RetainExceptionRetention)) #else - ProfileImage(image, name, profile_blob, profile_length, MagickFalse); + GVL_STRUCT_TYPE(ProfileImage) args = { image, name, profile_blob, profile_length, MagickFalse }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(&image->exception, RetainExceptionRetention)) #endif { break; } @@ -2691,14 +2980,16 @@ { profile_data = GetImageProfile(profile_image, profile_name); if (profile_data) { #if defined(IMAGEMAGICK_7) - ProfileImage(image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), exception); + GVL_STRUCT_TYPE(ProfileImage) args = { image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(exception, RetainExceptionRetention)) #else - ProfileImage(image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), MagickFalse); + GVL_STRUCT_TYPE(ProfileImage) args = { image, name, GetStringInfoDatum(profile_data), GetStringInfoLength(profile_data), MagickFalse }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); if (rm_should_raise_exception(&image->exception, RetainExceptionRetention)) #endif { break; } @@ -2843,16 +3134,18 @@ target_mpp.blue = (MagickRealType) target.blue; } #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - FloodfillPaintImage(new_image, draw_info, &target_mpp, x, y, invert, exception); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, draw_info, &target_mpp, x, y, invert, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); DestroyDrawInfo(draw_info); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - FloodfillPaintImage(new_image, DefaultChannels, draw_info, &target_mpp, x, y, invert); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, DefaultChannels, draw_info, &target_mpp, x, y, invert }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); DestroyDrawInfo(draw_info); rm_check_image_exception(new_image, DestroyOnError); #endif @@ -2912,14 +3205,15 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc); } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = ColorizeImage(image, opacity, &target, exception); + GVL_STRUCT_TYPE(ColorizeImage) args = { image, opacity, &target, exception }; #else - new_image = ColorizeImage(image, opacity, target, exception); + GVL_STRUCT_TYPE(ColorizeImage) args = { image, opacity, target, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ColorizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -3025,11 +3319,11 @@ * @return [Numeric] the number of colors */ VALUE Image_colors(VALUE self) { - IMPLEMENT_ATTR_READER(Image, colors, ulong); + IMPLEMENT_TYPED_ATTR_READER(Image, colors, ulong, &rm_image_data_type); } /** * Return the Image pixel interpretation. If the colorspace is RGB the pixels are red, green, * blue. If matte is true, then red, green, blue, and index. If it is CMYK, the pixels are cyan, @@ -3065,15 +3359,17 @@ image = rm_check_frozen(self); VALUE_TO_ENUM(colorspace, new_cs, ColorspaceType); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - TransformImageColorspace(image, new_cs, exception); + GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, new_cs, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - TransformImageColorspace(image, new_cs); + GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, new_cs }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args); rm_check_image_exception(image, RetainOnError); #endif return colorspace; } @@ -3085,11 +3381,11 @@ * @return [Numeric] the columns */ VALUE Image_columns(VALUE self) { - IMPLEMENT_ATTR_READER(Image, columns, int); + IMPLEMENT_TYPED_ATTR_READER(Image, columns, int, &rm_image_data_type); } /** * Compare one or more channels in two images and returns the specified distortion metric and a @@ -3169,14 +3465,16 @@ VALUE_TO_ENUM(argv[1], metric_type, MetricType); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - difference_image = CompareImages(image, r_image, metric_type, &distortion, exception); + GVL_STRUCT_TYPE(CompareImages) args = { image, r_image, metric_type, &distortion, exception }; + difference_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImages), &args); END_CHANNEL_MASK(image); #else - difference_image = CompareImageChannels(image, r_image, channels, metric_type, &distortion, exception); + GVL_STRUCT_TYPE(CompareImageChannels) args = { image, r_image, channels, metric_type, &distortion, exception }; + difference_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImageChannels), &args); #endif rm_check_exception(exception, difference_image, DestroyOnError); DestroyExceptionInfo(exception); ary = rb_ary_new2(2); @@ -3370,16 +3668,18 @@ if (bang) { #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(image, channels); - CompositeImage(image, comp_image, operator, MagickTrue, x_offset, y_offset, exception); + GVL_STRUCT_TYPE(CompositeImage) args = { image, comp_image, operator, MagickTrue, x_offset, y_offset, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); END_CHANNEL_MASK(image); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - CompositeImageChannel(image, channels, operator, comp_image, x_offset, y_offset); + GVL_STRUCT_TYPE(CompositeImageChannel) args = { image, channels, operator, comp_image, x_offset, y_offset }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImageChannel), &args); rm_check_image_exception(image, RetainOnError); #endif return self; } @@ -3388,16 +3688,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - CompositeImage(new_image, comp_image, operator, MagickTrue, x_offset, y_offset, exception); + GVL_STRUCT_TYPE(CompositeImage) args = { new_image, comp_image, operator, MagickTrue, x_offset, y_offset, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - CompositeImageChannel(new_image, channels, operator, comp_image, x_offset, y_offset); + GVL_STRUCT_TYPE(CompositeImageChannel) args = { new_image, channels, operator, comp_image, x_offset, y_offset }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -3507,15 +3809,17 @@ Export_AffineMatrix(&affine, affine_matrix); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - DrawAffineImage(new_image, composite_image, &affine, exception); + GVL_STRUCT_TYPE(DrawAffineImage) args = { new_image, composite_image, &affine, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DrawAffineImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - DrawAffineImage(new_image, composite_image, &affine); + GVL_STRUCT_TYPE(DrawAffineImage) args = { new_image, composite_image, &affine }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DrawAffineImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -3875,15 +4179,17 @@ { for (x = 0; status == MagickTrue && x < (long) image->columns; x += columns) { #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - status = CompositeImage(image, comp_image, operator, MagickTrue, x, y, exception); + GVL_STRUCT_TYPE(CompositeImage) args = { image, comp_image, operator, MagickTrue, x, y, exception }; + status = (MagickStatusType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); END_CHANNEL_MASK(image); rm_check_exception(exception, image, bang ? RetainOnError: DestroyOnError); #else - status = CompositeImageChannel(image, channels, operator, comp_image, x, y); + GVL_STRUCT_TYPE(CompositeImageChannel) args = { image, channels, operator, comp_image, x, y }; + status = (MagickStatusType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImageChannel), &args); rm_check_image_exception(image, bang ? RetainOnError: DestroyOnError); #endif } } @@ -3992,15 +4298,17 @@ image = rm_check_frozen(self); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = CompressImageColormap(image, exception); + GVL_STRUCT_TYPE(CompressImageColormap) args = { image, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompressImageColormap), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - okay = CompressImageColormap(image); + GVL_STRUCT_TYPE(CompressImageColormap) args = { image }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompressImageColormap), &args); rm_check_image_exception(image, RetainOnError); #endif if (!okay) { rb_warning("CompressImageColormap failed (probably DirectClass image)"); @@ -4126,13 +4434,15 @@ rb_raise(rb_eNoMemError, "not enough memory to continue."); } #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageExtent(new_image, width, height, exception); + GVL_STRUCT_TYPE(SetImageExtent) args_SetImageExtent = { new_image, width, height, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageExtent), &args_SetImageExtent); #else - SetImageExtent(new_image, width, height); + GVL_STRUCT_TYPE(SetImageExtent) args_SetImageExtent = { new_image, width, height }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageExtent), &args_SetImageExtent); exception = &new_image->exception; #endif if (rm_should_raise_exception(exception, RetainExceptionRetention)) { @@ -4144,13 +4454,15 @@ rm_check_image_exception(new_image, DestroyOnError); #endif } #if defined(IMAGEMAGICK_7) - SetImageBackgroundColor(new_image, exception); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args_SetImageBackgroundColor = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args_SetImageBackgroundColor); #else - SetImageBackgroundColor(new_image); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args_SetImageBackgroundColor = { new_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args_SetImageBackgroundColor); exception = &new_image->exception; #endif if (rm_should_raise_exception(exception, RetainExceptionRetention)) { @@ -4162,16 +4474,18 @@ rm_check_image_exception(new_image, DestroyOnError); #endif } #if defined(IMAGEMAGICK_7) - ImportImagePixels(new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v, exception); + GVL_STRUCT_TYPE(ImportImagePixels) args_ImportImagePixels = { new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImportImagePixels), &args_ImportImagePixels); xfree(pixels.v); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - ImportImagePixels(new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v); + GVL_STRUCT_TYPE(ImportImagePixels) args_ImportImagePixels = { new_image, 0, 0, width, height, map, stg_type, (const void *)pixels.v }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImportImagePixels), &args_ImportImagePixels); xfree(pixels.v); rm_check_image_exception(new_image, DestroyOnError); #endif RB_GC_GUARD(pixel); @@ -4334,16 +4648,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - ContrastStretchImage(new_image, black_point, white_point, exception); + GVL_STRUCT_TYPE(ContrastStretchImage) args = { new_image, black_point, white_point, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ContrastStretchImage), &args); END_CHANNEL_MASK(new_image); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - ContrastStretchImageChannel(new_image, channels, black_point, white_point); + GVL_STRUCT_TYPE(ContrastStretchImageChannel) args = { new_image, channels, black_point, white_point }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ContrastStretchImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -4409,21 +4725,23 @@ if (!rb_obj_is_kind_of(kernel_v, Class_KernelInfo)) { rb_raise(rb_eArgError, "expected String or Magick::KernelInfo"); } - Data_Get_Struct(kernel_v, KernelInfo, kernel); + TypedData_Get_Struct(kernel_v, KernelInfo, &rm_kernel_info_data_type, kernel); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channel); - new_image = MorphologyImage(image, method, NUM2LONG(iterations), kernel, exception); + GVL_STRUCT_TYPE(MorphologyImage) args = { image, method, NUM2LONG(iterations), kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MorphologyImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = MorphologyImageChannel(image, channel, method, NUM2LONG(iterations), kernel, exception); + GVL_STRUCT_TYPE(MorphologyImageChannel) args = { image, channel, method, NUM2LONG(iterations), kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(MorphologyImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -4530,14 +4848,16 @@ #endif exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = ConvolveImage(image, kernel, exception); + GVL_STRUCT_TYPE(ConvolveImage) args = { image, kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ConvolveImage), &args); DestroyKernelInfo(kernel); #else - new_image = ConvolveImage(image, order, kernel, exception); + GVL_STRUCT_TYPE(ConvolveImage) args = { image, order, kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ConvolveImage), &args); xfree((void *)kernel); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -4622,16 +4942,18 @@ exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = ConvolveImage(image, kernel, exception); + GVL_STRUCT_TYPE(ConvolveImage) args = { image, kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ConvolveImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); DestroyKernelInfo(kernel); #else - new_image = ConvolveImageChannel(image, channels, order, kernel, exception); + GVL_STRUCT_TYPE(ConvolveImageChannel) args = { image, channels, order, kernel, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ConvolveImageChannel), &args); xfree((void *)kernel); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -4770,15 +5092,17 @@ image = rm_check_destroyed(self); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - CycleColormapImage(new_image, amt, exception); + GVL_STRUCT_TYPE(CycleColormapImage) args = { new_image, amt, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CycleColormapImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - CycleColormapImage(new_image, amt); + GVL_STRUCT_TYPE(CycleColormapImage) args = { new_image, amt }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CycleColormapImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -4909,11 +5233,12 @@ pf = StringValueCStr(passphrase); // ensure passphrase is a string exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); - okay = DecipherImage(new_image, pf, exception); + GVL_STRUCT_TYPE(DecipherImage) args = { new_image, pf, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DecipherImage), &args); rm_check_exception(exception, new_image, DestroyOnError); if (!okay) { DestroyImage(new_image); rb_raise(rb_eRuntimeError, "DecipherImage failed for unknown reason."); @@ -4976,11 +5301,11 @@ * @return [Numeric] The current delay value. */ VALUE Image_delay(VALUE self) { - IMPLEMENT_ATTR_READER(Image, delay, ulong); + IMPLEMENT_TYPED_ATTR_READER(Image, delay, ulong, &rm_image_data_type); } /** * Set the Number of ticks which must expire before displaying the next image in an animated * sequence. @@ -4989,11 +5314,11 @@ * @return [Numeric] the given value */ VALUE Image_delay_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, delay, ulong); + IMPLEMENT_TYPED_ATTR_WRITER(Image, delay, ulong, &rm_image_data_type); } /** * Delete the image composite mask. @@ -5011,15 +5336,17 @@ image = rm_check_frozen(self); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageMask(image, CompositePixelMask, NULL, exception); + GVL_STRUCT_TYPE(SetImageMask) args = { image, CompositePixelMask, NULL, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageMask(image, NULL); + GVL_STRUCT_TYPE(SetImageMask) args = { image, NULL }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args); rm_check_image_exception(image, RetainOnError); #endif return self; } @@ -5039,15 +5366,17 @@ Image *image = rm_check_frozen(self); #if defined(IMAGEMAGICK_7) ExceptionInfo *exception = AcquireExceptionInfo(); - ProfileImage(image, StringValueCStr(name), NULL, 0, exception); + GVL_STRUCT_TYPE(ProfileImage) args = { image, StringValueCStr(name), NULL, 0, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - ProfileImage(image, StringValueCStr(name), NULL, 0, MagickTrue); + GVL_STRUCT_TYPE(ProfileImage) args = { image, StringValueCStr(name), NULL, 0, MagickTrue }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ProfileImage), &args); #endif return self; } @@ -5061,17 +5390,18 @@ */ VALUE Image_depth(VALUE self) { Image *image; - unsigned long depth = 0; + size_t depth = 0; ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - depth = GetImageDepth(image, exception); + GVL_STRUCT_TYPE(GetImageDepth) args = { image, exception }; + depth = (size_t)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageDepth), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); return INT2FIX(depth); @@ -5114,11 +5444,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } exception = AcquireExceptionInfo(); - new_image = DeskewImage(image, threshold, exception); + GVL_STRUCT_TYPE(DeskewImage) args = { image, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DeskewImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -5136,11 +5467,12 @@ ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = DespeckleImage(image, exception); + GVL_STRUCT_TYPE(DespeckleImage) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DespeckleImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -5155,11 +5487,11 @@ Image_destroy_bang(VALUE self) { Image *image; rb_check_frozen(self); - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); rm_image_destroy(image); DATA_PTR(self) = NULL; return self; } @@ -5172,11 +5504,11 @@ VALUE Image_destroyed_q(VALUE self) { Image *image; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); return image ? Qfalse : Qtrue; } /** @@ -5211,15 +5543,17 @@ other = rm_cur_image(other); image2 = rm_check_destroyed(other); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - GetImageDistortion(image, image2, MeanErrorPerPixelErrorMetric, &distortion, exception); + GVL_STRUCT_TYPE(GetImageDistortion) args = { image, image2, MeanErrorPerPixelErrorMetric, &distortion, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageDistortion), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - IsImagesEqual(image, image2); + GVL_STRUCT_TYPE(IsImagesEqual) args = { image, image2 }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(IsImagesEqual), &args); rm_check_image_exception(image, RetainOnError); #endif mean = rb_float_new(image->error.mean_error_per_pixel); nmean = rb_float_new(image->error.normalized_mean_error); @@ -5239,11 +5573,11 @@ * @return [String] the directory */ VALUE Image_directory(VALUE self) { - IMPLEMENT_ATTR_READER(Image, directory, str); + IMPLEMENT_TYPED_ATTR_READER(Image, directory, str, &rm_image_data_type); } /** * Uses displacement_map to move color from img to the output image. @@ -5364,14 +5698,15 @@ : (void *) ALLOC_N(double, npixels); // Create the Ruby array for the pixels. Return this even if ExportImagePixels fails. pixels_ary = rb_ary_new(); - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - okay = ExportImagePixels(image, x, y, columns, rows, map, stg_type, (void *)pixels.v, exception); + GVL_STRUCT_TYPE(ExportImagePixels) args = { image, x, y, columns, rows, map, stg_type, (void *)pixels.v, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ExportImagePixels), &args); if (!okay) { goto exit; } @@ -5426,11 +5761,11 @@ { rb_raise(rb_eArgError, "invalid image geometry (%"RMIuSIZE"x%"RMIuSIZE")", image->rows, image->columns); } info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); DisplayImages(info, image, exception); CHECK_EXCEPTION(); @@ -5629,11 +5964,12 @@ rb_raise(rb_eTypeError, "type mismatch: %s given", rb_class2name(CLASS_OF(element))); } } exception = AcquireExceptionInfo(); - new_image = DistortImage(image, distortion_method, npoints, points, bestfit, exception); + GVL_STRUCT_TYPE(DistortImage) args = { image, distortion_method, npoints, points, bestfit, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(DistortImage), &args); xfree(points); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); RB_GC_GUARD(pts); @@ -5688,15 +6024,17 @@ reconstruct = rm_check_destroyed(rec); VALUE_TO_ENUM(argv[1], metric, MetricType); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - difference_image = CompareImages(image, reconstruct, metric, &distortion, exception); + GVL_STRUCT_TYPE(CompareImages) args = { image, reconstruct, metric, &distortion, exception }; + difference_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompareImages), &args); END_CHANNEL_MASK(image); DestroyImage(difference_image); #else - GetImageChannelDistortion(image, reconstruct, channels, metric, &distortion, exception); + GVL_STRUCT_TYPE(GetImageChannelDistortion) args = { image, reconstruct, channels, metric, &distortion, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageChannelDistortion), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -5732,11 +6070,12 @@ rb_raise(rb_eNoMemError, "not enough memory to continue"); } strlcpy(info->magick, image->magick, sizeof(info->magick)); exception = AcquireExceptionInfo(); - blob = ImageToBlob(info, image, &length, exception); + GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception }; + blob = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args); // Free ImageInfo first - error handling may raise an exception DestroyImageInfo(info); CHECK_EXCEPTION(); @@ -5778,11 +6117,11 @@ Image_dup(VALUE self) { VALUE dup; rm_check_destroyed(self); - dup = Data_Wrap_Struct(CLASS_OF(self), NULL, rm_image_destroy, NULL); + dup = TypedData_Wrap_Struct(CLASS_OF(self), &rm_image_data_type, NULL); RB_GC_GUARD(dup); return rb_funcall(dup, rm_ID_initialize_copy, 1, self); } @@ -5860,18 +6199,22 @@ break; } exception = AcquireExceptionInfo(); - new_image = EdgeImage(image, radius, exception); + GVL_STRUCT_TYPE(EdgeImage) args = { image, radius, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EdgeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } +// aliases for common use of structure types; BlurImage, CharcoalImage, EmbossImage, GaussianBlurImage, SharpenImage +typedef GVL_STRUCT_TYPE(BlurImage) GVL_STRUCT_TYPE(effect_image); + /** * Call one of the effects methods. * * No Ruby usage (internal function) * @@ -5880,11 +6223,11 @@ * @param argv array of input arguments * @param effector the effector to call * @return a new image */ static VALUE -effect_image(VALUE self, int argc, VALUE *argv, effector_t effector) +effect_image(VALUE self, int argc, VALUE *argv, gvl_function_t fp) { Image *image, *new_image; ExceptionInfo *exception; double radius = 0.0, sigma = 1.0; @@ -5907,11 +6250,12 @@ { rb_raise(rb_eArgError, "sigma must be != 0.0"); } exception = AcquireExceptionInfo(); - new_image = (effector)(image, radius, sigma, exception); + GVL_STRUCT_TYPE(effect_image) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -5926,11 +6270,11 @@ * @return [Magick::Image] a new image */ VALUE Image_emboss(int argc, VALUE *argv, VALUE self) { - return effect_image(self, argc, argv, EmbossImage); + return effect_image(self, argc, argv, GVL_FUNC(EmbossImage)); } /** * Encipher an image. @@ -5952,11 +6296,12 @@ pf = StringValueCStr(passphrase); // ensure passphrase is a string exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); - okay = EncipherImage(new_image, pf, exception); + GVL_STRUCT_TYPE(EncipherImage) args = { new_image, pf, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EncipherImage), &args); rm_check_exception(exception, new_image, DestroyOnError); if (!okay) { DestroyImage(new_image); rb_raise(rb_eRuntimeError, "EncipherImage failed for unknown reason."); @@ -6008,11 +6353,12 @@ ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = EnhanceImage(image, exception); + GVL_STRUCT_TYPE(EnhanceImage) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EnhanceImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -6034,15 +6380,17 @@ image = rm_check_destroyed(self); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - EqualizeImage(new_image, exception); + GVL_STRUCT_TYPE(EqualizeImage) args = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EqualizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - EqualizeImage(new_image); + GVL_STRUCT_TYPE(EqualizeImage) args = { new_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EqualizeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -6078,16 +6426,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - EqualizeImage(new_image, exception); + GVL_STRUCT_TYPE(EqualizeImage) args = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EqualizeImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - EqualizeImageChannel(new_image, channels); + GVL_STRUCT_TYPE(EqualizeImageChannel) args = { new_image, channels }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EqualizeImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); @@ -6109,15 +6459,17 @@ image = rm_check_frozen(self); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageBackgroundColor(image, exception); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageBackgroundColor(image); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args = { image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args); rm_check_image_exception(image, RetainOnError); #endif return self; } @@ -6155,14 +6507,15 @@ rect.x = NUM2LONG(x); rect.y = NUM2LONG(y); rect.width = NUM2ULONG(width); rect.height = NUM2ULONG(height); - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = ExcerptImage(image, &rect, exception); + GVL_STRUCT_TYPE(ExcerptImage) args = { image, &rect, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ExcerptImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -6246,11 +6599,11 @@ { Image *image; long x_off = 0L, y_off = 0L; unsigned long cols, rows; long n, npixels; - unsigned int okay; + MagickBooleanType okay; const char *map = "RGB"; Quantum *pixels; VALUE ary; ExceptionInfo *exception; @@ -6293,11 +6646,12 @@ return rb_ary_new2(0L); } exception = AcquireExceptionInfo(); - okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, QuantumPixel, (void *)pixels, exception); + GVL_STRUCT_TYPE(ExportImagePixels) args = { image, x_off, y_off, cols, rows, map, QuantumPixel, (void *)pixels, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ExportImagePixels), &args); if (!okay) { xfree((void *)pixels); CHECK_EXCEPTION(); @@ -6375,14 +6729,15 @@ width, height, geometry.x, geometry.y); } } - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = ExtentImage(image, &geometry, exception); + GVL_STRUCT_TYPE(ExtentImage) args = { image, &geometry, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ExtentImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -6410,11 +6765,11 @@ Image *image; long x_off = 0L, y_off = 0L; unsigned long cols, rows; unsigned long npixels; size_t sz; - unsigned int okay; + MagickBooleanType okay; const char *map = "RGB"; StorageType type = CharPixel; VALUE string; ExceptionInfo *exception; @@ -6483,11 +6838,12 @@ string = rb_str_new2(""); rb_str_resize(string, (long)(sz * npixels)); exception = AcquireExceptionInfo(); - okay = ExportImagePixels(image, x_off, y_off, cols, rows, map, type, (void *)RSTRING_PTR(string), exception); + GVL_STRUCT_TYPE(ExportImagePixels) args = { image, x_off, y_off, cols, rows, map, type, (void *)RSTRING_PTR(string), exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ExportImagePixels), &args); if (!okay) { // Let GC have the string buffer. rb_str_resize(string, 0); CHECK_EXCEPTION(); @@ -6538,11 +6894,11 @@ * @return [String] the filename */ VALUE Image_filename(VALUE self) { - IMPLEMENT_ATTR_READER(Image, filename, str); + IMPLEMENT_TYPED_ATTR_READER(Image, filename, str, &rm_image_data_type); } /** * Return the image file size. @@ -6605,11 +6961,11 @@ { Image *image, *target; VALUE region, targ; ssize_t x = 0L, y = 0L; ExceptionInfo *exception; - unsigned int okay; + MagickBooleanType okay; image = rm_check_destroyed(self); switch (argc) { @@ -6625,11 +6981,17 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 3)", argc); break; } exception = AcquireExceptionInfo(); - okay = IsEquivalentImage(image, target, &x, &y, exception); +#if defined(IMAGEMAGICK_7) + GVL_STRUCT_TYPE(IsEquivalentImage) args = { image, target, &x, &y, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(IsEquivalentImage), &args); +#else + GVL_STRUCT_TYPE(IsImageSimilar) args = { image, target, &x, &y, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(IsImageSimilar), &args); +#endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); if (!okay) { @@ -6645,10 +7007,13 @@ return region; } +// aliases for common use of structure types; FlopImage, FlipImage +typedef GVL_STRUCT_TYPE(FlipImage) GVL_STRUCT_TYPE(flipflop); + /** * Call a flipflopper (a function that either flips or flops the image). * * No Ruby usage (internal function) * @@ -6660,19 +7025,20 @@ * @see Image_flip_bang * @see Image_flop * @see Image_flop_bang */ static VALUE -flipflop(int bang, VALUE self, flipper_t flipflopper) +flipflop(int bang, VALUE self, gvl_function_t fp) { Image *image, *new_image; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = (flipflopper)(image, exception); + GVL_STRUCT_TYPE(flipflop) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -6696,11 +7062,11 @@ */ VALUE Image_flip(VALUE self) { rm_check_destroyed(self); - return flipflop(False, self, FlipImage); + return flipflop(False, self, GVL_FUNC(FlipImage)); } /** * Create a vertical mirror image by reflecting the pixels around the central x-axis. @@ -6713,11 +7079,11 @@ */ VALUE Image_flip_bang(VALUE self) { rm_check_frozen(self); - return flipflop(True, self, FlipImage); + return flipflop(True, self, GVL_FUNC(FlipImage)); } /** * Create a horizonal mirror image by reflecting the pixels around the central y-axis. @@ -6729,11 +7095,11 @@ */ VALUE Image_flop(VALUE self) { rm_check_destroyed(self); - return flipflop(False, self, FlopImage); + return flipflop(False, self, GVL_FUNC(FlopImage)); } /** * Create a horizonal mirror image by reflecting the pixels around the central y-axis. @@ -6746,11 +7112,11 @@ */ VALUE Image_flop_bang(VALUE self) { rm_check_frozen(self); - return flipflop(True, self, FlopImage); + return flipflop(True, self, GVL_FUNC(FlopImage)); } /** * Return the image encoding format. For example, "GIF" or "PNG". @@ -6866,14 +7232,15 @@ break; } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = FrameImage(image, &frame_info, image->compose, exception); + GVL_STRUCT_TYPE(FrameImage) args = { image, &frame_info, image->compose, exception }; #else - new_image = FrameImage(image, &frame_info, exception); + GVL_STRUCT_TYPE(FrameImage) args = { image, &frame_info, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FrameImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -6905,14 +7272,15 @@ blob = (void *) rm_str2cstr(blob_arg, &length); // Get a new Info object - run the parm block if supplied info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); exception = AcquireExceptionInfo(); - images = BlobToImage(info, blob, (size_t)length, exception); + GVL_STRUCT_TYPE(BlobToImage) args = { info, blob, (size_t)length, exception }; + images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args); rm_check_exception(exception, images, DestroyOnError); DestroyExceptionInfo(exception); rm_ensure_result(images); @@ -7008,14 +7376,16 @@ exception = AcquireExceptionInfo(); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(new_image, channels); - FunctionImage(new_image, function, nparms, parms, exception); + GVL_STRUCT_TYPE(FunctionImage) args = { new_image, function, nparms, parms, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FunctionImage), &args); END_CHANNEL_MASK(new_image); #else - FunctionImageChannel(new_image, channels, function, nparms, parms, exception); + GVL_STRUCT_TYPE(FunctionImageChannel) args = { new_image, channels, function, nparms, parms, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FunctionImageChannel), &args); #endif xfree(parms); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -7032,11 +7402,11 @@ * @see Info#fuzz */ VALUE Image_fuzz(VALUE self) { - IMPLEMENT_ATTR_READER(Image, fuzz, dbl); + IMPLEMENT_TYPED_ATTR_READER(Image, fuzz, dbl, &rm_image_data_type); } /** * Set the number of algorithms search for a target color. @@ -7092,15 +7462,17 @@ expression = StringValueCStr(argv[0]); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = FxImage(image, expression, exception); + GVL_STRUCT_TYPE(FxImage) args = { image, expression, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FxImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = FxImageChannel(image, channels, expression, exception); + GVL_STRUCT_TYPE(FxImageChannel) args = { image, channels, expression, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FxImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -7112,11 +7484,11 @@ * @return [Float] the gamma level */ VALUE Image_gamma(VALUE self) { - IMPLEMENT_ATTR_READER(Image, gamma, dbl); + IMPLEMENT_TYPED_ATTR_READER(Image, gamma, dbl, &rm_image_data_type); } /** * Set the gamma level of the image. * @@ -7124,11 +7496,11 @@ * @return [Float] the gamma level */ VALUE Image_gamma_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, gamma, dbl); + IMPLEMENT_TYPED_ATTR_WRITER(Image, gamma, dbl, &rm_image_data_type); } /** * Apply gamma to a channel. @@ -7172,16 +7544,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - GammaImage(new_image, gamma, exception); + GVL_STRUCT_TYPE(GammaImage) args = { new_image, gamma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - GammaImageChannel(new_image, channels, gamma); + GVL_STRUCT_TYPE(GammaImageChannel) args = { new_image, channels, gamma }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -7233,34 +7607,44 @@ if ((red_gamma == green_gamma) && (green_gamma == blue_gamma)) { #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(new_image, (ChannelType) (RedChannel | GreenChannel | BlueChannel)); - GammaImage(new_image, red_gamma, exception); + GVL_STRUCT_TYPE(GammaImage) args = { new_image, red_gamma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImage), &args); END_CHANNEL_MASK(new_image); #else - GammaImageChannel(new_image, (ChannelType) (RedChannel | GreenChannel | BlueChannel), red_gamma); + GVL_STRUCT_TYPE(GammaImageChannel) args = { new_image, (ChannelType) (RedChannel | GreenChannel | BlueChannel), red_gamma }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImageChannel), &args); #endif } else { #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(new_image, RedChannel); - GammaImage(new_image, red_gamma, exception); + GVL_STRUCT_TYPE(GammaImage) args1 = { new_image, red_gamma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImage), &args1); END_CHANNEL_MASK(new_image); BEGIN_CHANNEL_MASK(new_image, GreenChannel); - GammaImage(new_image, green_gamma, exception); + GVL_STRUCT_TYPE(GammaImage) args2 = { new_image, green_gamma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImage), &args2); END_CHANNEL_MASK(new_image); BEGIN_CHANNEL_MASK(new_image, BlueChannel); - GammaImage(new_image, blue_gamma, exception); + GVL_STRUCT_TYPE(GammaImage) args3 = { new_image, blue_gamma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImage), &args3); END_CHANNEL_MASK(new_image); #else - GammaImageChannel(new_image, RedChannel, red_gamma); - GammaImageChannel(new_image, GreenChannel, green_gamma); - GammaImageChannel(new_image, BlueChannel, blue_gamma); + GVL_STRUCT_TYPE(GammaImageChannel) args1 = { new_image, RedChannel, red_gamma }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImageChannel), &args1); + + GVL_STRUCT_TYPE(GammaImageChannel) args2 = { new_image, GreenChannel, green_gamma }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImageChannel), &args2); + + GVL_STRUCT_TYPE(GammaImageChannel) args3 = { new_image, BlueChannel, blue_gamma }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GammaImageChannel), &args3); #endif } #if defined(IMAGEMAGICK_7) CHECK_EXCEPTION(); @@ -7282,11 +7666,11 @@ * @return [Magick::Image] a new image */ VALUE Image_gaussian_blur(int argc, VALUE *argv, VALUE self) { - return effect_image(self, argc, argv, GaussianBlurImage); + return effect_image(self, argc, argv, GVL_FUNC(GaussianBlurImage)); } /** * Blur the image on a channel. @@ -7330,16 +7714,18 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = GaussianBlurImage(image, radius, sigma, exception); + GVL_STRUCT_TYPE(GaussianBlurImage) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GaussianBlurImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); rm_check_exception(exception, new_image, DestroyOnError); #else - new_image = GaussianBlurImageChannel(image, channels, radius, sigma, exception); + GVL_STRUCT_TYPE(GaussianBlurImageChannel) args = { image, channels, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GaussianBlurImageChannel), &args); rm_check_exception(exception, new_image, DestroyOnError); #endif DestroyExceptionInfo(exception); @@ -7354,11 +7740,11 @@ * @see https://www.imagemagick.org/Magick++/Geometry.html */ VALUE Image_geometry(VALUE self) { - IMPLEMENT_ATTR_READER(Image, geometry, str); + IMPLEMENT_TYPED_ATTR_READER(Image, geometry, str, &rm_image_data_type); } /** * Set the preferred size of the image when encoding. @@ -7438,11 +7824,12 @@ } // 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. exception = AcquireExceptionInfo(); - pixels = GetVirtualPixels(image, x, y, columns, rows, exception); + GVL_STRUCT_TYPE(GetVirtualPixels) args = { image, x, y, columns, rows, exception }; + pixels = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetVirtualPixels), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); // If the function failed, return a 0-length array. @@ -7615,14 +8002,15 @@ image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = ImplodeImage(image, amount, image->interpolate, exception); + GVL_STRUCT_TYPE(ImplodeImage) args = { image, amount, image->interpolate, exception }; #else - new_image = ImplodeImage(image, amount, exception); + GVL_STRUCT_TYPE(ImplodeImage) args = { image, amount, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImplodeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -7658,11 +8046,11 @@ StorageType stg_type = CharPixel; size_t type_sz, map_l; Quantum *pixels = NULL; double *fpixels = NULL; void *buffer; - unsigned int okay; + MagickBooleanType okay; #if defined(IMAGEMAGICK_7) ExceptionInfo *exception; #endif image = rm_check_frozen(self); @@ -7795,14 +8183,15 @@ } #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = ImportImagePixels(image, x_off, y_off, cols, rows, map, stg_type, buffer, exception); + GVL_STRUCT_TYPE(ImportImagePixels) args = { image, x_off, y_off, cols, rows, map, stg_type, buffer, exception }; #else - okay = ImportImagePixels(image, x_off, y_off, cols, rows, map, stg_type, buffer); + GVL_STRUCT_TYPE(ImportImagePixels) args = { image, x_off, y_off, cols, rows, map, stg_type, buffer }; #endif + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImportImagePixels), &args); // Free pixel array before checking for errors. if (pixels) { xfree((void *)pixels); @@ -7985,11 +8374,11 @@ Image_inspect(VALUE self) { Image *image; char buffer[MaxTextExtent]; // image description buffer - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); if (!image) { return rb_str_new2("#<Magick::Image: (destroyed)>"); } build_inspect_string(image, buffer, sizeof(buffer)); @@ -8078,16 +8467,16 @@ * The reader is only used by the unit tests! */ VALUE Image_iterations(VALUE self) { - IMPLEMENT_ATTR_READER(Image, iterations, int); + IMPLEMENT_TYPED_ATTR_READER(Image, iterations, int, &rm_image_data_type); } VALUE Image_iterations_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, iterations, int); + IMPLEMENT_TYPED_ATTR_WRITER(Image, iterations, int, &rm_image_data_type); } /** * Adjusts the levels of an image by scaling the colors falling between specified white and black * points to the full available quantum range. @@ -8134,16 +8523,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - LevelImage(new_image, black_point, white_point, gamma_val, exception); + GVL_STRUCT_TYPE(LevelImage) args = { new_image, black_point, white_point, gamma_val, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else snprintf(level, sizeof(level), "%gx%g+%g", black_point, white_point, gamma_val); - LevelImage(new_image, level); + GVL_STRUCT_TYPE(LevelImage) args = { new_image, level }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -8198,16 +8589,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channel); - LevelImage(new_image, black_point, white_point, gamma_val, exception); + GVL_STRUCT_TYPE(LevelImage) args = { new_image, black_point, white_point, gamma_val, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - LevelImageChannel(new_image, channel, black_point, white_point, gamma_val); + GVL_STRUCT_TYPE(LevelImageChannel) args = { new_image, channel, black_point, white_point, gamma_val }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -8279,16 +8672,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - status = LevelImageColors(new_image, &black_color, &white_color, invert, exception); + GVL_STRUCT_TYPE(LevelImageColors) args = { new_image, &black_color, &white_color, invert, exception }; + status = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelImageColors), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - status = LevelColorsImageChannel(new_image, channels, &black_color, &white_color, invert); + GVL_STRUCT_TYPE(LevelColorsImageChannel) args = { new_image, channels, &black_color, &white_color, invert }; + status = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelColorsImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif if (!status) { rb_raise(rb_eRuntimeError, "LevelImageColors failed for unknown reason."); @@ -8354,16 +8749,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - status = LevelizeImage(new_image, black_point, white_point, gamma, exception); + GVL_STRUCT_TYPE(LevelizeImage) args = { new_image, black_point, white_point, gamma, exception }; + status = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelizeImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - status = LevelizeImageChannel(new_image, channels, black_point, white_point, gamma); + GVL_STRUCT_TYPE(LevelizeImageChannel) args = { new_image, channels, black_point, white_point, gamma }; + status = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LevelizeImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif if (!status) { @@ -8400,15 +8797,17 @@ get_black_white_point(image, argc, argv, &black_point, &white_point); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - LinearStretchImage(new_image, black_point, white_point, exception); + GVL_STRUCT_TYPE(LinearStretchImage) args = { new_image, black_point, white_point, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LinearStretchImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - LinearStretchImage(new_image, black_point, white_point); + GVL_STRUCT_TYPE(LinearStretchImage) args = { new_image, black_point, white_point }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LinearStretchImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -8450,11 +8849,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 4)", argc); break; } exception = AcquireExceptionInfo(); - new_image = LiquidRescaleImage(image, cols, rows, delta_x, rigidity, exception); + GVL_STRUCT_TYPE(LiquidRescaleImage) args = { image, cols, rows, delta_x, rigidity, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(LiquidRescaleImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -8518,20 +8918,24 @@ exception = AcquireExceptionInfo(); blob += offsetof(DumpedImage, magick) + mi.len; length -= offsetof(DumpedImage, magick) + mi.len; - image = BlobToImage(info, blob, (size_t) length, exception); + GVL_STRUCT_TYPE(BlobToImage) args = { info, blob, (size_t)length, exception }; + image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args); DestroyImageInfo(info); rm_check_exception(exception, image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(image); } +// aliases for common use of structure types; MagnifyImage, MinifyImage +typedef GVL_STRUCT_TYPE(MagnifyImage) GVL_STRUCT_TYPE(magnify); + /** * Scale an image proportionally to twice its size. * * No Ruby usage (internal function) * @@ -8539,20 +8943,21 @@ * @param self this object * @param magnifier function to use for magnification * @return self if bang, otherwise a new image */ static VALUE -magnify(int bang, VALUE self, magnifier_t magnifier) +magnify(int bang, VALUE self, gvl_function_t fp) { Image *image; Image *new_image; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = (magnifier)(image, exception); + GVL_STRUCT_TYPE(magnify) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) @@ -8575,11 +8980,11 @@ */ VALUE Image_magnify(VALUE self) { rm_check_destroyed(self); - return magnify(False, self, MagnifyImage); + return magnify(False, self, GVL_FUNC(MagnifyImage)); } /** * Scale an image proportionally to twice its size. @@ -8590,11 +8995,11 @@ */ VALUE Image_magnify_bang(VALUE self) { rm_check_frozen(self); - return magnify(True, self, MagnifyImage); + return magnify(True, self, GVL_FUNC(MagnifyImage)); } /** * Support Marshal.dump. @@ -8622,11 +9027,12 @@ ary = rb_ary_new2(2); rb_ary_store(ary, 0, rb_str_new2(image->filename)); exception = AcquireExceptionInfo(); - blob = ImageToBlob(info, image, &length, exception); + GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception }; + blob = (unsigned char *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args); // Destroy info before raising an exception DestroyImageInfo(info); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -8667,11 +9073,12 @@ exception = AcquireExceptionInfo(); if (filename != Qnil) { strlcpy(info->filename, RSTRING_PTR(filename), sizeof(info->filename)); } - image = BlobToImage(info, RSTRING_PTR(blob), RSTRING_LEN(blob), exception); + GVL_STRUCT_TYPE(BlobToImage) args = { info, RSTRING_PTR(blob), RSTRING_LEN(blob), exception }; + image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args); // Destroy info before raising an exception DestroyImageInfo(info); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -8700,13 +9107,15 @@ exception = AcquireExceptionInfo(); // The returned clip mask is a clone, ours to keep. #if defined(IMAGEMAGICK_7) - mask = GetImageMask(image, WritePixelMask, exception); + GVL_STRUCT_TYPE(GetImageMask) args = { image, WritePixelMask, exception }; + mask = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageMask), &args); #else - mask = GetImageClipMask(image, exception); + GVL_STRUCT_TYPE(GetImageClipMask) args = { image, exception }; + mask = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetImageClipMask), &args); #endif rm_check_exception(exception, mask, DestroyOnError); DestroyExceptionInfo(exception); @@ -8740,23 +9149,26 @@ clip_mask = rm_clone_image(mask_image); // Resize if necessary if (clip_mask->columns != image->columns || clip_mask->rows != image->rows) { - resized_image = ResizeImage(clip_mask, image->columns, image->rows, image->filter, exception); + GVL_STRUCT_TYPE(ResizeImage) args = { clip_mask, image->columns, image->rows, image->filter, exception }; + resized_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResizeImage), &args); DestroyImage(clip_mask); rm_check_exception(exception, resized_image, DestroyOnError); rm_ensure_result(resized_image); clip_mask = resized_image; } - SetImageMask(image, WritePixelMask, clip_mask, exception); + GVL_STRUCT_TYPE(SetImageMask) args = { image, WritePixelMask, clip_mask, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args); DestroyImage(clip_mask); } else { - SetImageMask(image, WritePixelMask, NULL, exception); + GVL_STRUCT_TYPE(SetImageMask) args = { image, WritePixelMask, NULL, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageMask), &args); } CHECK_EXCEPTION(); DestroyExceptionInfo(exception); // Always return a copy of the mask! @@ -8780,12 +9192,12 @@ // Resize if necessary if (clip_mask->columns != image->columns || clip_mask->rows != image->rows) { exception = AcquireExceptionInfo(); - resized_image = ResizeImage(clip_mask, image->columns, image->rows, - UndefinedFilter, 0.0, exception); + GVL_STRUCT_TYPE(ResizeImage) args = { clip_mask, image->columns, image->rows, UndefinedFilter, 0.0, exception }; + resized_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResizeImage), &args); rm_check_exception(exception, resized_image, DestroyOnError); DestroyExceptionInfo(exception); rm_ensure_result(resized_image); DestroyImage(clip_mask); clip_mask = resized_image; @@ -8794,11 +9206,12 @@ // The following section is copied from mogrify.c (6.2.8-8) exception = AcquireExceptionInfo(); for (y = 0; y < (long) clip_mask->rows; y++) { - q = GetAuthenticPixels(clip_mask, 0, y, clip_mask->columns, 1, exception); + GVL_STRUCT_TYPE(GetAuthenticPixels) args_GetAuthenticPixels = { clip_mask, 0, y, clip_mask->columns, 1, exception }; + q = (PixelPacket *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetAuthenticPixels), &args_GetAuthenticPixels); rm_check_exception(exception, clip_mask, DestroyOnError); if (!q) { break; @@ -8813,29 +9226,33 @@ q->green = q->opacity; q->blue = q->opacity; q += 1; } - SyncAuthenticPixels(clip_mask, exception); + GVL_STRUCT_TYPE(SyncAuthenticPixels) args_SyncAuthenticPixels = { clip_mask, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncAuthenticPixels), &args_SyncAuthenticPixels); rm_check_exception(exception, clip_mask, DestroyOnError); } DestroyExceptionInfo(exception); - SetImageStorageClass(clip_mask, DirectClass); + GVL_STRUCT_TYPE(SetImageStorageClass) args_SetImageStorageClass = { clip_mask, DirectClass }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args_SetImageStorageClass); rm_check_image_exception(clip_mask, DestroyOnError); clip_mask->matte = MagickTrue; // SetImageClipMask clones the clip_mask image. We can // destroy our copy after SetImageClipMask is done with it. - SetImageClipMask(image, clip_mask); + GVL_STRUCT_TYPE(SetImageClipMask) args_SetImageClipMask = { image, clip_mask }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageClipMask), &args_SetImageClipMask); DestroyImage(clip_mask); } else { - SetImageClipMask(image, NULL); + GVL_STRUCT_TYPE(SetImageClipMask) args_SetImageClipMask = { image, NULL }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageClipMask), &args_SetImageClipMask); } RB_GC_GUARD(mask); // Always return a copy of the mask! @@ -9005,17 +9422,19 @@ } #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, OpacityChannel); - FloodfillPaintImage(new_image, draw_info, &target_mpp, x, y, invert, exception); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, draw_info, &target_mpp, x, y, invert, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); END_CHANNEL_MASK(new_image); DestroyDrawInfo(draw_info); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - FloodfillPaintImage(new_image, OpacityChannel, draw_info, &target_mpp, x, y, invert); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, OpacityChannel, draw_info, &target_mpp, x, y, invert }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); DestroyDrawInfo(draw_info); rm_check_image_exception(new_image, DestroyOnError); #endif @@ -9049,11 +9468,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } exception = AcquireExceptionInfo(); - new_image = StatisticImage(image, MedianStatistic, (size_t)radius, (size_t)radius, exception); + GVL_STRUCT_TYPE(StatisticImage) args = { image, MedianStatistic, (size_t)radius, (size_t)radius, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(StatisticImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -9065,11 +9485,11 @@ * @return [Float] the mean error per pixel */ VALUE Image_mean_error_per_pixel(VALUE self) { - IMPLEMENT_ATTR_READERF(Image, mean_error_per_pixel, error.mean_error_per_pixel, dbl); + IMPLEMENT_TYPED_ATTR_READERF(Image, mean_error_per_pixel, error.mean_error_per_pixel, dbl, &rm_image_data_type); } /** * Return the officially registered (or de facto) MIME media-type corresponding to the image format. @@ -9108,11 +9528,11 @@ */ VALUE Image_minify(VALUE self) { rm_check_destroyed(self); - return magnify(False, self, MinifyImage); + return magnify(False, self, GVL_FUNC(MinifyImage)); } /** * Scale an image proportionally to half its size. In-place form of {Image#minify}. @@ -9122,11 +9542,11 @@ */ VALUE Image_minify_bang(VALUE self) { rm_check_frozen(self); - return magnify(True, self, MinifyImage); + return magnify(True, self, GVL_FUNC(MinifyImage)); } /** * Changes the brightness, saturation, and hue. @@ -9174,15 +9594,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - ModulateImage(new_image, modulate, exception); + GVL_STRUCT_TYPE(ModulateImage) args = { new_image, modulate, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ModulateImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - ModulateImage(new_image, modulate); + GVL_STRUCT_TYPE(ModulateImage) args = { new_image, modulate }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ModulateImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -9211,14 +9633,17 @@ * @return [String] the tile size and offset */ VALUE Image_montage(VALUE self) { - IMPLEMENT_ATTR_READER(Image, montage, str); + IMPLEMENT_TYPED_ATTR_READER(Image, montage, str, &rm_image_data_type); } +// aliases for common use of structure types; MotionBlurImage, SketchImage +typedef GVL_STRUCT_TYPE(MotionBlurImage) GVL_STRUCT_TYPE(motion_blur); + /** * Called from Image_motion_blur and Image_sketch. * * No Ruby usage (internal function) * @@ -9229,12 +9654,11 @@ * @return a new image * @see Image_motion_blur * @see Image_sketch */ static VALUE -motion_blur(int argc, VALUE *argv, VALUE self, - Image *fp(const Image *, const double, const double, const double, ExceptionInfo *)) +motion_blur(int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; double radius = 0.0; double sigma = 1.0; double angle = 0.0; @@ -9258,14 +9682,15 @@ if (sigma == 0.0) { rb_raise(rb_eArgError, "sigma must be != 0.0"); } - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = (fp)(image, radius, sigma, angle, exception); + GVL_STRUCT_TYPE(motion_blur) args = { image, radius, sigma, angle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -9285,11 +9710,11 @@ */ VALUE Image_motion_blur(int argc, VALUE *argv, VALUE self) { rm_check_destroyed(self); - return motion_blur(argc, argv, self, MotionBlurImage); + return motion_blur(argc, argv, self, GVL_FUNC(MotionBlurImage)); } /** * Negate the colors in the reference image. The grayscale option means that only grayscale values @@ -9320,15 +9745,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - NegateImage(new_image, grayscale, exception); + GVL_STRUCT_TYPE(NegateImage) args = { new_image, grayscale, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - NegateImage(new_image, grayscale); + GVL_STRUCT_TYPE(NegateImage) args = { new_image, grayscale }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -9377,16 +9804,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - NegateImage(new_image, grayscale, exception); + GVL_STRUCT_TYPE(NegateImage) args = { new_image, grayscale, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - NegateImageChannel(new_image, channels, grayscale); + GVL_STRUCT_TYPE(NegateImageChannel) args = { new_image, channels, grayscale }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NegateImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -9400,11 +9829,11 @@ VALUE Image_alloc(VALUE class) { VALUE image_obj; - image_obj = Data_Wrap_Struct(class, NULL, rm_image_destroy, NULL); + image_obj = TypedData_Wrap_Struct(class, &rm_image_data_type, NULL); RB_GC_GUARD(image_obj); return image_obj; } @@ -9444,11 +9873,11 @@ break; } // Create a new Info object to use when creating this image. info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); image = rm_acquire_image(info); if (!image) { rb_raise(rb_eNoMemError, "not enough memory to continue"); @@ -9459,29 +9888,33 @@ // NOW store a real image in the image object. UPDATE_DATA_PTR(self, image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageExtent(image, cols, rows, exception); + GVL_STRUCT_TYPE(SetImageExtent) args = { image, cols, rows, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageExtent), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageExtent(image, cols, rows); + GVL_STRUCT_TYPE(SetImageExtent) args = { image, cols, rows }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageExtent), &args); #endif // If the caller did not supply a fill argument, call SetImageBackgroundColor // to fill the image using the background color. The background color can // be set by specifying it when creating the Info parm block. if (NIL_P(fill)) { #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageBackgroundColor(image, exception); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageBackgroundColor(image); + GVL_STRUCT_TYPE(SetImageBackgroundColor) args = { image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageBackgroundColor), &args); #endif } // fillobj.fill(self) else { @@ -9510,11 +9943,11 @@ VALUE rm_image_new(Image *image) { rm_ensure_result(image); - return Data_Wrap_Struct(Class_Image, NULL, rm_image_destroy, image); + return TypedData_Wrap_Struct(Class_Image, &rm_image_data_type, image); } /** * Enhance the contrast of a color image by adjusting the pixels color to span the entire range of @@ -9533,15 +9966,17 @@ image = rm_check_destroyed(self); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - NormalizeImage(new_image, exception); + GVL_STRUCT_TYPE(NormalizeImage) args = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NormalizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - NormalizeImage(new_image); + GVL_STRUCT_TYPE(NormalizeImage) args = { new_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NormalizeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -9575,16 +10010,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - NormalizeImage(new_image, exception); + GVL_STRUCT_TYPE(NormalizeImage) args = { new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NormalizeImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - NormalizeImageChannel(new_image, channels); + GVL_STRUCT_TYPE(NormalizeImageChannel) args = { new_image, channels }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(NormalizeImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -9596,22 +10033,22 @@ * @return [Float] the normalized mean error */ VALUE Image_normalized_mean_error(VALUE self) { - IMPLEMENT_ATTR_READERF(Image, normalized_mean_error, error.normalized_mean_error, dbl); + IMPLEMENT_TYPED_ATTR_READERF(Image, normalized_mean_error, error.normalized_mean_error, dbl, &rm_image_data_type); } /** * Get The normalized maximum error per pixel computed when an image is color reduced. * * @return [Float] the normalized maximum error */ VALUE Image_normalized_maximum_error(VALUE self) { - IMPLEMENT_ATTR_READERF(Image, normalized_maximum_error, error.normalized_maximum_error, dbl); + IMPLEMENT_TYPED_ATTR_READERF(Image, normalized_maximum_error, error.normalized_maximum_error, dbl, &rm_image_data_type); } /** * Return the number of unique colors in the image. @@ -9621,16 +10058,17 @@ VALUE Image_number_colors(VALUE self) { Image *image; ExceptionInfo *exception; - unsigned long n = 0; + size_t n = 0; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - n = (unsigned long) GetNumberColors(image, NULL, exception); + GVL_STRUCT_TYPE(GetNumberColors) args = { image, NULL, exception }; + n = (size_t)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetNumberColors), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); return ULONG2NUM(n); @@ -9643,11 +10081,11 @@ * @return [Number] the offset */ VALUE Image_offset(VALUE self) { - IMPLEMENT_ATTR_READER(Image, offset, long); + IMPLEMENT_TYPED_ATTR_READER(Image, offset, long, &rm_image_data_type); } /** * Set the number of bytes to skip over when reading raw image. * @@ -9655,11 +10093,11 @@ * @return [Number] the given offset */ VALUE Image_offset_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, offset, long); + IMPLEMENT_TYPED_ATTR_WRITER(Image, offset, long, &rm_image_data_type); } /** * Apply a special effect filter that simulates an oil painting. @@ -9691,14 +10129,15 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = OilPaintImage(image, radius, sigma, exception); + GVL_STRUCT_TYPE(OilPaintImage) args = { image, radius, sigma, exception }; #else - new_image = OilPaintImage(image, radius, exception); + GVL_STRUCT_TYPE(OilPaintImage) args = { image, radius, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OilPaintImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -9735,15 +10174,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = OpaquePaintImage(new_image, &target_pp, &fill_pp, MagickFalse, exception); + GVL_STRUCT_TYPE(OpaquePaintImage) args = { new_image, &target_pp, &fill_pp, MagickFalse, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - okay = OpaquePaintImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp, MagickFalse); + GVL_STRUCT_TYPE(OpaquePaintImageChannel) args = { new_image, DefaultChannels, &target_pp, &fill_pp, MagickFalse }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif if (!okay) { @@ -9825,17 +10266,19 @@ new_image->fuzz = fuzz; #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - okay = OpaquePaintImage(new_image, &target_pp, &fill_pp, invert, exception); + GVL_STRUCT_TYPE(OpaquePaintImage) args = { new_image, &target_pp, &fill_pp, invert, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImage), &args); END_CHANNEL_MASK(new_image); new_image->fuzz = keep; rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - okay = OpaquePaintImageChannel(new_image, channels, &target_pp, &fill_pp, invert); + GVL_STRUCT_TYPE(OpaquePaintImageChannel) args = { new_image, channels, &target_pp, &fill_pp, invert }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OpaquePaintImageChannel), &args); new_image->fuzz = keep; rm_check_image_exception(new_image, DestroyOnError); #endif @@ -9916,11 +10359,17 @@ new_image = rm_clone_image(image); exception = AcquireExceptionInfo(); - OrderedDitherImage(new_image, threshold_map, exception); +#if defined(IMAGEMAGICK_7) + GVL_STRUCT_TYPE(OrderedDitherImage) args = { new_image, threshold_map, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OrderedDitherImage), &args); +#else + GVL_STRUCT_TYPE(OrderedPosterizeImage) args = { new_image, threshold_map, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(OrderedPosterizeImage), &args); +#endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -10051,16 +10500,18 @@ keep = new_image->fuzz; new_image->fuzz = fuzz; #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = TransparentPaintImage(new_image, (const MagickPixel *)&color, alpha, invert, exception); + GVL_STRUCT_TYPE(TransparentPaintImage) args = { new_image, (const MagickPixel *)&color, alpha, invert, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImage), &args); new_image->fuzz = keep; rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - okay = TransparentPaintImage(new_image, (const MagickPixel *)&color, QuantumRange - alpha, invert); + GVL_STRUCT_TYPE(TransparentPaintImage) args = { new_image, (const MagickPixel *)&color, QuantumRange - alpha, invert }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImage), &args); new_image->fuzz = keep; // Is it possible for TransparentPaintImage to silently fail? rm_check_image_exception(new_image, DestroyOnError); #endif @@ -10099,11 +10550,11 @@ * @see Image#read */ VALUE Image_ping(VALUE class, VALUE file_arg) { - return rd_image(class, file_arg, PingImage); + return rd_image(class, file_arg, GVL_FUNC(PingImage)); } /** * Get/set the color of the pixel at x, y. @@ -10165,11 +10616,12 @@ // Get the color of a pixel if (!set) { exception = AcquireExceptionInfo(); - old_pixel = GetVirtualPixels(image, x, y, 1, 1, exception); + GVL_STRUCT_TYPE(GetVirtualPixels) args = { image, x, y, 1, 1, exception }; + old_pixel = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetVirtualPixels), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #if defined(IMAGEMAGICK_7) @@ -10217,19 +10669,21 @@ #endif if (image->storage_class == PseudoClass) { #if defined(IMAGEMAGICK_7) - okay = SetImageStorageClass(image, DirectClass, exception); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, DirectClass, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); CHECK_EXCEPTION(); if (!okay) { DestroyExceptionInfo(exception); rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't set pixel color."); } #else - okay = SetImageStorageClass(image, DirectClass); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, DirectClass }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); rm_check_image_exception(image, RetainOnError); if (!okay) { rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't set pixel color."); } @@ -10238,11 +10692,12 @@ #if defined(IMAGEMAGICK_6) exception = AcquireExceptionInfo(); #endif - pixel = GetAuthenticPixels(image, x, y, 1, 1, exception); + GVL_STRUCT_TYPE(GetAuthenticPixels) args = { image, x, y, 1, 1, exception }; + pixel = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetAuthenticPixels), &args); CHECK_EXCEPTION(); if (pixel) { #if defined(IMAGEMAGICK_7) @@ -10273,11 +10728,12 @@ { SetPixelIndex(indexes, new_color.black); } #endif - SyncAuthenticPixels(image, exception); + GVL_STRUCT_TYPE(SyncAuthenticPixels) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncAuthenticPixels), &args); CHECK_EXCEPTION(); } DestroyExceptionInfo(exception); @@ -10362,22 +10818,24 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); break; } options = rm_polaroid_new(); - Data_Get_Struct(options, Draw, draw); + TypedData_Get_Struct(options, Draw, &rm_draw_data_type, draw); clone = rm_clone_image(image); clone->background_color = draw->shadow_color; clone->border_color = draw->info->border_color; exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) caption = GetImageProperty(clone, "Caption", exception); - new_image = PolaroidImage(clone, draw->info, caption, angle, image->interpolate, exception); + GVL_STRUCT_TYPE(PolaroidImage) args = { clone, draw->info, caption, angle, image->interpolate, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PolaroidImage), &args); #else - new_image = PolaroidImage(clone, draw->info, angle, exception); + GVL_STRUCT_TYPE(PolaroidImage) args = { clone, draw->info, angle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PolaroidImage), &args); #endif rm_check_exception(exception, clone, DestroyOnError); DestroyImage(clone); DestroyExceptionInfo(exception); @@ -10425,15 +10883,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); dither_method = dither ? RiemersmaDitherMethod : NoDitherMethod; - PosterizeImage(new_image, levels, dither_method, exception); + GVL_STRUCT_TYPE(PosterizeImage) args = { new_image, levels, dither_method, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PosterizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - PosterizeImage(new_image, levels, dither); + GVL_STRUCT_TYPE(PosterizeImage) args = { new_image, levels, dither }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PosterizeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -10455,11 +10915,12 @@ image = rm_check_destroyed(self); VALUE_TO_ENUM(preview, preview_type, PreviewType); exception = AcquireExceptionInfo(); - new_image = PreviewImage(image, preview_type, exception); + GVL_STRUCT_TYPE(PreviewImage) args = { image, preview_type, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(PreviewImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -10496,11 +10957,11 @@ * @return [Numeric] the quality */ VALUE Image_quality(VALUE self) { - IMPLEMENT_ATTR_READER(Image, quality, ulong); + IMPLEMENT_TYPED_ATTR_READER(Image, quality, ulong, &rm_image_data_type); } /** * Return the image depth to the nearest Quantum (8, 16, or 32). @@ -10682,14 +11143,16 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channel); - EvaluateImage(image, qop, rvalue, exception); + GVL_STRUCT_TYPE(EvaluateImage) args = { image, qop, rvalue, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EvaluateImage), &args); END_CHANNEL_MASK(image); #else - EvaluateImageChannel(image, channel, qop, rvalue, exception); + GVL_STRUCT_TYPE(EvaluateImageChannel) args = { image, channel, qop, rvalue, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(EvaluateImageChannel), &args); #endif CHECK_EXCEPTION(); DestroyExceptionInfo(exception); @@ -10762,15 +11225,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - QuantizeImage(&quantize_info, new_image, exception); + GVL_STRUCT_TYPE(QuantizeImage) args = { &quantize_info, new_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(QuantizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - QuantizeImage(&quantize_info, new_image); + GVL_STRUCT_TYPE(QuantizeImage) args = { &quantize_info, new_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(QuantizeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -10791,13 +11256,15 @@ image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9) - new_image = RotationalBlurImage(image, angle, exception); + GVL_STRUCT_TYPE(RotationalBlurImage) args = { image, angle, exception }; + new_image = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RotationalBlurImage), &args); #else - new_image = RadialBlurImage(image, angle, exception); + GVL_STRUCT_TYPE(RadialBlurImage) args = { image, angle, exception }; + new_image = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RadialBlurImage), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -10841,17 +11308,20 @@ angle = NUM2DBL(argv[0]); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = RotationalBlurImage(image, angle, exception); + GVL_STRUCT_TYPE(RotationalBlurImage) args = { image, angle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RotationalBlurImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #elif defined(IMAGEMAGICK_GREATER_THAN_EQUAL_6_8_9) - new_image = RotationalBlurImageChannel(image, channels, angle, exception); + GVL_STRUCT_TYPE(RotationalBlurImageChannel) args = { image, channels, angle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RotationalBlurImageChannel), &args); #else - new_image = RadialBlurImageChannel(image, channels, angle, exception); + GVL_STRUCT_TYPE(RadialBlurImageChannel) args = { image, channels, angle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RadialBlurImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -10908,15 +11378,17 @@ BEGIN_CHANNEL_MASK(new_image, channels); { GeometryInfo geometry_info; ParseGeometry(thresholds, &geometry_info); - RandomThresholdImage(new_image, geometry_info.rho, geometry_info.sigma, exception); + GVL_STRUCT_TYPE(RandomThresholdImage) args = { new_image, geometry_info.rho, geometry_info.sigma, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RandomThresholdImage), &args); } END_CHANNEL_MASK(new_image); #else - RandomThresholdImageChannel(new_image, channels, thresholds, exception); + GVL_STRUCT_TYPE(RandomThresholdImageChannel) args = { new_image, channels, thresholds, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RandomThresholdImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -10969,15 +11441,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - RaiseImage(new_image, &rect, raised, exception); + GVL_STRUCT_TYPE(RaiseImage) args = { new_image, &rect, raised, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RaiseImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - RaiseImage(new_image, &rect, raised); + GVL_STRUCT_TYPE(RaiseImage) args = { new_image, &rect, raised }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RaiseImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -10990,11 +11464,11 @@ * @return [Array<Magick::Image>] an array of 1 or more new image objects */ VALUE Image_read(VALUE class, VALUE file_arg) { - return rd_image(class, file_arg, ReadImage); + return rd_image(class, file_arg, GVL_FUNC(ReadImage)); } /** * Called when `rm_obj_to_s' raised an exception. @@ -11010,10 +11484,13 @@ rb_raise(rb_eTypeError, "argument must be path name or open file (%s given)", rb_class2name(CLASS_OF(arg))); } +// aliases for common use of structure types; PingImage, ReadImage +typedef GVL_STRUCT_TYPE(PingImage) GVL_STRUCT_TYPE(rd_image); + /** * Transform arguments, call either ReadImage or PingImage. * * No Ruby usage (internal function) * @@ -11035,22 +11512,22 @@ { } #endif static VALUE -rd_image(VALUE class ATTRIBUTE_UNUSED, VALUE file, reader_t reader) +rd_image(VALUE class ATTRIBUTE_UNUSED, VALUE file, gvl_function_t fp) { char *filename; long filename_l; Info *info; VALUE info_obj; Image *images; ExceptionInfo *exception; // Create a new Info structure for this read/ping info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); if (TYPE(file) == T_FILE) { rb_io_t *fptr; @@ -11086,11 +11563,12 @@ { rb_sys_fail("sigaction"); } #endif - images = (reader)(info, exception); + GVL_STRUCT_TYPE(rd_image) args = { info, exception }; + images = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); #if defined(__APPLE__) || defined(__FreeBSD__) if (sigaction(SIGCHLD, &oldact, NULL) < 0) { rb_sys_fail("sigaction"); @@ -11171,11 +11649,12 @@ } kernel_info->width = order; kernel_info->height = order; kernel_info->values = (double *) matrix; - new_image = ColorMatrixImage(image, kernel_info, exception); + GVL_STRUCT_TYPE(ColorMatrixImage) args = { image, kernel_info, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ColorMatrixImage), &args); kernel_info->values = (double *) NULL; DestroyKernelInfo(kernel_info); xfree((void *) matrix); rm_check_exception(exception, new_image, DestroyOnError); @@ -11218,24 +11697,26 @@ if (x < image_data_l) { image_data += x + 1; } - blob = Base64Decode(image_data, &blob_l); + GVL_STRUCT_TYPE(Base64Decode) args_Base64Decode = { image_data, &blob_l }; + blob = (unsigned char *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(Base64Decode), &args_Base64Decode); if (blob_l == 0) { rb_raise(rb_eArgError, "can't decode image"); } 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); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); - images = BlobToImage(info, blob, blob_l, exception); + GVL_STRUCT_TYPE(BlobToImage) args_BlobToImage = { info, blob, blob_l, exception }; + images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlobToImage), &args_BlobToImage); magick_free((void *)blob); rm_check_exception(exception, images, DestroyOnError); DestroyExceptionInfo(exception); @@ -11293,11 +11774,12 @@ size_t radius_size = NUM2SIZET(radius); image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = StatisticImage(image, NonpeakStatistic, radius_size, radius_size, exception); + GVL_STRUCT_TYPE(StatisticImage) args = { image, NonpeakStatistic, radius_size, radius_size, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(StatisticImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -11345,15 +11827,17 @@ remap_image = rm_check_destroyed(rm_cur_image(argv[0])); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - RemapImage(&quantize_info, image, remap_image, exception); + GVL_STRUCT_TYPE(RemapImage) args = { &quantize_info, image, remap_image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemapImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - RemapImage(&quantize_info, image, remap_image); + GVL_STRUCT_TYPE(RemapImage) args = { &quantize_info, image, remap_image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RemapImage), &args); rm_check_image_exception(image, RetainOnError); #endif return self; } @@ -11404,15 +11888,17 @@ Image *new_image; exception = AcquireExceptionInfo(); if (blur > 1.0) { - new_image = BlurImage(image, blur, blur, exception); + GVL_STRUCT_TYPE(BlurImage) args = { image, blur, blur, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BlurImage), &args); } else { - new_image = SharpenImage(image, blur, blur, exception); + GVL_STRUCT_TYPE(SharpenImage) args = { image, blur, blur, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SharpenImage), &args); } rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return new_image; @@ -11441,11 +11927,11 @@ FilterType filter; double x_resolution, y_resolution, blur; double width, height; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); // Set up defaults filter = image->filter; #if defined(IMAGEMAGICK_7) blur = 1.0; @@ -11501,14 +11987,16 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) Image *preprocess = blurred_image(image, blur); - new_image = ResampleImage(preprocess, x_resolution, y_resolution, filter, exception); + GVL_STRUCT_TYPE(ResampleImage) args = { preprocess, x_resolution, y_resolution, filter, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResampleImage), &args); DestroyImage(preprocess); #else - new_image = ResampleImage(image, x_resolution, y_resolution, filter, blur, exception); + GVL_STRUCT_TYPE(ResampleImage) args = { image, x_resolution, y_resolution, filter, blur, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResampleImage), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -11591,11 +12079,11 @@ FilterType filter; unsigned long rows, columns; double blur, drows, dcols; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); // Set up defaults filter = image->filter; #if defined(IMAGEMAGICK_7) blur = 1.0; @@ -11640,17 +12128,19 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) Image *preprocess = (argc == 4) ? blurred_image(image, blur) : image; - new_image = ResizeImage(preprocess, columns, rows, filter, exception); + GVL_STRUCT_TYPE(ResizeImage) args = { preprocess, columns, rows, filter, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResizeImage), &args); if (argc == 4) { DestroyImage(preprocess); } #else - new_image = ResizeImage(image, columns, rows, filter, blur, exception); + GVL_STRUCT_TYPE(ResizeImage) args = { image, columns, rows, filter, blur, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ResizeImage), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -11732,11 +12222,12 @@ ssize_t y = NUM2LONG(y_offset); image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = RollImage(image, x, y, exception); + GVL_STRUCT_TYPE(RollImage) args = { image, x, y, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RollImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -11762,11 +12253,11 @@ double degrees; char *arrow; long arrow_l; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); switch (argc) { case 2: arrow = rm_str2cstr(argv[1], &arrow_l); @@ -11790,11 +12281,12 @@ break; } exception = AcquireExceptionInfo(); - new_image = RotateImage(image, degrees, exception); + GVL_STRUCT_TYPE(RotateImage) args = { image, degrees, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(RotateImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -11863,11 +12355,11 @@ * @return [Numeric] the image rows */ VALUE Image_rows(VALUE self) { - IMPLEMENT_ATTR_READER(Image, rows, int); + IMPLEMENT_TYPED_ATTR_READER(Image, rows, int, &rm_image_data_type); } /** * Scale an image to the desired dimensions with pixel sampling. Unlike other scaling methods, this @@ -11887,11 +12379,11 @@ */ VALUE Image_sample(int argc, VALUE *argv, VALUE self) { rm_check_destroyed(self); - return scale(False, argc, argv, self, SampleImage); + return scale(False, argc, argv, self, GVL_FUNC(SampleImage)); } /** * Scale an image to the desired dimensions with pixel sampling. @@ -11911,11 +12403,11 @@ */ VALUE Image_sample_bang(int argc, VALUE *argv, VALUE self) { rm_check_frozen(self); - return scale(True, argc, argv, self, SampleImage); + return scale(True, argc, argv, self, GVL_FUNC(SampleImage)); } /** * Change the size of an image to the given dimensions. Alias of {Image#sample}. @@ -11935,11 +12427,11 @@ */ VALUE Image_scale(int argc, VALUE *argv, VALUE self) { rm_check_destroyed(self); - return scale(False, argc, argv, self, ScaleImage); + return scale(False, argc, argv, self, GVL_FUNC(ScaleImage)); } /** * Change the size of an image to the given dimensions. Alias of {Image#sample!}. @@ -11959,14 +12451,17 @@ */ VALUE Image_scale_bang(int argc, VALUE *argv, VALUE self) { rm_check_frozen(self); - return scale(True, argc, argv, self, ScaleImage); + return scale(True, argc, argv, self, GVL_FUNC(ScaleImage)); } +// aliases for common use of structure types; SampleImage, ScaleImage, +typedef GVL_STRUCT_TYPE(SampleImage) GVL_STRUCT_TYPE(scale); + /** * Call ScaleImage or SampleImage * * Notes: * - If 1 argument > 0, multiply current size by this much. @@ -11984,18 +12479,18 @@ * @see Image_sample_bang * @see Image_scale * @see Image_scale_bang */ static VALUE -scale(int bang, int argc, VALUE *argv, VALUE self, scaler_t scaler) +scale(int bang, int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; unsigned long columns, rows; double scale_arg, drows, dcols; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); switch (argc) { case 2: columns = NUM2ULONG(argv[0]); @@ -12024,11 +12519,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 or 2)", argc); break; } exception = AcquireExceptionInfo(); - new_image = (scaler)(image, columns, rows, exception); + GVL_STRUCT_TYPE(scale) args = { image, columns, rows, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -12049,11 +12545,11 @@ * @return [Numeric] the image scene */ VALUE Image_scene(VALUE self) { - IMPLEMENT_ATTR_READER(Image, scene, ulong); + IMPLEMENT_TYPED_ATTR_READER(Image, scene, ulong, &rm_image_data_type); } /** * Selectively blur pixels within a contrast threshold. @@ -12100,15 +12596,17 @@ threshold = rm_percentage(argv[2], 1.0) * QuantumRange; exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = SelectiveBlurImage(image, radius, sigma, threshold, exception); + GVL_STRUCT_TYPE(SelectiveBlurImage) args = { image, radius, sigma, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SelectiveBlurImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = SelectiveBlurImageChannel(image, channels, radius, sigma, threshold, exception); + GVL_STRUCT_TYPE(SelectiveBlurImageChannel) args = { image, channels, radius, sigma, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SelectiveBlurImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -12138,16 +12636,18 @@ channel_depth = NUM2ULONG(depth); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(image, channel); - SetImageDepth(image, channel_depth, exception); + GVL_STRUCT_TYPE(SetImageDepth) args = { image, channel_depth, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageDepth), &args); END_CHANNEL_MASK(image); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageChannelDepth(image, channel, channel_depth); + GVL_STRUCT_TYPE(SetImageChannelDepth) args = { image, channel, channel_depth }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageChannelDepth), &args); rm_check_image_exception(image, RetainOnError); #endif return self; } @@ -12181,15 +12681,17 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_images = SeparateImages(image, exception); + GVL_STRUCT_TYPE(SeparateImages) args = { image, exception }; + new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SeparateImages), &args); CHANGE_RESULT_CHANNEL_MASK(new_images); END_CHANNEL_MASK(image); #else - new_images = SeparateImages(image, channels, exception); + GVL_STRUCT_TYPE(SeparateImages) args = { image, channels, exception }; + new_images = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SeparateImages), &args); #endif rm_check_exception(exception, new_images, DestroyOnError); DestroyExceptionInfo(exception); return rm_imagelist_from_images(new_images); @@ -12224,11 +12726,12 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 1)", argc); } exception = AcquireExceptionInfo(); - new_image = SepiaToneImage(image, threshold, exception); + GVL_STRUCT_TYPE(SepiaToneImage) args = { image, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SepiaToneImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12282,15 +12785,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SegmentImage(new_image, colorspace, verbose, cluster_threshold, smoothing_threshold, exception); + GVL_STRUCT_TYPE(SegmentImage) args = { new_image, colorspace, verbose, cluster_threshold, smoothing_threshold, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SegmentImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - SegmentImage(new_image, colorspace, verbose, cluster_threshold, smoothing_threshold); + GVL_STRUCT_TYPE(SegmentImage) args = { new_image, colorspace, verbose, cluster_threshold, smoothing_threshold }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SegmentImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -12422,11 +12927,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc); break; } exception = AcquireExceptionInfo(); - new_image = ShadeImage(image, shading, azimuth, elevation, exception); + GVL_STRUCT_TYPE(ShadeImage) args = { image, shading, azimuth, elevation, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ShadeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12480,11 +12986,12 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc); break; } exception = AcquireExceptionInfo(); - new_image = ShadowImage(image, alpha, sigma, x_offset, y_offset, exception); + GVL_STRUCT_TYPE(ShadowImage) args = { image, alpha, sigma, x_offset, y_offset, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ShadowImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12499,11 +13006,11 @@ * @return [Magick::Image] a new image */ VALUE Image_sharpen(int argc, VALUE *argv, VALUE self) { - return effect_image(self, argc, argv, SharpenImage); + return effect_image(self, argc, argv, GVL_FUNC(SharpenImage)); } /** * Sharpen image on a channel. @@ -12547,15 +13054,17 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = SharpenImage(image, radius, sigma, exception); + GVL_STRUCT_TYPE(SharpenImage) args = { image, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SharpenImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = SharpenImageChannel(image, channels, radius, sigma, exception); + GVL_STRUCT_TYPE(SharpenImageChannel) args = { image, channels, radius, sigma, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SharpenImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -12574,11 +13083,11 @@ */ VALUE Image_shave(VALUE self, VALUE width, VALUE height) { rm_check_destroyed(self); - return xform_image(False, self, INT2FIX(0), INT2FIX(0), width, height, ShaveImage); + return xform_image(False, self, INT2FIX(0), INT2FIX(0), width, height, GVL_FUNC(ShaveImage)); } /** * Shave pixels from the image edges, leaving a rectangle of the specified width & height in the @@ -12592,11 +13101,11 @@ */ VALUE Image_shave_bang(VALUE self, VALUE width, VALUE height) { rm_check_frozen(self); - return xform_image(True, self, INT2FIX(0), INT2FIX(0), width, height, ShaveImage); + return xform_image(True, self, INT2FIX(0), INT2FIX(0), width, height, GVL_FUNC(ShaveImage)); } /** * Shearing slides one edge of an image along the X or Y axis, creating a parallelogram. An X @@ -12619,11 +13128,12 @@ double y = NUM2DBL(y_shear); image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = ShearImage(image, x, y, exception); + GVL_STRUCT_TYPE(ShearImage) args = { image, x, y, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ShearImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -12690,16 +13200,18 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); BEGIN_CHANNEL_MASK(new_image, channels); - SigmoidalContrastImage(new_image, sharpen, contrast, midpoint, exception); + GVL_STRUCT_TYPE(SigmoidalContrastImage) args = { new_image, sharpen, contrast, midpoint, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SigmoidalContrastImage), &args); END_CHANNEL_MASK(new_image); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - SigmoidalContrastImageChannel(new_image, channels, sharpen, contrast, midpoint); + GVL_STRUCT_TYPE(SigmoidalContrastImageChannel) args = { new_image, channels, sharpen, contrast, midpoint }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SigmoidalContrastImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -12722,15 +13234,17 @@ image = rm_check_destroyed(self); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SignatureImage(image, exception); + GVL_STRUCT_TYPE(SignatureImage) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SignatureImage(image); + GVL_STRUCT_TYPE(SignatureImage) args = { image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args); rm_check_image_exception(image, RetainOnError); #endif signature = rm_get_property(image, "signature"); if (!signature) { @@ -12752,11 +13266,11 @@ */ VALUE Image_sketch(int argc, VALUE *argv, VALUE self) { rm_check_destroyed(self); - return motion_blur(argc, argv, self, SketchImage); + return motion_blur(argc, argv, self, GVL_FUNC(SketchImage)); } /** * Apply a special effect to the image, similar to the effect achieved in a photo darkroom by @@ -12795,15 +13309,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SolarizeImage(new_image, threshold, exception); + GVL_STRUCT_TYPE(SolarizeImage) args = { new_image, threshold, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SolarizeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - SolarizeImage(new_image, threshold); + GVL_STRUCT_TYPE(SolarizeImage) args = { new_image, threshold }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SolarizeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -12835,18 +13351,22 @@ imageB = rm_check_destroyed(other); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SignatureImage(imageA, exception); + GVL_STRUCT_TYPE(SignatureImage) args1 = { imageA, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args1); CHECK_EXCEPTION(); - SignatureImage(imageB, exception); + GVL_STRUCT_TYPE(SignatureImage) args2 = { imageB, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args2); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SignatureImage(imageA); - SignatureImage(imageB); + GVL_STRUCT_TYPE(SignatureImage) args1 = { imageA }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args1); + GVL_STRUCT_TYPE(SignatureImage) args2 = { imageB }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SignatureImage), &args2); #endif sigA = rm_get_property(imageA, "signature"); sigB = rm_get_property(imageB, "signature"); if (!sigA || !sigB) { @@ -13019,15 +13539,17 @@ } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = SparseColorImage(image, method, nargs, args, exception); + GVL_STRUCT_TYPE(SparseColorImage) args_SparseColorImage = { image, method, nargs, args, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SparseColorImage), &args_SparseColorImage); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = SparseColorImage(image, channels, method, nargs, args, exception); + GVL_STRUCT_TYPE(SparseColorImage) args_SparseColorImage = { image, channels, method, nargs, args, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SparseColorImage), &args_SparseColorImage); #endif xfree((void *) args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -13082,11 +13604,12 @@ 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); + GVL_STRUCT_TYPE(SpliceImage) args = { image, &rectangle, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SpliceImage), &args); image->background_color = old_color; rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -13120,14 +13643,15 @@ break; } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = SpreadImage(image, image->interpolate, radius, exception); + GVL_STRUCT_TYPE(SpreadImage) args = { image, image->interpolate, radius, exception }; #else - new_image = SpreadImage(image, radius, exception); + GVL_STRUCT_TYPE(SpreadImage) args = { image, radius, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SpreadImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -13139,11 +13663,11 @@ * @return [Boolean] true or false */ VALUE Image_start_loop(VALUE self) { - IMPLEMENT_ATTR_READER(Image, start_loop, boolean); + IMPLEMENT_TYPED_ATTR_READER(Image, start_loop, boolean, &rm_image_data_type); } /** * Set the Boolean value that indicates the first image in an animation. * @@ -13151,11 +13675,11 @@ * @return [Boolean] the given value */ VALUE Image_start_loop_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, start_loop, boolean); + IMPLEMENT_TYPED_ATTR_WRITER(Image, start_loop, boolean, &rm_image_data_type); } /** * Hides a digital watermark in the receiver. You can retrieve the watermark by reading the file @@ -13183,11 +13707,12 @@ watermark = rm_check_destroyed(wm_image); image->offset = NUM2LONG(offset); exception = AcquireExceptionInfo(); - new_image = SteganoImage(image, watermark, exception); + GVL_STRUCT_TYPE(SteganoImage) args = { image, watermark, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SteganoImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); RB_GC_GUARD(wm_image); @@ -13215,11 +13740,12 @@ offset_image = rm_cur_image(offset_image_arg); offset = rm_check_destroyed(offset_image); exception = AcquireExceptionInfo(); - new_image = StereoImage(image, offset, exception); + GVL_STRUCT_TYPE(StereoImage) args = { image, offset, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(StereoImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); RB_GC_GUARD(offset_image); @@ -13273,36 +13799,42 @@ #endif if (image->storage_class == PseudoClass && class_type == DirectClass) { #if defined(IMAGEMAGICK_7) - SyncImage(image, exception); + GVL_STRUCT_TYPE(SyncImage) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncImage), &args); CHECK_EXCEPTION(); #else - SyncImage(image); + GVL_STRUCT_TYPE(SyncImage) args = { image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncImage), &args); #endif magick_free(image->colormap); image->colormap = NULL; } else if (image->storage_class == DirectClass && class_type == PseudoClass) { GetQuantizeInfo(&qinfo); qinfo.number_colors = QuantumRange+1; #if defined(IMAGEMAGICK_7) - QuantizeImage(&qinfo, image, exception); + GVL_STRUCT_TYPE(QuantizeImage) args = { &qinfo, image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(QuantizeImage), &args); CHECK_EXCEPTION(); #else - QuantizeImage(&qinfo, image); + GVL_STRUCT_TYPE(QuantizeImage) args = { &qinfo, image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(QuantizeImage), &args); #endif } #if defined(IMAGEMAGICK_7) - SetImageStorageClass(image, class_type, exception); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, class_type, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageStorageClass(image, class_type); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, class_type }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); #endif return new_class_type; } @@ -13327,11 +13859,11 @@ Pixel *pixel; VALUE new_pixel; long n, size; long x, y; unsigned long cols, rows; - unsigned int okay; + MagickBooleanType okay; ExceptionInfo *exception; #if defined(IMAGEMAGICK_7) Quantum *pixels; #else PixelPacket *pixels; @@ -13353,19 +13885,21 @@ new_pixels = rb_Array(new_pixels); rm_check_ary_len(new_pixels, size); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = SetImageStorageClass(image, DirectClass, exception); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, DirectClass, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); CHECK_EXCEPTION(); if (!okay) { DestroyExceptionInfo(exception); rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't store pixels."); } #else - okay = SetImageStorageClass(image, DirectClass); + GVL_STRUCT_TYPE(SetImageStorageClass) args = { image, DirectClass }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args); rm_check_image_exception(image, RetainOnError); if (!okay) { rb_raise(Class_ImageMagickError, "SetImageStorageClass failed. Can't store pixels."); } @@ -13373,11 +13907,12 @@ #endif // Get a pointer to the pixels. Replace the values with the PixelPackets // from the pixels argument. { - pixels = GetAuthenticPixels(image, x, y, cols, rows, exception); + GVL_STRUCT_TYPE(GetAuthenticPixels) args = { image, x, y, cols, rows, exception }; + pixels = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetAuthenticPixels), &args); CHECK_EXCEPTION(); if (pixels) { #if defined(IMAGEMAGICK_6) @@ -13389,11 +13924,11 @@ if (CLASS_OF(new_pixel) != Class_Pixel) { DestroyExceptionInfo(exception); rb_raise(rb_eTypeError, "Item in array should be a Pixel."); } - Data_Get_Struct(new_pixel, Pixel, pixel); + TypedData_Get_Struct(new_pixel, Pixel, &rm_pixel_data_type, pixel); #if defined(IMAGEMAGICK_7) SetPixelRed(image, pixel->red, pixels); SetPixelGreen(image, pixel->green, pixels); SetPixelBlue(image, pixel->blue, pixels); SetPixelAlpha(image, pixel->alpha, pixels); @@ -13409,11 +13944,12 @@ SetPixelIndex(indexes + n, pixel->black); } pixels++; #endif } - SyncAuthenticPixels(image, exception); + GVL_STRUCT_TYPE(SyncAuthenticPixels) args = { image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncAuthenticPixels), &args); CHECK_EXCEPTION(); } DestroyExceptionInfo(exception); } @@ -13469,14 +14005,15 @@ image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = SwirlImage(image, degrees, image->interpolate, exception); + GVL_STRUCT_TYPE(SwirlImage) args = { image, degrees, image->interpolate, exception }; #else - new_image = SwirlImage(image, degrees, exception); + GVL_STRUCT_TYPE(SwirlImage) args = { image, degrees, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SwirlImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -13563,16 +14100,18 @@ color_mpp.blue = (MagickRealType) color.blue; } #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - FloodfillPaintImage(new_image, draw_info, &color_mpp, x, y, invert, exception); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, draw_info, &color_mpp, x, y, invert, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); DestroyDrawInfo(draw_info); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - FloodfillPaintImage(new_image, DefaultChannels, draw_info, &color_mpp, x, y, invert); + GVL_STRUCT_TYPE(FloodfillPaintImage) args = { new_image, DefaultChannels, draw_info, &color_mpp, x, y, invert }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FloodfillPaintImage), &args); DestroyDrawInfo(draw_info); rm_check_image_exception(new_image, DestroyOnError); #endif @@ -13601,22 +14140,27 @@ image = rm_check_destroyed(self); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - BilevelImage(new_image, threshold, exception); + GVL_STRUCT_TYPE(BilevelImage) args = { new_image, threshold, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - BilevelImageChannel(new_image, DefaultChannels, threshold); + GVL_STRUCT_TYPE(BilevelImageChannel) args = { new_image, DefaultChannels, threshold }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(BilevelImageChannel), &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } +// aliases for common use of structure types; WhiteThresholdImage +typedef GVL_STRUCT_TYPE(WhiteThresholdImage) GVL_STRUCT_TYPE(threshold_image); + /** * Call one of the xxxxThresholdImage methods. * * No Ruby usage (internal function) * @@ -13624,12 +14168,12 @@ * @param argv array of input arguments * @param self this object * @param thresholder which xxxxThresholdImage method to call * @return a new image */ -static -VALUE threshold_image(int argc, VALUE *argv, VALUE self, thresholder_t thresholder) +static VALUE +threshold_image(int argc, VALUE *argv, VALUE self, gvl_function_t fp) { Image *image, *new_image; double red, green, blue, alpha; char ctarg[200]; #if defined(IMAGEMAGICK_7) @@ -13668,15 +14212,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - (thresholder)(new_image, ctarg, exception); + GVL_STRUCT_TYPE(threshold_image) args = { new_image, ctarg, exception }; + CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - (thresholder)(new_image, ctarg); + GVL_STRUCT_TYPE(threshold_image) args = { new_image, ctarg }; + CALL_FUNC_WITHOUT_GVL(fp, &args); rm_check_image_exception(new_image, DestroyOnError); #endif return rm_image_new(new_image); } @@ -13706,11 +14252,11 @@ double scale_arg, drows, dcols; char image_geometry[MaxTextExtent]; RectangleInfo geometry; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); switch (argc) { case 2: columns = NUM2ULONG(argv[0]); @@ -13744,11 +14290,12 @@ exception = AcquireExceptionInfo(); ParseRegionGeometry(image, image_geometry, &geometry, exception); rm_check_exception(exception, image, RetainOnError); - new_image = ThumbnailImage(image, geometry.width, geometry.height, exception); + GVL_STRUCT_TYPE(ThumbnailImage) args = { image, geometry.width, geometry.height, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ThumbnailImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); if (bang) { @@ -13902,14 +14449,15 @@ Color_to_PixelColor(&tint, argv[0]); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = TintImage(image, alpha, &tint, exception); + GVL_STRUCT_TYPE(TintImage) args = { image, alpha, &tint, exception }; #else - new_image = TintImage(image, alpha, tint, exception); + GVL_STRUCT_TYPE(TintImage) args = { image, alpha, tint, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TintImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -13938,24 +14486,26 @@ // 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(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); // Copy the depth and magick fields to the Image if (info->depth != 0) { #if defined(IMAGEMAGICK_7) - SetImageDepth(image, info->depth, exception); + GVL_STRUCT_TYPE(SetImageDepth) args = { image, info->depth, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageDepth), &args); CHECK_EXCEPTION(); #else - SetImageDepth(image, info->depth); + GVL_STRUCT_TYPE(SetImageDepth) args = { image, info->depth }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageDepth), &args); rm_check_image_exception(image, RetainOnError); #endif } if (*info->magick) @@ -13985,11 +14535,12 @@ } } rm_sync_image_options(image, info); - blob = ImageToBlob(info, image, &length, exception); + GVL_STRUCT_TYPE(ImageToBlob) args = { info, image, &length, exception }; + blob = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ImageToBlob), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); if (length == 0 || !blob) @@ -14131,15 +14682,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = TransparentPaintImage(new_image, &color, alpha, MagickFalse, exception); + GVL_STRUCT_TYPE(TransparentPaintImage) args = { new_image, &color, alpha, MagickFalse, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - okay = TransparentPaintImage(new_image, &color, QuantumRange - alpha, MagickFalse); + GVL_STRUCT_TYPE(TransparentPaintImage) args = { new_image, &color, QuantumRange - alpha, MagickFalse }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif if (!okay) { // Force exception @@ -14205,15 +14758,17 @@ new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - okay = TransparentPaintImageChroma(new_image, &low, &high, alpha, invert, exception); + GVL_STRUCT_TYPE(TransparentPaintImageChroma) args = { new_image, &low, &high, alpha, invert, exception }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImageChroma), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - okay = TransparentPaintImageChroma(new_image, &low, &high, QuantumRange - alpha, invert); + GVL_STRUCT_TYPE(TransparentPaintImageChroma) args = { new_image, &low, &high, QuantumRange - alpha, invert }; + okay = (MagickBooleanType)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransparentPaintImageChroma), &args); rm_check_image_exception(new_image, DestroyOnError); #endif if (!okay) { // Force exception @@ -14262,11 +14817,11 @@ */ VALUE Image_transpose(VALUE self) { rm_check_destroyed(self); - return crisscross(False, self, TransposeImage); + return crisscross(False, self, GVL_FUNC(TransposeImage)); } /** * Creates a horizontal mirror image by reflecting the pixels around the central y-axis while @@ -14278,11 +14833,11 @@ */ VALUE Image_transpose_bang(VALUE self) { rm_check_frozen(self); - return crisscross(True, self, TransposeImage); + return crisscross(True, self, GVL_FUNC(TransposeImage)); } /** * Creates a vertical mirror image by reflecting the pixels around the central x-axis while rotating @@ -14293,11 +14848,11 @@ */ VALUE Image_transverse(VALUE self) { rm_check_destroyed(self); - return crisscross(False, self, TransverseImage); + return crisscross(False, self, GVL_FUNC(TransverseImage)); } /** * Creates a vertical mirror image by reflecting the pixels around the central x-axis while rotating * them by 270 degrees @@ -14308,11 +14863,11 @@ */ VALUE Image_transverse_bang(VALUE self) { rm_check_frozen(self); - return crisscross(True, self, TransverseImage); + return crisscross(True, self, GVL_FUNC(TransverseImage)); } /** * Convenient front-end to CropImage. @@ -14346,14 +14901,15 @@ default: rb_raise(rb_eArgError, "wrong number of arguments (expecting 0 or 1, got %d)", argc); break; } - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); exception = AcquireExceptionInfo(); - new_image = TrimImage(image, exception); + GVL_STRUCT_TYPE(TrimImage) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TrimImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); rm_ensure_result(new_image); @@ -14530,11 +15086,12 @@ ExceptionInfo *exception; image = rm_check_destroyed(self); exception = AcquireExceptionInfo(); - new_image = UniqueImageColors(image, exception); + GVL_STRUCT_TYPE(UniqueImageColors) args = { image, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(UniqueImageColors), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -14696,11 +15253,12 @@ image = rm_check_destroyed(self); unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold); exception = AcquireExceptionInfo(); - new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, exception); + GVL_STRUCT_TYPE(UnsharpMaskImage) args = { image, radius, sigma, amount, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(UnsharpMaskImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -14751,15 +15309,17 @@ unsharp_mask_args(argc, argv, &radius, &sigma, &amount, &threshold); exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) BEGIN_CHANNEL_MASK(image, channels); - new_image = UnsharpMaskImage(image, radius, sigma, amount, threshold, exception); + GVL_STRUCT_TYPE(UnsharpMaskImage) args = { image, radius, sigma, amount, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(UnsharpMaskImage), &args); CHANGE_RESULT_CHANNEL_MASK(new_image); END_CHANNEL_MASK(image); #else - new_image = UnsharpMaskImageChannel(image, channels, radius, sigma, amount, threshold, exception); + GVL_STRUCT_TYPE(UnsharpMaskImageChannel) args = { image, channels, radius, sigma, amount, threshold, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(UnsharpMaskImageChannel), &args); #endif rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); @@ -14806,11 +15366,12 @@ break; } exception = AcquireExceptionInfo(); - new_image = VignetteImage(image, radius, sigma, horz_radius, vert_radius, exception); + GVL_STRUCT_TYPE(VignetteImage) args = { image, radius, sigma, horz_radius, vert_radius, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(VignetteImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -14952,15 +15513,17 @@ SetImageArtifact(overlay, "compose:args", geometry); new_image = rm_clone_image(image); #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - CompositeImage(new_image, overlay, ModulateCompositeOp, MagickTrue, x_offset, y_offset, exception); + GVL_STRUCT_TYPE(CompositeImage) args = { new_image, overlay, ModulateCompositeOp, MagickTrue, x_offset, y_offset, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); #else - CompositeImage(new_image, ModulateCompositeOp, overlay, x_offset, y_offset); + GVL_STRUCT_TYPE(CompositeImage) args = { new_image, ModulateCompositeOp, overlay, x_offset, y_offset }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args); rm_check_image_exception(new_image, DestroyOnError); #endif RB_GC_GUARD(ovly); @@ -14999,14 +15562,15 @@ break; } exception = AcquireExceptionInfo(); #if defined(IMAGEMAGICK_7) - new_image = WaveImage(image, amplitude, wavelength, image->interpolate, exception); + GVL_STRUCT_TYPE(WaveImage) args = { image, amplitude, wavelength, image->interpolate, exception }; #else - new_image = WaveImage(image, amplitude, wavelength, exception); + GVL_STRUCT_TYPE(WaveImage) args = { image, amplitude, wavelength, exception }; #endif + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(WaveImage), &args); rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); return rm_image_new(new_image); } @@ -15098,30 +15662,35 @@ step = 0.0; } exception = AcquireExceptionInfo(); - flip_image = FlipImage(image, exception); + GVL_STRUCT_TYPE(FlipImage) args_FlipImage = { image, exception }; + flip_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(FlipImage), &args_FlipImage); CHECK_EXCEPTION(); geometry.x = 0; geometry.y = 0; geometry.width = image->columns; geometry.height = max_rows; - reflection = CropImage(flip_image, &geometry, exception); + GVL_STRUCT_TYPE(CropImage) args_CropImage = { flip_image, &geometry, exception }; + reflection = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CropImage), &args_CropImage); DestroyImage(flip_image); CHECK_EXCEPTION(); #if defined(IMAGEMAGICK_7) - SetImageStorageClass(reflection, DirectClass, exception); + GVL_STRUCT_TYPE(SetImageStorageClass) args_SetImageStorageClass = { reflection, DirectClass, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args_SetImageStorageClass); rm_check_exception(exception, reflection, DestroyOnError); - SetImageAlphaChannel(reflection, ActivateAlphaChannel, exception); + GVL_STRUCT_TYPE(SetImageAlphaChannel) args_SetImageAlphaChannel = { reflection, ActivateAlphaChannel, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageAlphaChannel), &args_SetImageAlphaChannel); rm_check_exception(exception, reflection, DestroyOnError); #else - SetImageStorageClass(reflection, DirectClass); + GVL_STRUCT_TYPE(SetImageStorageClass) args_SetImageStorageClass = { reflection, DirectClass }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageStorageClass), &args_SetImageStorageClass); rm_check_image_exception(reflection, DestroyOnError); reflection->matte = MagickTrue; #endif @@ -15139,11 +15708,12 @@ { opacity = TransparentOpacity; } #endif - p = GetVirtualPixels(reflection, 0, y, image->columns, 1, exception); + GVL_STRUCT_TYPE(GetVirtualPixels) args_GetVirtualPixels = { reflection, 0, y, image->columns, 1, exception }; + p = CALL_FUNC_WITHOUT_GVL(GVL_FUNC(GetVirtualPixels), &args_GetVirtualPixels); rm_check_exception(exception, reflection, DestroyOnError); if (!p) { func = "AcquireImagePixels"; goto error; @@ -15171,12 +15741,12 @@ q[x] = p[x]; q[x].opacity = max(q[x].opacity, (Quantum)opacity); #endif } - - SyncAuthenticPixels(reflection, exception); + GVL_STRUCT_TYPE(SyncAuthenticPixels) args_SyncAuthenticPixels = { reflection, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SyncAuthenticPixels), &args_SyncAuthenticPixels); rm_check_exception(exception, reflection, DestroyOnError); opacity += step; } @@ -15205,11 +15775,11 @@ * @see Image#black_threshold */ VALUE Image_white_threshold(int argc, VALUE *argv, VALUE self) { - return threshold_image(argc, argv, self, WhiteThresholdImage); + return threshold_image(argc, argv, self, GVL_FUNC(WhiteThresholdImage)); } /** * Copy the filename to the Info and to the Image. Add format prefix if necessary. This complicated @@ -15318,11 +15888,11 @@ #endif image = rm_check_destroyed(self); info_obj = rm_info_new(); - Data_Get_Struct(info_obj, Info, info); + TypedData_Get_Struct(info_obj, Info, &rm_info_data_type, info); if (TYPE(file) == T_FILE) { rb_io_t *fptr; @@ -15348,15 +15918,17 @@ rm_sync_image_options(image, info); info->adjoin = MagickFalse; #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - WriteImage(info, image, exception); + GVL_STRUCT_TYPE(WriteImage) args = { info, image, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(WriteImage), &args); CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - WriteImage(info, image); + GVL_STRUCT_TYPE(WriteImage) args = { info, image }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(WriteImage), &args); rm_check_image_exception(image, RetainOnError); #endif RB_GC_GUARD(info_obj); @@ -15370,11 +15942,11 @@ * @return [Float] the resolution */ VALUE Image_x_resolution(VALUE self) { - IMPLEMENT_ATTR_READERF(Image, x_resolution, resolution.x, dbl); + IMPLEMENT_TYPED_ATTR_READERF(Image, x_resolution, resolution.x, dbl, &rm_image_data_type); } /** * Set the horizontal resolution of the image. * @@ -15382,22 +15954,22 @@ * @return [Float] the given resolution */ VALUE Image_x_resolution_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITERF(Image, x_resolution, resolution.x, dbl); + IMPLEMENT_TYPED_ATTR_WRITERF(Image, x_resolution, resolution.x, dbl, &rm_image_data_type); } /** * Get the vertical resolution of the image. * * @return [Float] the resolution */ VALUE Image_y_resolution(VALUE self) { - IMPLEMENT_ATTR_READERF(Image, y_resolution, resolution.y, dbl); + IMPLEMENT_TYPED_ATTR_READERF(Image, y_resolution, resolution.y, dbl, &rm_image_data_type); } /** * Set the vertical resolution of the image. * @@ -15405,22 +15977,22 @@ * @return [Float] the given resolution */ VALUE Image_y_resolution_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITERF(Image, y_resolution, resolution.y, dbl); + IMPLEMENT_TYPED_ATTR_WRITERF(Image, y_resolution, resolution.y, dbl, &rm_image_data_type); } #else /** * Get the horizontal resolution of the image. * * @return [Float] the resolution */ VALUE Image_x_resolution(VALUE self) { - IMPLEMENT_ATTR_READER(Image, x_resolution, dbl); + IMPLEMENT_TYPED_ATTR_READER(Image, x_resolution, dbl, &rm_image_data_type); } /** * Set the horizontal resolution of the image. * @@ -15428,22 +16000,22 @@ * @return [Float] the given resolution */ VALUE Image_x_resolution_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, x_resolution, dbl); + IMPLEMENT_TYPED_ATTR_WRITER(Image, x_resolution, dbl, &rm_image_data_type); } /** * Get the vertical resolution of the image. * * @return [Float] the resolution */ VALUE Image_y_resolution(VALUE self) { - IMPLEMENT_ATTR_READER(Image, y_resolution, dbl); + IMPLEMENT_TYPED_ATTR_READER(Image, y_resolution, dbl, &rm_image_data_type); } /** * Set the vertical resolution of the image. * @@ -15451,11 +16023,11 @@ * @return [Float] the given resolution */ VALUE Image_y_resolution_eq(VALUE self, VALUE val) { - IMPLEMENT_ATTR_WRITER(Image, y_resolution, dbl); + IMPLEMENT_TYPED_ATTR_WRITER(Image, y_resolution, dbl, &rm_image_data_type); } #endif /** @@ -15510,11 +16082,11 @@ } switch (argc) { case 5: - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); VALUE_TO_ENUM(argv[0], gravity, GravityType); x = argv[1]; y = argv[2]; @@ -15577,11 +16149,11 @@ width = argv[1]; height = argv[2]; columns = NUM2ULONG(width); rows = NUM2ULONG(height); - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); switch (gravity) { case ForgetGravity: case NorthWestGravity: @@ -15640,14 +16212,14 @@ rb_raise(rb_eArgError, "wrong number of arguments (%d for 3, 4, or 5)", argc); } break; } - cropped = xform_image(bang, self, x, y, width, height, CropImage); + cropped = xform_image(bang, self, x, y, width, height, GVL_FUNC(CropImage)); if (reset_page) { - Data_Get_Struct(cropped, Image, image); + TypedData_Get_Struct(cropped, Image, &rm_image_data_type, image); ResetImagePage(image, "0x0+0+0"); } RB_GC_GUARD(x); RB_GC_GUARD(y); @@ -15656,10 +16228,13 @@ return cropped; } +// aliases for common use of structure types; ChopImage, CropImage, ShaveImage +typedef GVL_STRUCT_TYPE(ChopImage) GVL_STRUCT_TYPE(xform_image); + /** * Call one of the image transformation functions. * * No Ruby usage (internal function) * @@ -15671,25 +16246,26 @@ * @param height height of region * @param xformer the transformation function * @return self if bang, otherwise a new image */ static VALUE -xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, xformer_t xformer) +xform_image(int bang, VALUE self, VALUE x, VALUE y, VALUE width, VALUE height, gvl_function_t fp) { Image *image, *new_image; RectangleInfo rect; ExceptionInfo *exception; - Data_Get_Struct(self, Image, image); + TypedData_Get_Struct(self, Image, &rm_image_data_type, image); rect.x = NUM2LONG(x); rect.y = NUM2LONG(y); rect.width = NUM2ULONG(width); rect.height = NUM2ULONG(height); exception = AcquireExceptionInfo(); - new_image = (xformer)(image, &rect, exception); + GVL_STRUCT_TYPE(xform_image) args = { image, &rect, exception }; + new_image = (Image *)CALL_FUNC_WITHOUT_GVL(fp, &args); // An exception can occur in either the old or the new images rm_check_exception(exception, new_image, DestroyOnError); DestroyExceptionInfo(exception); @@ -15793,6 +16369,17 @@ { DestroyImage(image); } } - +/** + * Get Image object size. + * + * No Ruby usage (internal function) + * + * @param ptr pointer to the Image object + */ +static size_t +rm_image_memsize(const void *ptr) +{ + return sizeof(Image); +}