Skip to content

Commit

Permalink
https://github.com/ImageMagick/ImageMagick/discussions/4856
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Feb 20, 2022
1 parent 3db22d0 commit 66cb4f9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
8 changes: 4 additions & 4 deletions coders/png.c
Original file line number Diff line number Diff line change
Expand Up @@ -11435,7 +11435,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
if (quantum_info == (QuantumInfo *) NULL)
png_error(ping,"Memory allocation for quantum_info failed");
quantum_info->format=UndefinedQuantumFormat;
SetQuantumDepth(image,quantum_info,image_depth);
(void) SetQuantumDepth(image,quantum_info,image_depth);
(void) SetQuantumEndian(image,quantum_info,MSBEndian);
num_passes=png_set_interlace_handling(ping);

Expand All @@ -11462,7 +11462,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
if (mng_info->write_png_colortype-1 == PNG_COLOR_TYPE_PALETTE)
quantum_type=IndexQuantum;
}
SetQuantumDepth(image,quantum_info,8);
(void) SetQuantumDepth(image,quantum_info,8);
for (pass=0; pass < num_passes; pass++)
{
/*
Expand Down Expand Up @@ -11644,7 +11644,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,
(void) LogMagickEvent(CoderEvent,GetMagickModule(),
" pass %d, Image Is not GRAY or GRAY_ALPHA",pass);

SetQuantumDepth(image,quantum_info,8);
(void) SetQuantumDepth(image,quantum_info,8);
image_depth=8;
}

Expand All @@ -11662,7 +11662,7 @@ static MagickBooleanType WriteOnePNGImage(MngInfo *mng_info,

if (ping_color_type == PNG_COLOR_TYPE_GRAY)
{
SetQuantumDepth(image,quantum_info,image->depth);
(void) SetQuantumDepth(image,quantum_info,image->depth);

(void) ExportQuantumPixels(image,(CacheView *) NULL,
quantum_info,GrayQuantum,ping_pixels,exception);
Expand Down
45 changes: 32 additions & 13 deletions coders/strimg.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/property.h"
#include "MagickCore/quantum.h"
#include "MagickCore/quantum-private.h"
#include "MagickCore/static.h"
#include "MagickCore/string_.h"
Expand Down Expand Up @@ -262,9 +263,15 @@ static MagickBooleanType WriteSTRIMGImage(const ImageInfo *image_info,
MagickBooleanType
status;

QuantumInfo
*quantum_info;

ssize_t
y;

unsigned char
*pixels;

/*
Open output image file.
*/
Expand All @@ -282,31 +289,43 @@ static MagickBooleanType WriteSTRIMGImage(const ImageInfo *image_info,
/*
Convert image to a string.
*/
quantum_info=AcquireQuantumInfo(image_info,image);
if (quantum_info == (QuantumInfo *) NULL)
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
if (SetQuantumDepth(image,quantum_info,8) == MagickFalse)
{
quantum_info=DestroyQuantumInfo(quantum_info);
ThrowWriterException(ResourceLimitError,"MemoryAllocationFailed");
}
pixels=(unsigned char *) GetQuantumPixels(quantum_info);
for (y=0; y < (ssize_t) image->rows; y++)
{
const Quantum
*p;

size_t
length;

ssize_t
x;
count;

p=GetVirtualPixels(image,0,y,image->columns,1,exception);
if (p == (const Quantum *) NULL)
break;
for (x=0; x < (ssize_t) image->columns; x++)
{
ssize_t
count;

count=WriteBlobByte(image,ScaleQuantumToChar(GetPixelIntensity(image,
p)));
if (count != 1)
break;
p+=GetPixelChannels(image);
}
if (x < (ssize_t) image->columns)
length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
GrayQuantum,pixels,exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,(MagickOffsetType) y,
image->rows);
if (status == MagickFalse)
break;
}
}
quantum_info=DestroyQuantumInfo(quantum_info);
if (y < (ssize_t) image->rows)
ThrowWriterException(CorruptImageError,"UnableToWriteImageData");
(void) CloseBlob(image);
Expand Down

0 comments on commit 66cb4f9

Please sign in to comment.