ext/RMagick/rmutil.cpp in rmagick-5.5.0 vs ext/RMagick/rmutil.cpp in rmagick-6.0.0

- old
+ new

@@ -19,10 +19,15 @@ #endif static VALUE rescue_not_str(VALUE, VALUE ATTRIBUTE_UNUSED) ATTRIBUTE_NORETURN; static void handle_exception(ExceptionInfo *, Image *, ErrorRetention); +#if defined(IMAGEMAGICK_7) +DEFINE_GVL_STUB3(TransformImageColorspace, Image *, const ColorspaceType, ExceptionInfo *); +#else +DEFINE_GVL_STUB2(TransformImageColorspace, Image *, const ColorspaceType); +#endif DEFINE_GVL_STUB5(CloneImage, const Image *, const size_t, const size_t, const MagickBooleanType, ExceptionInfo *); /** @@ -365,11 +370,10 @@ */ double rm_percentage2(VALUE arg, double max, bool only_positive) { double pct; - char *end; if (!rm_check_num2dbl(arg)) { pct = rm_str_to_pct(arg, only_positive) * max; } @@ -588,27 +592,31 @@ * @see rm_pixelcolor_to_color_name_info */ VALUE rm_pixelcolor_to_color_name(Image *image, PixelColor *color) { - PixelColor pp; - char name[MaxTextExtent]; - ExceptionInfo *exception; + MagickPixel mpp; + char tuple[MaxTextExtent]; - exception = AcquireExceptionInfo(); - - pp = *color; #if defined(IMAGEMAGICK_7) - pp.depth = MAGICKCORE_QUANTUM_DEPTH; - pp.colorspace = image->colorspace; + mpp = *color; + mpp.alpha_trait = BlendPixelTrait; + mpp.colorspace = image->colorspace; +#else + rm_init_magickpixel(image, &mpp); + mpp.red = GetPixelRed(color); + mpp.green = GetPixelGreen(color); + mpp.blue = GetPixelBlue(color); + mpp.opacity = GetPixelOpacity(color); + mpp.index = (MagickRealType) 0.0; + mpp.matte = MagickTrue; #endif + mpp.depth = image->depth; - QueryColorname(image, &pp, X11Compliance, name, exception); - CHECK_EXCEPTION(); - DestroyExceptionInfo(exception); + GetColorTuple(&mpp, MagickTrue, tuple); - return rb_str_new2(name); + return rb_str_new2(tuple); } /** * Map the color intensity to a named color. @@ -1055,16 +1063,17 @@ if (info->colorspace != UndefinedColorspace) { #if defined(IMAGEMAGICK_7) exception = AcquireExceptionInfo(); - SetImageColorspace(image, info->colorspace, exception); - // We should not throw an exception in this method because we will - // leak memory in the place where this method is called. And that is - // why the exception is being ignored here. + GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace, exception }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args); + CHECK_EXCEPTION(); DestroyExceptionInfo(exception); #else - SetImageColorspace(image, info->colorspace); + GVL_STRUCT_TYPE(TransformImageColorspace) args = { image, info->colorspace }; + CALL_FUNC_WITHOUT_GVL(GVL_FUNC(TransformImageColorspace), &args); + rm_check_image_exception(image, RetainOnError); #endif } if (info->compression != UndefinedCompression) {