~ubuntu-branches/ubuntu/oneiric/imagemagick/oneiric-updates

« back to all changes in this revision

Viewing changes to magick/colormap.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-06-15 11:05:28 UTC
  • mfrom: (6.2.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110615110528-08jgo07a4846xh8d
Tags: 8:6.6.0.4-3ubuntu1
* Resynchronise with Debian (LP: #797595).  Remaining changes:
  - Make ufraw-batch (universe) a suggestion instead of a recommendation.
  - Make debian/rules install target depend on check; they cannot reliably
    be run in parallel.
  - Don't set MAKEFLAGS in debian/rules; just pass it to the build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
%                                                                             %
74
74
%                                                                             %
75
75
%                                                                             %
76
 
%   A c q u i r e I m a g e C o l o r m a p                                   %
77
 
%                                                                             %
78
 
%                                                                             %
79
 
%                                                                             %
80
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
 
%
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.
86
 
%
87
 
%  The format of the AcquireImageColormap method is:
88
 
%
89
 
%      MagickBooleanType AcquireImageColormap(Image *image,
90
 
%        const size_t colors)
91
 
%
92
 
%  A description of each parameter follows:
93
 
%
94
 
%    o image: the image.
95
 
%
96
 
%    o colors: the number of colors in the image colormap.
97
 
%
98
 
*/
99
 
 
100
 
static inline size_t MagickMax(const size_t x,
101
 
  const size_t y)
102
 
{
103
 
  if (x > y)
104
 
    return(x);
105
 
  return(y);
106
 
}
107
 
 
108
 
static inline size_t MagickMin(const size_t x,
109
 
  const size_t y)
110
 
{
111
 
  if (x < y)
112
 
    return(x);
113
 
  return(y);
114
 
}
115
 
 
116
 
MagickExport MagickBooleanType AcquireImageColormap(Image *image,
117
 
  const size_t colors)
118
 
{
119
 
  register ssize_t
120
 
    i;
121
 
 
122
 
  size_t
123
 
    length;
124
 
 
125
 
  /*
126
 
    Allocate image colormap.
127
 
  */
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));
137
 
  else
138
 
    image->colormap=(PixelPacket *) ResizeQuantumMemory(image->colormap,length,
139
 
      sizeof(*image->colormap));
140
 
  if (image->colormap == (PixelPacket *) NULL)
141
 
    ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
142
 
      image->filename);
143
 
  for (i=0; i < (ssize_t) image->colors; i++)
144
 
  {
145
 
    size_t
146
 
      pixel;
147
 
 
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;
153
 
  }
154
 
  return(SetImageStorageClass(image,PseudoClass));
155
 
}
156
 
 
157
 
/*
158
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
 
%                                                                             %
160
 
%                                                                             %
161
 
%                                                                             %
162
76
%     C y c l e C o l o r m a p I m a g e                                     %
163
77
%                                                                             %
164
78
%                                                                             %
171
85
%
172
86
%  The format of the CycleColormapImage method is:
173
87
%
174
 
%      MagickBooleanType CycleColormapImage(Image *image,const ssize_t displace)
 
88
%      MagickBooleanType CycleColormapImage(Image *image,const long displace)
175
89
%
176
90
%  A description of each parameter follows:
177
91
%
181
95
%
182
96
*/
183
97
MagickExport MagickBooleanType CycleColormapImage(Image *image,
184
 
  const ssize_t displace)
 
98
  const long displace)
185
99
{
186
100
  CacheView
187
101
    *image_view;
189
103
  ExceptionInfo
190
104
    *exception;
191
105
 
192
 
  ssize_t
 
106
  long
193
107
    y;
194
108
 
195
109
  MagickBooleanType
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)
209
123
#endif
210
 
  for (y=0; y < (ssize_t) image->rows; y++)
 
124
  for (y=0; y < (long) image->rows; y++)
211
125
  {
212
 
    ssize_t
 
126
    long
213
127
      index;
214
128
 
215
129
    register IndexPacket
216
130
      *restrict indexes;
217
131
 
218
 
    register ssize_t
 
132
    register long
219
133
      x;
220
134
 
221
135
    register PixelPacket
230
144
        continue;
231
145
      }
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++)
234
148
    {
235
 
      index=(ssize_t) (indexes[x]+displace) % image->colors;
 
149
      index=(long) (indexes[x]+displace) % image->colors;
236
150
      if (index < 0)
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;
304
218
  ExceptionInfo
305
219
    *exception;
306
220
 
307
 
  ssize_t
 
221
  long
308
222
    y;
309
223
 
310
224
  MagickBooleanType
311
225
    status;
312
226
 
313
 
  register ssize_t
 
227
  register long
314
228
    i;
315
229
 
316
230
  unsigned short
336
250
#if defined(MAGICKCORE_OPENMP_SUPPORT)
337
251
  #pragma omp parallel for schedule(dynamic,4) shared(status)
338
252
#endif
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;
341
255
  /*
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)
351
265
#endif
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++)
358
272
  {
359
273
    IndexPacket
360
274
      index;
361
275
 
362
 
    register ssize_t
 
276
    register long
363
277
      x;
364
278
 
365
279
    register IndexPacket
375
289
        continue;
376
290
      }
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++)
379
293
    {
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];
383
297
    }
384
298
    if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
385
299
      status=MagickFalse;