Commit a9f3b47af for imagemagick.org
commit a9f3b47af88a8844da154c9b69d6b9d5fb445994
Author: Dirk Lemstra <dirk@lemstra.org>
Date: Wed Nov 25 12:05:09 2026 +0100
Write the MONO pixels per row instead.
diff --git a/coders/mono.c b/coders/mono.c
index 381738bd5..e57565523 100644
--- a/coders/mono.c
+++ b/coders/mono.c
@@ -299,11 +299,16 @@ static MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
size_t
bit,
- byte;
+ byte,
+ length;
ssize_t
y;
+ unsigned char
+ *pixels,
+ *q;
+
/*
Open output image file.
*/
@@ -324,6 +329,10 @@ static MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
Convert image to a bi-level image.
*/
(void) SetImageType(image,BilevelType,exception);
+ length=image->columns/8+(image->columns % 8 != 0 ? 1 : 0);
+ pixels=(unsigned char *) AcquireQuantumMemory(length,sizeof(*pixels));
+ if (pixels == (unsigned char *) NULL)
+ ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetVirtualPixels(image,0,y,image->columns,1,exception);
@@ -331,6 +340,7 @@ static MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
break;
bit=0;
byte=0;
+ q=pixels;
for (x=0; x < (ssize_t) image->columns; x++)
{
byte>>=1;
@@ -345,19 +355,25 @@ static MagickBooleanType WriteMONOImage(const ImageInfo *image_info,
bit++;
if (bit == 8)
{
- (void) WriteBlobByte(image,(unsigned char) byte);
+ *q++=(unsigned char) byte;
bit=0;
byte=0;
}
p+=(ptrdiff_t) GetPixelChannels(image);
}
if (bit != 0)
- (void) WriteBlobByte(image,(unsigned char) (byte >> (8-bit)));
+ *q++=(unsigned char) (byte >> (8-bit));
+ if (WriteBlob(image,length,pixels) != (ssize_t) length)
+ {
+ status=MagickFalse;
+ break;
+ }
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
+ pixels=(unsigned char *) RelinquishMagickMemory(pixels);
if (CloseBlob(image) == MagickFalse)
status=MagickFalse;
return(status);