blob: fce4090da9cc24b8a138e91e6b7d86b265ff83f8 [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% EEEEE X X PPPP OOO RRRR TTTTT %
13% E X X P P O O R R T %
14% EEE X PPPP O O RRRR T %
15% E X X P O O R R T %
16% EEEEE X X P OOO R R T %
17% %
18% MagickCore Methods to Export 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+ E x p o r t Q u a n t u m P i x e l s %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
85% ExportQuantumPixels() transfers one or more pixel components from the image
86% pixel cache to a user supplied buffer. The pixels are returned in network
87% byte order. MagickTrue is returned if the pixels are successfully
88% transferred, otherwise MagickFalse.
89%
90% The format of the ExportQuantumPixels method is:
91%
cristy891dc792010-03-04 01:47:16 +000092% size_t ExportQuantumPixels(const Image *image,
93% const CacheView *image_view,const QuantumInfo *quantum_info,
94% const QuantumType quantum_type,unsigned char *pixels,
95% ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +000096%
97% A description of each parameter follows:
98%
99% o image: the image.
100%
101% o image_view: the image cache view.
102%
103% o quantum_info: the quantum info.
104%
105% o quantum_type: Declare which pixel components to transfer (RGB, RGBA,
106% etc).
107%
108% o pixels: The components are transferred to this buffer.
109%
110% o exception: return any errors or warnings in this structure.
111%
112*/
113
114static inline unsigned char *PopDoublePixel(const QuantumState *quantum_state,
115 const double pixel,unsigned char *pixels)
116{
117 double
118 *p;
119
120 unsigned char
121 quantum[8];
122
123 p=(double *) quantum;
cristy82b15832009-10-06 19:17:37 +0000124 *p=(double) (pixel*quantum_state->inverse_scale+quantum_state->minimum);
cristy3ed852e2009-09-05 21:47:34 +0000125 if (quantum_state->endian != LSBEndian)
126 {
127 *pixels++=quantum[7];
128 *pixels++=quantum[6];
129 *pixels++=quantum[5];
130 *pixels++=quantum[4];
131 *pixels++=quantum[3];
132 *pixels++=quantum[2];
133 *pixels++=quantum[1];
134 *pixels++=quantum[0];
135 return(pixels);
136 }
137 *pixels++=quantum[0];
138 *pixels++=quantum[1];
139 *pixels++=quantum[2];
140 *pixels++=quantum[3];
141 *pixels++=quantum[4];
142 *pixels++=quantum[5];
143 *pixels++=quantum[6];
144 *pixels++=quantum[7];
145 return(pixels);
146}
147
148static inline unsigned char *PopFloatPixel(const QuantumState *quantum_state,
149 const float pixel,unsigned char *pixels)
150{
151 float
152 *p;
153
154 unsigned char
155 quantum[4];
156
157 p=(float *) quantum;
158 *p=(float) ((double) pixel*quantum_state->inverse_scale+
cristy82b15832009-10-06 19:17:37 +0000159 quantum_state->minimum);
cristy3ed852e2009-09-05 21:47:34 +0000160 if (quantum_state->endian != LSBEndian)
161 {
162 *pixels++=quantum[3];
163 *pixels++=quantum[2];
164 *pixels++=quantum[1];
165 *pixels++=quantum[0];
166 return(pixels);
167 }
168 *pixels++=quantum[0];
169 *pixels++=quantum[1];
170 *pixels++=quantum[2];
171 *pixels++=quantum[3];
172 return(pixels);
173}
174
175static inline unsigned char *PopQuantumPixel(QuantumState *quantum_state,
cristybb503372010-05-27 20:51:26 +0000176 const size_t depth,const QuantumAny pixel,unsigned char *pixels)
cristy3ed852e2009-09-05 21:47:34 +0000177{
cristybb503372010-05-27 20:51:26 +0000178 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000179 i;
180
cristy6b825f92010-06-04 02:01:10 +0000181 size_t
cristy3ed852e2009-09-05 21:47:34 +0000182 quantum_bits;
183
184 if (quantum_state->bits == 0UL)
cristy4cb162a2010-05-30 03:04:47 +0000185 quantum_state->bits=8U;
cristybb503372010-05-27 20:51:26 +0000186 for (i=(ssize_t) depth; i > 0L; )
cristy3ed852e2009-09-05 21:47:34 +0000187 {
cristy6b825f92010-06-04 02:01:10 +0000188 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000189 if (quantum_bits > quantum_state->bits)
190 quantum_bits=quantum_state->bits;
cristyebdf07a2010-06-04 14:48:53 +0000191 i-=(ssize_t) quantum_bits;
cristy6b825f92010-06-04 02:01:10 +0000192 if (quantum_state->bits == 8UL)
cristy3ed852e2009-09-05 21:47:34 +0000193 *pixels='\0';
194 quantum_state->bits-=quantum_bits;
cristy6b825f92010-06-04 02:01:10 +0000195 *pixels|=(((pixel >> i) &~ ((~0UL) << quantum_bits)) <<
cristy3ed852e2009-09-05 21:47:34 +0000196 quantum_state->bits);
197 if (quantum_state->bits == 0UL)
198 {
199 pixels++;
cristy6b825f92010-06-04 02:01:10 +0000200 quantum_state->bits=8UL;
cristy3ed852e2009-09-05 21:47:34 +0000201 }
202 }
203 return(pixels);
204}
205
206static inline unsigned char *PopQuantumLongPixel(QuantumState *quantum_state,
cristybb503372010-05-27 20:51:26 +0000207 const size_t depth,const size_t pixel,unsigned char *pixels)
cristy3ed852e2009-09-05 21:47:34 +0000208{
cristybb503372010-05-27 20:51:26 +0000209 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000210 i;
211
cristy6b825f92010-06-04 02:01:10 +0000212 size_t
cristy3ed852e2009-09-05 21:47:34 +0000213 quantum_bits;
214
cristy4cb162a2010-05-30 03:04:47 +0000215 if (quantum_state->bits == 0U)
cristy6b825f92010-06-04 02:01:10 +0000216 quantum_state->bits=32UL;
cristybb503372010-05-27 20:51:26 +0000217 for (i=(ssize_t) depth; i > 0; )
cristy3ed852e2009-09-05 21:47:34 +0000218 {
cristybb503372010-05-27 20:51:26 +0000219 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000220 if (quantum_bits > quantum_state->bits)
221 quantum_bits=quantum_state->bits;
222 quantum_state->pixel|=(((pixel >> (depth-i)) &
cristy4cb162a2010-05-30 03:04:47 +0000223 quantum_state->mask[quantum_bits]) << (32U-quantum_state->bits));
cristyeaedf062010-05-29 22:36:02 +0000224 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000225 quantum_state->bits-=quantum_bits;
226 if (quantum_state->bits == 0U)
227 {
228 pixels=PopLongPixel(quantum_state->endian,quantum_state->pixel,pixels);
229 quantum_state->pixel=0U;
cristy4cb162a2010-05-30 03:04:47 +0000230 quantum_state->bits=32U;
cristy3ed852e2009-09-05 21:47:34 +0000231 }
232 }
233 return(pixels);
234}
235
236MagickExport size_t ExportQuantumPixels(const Image *image,
237 const CacheView *image_view,const QuantumInfo *quantum_info,
238 const QuantumType quantum_type,unsigned char *pixels,ExceptionInfo *exception)
239{
240 EndianType
241 endian;
242
cristy3ed852e2009-09-05 21:47:34 +0000243 MagickRealType
244 alpha;
245
246 MagickSizeType
247 number_pixels;
248
249 QuantumAny
250 range;
251
252 QuantumState
253 quantum_state;
254
255 register const IndexPacket
cristyaebafa22009-11-26 01:48:56 +0000256 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000257
258 register const PixelPacket
cristyaebafa22009-11-26 01:48:56 +0000259 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000260
cristybb503372010-05-27 20:51:26 +0000261 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000262 x;
263
264 register unsigned char
cristyaebafa22009-11-26 01:48:56 +0000265 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000266
267 size_t
268 extent;
269
cristy9d314ff2011-03-09 01:30:28 +0000270 ssize_t
271 bit;
272
cristy3ed852e2009-09-05 21:47:34 +0000273 assert(image != (Image *) NULL);
274 assert(image->signature == MagickSignature);
275 if (image->debug != MagickFalse)
276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
277 assert(quantum_info != (QuantumInfo *) NULL);
278 assert(quantum_info->signature == MagickSignature);
279 if (pixels == (unsigned char *) NULL)
280 pixels=GetQuantumPixels(quantum_info);
cristy8a7ea362010-03-10 20:31:43 +0000281 if (image_view == (CacheView *) NULL)
282 {
283 number_pixels=GetImageExtent(image);
284 p=GetVirtualPixelQueue(image);
285 indexes=GetVirtualIndexQueue(image);
286 }
287 else
cristy3ed852e2009-09-05 21:47:34 +0000288 {
289 number_pixels=GetCacheViewExtent(image_view);
290 p=GetCacheViewVirtualPixelQueue(image_view);
291 indexes=GetCacheViewVirtualIndexQueue(image_view);
292 }
293 if (quantum_info->alpha_type == AssociatedQuantumAlpha)
294 {
295 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000296 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000297
298 /*
299 Associate alpha.
300 */
301 q=GetAuthenticPixelQueue(image);
302 if (image_view != (CacheView *) NULL)
303 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +0000304 for (x=0; x < (ssize_t) image->columns; x++)
cristy3ed852e2009-09-05 21:47:34 +0000305 {
306 alpha=QuantumScale*((double) QuantumRange-q->opacity);
cristye85007d2010-06-06 22:51:36 +0000307 q->red=ClampToQuantum(alpha*q->red);
308 q->green=ClampToQuantum(alpha*q->green);
309 q->blue=ClampToQuantum(alpha*q->blue);
cristy3ed852e2009-09-05 21:47:34 +0000310 q++;
311 }
312 }
cristya6a96a12010-08-23 13:37:35 +0000313 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
314 (quantum_type == BGROQuantum))
cristy3ed852e2009-09-05 21:47:34 +0000315 {
316 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000317 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000318
319 q=GetAuthenticPixelQueue(image);
320 if (image_view != (CacheView *) NULL)
321 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +0000322 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000323 {
cristy46f08202010-01-10 04:04:21 +0000324 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +0000325 q++;
326 }
327 }
328 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
329 {
330 Quantum
331 quantum;
332
333 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000334 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000335
336 q=GetAuthenticPixelQueue(image);
337 if (image_view != (CacheView *) NULL)
338 q=GetAuthenticPixelQueue(image);
cristybb503372010-05-27 20:51:26 +0000339 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000340 {
341 quantum=q->red;
342 q->red=q->green;
343 q->green=quantum;
344 q++;
345 }
346 }
347 x=0;
348 q=pixels;
349 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
350 extent=GetQuantumExtent(image,quantum_info,quantum_type);
351 endian=quantum_state.endian;
352 switch (quantum_type)
353 {
354 case IndexQuantum:
355 {
356 if (image->storage_class != PseudoClass)
357 {
358 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
359 "ColormappedImageRequired","`%s'",image->filename);
360 return(extent);
361 }
362 switch (quantum_info->depth)
363 {
364 case 1:
365 {
366 register unsigned char
367 pixel;
368
cristybb503372010-05-27 20:51:26 +0000369 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
cristy3ed852e2009-09-05 21:47:34 +0000370 {
371 pixel=(unsigned char) *indexes++;
372 *q=((pixel & 0x01) << 7);
373 pixel=(unsigned char) *indexes++;
374 *q|=((pixel & 0x01) << 6);
375 pixel=(unsigned char) *indexes++;
376 *q|=((pixel & 0x01) << 5);
377 pixel=(unsigned char) *indexes++;
378 *q|=((pixel & 0x01) << 4);
379 pixel=(unsigned char) *indexes++;
380 *q|=((pixel & 0x01) << 3);
381 pixel=(unsigned char) *indexes++;
382 *q|=((pixel & 0x01) << 2);
383 pixel=(unsigned char) *indexes++;
384 *q|=((pixel & 0x01) << 1);
385 pixel=(unsigned char) *indexes++;
386 *q|=((pixel & 0x01) << 0);
387 q++;
388 }
389 if ((number_pixels % 8) != 0)
390 {
391 *q='\0';
cristybb503372010-05-27 20:51:26 +0000392 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
cristy3ed852e2009-09-05 21:47:34 +0000393 {
394 pixel=(unsigned char) *indexes++;
395 *q|=((pixel & 0x01) << (unsigned char) bit);
396 }
397 q++;
398 }
399 break;
400 }
401 case 4:
402 {
403 register unsigned char
404 pixel;
405
cristybb503372010-05-27 20:51:26 +0000406 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000407 {
408 pixel=(unsigned char) *indexes++;
409 *q=((pixel & 0xf) << 4);
410 pixel=(unsigned char) *indexes++;
411 *q|=((pixel & 0xf) << 0);
412 q++;
413 }
414 if ((number_pixels % 2) != 0)
415 {
416 pixel=(unsigned char) *indexes++;
417 *q=((pixel & 0xf) << 4);
418 q++;
419 }
420 break;
421 }
422 case 8:
423 {
cristybb503372010-05-27 20:51:26 +0000424 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000425 {
426 q=PopCharPixel((unsigned char) indexes[x],q);
427 q+=quantum_info->pad;
428 }
429 break;
430 }
431 case 16:
432 {
cristyc9672a92010-01-06 00:57:45 +0000433 if (quantum_info->format == FloatingPointQuantumFormat)
434 {
cristybb503372010-05-27 20:51:26 +0000435 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000436 {
cristy2a4d01c2010-01-10 21:14:51 +0000437 q=PopShortPixel(endian,SinglePrecisionToHalf(QuantumScale*
cristyc9672a92010-01-06 00:57:45 +0000438 indexes[x]),q);
439 q+=quantum_info->pad;
440 }
441 break;
442 }
cristybb503372010-05-27 20:51:26 +0000443 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000444 {
445 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
446 q+=quantum_info->pad;
447 }
448 break;
449 }
450 case 32:
451 {
452 if (quantum_info->format == FloatingPointQuantumFormat)
453 {
cristybb503372010-05-27 20:51:26 +0000454 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000455 {
456 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
457 p++;
458 q+=quantum_info->pad;
459 }
460 break;
461 }
cristybb503372010-05-27 20:51:26 +0000462 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000463 {
cristy4cb162a2010-05-30 03:04:47 +0000464 q=PopLongPixel(endian,(unsigned int) indexes[x],q);
cristy3ed852e2009-09-05 21:47:34 +0000465 q+=quantum_info->pad;
466 }
467 break;
468 }
469 case 64:
470 {
471 if (quantum_info->format == FloatingPointQuantumFormat)
472 {
cristybb503372010-05-27 20:51:26 +0000473 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000474 {
475 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
476 p++;
477 q+=quantum_info->pad;
478 }
479 break;
480 }
481 }
482 default:
483 {
cristybb503372010-05-27 20:51:26 +0000484 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000485 {
cristy02422272011-03-16 01:08:49 +0000486 q=PopQuantumPixel(&quantum_state,quantum_info->depth,indexes[x],q);
cristy3ed852e2009-09-05 21:47:34 +0000487 p++;
488 q+=quantum_info->pad;
489 }
490 break;
491 }
492 }
493 break;
494 }
495 case IndexAlphaQuantum:
496 {
497 if (image->storage_class != PseudoClass)
498 {
499 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
500 "ColormappedImageRequired","`%s'",image->filename);
501 return(extent);
502 }
503 switch (quantum_info->depth)
504 {
505 case 1:
506 {
507 register unsigned char
508 pixel;
509
cristybb503372010-05-27 20:51:26 +0000510 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
cristy3ed852e2009-09-05 21:47:34 +0000511 {
512 pixel=(unsigned char) *indexes++;
513 *q=((pixel & 0x01) << 7);
514 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
515 1 : 0);
516 *q|=((pixel & 0x01) << 6);
517 p++;
518 pixel=(unsigned char) *indexes++;
519 *q|=((pixel & 0x01) << 5);
520 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
521 1 : 0);
522 *q|=((pixel & 0x01) << 4);
523 p++;
524 pixel=(unsigned char) *indexes++;
525 *q|=((pixel & 0x01) << 3);
526 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
527 1 : 0);
528 *q|=((pixel & 0x01) << 2);
529 p++;
530 pixel=(unsigned char) *indexes++;
531 *q|=((pixel & 0x01) << 1);
532 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
533 1 : 0);
534 *q|=((pixel & 0x01) << 0);
535 p++;
536 q++;
537 }
538 if ((number_pixels % 4) != 0)
539 {
540 *q='\0';
cristybb503372010-05-27 20:51:26 +0000541 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
cristy3ed852e2009-09-05 21:47:34 +0000542 {
543 pixel=(unsigned char) *indexes++;
cristyb32b90a2009-09-07 21:45:48 +0000544 *q|=((pixel & 0x01) << (unsigned char) (bit+4));
cristy3ed852e2009-09-05 21:47:34 +0000545 pixel=(unsigned char) (p->opacity == (Quantum)
546 TransparentOpacity ? 1 : 0);
cristyb32b90a2009-09-07 21:45:48 +0000547 *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
cristy3ed852e2009-09-05 21:47:34 +0000548 p++;
549 }
550 q++;
551 }
552 break;
553 }
554 case 4:
555 {
556 register unsigned char
557 pixel;
558
cristybb503372010-05-27 20:51:26 +0000559 for (x=0; x < (ssize_t) number_pixels ; x++)
cristy3ed852e2009-09-05 21:47:34 +0000560 {
561 pixel=(unsigned char) *indexes++;
562 *q=((pixel & 0xf) << 4);
563 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +0000564 GetOpacityPixelComponent(p)))+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000565 *q|=((pixel & 0xf) << 0);
566 p++;
567 q++;
568 }
569 break;
570 }
571 case 8:
572 {
573 register unsigned char
574 pixel;
575
cristybb503372010-05-27 20:51:26 +0000576 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000577 {
578 q=PopCharPixel((unsigned char) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000579 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
580 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000581 q=PopCharPixel(pixel,q);
582 p++;
583 q+=quantum_info->pad;
584 }
585 break;
586 }
587 case 16:
588 {
589 register unsigned short
590 pixel;
591
cristyc9672a92010-01-06 00:57:45 +0000592 if (quantum_info->format == FloatingPointQuantumFormat)
593 {
cristybb503372010-05-27 20:51:26 +0000594 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000595 {
596 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
cristy2a4d01c2010-01-10 21:14:51 +0000597 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +0000598 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +0000599 q=PopShortPixel(endian,pixel,q);
600 p++;
601 q+=quantum_info->pad;
602 }
603 break;
604 }
cristybb503372010-05-27 20:51:26 +0000605 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000606 {
607 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000608 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
609 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000610 q=PopShortPixel(endian,pixel,q);
611 p++;
612 q+=quantum_info->pad;
613 }
614 break;
615 }
616 case 32:
617 {
cristy4cb162a2010-05-30 03:04:47 +0000618 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000619 pixel;
620
621 if (quantum_info->format == FloatingPointQuantumFormat)
622 {
cristybb503372010-05-27 20:51:26 +0000623 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000624 {
625 float
626 pixel;
627
628 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +0000629 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000630 q=PopFloatPixel(&quantum_state,pixel,q);
631 p++;
632 q+=quantum_info->pad;
633 }
634 break;
635 }
cristybb503372010-05-27 20:51:26 +0000636 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000637 {
cristy4cb162a2010-05-30 03:04:47 +0000638 q=PopLongPixel(endian,(unsigned int) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000639 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
640 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000641 q=PopLongPixel(endian,pixel,q);
642 p++;
643 q+=quantum_info->pad;
644 }
645 break;
646 }
647 case 64:
648 {
649 if (quantum_info->format == FloatingPointQuantumFormat)
650 {
cristybb503372010-05-27 20:51:26 +0000651 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000652 {
653 double
654 pixel;
655
656 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +0000657 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000658 q=PopDoublePixel(&quantum_state,pixel,q);
659 p++;
660 q+=quantum_info->pad;
661 }
662 break;
663 }
664 }
665 default:
666 {
cristy02422272011-03-16 01:08:49 +0000667 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +0000668 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000669 {
cristy02422272011-03-16 01:08:49 +0000670 q=PopQuantumPixel(&quantum_state,quantum_info->depth,indexes[x],q);
671 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
672 ScaleQuantumToAny((Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +0000673 p++;
674 q+=quantum_info->pad;
675 }
676 break;
677 }
678 }
679 break;
680 }
cristya6a96a12010-08-23 13:37:35 +0000681 case BGRQuantum:
682 {
683 switch (quantum_info->depth)
684 {
685 case 8:
686 {
687 for (x=0; x < (ssize_t) number_pixels; x++)
688 {
689 q=PopCharPixel(ScaleQuantumToChar(GetBluePixelComponent(p)),q);
690 q=PopCharPixel(ScaleQuantumToChar(GetGreenPixelComponent(p)),q);
691 q=PopCharPixel(ScaleQuantumToChar(GetRedPixelComponent(p)),q);
692 p++;
693 q+=quantum_info->pad;
694 }
695 break;
696 }
697 case 10:
698 {
699 register unsigned int
700 pixel;
701
cristy02422272011-03-16 01:08:49 +0000702 range=GetQuantumRange(quantum_info->depth);
cristya6a96a12010-08-23 13:37:35 +0000703 if (quantum_info->pack == MagickFalse)
704 {
705 for (x=0; x < (ssize_t) number_pixels; x++)
706 {
707 pixel=(unsigned int) (ScaleQuantumToAny(p->red,range) << 22 |
708 ScaleQuantumToAny(p->green,range) << 12 |
709 ScaleQuantumToAny(p->blue,range) << 2);
710 q=PopLongPixel(endian,pixel,q);
711 p++;
712 q+=quantum_info->pad;
713 }
714 break;
715 }
716 if (quantum_info->quantum == 32UL)
717 {
718 for (x=0; x < (ssize_t) number_pixels; x++)
719 {
720 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +0000721 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
722 q);
cristya6a96a12010-08-23 13:37:35 +0000723 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +0000724 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
725 q);
cristya6a96a12010-08-23 13:37:35 +0000726 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +0000727 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
728 q);
cristya6a96a12010-08-23 13:37:35 +0000729 p++;
730 q+=quantum_info->pad;
731 }
732 break;
733 }
734 for (x=0; x < (ssize_t) number_pixels; x++)
735 {
736 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +0000737 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000738 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +0000739 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000740 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +0000741 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000742 p++;
743 q+=quantum_info->pad;
744 }
745 break;
746 }
747 case 12:
748 {
749 register unsigned int
750 pixel;
751
cristy02422272011-03-16 01:08:49 +0000752 range=GetQuantumRange(quantum_info->depth);
cristya6a96a12010-08-23 13:37:35 +0000753 if (quantum_info->pack == MagickFalse)
754 {
755 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
756 {
757 switch (x % 3)
758 {
759 default:
760 case 0:
761 {
762 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
763 break;
764 }
765 case 1:
766 {
767 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
768 break;
769 }
770 case 2:
771 {
772 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
773 p++;
774 break;
775 }
776 }
777 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
778 switch ((x+1) % 3)
779 {
780 default:
781 case 0:
782 {
783 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
784 break;
785 }
786 case 1:
787 {
788 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
789 break;
790 }
791 case 2:
792 {
793 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
794 p++;
795 break;
796 }
797 }
798 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
799 q+=quantum_info->pad;
800 }
801 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
802 {
803 switch ((x+bit) % 3)
804 {
805 default:
806 case 0:
807 {
808 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
809 break;
810 }
811 case 1:
812 {
813 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
814 break;
815 }
816 case 2:
817 {
818 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
819 p++;
820 break;
821 }
822 }
823 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
824 q+=quantum_info->pad;
825 }
826 if (bit != 0)
827 p++;
828 break;
829 }
830 if (quantum_info->quantum == 32UL)
831 {
832 for (x=0; x < (ssize_t) number_pixels; x++)
833 {
834 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +0000835 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
836 q);
cristya6a96a12010-08-23 13:37:35 +0000837 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +0000838 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
839 q);
cristya6a96a12010-08-23 13:37:35 +0000840 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +0000841 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
842 q);
cristya6a96a12010-08-23 13:37:35 +0000843 p++;
844 q+=quantum_info->pad;
845 }
846 break;
847 }
848 for (x=0; x < (ssize_t) number_pixels; x++)
849 {
850 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +0000851 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000852 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +0000853 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000854 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +0000855 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +0000856 p++;
857 q+=quantum_info->pad;
858 }
859 break;
860 }
861 case 16:
862 {
863 register unsigned short
864 pixel;
865
866 if (quantum_info->format == FloatingPointQuantumFormat)
867 {
868 for (x=0; x < (ssize_t) number_pixels; x++)
869 {
870 pixel=SinglePrecisionToHalf(QuantumScale*
871 GetBluePixelComponent(p));
872 q=PopShortPixel(endian,pixel,q);
873 pixel=SinglePrecisionToHalf(QuantumScale*
874 GetGreenPixelComponent(p));
875 q=PopShortPixel(endian,pixel,q);
876 pixel=SinglePrecisionToHalf(QuantumScale*
877 GetRedPixelComponent(p));
878 q=PopShortPixel(endian,pixel,q);
879 p++;
880 q+=quantum_info->pad;
881 }
882 break;
883 }
884 for (x=0; x < (ssize_t) number_pixels; x++)
885 {
886 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
887 q=PopShortPixel(endian,pixel,q);
888 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
889 q=PopShortPixel(endian,pixel,q);
890 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
891 q=PopShortPixel(endian,pixel,q);
892 p++;
893 q+=quantum_info->pad;
894 }
895 break;
896 }
897 case 32:
898 {
899 register unsigned int
900 pixel;
901
902 if (quantum_info->format == FloatingPointQuantumFormat)
903 {
904 for (x=0; x < (ssize_t) number_pixels; x++)
905 {
906 q=PopFloatPixel(&quantum_state,(float) p->red,q);
907 q=PopFloatPixel(&quantum_state,(float) p->green,q);
908 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
909 p++;
910 q+=quantum_info->pad;
911 }
912 break;
913 }
914 for (x=0; x < (ssize_t) number_pixels; x++)
915 {
916 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
917 q=PopLongPixel(endian,pixel,q);
918 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
919 q=PopLongPixel(endian,pixel,q);
920 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
921 q=PopLongPixel(endian,pixel,q);
922 p++;
923 q+=quantum_info->pad;
924 }
925 break;
926 }
927 case 64:
928 {
929 if (quantum_info->format == FloatingPointQuantumFormat)
930 {
931 for (x=0; x < (ssize_t) number_pixels; x++)
932 {
933 q=PopDoublePixel(&quantum_state,(double) p->red,q);
934 q=PopDoublePixel(&quantum_state,(double) p->green,q);
935 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
936 p++;
937 q+=quantum_info->pad;
938 }
939 break;
940 }
941 }
942 default:
943 {
cristy02422272011-03-16 01:08:49 +0000944 range=GetQuantumRange(quantum_info->depth);
cristya6a96a12010-08-23 13:37:35 +0000945 for (x=0; x < (ssize_t) number_pixels; x++)
946 {
cristy02422272011-03-16 01:08:49 +0000947 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
948 ScaleQuantumToAny(p->red,range),q);
949 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
950 ScaleQuantumToAny(p->green,range),q);
951 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
952 ScaleQuantumToAny(p->blue,range),q);
cristya6a96a12010-08-23 13:37:35 +0000953 p++;
954 q+=quantum_info->pad;
955 }
956 break;
957 }
958 }
959 break;
960 }
961 case BGRAQuantum:
962 case BGROQuantum:
963 {
964 switch (quantum_info->depth)
965 {
966 case 8:
967 {
968 register unsigned char
969 pixel;
970
971 for (x=0; x < (ssize_t) number_pixels; x++)
972 {
973 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
974 q=PopCharPixel(pixel,q);
975 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
976 q=PopCharPixel(pixel,q);
977 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
978 q=PopCharPixel(pixel,q);
979 pixel=ScaleQuantumToChar((Quantum) GetAlphaPixelComponent(p));
980 q=PopCharPixel(pixel,q);
981 p++;
982 q+=quantum_info->pad;
983 }
984 break;
985 }
986 case 10:
987 {
988 register unsigned int
989 pixel;
990
cristy02422272011-03-16 01:08:49 +0000991 range=GetQuantumRange(quantum_info->depth);
cristya6a96a12010-08-23 13:37:35 +0000992 if (quantum_info->pack == MagickFalse)
993 {
cristya6a96a12010-08-23 13:37:35 +0000994 register ssize_t
995 i;
996
997 size_t
998 quantum;
999
cristy9d314ff2011-03-09 01:30:28 +00001000 ssize_t
1001 n;
1002
cristya6a96a12010-08-23 13:37:35 +00001003 n=0;
1004 quantum=0;
1005 pixel=0;
1006 for (x=0; x < (ssize_t) number_pixels; x++)
1007 {
1008 for (i=0; i < 4; i++)
1009 {
1010 switch (i)
1011 {
1012 case 0: quantum=p->red; break;
1013 case 1: quantum=p->green; break;
1014 case 2: quantum=p->blue; break;
1015 case 3: quantum=(Quantum) (QuantumRange-p->opacity); break;
1016 }
1017 switch (n % 3)
1018 {
1019 case 0:
1020 {
1021 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1022 range) << 22);
1023 break;
1024 }
1025 case 1:
1026 {
1027 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1028 range) << 12);
1029 break;
1030 }
1031 case 2:
1032 {
1033 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1034 range) << 2);
1035 q=PopLongPixel(endian,pixel,q);
1036 pixel=0;
1037 break;
1038 }
1039 }
1040 n++;
1041 }
1042 p++;
1043 q+=quantum_info->pad;
1044 }
1045 break;
1046 }
1047 if (quantum_info->quantum == 32UL)
1048 {
1049 for (x=0; x < (ssize_t) number_pixels; x++)
1050 {
1051 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00001052 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1053 q);
cristya6a96a12010-08-23 13:37:35 +00001054 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00001055 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1056 q);
cristya6a96a12010-08-23 13:37:35 +00001057 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00001058 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1059 q);
cristya6a96a12010-08-23 13:37:35 +00001060 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
1061 p->opacity),range);
cristy02422272011-03-16 01:08:49 +00001062 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1063 q);
cristya6a96a12010-08-23 13:37:35 +00001064 p++;
1065 q+=quantum_info->pad;
1066 }
1067 break;
1068 }
1069 for (x=0; x < (ssize_t) number_pixels; x++)
1070 {
1071 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00001072 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +00001073 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00001074 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +00001075 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00001076 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +00001077 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
1078 p->opacity),range);
cristy02422272011-03-16 01:08:49 +00001079 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristya6a96a12010-08-23 13:37:35 +00001080 p++;
1081 q+=quantum_info->pad;
1082 }
1083 break;
1084 }
1085 case 16:
1086 {
1087 register unsigned short
1088 pixel;
1089
1090 if (quantum_info->format == FloatingPointQuantumFormat)
1091 {
1092 for (x=0; x < (ssize_t) number_pixels; x++)
1093 {
1094 pixel=SinglePrecisionToHalf(QuantumScale*
1095 GetBluePixelComponent(p));
1096 q=PopShortPixel(endian,pixel,q);
1097 pixel=SinglePrecisionToHalf(QuantumScale*
1098 GetGreenPixelComponent(p));
1099 q=PopShortPixel(endian,pixel,q);
1100 pixel=SinglePrecisionToHalf(QuantumScale*
1101 GetRedPixelComponent(p));
1102 q=PopShortPixel(endian,pixel,q);
1103 pixel=SinglePrecisionToHalf(QuantumScale*
1104 GetAlphaPixelComponent(p));
1105 q=PopShortPixel(endian,pixel,q);
1106 p++;
1107 q+=quantum_info->pad;
1108 }
1109 break;
1110 }
1111 for (x=0; x < (ssize_t) number_pixels; x++)
1112 {
1113 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
1114 q=PopShortPixel(endian,pixel,q);
1115 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
1116 q=PopShortPixel(endian,pixel,q);
1117 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
1118 q=PopShortPixel(endian,pixel,q);
1119 pixel=ScaleQuantumToShort((Quantum) GetAlphaPixelComponent(p));
1120 q=PopShortPixel(endian,pixel,q);
1121 p++;
1122 q+=quantum_info->pad;
1123 }
1124 break;
1125 }
1126 case 32:
1127 {
1128 register unsigned int
1129 pixel;
1130
1131 if (quantum_info->format == FloatingPointQuantumFormat)
1132 {
1133 for (x=0; x < (ssize_t) number_pixels; x++)
1134 {
1135 float
1136 pixel;
1137
1138 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1139 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1140 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1141 pixel=(float) GetAlphaPixelComponent(p);
1142 q=PopFloatPixel(&quantum_state,pixel,q);
1143 p++;
1144 q+=quantum_info->pad;
1145 }
1146 break;
1147 }
1148 for (x=0; x < (ssize_t) number_pixels; x++)
1149 {
1150 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
1151 q=PopLongPixel(endian,pixel,q);
1152 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
1153 q=PopLongPixel(endian,pixel,q);
1154 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
1155 q=PopLongPixel(endian,pixel,q);
1156 pixel=ScaleQuantumToLong((Quantum) GetAlphaPixelComponent(p));
1157 q=PopLongPixel(endian,pixel,q);
1158 p++;
1159 q+=quantum_info->pad;
1160 }
1161 break;
1162 }
1163 case 64:
1164 {
1165 if (quantum_info->format == FloatingPointQuantumFormat)
1166 {
1167 double
1168 pixel;
1169
1170 for (x=0; x < (ssize_t) number_pixels; x++)
1171 {
1172 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1173 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1174 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1175 pixel=(double) GetAlphaPixelComponent(p);
1176 q=PopDoublePixel(&quantum_state,pixel,q);
1177 p++;
1178 q+=quantum_info->pad;
1179 }
1180 break;
1181 }
1182 }
1183 default:
1184 {
cristy02422272011-03-16 01:08:49 +00001185 range=GetQuantumRange(quantum_info->depth);
cristya6a96a12010-08-23 13:37:35 +00001186 for (x=0; x < (ssize_t) number_pixels; x++)
1187 {
cristy02422272011-03-16 01:08:49 +00001188 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1189 ScaleQuantumToAny(GetBluePixelComponent(p),range),q);
1190 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1191 ScaleQuantumToAny(GetGreenPixelComponent(p),range),q);
1192 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1193 ScaleQuantumToAny(GetRedPixelComponent(p),range),q);
1194 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1195 ScaleQuantumToAny((Quantum) GetAlphaPixelComponent(p),range),q);
cristya6a96a12010-08-23 13:37:35 +00001196 p++;
1197 q+=quantum_info->pad;
1198 }
1199 break;
1200 }
1201 }
1202 break;
1203 }
cristy3ed852e2009-09-05 21:47:34 +00001204 case GrayQuantum:
1205 {
1206 switch (quantum_info->depth)
1207 {
1208 case 1:
1209 {
1210 register Quantum
1211 threshold;
1212
1213 register unsigned char
1214 black,
1215 white;
1216
1217 black=0x00;
1218 white=0x01;
1219 if (quantum_info->min_is_white != MagickFalse)
1220 {
1221 black=0x01;
1222 white=0x00;
1223 }
1224 threshold=(Quantum) (QuantumRange/2);
cristybb503372010-05-27 20:51:26 +00001225 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
cristy3ed852e2009-09-05 21:47:34 +00001226 {
1227 *q='\0';
1228 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 7;
1229 p++;
1230 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 6;
1231 p++;
1232 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 5;
1233 p++;
1234 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 4;
1235 p++;
1236 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 3;
1237 p++;
1238 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 2;
1239 p++;
1240 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 1;
1241 p++;
1242 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 0;
1243 p++;
1244 q++;
1245 }
1246 if ((number_pixels % 8) != 0)
1247 {
1248 *q='\0';
cristybb503372010-05-27 20:51:26 +00001249 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
cristy3ed852e2009-09-05 21:47:34 +00001250 {
1251 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) <<
1252 bit;
1253 p++;
1254 }
1255 q++;
1256 }
1257 break;
1258 }
1259 case 4:
1260 {
1261 register unsigned char
1262 pixel;
1263
cristybb503372010-05-27 20:51:26 +00001264 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001265 {
1266 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1267 *q=(((pixel >> 4) & 0xf) << 4);
1268 p++;
1269 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1270 *q|=pixel >> 4;
1271 p++;
1272 q++;
1273 }
1274 if ((number_pixels % 2) != 0)
1275 {
1276 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1277 *q=(((pixel >> 4) & 0xf) << 4);
1278 p++;
1279 q++;
1280 }
1281 break;
1282 }
1283 case 8:
1284 {
1285 register unsigned char
1286 pixel;
1287
cristybb503372010-05-27 20:51:26 +00001288 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001289 {
1290 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1291 q=PopCharPixel(pixel,q);
1292 p++;
1293 q+=quantum_info->pad;
1294 }
1295 break;
1296 }
1297 case 10:
1298 {
cristy02422272011-03-16 01:08:49 +00001299 range=GetQuantumRange(quantum_info->depth);
cristy3ed852e2009-09-05 21:47:34 +00001300 if (quantum_info->pack == MagickFalse)
1301 {
cristy4cb162a2010-05-30 03:04:47 +00001302 register unsigned int
cristyff024b42010-02-21 22:55:09 +00001303 pixel;
1304
cristybb503372010-05-27 20:51:26 +00001305 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +00001306 {
cristy4cb162a2010-05-30 03:04:47 +00001307 pixel=(unsigned int) (
cristyff024b42010-02-21 22:55:09 +00001308 ScaleQuantumToAny(PixelIntensityToQuantum(p+2),range) << 22 |
1309 ScaleQuantumToAny(PixelIntensityToQuantum(p+1),range) << 12 |
1310 ScaleQuantumToAny(PixelIntensityToQuantum(p+0),range) << 2);
1311 q=PopLongPixel(endian,pixel,q);
1312 p+=3;
cristy3ed852e2009-09-05 21:47:34 +00001313 q+=quantum_info->pad;
1314 }
cristy69702dd2010-02-22 15:26:39 +00001315 pixel=0UL;
cristybb503372010-05-27 20:51:26 +00001316 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +00001317 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+1),
1318 range) << 12;
cristybb503372010-05-27 20:51:26 +00001319 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +00001320 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+0),
1321 range) << 2;
1322 q=PopLongPixel(endian,pixel,q);
cristy3ed852e2009-09-05 21:47:34 +00001323 break;
1324 }
cristybb503372010-05-27 20:51:26 +00001325 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001326 {
cristy02422272011-03-16 01:08:49 +00001327 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1328 ScaleQuantumToAny(PixelIntensityToQuantum(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001329 p++;
1330 q+=quantum_info->pad;
1331 }
1332 break;
1333 }
1334 case 12:
1335 {
1336 register unsigned short
1337 pixel;
1338
cristy02422272011-03-16 01:08:49 +00001339 range=GetQuantumRange(quantum_info->depth);
cristy3ed852e2009-09-05 21:47:34 +00001340 if (quantum_info->pack == MagickFalse)
1341 {
cristybb503372010-05-27 20:51:26 +00001342 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001343 {
1344 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
1345 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
1346 p++;
1347 q+=quantum_info->pad;
1348 }
1349 break;
1350 }
cristybb503372010-05-27 20:51:26 +00001351 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001352 {
cristy02422272011-03-16 01:08:49 +00001353 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1354 ScaleQuantumToAny(PixelIntensityToQuantum(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001355 p++;
1356 q+=quantum_info->pad;
1357 }
1358 break;
1359 }
1360 case 16:
1361 {
1362 register unsigned short
1363 pixel;
1364
cristyc9672a92010-01-06 00:57:45 +00001365 if (quantum_info->format == FloatingPointQuantumFormat)
1366 {
cristybb503372010-05-27 20:51:26 +00001367 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001368 {
cristy2a4d01c2010-01-10 21:14:51 +00001369 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001370 PixelIntensityToQuantum(p));
cristyc9672a92010-01-06 00:57:45 +00001371 q=PopShortPixel(endian,pixel,q);
1372 p++;
1373 q+=quantum_info->pad;
1374 }
1375 break;
1376 }
cristybb503372010-05-27 20:51:26 +00001377 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001378 {
1379 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
1380 q=PopShortPixel(endian,pixel,q);
1381 p++;
1382 q+=quantum_info->pad;
1383 }
1384 break;
1385 }
1386 case 32:
1387 {
cristy4cb162a2010-05-30 03:04:47 +00001388 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001389 pixel;
1390
1391 if (quantum_info->format == FloatingPointQuantumFormat)
1392 {
cristybb503372010-05-27 20:51:26 +00001393 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001394 {
1395 float
1396 pixel;
1397
1398 pixel=(float) PixelIntensityToQuantum(p);
1399 q=PopFloatPixel(&quantum_state,pixel,q);
1400 p++;
1401 q+=quantum_info->pad;
1402 }
1403 break;
1404 }
cristybb503372010-05-27 20:51:26 +00001405 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001406 {
1407 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
1408 q=PopLongPixel(endian,pixel,q);
1409 p++;
1410 q+=quantum_info->pad;
1411 }
1412 break;
1413 }
1414 case 64:
1415 {
1416 if (quantum_info->format == FloatingPointQuantumFormat)
1417 {
cristybb503372010-05-27 20:51:26 +00001418 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001419 {
1420 double
1421 pixel;
1422
1423 pixel=(double) PixelIntensityToQuantum(p);
1424 q=PopDoublePixel(&quantum_state,pixel,q);
1425 p++;
1426 q+=quantum_info->pad;
1427 }
1428 break;
1429 }
1430 }
1431 default:
1432 {
cristy02422272011-03-16 01:08:49 +00001433 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00001434 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001435 {
cristy02422272011-03-16 01:08:49 +00001436 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1437 ScaleQuantumToAny(PixelIntensityToQuantum(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001438 p++;
1439 q+=quantum_info->pad;
1440 }
1441 break;
1442 }
1443 }
1444 break;
1445 }
1446 case GrayAlphaQuantum:
1447 {
1448 switch (quantum_info->depth)
1449 {
1450 case 1:
1451 {
1452 register Quantum
1453 threshold;
1454
1455 register unsigned char
1456 black,
1457 pixel,
1458 white;
1459
1460 black=0x00;
1461 white=0x01;
1462 if (quantum_info->min_is_white == MagickFalse)
1463 {
1464 black=0x01;
1465 white=0x00;
1466 }
1467 threshold=(Quantum) (QuantumRange/2);
cristybb503372010-05-27 20:51:26 +00001468 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
cristy3ed852e2009-09-05 21:47:34 +00001469 {
1470 *q='\0';
cristy4c27e792010-08-10 01:33:20 +00001471 *q|=(PixelIntensityToQuantum(p) > threshold ? black : white) << 7;
cristy3ed852e2009-09-05 21:47:34 +00001472 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
cristybfe29252010-08-10 02:12:17 +00001473 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
cristy3ed852e2009-09-05 21:47:34 +00001474 p++;
cristy4c27e792010-08-10 01:33:20 +00001475 *q|=(PixelIntensityToQuantum(p) > threshold ? black : white) << 5;
cristy3ed852e2009-09-05 21:47:34 +00001476 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
cristybfe29252010-08-10 02:12:17 +00001477 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
cristy3ed852e2009-09-05 21:47:34 +00001478 p++;
cristy4c27e792010-08-10 01:33:20 +00001479 *q|=(PixelIntensityToQuantum(p) > threshold ? black : white) << 3;
cristy3ed852e2009-09-05 21:47:34 +00001480 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
cristybfe29252010-08-10 02:12:17 +00001481 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
cristy3ed852e2009-09-05 21:47:34 +00001482 p++;
cristy4c27e792010-08-10 01:33:20 +00001483 *q|=(PixelIntensityToQuantum(p) > threshold ? black : white) << 1;
cristy3ed852e2009-09-05 21:47:34 +00001484 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
cristybfe29252010-08-10 02:12:17 +00001485 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
cristy3ed852e2009-09-05 21:47:34 +00001486 p++;
1487 q++;
1488 }
1489 if ((number_pixels % 4) != 0)
1490 {
1491 *q='\0';
cristy2837bcc2010-08-07 23:57:39 +00001492 for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +00001493 {
cristy4c27e792010-08-10 01:33:20 +00001494 *q|=(PixelIntensityToQuantum(p) > threshold ? black : white) <<
cristy2837bcc2010-08-07 23:57:39 +00001495 (7-bit);
cristy3ed852e2009-09-05 21:47:34 +00001496 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 :
1497 0x01);
cristybfe29252010-08-10 02:12:17 +00001498 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
cristy2837bcc2010-08-07 23:57:39 +00001499 (7-bit-1));
cristy3ed852e2009-09-05 21:47:34 +00001500 p++;
1501 }
1502 q++;
1503 }
1504 break;
1505 }
1506 case 4:
1507 {
1508 register unsigned char
1509 pixel;
1510
cristybb503372010-05-27 20:51:26 +00001511 for (x=0; x < (ssize_t) number_pixels ; x++)
cristy3ed852e2009-09-05 21:47:34 +00001512 {
1513 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1514 *q=(((pixel >> 4) & 0xf) << 4);
1515 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +00001516 GetOpacityPixelComponent(p)))+0.5);
cristy3ed852e2009-09-05 21:47:34 +00001517 *q|=pixel & 0xf;
1518 p++;
1519 q++;
1520 }
1521 break;
1522 }
1523 case 8:
1524 {
1525 register unsigned char
1526 pixel;
1527
cristybb503372010-05-27 20:51:26 +00001528 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001529 {
1530 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1531 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00001532 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1533 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001534 q=PopCharPixel(pixel,q);
1535 p++;
1536 q+=quantum_info->pad;
1537 }
1538 break;
1539 }
1540 case 16:
1541 {
1542 register unsigned short
1543 pixel;
1544
cristyc9672a92010-01-06 00:57:45 +00001545 if (quantum_info->format == FloatingPointQuantumFormat)
1546 {
cristybb503372010-05-27 20:51:26 +00001547 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001548 {
cristy2a4d01c2010-01-10 21:14:51 +00001549 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001550 PixelIntensityToQuantum(p));
cristyc9672a92010-01-06 00:57:45 +00001551 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00001552 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001553 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001554 q=PopShortPixel(endian,pixel,q);
1555 p++;
1556 q+=quantum_info->pad;
1557 }
1558 break;
1559 }
cristybb503372010-05-27 20:51:26 +00001560 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001561 {
1562 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
1563 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001564 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1565 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001566 q=PopShortPixel(endian,pixel,q);
1567 p++;
1568 q+=quantum_info->pad;
1569 }
1570 break;
1571 }
1572 case 32:
1573 {
cristy4cb162a2010-05-30 03:04:47 +00001574 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001575 pixel;
1576
1577 if (quantum_info->format == FloatingPointQuantumFormat)
1578 {
cristybb503372010-05-27 20:51:26 +00001579 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001580 {
1581 float
1582 pixel;
1583
1584 pixel=(float) PixelIntensityToQuantum(p);
1585 q=PopFloatPixel(&quantum_state,pixel,q);
cristy46f08202010-01-10 04:04:21 +00001586 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001587 q=PopFloatPixel(&quantum_state,pixel,q);
1588 p++;
1589 q+=quantum_info->pad;
1590 }
1591 break;
1592 }
cristybb503372010-05-27 20:51:26 +00001593 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001594 {
1595 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
1596 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001597 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
1598 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001599 q=PopLongPixel(endian,pixel,q);
1600 p++;
1601 q+=quantum_info->pad;
1602 }
1603 break;
1604 }
1605 case 64:
1606 {
1607 if (quantum_info->format == FloatingPointQuantumFormat)
1608 {
cristybb503372010-05-27 20:51:26 +00001609 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001610 {
1611 double
1612 pixel;
1613
1614 pixel=(double) PixelIntensityToQuantum(p);
1615 q=PopDoublePixel(&quantum_state,pixel,q);
cristy46f08202010-01-10 04:04:21 +00001616 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001617 q=PopDoublePixel(&quantum_state,pixel,q);
1618 p++;
1619 q+=quantum_info->pad;
1620 }
1621 break;
1622 }
1623 }
1624 default:
1625 {
cristy02422272011-03-16 01:08:49 +00001626 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00001627 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001628 {
cristy02422272011-03-16 01:08:49 +00001629 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1630 ScaleQuantumToAny(PixelIntensityToQuantum(p),range),q);
1631 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1632 ScaleQuantumToAny((Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001633 p++;
1634 q+=quantum_info->pad;
1635 }
1636 break;
1637 }
1638 }
1639 break;
1640 }
1641 case RedQuantum:
1642 case CyanQuantum:
1643 {
1644 switch (quantum_info->depth)
1645 {
1646 case 8:
1647 {
1648 register unsigned char
1649 pixel;
1650
cristybb503372010-05-27 20:51:26 +00001651 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001652 {
cristyce70c172010-01-07 17:15:30 +00001653 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001654 q=PopCharPixel(pixel,q);
1655 p++;
1656 q+=quantum_info->pad;
1657 }
1658 break;
1659 }
1660 case 16:
1661 {
1662 register unsigned short
1663 pixel;
1664
cristyc9672a92010-01-06 00:57:45 +00001665 if (quantum_info->format == FloatingPointQuantumFormat)
1666 {
cristybb503372010-05-27 20:51:26 +00001667 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001668 {
cristy2a4d01c2010-01-10 21:14:51 +00001669 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001670 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001671 q=PopShortPixel(endian,pixel,q);
1672 p++;
1673 q+=quantum_info->pad;
1674 }
1675 break;
1676 }
cristybb503372010-05-27 20:51:26 +00001677 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001678 {
cristyce70c172010-01-07 17:15:30 +00001679 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001680 q=PopShortPixel(endian,pixel,q);
1681 p++;
1682 q+=quantum_info->pad;
1683 }
1684 break;
1685 }
1686 case 32:
1687 {
cristy4cb162a2010-05-30 03:04:47 +00001688 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001689 pixel;
1690
1691 if (quantum_info->format == FloatingPointQuantumFormat)
1692 {
cristybb503372010-05-27 20:51:26 +00001693 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001694 {
1695 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1696 p++;
1697 q+=quantum_info->pad;
1698 }
1699 break;
1700 }
cristybb503372010-05-27 20:51:26 +00001701 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001702 {
cristyce70c172010-01-07 17:15:30 +00001703 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001704 q=PopLongPixel(endian,pixel,q);
1705 p++;
1706 q+=quantum_info->pad;
1707 }
1708 break;
1709 }
1710 case 64:
1711 {
1712 if (quantum_info->format == FloatingPointQuantumFormat)
1713 {
cristybb503372010-05-27 20:51:26 +00001714 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001715 {
1716 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1717 p++;
1718 q+=quantum_info->pad;
1719 }
1720 break;
1721 }
1722 }
1723 default:
1724 {
cristy02422272011-03-16 01:08:49 +00001725 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00001726 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001727 {
cristy02422272011-03-16 01:08:49 +00001728 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1729 ScaleQuantumToAny(p->red,range),q);
cristy3ed852e2009-09-05 21:47:34 +00001730 p++;
1731 q+=quantum_info->pad;
1732 }
1733 break;
1734 }
1735 }
1736 break;
1737 }
1738 case GreenQuantum:
1739 case MagentaQuantum:
1740 {
1741 switch (quantum_info->depth)
1742 {
1743 case 8:
1744 {
1745 register unsigned char
1746 pixel;
1747
cristybb503372010-05-27 20:51:26 +00001748 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001749 {
cristyce70c172010-01-07 17:15:30 +00001750 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001751 q=PopCharPixel(pixel,q);
1752 p++;
1753 q+=quantum_info->pad;
1754 }
1755 break;
1756 }
1757 case 16:
1758 {
1759 register unsigned short
1760 pixel;
1761
cristyc9672a92010-01-06 00:57:45 +00001762 if (quantum_info->format == FloatingPointQuantumFormat)
1763 {
cristybb503372010-05-27 20:51:26 +00001764 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001765 {
cristy2a4d01c2010-01-10 21:14:51 +00001766 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001767 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001768 q=PopShortPixel(endian,pixel,q);
1769 p++;
1770 q+=quantum_info->pad;
1771 }
1772 break;
1773 }
cristybb503372010-05-27 20:51:26 +00001774 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001775 {
cristyce70c172010-01-07 17:15:30 +00001776 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001777 q=PopShortPixel(endian,pixel,q);
1778 p++;
1779 q+=quantum_info->pad;
1780 }
1781 break;
1782 }
1783 case 32:
1784 {
cristy4cb162a2010-05-30 03:04:47 +00001785 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001786 pixel;
1787
1788 if (quantum_info->format == FloatingPointQuantumFormat)
1789 {
cristybb503372010-05-27 20:51:26 +00001790 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001791 {
1792 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1793 p++;
1794 q+=quantum_info->pad;
1795 }
1796 break;
1797 }
cristybb503372010-05-27 20:51:26 +00001798 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001799 {
cristyce70c172010-01-07 17:15:30 +00001800 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001801 q=PopLongPixel(endian,pixel,q);
1802 p++;
1803 q+=quantum_info->pad;
1804 }
1805 break;
1806 }
1807 case 64:
1808 {
1809 if (quantum_info->format == FloatingPointQuantumFormat)
1810 {
cristybb503372010-05-27 20:51:26 +00001811 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001812 {
1813 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1814 p++;
1815 q+=quantum_info->pad;
1816 }
1817 break;
1818 }
1819 }
1820 default:
1821 {
cristy02422272011-03-16 01:08:49 +00001822 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00001823 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001824 {
cristy02422272011-03-16 01:08:49 +00001825 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1826 ScaleQuantumToAny(p->green,range),q);
cristy3ed852e2009-09-05 21:47:34 +00001827 p++;
1828 q+=quantum_info->pad;
1829 }
1830 break;
1831 }
1832 }
1833 break;
1834 }
1835 case BlueQuantum:
1836 case YellowQuantum:
1837 {
1838 switch (quantum_info->depth)
1839 {
1840 case 8:
1841 {
1842 register unsigned char
1843 pixel;
1844
cristybb503372010-05-27 20:51:26 +00001845 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001846 {
cristyce70c172010-01-07 17:15:30 +00001847 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001848 q=PopCharPixel(pixel,q);
1849 p++;
1850 q+=quantum_info->pad;
1851 }
1852 break;
1853 }
1854 case 16:
1855 {
1856 register unsigned short
1857 pixel;
1858
cristyc9672a92010-01-06 00:57:45 +00001859 if (quantum_info->format == FloatingPointQuantumFormat)
1860 {
cristybb503372010-05-27 20:51:26 +00001861 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001862 {
cristy2a4d01c2010-01-10 21:14:51 +00001863 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001864 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001865 q=PopShortPixel(endian,pixel,q);
1866 p++;
1867 q+=quantum_info->pad;
1868 }
1869 break;
1870 }
cristybb503372010-05-27 20:51:26 +00001871 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001872 {
cristyce70c172010-01-07 17:15:30 +00001873 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001874 q=PopShortPixel(endian,pixel,q);
1875 p++;
1876 q+=quantum_info->pad;
1877 }
1878 break;
1879 }
1880 case 32:
1881 {
cristy4cb162a2010-05-30 03:04:47 +00001882 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001883 pixel;
1884
1885 if (quantum_info->format == FloatingPointQuantumFormat)
1886 {
cristybb503372010-05-27 20:51:26 +00001887 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001888 {
1889 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1890 p++;
1891 q+=quantum_info->pad;
1892 }
1893 break;
1894 }
cristybb503372010-05-27 20:51:26 +00001895 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001896 {
cristyce70c172010-01-07 17:15:30 +00001897 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001898 q=PopLongPixel(endian,pixel,q);
1899 p++;
1900 q+=quantum_info->pad;
1901 }
1902 break;
1903 }
1904 case 64:
1905 {
1906 if (quantum_info->format == FloatingPointQuantumFormat)
1907 {
cristybb503372010-05-27 20:51:26 +00001908 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001909 {
1910 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1911 p++;
1912 q+=quantum_info->pad;
1913 }
1914 break;
1915 }
1916 }
1917 default:
1918 {
cristy02422272011-03-16 01:08:49 +00001919 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00001920 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001921 {
cristy02422272011-03-16 01:08:49 +00001922 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1923 ScaleQuantumToAny(p->blue,range),q);
cristy3ed852e2009-09-05 21:47:34 +00001924 p++;
1925 q+=quantum_info->pad;
1926 }
1927 break;
1928 }
1929 }
1930 break;
1931 }
1932 case AlphaQuantum:
1933 {
1934 switch (quantum_info->depth)
1935 {
1936 case 8:
1937 {
1938 register unsigned char
1939 pixel;
1940
cristybb503372010-05-27 20:51:26 +00001941 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001942 {
cristyce70c172010-01-07 17:15:30 +00001943 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1944 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001945 q=PopCharPixel(pixel,q);
1946 p++;
1947 q+=quantum_info->pad;
1948 }
1949 break;
1950 }
1951 case 16:
1952 {
1953 register unsigned short
1954 pixel;
1955
cristyc9672a92010-01-06 00:57:45 +00001956 if (quantum_info->format == FloatingPointQuantumFormat)
1957 {
cristybb503372010-05-27 20:51:26 +00001958 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001959 {
cristy2a4d01c2010-01-10 21:14:51 +00001960 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001961 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001962 q=PopShortPixel(endian,pixel,q);
1963 p++;
1964 q+=quantum_info->pad;
1965 }
1966 break;
1967 }
cristybb503372010-05-27 20:51:26 +00001968 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001969 {
cristyce70c172010-01-07 17:15:30 +00001970 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1971 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001972 q=PopShortPixel(endian,pixel,q);
1973 p++;
1974 q+=quantum_info->pad;
1975 }
1976 break;
1977 }
1978 case 32:
1979 {
cristy4cb162a2010-05-30 03:04:47 +00001980 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001981 pixel;
1982
1983 if (quantum_info->format == FloatingPointQuantumFormat)
1984 {
cristybb503372010-05-27 20:51:26 +00001985 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001986 {
1987 float
1988 pixel;
1989
cristy46f08202010-01-10 04:04:21 +00001990 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001991 q=PopFloatPixel(&quantum_state,pixel,q);
1992 p++;
1993 q+=quantum_info->pad;
1994 }
1995 break;
1996 }
cristybb503372010-05-27 20:51:26 +00001997 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001998 {
cristyce70c172010-01-07 17:15:30 +00001999 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
2000 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002001 q=PopLongPixel(endian,pixel,q);
2002 p++;
2003 q+=quantum_info->pad;
2004 }
2005 break;
2006 }
2007 case 64:
2008 {
2009 if (quantum_info->format == FloatingPointQuantumFormat)
2010 {
cristybb503372010-05-27 20:51:26 +00002011 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002012 {
2013 double
2014 pixel;
2015
cristy46f08202010-01-10 04:04:21 +00002016 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002017 q=PopDoublePixel(&quantum_state,pixel,q);
2018 p++;
2019 q+=quantum_info->pad;
2020 }
2021 break;
2022 }
2023 }
2024 default:
2025 {
cristy02422272011-03-16 01:08:49 +00002026 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002027 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002028 {
cristy02422272011-03-16 01:08:49 +00002029 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2030 ScaleQuantumToAny((Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002031 p++;
2032 q+=quantum_info->pad;
2033 }
2034 break;
2035 }
2036 }
2037 break;
2038 }
2039 case OpacityQuantum:
2040 {
2041 switch (quantum_info->depth)
2042 {
2043 case 8:
2044 {
2045 register unsigned char
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 {
cristyce70c172010-01-07 17:15:30 +00002050 pixel=ScaleQuantumToChar(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002051 q=PopCharPixel(pixel,q);
2052 p++;
2053 q+=quantum_info->pad;
2054 }
2055 break;
2056 }
2057 case 16:
2058 {
2059 register unsigned short
2060 pixel;
2061
cristyc9672a92010-01-06 00:57:45 +00002062 if (quantum_info->format == FloatingPointQuantumFormat)
2063 {
cristybb503372010-05-27 20:51:26 +00002064 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002065 {
cristy2a4d01c2010-01-10 21:14:51 +00002066 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002067 GetOpacityPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002068 q=PopShortPixel(endian,pixel,q);
2069 p++;
2070 q+=quantum_info->pad;
2071 }
2072 break;
2073 }
cristybb503372010-05-27 20:51:26 +00002074 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002075 {
cristyce70c172010-01-07 17:15:30 +00002076 pixel=ScaleQuantumToShort(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002077 q=PopShortPixel(endian,pixel,q);
2078 p++;
2079 q+=quantum_info->pad;
2080 }
2081 break;
2082 }
2083 case 32:
2084 {
cristy4cb162a2010-05-30 03:04:47 +00002085 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002086 pixel;
2087
2088 if (quantum_info->format == FloatingPointQuantumFormat)
2089 {
cristybb503372010-05-27 20:51:26 +00002090 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002091 {
2092 q=PopFloatPixel(&quantum_state,(float) p->opacity,q);
2093 p++;
2094 q+=quantum_info->pad;
2095 }
2096 break;
2097 }
cristybb503372010-05-27 20:51:26 +00002098 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002099 {
cristyce70c172010-01-07 17:15:30 +00002100 pixel=ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002101 q=PopLongPixel(endian,pixel,q);
2102 p++;
2103 q+=quantum_info->pad;
2104 }
2105 break;
2106 }
2107 case 64:
2108 {
2109 if (quantum_info->format == FloatingPointQuantumFormat)
2110 {
cristybb503372010-05-27 20:51:26 +00002111 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002112 {
2113 q=PopDoublePixel(&quantum_state,(double) p->opacity,q);
2114 p++;
2115 q+=quantum_info->pad;
2116 }
2117 break;
2118 }
2119 }
2120 default:
2121 {
cristy02422272011-03-16 01:08:49 +00002122 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002123 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002124 {
cristy02422272011-03-16 01:08:49 +00002125 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2126 ScaleQuantumToAny(p->opacity,range),q);
cristy3ed852e2009-09-05 21:47:34 +00002127 p++;
2128 q+=quantum_info->pad;
2129 }
2130 break;
2131 }
2132 }
2133 break;
2134 }
2135 case BlackQuantum:
2136 {
2137 if (image->colorspace != CMYKColorspace)
2138 {
2139 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2140 "ColorSeparatedImageRequired","`%s'",image->filename);
2141 return(extent);
2142 }
2143 switch (quantum_info->depth)
2144 {
2145 case 8:
2146 {
2147 register unsigned char
2148 pixel;
2149
cristybb503372010-05-27 20:51:26 +00002150 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002151 {
2152 pixel=ScaleQuantumToChar(indexes[x]);
2153 q=PopCharPixel(pixel,q);
2154 p++;
2155 q+=quantum_info->pad;
2156 }
2157 break;
2158 }
2159 case 16:
2160 {
2161 register unsigned short
2162 pixel;
2163
cristyc9672a92010-01-06 00:57:45 +00002164 if (quantum_info->format == FloatingPointQuantumFormat)
2165 {
cristybb503372010-05-27 20:51:26 +00002166 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002167 {
cristy2a4d01c2010-01-10 21:14:51 +00002168 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00002169 q=PopShortPixel(endian,pixel,q);
2170 p++;
2171 q+=quantum_info->pad;
2172 }
2173 break;
2174 }
cristybb503372010-05-27 20:51:26 +00002175 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002176 {
2177 pixel=ScaleQuantumToShort(indexes[x]);
2178 q=PopShortPixel(endian,pixel,q);
2179 p++;
2180 q+=quantum_info->pad;
2181 }
2182 break;
2183 }
2184 case 32:
2185 {
cristy4cb162a2010-05-30 03:04:47 +00002186 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002187 pixel;
2188
2189 if (quantum_info->format == FloatingPointQuantumFormat)
2190 {
cristybb503372010-05-27 20:51:26 +00002191 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002192 {
2193 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
2194 p++;
2195 q+=quantum_info->pad;
2196 }
2197 break;
2198 }
cristybb503372010-05-27 20:51:26 +00002199 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002200 {
2201 pixel=ScaleQuantumToLong(indexes[x]);
2202 q=PopLongPixel(endian,pixel,q);
2203 p++;
2204 q+=quantum_info->pad;
2205 }
2206 break;
2207 }
2208 case 64:
2209 {
2210 if (quantum_info->format == FloatingPointQuantumFormat)
2211 {
cristybb503372010-05-27 20:51:26 +00002212 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002213 {
2214 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
2215 p++;
2216 q+=quantum_info->pad;
2217 }
2218 break;
2219 }
2220 }
2221 default:
2222 {
cristy02422272011-03-16 01:08:49 +00002223 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002224 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002225 {
cristy02422272011-03-16 01:08:49 +00002226 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2227 ScaleQuantumToAny((Quantum) indexes[x],range),q);
cristy3ed852e2009-09-05 21:47:34 +00002228 p++;
2229 q+=quantum_info->pad;
2230 }
2231 break;
2232 }
2233 }
2234 break;
2235 }
2236 case RGBQuantum:
2237 case CbYCrQuantum:
2238 {
2239 switch (quantum_info->depth)
2240 {
2241 case 8:
2242 {
cristybb503372010-05-27 20:51:26 +00002243 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002244 {
cristyce70c172010-01-07 17:15:30 +00002245 q=PopCharPixel(ScaleQuantumToChar(GetRedPixelComponent(p)),q);
2246 q=PopCharPixel(ScaleQuantumToChar(GetGreenPixelComponent(p)),q);
2247 q=PopCharPixel(ScaleQuantumToChar(GetBluePixelComponent(p)),q);
cristy3ed852e2009-09-05 21:47:34 +00002248 p++;
2249 q+=quantum_info->pad;
2250 }
2251 break;
2252 }
2253 case 10:
2254 {
cristy4cb162a2010-05-30 03:04:47 +00002255 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002256 pixel;
2257
cristy02422272011-03-16 01:08:49 +00002258 range=GetQuantumRange(quantum_info->depth);
cristy3ed852e2009-09-05 21:47:34 +00002259 if (quantum_info->pack == MagickFalse)
2260 {
cristybb503372010-05-27 20:51:26 +00002261 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002262 {
cristy4cb162a2010-05-30 03:04:47 +00002263 pixel=(unsigned int) (ScaleQuantumToAny(p->red,range) << 22 |
cristyff024b42010-02-21 22:55:09 +00002264 ScaleQuantumToAny(p->green,range) << 12 |
cristy3ed852e2009-09-05 21:47:34 +00002265 ScaleQuantumToAny(p->blue,range) << 2);
2266 q=PopLongPixel(endian,pixel,q);
2267 p++;
2268 q+=quantum_info->pad;
2269 }
2270 break;
2271 }
2272 if (quantum_info->quantum == 32UL)
2273 {
cristybb503372010-05-27 20:51:26 +00002274 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002275 {
cristy4cb162a2010-05-30 03:04:47 +00002276 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002277 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2278 q);
cristy4cb162a2010-05-30 03:04:47 +00002279 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002280 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2281 q);
cristy4cb162a2010-05-30 03:04:47 +00002282 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002283 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2284 q);
cristy3ed852e2009-09-05 21:47:34 +00002285 p++;
2286 q+=quantum_info->pad;
2287 }
2288 break;
2289 }
cristybb503372010-05-27 20:51:26 +00002290 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002291 {
cristy4cb162a2010-05-30 03:04:47 +00002292 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002293 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002294 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002295 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002296 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002297 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy3ed852e2009-09-05 21:47:34 +00002298 p++;
2299 q+=quantum_info->pad;
2300 }
2301 break;
2302 }
2303 case 12:
2304 {
cristy4cb162a2010-05-30 03:04:47 +00002305 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002306 pixel;
2307
cristy02422272011-03-16 01:08:49 +00002308 range=GetQuantumRange(quantum_info->depth);
cristy3ed852e2009-09-05 21:47:34 +00002309 if (quantum_info->pack == MagickFalse)
2310 {
cristybb503372010-05-27 20:51:26 +00002311 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002312 {
2313 switch (x % 3)
2314 {
2315 default:
2316 case 0:
2317 {
cristy4cb162a2010-05-30 03:04:47 +00002318 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00002319 break;
2320 }
2321 case 1:
2322 {
cristy4cb162a2010-05-30 03:04:47 +00002323 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00002324 break;
2325 }
2326 case 2:
2327 {
cristy4cb162a2010-05-30 03:04:47 +00002328 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00002329 p++;
2330 break;
2331 }
2332 }
2333 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2334 switch ((x+1) % 3)
2335 {
2336 default:
2337 case 0:
2338 {
cristy4cb162a2010-05-30 03:04:47 +00002339 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00002340 break;
2341 }
2342 case 1:
2343 {
cristy4cb162a2010-05-30 03:04:47 +00002344 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00002345 break;
2346 }
2347 case 2:
2348 {
cristy4cb162a2010-05-30 03:04:47 +00002349 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00002350 p++;
2351 break;
2352 }
2353 }
2354 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2355 q+=quantum_info->pad;
2356 }
cristybb503372010-05-27 20:51:26 +00002357 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00002358 {
2359 switch ((x+bit) % 3)
2360 {
2361 default:
2362 case 0:
2363 {
cristy4cb162a2010-05-30 03:04:47 +00002364 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00002365 break;
2366 }
2367 case 1:
2368 {
cristy4cb162a2010-05-30 03:04:47 +00002369 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00002370 break;
2371 }
2372 case 2:
2373 {
cristy4cb162a2010-05-30 03:04:47 +00002374 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00002375 p++;
2376 break;
2377 }
2378 }
2379 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2380 q+=quantum_info->pad;
2381 }
2382 if (bit != 0)
2383 p++;
2384 break;
2385 }
2386 if (quantum_info->quantum == 32UL)
2387 {
cristybb503372010-05-27 20:51:26 +00002388 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002389 {
cristy4cb162a2010-05-30 03:04:47 +00002390 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002391 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2392 q);
cristy4cb162a2010-05-30 03:04:47 +00002393 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002394 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2395 q);
cristy4cb162a2010-05-30 03:04:47 +00002396 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002397 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2398 q);
cristy3ed852e2009-09-05 21:47:34 +00002399 p++;
2400 q+=quantum_info->pad;
2401 }
2402 break;
2403 }
cristybb503372010-05-27 20:51:26 +00002404 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002405 {
cristy4cb162a2010-05-30 03:04:47 +00002406 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002407 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002408 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002409 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002410 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002411 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy3ed852e2009-09-05 21:47:34 +00002412 p++;
2413 q+=quantum_info->pad;
2414 }
2415 break;
2416 }
2417 case 16:
2418 {
2419 register unsigned short
2420 pixel;
2421
cristyc9672a92010-01-06 00:57:45 +00002422 if (quantum_info->format == FloatingPointQuantumFormat)
2423 {
cristybb503372010-05-27 20:51:26 +00002424 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002425 {
cristy2a4d01c2010-01-10 21:14:51 +00002426 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002427 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002428 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002429 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002430 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002431 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002432 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002433 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002434 q=PopShortPixel(endian,pixel,q);
2435 p++;
2436 q+=quantum_info->pad;
2437 }
2438 break;
2439 }
cristybb503372010-05-27 20:51:26 +00002440 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002441 {
cristyce70c172010-01-07 17:15:30 +00002442 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002443 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002444 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002445 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002446 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002447 q=PopShortPixel(endian,pixel,q);
2448 p++;
2449 q+=quantum_info->pad;
2450 }
2451 break;
2452 }
2453 case 32:
2454 {
cristy4cb162a2010-05-30 03:04:47 +00002455 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002456 pixel;
2457
2458 if (quantum_info->format == FloatingPointQuantumFormat)
2459 {
cristybb503372010-05-27 20:51:26 +00002460 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002461 {
2462 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2463 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2464 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2465 p++;
2466 q+=quantum_info->pad;
2467 }
2468 break;
2469 }
cristybb503372010-05-27 20:51:26 +00002470 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002471 {
cristyce70c172010-01-07 17:15:30 +00002472 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002473 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002474 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002475 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002476 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002477 q=PopLongPixel(endian,pixel,q);
2478 p++;
2479 q+=quantum_info->pad;
2480 }
2481 break;
2482 }
2483 case 64:
2484 {
2485 if (quantum_info->format == FloatingPointQuantumFormat)
2486 {
cristybb503372010-05-27 20:51:26 +00002487 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002488 {
2489 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2490 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2491 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2492 p++;
2493 q+=quantum_info->pad;
2494 }
2495 break;
2496 }
2497 }
2498 default:
2499 {
cristy02422272011-03-16 01:08:49 +00002500 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002501 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002502 {
cristy02422272011-03-16 01:08:49 +00002503 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2504 ScaleQuantumToAny(p->red,range),q);
2505 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2506 ScaleQuantumToAny(p->green,range),q);
2507 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2508 ScaleQuantumToAny(p->blue,range),q);
cristy3ed852e2009-09-05 21:47:34 +00002509 p++;
2510 q+=quantum_info->pad;
2511 }
2512 break;
2513 }
2514 }
2515 break;
2516 }
2517 case RGBAQuantum:
2518 case RGBOQuantum:
2519 case CbYCrAQuantum:
2520 {
2521 switch (quantum_info->depth)
2522 {
2523 case 8:
2524 {
2525 register unsigned char
2526 pixel;
2527
cristybb503372010-05-27 20:51:26 +00002528 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002529 {
cristyce70c172010-01-07 17:15:30 +00002530 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002531 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002532 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002533 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002534 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002535 q=PopCharPixel(pixel,q);
cristycee97112010-05-28 00:44:52 +00002536 pixel=ScaleQuantumToChar((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002537 q=PopCharPixel(pixel,q);
2538 p++;
2539 q+=quantum_info->pad;
2540 }
2541 break;
2542 }
cristy891dc792010-03-04 01:47:16 +00002543 case 10:
2544 {
cristy4cb162a2010-05-30 03:04:47 +00002545 register unsigned int
cristy891dc792010-03-04 01:47:16 +00002546 pixel;
2547
cristy02422272011-03-16 01:08:49 +00002548 range=GetQuantumRange(quantum_info->depth);
cristy891dc792010-03-04 01:47:16 +00002549 if (quantum_info->pack == MagickFalse)
2550 {
cristybb503372010-05-27 20:51:26 +00002551 register ssize_t
cristy891dc792010-03-04 01:47:16 +00002552 i;
2553
cristybb503372010-05-27 20:51:26 +00002554 size_t
cristy891dc792010-03-04 01:47:16 +00002555 quantum;
2556
cristy9d314ff2011-03-09 01:30:28 +00002557 ssize_t
2558 n;
2559
cristy891dc792010-03-04 01:47:16 +00002560 n=0;
2561 quantum=0;
2562 pixel=0;
cristybb503372010-05-27 20:51:26 +00002563 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002564 {
2565 for (i=0; i < 4; i++)
2566 {
2567 switch (i)
2568 {
2569 case 0: quantum=p->red; break;
2570 case 1: quantum=p->green; break;
2571 case 2: quantum=p->blue; break;
cristycee97112010-05-28 00:44:52 +00002572 case 3: quantum=(Quantum) (QuantumRange-p->opacity); break;
cristy891dc792010-03-04 01:47:16 +00002573 }
2574 switch (n % 3)
2575 {
2576 case 0:
2577 {
cristycee97112010-05-28 00:44:52 +00002578 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002579 range) << 22);
2580 break;
2581 }
2582 case 1:
2583 {
cristycee97112010-05-28 00:44:52 +00002584 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002585 range) << 12);
2586 break;
2587 }
2588 case 2:
2589 {
cristycee97112010-05-28 00:44:52 +00002590 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002591 range) << 2);
2592 q=PopLongPixel(endian,pixel,q);
2593 pixel=0;
2594 break;
2595 }
2596 }
2597 n++;
2598 }
2599 p++;
2600 q+=quantum_info->pad;
2601 }
2602 break;
2603 }
2604 if (quantum_info->quantum == 32UL)
2605 {
cristybb503372010-05-27 20:51:26 +00002606 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002607 {
cristy4cb162a2010-05-30 03:04:47 +00002608 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002609 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2610 q);
cristy4cb162a2010-05-30 03:04:47 +00002611 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002612 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2613 q);
cristy4cb162a2010-05-30 03:04:47 +00002614 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002615 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2616 q);
cristy4cb162a2010-05-30 03:04:47 +00002617 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
cristycee97112010-05-28 00:44:52 +00002618 p->opacity),range);
cristy02422272011-03-16 01:08:49 +00002619 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2620 q);
cristy891dc792010-03-04 01:47:16 +00002621 p++;
2622 q+=quantum_info->pad;
2623 }
2624 break;
2625 }
cristybb503372010-05-27 20:51:26 +00002626 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002627 {
cristy4cb162a2010-05-30 03:04:47 +00002628 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy02422272011-03-16 01:08:49 +00002629 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002630 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy02422272011-03-16 01:08:49 +00002631 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002632 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy02422272011-03-16 01:08:49 +00002633 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002634 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
cristycee97112010-05-28 00:44:52 +00002635 p->opacity),range);
cristy02422272011-03-16 01:08:49 +00002636 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
cristy891dc792010-03-04 01:47:16 +00002637 p++;
2638 q+=quantum_info->pad;
2639 }
2640 break;
2641 }
cristy3ed852e2009-09-05 21:47:34 +00002642 case 16:
2643 {
2644 register unsigned short
2645 pixel;
2646
cristyc9672a92010-01-06 00:57:45 +00002647 if (quantum_info->format == FloatingPointQuantumFormat)
2648 {
cristybb503372010-05-27 20:51:26 +00002649 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002650 {
cristy2a4d01c2010-01-10 21:14:51 +00002651 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002652 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002653 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002654 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002655 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002656 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002657 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002658 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002659 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002660 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002661 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002662 q=PopShortPixel(endian,pixel,q);
2663 p++;
2664 q+=quantum_info->pad;
2665 }
2666 break;
2667 }
cristybb503372010-05-27 20:51:26 +00002668 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002669 {
cristyce70c172010-01-07 17:15:30 +00002670 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002671 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002672 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002673 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002674 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002675 q=PopShortPixel(endian,pixel,q);
cristycee97112010-05-28 00:44:52 +00002676 pixel=ScaleQuantumToShort((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002677 q=PopShortPixel(endian,pixel,q);
2678 p++;
2679 q+=quantum_info->pad;
2680 }
2681 break;
2682 }
2683 case 32:
2684 {
cristy4cb162a2010-05-30 03:04:47 +00002685 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002686 pixel;
2687
2688 if (quantum_info->format == FloatingPointQuantumFormat)
2689 {
cristybb503372010-05-27 20:51:26 +00002690 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002691 {
2692 float
2693 pixel;
2694
2695 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2696 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2697 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
cristycee97112010-05-28 00:44:52 +00002698 pixel=(float) GetAlphaPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002699 q=PopFloatPixel(&quantum_state,pixel,q);
2700 p++;
2701 q+=quantum_info->pad;
2702 }
2703 break;
2704 }
cristybb503372010-05-27 20:51:26 +00002705 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002706 {
cristyce70c172010-01-07 17:15:30 +00002707 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002708 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002709 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002710 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002711 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002712 q=PopLongPixel(endian,pixel,q);
cristycee97112010-05-28 00:44:52 +00002713 pixel=ScaleQuantumToLong((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002714 q=PopLongPixel(endian,pixel,q);
2715 p++;
2716 q+=quantum_info->pad;
2717 }
2718 break;
2719 }
2720 case 64:
2721 {
2722 if (quantum_info->format == FloatingPointQuantumFormat)
2723 {
2724 double
2725 pixel;
2726
cristybb503372010-05-27 20:51:26 +00002727 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002728 {
2729 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2730 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2731 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
cristyeec18db2010-03-03 21:15:45 +00002732 pixel=(double) GetAlphaPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002733 q=PopDoublePixel(&quantum_state,pixel,q);
2734 p++;
2735 q+=quantum_info->pad;
2736 }
2737 break;
2738 }
2739 }
2740 default:
2741 {
cristy02422272011-03-16 01:08:49 +00002742 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002743 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002744 {
cristy02422272011-03-16 01:08:49 +00002745 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2746 ScaleQuantumToAny(GetRedPixelComponent(p),range),q);
2747 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2748 ScaleQuantumToAny(GetGreenPixelComponent(p),range),q);
2749 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2750 ScaleQuantumToAny(GetBluePixelComponent(p),range),q);
2751 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2752 ScaleQuantumToAny((Quantum) GetAlphaPixelComponent(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002753 p++;
2754 q+=quantum_info->pad;
2755 }
2756 break;
2757 }
2758 }
2759 break;
2760 }
2761 case CMYKQuantum:
2762 {
2763 if (image->colorspace != CMYKColorspace)
2764 {
2765 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2766 "ColorSeparatedImageRequired","`%s'",image->filename);
2767 return(extent);
2768 }
2769 switch (quantum_info->depth)
2770 {
2771 case 8:
2772 {
2773 register unsigned char
2774 pixel;
2775
cristybb503372010-05-27 20:51:26 +00002776 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002777 {
cristyce70c172010-01-07 17:15:30 +00002778 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002779 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002780 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002781 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002782 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002783 q=PopCharPixel(pixel,q);
2784 pixel=ScaleQuantumToChar(indexes[x]);
2785 q=PopCharPixel(pixel,q);
2786 p++;
2787 q+=quantum_info->pad;
2788 }
2789 break;
2790 }
2791 case 16:
2792 {
2793 register unsigned short
2794 pixel;
2795
cristyc9672a92010-01-06 00:57:45 +00002796 if (quantum_info->format == FloatingPointQuantumFormat)
2797 {
cristybb503372010-05-27 20:51:26 +00002798 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002799 {
cristy2a4d01c2010-01-10 21:14:51 +00002800 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002801 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002802 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002803 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002804 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002805 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002806 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002807 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002808 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002809 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00002810 q=PopShortPixel(endian,pixel,q);
2811 p++;
2812 q+=quantum_info->pad;
2813 }
2814 break;
2815 }
cristybb503372010-05-27 20:51:26 +00002816 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002817 {
cristyce70c172010-01-07 17:15:30 +00002818 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002819 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002820 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002821 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002822 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002823 q=PopShortPixel(endian,pixel,q);
2824 pixel=ScaleQuantumToShort(indexes[x]);
2825 q=PopShortPixel(endian,pixel,q);
2826 p++;
2827 q+=quantum_info->pad;
2828 }
2829 break;
2830 }
2831 case 32:
2832 {
cristy4cb162a2010-05-30 03:04:47 +00002833 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002834 pixel;
2835
2836 if (quantum_info->format == FloatingPointQuantumFormat)
2837 {
cristybb503372010-05-27 20:51:26 +00002838 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002839 {
2840 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2841 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2842 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2843 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
2844 p++;
2845 q+=quantum_info->pad;
2846 }
2847 break;
2848 }
cristybb503372010-05-27 20:51:26 +00002849 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002850 {
cristyce70c172010-01-07 17:15:30 +00002851 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002852 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002853 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002854 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002855 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002856 q=PopLongPixel(endian,pixel,q);
2857 pixel=ScaleQuantumToLong(indexes[x]);
2858 q=PopLongPixel(endian,pixel,q);
2859 p++;
2860 q+=quantum_info->pad;
2861 }
2862 break;
2863 }
2864 case 64:
2865 {
2866 if (quantum_info->format == FloatingPointQuantumFormat)
2867 {
cristybb503372010-05-27 20:51:26 +00002868 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002869 {
2870 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2871 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2872 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2873 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
2874 p++;
2875 q+=quantum_info->pad;
2876 }
2877 break;
2878 }
2879 }
2880 default:
2881 {
cristy02422272011-03-16 01:08:49 +00002882 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00002883 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002884 {
cristy02422272011-03-16 01:08:49 +00002885 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2886 ScaleQuantumToAny(p->red,range),q);
2887 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2888 ScaleQuantumToAny(p->green,range),q);
2889 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2890 ScaleQuantumToAny(p->blue,range),q);
2891 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2892 ScaleQuantumToAny(indexes[x],range),q);
cristy3ed852e2009-09-05 21:47:34 +00002893 p++;
2894 q+=quantum_info->pad;
2895 }
2896 break;
2897 }
2898 }
2899 break;
2900 }
2901 case CMYKAQuantum:
2902 case CMYKOQuantum:
2903 {
2904 if (image->colorspace != CMYKColorspace)
2905 {
2906 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2907 "ColorSeparatedImageRequired","`%s'",image->filename);
2908 return(extent);
2909 }
2910 switch (quantum_info->depth)
2911 {
2912 case 8:
2913 {
2914 register unsigned char
2915 pixel;
2916
cristybb503372010-05-27 20:51:26 +00002917 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002918 {
cristyce70c172010-01-07 17:15:30 +00002919 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002920 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002921 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002922 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002923 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002924 q=PopCharPixel(pixel,q);
2925 pixel=ScaleQuantumToChar(indexes[x]);
2926 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002927 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
2928 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002929 q=PopCharPixel(pixel,q);
2930 p++;
2931 q+=quantum_info->pad;
2932 }
2933 break;
2934 }
2935 case 16:
2936 {
2937 register unsigned short
2938 pixel;
2939
cristyc9672a92010-01-06 00:57:45 +00002940 if (quantum_info->format == FloatingPointQuantumFormat)
2941 {
cristybb503372010-05-27 20:51:26 +00002942 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002943 {
cristy2a4d01c2010-01-10 21:14:51 +00002944 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002945 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002946 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002947 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002948 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002949 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002950 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002951 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002952 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002953 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00002954 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002955 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002956 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002957 q=PopShortPixel(endian,pixel,q);
2958 p++;
2959 q+=quantum_info->pad;
2960 }
2961 break;
2962 }
cristybb503372010-05-27 20:51:26 +00002963 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002964 {
cristyce70c172010-01-07 17:15:30 +00002965 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002966 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002967 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002968 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002969 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002970 q=PopShortPixel(endian,pixel,q);
2971 pixel=ScaleQuantumToShort(indexes[x]);
2972 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002973 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
2974 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002975 q=PopShortPixel(endian,pixel,q);
2976 p++;
2977 q+=quantum_info->pad;
2978 }
2979 break;
2980 }
2981 case 32:
2982 {
cristy4cb162a2010-05-30 03:04:47 +00002983 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002984 pixel;
2985
2986 if (quantum_info->format == FloatingPointQuantumFormat)
2987 {
cristybb503372010-05-27 20:51:26 +00002988 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002989 {
2990 float
2991 pixel;
2992
2993 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2994 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2995 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2996 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +00002997 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002998 q=PopFloatPixel(&quantum_state,pixel,q);
2999 p++;
3000 q+=quantum_info->pad;
3001 }
3002 break;
3003 }
cristybb503372010-05-27 20:51:26 +00003004 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003005 {
cristyce70c172010-01-07 17:15:30 +00003006 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00003007 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00003008 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00003009 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00003010 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00003011 q=PopLongPixel(endian,pixel,q);
3012 pixel=ScaleQuantumToLong(indexes[x]);
3013 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00003014 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
3015 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00003016 q=PopLongPixel(endian,pixel,q);
3017 p++;
3018 q+=quantum_info->pad;
3019 }
3020 break;
3021 }
3022 case 64:
3023 {
3024 if (quantum_info->format == FloatingPointQuantumFormat)
3025 {
3026 double
3027 pixel;
3028
cristybb503372010-05-27 20:51:26 +00003029 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003030 {
3031 q=PopDoublePixel(&quantum_state,(double) p->red,q);
3032 q=PopDoublePixel(&quantum_state,(double) p->green,q);
3033 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
3034 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +00003035 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00003036 q=PopDoublePixel(&quantum_state,pixel,q);
3037 p++;
3038 q+=quantum_info->pad;
3039 }
3040 break;
3041 }
3042 }
3043 default:
3044 {
cristy02422272011-03-16 01:08:49 +00003045 range=GetQuantumRange(quantum_info->depth);
cristybb503372010-05-27 20:51:26 +00003046 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003047 {
cristy02422272011-03-16 01:08:49 +00003048 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3049 ScaleQuantumToAny(p->red,range),q);
3050 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3051 ScaleQuantumToAny(p->green,range),q);
3052 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3053 ScaleQuantumToAny(p->blue,range),q);
3054 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3055 ScaleQuantumToAny(indexes[x],range),q);
3056 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3057 ScaleQuantumToAny(p->opacity,range),q);
cristy3ed852e2009-09-05 21:47:34 +00003058 p++;
3059 q+=quantum_info->pad;
3060 }
3061 break;
3062 }
3063 }
3064 break;
3065 }
3066 case CbYCrYQuantum:
3067 {
cristy3ed852e2009-09-05 21:47:34 +00003068 Quantum
3069 cbcr[4];
3070
cristybb503372010-05-27 20:51:26 +00003071 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003072 i;
3073
cristy4cb162a2010-05-30 03:04:47 +00003074 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00003075 pixel;
3076
cristybb503372010-05-27 20:51:26 +00003077 size_t
cristy3ed852e2009-09-05 21:47:34 +00003078 quantum;
3079
cristy9d314ff2011-03-09 01:30:28 +00003080 ssize_t
3081 n;
3082
cristy3ed852e2009-09-05 21:47:34 +00003083 n=0;
3084 quantum=0;
cristy02422272011-03-16 01:08:49 +00003085 range=GetQuantumRange(quantum_info->depth);
cristy3ed852e2009-09-05 21:47:34 +00003086 switch (quantum_info->depth)
3087 {
3088 case 10:
3089 {
3090 if (quantum_info->pack == MagickFalse)
3091 {
cristybb503372010-05-27 20:51:26 +00003092 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00003093 {
3094 for (i=0; i < 4; i++)
3095 {
3096 switch (n % 3)
3097 {
3098 case 0:
3099 {
cristyce70c172010-01-07 17:15:30 +00003100 quantum=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003101 break;
3102 }
3103 case 1:
3104 {
cristyce70c172010-01-07 17:15:30 +00003105 quantum=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003106 break;
3107 }
3108 case 2:
3109 {
cristyce70c172010-01-07 17:15:30 +00003110 quantum=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003111 break;
3112 }
3113 }
3114 cbcr[i]=(Quantum) quantum;
3115 n++;
3116 }
cristy4cb162a2010-05-30 03:04:47 +00003117 pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 |
cristybb503372010-05-27 20:51:26 +00003118 (size_t) (cbcr[0]) << 12 |
3119 (size_t) (cbcr[2]) << 2);
cristy3ed852e2009-09-05 21:47:34 +00003120 q=PopLongPixel(endian,pixel,q);
3121 p++;
cristy4cb162a2010-05-30 03:04:47 +00003122 pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 |
cristybb503372010-05-27 20:51:26 +00003123 (size_t) (cbcr[0]) << 12 |
3124 (size_t) (cbcr[2]) << 2);
cristy3ed852e2009-09-05 21:47:34 +00003125 q=PopLongPixel(endian,pixel,q);
3126 p++;
3127 q+=quantum_info->pad;
3128 }
3129 break;
3130 }
3131 break;
3132 }
3133 default:
3134 {
cristybb503372010-05-27 20:51:26 +00003135 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00003136 {
3137 for (i=0; i < 4; i++)
3138 {
3139 switch (n % 3)
3140 {
3141 case 0:
3142 {
cristyce70c172010-01-07 17:15:30 +00003143 quantum=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003144 break;
3145 }
3146 case 1:
3147 {
cristyce70c172010-01-07 17:15:30 +00003148 quantum=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003149 break;
3150 }
3151 case 2:
3152 {
cristyce70c172010-01-07 17:15:30 +00003153 quantum=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00003154 break;
3155 }
3156 }
3157 cbcr[i]=(Quantum) quantum;
3158 n++;
3159 }
cristy02422272011-03-16 01:08:49 +00003160 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3161 ScaleQuantumToAny(cbcr[1],range),q);
3162 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3163 ScaleQuantumToAny(cbcr[0],range),q);
3164 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3165 ScaleQuantumToAny(cbcr[2],range),q);
cristy3ed852e2009-09-05 21:47:34 +00003166 p++;
cristy02422272011-03-16 01:08:49 +00003167 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3168 ScaleQuantumToAny(cbcr[3],range),q);
3169 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3170 ScaleQuantumToAny(cbcr[0],range),q);
3171 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3172 ScaleQuantumToAny(cbcr[2],range),q);
cristy3ed852e2009-09-05 21:47:34 +00003173 p++;
3174 q+=quantum_info->pad;
3175 }
3176 break;
3177 }
3178 }
3179 break;
3180 }
3181 default:
3182 break;
3183 }
3184 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3185 {
3186 Quantum
3187 quantum;
3188
3189 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003190 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003191
3192 q=GetAuthenticPixelQueue(image);
3193 if (image_view != (CacheView *) NULL)
3194 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003195 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003196 {
3197 quantum=q->red;
3198 q->red=q->green;
3199 q->green=quantum;
3200 q++;
3201 }
3202 }
cristya6a96a12010-08-23 13:37:35 +00003203 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
3204 (quantum_type == BGROQuantum))
cristy3ed852e2009-09-05 21:47:34 +00003205 {
3206 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003207 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003208
3209 q=GetAuthenticPixelQueue(image);
3210 if (image_view != (CacheView *) NULL)
3211 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003212 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003213 {
cristy46f08202010-01-10 04:04:21 +00003214 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00003215 q++;
3216 }
3217 }
3218 return(extent);
3219}