This source file includes following definitions.
- ColorToNodeId
- ClassifyImageColors
- DefineImageHistogram
- DestroyCubeInfo
- DestroyColorCube
- GetCubeInfo
- GetImageHistogram
- GetNodeInfo
- CheckImageColors
- IdentifyPaletteImage
- IsHistogramImage
- IsPaletteImage
- MinMaxStretchImage
- HistogramCompare
- GetNumberColors
- UniqueColorsToImage
- UniqueImageColors
#include "magick/studio.h"
#include "magick/cache-view.h"
#include "magick/color-private.h"
#include "magick/enhance.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/hashmap.h"
#include "magick/histogram.h"
#include "magick/image.h"
#include "magick/list.h"
#include "magick/memory_.h"
#include "magick/monitor-private.h"
#include "magick/pixel-private.h"
#include "magick/prepress.h"
#include "magick/quantize.h"
#include "magick/registry.h"
#include "magick/semaphore.h"
#include "magick/splay-tree.h"
#include "magick/statistic.h"
#include "magick/string_.h"
#define MaxTreeDepth 8
#define NodesInAList 1536
typedef struct _NodeInfo
{
struct _NodeInfo
*child[16];
ColorPacket
*list;
MagickSizeType
number_unique;
size_t
level;
} NodeInfo;
typedef struct _Nodes
{
NodeInfo
nodes[NodesInAList];
struct _Nodes
*next;
} Nodes;
typedef struct _CubeInfo
{
NodeInfo
*root;
ssize_t
x;
MagickOffsetType
progress;
size_t
colors,
free_nodes;
NodeInfo
*node_info;
Nodes
*node_queue;
} CubeInfo;
static CubeInfo
*GetCubeInfo(void);
static NodeInfo
*GetNodeInfo(CubeInfo *,const size_t);
static void
DestroyColorCube(const Image *,NodeInfo *);
static inline size_t ColorToNodeId(const Image *image,
const MagickPixelPacket *pixel,size_t index)
{
size_t
id;
id=(size_t) (
((ScaleQuantumToChar(ClampToQuantum(pixel->red)) >> index) & 0x01) |
((ScaleQuantumToChar(ClampToQuantum(pixel->green)) >> index) & 0x01) << 1 |
((ScaleQuantumToChar(ClampToQuantum(pixel->blue)) >> index) & 0x01) << 2);
if (image->matte != MagickFalse)
id|=((ScaleQuantumToChar(ClampToQuantum(pixel->opacity)) >> index) &
0x01) << 3;
return(id);
}
static CubeInfo *ClassifyImageColors(const Image *image,
ExceptionInfo *exception)
{
#define EvaluateImageTag " Compute image colors... "
CacheView
*image_view;
CubeInfo
*cube_info;
MagickBooleanType
proceed;
MagickPixelPacket
pixel,
target;
NodeInfo
*node_info;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register size_t
id,
index,
level;
register ssize_t
i,
x;
ssize_t
y;
assert(image != (const Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
cube_info=GetCubeInfo();
if (cube_info == (CubeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(cube_info);
}
GetMagickPixelPacket(image,&pixel);
GetMagickPixelPacket(image,&target);
image_view=AcquireVirtualCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
node_info=cube_info->root;
index=MaxTreeDepth-1;
for (level=1; level < MaxTreeDepth; level++)
{
SetMagickPixelPacket(image,p,indexes+x,&pixel);
id=ColorToNodeId(image,&pixel,index);
if (node_info->child[id] == (NodeInfo *) NULL)
{
node_info->child[id]=GetNodeInfo(cube_info,level);
if (node_info->child[id] == (NodeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
return(0);
}
}
node_info=node_info->child[id];
index--;
}
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
SetMagickPixelPacket(image,&node_info->list[i].pixel,
&node_info->list[i].index,&target);
if (IsMagickColorEqual(&pixel,&target) != MagickFalse)
break;
}
if (i < (ssize_t) node_info->number_unique)
node_info->list[i].count++;
else
{
if (node_info->number_unique == 0)
node_info->list=(ColorPacket *) AcquireMagickMemory(
sizeof(*node_info->list));
else
node_info->list=(ColorPacket *) ResizeQuantumMemory(node_info->list,
(size_t) (i+1),sizeof(*node_info->list));
if (node_info->list == (ColorPacket *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
return(0);
}
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
node_info->list[i].index=GetPixelIndex(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
}
p++;
}
proceed=SetImageProgress(image,EvaluateImageTag,(MagickOffsetType) y,
image->rows);
if (proceed == MagickFalse)
break;
}
image_view=DestroyCacheView(image_view);
return(cube_info);
}
static void DefineImageHistogram(const Image *image,NodeInfo *node_info,
ColorPacket **histogram)
{
register ssize_t
i;
size_t
number_children;
number_children=image->matte == MagickFalse ? 8UL : 16UL;
for (i=0; i < (ssize_t) number_children; i++)
if (node_info->child[i] != (NodeInfo *) NULL)
DefineImageHistogram(image,node_info->child[i],histogram);
if (node_info->level == (MaxTreeDepth-1))
{
register ColorPacket
*p;
p=node_info->list;
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
(*histogram)->pixel=p->pixel;
(*histogram)->index=p->index;
(*histogram)->count=p->count;
(*histogram)++;
p++;
}
}
}
static CubeInfo *DestroyCubeInfo(const Image *image,CubeInfo *cube_info)
{
register Nodes
*nodes;
DestroyColorCube(image,cube_info->root);
do
{
nodes=cube_info->node_queue->next;
cube_info->node_queue=(Nodes *)
RelinquishMagickMemory(cube_info->node_queue);
cube_info->node_queue=nodes;
} while (cube_info->node_queue != (Nodes *) NULL);
return((CubeInfo *) RelinquishMagickMemory(cube_info));
}
static void DestroyColorCube(const Image *image,NodeInfo *node_info)
{
register ssize_t
i;
size_t
number_children;
number_children=image->matte == MagickFalse ? 8UL : 16UL;
for (i=0; i < (ssize_t) number_children; i++)
if (node_info->child[i] != (NodeInfo *) NULL)
DestroyColorCube(image,node_info->child[i]);
if (node_info->list != (ColorPacket *) NULL)
node_info->list=(ColorPacket *) RelinquishMagickMemory(node_info->list);
}
static CubeInfo *GetCubeInfo(void)
{
CubeInfo
*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));
cube_info->root=GetNodeInfo(cube_info,0);
if (cube_info->root == (NodeInfo *) NULL)
return((CubeInfo *) NULL);
return(cube_info);
}
MagickExport ColorPacket *GetImageHistogram(const Image *image,
size_t *number_colors,ExceptionInfo *exception)
{
ColorPacket
*histogram;
CubeInfo
*cube_info;
*number_colors=0;
histogram=(ColorPacket *) NULL;
cube_info=ClassifyImageColors(image,exception);
if (cube_info != (CubeInfo *) NULL)
{
histogram=(ColorPacket *) AcquireQuantumMemory((size_t) cube_info->colors,
sizeof(*histogram));
if (histogram == (ColorPacket *) NULL)
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
else
{
ColorPacket
*root;
*number_colors=cube_info->colors;
root=histogram;
DefineImageHistogram(image,cube_info->root,&root);
}
}
cube_info=DestroyCubeInfo(image,cube_info);
return(histogram);
}
static NodeInfo *GetNodeInfo(CubeInfo *cube_info,const size_t level)
{
NodeInfo
*node_info;
if (cube_info->free_nodes == 0)
{
Nodes
*nodes;
nodes=(Nodes *) AcquireMagickMemory(sizeof(*nodes));
if (nodes == (Nodes *) NULL)
return((NodeInfo *) NULL);
nodes->next=cube_info->node_queue;
cube_info->node_queue=nodes;
cube_info->node_info=nodes->nodes;
cube_info->free_nodes=NodesInAList;
}
cube_info->free_nodes--;
node_info=cube_info->node_info++;
(void) ResetMagickMemory(node_info,0,sizeof(*node_info));
node_info->level=level;
return(node_info);
}
static MagickBooleanType CheckImageColors(const Image *image,
ExceptionInfo *exception,size_t max_colors)
{
CacheView
*image_view;
CubeInfo
*cube_info;
MagickPixelPacket
pixel,
target;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
x;
register NodeInfo
*node_info;
register ssize_t
i;
size_t
id,
index,
level;
ssize_t
y;
if (image->storage_class == PseudoClass)
return((image->colors <= max_colors) ? MagickTrue : MagickFalse);
cube_info=GetCubeInfo();
if (cube_info == (CubeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(MagickFalse);
}
GetMagickPixelPacket(image,&pixel);
GetMagickPixelPacket(image,&target);
image_view=AcquireVirtualCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
node_info=cube_info->root;
index=MaxTreeDepth-1;
for (level=1; level < MaxTreeDepth; level++)
{
SetMagickPixelPacket(image,p,indexes+x,&pixel);
id=ColorToNodeId(image,&pixel,index);
if (node_info->child[id] == (NodeInfo *) NULL)
{
node_info->child[id]=GetNodeInfo(cube_info,level);
if (node_info->child[id] == (NodeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
break;
}
}
node_info=node_info->child[id];
index--;
}
if (level < MaxTreeDepth)
break;
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
SetMagickPixelPacket(image,&node_info->list[i].pixel,
&node_info->list[i].index,&target);
if (IsMagickColorEqual(&pixel,&target) != MagickFalse)
break;
}
if (i < (ssize_t) node_info->number_unique)
node_info->list[i].count++;
else
{
if (node_info->number_unique == 0)
node_info->list=(ColorPacket *) AcquireMagickMemory(
sizeof(*node_info->list));
else
node_info->list=(ColorPacket *) ResizeQuantumMemory(node_info->list,
(size_t) (i+1),sizeof(*node_info->list));
if (node_info->list == (ColorPacket *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
break;
}
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
node_info->list[i].index=GetPixelIndex(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
if (cube_info->colors > max_colors)
break;
}
p++;
}
if (x < (ssize_t) image->columns)
break;
}
image_view=DestroyCacheView(image_view);
cube_info=DestroyCubeInfo(image,cube_info);
return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue);
}
MagickExport MagickBooleanType IdentifyPaletteImage(const Image *image,
ExceptionInfo *exception)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
return(CheckImageColors(image,exception,256));
}
MagickExport MagickBooleanType IsHistogramImage(const Image *image,
ExceptionInfo *exception)
{
#define MaximumUniqueColors 1024
CacheView
*image_view;
CubeInfo
*cube_info;
MagickPixelPacket
pixel,
target;
register const IndexPacket
*indexes;
register const PixelPacket
*p;
register ssize_t
x;
register NodeInfo
*node_info;
register ssize_t
i;
size_t
id,
index,
level;
ssize_t
y;
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if ((image->storage_class == PseudoClass) &&
(image->colors <= MaximumUniqueColors))
return(MagickTrue);
if (image->storage_class == PseudoClass)
return(MagickFalse);
cube_info=GetCubeInfo();
if (cube_info == (CubeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename);
return(MagickFalse);
}
GetMagickPixelPacket(image,&pixel);
GetMagickPixelPacket(image,&target);
image_view=AcquireVirtualCacheView(image,exception);
for (y=0; y < (ssize_t) image->rows; y++)
{
p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
if (p == (const PixelPacket *) NULL)
break;
indexes=GetCacheViewVirtualIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
node_info=cube_info->root;
index=MaxTreeDepth-1;
for (level=1; level < MaxTreeDepth; level++)
{
SetMagickPixelPacket(image,p,indexes+x,&pixel);
id=ColorToNodeId(image,&pixel,index);
if (node_info->child[id] == (NodeInfo *) NULL)
{
node_info->child[id]=GetNodeInfo(cube_info,level);
if (node_info->child[id] == (NodeInfo *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
break;
}
}
node_info=node_info->child[id];
index--;
}
if (level < MaxTreeDepth)
break;
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
SetMagickPixelPacket(image,&node_info->list[i].pixel,
&node_info->list[i].index,&target);
if (IsMagickColorEqual(&pixel,&target) != MagickFalse)
break;
}
if (i < (ssize_t) node_info->number_unique)
node_info->list[i].count++;
else
{
if (node_info->number_unique == 0)
node_info->list=(ColorPacket *) AcquireMagickMemory(
sizeof(*node_info->list));
else
node_info->list=(ColorPacket *) ResizeQuantumMemory(node_info->list,
(size_t) (i+1),sizeof(*node_info->list));
if (node_info->list == (ColorPacket *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),
ResourceLimitError,"MemoryAllocationFailed","`%s'",
image->filename);
break;
}
node_info->list[i].pixel=(*p);
if ((image->colorspace == CMYKColorspace) ||
(image->storage_class == PseudoClass))
node_info->list[i].index=GetPixelIndex(indexes+x);
node_info->list[i].count=1;
node_info->number_unique++;
cube_info->colors++;
if (cube_info->colors > MaximumUniqueColors)
break;
}
p++;
}
if (x < (ssize_t) image->columns)
break;
}
image_view=DestroyCacheView(image_view);
cube_info=DestroyCubeInfo(image,cube_info);
return(y < (ssize_t) image->rows ? MagickFalse : MagickTrue);
}
MagickExport MagickBooleanType IsPaletteImage(const Image *image,
ExceptionInfo *exception)
{
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class != PseudoClass)
return(MagickFalse);
return((image->colors <= 256) ? MagickTrue : MagickFalse);
}
MagickExport MagickBooleanType MinMaxStretchImage(Image *image,
const ChannelType channel,const double black_value,const double white_value)
{
double
min,
max;
MagickStatusType
status;
status=MagickTrue;
if ((channel & SyncChannels) != 0)
{
(void) GetImageChannelRange(image,channel,&min,&max,&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,channel,min,max,1.0);
return(status != 0 ? MagickTrue : MagickFalse);
}
if ((channel & RedChannel) != 0)
{
(void) GetImageChannelRange(image,RedChannel,&min,&max,&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,RedChannel,min,max,1.0);
}
if ((channel & GreenChannel) != 0)
{
(void) GetImageChannelRange(image,GreenChannel,&min,&max,
&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,GreenChannel,min,max,1.0);
}
if ((channel & BlueChannel) != 0)
{
(void) GetImageChannelRange(image,BlueChannel,&min,&max,
&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,BlueChannel,min,max,1.0);
}
if (((channel & OpacityChannel) != 0) &&
(image->matte != MagickFalse))
{
(void) GetImageChannelRange(image,OpacityChannel,&min,&max,
&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,OpacityChannel,min,max,1.0);
}
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
{
(void) GetImageChannelRange(image,IndexChannel,&min,&max,
&image->exception);
min+=black_value;
max-=white_value;
if (fabs(min-max) >= MagickEpsilon)
status&=LevelImageChannel(image,IndexChannel,min,max,1.0);
}
return(status != 0 ? MagickTrue : MagickFalse);
}
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
static int HistogramCompare(const void *x,const void *y)
{
const ColorPacket
*color_1,
*color_2;
color_1=(const ColorPacket *) x;
color_2=(const ColorPacket *) y;
if (color_2->pixel.red != color_1->pixel.red)
return((int) color_1->pixel.red-(int) color_2->pixel.red);
if (color_2->pixel.green != color_1->pixel.green)
return((int) color_1->pixel.green-(int) color_2->pixel.green);
if (color_2->pixel.blue != color_1->pixel.blue)
return((int) color_1->pixel.blue-(int) color_2->pixel.blue);
return((int) color_2->count-(int) color_1->count);
}
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
MagickExport size_t GetNumberColors(const Image *image,FILE *file,
ExceptionInfo *exception)
{
#define HistogramImageTag "Histogram/Image"
char
color[MaxTextExtent],
hex[MaxTextExtent],
tuple[MaxTextExtent];
ColorPacket
*histogram;
MagickBooleanType
status;
MagickPixelPacket
pixel;
register ColorPacket
*p;
register ssize_t
i;
size_t
number_colors;
number_colors=0;
if (file == (FILE *) NULL)
{
CubeInfo
*cube_info;
cube_info=ClassifyImageColors(image,exception);
if (cube_info != (CubeInfo *) NULL)
number_colors=cube_info->colors;
cube_info=DestroyCubeInfo(image,cube_info);
return(number_colors);
}
histogram=GetImageHistogram(image,&number_colors,exception);
if (histogram == (ColorPacket *) NULL)
return(number_colors);
qsort((void *) histogram,(size_t) number_colors,sizeof(*histogram),
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) CopyMagickString(tuple,"(",MaxTextExtent);
ConcatenateColorComponent(&pixel,RedChannel,X11Compliance,tuple);
(void) ConcatenateMagickString(tuple,",",MaxTextExtent);
ConcatenateColorComponent(&pixel,GreenChannel,X11Compliance,tuple);
(void) ConcatenateMagickString(tuple,",",MaxTextExtent);
ConcatenateColorComponent(&pixel,BlueChannel,X11Compliance,tuple);
if (pixel.colorspace == CMYKColorspace)
{
(void) ConcatenateMagickString(tuple,",",MaxTextExtent);
ConcatenateColorComponent(&pixel,IndexChannel,X11Compliance,tuple);
}
if (pixel.matte != MagickFalse)
{
(void) ConcatenateMagickString(tuple,",",MaxTextExtent);
ConcatenateColorComponent(&pixel,OpacityChannel,X11Compliance,tuple);
}
(void) ConcatenateMagickString(tuple,")",MaxTextExtent);
(void) QueryMagickColorname(image,&pixel,SVGCompliance,color,exception);
GetColorTuple(&pixel,MagickTrue,hex);
(void) FormatLocaleFile(file,"%10.20g",(double) ((MagickOffsetType)
p->count));
(void) FormatLocaleFile(file,": %s %s %s\n",tuple,hex,color);
if (image->progress_monitor != (MagickProgressMonitor) NULL)
{
MagickBooleanType
proceed;
proceed=SetImageProgress(image,HistogramImageTag,(MagickOffsetType) i,
number_colors);
if (proceed == MagickFalse)
status=MagickFalse;
}
p++;
}
(void) fflush(file);
histogram=(ColorPacket *) RelinquishMagickMemory(histogram);
if (status == MagickFalse)
return(0);
return(number_colors);
}
static void UniqueColorsToImage(Image *unique_image,CacheView *unique_view,
CubeInfo *cube_info,const NodeInfo *node_info,ExceptionInfo *exception)
{
#define UniqueColorsImageTag "UniqueColors/Image"
MagickBooleanType
status;
register ssize_t
i;
size_t
number_children;
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(unique_image,unique_view,cube_info,
node_info->child[i],exception);
if (node_info->level == (MaxTreeDepth-1))
{
register ColorPacket
*p;
register IndexPacket
*magick_restrict indexes;
register PixelPacket
*magick_restrict q;
status=MagickTrue;
p=node_info->list;
for (i=0; i < (ssize_t) node_info->number_unique; i++)
{
q=QueueCacheViewAuthenticPixels(unique_view,cube_info->x,0,1,1,
exception);
if (q == (PixelPacket *) NULL)
continue;
indexes=GetCacheViewAuthenticIndexQueue(unique_view);
*q=p->pixel;
if (unique_image->colorspace == CMYKColorspace)
*indexes=p->index;
if (SyncCacheViewAuthenticPixels(unique_view,exception) == MagickFalse)
break;
cube_info->x++;
p++;
}
if (unique_image->progress_monitor != (MagickProgressMonitor) NULL)
{
MagickBooleanType
proceed;
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;
Image
*unique_image;
cube_info=ClassifyImageColors(image,exception);
if (cube_info == (CubeInfo *) NULL)
return((Image *) NULL);
unique_image=CloneImage(image,cube_info->colors,1,MagickTrue,exception);
if (unique_image == (Image *) NULL)
return(unique_image);
if (SetImageStorageClass(unique_image,DirectClass) == MagickFalse)
{
InheritException(exception,&unique_image->exception);
unique_image=DestroyImage(unique_image);
return((Image *) NULL);
}
unique_view=AcquireVirtualCacheView(unique_image,exception);
UniqueColorsToImage(unique_image,unique_view,cube_info,cube_info->root,
exception);
unique_view=DestroyCacheView(unique_view);
cube_info=DestroyCubeInfo(image,cube_info);
return(unique_image);
}