Commit 04fd26111 for imagemagick.org

commit 04fd26111c0ccb1afd60ab08d6037c4776080b45
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Mon Sep 7 18:18:29 2026 -0400

    threads heuristic now based on pixel rather than row count

diff --git a/MagickCore/thread-private.h b/MagickCore/thread-private.h
index 4bdf0405b..f64ebf7c4 100644
--- a/MagickCore/thread-private.h
+++ b/MagickCore/thread-private.h
@@ -49,7 +49,7 @@ extern "C" {

 static inline int GetMagickNumberThreads(const Image *source,
   const Image *destination,const size_t chunk,const double factor)
-{
+{
   const CacheType
     destination_type = (CacheType) GetImagePixelCacheType(destination),
     source_type = (CacheType) GetImagePixelCacheType(source);
@@ -57,20 +57,18 @@ static inline int GetMagickNumberThreads(const Image *source,
   size_t
     max_threads = (size_t) GetMagickResourceLimit(ThreadResource),
     number_threads = 1UL,
-    rows_per_thread = CastDoubleToSizeT(64.0*factor);  /* workload */
-
-  /*
-    Determine number of threads based on rows per thread heuristic.
-  */
-  if (rows_per_thread != 0)
-    number_threads=(chunk < rows_per_thread) ? 1UL : MagickMin(max_threads,
-      (chunk+rows_per_thread-1)/rows_per_thread);
-  /*
-    Limit threads for non-memory or non-map cache sources/destinations.
-  */
+    pixels_per_thread = CastDoubleToSizeT(262144.0*factor);
+
+  if (pixels_per_thread != 0)
+    {
+      const size_t total_pixels = chunk*source->columns;
+      number_threads=(total_pixels < pixels_per_thread) ? 1UL :
+        MagickMin(max_threads,(total_pixels+pixels_per_thread-1)/
+        pixels_per_thread);
+    }
   if (((source_type != MemoryCache) && (source_type != MapCache)) ||
       ((destination_type != MemoryCache) && (destination_type != MapCache)))
-    number_threads=MagickMin(number_threads,4);
+    number_threads=MagickMin(number_threads,4UL);
   return((int) number_threads);
 }