Commit fe3f2a30e for imagemagick.org
commit fe3f2a30e4924e5860eb1fe0ba5ec2e151c7e061
Author: Cristy <urban-warrior@imagemagick.org>
Date: Mon Nov 30 19:53:51 2026 -0500
Partition-interlace read of RGBA now reads the alpha plane
diff --git a/coders/rgb.c b/coders/rgb.c
index 74d1b6c43..927988f34 100644
--- a/coders/rgb.c
+++ b/coders/rgb.c
@@ -116,6 +116,7 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
*quantum_info;
QuantumType
+ alpha_type = AlphaQuantum,
quantum_type;
ssize_t
@@ -157,8 +158,12 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
return((Image *) NULL);
}
if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
+ {
+ ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
+ image->filename);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
}
/*
Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
@@ -564,12 +569,14 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
}
if (image->previous == (Image *) NULL)
{
- status=SetImageProgress(image,LoadImageTag,4,6);
+ status=SetImageProgress(image,LoadImageTag,3,6);
if (status == MagickFalse)
break;
}
if (image->alpha_trait != UndefinedPixelTrait)
{
+ alpha_type=(LocaleCompare(image_info->magick,"RGBO") == 0) ?
+ OpacityQuantum : AlphaQuantum;
for (y=0; y < (ssize_t) image->extract_info.height; y++)
{
const Quantum
@@ -593,7 +600,7 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (q == (Quantum *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
- quantum_info,AlphaQuantum,(unsigned char *) stream,exception);
+ quantum_info,alpha_type,(unsigned char *) stream,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
@@ -607,7 +614,10 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
for (x=0; x < columns; x++)
{
- SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
+ if (alpha_type == OpacityQuantum)
+ SetPixelOpacity(image,GetPixelOpacity(canvas_image,p),q);
+ else
+ SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
p+=(ptrdiff_t) GetPixelChannels(canvas_image);
q+=(ptrdiff_t) GetPixelChannels(image);
}
@@ -862,7 +872,9 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
if (status == MagickFalse)
break;
- length=GetQuantumExtent(canvas_image,quantum_info,AlphaQuantum);
+ alpha_type=(LocaleCompare(image_info->magick,"RGBO") == 0) ?
+ OpacityQuantum : AlphaQuantum;
+ length=GetQuantumExtent(canvas_image,quantum_info,alpha_type);
for (i=0; i < (ssize_t) scene; i++)
{
for (y=0; y < (ssize_t) image->extract_info.height; y++)
@@ -898,7 +910,7 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
if (q == (Quantum *) NULL)
break;
length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
- quantum_info,BlueQuantum,(unsigned char *) stream,exception);
+ quantum_info,alpha_type,(unsigned char *) stream,exception);
if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
break;
if (((y-image->extract_info.y) >= 0) &&
@@ -912,13 +924,16 @@ static Image *ReadRGBImage(const ImageInfo *image_info,ExceptionInfo *exception)
break;
for (x=0; x < columns; x++)
{
- SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
+ if (alpha_type == OpacityQuantum)
+ SetPixelOpacity(image,GetPixelOpacity(canvas_image,p),q);
+ else
+ SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
p+=(ptrdiff_t) GetPixelChannels(canvas_image);
q+=(ptrdiff_t) GetPixelChannels(image);
}
if (SyncAuthenticPixels(image,exception) == MagickFalse)
break;
- }
+ }
stream=ReadBlobStream(image,length,pixels,&count);
}
if (image->previous == (Image *) NULL)
@@ -1062,15 +1077,19 @@ static Image *ReadRGB565Image(const ImageInfo *image_info,
return((Image *) NULL);
}
if (DiscardBlobBytes(image,(MagickSizeType) image->offset) == MagickFalse)
- ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
- image->filename);
+ {
+ ThrowFileException(exception,CorruptImageError,"UnexpectedEndOfFile",
+ image->filename);
+ image=DestroyImageList(image);
+ return((Image *) NULL);
+ }
}
/*
Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
*/
canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
exception);
- if(canvas_image == (Image *) NULL)
+ if (canvas_image == (Image *) NULL)
ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
(void) SetImageVirtualPixelMethod(canvas_image,BlackVirtualPixelMethod,
exception);
@@ -1159,13 +1178,22 @@ static Image *ReadRGB565Image(const ImageInfo *image_info,
for (x=0; x < columns; x++)
{
unsigned short
- pixel;
+ blue,
+ green,
+ pixel,
+ red;
pixel=(unsigned short) ScaleQuantumToShort(GetPixelGray(
canvas_image,p));
- SetPixelRed(image,(Quantum) (((pixel >> 11) & 0x1f) << 11),q);
- SetPixelGreen(image,(Quantum) (((pixel >> 5) & 0x3f) << 10),q);
- SetPixelBlue(image,(Quantum) ((pixel & 0x1f) << 11),q);
+ red=(unsigned short) ((pixel >> 11) & 0x1f);
+ green=(unsigned short) ((pixel >> 5) & 0x3f);
+ blue=(unsigned short) (pixel & 0x1f);
+ SetPixelRed(image,ScaleShortToQuantum((unsigned short)
+ ((red << 11) | (red << 6) | (red << 1) | (red >> 4))),q);
+ SetPixelGreen(image,ScaleShortToQuantum((unsigned short)
+ ((green << 10) | (green << 4) | (green >> 2))),q);
+ SetPixelBlue(image,ScaleShortToQuantum((unsigned short)
+ ((blue << 11) | (blue << 6) | (blue << 1) | (blue >> 4))),q);
p+=(ptrdiff_t) GetPixelChannels(canvas_image);
q+=(ptrdiff_t) GetPixelChannels(image);
}
@@ -1183,7 +1211,6 @@ static Image *ReadRGB565Image(const ImageInfo *image_info,
}
if (status == MagickFalse)
break;
- SetQuantumImageType(image,quantum_type);
/*
Proceed to next image.
*/
@@ -1297,6 +1324,7 @@ ModuleExport size_t RegisterRGBImage(void)
*/
ModuleExport void UnregisterRGBImage(void)
{
+ (void) UnregisterMagickInfo("RGB565");
(void) UnregisterMagickInfo("RGBO");
(void) UnregisterMagickInfo("RGBA");
(void) UnregisterMagickInfo("RGB");
@@ -1343,6 +1371,7 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
*quantum_info;
QuantumType
+ alpha_type = AlphaQuantum,
quantum_type;
size_t
@@ -1378,7 +1407,10 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
if (LocaleCompare(image_info->magick,"RGBA") == 0)
quantum_type=RGBAQuantum;
if (LocaleCompare(image_info->magick,"RGBO") == 0)
- quantum_type=RGBOQuantum;
+ {
+ quantum_type=RGBOQuantum;
+ alpha_type=OpacityQuantum;
+ }
scene=0;
number_scenes=GetImageListLength(image);
do
@@ -1388,7 +1420,7 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
*/
if (IssRGBCompatibleColorspace(image->colorspace) == MagickFalse)
(void) TransformImageColorspace(image,sRGBColorspace,exception);
- if ((LocaleCompare(image_info->magick,"RGBA") == 0) &&
+ if (((quantum_type == RGBAQuantum) || (quantum_type == RGBOQuantum)) &&
((image->alpha_trait & BlendPixelTrait) == 0))
(void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception);
quantum_info=AcquireQuantumInfo(image_info,image);
@@ -1466,21 +1498,10 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
status=MagickFalse;
break;
}
- if (quantum_type == RGBAQuantum)
- {
- length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- AlphaQuantum,pixels,exception);
- count=WriteBlob(image,length,pixels);
- if (count != (ssize_t) length)
- {
- status=MagickFalse;
- break;
- }
- }
- if (quantum_type == RGBOQuantum)
+ if ((quantum_type == RGBAQuantum) || (quantum_type == RGBOQuantum))
{
length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- OpacityQuantum,pixels,exception);
+ alpha_type,pixels,exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
{
@@ -1520,6 +1541,8 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
break;
}
}
+ if (status == MagickFalse)
+ break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,1,6);
@@ -1543,6 +1566,8 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
break;
}
}
+ if (status == MagickFalse)
+ break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,2,6);
@@ -1566,13 +1591,15 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
break;
}
}
+ if (status == MagickFalse)
+ break;
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,3,6);
if (status == MagickFalse)
break;
}
- if (quantum_type == RGBAQuantum)
+ if ((quantum_type == RGBAQuantum) || (quantum_type == RGBOQuantum))
{
for (y=0; y < (ssize_t) image->rows; y++)
{
@@ -1583,7 +1610,7 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
if (p == (const Quantum *) NULL)
break;
length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- AlphaQuantum,pixels,exception);
+ alpha_type,pixels,exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
{
@@ -1598,9 +1625,6 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
break;
}
}
- if (image_info->interlace == PartitionInterlace)
- (void) CopyMagickString(image->filename,image_info->filename,
- MagickPathExtent);
if (image->previous == (Image *) NULL)
{
status=SetImageProgress(image,SaveImageTag,6,6);
@@ -1711,7 +1735,7 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
if (status == MagickFalse)
break;
}
- if (quantum_type == RGBAQuantum)
+ if ((quantum_type == RGBAQuantum) || (quantum_type == RGBOQuantum))
{
if (CloseBlob(image) == MagickFalse)
break;
@@ -1732,7 +1756,7 @@ static MagickBooleanType WriteRGBImage(const ImageInfo *image_info,
if (p == (const Quantum *) NULL)
break;
length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
- AlphaQuantum,pixels,exception);
+ alpha_type,pixels,exception);
count=WriteBlob(image,length,pixels);
if (count != (ssize_t) length)
{