From d6f3c03cf55c98da87e547882379a85ce2b3dc81 Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Fri, 11 Oct 2019 20:21:42 -0400
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1740

---
 magick/quantize.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/magick/quantize.c b/magick/quantize.c
index 0f963b4..b6c1645 100644
--- a/magick/quantize.c
+++ b/magick/quantize.c
@@ -2293,8 +2293,8 @@ MagickExport MagickBooleanType PosterizeImageChannel(Image *image,
   const ChannelType channel,const size_t levels,const MagickBooleanType dither)
 {
 #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;
@@ -3342,7 +3342,7 @@ static MagickBooleanType SetGrayscaleImage(Image *image)
     }
   (void) memset(colormap_index,0,extent*sizeof(*colormap_index));
   for (i=0; i < (ssize_t) image->colors; i++)
-    image->colormap[i].opacity=(unsigned short) i;
+    image->colormap[i].opacity=(Quantum) i;
   qsort((void *) image->colormap,image->colors,sizeof(PixelPacket),
     IntensityCompare);
   colormap=(PixelPacket *) AcquireQuantumMemory(image->colors,
-- 
2.23.0

