Commit 4cd023cc4 for imagemagick.org

commit 4cd023cc4729b49b4121905406bcc143194192d2
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Fri Dec 4 22:28:54 2026 -0500

    RadonTransform() always reported success, even when reading pixels failed

diff --git a/MagickCore/shear.c b/MagickCore/shear.c
index 5925967fc..542d8939e 100644
--- a/MagickCore/shear.c
+++ b/MagickCore/shear.c
@@ -98,7 +98,7 @@
 %  The format of the CropToFitImage method is:
 %
 %      MagickBooleanType CropToFitImage(Image **image,
-%        const double x_shear,const double x_shear,
+%        const double x_shear,const double y_shear,
 %        const double width,const double height,
 %        const MagickBooleanType rotate,ExceptionInfo *exception)
 %
@@ -108,6 +108,9 @@
 %
 %    o x_shear, y_shear, width, height: Defines a region of the image to crop.
 %
+%    o rotate: apply the second X shear (three-shear rotation) when computing
+%      the bounding box.
+%
 %    o exception: return any errors or warnings in this structure.
 %
 */
@@ -430,6 +433,13 @@ static MagickBooleanType RadonTransform(const Image *image,
         (void) SetMatrixElement(source_matrices,--i,y,&value);
       }
   }
+  if (status == MagickFalse)
+    {
+      image_view=DestroyCacheView(image_view);
+      destination_matrices=DestroyMatrixInfo(destination_matrices);
+      source_matrices=DestroyMatrixInfo(source_matrices);
+      return(MagickFalse);
+    }
   RadonProjection(source_matrices,destination_matrices,-1,projection);
   (void) NullMatrix(source_matrices);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
@@ -487,11 +497,12 @@ static MagickBooleanType RadonTransform(const Image *image,
         (void) SetMatrixElement(source_matrices,i++,y,&value);
       }
   }
-  RadonProjection(source_matrices,destination_matrices,1,projection);
+  if (status != MagickFalse)
+    RadonProjection(source_matrices,destination_matrices,1,projection);
   image_view=DestroyCacheView(image_view);
   destination_matrices=DestroyMatrixInfo(destination_matrices);
   source_matrices=DestroyMatrixInfo(source_matrices);
-  return(MagickTrue);
+  return(status);
 }

 static void GetImageBackgroundColor(Image *image,const ssize_t offset,
@@ -510,11 +521,15 @@ static void GetImageBackgroundColor(Image *image,const ssize_t offset,
     y;

   /*
-    Compute average background color.
+    Compute average background color from a border frame 'offset' pixels wide.
   */
   if (offset <= 0)
     return;
   GetPixelInfo(image,&background);
+  background.red=0.0;
+  background.green=0.0;
+  background.blue=0.0;
+  background.alpha=0.0;
   count=0.0;
   image_view=AcquireVirtualCacheView(image,exception);
   for (y=0; y < (ssize_t) image->rows; y++)
@@ -522,28 +537,35 @@ static void GetImageBackgroundColor(Image *image,const ssize_t offset,
     const Quantum
       *magick_restrict p;

+    MagickBooleanType
+      edge_row;
+
     ssize_t
       x;

-    if ((y >= offset) && (y < ((ssize_t) image->rows-offset)))
-      continue;
+    edge_row=((y < offset) || (y >= ((ssize_t) image->rows-offset))) ?
+      MagickTrue : MagickFalse;
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
     if (p == (const Quantum *) NULL)
       continue;
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      if ((x >= offset) && (x < ((ssize_t) image->columns-offset)))
-        continue;
-      background.red+=QuantumScale*(double) GetPixelRed(image,p);
-      background.green+=QuantumScale*(double) GetPixelGreen(image,p);
-      background.blue+=QuantumScale*(double) GetPixelBlue(image,p);
-      if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
-        background.alpha+=QuantumScale*(double) GetPixelAlpha(image,p);
-      count++;
+      if ((edge_row != MagickFalse) || (x < offset) ||
+          (x >= ((ssize_t) image->columns-offset)))
+        {
+          background.red+=QuantumScale*(double) GetPixelRed(image,p);
+          background.green+=QuantumScale*(double) GetPixelGreen(image,p);
+          background.blue+=QuantumScale*(double) GetPixelBlue(image,p);
+          if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0)
+            background.alpha+=QuantumScale*(double) GetPixelAlpha(image,p);
+          count++;
+        }
       p+=(ptrdiff_t) GetPixelChannels(image);
     }
   }
   image_view=DestroyCacheView(image_view);
+  if (count == 0.0)
+    return;
   image->background_color.red=(double) ClampToQuantum((double) QuantumRange*
     (double) background.red/count);
   image->background_color.green=(double) ClampToQuantum((double) QuantumRange*
@@ -588,6 +610,12 @@ MagickExport Image *DeskewImage(const Image *image,const double threshold,
     i,
     skew;

+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  if (IsEventLogging() != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   /*
     Compute deskew angle.
   */
@@ -723,6 +751,11 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
     Initialize rotated image attributes.
   */
   assert(image != (Image *) NULL);
+  assert(image->signature == MagickCoreSignature);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickCoreSignature);
+  if (IsEventLogging() != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   page=image->page;
   rotations%=4;
   switch (rotations)
@@ -775,7 +808,7 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
       GetPixelCacheTileSize(image,&tile_width,&tile_height);
       tile_width=image->columns;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static) shared(status) \
+      #pragma omp parallel for schedule(static) shared(progress,status) \
         magick_number_threads(image,rotate_image,image->rows/tile_height,2)
 #endif
       for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
@@ -868,8 +901,12 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
             MagickBooleanType
               proceed;

-            proceed=SetImageProgress(image,RotateImageTag,
-              progress+=(MagickOffsetType) tile_height,image->rows);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+            #pragma omp atomic
+#endif
+            progress+=(MagickOffsetType) tile_height;
+            proceed=SetImageProgress(image,RotateImageTag,progress,
+              image->rows);
             if (proceed == MagickFalse)
               status=MagickFalse;
           }
@@ -891,7 +928,7 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
         Rotate 180 degrees.
       */
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static) shared(status) \
+      #pragma omp parallel for schedule(static) shared(progress,status) \
         magick_number_threads(image,rotate_image,image->rows,2)
 #endif
       for (y=0; y < (ssize_t) image->rows; y++)
@@ -946,7 +983,11 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
             MagickBooleanType
               proceed;

-            proceed=SetImageProgress(image,RotateImageTag,progress++,
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+            #pragma omp atomic
+#endif
+            progress++;
+            proceed=SetImageProgress(image,RotateImageTag,progress,
               image->rows);
             if (proceed == MagickFalse)
               status=MagickFalse;
@@ -975,7 +1016,7 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
       GetPixelCacheTileSize(image,&tile_width,&tile_height);
       tile_width=image->columns;
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-      #pragma omp parallel for schedule(static) shared(status) \
+      #pragma omp parallel for schedule(static) shared(progress,status) \
         magick_number_threads(image,rotate_image,image->rows/tile_height,2)
 #endif
       for (tile_y=0; tile_y < (ssize_t) image->rows; tile_y+=(ssize_t) tile_height)
@@ -1070,8 +1111,12 @@ MagickExport Image *IntegralRotateImage(const Image *image,size_t rotations,
             MagickBooleanType
               proceed;

-            proceed=SetImageProgress(image,RotateImageTag,
-              progress+=(MagickOffsetType) tile_height,image->rows);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+            #pragma omp atomic
+#endif
+            progress+=(MagickOffsetType) tile_height;
+            proceed=SetImageProgress(image,RotateImageTag,progress,
+              image->rows);
             if (proceed == MagickFalse)
               status=MagickFalse;
           }
@@ -1530,7 +1575,7 @@ static MagickBooleanType YShearImage(Image *image,const double degrees,
         #pragma omp atomic
 #endif
         progress++;
-        proceed=SetImageProgress(image,YShearImageTag,progress,image->rows);
+        proceed=SetImageProgress(image,YShearImageTag,progress,width);
         if (proceed == MagickFalse)
           status=MagickFalse;
       }
@@ -1686,7 +1731,7 @@ MagickExport Image *ShearImage(const Image *image,const double x_shear,
 %  ShearRotateImage() creates a new image that is a rotated copy of an existing
 %  one.  Positive angles rotate counter-clockwise (right-hand rule), while
 %  negative angles rotate clockwise.  Rotated images are usually larger than
-%  the originals and have 'empty' triangular corners.  X axis.  Empty
+%  the originals and have 'empty' triangular corners.  Empty
 %  triangles left over from shearing the image are filled with the background
 %  color defined by member 'background_color' of the image.  ShearRotateImage
 %  allocates the memory necessary for the new Image structure and returns a