From e5e15b4456c825f78554e2ef1cc6344fa1218448 Mon Sep 17 00:00:00 2001
From: Cristy <urban-warrior@imagemagick.org>
Date: Sat, 5 Oct 2019 09:44:24 -0400
Subject: [PATCH] https://github.com/ImageMagick/ImageMagick/issues/1719

---
 coders/txt.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/coders/txt.c b/coders/txt.c
index 3a57bcece..9f0354ffb 100644
--- a/coders/txt.c
+++ b/coders/txt.c
@@ -572,16 +572,16 @@ static Image *ReadTXTImage(const ImageInfo *image_info,ExceptionInfo *exception)
             green+=(range+1)/2.0;
             blue+=(range+1)/2.0;
           }
-        pixel.red=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (red+0.5),
-          range);
-        pixel.green=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (green+0.5),
-          range);
-        pixel.blue=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (blue+0.5),
-          range);
-        pixel.index=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (index+0.5),
-          range);
-        pixel.opacity=(MagickRealType) ScaleAnyToQuantum((QuantumAny) (opacity+
-          0.5),range);
+        pixel.red=(MagickRealType) ScaleAnyToQuantum((QuantumAny)
+          MagickMax(red+0.5,0.0),range);
+        pixel.green=(MagickRealType) ScaleAnyToQuantum((QuantumAny)
+          MagickMax(green+0.5,0.0),range);
+        pixel.blue=(MagickRealType) ScaleAnyToQuantum((QuantumAny)
+          MagickMax(blue+0.5,0.0),range);
+        pixel.index=(MagickRealType) ScaleAnyToQuantum((QuantumAny)
+          MagickMax(index+0.5,0.0),range);
+        pixel.opacity=(MagickRealType) ScaleAnyToQuantum((QuantumAny)
+          MagickMax(opacity+0.5,0.0),range);
         q=GetAuthenticPixels(image,(ssize_t) x_offset,(ssize_t) y_offset,1,1,
           exception);
         if (q == (PixelPacket *) NULL)
