Commit 3a2f02c22 for imagemagick.org

commit 3a2f02c22a4b804434cf1f5921a7d92f534e7afa
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Mon Nov 30 19:59:09 2026 -0500

    partition alpha plane now uses AlphaQuantum

diff --git a/coders/gray.c b/coders/gray.c
index ae613ba10..f8d59a790 100644
--- a/coders/gray.c
+++ b/coders/gray.c
@@ -149,7 +149,6 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
   status=SetImageExtent(image,image->columns,image->rows,exception);
   if (status == MagickFalse)
     return(DestroyImageList(image));
-  (void) SetImageColorspace(image,GRAYColorspace,exception);
   if (image_info->interlace != PartitionInterlace)
     {
       status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
@@ -163,7 +162,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
           image->filename);
     }
   /*
-    Create virtual canvas to support cropping (i.e. image.rgb[100x100+10+20]).
+    Create virtual canvas to support cropping (i.e. image.gray[100x100+10+20]).
   */
   canvas_image=CloneImage(image,image->extract_info.width,1,MagickFalse,
     exception);
@@ -217,6 +216,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
     status=SetImageExtent(image,image->columns,image->rows,exception);
     if (status == MagickFalse)
       break;
+    (void) SetImageColorspace(image,GRAYColorspace,exception);
     switch (image_info->interlace)
     {
       case NoInterlace:
@@ -251,12 +251,18 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
             exception);
           if (q == (Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
             quantum_info,quantum_type,(unsigned char *) stream,exception);
           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-            break;
-          if (((y-image->extract_info.y) >= 0) &&
+            {
+              status=MagickFalse;
+              break;
+            }
+          if (((y-image->extract_info.y) >= 0) &&
               ((y-image->extract_info.y) < (ssize_t) image->rows))
             {
               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
@@ -264,20 +270,23 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               q=QueueAuthenticPixels(image,0,y-image->extract_info.y,
                 image->columns,1,exception);
               if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               for (x=0; x < columns; x++)
               {
-                SetPixelRed(image,GetPixelRed(canvas_image,p),q);
-                SetPixelGreen(image,GetPixelGreen(canvas_image,p),q);
-                SetPixelBlue(image,GetPixelBlue(canvas_image,p),q);
-                SetPixelAlpha(image,OpaqueAlpha,q);
+                SetPixelGray(image,GetPixelGray(canvas_image,p),q);
                 if (image->alpha_trait != UndefinedPixelTrait)
                   SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
                 p+=(ptrdiff_t) GetPixelChannels(canvas_image);
                 q+=(ptrdiff_t) GetPixelChannels(image);
               }
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
             }
           if (image->previous == (Image *) NULL)
             {
@@ -292,25 +301,28 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
       }
       case LineInterlace:
       {
-        static QuantumType
-          quantum_types[4] =
+        static const QuantumType
+          quantum_types[2] =
           {
             GrayQuantum,
             AlphaQuantum
           };

         /*
-          Line interlacing:  G...G...G...
+          Line interlacing:  G...A...G...A...
         */
         if (scene == 0)
           {
-            length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
+            length=GetQuantumExtent(canvas_image,quantum_info,GrayQuantum);
             stream=ReadBlobStream(image,length,pixels,&count);
           }
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
         {
-          for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 4 : 3); i++)
+          for (i=0; i < (ssize_t) (image->alpha_trait != UndefinedPixelTrait ? 2 : 1); i++)
           {
+            QuantumType
+              line_type;
+
             const Quantum
               *magick_restrict p;

@@ -327,16 +339,22 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                   "UnexpectedEndOfFile",image->filename);
                 break;
               }
-            quantum_type=quantum_types[i];
+            line_type=quantum_types[i];
             q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
               exception);
             if (q == (Quantum *) NULL)
-              break;
+              {
+                status=MagickFalse;
+                break;
+              }
             length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
-              quantum_info,quantum_type,(unsigned char *) stream,exception);
+              quantum_info,line_type,(unsigned char *) stream,exception);
             if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-              break;
-            if (((y-image->extract_info.y) >= 0) &&
+              {
+                status=MagickFalse;
+                break;
+              }
+            if (((y-image->extract_info.y) >= 0) &&
                 ((y-image->extract_info.y) < (ssize_t) image->rows))
               {
                 p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
@@ -344,10 +362,13 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                 q=GetAuthenticPixels(image,0,y-image->extract_info.y,
                   image->columns,1,exception);
                 if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                  break;
+                  {
+                    status=MagickFalse;
+                    break;
+                  }
                 for (x=0; x < columns; x++)
                 {
-                  switch (quantum_type)
+                  switch (line_type)
                   {
                     case GrayQuantum:
                     {
@@ -366,10 +387,15 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                   q+=(ptrdiff_t) GetPixelChannels(image);
                 }
                 if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                  break;
+                  {
+                    status=MagickFalse;
+                    break;
+                  }
               }
             stream=ReadBlobStream(image,length,pixels,&count);
           }
+          if (status == MagickFalse)
+            break;
           if (image->previous == (Image *) NULL)
             {
               status=SetImageProgress(image,LoadImageTag,(MagickOffsetType) y,
@@ -383,11 +409,11 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
       case PlaneInterlace:
       {
         /*
-          Plane interlacing:  G...G...G...
+          Plane interlacing:  GGG...AAA...
         */
         if (scene == 0)
           {
-            length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
+            length=GetQuantumExtent(canvas_image,quantum_info,GrayQuantum);
             stream=ReadBlobStream(image,length,pixels,&count);
           }
         for (y=0; y < (ssize_t) image->extract_info.height; y++)
@@ -411,12 +437,18 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
             exception);
           if (q == (Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
-            quantum_info,RedQuantum,(unsigned char *) stream,exception);
+            quantum_info,GrayQuantum,(unsigned char *) stream,exception);
           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-            break;
-          if (((y-image->extract_info.y) >= 0) &&
+            {
+              status=MagickFalse;
+              break;
+            }
+          if (((y-image->extract_info.y) >= 0) &&
               ((y-image->extract_info.y) < (ssize_t) image->rows))
             {
               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
@@ -424,7 +456,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
                 image->columns,1,exception);
               if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               for (x=0; x < columns; x++)
               {
                 SetPixelGray(image,GetPixelGray(canvas_image,p),q);
@@ -432,10 +467,15 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                 q+=(ptrdiff_t) GetPixelChannels(image);
               }
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
             }
           stream=ReadBlobStream(image,length,pixels,&count);
         }
+        if (status == MagickFalse)
+          break;
         if (image->previous == (Image *) NULL)
           {
             status=SetImageProgress(image,LoadImageTag,1,6);
@@ -465,12 +505,18 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
                 exception);
               if (q == (Quantum *) NULL)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
                 quantum_info,AlphaQuantum,(unsigned char *) stream,exception);
               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-                break;
-              if (((y-image->extract_info.y) >= 0) &&
+                {
+                  status=MagickFalse;
+                  break;
+                }
+              if (((y-image->extract_info.y) >= 0) &&
                   ((y-image->extract_info.y) < (ssize_t) image->rows))
                 {
                   p=GetVirtualPixels(canvas_image,
@@ -479,7 +525,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
                     image->columns,1,exception);
                   if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                    break;
+                    {
+                      status=MagickFalse;
+                      break;
+                    }
                   for (x=0; x < columns; x++)
                   {
                     SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
@@ -487,7 +536,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                     q+=(ptrdiff_t) GetPixelChannels(image);
                   }
                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                    break;
+                    {
+                      status=MagickFalse;
+                      break;
+                    }
                 }
               stream=ReadBlobStream(image,length,pixels,&count);
             }
@@ -509,7 +561,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
       case PartitionInterlace:
       {
         /*
-          Partition interlacing:  G..., G..., G...
+          Partition interlacing:  G..., A...
         */
         AppendImageFormat("G",image->filename);
         status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
@@ -522,7 +574,7 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               "UnexpectedEndOfFile",image->filename);
             break;
           }
-        length=GetQuantumExtent(canvas_image,quantum_info,RedQuantum);
+        length=GetQuantumExtent(canvas_image,quantum_info,GrayQuantum);
         for (i=0; i < (ssize_t) scene; i++)
         {
           for (y=0; y < (ssize_t) image->extract_info.height; y++)
@@ -556,12 +608,18 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
           q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
             exception);
           if (q == (Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
-            quantum_info,RedQuantum,(unsigned char *) stream,exception);
+            quantum_info,GrayQuantum,(unsigned char *) stream,exception);
           if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-            break;
-          if (((y-image->extract_info.y) >= 0) &&
+            {
+              status=MagickFalse;
+              break;
+            }
+          if (((y-image->extract_info.y) >= 0) &&
               ((y-image->extract_info.y) < (ssize_t) image->rows))
             {
               p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,0,
@@ -569,15 +627,21 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               q=GetAuthenticPixels(image,0,y-image->extract_info.y,
                 image->columns,1,exception);
               if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               for (x=0; x < columns; x++)
               {
-                SetPixelRed(image,GetPixelRed(canvas_image,p),q);
+                SetPixelGray(image,GetPixelGray(canvas_image,p),q);
                 p+=(ptrdiff_t) GetPixelChannels(canvas_image);
                 q+=(ptrdiff_t) GetPixelChannels(image);
               }
               if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
             }
           stream=ReadBlobStream(image,length,pixels,&count);
         }
@@ -588,10 +652,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               break;
           }
         (void) CloseBlob(image);
+        if (status == MagickFalse)
+          break;
         if (image->alpha_trait != UndefinedPixelTrait)
           {
-            if (CloseBlob(image) == MagickFalse)
-              break;
             AppendImageFormat("A",image->filename);
             status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
             if (status == MagickFalse)
@@ -630,12 +694,18 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               q=GetAuthenticPixels(canvas_image,0,0,canvas_image->columns,1,
                 exception);
               if (q == (Quantum *) NULL)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               length=ImportQuantumPixels(canvas_image,(CacheView *) NULL,
-                quantum_info,BlueQuantum,(unsigned char *) stream,exception);
+                quantum_info,AlphaQuantum,(unsigned char *) stream,exception);
               if (SyncAuthenticPixels(canvas_image,exception) == MagickFalse)
-                break;
-              if (((y-image->extract_info.y) >= 0) &&
+                {
+                  status=MagickFalse;
+                  break;
+                }
+              if (((y-image->extract_info.y) >= 0) &&
                   ((y-image->extract_info.y) < (ssize_t) image->rows))
                 {
                   p=GetVirtualPixels(canvas_image,canvas_image->extract_info.x,
@@ -643,7 +713,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                   q=GetAuthenticPixels(image,0,y-image->extract_info.y,
                     image->columns,1,exception);
                   if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-                    break;
+                    {
+                      status=MagickFalse;
+                      break;
+                    }
                   for (x=0; x < columns; x++)
                   {
                     SetPixelAlpha(image,GetPixelAlpha(canvas_image,p),q);
@@ -651,7 +724,10 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
                     q+=(ptrdiff_t) GetPixelChannels(image);
                   }
                   if (SyncAuthenticPixels(image,exception) == MagickFalse)
-                    break;
+                    {
+                      status=MagickFalse;
+                      break;
+                    }
                }
               stream=ReadBlobStream(image,length,pixels,&count);
             }
@@ -663,6 +739,8 @@ static Image *ReadGRAYImage(const ImageInfo *image_info,
               }
           }
         (void) CloseBlob(image);
+        (void) CopyMagickString(image->filename,image_info->filename,
+          MagickPathExtent);
         if (image->previous == (Image *) NULL)
           {
             status=SetImageProgress(image,LoadImageTag,5,5);
@@ -790,8 +868,8 @@ ModuleExport void UnregisterGRAYImage(void)
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  WriteGRAYImage() writes an image to a file in the GRAY, GRAYAlpha, or GRAYO
-%  rasterfile format.
+%  WriteGRAYImage() writes an image to a file in the GRAY or GRAYA raw
+%  raster format.
 %
 %  The format of the WriteGRAYImage method is:
 %
@@ -884,7 +962,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
           if (p == (const Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
             quantum_type,pixels,exception);
           count=WriteBlob(image,length,pixels);
@@ -906,7 +987,7 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
       case LineInterlace:
       {
         /*
-          Line interlacing:  G...G...G...
+          Line interlacing:  G...A...G...A...
         */
         for (y=0; y < (ssize_t) image->rows; y++)
         {
@@ -915,7 +996,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
           if (p == (const Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
             GrayQuantum,pixels,exception);
           count=WriteBlob(image,length,pixels);
@@ -948,7 +1032,7 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
       case PlaneInterlace:
       {
         /*
-          Plane interlacing:  G...G...G...
+          Plane interlacing:  GGG...AAA...
         */
         for (y=0; y < (ssize_t) image->rows; y++)
         {
@@ -957,7 +1041,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
           if (p == (const Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
             GrayQuantum,pixels,exception);
           count=WriteBlob(image,length,pixels);
@@ -967,6 +1054,8 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
               break;
             }
         }
+        if (status == MagickFalse)
+          break;
         if (image->previous == (Image *) NULL)
           {
             status=SetImageProgress(image,SaveImageTag,1,6);
@@ -982,7 +1071,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
               if (p == (const Quantum *) NULL)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
                 AlphaQuantum,pixels,exception);
               count=WriteBlob(image,length,pixels);
@@ -999,9 +1091,6 @@ static MagickBooleanType WriteGRAYImage(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);
@@ -1013,7 +1102,7 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
       case PartitionInterlace:
       {
         /*
-          Partition interlacing:  G..., G..., G...
+          Partition interlacing:  G..., A...
         */
         AppendImageFormat("G",image->filename);
         status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
@@ -1030,9 +1119,12 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

           p=GetVirtualPixels(image,0,y,image->columns,1,exception);
           if (p == (const Quantum *) NULL)
-            break;
+            {
+              status=MagickFalse;
+              break;
+            }
           length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
-            RedQuantum,pixels,exception);
+            GrayQuantum,pixels,exception);
           count=WriteBlob(image,length,pixels);
           if (count != (ssize_t) length)
             {
@@ -1040,6 +1132,8 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
               break;
             }
         }
+        if (status == MagickFalse)
+          break;
         if (image->previous == (Image *) NULL)
           {
             status=SetImageProgress(image,SaveImageTag,1,6);
@@ -1050,7 +1144,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,
         if (quantum_type == GrayAlphaQuantum)
           {
             if (CloseBlob(image) == MagickFalse)
-              break;
+              {
+                status=MagickFalse;
+                break;
+              }
             AppendImageFormat("A",image->filename);
             status=OpenBlob(image_info,image,scene == 0 ? WriteBinaryBlobMode :
               AppendBinaryBlobMode,exception);
@@ -1066,7 +1163,10 @@ static MagickBooleanType WriteGRAYImage(const ImageInfo *image_info,

               p=GetVirtualPixels(image,0,y,image->columns,1,exception);
               if (p == (const Quantum *) NULL)
-                break;
+                {
+                  status=MagickFalse;
+                  break;
+                }
               length=ExportQuantumPixels(image,(CacheView *) NULL,quantum_info,
                 AlphaQuantum,pixels,exception);
               count=WriteBlob(image,length,pixels);