% MagickCore Methods to Reduce the Number of Unique Colors in an Image %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% July 1992 %
% %
% %
%
% The algorithm maps this domain onto a tree in which each node
% represents a cube within that domain. In the following discussion
-% these cubes are defined by the coordinate of two opposite vertices:
-% The vertex nearest the origin in RGB space and the vertex farthest from
-% the origin.
+% these cubes are defined by the coordinate of two opposite vertices (vertex
+% nearest the origin in RGB space and the vertex farthest from the origin).
%
% The tree's root node represents the entire domain, (0,0,0) through
% (Cmax,Cmax,Cmax). Each lower level in the tree is generated by
associate_alpha=image->alpha_trait == BlendPixelTrait ? MagickTrue :
MagickFalse;
- if (cube_info->quantize_info->colorspace == TransparentColorspace)
- associate_alpha=MagickFalse;
if ((cube_info->quantize_info->number_colors == 2) &&
(cube_info->quantize_info->colorspace == GRAYColorspace))
associate_alpha=MagickFalse;
*/
node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info);
if (node_info->child[id] == (NodeInfo *) NULL)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- image->filename);
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","`%s'",
+ image->filename);
+ continue;
+ }
if (level == MaxTreeDepth)
cube_info->colors++;
}
*/
node_info->child[id]=GetNodeInfo(cube_info,id,level,node_info);
if (node_info->child[id] == (NodeInfo *) NULL)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","%s",
- image->filename);
+ {
+ (void) ThrowMagickException(exception,GetMagickModule(),
+ ResourceLimitError,"MemoryAllocationFailed","%s",
+ image->filename);
+ continue;
+ }
if (level == cube_info->depth)
cube_info->colors++;
}
if ((cube_info->quantize_info->colorspace != UndefinedColorspace) &&
(cube_info->quantize_info->colorspace != CMYKColorspace))
(void) TransformImageColorspace((Image *) image,sRGBColorspace,exception);
- return(MagickTrue);
+ return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue);
}
\f
/*
MagickBooleanType
proceed;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_FloydSteinbergDither)
-#endif
proceed=SetImageProgress(image,DitherImageTag,(MagickOffsetType) y,
image->rows);
if (proceed == MagickFalse)
depth--;
if ((image->alpha_trait == BlendPixelTrait) && (depth > 5))
depth--;
+ if (IsImageGray(image,exception) != MagickFalse)
+ depth=MaxTreeDepth;
}
/*
Initialize color cube.
span;
cube_info->next_threshold=0.0;
- if ((cube_info->colors > cube_info->maximum_colors) && (cube_info->depth > 3))
+ if ((cube_info->colors > cube_info->maximum_colors) &&
+ (cube_info->nodes > 128))
{
MagickRealType
*quantize_error;
qsort(quantize_error,cube_info->nodes,sizeof(MagickRealType),
MagickRealTypeCompare);
cube_info->next_threshold=quantize_error[MagickMax(cube_info->nodes-
- cube_info->maximum_colors,0)];
+ 110*(cube_info->maximum_colors+1)/100,0)];
quantize_error=(MagickRealType *) RelinquishMagickMemory(
quantize_error);
}