blob: 246225c191d3e6c553f6acb3cd653be6042b1c3a [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% QQQ U U AAA N N TTTTT U U M M %
7% Q Q U U A A NN N T U U MM MM %
8% Q Q U U AAAAA N N N T U U M M M %
9% Q QQ U U A A N NN T U U M M %
10% QQQQ UUU A A N N T UUU M M %
11% %
12% IIIII M M PPPP OOO RRRR TTTTT %
13% I MM MM P P O O R R T %
14% I M M M PPPP O O RRRR T %
15% I M M P O O R R T %
16% IIIII M M P OOO R R T %
17% %
18% MagickCore Methods to Import Quantum Pixels %
19% %
20% Software Design %
21% John Cristy %
22% October 1998 %
23% %
24% %
25% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
26% dedicated to making software imaging solutions freely available. %
27% %
28% You may not use this file except in compliance with the License. You may %
29% obtain a copy of the License at %
30% %
31% http://www.imagemagick.org/script/license.php %
32% %
33% Unless required by applicable law or agreed to in writing, software %
34% distributed under the License is distributed on an "AS IS" BASIS, %
35% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36% See the License for the specific language governing permissions and %
37% limitations under the License. %
38% %
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40%
41%
42*/
43
44/*
45 Include declarations.
46*/
47#include "magick/studio.h"
48#include "magick/property.h"
49#include "magick/blob.h"
50#include "magick/blob-private.h"
51#include "magick/color-private.h"
52#include "magick/exception.h"
53#include "magick/exception-private.h"
54#include "magick/cache.h"
55#include "magick/constitute.h"
56#include "magick/delegate.h"
57#include "magick/geometry.h"
58#include "magick/list.h"
59#include "magick/magick.h"
60#include "magick/memory_.h"
61#include "magick/monitor.h"
62#include "magick/option.h"
63#include "magick/pixel.h"
64#include "magick/pixel-private.h"
65#include "magick/quantum.h"
66#include "magick/quantum-private.h"
67#include "magick/resource_.h"
68#include "magick/semaphore.h"
69#include "magick/statistic.h"
70#include "magick/stream.h"
71#include "magick/string_.h"
72#include "magick/utility.h"
73
74/*
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76% %
77% %
78% %
79% I m p o r t Q u a n t u m P i x e l s %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
85% ImportQuantumPixels() transfers one or more pixel components from a user
86% supplied buffer into the image pixel cache of an image. The pixels are
87% expected in network byte order. It returns MagickTrue if the pixels are
88% successfully transferred, otherwise MagickFalse.
89%
90% The format of the ImportQuantumPixels method is:
91%
92% size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93% const QuantumInfo *quantum_info,const QuantumType quantum_type,
94% const unsigned char *pixels,ExceptionInfo *exception)
95%
96% A description of each parameter follows:
97%
98% o image: the image.
99%
100% o image_view: the image cache view.
101%
102% o quantum_info: the quantum info.
103%
104% o quantum_type: Declare which pixel components to transfer (red, green,
105% blue, opacity, RGB, or RGBA).
106%
107% o pixels: The pixel components are transferred from this buffer.
108%
109% o exception: return any errors or warnings in this structure.
110%
111*/
112
113static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +0000114 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +0000115{
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
120}
121
122static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
124{
125 double
126 *p;
127
128 unsigned char
129 quantum[8];
130
131 if (quantum_state->endian != LSBEndian)
132 {
133 quantum[7]=(*pixels++);
134 quantum[6]=(*pixels++);
135 quantum[5]=(*pixels++);
136 quantum[5]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[2]=(*pixels++);
139 quantum[1]=(*pixels++);
140 quantum[0]=(*pixels++);
141 p=(double *) quantum;
142 *pixel=(*p);
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
145 return(pixels);
146 }
147 quantum[0]=(*pixels++);
148 quantum[1]=(*pixels++);
149 quantum[2]=(*pixels++);
150 quantum[3]=(*pixels++);
151 quantum[4]=(*pixels++);
152 quantum[5]=(*pixels++);
153 quantum[6]=(*pixels++);
154 quantum[7]=(*pixels++);
155 p=(double *) quantum;
156 *pixel=(*p);
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
159 return(pixels);
160}
161
162static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
164{
165 float
166 *p;
167
168 unsigned char
169 quantum[4];
170
171 if (quantum_state->endian != LSBEndian)
172 {
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
177 p=(float *) quantum;
178 *pixel=(*p);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
181 return(pixels);
182 }
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
187 p=(float *) quantum;
188 *pixel=(*p);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
191 return(pixels);
192}
193
194static inline const unsigned char *PushQuantumPixel(
cristybb503372010-05-27 20:51:26 +0000195 QuantumState *quantum_state,const size_t depth,
cristy4cb162a2010-05-30 03:04:47 +0000196 const unsigned char *pixels,unsigned int *quantum)
cristy3ed852e2009-09-05 21:47:34 +0000197{
cristybb503372010-05-27 20:51:26 +0000198 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000199 i;
200
cristy6b825f92010-06-04 02:01:10 +0000201 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000202 quantum_bits;
203
204 *quantum=(QuantumAny) 0;
cristybb503372010-05-27 20:51:26 +0000205 for (i=(ssize_t) depth; i > 0L; )
cristy3ed852e2009-09-05 21:47:34 +0000206 {
207 if (quantum_state->bits == 0UL)
208 {
209 quantum_state->pixel=(*pixels++);
cristy6b825f92010-06-04 02:01:10 +0000210 quantum_state->bits=8UL;
cristy3ed852e2009-09-05 21:47:34 +0000211 }
cristybb503372010-05-27 20:51:26 +0000212 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
cristyebdf07a2010-06-04 14:48:53 +0000215 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000216 quantum_state->bits-=quantum_bits;
cristy6b825f92010-06-04 02:01:10 +0000217 *quantum=(unsigned int) ((*quantum << quantum_bits) |
218 ((quantum_state->pixel >> quantum_state->bits) &~ ((~0UL) <<
219 quantum_bits)));
cristy3ed852e2009-09-05 21:47:34 +0000220 }
221 return(pixels);
222}
223
224static inline const unsigned char *PushQuantumLongPixel(
cristybb503372010-05-27 20:51:26 +0000225 QuantumState *quantum_state,const size_t depth,
cristy4cb162a2010-05-30 03:04:47 +0000226 const unsigned char *pixels,unsigned int *quantum)
cristy3ed852e2009-09-05 21:47:34 +0000227{
cristybb503372010-05-27 20:51:26 +0000228 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000229 i;
230
cristybb503372010-05-27 20:51:26 +0000231 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000232 quantum_bits;
233
234 *quantum=0UL;
cristybb503372010-05-27 20:51:26 +0000235 for (i=(ssize_t) depth; i > 0; )
cristy3ed852e2009-09-05 21:47:34 +0000236 {
237 if (quantum_state->bits == 0)
238 {
239 pixels=PushLongPixel(quantum_state->endian,pixels,
240 &quantum_state->pixel);
cristy4cb162a2010-05-30 03:04:47 +0000241 quantum_state->bits=32U;
cristy3ed852e2009-09-05 21:47:34 +0000242 }
cristybb503372010-05-27 20:51:26 +0000243 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000244 if (quantum_bits > quantum_state->bits)
245 quantum_bits=quantum_state->bits;
cristy4cb162a2010-05-30 03:04:47 +0000246 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
cristy3ed852e2009-09-05 21:47:34 +0000247 quantum_state->mask[quantum_bits]) << (depth-i));
cristyeaedf062010-05-29 22:36:02 +0000248 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000249 quantum_state->bits-=quantum_bits;
250 }
251 return(pixels);
252}
253
254MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
255 const QuantumInfo *quantum_info,const QuantumType quantum_type,
256 const unsigned char *pixels,ExceptionInfo *exception)
257{
258 EndianType
259 endian;
260
cristybb503372010-05-27 20:51:26 +0000261 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000262 bit;
263
264 MagickSizeType
265 number_pixels;
266
267 QuantumAny
268 range;
269
270 QuantumState
271 quantum_state;
272
273 register const unsigned char
cristyaebafa22009-11-26 01:48:56 +0000274 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000275
276 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000277 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000278
cristybb503372010-05-27 20:51:26 +0000279 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000280 x;
281
282 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000283 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000284
285 size_t
286 extent;
287
cristy4cb162a2010-05-30 03:04:47 +0000288 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000289 pixel;
290
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
295 assert(quantum_info != (QuantumInfo *) NULL);
296 assert(quantum_info->signature == MagickSignature);
297 if (pixels == (const unsigned char *) NULL)
298 pixels=GetQuantumPixels(quantum_info);
299 x=0;
300 p=pixels;
cristy8a7ea362010-03-10 20:31:43 +0000301 if (image_view == (CacheView *) NULL)
302 {
303 number_pixels=GetImageExtent(image);
304 q=GetAuthenticPixelQueue(image);
305 indexes=GetAuthenticIndexQueue(image);
306 }
307 else
cristy3ed852e2009-09-05 21:47:34 +0000308 {
309 number_pixels=GetCacheViewExtent(image_view);
310 q=GetCacheViewAuthenticPixelQueue(image_view);
311 indexes=GetCacheViewAuthenticIndexQueue(image_view);
312 }
313 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
314 extent=GetQuantumExtent(image,quantum_info,quantum_type);
315 endian=quantum_state.endian;
316 switch (quantum_type)
317 {
318 case IndexQuantum:
319 {
320 MagickBooleanType
321 range_exception;
322
323 if (image->storage_class != PseudoClass)
324 {
325 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
326 "ColormappedImageRequired","`%s'",image->filename);
327 return(extent);
328 }
329 range_exception=MagickFalse;
330 switch (quantum_info->depth)
331 {
332 case 1:
333 {
334 register unsigned char
335 pixel;
336
cristybb503372010-05-27 20:51:26 +0000337 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000338 {
339 for (bit=0; bit < 8; bit++)
340 {
341 if (quantum_info->min_is_white == MagickFalse)
342 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
343 0x00 : 0x01);
344 else
345 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
346 0x00 : 0x01);
347 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000348 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000349 q++;
350 }
351 p++;
352 }
cristybb503372010-05-27 20:51:26 +0000353 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000354 {
355 if (quantum_info->min_is_white == MagickFalse)
356 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
357 0x00 : 0x01);
358 else
359 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
360 0x00 : 0x01);
361 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000362 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000363 q++;
364 }
365 break;
366 }
367 case 4:
368 {
369 register unsigned char
370 pixel;
371
cristybb503372010-05-27 20:51:26 +0000372 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000373 {
374 pixel=(unsigned char) ((*p >> 4) & 0xf);
375 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000376 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000377 q++;
378 pixel=(unsigned char) ((*p) & 0xf);
379 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000380 *q=image->colormap[(ssize_t) indexes[x+1]];
cristy3ed852e2009-09-05 21:47:34 +0000381 p++;
382 q++;
383 }
cristybb503372010-05-27 20:51:26 +0000384 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000385 {
386 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
387 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000388 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000389 q++;
390 }
391 break;
392 }
393 case 8:
394 {
395 unsigned char
396 pixel;
397
cristybb503372010-05-27 20:51:26 +0000398 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000399 {
400 p=PushCharPixel(p,&pixel);
401 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000402 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000403 p+=quantum_info->pad;
404 q++;
405 }
406 break;
407 }
408 case 16:
409 {
410 unsigned short
411 pixel;
412
cristyc9672a92010-01-06 00:57:45 +0000413 if (quantum_info->format == FloatingPointQuantumFormat)
414 {
cristybb503372010-05-27 20:51:26 +0000415 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000416 {
417 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000418 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000419 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
420 &range_exception);
cristybb503372010-05-27 20:51:26 +0000421 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000422 p+=quantum_info->pad;
423 q++;
424 }
425 break;
426 }
cristybb503372010-05-27 20:51:26 +0000427 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000428 {
429 p=PushShortPixel(endian,p,&pixel);
430 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000431 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000432 p+=quantum_info->pad;
433 q++;
434 }
435 break;
436 }
437 case 32:
438 {
cristy4cb162a2010-05-30 03:04:47 +0000439 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000440 pixel;
441
442 if (quantum_info->format == FloatingPointQuantumFormat)
443 {
444 float
445 pixel;
446
cristybb503372010-05-27 20:51:26 +0000447 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000448 {
449 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000450 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000451 &range_exception);
cristybb503372010-05-27 20:51:26 +0000452 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000453 p+=quantum_info->pad;
454 q++;
455 }
456 break;
457 }
cristybb503372010-05-27 20:51:26 +0000458 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000459 {
460 p=PushLongPixel(endian,p,&pixel);
461 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000462 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000463 p+=quantum_info->pad;
464 q++;
465 }
466 break;
467 }
468 case 64:
469 {
470 if (quantum_info->format == FloatingPointQuantumFormat)
471 {
472 double
473 pixel;
474
cristybb503372010-05-27 20:51:26 +0000475 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000476 {
477 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000478 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000479 &range_exception);
cristybb503372010-05-27 20:51:26 +0000480 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000481 p+=quantum_info->pad;
482 q++;
483 }
484 break;
485 }
486 }
487 default:
488 {
cristybb503372010-05-27 20:51:26 +0000489 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000490 {
491 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
492 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000493 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000494 p+=quantum_info->pad;
495 q++;
496 }
497 break;
498 }
499 }
500 if (range_exception != MagickFalse)
501 (void) ThrowMagickException(exception,GetMagickModule(),
502 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
503 break;
504 }
505 case IndexAlphaQuantum:
506 {
507 MagickBooleanType
508 range_exception;
509
510 if (image->storage_class != PseudoClass)
511 {
512 (void) ThrowMagickException(exception,GetMagickModule(),
513 ImageError,"ColormappedImageRequired","`%s'",image->filename);
514 return(extent);
515 }
516 range_exception=MagickFalse;
517 switch (quantum_info->depth)
518 {
519 case 1:
520 {
521 register unsigned char
522 pixel;
523
cristybb503372010-05-27 20:51:26 +0000524 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +0000525 {
526 for (bit=0; bit < 8; bit+=2)
527 {
528 if (quantum_info->min_is_white == MagickFalse)
529 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
530 0x00 : 0x01);
531 else
532 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
533 0x00 : 0x01);
534 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
535 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
536 q->green=q->red;
537 q->blue=q->red;
538 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
539 == 0 ? TransparentOpacity : OpaqueOpacity);
540 q++;
541 }
542 }
cristybb503372010-05-27 20:51:26 +0000543 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +0000544 {
545 if (quantum_info->min_is_white == MagickFalse)
546 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
547 0x00 : 0x01);
548 else
549 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
550 0x00 : 0x01);
551 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
552 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
553 q->green=q->red;
554 q->blue=q->red;
555 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
556 0 ? TransparentOpacity : OpaqueOpacity);
557 q++;
558 }
559 break;
560 }
561 case 4:
562 {
563 register unsigned char
564 pixel;
565
566 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000567 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000568 {
569 pixel=(unsigned char) ((*p >> 4) & 0xf);
570 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000571 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000572 pixel=(unsigned char) ((*p) & 0xf);
573 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
574 p++;
575 q++;
576 }
577 break;
578 }
579 case 8:
580 {
581 unsigned char
582 pixel;
583
cristybb503372010-05-27 20:51:26 +0000584 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000585 {
586 p=PushCharPixel(p,&pixel);
587 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000588 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000589 p=PushCharPixel(p,&pixel);
590 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
591 p+=quantum_info->pad;
592 q++;
593 }
594 break;
595 }
596 case 16:
597 {
598 unsigned short
599 pixel;
600
cristyc9672a92010-01-06 00:57:45 +0000601 if (quantum_info->format == FloatingPointQuantumFormat)
602 {
cristybb503372010-05-27 20:51:26 +0000603 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000604 {
605 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000606 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000607 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
608 &range_exception);
cristybb503372010-05-27 20:51:26 +0000609 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000610 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000611 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000612 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +0000613 p+=quantum_info->pad;
614 q++;
615 }
616 break;
617 }
cristybb503372010-05-27 20:51:26 +0000618 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000619 {
620 p=PushShortPixel(endian,p,&pixel);
621 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000622 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000623 p=PushShortPixel(endian,p,&pixel);
624 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
625 p+=quantum_info->pad;
626 q++;
627 }
628 break;
629 }
630 case 32:
631 {
cristy4cb162a2010-05-30 03:04:47 +0000632 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000633 pixel;
634
635 if (quantum_info->format == FloatingPointQuantumFormat)
636 {
637 float
638 pixel;
639
cristybb503372010-05-27 20:51:26 +0000640 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000641 {
642 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000643 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000644 &range_exception);
cristybb503372010-05-27 20:51:26 +0000645 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000646 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000647 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000648 p+=quantum_info->pad;
649 q++;
650 }
651 break;
652 }
cristybb503372010-05-27 20:51:26 +0000653 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000654 {
655 p=PushLongPixel(endian,p,&pixel);
656 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000657 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000658 p=PushLongPixel(endian,p,&pixel);
659 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
660 p+=quantum_info->pad;
661 q++;
662 }
663 break;
664 }
665 case 64:
666 {
667 if (quantum_info->format == FloatingPointQuantumFormat)
668 {
669 double
670 pixel;
671
cristybb503372010-05-27 20:51:26 +0000672 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000673 {
674 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000675 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000676 &range_exception);
cristybb503372010-05-27 20:51:26 +0000677 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000678 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000679 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000680 p+=quantum_info->pad;
681 q++;
682 }
683 break;
684 }
685 }
686 default:
687 {
688 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000689 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000690 {
691 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
692 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000693 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000694 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
695 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
696 p+=quantum_info->pad;
697 q++;
698 }
699 break;
700 }
701 }
702 if (range_exception != MagickFalse)
703 (void) ThrowMagickException(exception,GetMagickModule(),
704 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
705 break;
706 }
707 case GrayQuantum:
708 {
709 switch (quantum_info->depth)
710 {
711 case 1:
712 {
713 register Quantum
714 black,
715 white;
716
717 black=0;
718 white=(Quantum) QuantumRange;
719 if (quantum_info->min_is_white != MagickFalse)
720 {
721 black=(Quantum) QuantumRange;
722 white=0;
723 }
cristybb503372010-05-27 20:51:26 +0000724 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000725 {
726 for (bit=0; bit < 8; bit++)
727 {
728 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
729 q->green=q->red;
730 q->blue=q->red;
731 q++;
732 }
733 p++;
734 }
cristybb503372010-05-27 20:51:26 +0000735 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000736 {
737 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
738 q->green=q->red;
739 q->blue=q->red;
740 q++;
741 }
742 if (bit != 0)
743 p++;
744 break;
745 }
746 case 4:
747 {
748 register unsigned char
749 pixel;
750
751 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000752 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000753 {
754 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +0000755 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000756 q->green=q->red;
757 q->blue=q->red;
758 q++;
759 pixel=(unsigned char) ((*p) & 0xf);
cristyce70c172010-01-07 17:15:30 +0000760 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000761 q->green=q->red;
762 q->blue=q->red;
763 p++;
764 q++;
765 }
cristybb503372010-05-27 20:51:26 +0000766 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000767 {
768 pixel=(unsigned char) (*p++ >> 4);
cristyce70c172010-01-07 17:15:30 +0000769 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000770 q->green=q->red;
771 q->blue=q->red;
772 q++;
773 }
774 break;
775 }
776 case 8:
777 {
778 unsigned char
779 pixel;
780
781 if (quantum_info->min_is_white != MagickFalse)
782 {
cristybb503372010-05-27 20:51:26 +0000783 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000784 {
785 p=PushCharPixel(p,&pixel);
786 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
787 q->green=q->red;
788 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +0000789 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000790 p+=quantum_info->pad;
791 q++;
792 }
793 break;
794 }
cristybb503372010-05-27 20:51:26 +0000795 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000796 {
797 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000798 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000799 q->green=q->red;
800 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +0000801 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000802 p+=quantum_info->pad;
803 q++;
804 }
805 break;
806 }
807 case 10:
808 {
809 range=GetQuantumRange(image->depth);
810 if (quantum_info->pack == MagickFalse)
811 {
812 if (image->endian != LSBEndian)
813 {
cristybb503372010-05-27 20:51:26 +0000814 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +0000815 {
816 p=PushLongPixel(endian,p,&pixel);
cristyff024b42010-02-21 22:55:09 +0000817 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000818 q->green=q->red;
819 q->blue=q->red;
820 q++;
cristyff024b42010-02-21 22:55:09 +0000821 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000822 q->green=q->red;
823 q->blue=q->red;
824 q++;
cristyff024b42010-02-21 22:55:09 +0000825 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000826 q->green=q->red;
827 q->blue=q->red;
828 p+=quantum_info->pad;
829 q++;
830 }
cristy69702dd2010-02-22 15:26:39 +0000831 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +0000832 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +0000833 {
834 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
835 q->green=q->red;
836 q->blue=q->red;
837 q++;
838 }
cristybb503372010-05-27 20:51:26 +0000839 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +0000840 {
841 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
842 q->green=q->red;
843 q->blue=q->red;
844 q++;
845 }
cristy3ed852e2009-09-05 21:47:34 +0000846 break;
847 }
cristybb503372010-05-27 20:51:26 +0000848 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +0000849 {
850 p=PushLongPixel(endian,p,&pixel);
851 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
852 q->green=q->red;
853 q->blue=q->red;
854 q++;
855 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
856 q->green=q->red;
857 q->blue=q->red;
858 q++;
859 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
860 q->green=q->red;
861 q->blue=q->red;
862 p+=quantum_info->pad;
863 q++;
864 }
cristy69702dd2010-02-22 15:26:39 +0000865 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +0000866 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +0000867 {
868 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
869 q->green=q->red;
870 q->blue=q->red;
871 q++;
872 }
cristybb503372010-05-27 20:51:26 +0000873 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +0000874 {
875 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
876 q->green=q->red;
877 q->blue=q->red;
878 q++;
879 }
cristy3ed852e2009-09-05 21:47:34 +0000880 break;
881 }
cristybb503372010-05-27 20:51:26 +0000882 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000883 {
884 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000885 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000886 q->green=q->red;
887 q->blue=q->red;
888 p+=quantum_info->pad;
889 q++;
890 }
891 break;
892 }
893 case 12:
894 {
895 range=GetQuantumRange(image->depth);
896 if (quantum_info->pack == MagickFalse)
897 {
898 unsigned short
899 pixel;
900
cristybb503372010-05-27 20:51:26 +0000901 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000902 {
903 p=PushShortPixel(endian,p,&pixel);
904 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
905 q->green=q->red;
906 q->blue=q->red;
907 q++;
908 p=PushShortPixel(endian,p,&pixel);
909 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
910 q->green=q->red;
911 q->blue=q->red;
912 p+=quantum_info->pad;
913 q++;
914 }
cristybb503372010-05-27 20:51:26 +0000915 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000916 {
917 p=PushShortPixel(endian,p,&pixel);
918 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
919 q->green=q->red;
920 q->blue=q->red;
921 p+=quantum_info->pad;
922 q++;
923 }
924 if (bit != 0)
925 p++;
926 break;
927 }
cristybb503372010-05-27 20:51:26 +0000928 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000929 {
930 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000931 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000932 q->green=q->red;
933 q->blue=q->red;
934 p+=quantum_info->pad;
935 q++;
936 }
937 break;
938 }
939 case 16:
940 {
941 unsigned short
942 pixel;
943
944 if (quantum_info->min_is_white != MagickFalse)
945 {
cristybb503372010-05-27 20:51:26 +0000946 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000947 {
948 p=PushShortPixel(endian,p,&pixel);
949 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
950 q->green=q->red;
951 q->blue=q->red;
952 p+=quantum_info->pad;
953 q++;
954 }
955 break;
956 }
cristyc9672a92010-01-06 00:57:45 +0000957 if (quantum_info->format == FloatingPointQuantumFormat)
958 {
cristybb503372010-05-27 20:51:26 +0000959 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000960 {
961 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000962 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +0000963 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +0000964 q->green=q->red;
965 q->blue=q->red;
966 p+=quantum_info->pad;
967 q++;
968 }
969 break;
970 }
cristybb503372010-05-27 20:51:26 +0000971 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000972 {
973 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000974 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000975 q->green=q->red;
976 q->blue=q->red;
977 p+=quantum_info->pad;
978 q++;
979 }
980 break;
981 }
982 case 32:
983 {
cristy4cb162a2010-05-30 03:04:47 +0000984 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000985 pixel;
986
987 if (quantum_info->format == FloatingPointQuantumFormat)
988 {
989 float
990 pixel;
991
cristybb503372010-05-27 20:51:26 +0000992 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000993 {
994 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000995 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +0000996 q->green=q->red;
997 q->blue=q->red;
998 p+=quantum_info->pad;
999 q++;
1000 }
1001 break;
1002 }
cristybb503372010-05-27 20:51:26 +00001003 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001004 {
1005 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001006 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001007 q->green=q->red;
1008 q->blue=q->red;
1009 p+=quantum_info->pad;
1010 q++;
1011 }
1012 break;
1013 }
1014 case 64:
1015 {
1016 if (quantum_info->format == FloatingPointQuantumFormat)
1017 {
1018 double
1019 pixel;
1020
cristybb503372010-05-27 20:51:26 +00001021 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001022 {
1023 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001024 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001025 q->green=q->red;
1026 q->blue=q->red;
1027 p+=quantum_info->pad;
1028 q++;
1029 }
1030 break;
1031 }
1032 }
1033 default:
1034 {
1035 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001036 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001037 {
1038 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001039 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001040 q->green=q->red;
1041 q->blue=q->red;
1042 p+=quantum_info->pad;
1043 q++;
1044 }
1045 break;
1046 }
1047 }
1048 break;
1049 }
1050 case GrayAlphaQuantum:
1051 {
1052 switch (quantum_info->depth)
1053 {
1054 case 1:
1055 {
1056 register unsigned char
1057 pixel;
1058
cristybb503372010-05-27 20:51:26 +00001059 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +00001060 {
1061 for (bit=0; bit < 8; bit+=2)
1062 {
1063 pixel=(unsigned char)
1064 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1065 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1066 q->green=q->red;
1067 q->blue=q->red;
1068 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1069 == 0 ? TransparentOpacity : OpaqueOpacity);
1070 q++;
1071 }
1072 p++;
1073 }
cristybb503372010-05-27 20:51:26 +00001074 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +00001075 {
1076 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1077 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1078 q->green=q->red;
1079 q->blue=q->red;
1080 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1081 ? TransparentOpacity : OpaqueOpacity);
1082 q++;
1083 }
1084 if (bit != 0)
1085 p++;
1086 break;
1087 }
1088 case 4:
1089 {
1090 register unsigned char
1091 pixel;
1092
1093 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001094 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001095 {
1096 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +00001097 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001098 q->green=q->red;
1099 q->blue=q->red;
1100 pixel=(unsigned char) ((*p) & 0xf);
1101 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1102 p++;
1103 q++;
1104 }
1105 break;
1106 }
1107 case 8:
1108 {
1109 unsigned char
1110 pixel;
1111
cristybb503372010-05-27 20:51:26 +00001112 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001113 {
1114 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001115 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001116 q->green=q->red;
1117 q->blue=q->red;
1118 p=PushCharPixel(p,&pixel);
1119 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1120 p+=quantum_info->pad;
1121 q++;
1122 }
1123 break;
1124 }
1125 case 10:
1126 {
1127 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001128 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001129 {
1130 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001131 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001132 q->green=q->red;
1133 q->blue=q->red;
1134 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001135 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001136 p+=quantum_info->pad;
1137 q++;
1138 }
1139 break;
1140 }
1141 case 12:
1142 {
1143 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001144 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001145 {
1146 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001147 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001148 q->green=q->red;
1149 q->blue=q->red;
1150 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001151 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001152 p+=quantum_info->pad;
1153 q++;
1154 }
1155 break;
1156 }
1157 case 16:
1158 {
1159 unsigned short
1160 pixel;
1161
cristyc9672a92010-01-06 00:57:45 +00001162 if (quantum_info->format == FloatingPointQuantumFormat)
1163 {
cristybb503372010-05-27 20:51:26 +00001164 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001165 {
1166 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001167 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001168 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001169 q->green=q->red;
1170 q->blue=q->red;
1171 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001172 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00001173 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00001174 p+=quantum_info->pad;
1175 q++;
1176 }
1177 break;
1178 }
cristybb503372010-05-27 20:51:26 +00001179 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001180 {
1181 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001182 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001183 q->green=q->red;
1184 q->blue=q->red;
1185 p=PushShortPixel(endian,p,&pixel);
1186 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1187 p+=quantum_info->pad;
1188 q++;
1189 }
1190 break;
1191 }
1192 case 32:
1193 {
cristy4cb162a2010-05-30 03:04:47 +00001194 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001195 pixel;
1196
1197 if (quantum_info->format == FloatingPointQuantumFormat)
1198 {
1199 float
1200 pixel;
1201
cristybb503372010-05-27 20:51:26 +00001202 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001203 {
1204 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001205 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001206 q->green=q->red;
1207 q->blue=q->red;
1208 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001209 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001210 p+=quantum_info->pad;
1211 q++;
1212 }
1213 break;
1214 }
cristybb503372010-05-27 20:51:26 +00001215 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001216 {
1217 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001218 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001219 q->green=q->red;
1220 q->blue=q->red;
1221 p=PushLongPixel(endian,p,&pixel);
1222 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1223 p+=quantum_info->pad;
1224 q++;
1225 }
1226 break;
1227 }
1228 case 64:
1229 {
1230 if (quantum_info->format == FloatingPointQuantumFormat)
1231 {
1232 double
1233 pixel;
1234
cristybb503372010-05-27 20:51:26 +00001235 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001236 {
1237 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001238 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001239 q->green=q->red;
1240 q->blue=q->red;
1241 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001242 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001243 p+=quantum_info->pad;
1244 q++;
1245 }
1246 break;
1247 }
1248 }
1249 default:
1250 {
1251 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001252 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001253 {
1254 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001255 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001256 q->green=q->red;
1257 q->blue=q->red;
1258 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1259 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1260 p+=quantum_info->pad;
1261 q++;
1262 }
1263 break;
1264 }
1265 }
1266 break;
1267 }
1268 case RedQuantum:
1269 case CyanQuantum:
1270 {
1271 switch (quantum_info->depth)
1272 {
1273 case 8:
1274 {
1275 unsigned char
1276 pixel;
1277
cristybb503372010-05-27 20:51:26 +00001278 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001279 {
1280 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001281 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001282 p+=quantum_info->pad;
1283 q++;
1284 }
1285 break;
1286 }
1287 case 16:
1288 {
1289 unsigned short
1290 pixel;
1291
cristyc9672a92010-01-06 00:57:45 +00001292 if (quantum_info->format == FloatingPointQuantumFormat)
1293 {
cristybb503372010-05-27 20:51:26 +00001294 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001295 {
1296 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001297 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001298 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001299 p+=quantum_info->pad;
1300 q++;
1301 }
1302 break;
1303 }
cristybb503372010-05-27 20:51:26 +00001304 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001305 {
1306 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001307 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001308 p+=quantum_info->pad;
1309 q++;
1310 }
1311 break;
1312 }
1313 case 32:
1314 {
cristy4cb162a2010-05-30 03:04:47 +00001315 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001316 pixel;
1317
1318 if (quantum_info->format == FloatingPointQuantumFormat)
1319 {
1320 float
1321 pixel;
1322
cristybb503372010-05-27 20:51:26 +00001323 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001324 {
1325 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001326 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001327 p+=quantum_info->pad;
1328 q++;
1329 }
1330 break;
1331 }
cristybb503372010-05-27 20:51:26 +00001332 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001333 {
1334 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001335 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001336 p+=quantum_info->pad;
1337 q++;
1338 }
1339 break;
1340 }
1341 case 64:
1342 {
1343 if (quantum_info->format == FloatingPointQuantumFormat)
1344 {
1345 double
1346 pixel;
1347
cristybb503372010-05-27 20:51:26 +00001348 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001349 {
1350 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001351 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001352 p+=quantum_info->pad;
1353 q++;
1354 }
1355 break;
1356 }
1357 }
1358 default:
1359 {
1360 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001361 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001362 {
1363 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001364 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001365 p+=quantum_info->pad;
1366 q++;
1367 }
1368 break;
1369 }
1370 }
1371 break;
1372 }
1373 case GreenQuantum:
1374 case MagentaQuantum:
1375 {
1376 switch (quantum_info->depth)
1377 {
1378 case 8:
1379 {
1380 unsigned char
1381 pixel;
1382
cristybb503372010-05-27 20:51:26 +00001383 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001384 {
1385 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001386 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001387 p+=quantum_info->pad;
1388 q++;
1389 }
1390 break;
1391 }
1392 case 16:
1393 {
1394 unsigned short
1395 pixel;
1396
cristyc9672a92010-01-06 00:57:45 +00001397 if (quantum_info->format == FloatingPointQuantumFormat)
1398 {
cristybb503372010-05-27 20:51:26 +00001399 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001400 {
1401 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001402 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001403 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001404 p+=quantum_info->pad;
1405 q++;
1406 }
1407 break;
1408 }
cristybb503372010-05-27 20:51:26 +00001409 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001410 {
1411 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001412 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001413 p+=quantum_info->pad;
1414 q++;
1415 }
1416 break;
1417 }
1418 case 32:
1419 {
cristy4cb162a2010-05-30 03:04:47 +00001420 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001421 pixel;
1422
1423 if (quantum_info->format == FloatingPointQuantumFormat)
1424 {
1425 float
1426 pixel;
1427
cristybb503372010-05-27 20:51:26 +00001428 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001429 {
1430 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001431 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001432 p+=quantum_info->pad;
1433 q++;
1434 }
1435 break;
1436 }
cristybb503372010-05-27 20:51:26 +00001437 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001438 {
1439 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001440 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001441 p+=quantum_info->pad;
1442 q++;
1443 }
1444 break;
1445 }
1446 case 64:
1447 {
1448 if (quantum_info->format == FloatingPointQuantumFormat)
1449 {
1450 double
1451 pixel;
1452
cristybb503372010-05-27 20:51:26 +00001453 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001454 {
1455 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001456 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001457 p+=quantum_info->pad;
1458 q++;
1459 }
1460 break;
1461 }
1462 }
1463 default:
1464 {
1465 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001466 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001467 {
1468 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001469 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001470 p+=quantum_info->pad;
1471 q++;
1472 }
1473 break;
1474 }
1475 }
1476 break;
1477 }
1478 case BlueQuantum:
1479 case YellowQuantum:
1480 {
1481 switch (quantum_info->depth)
1482 {
1483 case 8:
1484 {
1485 unsigned char
1486 pixel;
1487
cristybb503372010-05-27 20:51:26 +00001488 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001489 {
1490 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001491 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001492 p+=quantum_info->pad;
1493 q++;
1494 }
1495 break;
1496 }
1497 case 16:
1498 {
1499 unsigned short
1500 pixel;
1501
cristyc9672a92010-01-06 00:57:45 +00001502 if (quantum_info->format == FloatingPointQuantumFormat)
1503 {
cristybb503372010-05-27 20:51:26 +00001504 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001505 {
1506 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001507 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001508 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001509 p+=quantum_info->pad;
1510 q++;
1511 }
1512 break;
1513 }
cristybb503372010-05-27 20:51:26 +00001514 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001515 {
1516 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001517 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001518 p+=quantum_info->pad;
1519 q++;
1520 }
1521 break;
1522 }
1523 case 32:
1524 {
cristy4cb162a2010-05-30 03:04:47 +00001525 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001526 pixel;
1527
1528 if (quantum_info->format == FloatingPointQuantumFormat)
1529 {
1530 float
1531 pixel;
1532
cristybb503372010-05-27 20:51:26 +00001533 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001534 {
1535 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001536 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001537 p+=quantum_info->pad;
1538 q++;
1539 }
1540 break;
1541 }
cristybb503372010-05-27 20:51:26 +00001542 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001543 {
1544 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001545 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001546 p+=quantum_info->pad;
1547 q++;
1548 }
1549 break;
1550 }
1551 case 64:
1552 {
1553 if (quantum_info->format == FloatingPointQuantumFormat)
1554 {
1555 double
1556 pixel;
1557
cristybb503372010-05-27 20:51:26 +00001558 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001559 {
1560 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001561 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001562 p+=quantum_info->pad;
1563 q++;
1564 }
1565 break;
1566 }
1567 }
1568 default:
1569 {
1570 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001571 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001572 {
1573 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001574 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001575 p+=quantum_info->pad;
1576 q++;
1577 }
1578 break;
1579 }
1580 }
1581 break;
1582 }
1583 case AlphaQuantum:
1584 {
1585 switch (quantum_info->depth)
1586 {
1587 case 8:
1588 {
1589 unsigned char
1590 pixel;
1591
cristybb503372010-05-27 20:51:26 +00001592 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001593 {
1594 p=PushCharPixel(p,&pixel);
1595 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1596 p+=quantum_info->pad;
1597 q++;
1598 }
1599 break;
1600 }
1601 case 16:
1602 {
1603 unsigned short
1604 pixel;
1605
cristyc9672a92010-01-06 00:57:45 +00001606 if (quantum_info->format == FloatingPointQuantumFormat)
1607 {
cristybb503372010-05-27 20:51:26 +00001608 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001609 {
1610 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001611 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00001612 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00001613 p+=quantum_info->pad;
1614 q++;
1615 }
1616 break;
1617 }
cristybb503372010-05-27 20:51:26 +00001618 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001619 {
1620 p=PushShortPixel(endian,p,&pixel);
1621 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1622 p+=quantum_info->pad;
1623 q++;
1624 }
1625 break;
1626 }
1627 case 32:
1628 {
cristy4cb162a2010-05-30 03:04:47 +00001629 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001630 pixel;
1631
1632 if (quantum_info->format == FloatingPointQuantumFormat)
1633 {
1634 float
1635 pixel;
1636
cristybb503372010-05-27 20:51:26 +00001637 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001638 {
1639 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001640 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001641 p+=quantum_info->pad;
1642 q++;
1643 }
1644 break;
1645 }
cristybb503372010-05-27 20:51:26 +00001646 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001647 {
1648 p=PushLongPixel(endian,p,&pixel);
1649 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1650 p+=quantum_info->pad;
1651 q++;
1652 }
1653 break;
1654 }
1655 case 64:
1656 {
1657 if (quantum_info->format == FloatingPointQuantumFormat)
1658 {
1659 double
1660 pixel;
1661
cristybb503372010-05-27 20:51:26 +00001662 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001663 {
1664 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001665 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001666 p+=quantum_info->pad;
1667 q++;
1668 }
1669 break;
1670 }
1671 }
1672 default:
1673 {
1674 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001675 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001676 {
1677 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1678 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1679 p+=quantum_info->pad;
1680 q++;
1681 }
1682 break;
1683 }
1684 }
1685 break;
1686 }
1687 case BlackQuantum:
1688 {
1689 if (image->colorspace != CMYKColorspace)
1690 {
1691 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1692 "ColorSeparatedImageRequired","`%s'",image->filename);
1693 return(extent);
1694 }
1695 switch (quantum_info->depth)
1696 {
1697 case 8:
1698 {
1699 unsigned char
1700 pixel;
1701
cristybb503372010-05-27 20:51:26 +00001702 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001703 {
1704 p=PushCharPixel(p,&pixel);
1705 indexes[x]=ScaleCharToQuantum(pixel);
1706 p+=quantum_info->pad;
1707 }
1708 break;
1709 }
1710 case 16:
1711 {
1712 unsigned short
1713 pixel;
1714
cristyc9672a92010-01-06 00:57:45 +00001715 if (quantum_info->format == FloatingPointQuantumFormat)
1716 {
cristybb503372010-05-27 20:51:26 +00001717 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001718 {
1719 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001720 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001721 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001722 p+=quantum_info->pad;
1723 }
1724 break;
1725 }
cristybb503372010-05-27 20:51:26 +00001726 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001727 {
1728 p=PushShortPixel(endian,p,&pixel);
1729 indexes[x]=ScaleShortToQuantum(pixel);
1730 p+=quantum_info->pad;
1731 }
1732 break;
1733 }
1734 case 32:
1735 {
cristy4cb162a2010-05-30 03:04:47 +00001736 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001737 pixel;
1738
1739 if (quantum_info->format == FloatingPointQuantumFormat)
1740 {
1741 float
1742 pixel;
1743
cristybb503372010-05-27 20:51:26 +00001744 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001745 {
1746 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001747 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001748 p+=quantum_info->pad;
1749 q++;
1750 }
1751 break;
1752 }
cristybb503372010-05-27 20:51:26 +00001753 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001754 {
1755 p=PushLongPixel(endian,p,&pixel);
1756 indexes[x]=ScaleLongToQuantum(pixel);
1757 p+=quantum_info->pad;
1758 q++;
1759 }
1760 break;
1761 }
1762 case 64:
1763 {
1764 if (quantum_info->format == FloatingPointQuantumFormat)
1765 {
1766 double
1767 pixel;
1768
cristybb503372010-05-27 20:51:26 +00001769 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001770 {
1771 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001772 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001773 p+=quantum_info->pad;
1774 q++;
1775 }
1776 break;
1777 }
1778 }
1779 default:
1780 {
1781 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001782 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001783 {
1784 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1785 indexes[x]=ScaleAnyToQuantum(pixel,range);
1786 p+=quantum_info->pad;
1787 q++;
1788 }
1789 break;
1790 }
1791 }
1792 break;
1793 }
1794 case RGBQuantum:
1795 case CbYCrQuantum:
1796 {
1797 switch (quantum_info->depth)
1798 {
1799 case 8:
1800 {
1801 unsigned char
1802 pixel;
1803
cristybb503372010-05-27 20:51:26 +00001804 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001805 {
1806 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001807 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001808 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001809 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001810 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001811 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1812 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001813 p+=quantum_info->pad;
1814 q++;
1815 }
1816 break;
1817 }
1818 case 10:
1819 {
1820 range=GetQuantumRange(image->depth);
1821 if (quantum_info->pack == MagickFalse)
1822 {
cristybb503372010-05-27 20:51:26 +00001823 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001824 {
1825 p=PushLongPixel(endian,p,&pixel);
1826 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1827 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1828 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1829 p+=quantum_info->pad;
1830 q++;
1831 }
1832 break;
1833 }
cristy4cb162a2010-05-30 03:04:47 +00001834 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00001835 {
cristybb503372010-05-27 20:51:26 +00001836 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001837 {
1838 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001839 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001840 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001841 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001842 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001843 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001844 q++;
1845 }
1846 break;
1847 }
cristybb503372010-05-27 20:51:26 +00001848 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001849 {
1850 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001851 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001852 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001853 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001854 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001855 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001856 q++;
1857 }
1858 break;
1859 }
1860 case 12:
1861 {
1862 range=GetQuantumRange(image->depth);
1863 if (quantum_info->pack == MagickFalse)
1864 {
1865 unsigned short
1866 pixel;
1867
cristybb503372010-05-27 20:51:26 +00001868 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001869 {
1870 p=PushShortPixel(endian,p,&pixel);
1871 switch (x % 3)
1872 {
1873 default:
1874 case 0:
1875 {
1876 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1877 break;
1878 }
1879 case 1:
1880 {
1881 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1882 break;
1883 }
1884 case 2:
1885 {
1886 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1887 q++;
1888 break;
1889 }
1890 }
1891 p=PushShortPixel(endian,p,&pixel);
1892 switch ((x+1) % 3)
1893 {
1894 default:
1895 case 0:
1896 {
1897 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1898 break;
1899 }
1900 case 1:
1901 {
1902 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1903 break;
1904 }
1905 case 2:
1906 {
1907 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1908 q++;
1909 break;
1910 }
1911 }
1912 p+=quantum_info->pad;
1913 }
cristybb503372010-05-27 20:51:26 +00001914 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001915 {
1916 p=PushShortPixel(endian,p,&pixel);
1917 switch ((x+bit) % 3)
1918 {
1919 default:
1920 case 0:
1921 {
1922 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1923 break;
1924 }
1925 case 1:
1926 {
1927 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1928 break;
1929 }
1930 case 2:
1931 {
1932 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1933 q++;
1934 break;
1935 }
1936 }
1937 p+=quantum_info->pad;
1938 }
1939 if (bit != 0)
1940 p++;
1941 break;
1942 }
cristy4cb162a2010-05-30 03:04:47 +00001943 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00001944 {
cristybb503372010-05-27 20:51:26 +00001945 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001946 {
1947 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001948 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001949 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001950 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001951 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001952 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001953 q++;
1954 }
1955 break;
1956 }
cristybb503372010-05-27 20:51:26 +00001957 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001958 {
1959 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001960 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001961 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001962 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001963 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001964 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001965 q++;
1966 }
1967 break;
1968 }
1969 case 16:
1970 {
1971 unsigned short
1972 pixel;
1973
cristyc9672a92010-01-06 00:57:45 +00001974 if (quantum_info->format == FloatingPointQuantumFormat)
1975 {
cristybb503372010-05-27 20:51:26 +00001976 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001977 {
1978 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001979 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001980 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001981 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001982 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001983 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001984 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001985 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001986 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001987 p+=quantum_info->pad;
1988 q++;
1989 }
1990 break;
1991 }
cristybb503372010-05-27 20:51:26 +00001992 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001993 {
1994 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001995 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001996 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001997 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001998 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001999 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002000 p+=quantum_info->pad;
2001 q++;
2002 }
2003 break;
2004 }
2005 case 32:
2006 {
cristy4cb162a2010-05-30 03:04:47 +00002007 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002008 pixel;
2009
2010 if (quantum_info->format == FloatingPointQuantumFormat)
2011 {
2012 float
2013 pixel;
2014
cristybb503372010-05-27 20:51:26 +00002015 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002016 {
2017 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002018 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002019 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002020 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002021 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002022 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002023 p+=quantum_info->pad;
2024 q++;
2025 }
2026 break;
2027 }
cristybb503372010-05-27 20:51:26 +00002028 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002029 {
2030 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002031 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002032 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002033 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002034 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002035 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002036 p+=quantum_info->pad;
2037 q++;
2038 }
2039 break;
2040 }
2041 case 64:
2042 {
2043 if (quantum_info->format == FloatingPointQuantumFormat)
2044 {
2045 double
2046 pixel;
2047
cristybb503372010-05-27 20:51:26 +00002048 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002049 {
2050 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002051 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002052 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002053 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002054 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002055 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002056 p+=quantum_info->pad;
2057 q++;
2058 }
2059 break;
2060 }
2061 }
2062 default:
2063 {
2064 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002065 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002066 {
2067 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002068 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002069 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002070 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002071 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002072 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002073 q++;
2074 }
2075 break;
2076 }
2077 }
2078 break;
2079 }
2080 case RGBAQuantum:
2081 case RGBOQuantum:
2082 case CbYCrAQuantum:
2083 {
2084 switch (quantum_info->depth)
2085 {
2086 case 8:
2087 {
2088 unsigned char
2089 pixel;
2090
cristybb503372010-05-27 20:51:26 +00002091 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002092 {
2093 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002094 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002095 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002096 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002097 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002098 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002099 p=PushCharPixel(p,&pixel);
2100 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2101 p+=quantum_info->pad;
2102 q++;
2103 }
2104 break;
2105 }
2106 case 10:
2107 {
2108 pixel=0;
2109 if (quantum_info->pack == MagickFalse)
2110 {
cristybb503372010-05-27 20:51:26 +00002111 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002112 n;
2113
cristybb503372010-05-27 20:51:26 +00002114 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002115 i;
2116
cristybb503372010-05-27 20:51:26 +00002117 size_t
cristy3ed852e2009-09-05 21:47:34 +00002118 quantum;
2119
2120 n=0;
2121 quantum=0;
cristybb503372010-05-27 20:51:26 +00002122 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002123 {
2124 for (i=0; i < 4; i++)
2125 {
2126 switch (n % 3)
2127 {
2128 case 0:
2129 {
2130 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00002131 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002132 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2133 break;
2134 }
2135 case 1:
2136 {
cristybb503372010-05-27 20:51:26 +00002137 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002138 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2139 break;
2140 }
2141 case 2:
2142 {
cristybb503372010-05-27 20:51:26 +00002143 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002144 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2145 break;
2146 }
2147 }
2148 switch (i)
2149 {
2150 case 0: q->red=(Quantum) (quantum); break;
2151 case 1: q->green=(Quantum) (quantum); break;
2152 case 2: q->blue=(Quantum) (quantum); break;
2153 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2154 }
2155 n++;
2156 }
2157 p+=quantum_info->pad;
2158 q++;
2159 }
2160 break;
2161 }
cristybb503372010-05-27 20:51:26 +00002162 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002163 {
2164 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2165 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2166 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2167 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2168 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2169 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2170 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2171 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2172 (unsigned short) (pixel << 6)));
2173 q++;
2174 }
2175 break;
2176 }
2177 case 16:
2178 {
2179 unsigned short
2180 pixel;
2181
cristyc9672a92010-01-06 00:57:45 +00002182 if (quantum_info->format == FloatingPointQuantumFormat)
2183 {
cristybb503372010-05-27 20:51:26 +00002184 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002185 {
2186 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002187 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002188 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002189 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002190 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002191 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002192 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002193 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002194 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002195 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002196 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002197 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002198 p+=quantum_info->pad;
2199 q++;
2200 }
2201 break;
2202 }
cristybb503372010-05-27 20:51:26 +00002203 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002204 {
2205 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002206 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002207 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002208 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002209 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002210 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002211 p=PushShortPixel(endian,p,&pixel);
2212 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2213 p+=quantum_info->pad;
2214 q++;
2215 }
2216 break;
2217 }
2218 case 32:
2219 {
cristy4cb162a2010-05-30 03:04:47 +00002220 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002221 pixel;
2222
2223 if (quantum_info->format == FloatingPointQuantumFormat)
2224 {
2225 float
2226 pixel;
2227
cristybb503372010-05-27 20:51:26 +00002228 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002229 {
2230 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002231 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002232 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002233 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002234 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002235 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002236 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002237 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002238 p+=quantum_info->pad;
2239 q++;
2240 }
2241 break;
2242 }
cristybb503372010-05-27 20:51:26 +00002243 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002244 {
2245 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002246 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002247 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002248 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002249 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002250 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002251 p=PushLongPixel(endian,p,&pixel);
2252 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2253 p+=quantum_info->pad;
2254 q++;
2255 }
2256 break;
2257 }
2258 case 64:
2259 {
2260 if (quantum_info->format == FloatingPointQuantumFormat)
2261 {
2262 double
2263 pixel;
2264
cristybb503372010-05-27 20:51:26 +00002265 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002266 {
2267 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002268 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002269 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002270 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002271 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002272 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002273 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002274 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002275 p+=quantum_info->pad;
2276 q++;
2277 }
2278 break;
2279 }
2280 }
2281 default:
2282 {
2283 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002284 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002285 {
2286 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002287 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002288 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002289 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002290 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002291 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002292 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2293 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2294 q++;
2295 }
2296 break;
2297 }
2298 }
2299 break;
2300 }
2301 case CMYKQuantum:
2302 {
2303 if (image->colorspace != CMYKColorspace)
2304 {
2305 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2306 "ColorSeparatedImageRequired","`%s'",image->filename);
2307 return(extent);
2308 }
2309 switch (quantum_info->depth)
2310 {
2311 case 8:
2312 {
2313 unsigned char
2314 pixel;
2315
cristybb503372010-05-27 20:51:26 +00002316 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002317 {
2318 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002319 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002320 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002321 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002322 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002323 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002324 p=PushCharPixel(p,&pixel);
2325 indexes[x]=ScaleCharToQuantum(pixel);
2326 p+=quantum_info->pad;
2327 q++;
2328 }
2329 break;
2330 }
2331 case 16:
2332 {
2333 unsigned short
2334 pixel;
2335
cristyc9672a92010-01-06 00:57:45 +00002336 if (quantum_info->format == FloatingPointQuantumFormat)
2337 {
cristybb503372010-05-27 20:51:26 +00002338 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002339 {
2340 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002341 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002342 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002343 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002344 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002345 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002346 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002347 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002348 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002349 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002350 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002351 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002352 p+=quantum_info->pad;
2353 q++;
2354 }
2355 break;
2356 }
cristybb503372010-05-27 20:51:26 +00002357 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002358 {
2359 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002360 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002361 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002362 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002363 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002364 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002365 p=PushShortPixel(endian,p,&pixel);
2366 indexes[x]=ScaleShortToQuantum(pixel);
2367 p+=quantum_info->pad;
2368 q++;
2369 }
2370 break;
2371 }
2372 case 32:
2373 {
cristy4cb162a2010-05-30 03:04:47 +00002374 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002375 pixel;
2376
2377 if (quantum_info->format == FloatingPointQuantumFormat)
2378 {
2379 float
2380 pixel;
2381
cristybb503372010-05-27 20:51:26 +00002382 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002383 {
2384 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002385 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002386 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002387 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002388 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002389 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002390 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002391 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002392 p+=quantum_info->pad;
2393 q++;
2394 }
2395 break;
2396 }
cristybb503372010-05-27 20:51:26 +00002397 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002398 {
2399 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002400 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002401 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002402 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002403 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002404 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002405 p=PushLongPixel(endian,p,&pixel);
2406 indexes[x]=ScaleLongToQuantum(pixel);
2407 p+=quantum_info->pad;
2408 q++;
2409 }
2410 break;
2411 }
2412 case 64:
2413 {
2414 if (quantum_info->format == FloatingPointQuantumFormat)
2415 {
2416 double
2417 pixel;
2418
cristybb503372010-05-27 20:51:26 +00002419 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002420 {
2421 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002422 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002423 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002424 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002425 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002426 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002427 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002428 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002429 p+=quantum_info->pad;
2430 q++;
2431 }
2432 break;
2433 }
2434 }
2435 default:
2436 {
2437 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002438 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002439 {
2440 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002441 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002442 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002443 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002444 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002445 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002446 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2447 indexes[x]=ScaleAnyToQuantum(pixel,range);
2448 q++;
2449 }
2450 break;
2451 }
2452 }
2453 break;
2454 }
2455 case CMYKAQuantum:
2456 case CMYKOQuantum:
2457 {
2458 if (image->colorspace != CMYKColorspace)
2459 {
2460 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2461 "ColorSeparatedImageRequired","`%s'",image->filename);
2462 return(extent);
2463 }
2464 switch (quantum_info->depth)
2465 {
2466 case 8:
2467 {
2468 unsigned char
2469 pixel;
2470
cristybb503372010-05-27 20:51:26 +00002471 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002472 {
2473 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002474 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002475 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002476 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002477 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002478 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002479 p=PushCharPixel(p,&pixel);
2480 indexes[x]=ScaleCharToQuantum(pixel);
2481 p=PushCharPixel(p,&pixel);
2482 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2483 p+=quantum_info->pad;
2484 q++;
2485 }
2486 break;
2487 }
2488 case 16:
2489 {
2490 unsigned short
2491 pixel;
2492
cristyc9672a92010-01-06 00:57:45 +00002493 if (quantum_info->format == FloatingPointQuantumFormat)
2494 {
cristybb503372010-05-27 20:51:26 +00002495 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002496 {
2497 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002498 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002499 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002500 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002501 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002502 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002503 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002504 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002505 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002506 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002507 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002508 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002509 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002510 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002511 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002512 p+=quantum_info->pad;
2513 q++;
2514 }
2515 break;
2516 }
cristybb503372010-05-27 20:51:26 +00002517 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002518 {
2519 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002520 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002521 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002522 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002523 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002524 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002525 p=PushShortPixel(endian,p,&pixel);
2526 indexes[x]=ScaleShortToQuantum(pixel);
2527 p=PushShortPixel(endian,p,&pixel);
2528 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2529 p+=quantum_info->pad;
2530 q++;
2531 }
2532 break;
2533 }
2534 case 32:
2535 {
cristy4cb162a2010-05-30 03:04:47 +00002536 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002537 pixel;
2538
2539 if (quantum_info->format == FloatingPointQuantumFormat)
2540 {
2541 float
2542 pixel;
2543
cristybb503372010-05-27 20:51:26 +00002544 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002545 {
2546 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002547 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002548 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002549 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002550 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002551 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002552 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002553 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002554 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002555 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002556 p+=quantum_info->pad;
2557 q++;
2558 }
2559 break;
2560 }
cristybb503372010-05-27 20:51:26 +00002561 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002562 {
2563 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002564 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002565 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002566 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002567 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002568 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002569 p=PushLongPixel(endian,p,&pixel);
2570 indexes[x]=ScaleLongToQuantum(pixel);
2571 p=PushLongPixel(endian,p,&pixel);
2572 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2573 p+=quantum_info->pad;
2574 q++;
2575 }
2576 break;
2577 }
2578 case 64:
2579 {
2580 if (quantum_info->format == FloatingPointQuantumFormat)
2581 {
2582 double
2583 pixel;
2584
cristybb503372010-05-27 20:51:26 +00002585 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002586 {
2587 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002588 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002589 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002590 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002591 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002592 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002593 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002594 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002595 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002596 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002597 p=PushDoublePixel(&quantum_state,p,&pixel);
2598 p+=quantum_info->pad;
2599 q++;
2600 }
2601 break;
2602 }
2603 }
2604 default:
2605 {
2606 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002607 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002608 {
2609 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002610 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002611 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002612 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002613 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002614 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002615 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2616 indexes[x]=ScaleAnyToQuantum(pixel,range);
2617 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2618 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2619 q++;
2620 }
2621 break;
2622 }
2623 }
2624 break;
2625 }
2626 case CbYCrYQuantum:
2627 {
2628 switch (quantum_info->depth)
2629 {
2630 case 10:
2631 {
2632 Quantum
2633 cbcr[4];
2634
2635 pixel=0;
2636 if (quantum_info->pack == MagickFalse)
2637 {
cristybb503372010-05-27 20:51:26 +00002638 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002639 n;
2640
cristybb503372010-05-27 20:51:26 +00002641 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002642 i;
2643
cristybb503372010-05-27 20:51:26 +00002644 size_t
cristy3ed852e2009-09-05 21:47:34 +00002645 quantum;
2646
2647 n=0;
2648 quantum=0;
cristybb503372010-05-27 20:51:26 +00002649 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002650 {
2651 for (i=0; i < 4; i++)
2652 {
2653 switch (n % 3)
2654 {
2655 case 0:
2656 {
2657 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00002658 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002659 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2660 break;
2661 }
2662 case 1:
2663 {
cristybb503372010-05-27 20:51:26 +00002664 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002665 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2666 break;
2667 }
2668 case 2:
2669 {
cristybb503372010-05-27 20:51:26 +00002670 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002671 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2672 break;
2673 }
2674 }
2675 cbcr[i]=(Quantum) (quantum);
2676 n++;
2677 }
2678 p+=quantum_info->pad;
2679 q->red=cbcr[1];
2680 q->green=cbcr[0];
2681 q->blue=cbcr[2];
2682 q++;
2683 q->red=cbcr[3];
2684 q->green=cbcr[0];
2685 q->blue=cbcr[2];
2686 q++;
2687 }
2688 break;
2689 }
2690 }
2691 default:
2692 {
2693 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002694 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002695 {
2696 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002697 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002698 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002699 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002700 q++;
2701 }
2702 break;
2703 }
2704 }
2705 break;
2706 }
2707 default:
2708 break;
2709 }
2710 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2711 {
2712 Quantum
2713 quantum;
2714
2715 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002716 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002717
2718 q=GetAuthenticPixelQueue(image);
2719 if (image_view != (CacheView *) NULL)
2720 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002721 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002722 {
2723 quantum=q->red;
2724 q->red=q->green;
2725 q->green=quantum;
2726 q++;
2727 }
2728 }
2729 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2730 {
2731 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002732 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002733
2734 q=GetAuthenticPixelQueue(image);
2735 if (image_view != (CacheView *) NULL)
2736 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002737 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002738 {
cristy46f08202010-01-10 04:04:21 +00002739 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00002740 q++;
2741 }
2742 }
2743 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2744 {
2745 MagickRealType
2746 alpha;
2747
2748 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002749 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002750
2751 /*
2752 Disassociate alpha.
2753 */
2754 q=GetAuthenticPixelQueue(image);
2755 if (image_view != (CacheView *) NULL)
2756 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002757 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002758 {
2759 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2760 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
cristyce70c172010-01-07 17:15:30 +00002761 q->red=ClampToQuantum(alpha*q->red);
2762 q->green=ClampToQuantum(alpha*q->green);
2763 q->blue=ClampToQuantum(alpha*q->blue);
cristy3ed852e2009-09-05 21:47:34 +00002764 q++;
2765 }
2766 }
2767 return(extent);
2768}