Commit ec19dcdb9 for imagemagick.org

commit ec19dcdb901535fe6d992af592acc6bf9378c103
Author: Cristy <urban-warrior@imagemagick.org>
Date:   Sat Jul 18 15:21:54 2026 -0400

    avoid division by 0

diff --git a/MagickCore/thread-private.h b/MagickCore/thread-private.h
index 91052b96a..420881d6d 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 int factor)
-{
+{
   const CacheType
     destination_type = (CacheType) GetImagePixelCacheType(destination),
     source_type = (CacheType) GetImagePixelCacheType(source);
@@ -57,14 +57,13 @@ static inline int GetMagickNumberThreads(const Image *source,
   size_t
     max_threads = (size_t) GetMagickResourceLimit(ThreadResource),
     number_threads = 1UL,
-    workload_factor = 32UL << factor;
+    rows_per_thread = 64UL*MagickMax(factor,1); /* target workload per thread */

   /*
-    Determine number of threads based on workload.
+    Determine number of threads based on rows per thread heuristic.
   */
-  number_threads=(chunk <= workload_factor) ? 1UL :
-    (chunk >= (workload_factor << 6)) ? max_threads :
-    1UL+(chunk-workload_factor)*(max_threads-1L)/(((workload_factor << 6))-1L);
+  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.
   */