Commit befd5d8af for imagemagick.org

commit befd5d8afe6cd0555c7738b1371f20f0c4c6d02b
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Wed Dec 2 19:06:14 2026 -0500

    empty colors, e.g. white-,  now falls back to its default

diff --git a/coders/gradient.c b/coders/gradient.c
index ffa173651..c68bb3569 100644
--- a/coders/gradient.c
+++ b/coders/gradient.c
@@ -62,27 +62,25 @@
 #include "MagickCore/static.h"
 #include "MagickCore/string_.h"
 #include "MagickCore/module.h"
-#include "MagickCore/studio.h"

 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   R e a d G R A D I E N T I m a g e                                         %
+%   R e a d X C I m a g e                                                     %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ReadGRADIENTImage creates a gradient image and initializes it to
-%  the color range as specified by the filename.  It allocates the memory
-%  necessary for the new Image structure and returns a pointer to the new
-%  image.
+%  ReadXCImage creates a solid-color image filled with the color named by
+%  the filename (or the background color if no name is given).  It is used
+%  as the base canvas for the gradient.
 %
-%  The format of the ReadGRADIENTImage method is:
+%  The format of the ReadXCImage method is:
 %
-%      Image *ReadGRADIENTImage(const ImageInfo *image_info,
+%      Image *ReadXCImage(const ImageInfo *image_info,
 %        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -151,17 +149,54 @@ static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
   {
     q=QueueAuthenticPixels(image,0,y,image->columns,1,exception);
     if (q == (Quantum *) NULL)
-      break;
+      {
+        status=MagickFalse;
+        break;
+      }
     for (x=0; x < (ssize_t) image->columns; x++)
     {
       SetPixelViaPixelInfo(image,&pixel,q);
       q+=(ptrdiff_t) GetPixelChannels(image);
     }
     if (SyncAuthenticPixels(image,exception) == MagickFalse)
-      break;
+      {
+        status=MagickFalse;
+        break;
+      }
   }
+  if (status == MagickFalse)
+    return(DestroyImageList(image));
   return(GetFirstImageInList(image));
 }
+
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   R e a d G R A D I E N T I m a g e                                         %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ReadGRADIENTImage creates a gradient image and initializes it to
+%  the color range as specified by the filename.  It allocates the memory
+%  necessary for the new Image structure and returns a pointer to the new
+%  image.
+%
+%  The format of the ReadGRADIENTImage method is:
+%
+%      Image *ReadGRADIENTImage(const ImageInfo *image_info,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image_info: the image info.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/

 static Image *ReadGRADIENTImage(const ImageInfo *image_info,
   ExceptionInfo *exception)
@@ -180,7 +215,7 @@ static Image *ReadGRADIENTImage(const ImageInfo *image_info,
     status;

   StopInfo
-    *stops;
+    stops[2];

   /*
     Identify start and stop gradient colors.
@@ -211,6 +246,13 @@ static Image *ReadGRADIENTImage(const ImageInfo *image_info,
       if (*p == '-')
         (void) CopyMagickString(stop_color,p+1,MagickPathExtent);
       *p='\0';
+      /*
+        An omitted color ("-black", "white-") falls back to its default.
+      */
+      if (*start_color == '\0')
+        (void) CopyMagickString(start_color,"white",MagickPathExtent);
+      if (*stop_color == '\0')
+        (void) CopyMagickString(stop_color,"black",MagickPathExtent);
     }
   /*
     Create base gradient image from start color.
@@ -222,12 +264,12 @@ static Image *ReadGRADIENTImage(const ImageInfo *image_info,
   read_info=DestroyImageInfo(read_info);
   if (image == (Image *) NULL)
     return((Image *) NULL);
+  (void) CopyMagickString(image->filename,image_info->filename,
+    MagickPathExtent);
   /*
     Create gradient stops.
   */
-  stops=(StopInfo *) AcquireQuantumMemory(2,sizeof(*stops));
-  if (stops == (StopInfo *) NULL)
-    ThrowReaderException(ResourceLimitError,"MemoryAllocationFailed");
+  (void) memset(stops,0,sizeof(stops));
   stops[0].offset=0.0;
   stops[1].offset=1.0;
   status=QueryColorCompliance(start_color,AllCompliance,&stops[0].color,
@@ -237,20 +279,18 @@ static Image *ReadGRADIENTImage(const ImageInfo *image_info,
       exception);
   if (status == MagickFalse)
     {
-      stops=(StopInfo *) RelinquishMagickMemory(stops);
-      image=DestroyImage(image);
+      image=DestroyImageList(image);
       return((Image *) NULL);
     }
   (void) SetImageColorspace(image,stops[0].color.colorspace,exception);
   if ((stops[0].color.alpha_trait != UndefinedPixelTrait) ||
       (stops[1].color.alpha_trait != UndefinedPixelTrait))
-    SetImageAlpha(image,TransparentAlpha,exception);
+    (void) SetImageAlpha(image,TransparentAlpha,exception);
   /*
     Paint gradient.
   */
   status=GradientImage(image,LocaleCompare(image_info->magick,"GRADIENT") == 0 ?
     LinearGradient : RadialGradient,PadSpread,stops,2,exception);
-  stops=(StopInfo *) RelinquishMagickMemory(stops);
   if (status == MagickFalse)
     {
       image=DestroyImageList(image);
@@ -290,14 +330,14 @@ ModuleExport size_t RegisterGRADIENTImage(void)
   entry=AcquireMagickInfo("GRADIENT","GRADIENT",
     "Gradual linear passing from one shade to another");
   entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
-  entry->flags^=CoderAdjoinFlag;
+  entry->flags&=~CoderAdjoinFlag;
   entry->flags|=CoderRawSupportFlag;
   entry->format_type=ImplicitFormatType;
   (void) RegisterMagickInfo(entry);
   entry=AcquireMagickInfo("GRADIENT","RADIAL-GRADIENT",
     "Gradual radial passing from one shade to another");
   entry->decoder=(DecodeImageHandler *) ReadGRADIENTImage;
-  entry->flags^=CoderAdjoinFlag;
+  entry->flags&=~CoderAdjoinFlag;
   entry->flags|=CoderRawSupportFlag;
   entry->format_type=ImplicitFormatType;
   (void) RegisterMagickInfo(entry);