Skip to content

Commit

Permalink
optimize on grayscale detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jul 20, 2021
1 parent e2045ec commit e38fce1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions coders/ps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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]);
}
Expand All @@ -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;
Expand Down

0 comments on commit e38fce1

Please sign in to comment.