From: Cristy Date: Sat, 12 Oct 2019 00:20:19 +0000 (-0400) Subject: https://github.com/ImageMagick/ImageMagick/issues/1740 X-Git-Tag: 7.0.9-0~89 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b058696133c6d36e0b48a454e357482db71982e;p=imagemagick https://github.com/ImageMagick/ImageMagick/issues/1740 --- diff --git a/MagickCore/quantize.c b/MagickCore/quantize.c index d65cb2d7e..38ea0d3e7 100644 --- a/MagickCore/quantize.c +++ b/MagickCore/quantize.c @@ -2347,8 +2347,8 @@ MagickExport MagickBooleanType PosterizeImage(Image *image,const size_t levels, const DitherMethod dither_method,ExceptionInfo *exception) { #define PosterizeImageTag "Posterize/Image" -#define PosterizePixel(pixel) (Quantum) (QuantumRange*(MagickRound( \ - QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1)) +#define PosterizePixel(pixel) ClampToQuantum((MagickRealType) QuantumRange*( \ + MagickRound(QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1)) CacheView *image_view; @@ -3282,17 +3282,21 @@ extern "C" { static int IntensityCompare(const void *x,const void *y) { + double + intensity; + PixelInfo *color_1, *color_2; - ssize_t - intensity; - color_1=(PixelInfo *) x; color_2=(PixelInfo *) y; - intensity=(ssize_t) (GetPixelInfoIntensity((const Image *) NULL,color_1)- - GetPixelInfoIntensity((const Image *) NULL,color_2)); + intensity=GetPixelInfoIntensity((const Image *) NULL,color_1)- + GetPixelInfoIntensity((const Image *) NULL,color_2); + if (intensity > (double) INT_MAX) + intensity=(double) INT_MAX; + if (intensity < (double) INT_MIN) + intensity=(double) INT_MIN; return((int) intensity); }