% August 2009 %
% %
% %
-% Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
%
% ClassifyImageColors() builds a populated CubeInfo tree for the specified
% image. The returned tree should be deallocated using DestroyCubeInfo()
-% once it is no ssize_ter needed.
+% once it is no longer needed.
%
% The format of the ClassifyImageColors() method is:
%
CubeInfo
*cube_info;
- ssize_t
- y;
-
MagickBooleanType
proceed;
register const PixelPacket
*p;
- register ssize_t
- i,
- x;
-
register size_t
id,
index,
level;
+ register ssize_t
+ i,
+ x;
+
+ ssize_t
+ y;
+
/*
Initialize color description tree.
*/
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
- node_info->list[i].index=indexes[x];
+ node_info->list[i].index=GetIndexPixelComponent(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
/*
Initialize tree to describe color cube.
*/
- cube_info=(CubeInfo *) AcquireAlignedMemory(1,sizeof(*cube_info));
+ cube_info=(CubeInfo *) AcquireMagickMemory(sizeof(*cube_info));
if (cube_info == (CubeInfo *) NULL)
return((CubeInfo *) NULL);
(void) ResetMagickMemory(cube_info,0,sizeof(*cube_info));
/*
Allocate a new nodes of nodes.
*/
- nodes=(Nodes *) AcquireAlignedMemory(1,sizeof(*nodes));
+ nodes=(Nodes *) AcquireMagickMemory(sizeof(*nodes));
if (nodes == (Nodes *) NULL)
return((NodeInfo *) NULL);
nodes->next=cube_info->node_queue;
CubeInfo
*cube_info;
- ssize_t
- y;
-
MagickPixelPacket
pixel,
target;
index,
level;
+ ssize_t
+ y;
+
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
- node_info->list[i].index=indexes[x];
+ node_info->list[i].index=GetIndexPixelComponent(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
CubeInfo
*cube_info;
- ssize_t
- y;
-
MagickPixelPacket
pixel,
target;
index,
level;
+ ssize_t
+ y;
+
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
- node_info->list[i].index=indexes[x];
+ node_info->list[i].index=GetIndexPixelComponent(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
% stretch the colors (and histogram) of the image. The stretch points are
% also moved further inward by the adjustment values given.
%
-% If the adjustment values are both zero this function is equivelent to a
+% If the adjustment values are both zero this function is equivalent to a
% perfect normalization (or autolevel) of the image.
%
% Each channel is stretched independantally of each other (producing color
HistogramCompare);
GetMagickPixelPacket(image,&pixel);
p=histogram;
+ status=MagickTrue;
for (i=0; i < (ssize_t) number_colors; i++)
{
SetMagickPixelPacket(image,&p->pixel,&p->index,&pixel);
}
(void) fflush(file);
histogram=(ColorPacket *) RelinquishMagickMemory(histogram);
+ if (status == MagickFalse)
+ return(0);
return(number_colors);
}
\f
%
*/
-static void UniqueColorsToImage(Image *image,CubeInfo *cube_info,
- const NodeInfo *node_info,ExceptionInfo *exception)
+static void UniqueColorsToImage(Image *unique_image,CacheView *unique_view,
+ CubeInfo *cube_info,const NodeInfo *node_info,ExceptionInfo *exception)
{
#define UniqueColorsImageTag "UniqueColors/Image"
/*
Traverse any children.
*/
- number_children=image->matte == MagickFalse ? 8UL : 16UL;
+ number_children=unique_image->matte == MagickFalse ? 8UL : 16UL;
for (i=0; i < (ssize_t) number_children; i++)
if (node_info->child[i] != (NodeInfo *) NULL)
- UniqueColorsToImage(image,cube_info,node_info->child[i],exception);
+ UniqueColorsToImage(unique_image,unique_view,cube_info,
+ node_info->child[i],exception);
if (node_info->level == (MaxTreeDepth-1))
{
register ColorPacket
register PixelPacket
*restrict q;
+ status=MagickTrue;
p=node_info->list;
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
- q=QueueAuthenticPixels(image,cube_info->x,0,1,1,exception);
+ q=QueueCacheViewAuthenticPixels(unique_view,cube_info->x,0,1,1,
+ exception);
if (q == (PixelPacket *) NULL)
continue;
- indexes=GetAuthenticIndexQueue(image);
+ indexes=GetCacheViewAuthenticIndexQueue(unique_view);
*q=p->pixel;
- if (image->colorspace == CMYKColorspace)
+ if (unique_image->colorspace == CMYKColorspace)
*indexes=p->index;
- if (SyncAuthenticPixels(image,exception) == MagickFalse)
+ if (SyncCacheViewAuthenticPixels(unique_view,exception) == MagickFalse)
break;
cube_info->x++;
p++;
}
- if (image->progress_monitor != (MagickProgressMonitor) NULL)
+ if (unique_image->progress_monitor != (MagickProgressMonitor) NULL)
{
MagickBooleanType
proceed;
- proceed=SetImageProgress(image,UniqueColorsImageTag,
+ proceed=SetImageProgress(unique_image,UniqueColorsImageTag,
cube_info->progress,cube_info->colors);
if (proceed == MagickFalse)
status=MagickFalse;
}
cube_info->progress++;
+ if (status == MagickFalse)
+ return;
}
}
MagickExport Image *UniqueImageColors(const Image *image,
ExceptionInfo *exception)
{
+ CacheView
+ *unique_view;
+
CubeInfo
*cube_info;
unique_image=DestroyImage(unique_image);
return((Image *) NULL);
}
- UniqueColorsToImage(unique_image,cube_info,cube_info->root,exception);
+ unique_view=AcquireCacheView(unique_image);
+ UniqueColorsToImage(unique_image,unique_view,cube_info,cube_info->root,
+ exception);
+ unique_view=DestroyCacheView(unique_view);
if (cube_info->colors < MaxColormapSize)
{
QuantizeInfo