76
% A c q u i r e I m a g e C o l o r m a p %
80
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
% AcquireImageColormap() allocates an image colormap and initializes
83
% it to a linear gray colorspace. If the image already has a colormap,
84
% it is replaced. AcquireImageColormap() returns MagickTrue if successful,
85
% otherwise MagickFalse if there is not enough memory.
87
% The format of the AcquireImageColormap method is:
89
% MagickBooleanType AcquireImageColormap(Image *image,
90
% const size_t colors)
92
% A description of each parameter follows:
96
% o colors: the number of colors in the image colormap.
100
static inline size_t MagickMax(const size_t x,
108
static inline size_t MagickMin(const size_t x,
116
MagickExport MagickBooleanType AcquireImageColormap(Image *image,
126
Allocate image colormap.
128
assert(image != (Image *) NULL);
129
assert(image->signature == MagickSignature);
130
if (image->debug != MagickFalse)
131
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
132
image->colors=colors;
133
length=(size_t) colors;
134
if (image->colormap == (PixelPacket *) NULL)
135
image->colormap=(PixelPacket *) AcquireQuantumMemory(length,
136
sizeof(*image->colormap));
138
image->colormap=(PixelPacket *) ResizeQuantumMemory(image->colormap,length,
139
sizeof(*image->colormap));
140
if (image->colormap == (PixelPacket *) NULL)
141
ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
143
for (i=0; i < (ssize_t) image->colors; i++)
148
pixel=(size_t) (i*(QuantumRange/MagickMax(colors-1,1)));
149
image->colormap[i].red=(Quantum) pixel;
150
image->colormap[i].green=(Quantum) pixel;
151
image->colormap[i].blue=(Quantum) pixel;
152
image->colormap[i].opacity=OpaqueOpacity;
154
return(SetImageStorageClass(image,PseudoClass));
158
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162
76
% C y c l e C o l o r m a p I m a g e %
172
86
% The format of the CycleColormapImage method is:
174
% MagickBooleanType CycleColormapImage(Image *image,const ssize_t displace)
88
% MagickBooleanType CycleColormapImage(Image *image,const long displace)
176
90
% A description of each parameter follows:
204
118
status=MagickTrue;
205
119
exception=(&image->exception);
206
120
image_view=AcquireCacheView(image);
207
#if defined(MAGICKCORE_OPENMP_SUPPORT)
208
#pragma omp parallel for schedule(dynamic,4) shared(status)
121
#if defined(MAGICKCORE_OPENMP_SUPPORT)
122
#pragma omp parallel for schedule(static) shared(status)
210
for (y=0; y < (ssize_t) image->rows; y++)
124
for (y=0; y < (long) image->rows; y++)
215
129
register IndexPacket
216
130
*restrict indexes;
221
135
register PixelPacket
232
146
indexes=GetCacheViewAuthenticIndexQueue(image_view);
233
for (x=0; x < (ssize_t) image->columns; x++)
147
for (x=0; x < (long) image->columns; x++)
235
index=(ssize_t) (indexes[x]+displace) % image->colors;
149
index=(long) (indexes[x]+displace) % image->colors;
237
index+=(ssize_t) image->colors;
151
index+=image->colors;
238
152
indexes[x]=(IndexPacket) index;
239
153
q->red=image->colormap[index].red;
240
154
q->green=image->colormap[index].green;
336
250
#if defined(MAGICKCORE_OPENMP_SUPPORT)
337
251
#pragma omp parallel for schedule(dynamic,4) shared(status)
339
for (i=0; i < (ssize_t) image->colors; i++)
253
for (i=0; i < (long) image->colors; i++)
340
254
image->colormap[i].opacity=(IndexPacket) i;
342
256
Sort image colormap by decreasing color popularity.
349
263
#if defined(MAGICKCORE_OPENMP_SUPPORT)
350
264
#pragma omp parallel for schedule(dynamic,4) shared(status)
352
for (i=0; i < (ssize_t) image->colors; i++)
353
pixels[(ssize_t) image->colormap[i].opacity]=(unsigned short) i;
266
for (i=0; i < (long) image->colors; i++)
267
pixels[(long) image->colormap[i].opacity]=(unsigned short) i;
354
268
status=MagickTrue;
355
269
exception=(&image->exception);
356
270
image_view=AcquireCacheView(image);
357
for (y=0; y < (ssize_t) image->rows; y++)
271
for (y=0; y < (long) image->rows; y++)
365
279
register IndexPacket
377
291
indexes=GetCacheViewAuthenticIndexQueue(image_view);
378
for (x=0; x < (ssize_t) image->columns; x++)
292
for (x=0; x < (long) image->columns; x++)
380
index=(IndexPacket) pixels[(ssize_t) indexes[x]];
294
index=(IndexPacket) pixels[(long) indexes[x]];
381
295
indexes[x]=index;
382
*q++=image->colormap[(ssize_t) index];
296
*q++=image->colormap[(long) index];
384
298
if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
385
299
status=MagickFalse;