#include "magick/quantize.h"
#include "magick/quantum.h"
#include "magick/string_.h"
+#include "magick/thread-private.h"
\f
/*
Define declarations.
quantize_info->dither=image_info->dither;
option=GetImageOption(image_info,"dither");
if (option != (const char *) NULL)
- quantize_info->dither_method=(DitherMethod) ParseMagickOption(
+ quantize_info->dither_method=(DitherMethod) ParseCommandOption(
MagickDitherOptions,MagickFalse,option);
quantize_info->measure_error=image_info->verbose;
}
if ((cube_info->associate_alpha == MagickFalse) ||
(pixel->opacity == OpaqueOpacity))
{
- alpha_pixel->red=(MagickRealType) pixel->red;
- alpha_pixel->green=(MagickRealType) pixel->green;
- alpha_pixel->blue=(MagickRealType) pixel->blue;
- alpha_pixel->opacity=(MagickRealType) pixel->opacity;
+ alpha_pixel->red=(MagickRealType) GetRedPixelComponent(pixel);
+ alpha_pixel->green=(MagickRealType) GetGreenPixelComponent(pixel);
+ alpha_pixel->blue=(MagickRealType) GetBluePixelComponent(pixel);
+ alpha_pixel->opacity=(MagickRealType) GetOpacityPixelComponent(pixel);
return;
}
- alpha=(MagickRealType) (QuantumScale*(QuantumRange-pixel->opacity));
- alpha_pixel->red=alpha*pixel->red;
- alpha_pixel->green=alpha*pixel->green;
- alpha_pixel->blue=alpha*pixel->blue;
- alpha_pixel->opacity=(MagickRealType) pixel->opacity;
+ alpha=(MagickRealType) (QuantumScale*(QuantumRange-
+ GetOpacityPixelComponent(pixel)));
+ alpha_pixel->red=alpha*GetRedPixelComponent(pixel);
+ alpha_pixel->green=alpha*GetGreenPixelComponent(pixel);
+ alpha_pixel->blue=alpha*GetBluePixelComponent(pixel);
+ alpha_pixel->opacity=(MagickRealType) GetOpacityPixelComponent(pixel);
}
static inline Quantum ClampToUnsignedQuantum(const MagickRealType value)
size_t
id;
- id=(size_t) (
- ((ScaleQuantumToChar(ClampToUnsignedQuantum(pixel->red)) >> index) & 0x1) |
- ((ScaleQuantumToChar(ClampToUnsignedQuantum(pixel->green)) >> index) & 0x1) << 1 |
- ((ScaleQuantumToChar(ClampToUnsignedQuantum(pixel->blue)) >> index) & 0x1) << 2);
+ id=(size_t) (((ScaleQuantumToChar(ClampToUnsignedQuantum(
+ GetRedPixelComponent(pixel))) >> index) & 0x01) |
+ ((ScaleQuantumToChar(ClampToUnsignedQuantum(
+ GetGreenPixelComponent(pixel))) >> index) & 0x01) << 1 |
+ ((ScaleQuantumToChar(ClampToUnsignedQuantum(
+ GetBluePixelComponent(pixel))) >> index) & 0x01) << 2);
if (cube_info->associate_alpha != MagickFalse)
- id|=((ScaleQuantumToChar(ClampToUnsignedQuantum(pixel->opacity)) >> index) & 0x1)
- << 3;
+ id|=((ScaleQuantumToChar(ClampToUnsignedQuantum(
+ GetOpacityPixelComponent(pixel))) >> index) & 0x1) << 3;
return(id);
}
static inline MagickBooleanType IsSameColor(const Image *image,
const PixelPacket *p,const PixelPacket *q)
{
- if ((p->red != q->red) || (p->green != q->green) || (p->blue != q->blue))
+ if ((GetRedPixelComponent(p) != GetRedPixelComponent(q)) ||
+ (GetGreenPixelComponent(p) != GetGreenPixelComponent(q)) ||
+ (GetBluePixelComponent(p) != GetBluePixelComponent(q)))
return(MagickFalse);
- if ((image->matte != MagickFalse) && (p->opacity != q->opacity))
+ if ((image->matte != MagickFalse) &&
+ (GetOpacityPixelComponent(p) != GetOpacityPixelComponent(q)))
return(MagickFalse);
return(MagickTrue);
}
{
#define AssignImageTag "Assign/Image"
- MagickBooleanType
- proceed;
-
- RealPixelPacket
- pixel;
-
- register const NodeInfo
- *node_info;
-
- register ssize_t
- i,
- x;
-
- size_t
- id,
- index;
-
ssize_t
- count,
y;
/*
(void) DitherImage(image,cube_info);
else
{
+ CacheView
+ *image_view;
+
ExceptionInfo
*exception;
- CacheView
- *image_view;
+ MagickBooleanType
+ status;
+ status=MagickTrue;
exception=(&image->exception);
image_view=AcquireCacheView(image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp parallel for schedule(dynamic,4) shared(status)
+#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
+ CubeInfo
+ cube;
+
register IndexPacket
*restrict indexes;
register PixelPacket
*restrict q;
+ register ssize_t
+ x;
+
+ ssize_t
+ count;
+
+ if (status == MagickFalse)
+ continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,
exception);
if (q == (PixelPacket *) NULL)
- break;
+ {
+ status=MagickFalse;
+ continue;
+ }
indexes=GetCacheViewAuthenticIndexQueue(image_view);
+ cube=(*cube_info);
for (x=0; x < (ssize_t) image->columns; x+=count)
{
+ RealPixelPacket
+ pixel;
+
+ register const NodeInfo
+ *node_info;
+
+ register ssize_t
+ i;
+
+ size_t
+ id,
+ index;
+
/*
Identify the deepest node containing the pixel's color.
*/
for (count=1; (x+count) < (ssize_t) image->columns; count++)
if (IsSameColor(image,q,q+count) == MagickFalse)
break;
- AssociateAlphaPixel(cube_info,q,&pixel);
- node_info=cube_info->root;
+ AssociateAlphaPixel(&cube,q,&pixel);
+ node_info=cube.root;
for (index=MaxTreeDepth-1; (ssize_t) index > 0; index--)
{
- id=ColorToNodeId(cube_info,&pixel,index);
+ id=ColorToNodeId(&cube,&pixel,index);
if (node_info->child[id] == (NodeInfo *) NULL)
break;
node_info=node_info->child[id];
}
- node_info=node_info->parent;
/*
Find closest color among siblings and their children.
*/
- cube_info->target=pixel;
- cube_info->distance=(MagickRealType) (4.0*(QuantumRange+1.0)*
+ cube.target=pixel;
+ cube.distance=(MagickRealType) (4.0*(QuantumRange+1.0)*
(QuantumRange+1.0)+1.0);
- ClosestColor(image,cube_info,node_info->parent);
- index=cube_info->color_number;
+ ClosestColor(image,&cube,node_info->parent);
+ index=cube.color_number;
for (i=0; i < (ssize_t) count; i++)
{
if (image->storage_class == PseudoClass)
- indexes[x+i]=(IndexPacket) index;
- if (cube_info->quantize_info->measure_error == MagickFalse)
+ SetIndexPixelComponent(indexes+x+i,index);
+ if (cube.quantize_info->measure_error == MagickFalse)
{
- q->red=image->colormap[index].red;
- q->green=image->colormap[index].green;
- q->blue=image->colormap[index].blue;
- if (cube_info->associate_alpha != MagickFalse)
- q->opacity=image->colormap[index].opacity;
+ SetRGBPixelComponents(q,image->colormap+index);
+ if (cube.associate_alpha != MagickFalse)
+ SetOpacityPixelComponent(q,image->colormap[index].opacity);
}
q++;
}
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- break;
- proceed=SetImageProgress(image,AssignImageTag,(MagickOffsetType) y,
- image->rows);
- if (proceed == MagickFalse)
- break;
+ status=MagickFalse;
+ if (image->progress_monitor != (MagickProgressMonitor) NULL)
+ {
+ MagickBooleanType
+ proceed;
+
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp critical (MagickCore_AssignImageColors)
+#endif
+ proceed=SetImageProgress(image,AssignImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (proceed == MagickFalse)
+ status=MagickFalse;
+ }
}
image_view=DestroyCacheView(image_view);
}
register PixelPacket
*restrict q;
+ register ssize_t
+ i;
+
/*
Monochrome image.
*/
{
intensity=(Quantum) (PixelIntensity(q) < ((MagickRealType)
QuantumRange/2.0) ? 0 : QuantumRange);
- q->red=intensity;
- q->green=intensity;
- q->blue=intensity;
+ SetRedPixelComponent(q,intensity);
+ SetGreenPixelComponent(q,intensity);
+ SetBluePixelComponent(q,intensity);
q++;
}
}
alpha=(MagickRealType) (QuantumScale*GetAlphaPixelComponent(p));
beta=(MagickRealType) (QuantumScale*GetAlphaPixelComponent(q));
}
- pixel=alpha*p->red-beta*q->red;
+ pixel=alpha*GetRedPixelComponent(p)-beta*GetRedPixelComponent(q);
distance=pixel*pixel;
if (distance <= cube_info->distance)
{
- pixel=alpha*p->green-beta*q->green;
+ pixel=alpha*GetGreenPixelComponent(p)-beta*GetGreenPixelComponent(q);
distance+=pixel*pixel;
if (distance <= cube_info->distance)
{
- pixel=alpha*p->blue-beta*q->blue;
+ pixel=alpha*GetBluePixelComponent(p)-beta*
+ GetBluePixelComponent(q);
distance+=pixel*pixel;
if (distance <= cube_info->distance)
{
alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
if (cube_info->associate_alpha == MagickFalse)
{
- q->red=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.red));
- q->green=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.green));
- q->blue=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.blue));
+ SetRedPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.red)));
+ SetGreenPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.green)));
+ SetBluePixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.blue)));
SetOpacityPixelComponent(q,OpaqueOpacity);
}
else
opacity=(MagickRealType) (alpha*QuantumRange*
node_info->total_color.opacity);
- q->opacity=ClampToQuantum(opacity);
+ SetOpacityPixelComponent(q,ClampToQuantum(opacity));
if (q->opacity == OpaqueOpacity)
{
- q->red=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.red));
- q->green=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.green));
- q->blue=ClampToQuantum((MagickRealType) (alpha*QuantumRange*
- node_info->total_color.blue));
+ SetRedPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.red)));
+ SetGreenPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.green)));
+ SetBluePixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ QuantumRange*node_info->total_color.blue)));
}
else
{
gamma=(MagickRealType) (QuantumScale*(QuantumRange-
(MagickRealType) q->opacity));
gamma=1.0/(fabs(gamma) <= MagickEpsilon ? 1.0 : gamma);
- q->red=ClampToQuantum((MagickRealType) (alpha*gamma*QuantumRange*
- node_info->total_color.red));
- q->green=ClampToQuantum((MagickRealType) (alpha*gamma*
- QuantumRange*node_info->total_color.green));
- q->blue=ClampToQuantum((MagickRealType) (alpha*gamma*QuantumRange*
- node_info->total_color.blue));
+ SetRedPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ gamma*QuantumRange*node_info->total_color.red)));
+ SetGreenPixelComponent(q,ClampToQuantum((MagickRealType) (alpha*
+ gamma*QuantumRange*node_info->total_color.green)));
+ SetBluePixelComponent(q,ClampToQuantum((MagickRealType) (
+ alpha*gamma*QuantumRange*node_info->total_color.blue)));
if (node_info->number_unique > cube_info->transparent_pixels)
{
cube_info->transparent_pixels=node_info->number_unique;
%
*/
+static RealPixelPacket **DestroyPixelThreadSet(RealPixelPacket **pixels)
+{
+ register ssize_t
+ i;
+
+ assert(pixels != (RealPixelPacket **) NULL);
+ for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
+ if (pixels[i] != (RealPixelPacket *) NULL)
+ pixels[i]=(RealPixelPacket *) RelinquishMagickMemory(pixels[i]);
+ pixels=(RealPixelPacket **) RelinquishMagickMemory(pixels);
+ return(pixels);
+}
+
+static RealPixelPacket **AcquirePixelThreadSet(const size_t count)
+{
+ RealPixelPacket
+ **pixels;
+
+ register ssize_t
+ i;
+
+ size_t
+ number_threads;
+
+ number_threads=GetOpenMPMaximumThreads();
+ pixels=(RealPixelPacket **) AcquireQuantumMemory(number_threads,
+ sizeof(*pixels));
+ if (pixels == (RealPixelPacket **) NULL)
+ return((RealPixelPacket **) NULL);
+ (void) ResetMagickMemory(pixels,0,number_threads*sizeof(*pixels));
+ for (i=0; i < (ssize_t) number_threads; i++)
+ {
+ pixels[i]=(RealPixelPacket *) AcquireQuantumMemory(count,
+ 2*sizeof(**pixels));
+ if (pixels[i] == (RealPixelPacket *) NULL)
+ return(DestroyPixelThreadSet(pixels));
+ }
+ return(pixels);
+}
+
static inline ssize_t CacheOffset(CubeInfo *cube_info,
const RealPixelPacket *pixel)
{
*exception;
MagickBooleanType
- proceed;
+ status;
RealPixelPacket
- color,
- *current,
- pixel,
- *previous,
- *scanlines;
-
- register CubeInfo
- *p;
-
- size_t
- index;
+ **pixels;
ssize_t
- u,
- v,
y;
/*
Distribute quantization error using Floyd-Steinberg.
*/
- scanlines=(RealPixelPacket *) AcquireQuantumMemory(image->columns,
- 2*sizeof(*scanlines));
- if (scanlines == (RealPixelPacket *) NULL)
+ pixels=AcquirePixelThreadSet(image->columns);
+ if (pixels == (RealPixelPacket **) NULL)
return(MagickFalse);
- p=cube_info;
exception=(&image->exception);
+ status=MagickTrue;
image_view=AcquireCacheView(image);
for (y=0; y < (ssize_t) image->rows; y++)
{
+ const int
+ id = GetOpenMPThreadId();
+
+ CubeInfo
+ cube;
+
+ RealPixelPacket
+ *current,
+ *previous;
+
register IndexPacket
*restrict indexes;
*restrict q;
register ssize_t
- i,
x;
+ size_t
+ index;
+
+ ssize_t
+ v;
+
+ if (status == MagickFalse)
+ continue;
q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
if (q == (PixelPacket *) NULL)
- return(MagickFalse);
+ {
+ status=MagickFalse;
+ continue;
+ }
indexes=GetCacheViewAuthenticIndexQueue(image_view);
- current=scanlines+(y & 0x01)*image->columns;
- previous=scanlines+((y+1) & 0x01)*image->columns;
+ cube=(*cube_info);
+ current=pixels[id]+(y & 0x01)*image->columns;
+ previous=pixels[id]+((y+1) & 0x01)*image->columns;
v=(ssize_t) ((y & 0x01) ? -1 : 1);
for (x=0; x < (ssize_t) image->columns; x++)
{
+ RealPixelPacket
+ color,
+ pixel;
+
+ register ssize_t
+ i;
+
+ ssize_t
+ u;
+
u=(y & 0x01) ? (ssize_t) image->columns-1-x : x;
- AssociateAlphaPixel(cube_info,q+u,&pixel);
+ AssociateAlphaPixel(&cube,q+u,&pixel);
if (x > 0)
{
pixel.red+=7*current[u-v].red/16;
pixel.green+=7*current[u-v].green/16;
pixel.blue+=7*current[u-v].blue/16;
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
pixel.opacity+=7*current[u-v].opacity/16;
}
if (y > 0)
pixel.red+=previous[u+v].red/16;
pixel.green+=previous[u+v].green/16;
pixel.blue+=previous[u+v].blue/16;
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
pixel.opacity+=previous[u+v].opacity/16;
}
pixel.red+=5*previous[u].red/16;
pixel.green+=5*previous[u].green/16;
pixel.blue+=5*previous[u].blue/16;
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
pixel.opacity+=5*previous[u].opacity/16;
if (x > 0)
{
pixel.red+=3*previous[u-v].red/16;
pixel.green+=3*previous[u-v].green/16;
pixel.blue+=3*previous[u-v].blue/16;
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
pixel.opacity+=3*previous[u-v].opacity/16;
}
}
pixel.red=(MagickRealType) ClampToUnsignedQuantum(pixel.red);
pixel.green=(MagickRealType) ClampToUnsignedQuantum(pixel.green);
pixel.blue=(MagickRealType) ClampToUnsignedQuantum(pixel.blue);
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
pixel.opacity=(MagickRealType) ClampToUnsignedQuantum(pixel.opacity);
- i=CacheOffset(cube_info,&pixel);
- if (p->cache[i] < 0)
+ i=CacheOffset(&cube,&pixel);
+ if (cube.cache[i] < 0)
{
register NodeInfo
*node_info;
/*
Identify the deepest node containing the pixel's color.
*/
- node_info=p->root;
+ node_info=cube.root;
for (index=MaxTreeDepth-1; (ssize_t) index > 0; index--)
{
- id=ColorToNodeId(cube_info,&pixel,index);
+ id=ColorToNodeId(&cube,&pixel,index);
if (node_info->child[id] == (NodeInfo *) NULL)
break;
node_info=node_info->child[id];
}
- node_info=node_info->parent;
/*
Find closest color among siblings and their children.
*/
- p->target=pixel;
- p->distance=(MagickRealType) (4.0*(QuantumRange+1.0)*(QuantumRange+
+ cube.target=pixel;
+ cube.distance=(MagickRealType) (4.0*(QuantumRange+1.0)*(QuantumRange+
1.0)+1.0);
- ClosestColor(image,p,node_info->parent);
- p->cache[i]=(ssize_t) p->color_number;
+ ClosestColor(image,&cube,node_info->parent);
+ cube.cache[i]=(ssize_t) cube.color_number;
}
/*
Assign pixel to closest colormap entry.
*/
- index=(size_t) p->cache[i];
+ index=(size_t) cube.cache[i];
if (image->storage_class == PseudoClass)
- indexes[u]=(IndexPacket) index;
- if (cube_info->quantize_info->measure_error == MagickFalse)
+ SetIndexPixelComponent(indexes+u,index);
+ if (cube.quantize_info->measure_error == MagickFalse)
{
- (q+u)->red=image->colormap[index].red;
- (q+u)->green=image->colormap[index].green;
- (q+u)->blue=image->colormap[index].blue;
- if (cube_info->associate_alpha != MagickFalse)
- (q+u)->opacity=image->colormap[index].opacity;
+ SetRGBPixelComponents(q,image->colormap+index);
+ if (cube.associate_alpha != MagickFalse)
+ SetOpacityPixelComponent(q+u,image->colormap[index].opacity);
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- return(MagickFalse);
+ status=MagickFalse;
/*
Store the error.
*/
- AssociateAlphaPixel(cube_info,image->colormap+index,&color);
+ AssociateAlphaPixel(&cube,image->colormap+index,&color);
current[u].red=pixel.red-color.red;
current[u].green=pixel.green-color.green;
current[u].blue=pixel.blue-color.blue;
- if (cube_info->associate_alpha != MagickFalse)
+ if (cube.associate_alpha != MagickFalse)
current[u].opacity=pixel.opacity-color.opacity;
- proceed=SetImageProgress(image,DitherImageTag,p->offset,p->span);
- if (proceed == MagickFalse)
- return(MagickFalse);
- p->offset++;
+ if (image->progress_monitor != (MagickProgressMonitor) NULL)
+ {
+ MagickBooleanType
+ proceed;
+
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+ #pragma omp critical (MagickCore_FloydSteinbergDither)
+#endif
+ proceed=SetImageProgress(image,DitherImageTag,(MagickOffsetType) y,
+ image->rows);
+ if (proceed == MagickFalse)
+ status=MagickFalse;
+ }
}
}
- scanlines=(RealPixelPacket *) RelinquishMagickMemory(scanlines);
image_view=DestroyCacheView(image_view);
+ pixels=DestroyPixelThreadSet(pixels);
return(MagickTrue);
}
*indexes=(IndexPacket) index;
if (cube_info->quantize_info->measure_error == MagickFalse)
{
- q->red=image->colormap[index].red;
- q->green=image->colormap[index].green;
- q->blue=image->colormap[index].blue;
+ SetRGBPixelComponents(q,image->colormap+index);
if (cube_info->associate_alpha != MagickFalse)
- q->opacity=image->colormap[index].opacity;
+ SetOpacityPixelComponent(q,image->colormap[index].opacity);
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
return(MagickFalse);
size_t
depth;
- if (cube_info->quantize_info->dither_method == FloydSteinbergDitherMethod)
+ if (cube_info->quantize_info->dither_method != RiemersmaDitherMethod)
return(FloydSteinbergDither(image,cube_info));
/*
Distribute quantization error along a Hilbert curve.
indexes=GetCacheViewAuthenticIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
{
- index=1UL*indexes[x];
+ index=1UL*GetIndexPixelComponent(indexes+x);
if (image->matte != MagickFalse)
{
alpha=(MagickRealType) (QuantumScale*(GetAlphaPixelComponent(p)));
beta=(MagickRealType) (QuantumScale*(QuantumRange-
image->colormap[index].opacity));
}
- distance=fabs(alpha*p->red-beta*image->colormap[index].red);
+ distance=fabs(alpha*GetRedPixelComponent(p)-beta*
+ image->colormap[index].red);
mean_error_per_pixel+=distance;
mean_error+=distance*distance;
if (distance > maximum_error)
maximum_error=distance;
- distance=fabs(alpha*p->green-beta*image->colormap[index].green);
+ distance=fabs(alpha*GetGreenPixelComponent(p)-beta*
+ image->colormap[index].green);
mean_error_per_pixel+=distance;
mean_error+=distance*distance;
if (distance > maximum_error)
maximum_error=distance;
- distance=fabs(alpha*p->blue-beta*image->colormap[index].blue);
+ distance=fabs(alpha*GetBluePixelComponent(p)-beta*
+ image->colormap[index].blue);
mean_error_per_pixel+=distance;
mean_error+=distance*distance;
if (distance > maximum_error)
{
#define PosterizeImageTag "Posterize/Image"
#define PosterizePixel(pixel) (Quantum) (QuantumRange*(MagickRound( \
- QuantumScale*pixel*(levels-1)))/(levels-1))
+ QuantumScale*pixel*(levels-1)))/MagickMax((ssize_t) levels-1,1))
CacheView
*image_view;
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
if (image->storage_class == PseudoClass)
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
+ #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
#endif
for (i=0; i < (ssize_t) image->colors; i++)
{
for (x=0; x < (ssize_t) image->columns; x++)
{
if ((channel & RedChannel) != 0)
- q->red=PosterizePixel(q->red);
+ SetRedPixelComponent(q,PosterizePixel(GetRedPixelComponent(q)));
if ((channel & GreenChannel) != 0)
- q->green=PosterizePixel(q->green);
+ SetGreenPixelComponent(q,PosterizePixel(GetGreenPixelComponent(q)));
if ((channel & BlueChannel) != 0)
- q->blue=PosterizePixel(q->blue);
+ SetBluePixelComponent(q,PosterizePixel(GetBluePixelComponent(q)));
if (((channel & OpacityChannel) != 0) &&
(image->matte == MagickTrue))
- q->opacity=PosterizePixel(q->opacity);
+ SetOpacityPixelComponent(q,PosterizePixel(GetOpacityPixelComponent(q)));
if (((channel & IndexChannel) != 0) &&
(image->colorspace == CMYKColorspace))
- indexes[x]=PosterizePixel(indexes[x]);
+ SetIndexPixelComponent(indexes+x,PosterizePixel(
+ GetIndexPixelComponent(indexes+x)));
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
proceed;
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_PosterizeImageChannel)
+ #pragma omp critical (MagickCore_PosterizeImageChannel)
#endif
proceed=SetImageProgress(image,PosterizeImageTag,progress++,
image->rows);
quantize_info->number_colors=(size_t) MagickMin((ssize_t) levels*levels*
levels,MaxColormapSize+1);
quantize_info->dither=dither;
+ quantize_info->tree_depth=MaxTreeDepth;
status=QuantizeImage(quantize_info,image);
quantize_info=DestroyQuantizeInfo(quantize_info);
return(status);
% o image: the image.
%
*/
-static MagickBooleanType DirectToColormapImage(Image *image,
- ExceptionInfo *exception)
-{
- CacheView
- *image_view;
-
- MagickBooleanType
- status;
-
- register ssize_t
- i;
-
- size_t
- number_colors;
-
- ssize_t
- y;
-
- status=MagickTrue;
- number_colors=(size_t) (image->columns*image->rows);
- if (AcquireImageColormap(image,number_colors) == MagickFalse)
- ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
- image->filename);
- i=0;
- image_view=AcquireCacheView(image);
- for (y=0; y < (ssize_t) image->rows; y++)
- {
- MagickBooleanType
- proceed;
-
- register IndexPacket
- *restrict indexes;
-
- register PixelPacket
- *restrict q;
-
- register ssize_t
- x;
-
- q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception);
- if (q == (const PixelPacket *) NULL)
- break;
- indexes=GetCacheViewAuthenticIndexQueue(image_view);
- for (x=0; x < (ssize_t) image->columns; x++)
- {
- indexes[x]=(IndexPacket) i;
- image->colormap[i++]=(*q++);
- }
- if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
- break;
- proceed=SetImageProgress(image,AssignImageTag,(MagickOffsetType) y,
- image->rows);
- if (proceed == MagickFalse)
- status=MagickFalse;
- }
- image_view=DestroyCacheView(image_view);
- return(status);
-}
-
MagickExport MagickBooleanType QuantizeImage(const QuantizeInfo *quantize_info,
Image *image)
{
maximum_colors=MaxColormapSize;
if (maximum_colors > MaxColormapSize)
maximum_colors=MaxColormapSize;
- if ((image->columns*image->rows) <= maximum_colors)
- return(DirectToColormapImage(image,&image->exception));
if ((IsGrayImage(image,&image->exception) != MagickFalse) &&
(image->matte == MagickFalse))
(void) SetGrayscaleImage(image);
exception=(&image->exception);
image_view=AcquireCacheView(image);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(dynamic,4) shared(status)
+ #pragma omp parallel for schedule(dynamic,4) shared(status)
#endif
for (y=0; y < (ssize_t) image->rows; y++)
{
register size_t
intensity;
- intensity=ScaleQuantumToMap(q->red);
+ intensity=ScaleQuantumToMap(GetRedPixelComponent(q));
if (colormap_index[intensity] < 0)
{
#if defined(MAGICKCORE_OPENMP_SUPPORT)
if (colormap_index[intensity] < 0)
{
colormap_index[intensity]=(ssize_t) image->colors;
- image->colormap[image->colors]=(*q);
+ image->colormap[image->colors].red=GetRedPixelComponent(q);
+ image->colormap[image->colors].green=
+ GetGreenPixelComponent(q);
+ image->colormap[image->colors].blue=GetBluePixelComponent(q);
image->colors++;
}
}
- indexes[x]=(IndexPacket) colormap_index[intensity];
+ SetIndexPixelComponent(indexes+x,colormap_index[intensity]);
q++;
}
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
}
indexes=GetCacheViewAuthenticIndexQueue(image_view);
for (x=0; x < (ssize_t) image->columns; x++)
- indexes[x]=(IndexPacket) colormap_index[ScaleQuantumToMap(indexes[x])];
+ SetIndexPixelComponent(indexes+x,colormap_index[ScaleQuantumToMap(
+ GetIndexPixelComponent(indexes+x))]);
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
status=MagickFalse;
}