]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/quantize.c
(no commit message)
[imagemagick] / MagickCore / quantize.c
index 8691fed97f4f5f1dea30807bc6a04a1a54d20d8d..5cba535ff0c1ff23695d8259fa6d63e9e6d35ec3 100644 (file)
@@ -2767,6 +2767,8 @@ MagickExport MagickBooleanType QuantizeImage(const QuantizeInfo *quantize_info,
         depth--;
       if ((image->alpha_trait == BlendPixelTrait) && (depth > 5))
         depth--;
+      if (IsImageGray(image,exception) != MagickFalse)
+        depth=MaxTreeDepth;
     }
   /*
     Initialize color cube.
@@ -3128,7 +3130,8 @@ static void ReduceImageColors(const Image *image,CubeInfo *cube_info)
     span;
 
   cube_info->next_threshold=0.0;
-  if (cube_info->colors > cube_info->maximum_colors)
+  if ((cube_info->colors > cube_info->maximum_colors) && 
+      (cube_info->nodes > 128))
     {
       MagickRealType
         *quantize_error;
@@ -3145,7 +3148,7 @@ static void ReduceImageColors(const Image *image,CubeInfo *cube_info)
           qsort(quantize_error,cube_info->nodes,sizeof(MagickRealType),
             MagickRealTypeCompare);
           cube_info->next_threshold=quantize_error[MagickMax(cube_info->nodes-
-            110*cube_info->maximum_colors/100,0)];
+            110*(cube_info->maximum_colors+1)/100,0)];
           quantize_error=(MagickRealType *) RelinquishMagickMemory(
             quantize_error);
         }