From e38fce1ef0f7b569ec664a4b228335e34e037ae0 Mon Sep 17 00:00:00 2001 From: Cristy Date: Mon, 19 Jul 2021 21:09:32 -0400 Subject: [PATCH] optimize on grayscale detection --- coders/ps.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/coders/ps.c b/coders/ps.c index caa1625b80..9937c5d1c3 100644 --- a/coders/ps.c +++ b/coders/ps.c @@ -342,7 +342,8 @@ static void ReadPSInfo(const ImageInfo *image_info,Image *image, i=0; for (c=ReadMagickByteBuffer(&buffer); c != EOF; c=ReadMagickByteBuffer(&buffer)) { - if ((c == '\r') || (c == '\n') || ((i+1) == sizeof(version))) + if ((c == '\r') || (c == '\n') || + ((i+1) == (ssize_t) sizeof(version))) break; version[i++]=(char) c; } @@ -1476,6 +1477,9 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) imageListLength=GetImageListLength(image); do { + ImageType + type = UndefinedType; + /* Scale relative to dots-per-inch. */ @@ -1770,8 +1774,7 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) { for (i=0; labels[i] != (char *) NULL; i++) { - (void) FormatLocaleString(buffer,MaxTextExtent,"%s \n", - labels[i]); + (void) FormatLocaleString(buffer,MaxTextExtent,"%s \n",labels[i]); (void) WriteBlobString(image,buffer); labels[i]=DestroyString(labels[i]); } @@ -1781,10 +1784,11 @@ static MagickBooleanType WritePSImage(const ImageInfo *image_info,Image *image) pixel.opacity=(Quantum) TransparentOpacity; index=(IndexPacket) 0; x=0; - if ((image_info->type != TrueColorType) && - (SetImageGray(image,&image->exception) != MagickFalse)) + if (image_info->type != TrueColorType) + type=IdentifyImageType(image,&image->exception); + if ((type == GrayscaleType) || (type == BilevelType)) { - if (SetImageMonochrome(image,&image->exception) == MagickFalse) + if (type == GrayscaleType) { Quantum pixel;