]> granicus.if.org Git - imagemagick/commitdiff
Performance optimzation when computing the number of unique image colors
authorCristy <urban-warrior@imagemagick.org>
Mon, 18 Sep 2017 23:12:27 +0000 (19:12 -0400)
committerCristy <urban-warrior@imagemagick.org>
Mon, 18 Sep 2017 23:12:27 +0000 (19:12 -0400)
MagickCore/histogram.c

index 03dc54ea18f42ad60ee2b24bbdf0e0883f1cc231..5b9d9f877a11f1a43781ca4da5f031b43b938115 100644 (file)
@@ -79,6 +79,7 @@ typedef struct _NodeInfo
     *list;
 
   MagickSizeType
+    extent,
     number_unique;
 
   size_t
@@ -261,11 +262,18 @@ static CubeInfo *ClassifyImageColors(const Image *image,
       else
         {
           if (node_info->number_unique == 0)
-            node_info->list=(PixelInfo *) AcquireMagickMemory(
-              sizeof(*node_info->list));
+            {
+              node_info->extent=1;
+              node_info->list=(PixelInfo *) AcquireQuantumMemory(
+                node_info->extent,sizeof(*node_info->list));
+            }
           else
-            node_info->list=(PixelInfo *) ResizeQuantumMemory(node_info->list,
-              (size_t) (i+1),sizeof(*node_info->list));
+            if (i >= node_info->extent)
+              {
+                node_info->extent<<=1;
+                node_info->list=(PixelInfo *) ResizeQuantumMemory(
+                  node_info->list,node_info->extent,sizeof(*node_info->list));
+              }
           if (node_info->list == (PixelInfo *) NULL)
             {
               (void) ThrowMagickException(exception,GetMagickModule(),