blob: cdfc1da9180243bfce685f3fc9ac5f7957b12c56 [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
cristybb503372010-05-27 20:51:26 +0000243 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000244 bit;
245
246 MagickRealType
247 alpha;
248
249 MagickSizeType
250 number_pixels;
251
252 QuantumAny
253 range;
254
255 QuantumState
256 quantum_state;
257
258 register const IndexPacket
cristyaebafa22009-11-26 01:48:56 +0000259 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000260
261 register const PixelPacket
cristyaebafa22009-11-26 01:48:56 +0000262 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000263
cristybb503372010-05-27 20:51:26 +0000264 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000265 x;
266
267 register unsigned char
cristyaebafa22009-11-26 01:48:56 +0000268 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000269
270 size_t
271 extent;
272
273 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);
cristyce70c172010-01-07 17:15:30 +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 }
313 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
314 {
315 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000316 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000317
318 q=GetAuthenticPixelQueue(image);
319 if (image_view != (CacheView *) NULL)
320 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +0000321 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000322 {
cristy46f08202010-01-10 04:04:21 +0000323 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +0000324 q++;
325 }
326 }
327 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
328 {
329 Quantum
330 quantum;
331
332 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000333 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000334
335 q=GetAuthenticPixelQueue(image);
336 if (image_view != (CacheView *) NULL)
337 q=GetAuthenticPixelQueue(image);
cristybb503372010-05-27 20:51:26 +0000338 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000339 {
340 quantum=q->red;
341 q->red=q->green;
342 q->green=quantum;
343 q++;
344 }
345 }
346 x=0;
347 q=pixels;
348 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
349 extent=GetQuantumExtent(image,quantum_info,quantum_type);
350 endian=quantum_state.endian;
351 switch (quantum_type)
352 {
353 case IndexQuantum:
354 {
355 if (image->storage_class != PseudoClass)
356 {
357 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
358 "ColormappedImageRequired","`%s'",image->filename);
359 return(extent);
360 }
361 switch (quantum_info->depth)
362 {
363 case 1:
364 {
365 register unsigned char
366 pixel;
367
cristybb503372010-05-27 20:51:26 +0000368 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
cristy3ed852e2009-09-05 21:47:34 +0000369 {
370 pixel=(unsigned char) *indexes++;
371 *q=((pixel & 0x01) << 7);
372 pixel=(unsigned char) *indexes++;
373 *q|=((pixel & 0x01) << 6);
374 pixel=(unsigned char) *indexes++;
375 *q|=((pixel & 0x01) << 5);
376 pixel=(unsigned char) *indexes++;
377 *q|=((pixel & 0x01) << 4);
378 pixel=(unsigned char) *indexes++;
379 *q|=((pixel & 0x01) << 3);
380 pixel=(unsigned char) *indexes++;
381 *q|=((pixel & 0x01) << 2);
382 pixel=(unsigned char) *indexes++;
383 *q|=((pixel & 0x01) << 1);
384 pixel=(unsigned char) *indexes++;
385 *q|=((pixel & 0x01) << 0);
386 q++;
387 }
388 if ((number_pixels % 8) != 0)
389 {
390 *q='\0';
cristybb503372010-05-27 20:51:26 +0000391 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
cristy3ed852e2009-09-05 21:47:34 +0000392 {
393 pixel=(unsigned char) *indexes++;
394 *q|=((pixel & 0x01) << (unsigned char) bit);
395 }
396 q++;
397 }
398 break;
399 }
400 case 4:
401 {
402 register unsigned char
403 pixel;
404
cristybb503372010-05-27 20:51:26 +0000405 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000406 {
407 pixel=(unsigned char) *indexes++;
408 *q=((pixel & 0xf) << 4);
409 pixel=(unsigned char) *indexes++;
410 *q|=((pixel & 0xf) << 0);
411 q++;
412 }
413 if ((number_pixels % 2) != 0)
414 {
415 pixel=(unsigned char) *indexes++;
416 *q=((pixel & 0xf) << 4);
417 q++;
418 }
419 break;
420 }
421 case 8:
422 {
cristybb503372010-05-27 20:51:26 +0000423 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000424 {
425 q=PopCharPixel((unsigned char) indexes[x],q);
426 q+=quantum_info->pad;
427 }
428 break;
429 }
430 case 16:
431 {
cristyc9672a92010-01-06 00:57:45 +0000432 if (quantum_info->format == FloatingPointQuantumFormat)
433 {
cristybb503372010-05-27 20:51:26 +0000434 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000435 {
cristy2a4d01c2010-01-10 21:14:51 +0000436 q=PopShortPixel(endian,SinglePrecisionToHalf(QuantumScale*
cristyc9672a92010-01-06 00:57:45 +0000437 indexes[x]),q);
438 q+=quantum_info->pad;
439 }
440 break;
441 }
cristybb503372010-05-27 20:51:26 +0000442 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000443 {
444 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
445 q+=quantum_info->pad;
446 }
447 break;
448 }
449 case 32:
450 {
451 if (quantum_info->format == FloatingPointQuantumFormat)
452 {
cristybb503372010-05-27 20:51:26 +0000453 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000454 {
455 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
456 p++;
457 q+=quantum_info->pad;
458 }
459 break;
460 }
cristybb503372010-05-27 20:51:26 +0000461 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000462 {
cristy4cb162a2010-05-30 03:04:47 +0000463 q=PopLongPixel(endian,(unsigned int) indexes[x],q);
cristy3ed852e2009-09-05 21:47:34 +0000464 q+=quantum_info->pad;
465 }
466 break;
467 }
468 case 64:
469 {
470 if (quantum_info->format == FloatingPointQuantumFormat)
471 {
cristybb503372010-05-27 20:51:26 +0000472 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000473 {
474 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
475 p++;
476 q+=quantum_info->pad;
477 }
478 break;
479 }
480 }
481 default:
482 {
cristybb503372010-05-27 20:51:26 +0000483 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000484 {
485 q=PopQuantumPixel(&quantum_state,image->depth,indexes[x],q);
486 p++;
487 q+=quantum_info->pad;
488 }
489 break;
490 }
491 }
492 break;
493 }
494 case IndexAlphaQuantum:
495 {
496 if (image->storage_class != PseudoClass)
497 {
498 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
499 "ColormappedImageRequired","`%s'",image->filename);
500 return(extent);
501 }
502 switch (quantum_info->depth)
503 {
504 case 1:
505 {
506 register unsigned char
507 pixel;
508
cristybb503372010-05-27 20:51:26 +0000509 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
cristy3ed852e2009-09-05 21:47:34 +0000510 {
511 pixel=(unsigned char) *indexes++;
512 *q=((pixel & 0x01) << 7);
513 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
514 1 : 0);
515 *q|=((pixel & 0x01) << 6);
516 p++;
517 pixel=(unsigned char) *indexes++;
518 *q|=((pixel & 0x01) << 5);
519 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
520 1 : 0);
521 *q|=((pixel & 0x01) << 4);
522 p++;
523 pixel=(unsigned char) *indexes++;
524 *q|=((pixel & 0x01) << 3);
525 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
526 1 : 0);
527 *q|=((pixel & 0x01) << 2);
528 p++;
529 pixel=(unsigned char) *indexes++;
530 *q|=((pixel & 0x01) << 1);
531 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
532 1 : 0);
533 *q|=((pixel & 0x01) << 0);
534 p++;
535 q++;
536 }
537 if ((number_pixels % 4) != 0)
538 {
539 *q='\0';
cristybb503372010-05-27 20:51:26 +0000540 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
cristy3ed852e2009-09-05 21:47:34 +0000541 {
542 pixel=(unsigned char) *indexes++;
cristyb32b90a2009-09-07 21:45:48 +0000543 *q|=((pixel & 0x01) << (unsigned char) (bit+4));
cristy3ed852e2009-09-05 21:47:34 +0000544 pixel=(unsigned char) (p->opacity == (Quantum)
545 TransparentOpacity ? 1 : 0);
cristyb32b90a2009-09-07 21:45:48 +0000546 *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
cristy3ed852e2009-09-05 21:47:34 +0000547 p++;
548 }
549 q++;
550 }
551 break;
552 }
553 case 4:
554 {
555 register unsigned char
556 pixel;
557
cristybb503372010-05-27 20:51:26 +0000558 for (x=0; x < (ssize_t) number_pixels ; x++)
cristy3ed852e2009-09-05 21:47:34 +0000559 {
560 pixel=(unsigned char) *indexes++;
561 *q=((pixel & 0xf) << 4);
562 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +0000563 GetOpacityPixelComponent(p)))+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000564 *q|=((pixel & 0xf) << 0);
565 p++;
566 q++;
567 }
568 break;
569 }
570 case 8:
571 {
572 register unsigned char
573 pixel;
574
cristybb503372010-05-27 20:51:26 +0000575 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000576 {
577 q=PopCharPixel((unsigned char) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000578 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
579 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000580 q=PopCharPixel(pixel,q);
581 p++;
582 q+=quantum_info->pad;
583 }
584 break;
585 }
586 case 16:
587 {
588 register unsigned short
589 pixel;
590
cristyc9672a92010-01-06 00:57:45 +0000591 if (quantum_info->format == FloatingPointQuantumFormat)
592 {
cristybb503372010-05-27 20:51:26 +0000593 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000594 {
595 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
cristy2a4d01c2010-01-10 21:14:51 +0000596 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +0000597 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +0000598 q=PopShortPixel(endian,pixel,q);
599 p++;
600 q+=quantum_info->pad;
601 }
602 break;
603 }
cristybb503372010-05-27 20:51:26 +0000604 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000605 {
606 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000607 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
608 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000609 q=PopShortPixel(endian,pixel,q);
610 p++;
611 q+=quantum_info->pad;
612 }
613 break;
614 }
615 case 32:
616 {
cristy4cb162a2010-05-30 03:04:47 +0000617 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000618 pixel;
619
620 if (quantum_info->format == FloatingPointQuantumFormat)
621 {
cristybb503372010-05-27 20:51:26 +0000622 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000623 {
624 float
625 pixel;
626
627 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +0000628 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000629 q=PopFloatPixel(&quantum_state,pixel,q);
630 p++;
631 q+=quantum_info->pad;
632 }
633 break;
634 }
cristybb503372010-05-27 20:51:26 +0000635 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000636 {
cristy4cb162a2010-05-30 03:04:47 +0000637 q=PopLongPixel(endian,(unsigned int) indexes[x],q);
cristyce70c172010-01-07 17:15:30 +0000638 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
639 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +0000640 q=PopLongPixel(endian,pixel,q);
641 p++;
642 q+=quantum_info->pad;
643 }
644 break;
645 }
646 case 64:
647 {
648 if (quantum_info->format == FloatingPointQuantumFormat)
649 {
cristybb503372010-05-27 20:51:26 +0000650 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000651 {
652 double
653 pixel;
654
655 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +0000656 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +0000657 q=PopDoublePixel(&quantum_state,pixel,q);
658 p++;
659 q+=quantum_info->pad;
660 }
661 break;
662 }
663 }
664 default:
665 {
666 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000667 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000668 {
669 q=PopQuantumPixel(&quantum_state,image->depth,indexes[x],q);
670 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristy46f08202010-01-10 04:04:21 +0000671 (Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +0000672 p++;
673 q+=quantum_info->pad;
674 }
675 break;
676 }
677 }
678 break;
679 }
680 case GrayQuantum:
681 {
682 switch (quantum_info->depth)
683 {
684 case 1:
685 {
686 register Quantum
687 threshold;
688
689 register unsigned char
690 black,
691 white;
692
693 black=0x00;
694 white=0x01;
695 if (quantum_info->min_is_white != MagickFalse)
696 {
697 black=0x01;
698 white=0x00;
699 }
700 threshold=(Quantum) (QuantumRange/2);
cristybb503372010-05-27 20:51:26 +0000701 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
cristy3ed852e2009-09-05 21:47:34 +0000702 {
703 *q='\0';
704 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 7;
705 p++;
706 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 6;
707 p++;
708 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 5;
709 p++;
710 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 4;
711 p++;
712 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 3;
713 p++;
714 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 2;
715 p++;
716 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 1;
717 p++;
718 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 0;
719 p++;
720 q++;
721 }
722 if ((number_pixels % 8) != 0)
723 {
724 *q='\0';
cristybb503372010-05-27 20:51:26 +0000725 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
cristy3ed852e2009-09-05 21:47:34 +0000726 {
727 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) <<
728 bit;
729 p++;
730 }
731 q++;
732 }
733 break;
734 }
735 case 4:
736 {
737 register unsigned char
738 pixel;
739
cristybb503372010-05-27 20:51:26 +0000740 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000741 {
742 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
743 *q=(((pixel >> 4) & 0xf) << 4);
744 p++;
745 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
746 *q|=pixel >> 4;
747 p++;
748 q++;
749 }
750 if ((number_pixels % 2) != 0)
751 {
752 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
753 *q=(((pixel >> 4) & 0xf) << 4);
754 p++;
755 q++;
756 }
757 break;
758 }
759 case 8:
760 {
761 register unsigned char
762 pixel;
763
cristybb503372010-05-27 20:51:26 +0000764 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000765 {
766 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
767 q=PopCharPixel(pixel,q);
768 p++;
769 q+=quantum_info->pad;
770 }
771 break;
772 }
773 case 10:
774 {
cristy3ed852e2009-09-05 21:47:34 +0000775 range=GetQuantumRange(image->depth);
776 if (quantum_info->pack == MagickFalse)
777 {
cristy4cb162a2010-05-30 03:04:47 +0000778 register unsigned int
cristyff024b42010-02-21 22:55:09 +0000779 pixel;
780
cristybb503372010-05-27 20:51:26 +0000781 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +0000782 {
cristy4cb162a2010-05-30 03:04:47 +0000783 pixel=(unsigned int) (
cristyff024b42010-02-21 22:55:09 +0000784 ScaleQuantumToAny(PixelIntensityToQuantum(p+2),range) << 22 |
785 ScaleQuantumToAny(PixelIntensityToQuantum(p+1),range) << 12 |
786 ScaleQuantumToAny(PixelIntensityToQuantum(p+0),range) << 2);
787 q=PopLongPixel(endian,pixel,q);
788 p+=3;
cristy3ed852e2009-09-05 21:47:34 +0000789 q+=quantum_info->pad;
790 }
cristy69702dd2010-02-22 15:26:39 +0000791 pixel=0UL;
cristybb503372010-05-27 20:51:26 +0000792 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +0000793 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+1),
794 range) << 12;
cristybb503372010-05-27 20:51:26 +0000795 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +0000796 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+0),
797 range) << 2;
798 q=PopLongPixel(endian,pixel,q);
cristy3ed852e2009-09-05 21:47:34 +0000799 break;
800 }
cristybb503372010-05-27 20:51:26 +0000801 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000802 {
803 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
804 PixelIntensityToQuantum(p),range),q);
805 p++;
806 q+=quantum_info->pad;
807 }
808 break;
809 }
810 case 12:
811 {
812 register unsigned short
813 pixel;
814
815 range=GetQuantumRange(image->depth);
816 if (quantum_info->pack == MagickFalse)
817 {
cristybb503372010-05-27 20:51:26 +0000818 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000819 {
820 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
821 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
822 p++;
823 q+=quantum_info->pad;
824 }
825 break;
826 }
cristybb503372010-05-27 20:51:26 +0000827 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000828 {
829 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
830 PixelIntensityToQuantum(p),range),q);
831 p++;
832 q+=quantum_info->pad;
833 }
834 break;
835 }
836 case 16:
837 {
838 register unsigned short
839 pixel;
840
cristyc9672a92010-01-06 00:57:45 +0000841 if (quantum_info->format == FloatingPointQuantumFormat)
842 {
cristybb503372010-05-27 20:51:26 +0000843 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000844 {
cristy2a4d01c2010-01-10 21:14:51 +0000845 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +0000846 PixelIntensityToQuantum(p));
cristyc9672a92010-01-06 00:57:45 +0000847 q=PopShortPixel(endian,pixel,q);
848 p++;
849 q+=quantum_info->pad;
850 }
851 break;
852 }
cristybb503372010-05-27 20:51:26 +0000853 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000854 {
855 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
856 q=PopShortPixel(endian,pixel,q);
857 p++;
858 q+=quantum_info->pad;
859 }
860 break;
861 }
862 case 32:
863 {
cristy4cb162a2010-05-30 03:04:47 +0000864 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000865 pixel;
866
867 if (quantum_info->format == FloatingPointQuantumFormat)
868 {
cristybb503372010-05-27 20:51:26 +0000869 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000870 {
871 float
872 pixel;
873
874 pixel=(float) PixelIntensityToQuantum(p);
875 q=PopFloatPixel(&quantum_state,pixel,q);
876 p++;
877 q+=quantum_info->pad;
878 }
879 break;
880 }
cristybb503372010-05-27 20:51:26 +0000881 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000882 {
883 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
884 q=PopLongPixel(endian,pixel,q);
885 p++;
886 q+=quantum_info->pad;
887 }
888 break;
889 }
890 case 64:
891 {
892 if (quantum_info->format == FloatingPointQuantumFormat)
893 {
cristybb503372010-05-27 20:51:26 +0000894 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000895 {
896 double
897 pixel;
898
899 pixel=(double) PixelIntensityToQuantum(p);
900 q=PopDoublePixel(&quantum_state,pixel,q);
901 p++;
902 q+=quantum_info->pad;
903 }
904 break;
905 }
906 }
907 default:
908 {
909 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000910 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000911 {
912 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
913 PixelIntensityToQuantum(p),range),q);
914 p++;
915 q+=quantum_info->pad;
916 }
917 break;
918 }
919 }
920 break;
921 }
922 case GrayAlphaQuantum:
923 {
924 switch (quantum_info->depth)
925 {
926 case 1:
927 {
928 register Quantum
929 threshold;
930
931 register unsigned char
932 black,
933 pixel,
934 white;
935
936 black=0x00;
937 white=0x01;
938 if (quantum_info->min_is_white == MagickFalse)
939 {
940 black=0x01;
941 white=0x00;
942 }
943 threshold=(Quantum) (QuantumRange/2);
cristybb503372010-05-27 20:51:26 +0000944 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
cristy3ed852e2009-09-05 21:47:34 +0000945 {
946 *q='\0';
947 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 7;
948 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
949 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
950 p++;
951 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 5;
952 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
953 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
954 p++;
955 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 3;
956 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
957 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
958 p++;
959 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 1;
960 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
961 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
962 p++;
963 q++;
964 }
965 if ((number_pixels % 4) != 0)
966 {
967 *q='\0';
cristybb503372010-05-27 20:51:26 +0000968 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
cristy3ed852e2009-09-05 21:47:34 +0000969 {
970 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) <<
cristyb32b90a2009-09-07 21:45:48 +0000971 (bit+4);
cristy3ed852e2009-09-05 21:47:34 +0000972 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 :
973 0x01);
974 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
cristyb32b90a2009-09-07 21:45:48 +0000975 (bit+4-1));
cristy3ed852e2009-09-05 21:47:34 +0000976 p++;
977 }
978 q++;
979 }
980 break;
981 }
982 case 4:
983 {
984 register unsigned char
985 pixel;
986
cristybb503372010-05-27 20:51:26 +0000987 for (x=0; x < (ssize_t) number_pixels ; x++)
cristy3ed852e2009-09-05 21:47:34 +0000988 {
989 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
990 *q=(((pixel >> 4) & 0xf) << 4);
991 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
cristyce70c172010-01-07 17:15:30 +0000992 GetOpacityPixelComponent(p)))+0.5);
cristy3ed852e2009-09-05 21:47:34 +0000993 *q|=pixel & 0xf;
994 p++;
995 q++;
996 }
997 break;
998 }
999 case 8:
1000 {
1001 register unsigned char
1002 pixel;
1003
cristybb503372010-05-27 20:51:26 +00001004 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001005 {
1006 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1007 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00001008 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1009 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001010 q=PopCharPixel(pixel,q);
1011 p++;
1012 q+=quantum_info->pad;
1013 }
1014 break;
1015 }
1016 case 16:
1017 {
1018 register unsigned short
1019 pixel;
1020
cristyc9672a92010-01-06 00:57:45 +00001021 if (quantum_info->format == FloatingPointQuantumFormat)
1022 {
cristybb503372010-05-27 20:51:26 +00001023 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001024 {
cristy2a4d01c2010-01-10 21:14:51 +00001025 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001026 PixelIntensityToQuantum(p));
cristyc9672a92010-01-06 00:57:45 +00001027 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00001028 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001029 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001030 q=PopShortPixel(endian,pixel,q);
1031 p++;
1032 q+=quantum_info->pad;
1033 }
1034 break;
1035 }
cristybb503372010-05-27 20:51:26 +00001036 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001037 {
1038 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
1039 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001040 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1041 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001042 q=PopShortPixel(endian,pixel,q);
1043 p++;
1044 q+=quantum_info->pad;
1045 }
1046 break;
1047 }
1048 case 32:
1049 {
cristy4cb162a2010-05-30 03:04:47 +00001050 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001051 pixel;
1052
1053 if (quantum_info->format == FloatingPointQuantumFormat)
1054 {
cristybb503372010-05-27 20:51:26 +00001055 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001056 {
1057 float
1058 pixel;
1059
1060 pixel=(float) PixelIntensityToQuantum(p);
1061 q=PopFloatPixel(&quantum_state,pixel,q);
cristy46f08202010-01-10 04:04:21 +00001062 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001063 q=PopFloatPixel(&quantum_state,pixel,q);
1064 p++;
1065 q+=quantum_info->pad;
1066 }
1067 break;
1068 }
cristybb503372010-05-27 20:51:26 +00001069 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001070 {
1071 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
1072 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001073 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
1074 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001075 q=PopLongPixel(endian,pixel,q);
1076 p++;
1077 q+=quantum_info->pad;
1078 }
1079 break;
1080 }
1081 case 64:
1082 {
1083 if (quantum_info->format == FloatingPointQuantumFormat)
1084 {
cristybb503372010-05-27 20:51:26 +00001085 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001086 {
1087 double
1088 pixel;
1089
1090 pixel=(double) PixelIntensityToQuantum(p);
1091 q=PopDoublePixel(&quantum_state,pixel,q);
cristy46f08202010-01-10 04:04:21 +00001092 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001093 q=PopDoublePixel(&quantum_state,pixel,q);
1094 p++;
1095 q+=quantum_info->pad;
1096 }
1097 break;
1098 }
1099 }
1100 default:
1101 {
1102 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001103 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001104 {
1105 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1106 PixelIntensityToQuantum(p),range),q);
1107 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristy46f08202010-01-10 04:04:21 +00001108 (Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001109 p++;
1110 q+=quantum_info->pad;
1111 }
1112 break;
1113 }
1114 }
1115 break;
1116 }
1117 case RedQuantum:
1118 case CyanQuantum:
1119 {
1120 switch (quantum_info->depth)
1121 {
1122 case 8:
1123 {
1124 register unsigned char
1125 pixel;
1126
cristybb503372010-05-27 20:51:26 +00001127 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001128 {
cristyce70c172010-01-07 17:15:30 +00001129 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001130 q=PopCharPixel(pixel,q);
1131 p++;
1132 q+=quantum_info->pad;
1133 }
1134 break;
1135 }
1136 case 16:
1137 {
1138 register unsigned short
1139 pixel;
1140
cristyc9672a92010-01-06 00:57:45 +00001141 if (quantum_info->format == FloatingPointQuantumFormat)
1142 {
cristybb503372010-05-27 20:51:26 +00001143 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001144 {
cristy2a4d01c2010-01-10 21:14:51 +00001145 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001146 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001147 q=PopShortPixel(endian,pixel,q);
1148 p++;
1149 q+=quantum_info->pad;
1150 }
1151 break;
1152 }
cristybb503372010-05-27 20:51:26 +00001153 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001154 {
cristyce70c172010-01-07 17:15:30 +00001155 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001156 q=PopShortPixel(endian,pixel,q);
1157 p++;
1158 q+=quantum_info->pad;
1159 }
1160 break;
1161 }
1162 case 32:
1163 {
cristy4cb162a2010-05-30 03:04:47 +00001164 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001165 pixel;
1166
1167 if (quantum_info->format == FloatingPointQuantumFormat)
1168 {
cristybb503372010-05-27 20:51:26 +00001169 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001170 {
1171 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1172 p++;
1173 q+=quantum_info->pad;
1174 }
1175 break;
1176 }
cristybb503372010-05-27 20:51:26 +00001177 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001178 {
cristyce70c172010-01-07 17:15:30 +00001179 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001180 q=PopLongPixel(endian,pixel,q);
1181 p++;
1182 q+=quantum_info->pad;
1183 }
1184 break;
1185 }
1186 case 64:
1187 {
1188 if (quantum_info->format == FloatingPointQuantumFormat)
1189 {
cristybb503372010-05-27 20:51:26 +00001190 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001191 {
1192 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1193 p++;
1194 q+=quantum_info->pad;
1195 }
1196 break;
1197 }
1198 }
1199 default:
1200 {
1201 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001202 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001203 {
1204 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1205 p->red,range),q);
1206 p++;
1207 q+=quantum_info->pad;
1208 }
1209 break;
1210 }
1211 }
1212 break;
1213 }
1214 case GreenQuantum:
1215 case MagentaQuantum:
1216 {
1217 switch (quantum_info->depth)
1218 {
1219 case 8:
1220 {
1221 register unsigned char
1222 pixel;
1223
cristybb503372010-05-27 20:51:26 +00001224 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001225 {
cristyce70c172010-01-07 17:15:30 +00001226 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001227 q=PopCharPixel(pixel,q);
1228 p++;
1229 q+=quantum_info->pad;
1230 }
1231 break;
1232 }
1233 case 16:
1234 {
1235 register unsigned short
1236 pixel;
1237
cristyc9672a92010-01-06 00:57:45 +00001238 if (quantum_info->format == FloatingPointQuantumFormat)
1239 {
cristybb503372010-05-27 20:51:26 +00001240 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001241 {
cristy2a4d01c2010-01-10 21:14:51 +00001242 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001243 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001244 q=PopShortPixel(endian,pixel,q);
1245 p++;
1246 q+=quantum_info->pad;
1247 }
1248 break;
1249 }
cristybb503372010-05-27 20:51:26 +00001250 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001251 {
cristyce70c172010-01-07 17:15:30 +00001252 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001253 q=PopShortPixel(endian,pixel,q);
1254 p++;
1255 q+=quantum_info->pad;
1256 }
1257 break;
1258 }
1259 case 32:
1260 {
cristy4cb162a2010-05-30 03:04:47 +00001261 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001262 pixel;
1263
1264 if (quantum_info->format == FloatingPointQuantumFormat)
1265 {
cristybb503372010-05-27 20:51:26 +00001266 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001267 {
1268 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1269 p++;
1270 q+=quantum_info->pad;
1271 }
1272 break;
1273 }
cristybb503372010-05-27 20:51:26 +00001274 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001275 {
cristyce70c172010-01-07 17:15:30 +00001276 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001277 q=PopLongPixel(endian,pixel,q);
1278 p++;
1279 q+=quantum_info->pad;
1280 }
1281 break;
1282 }
1283 case 64:
1284 {
1285 if (quantum_info->format == FloatingPointQuantumFormat)
1286 {
cristybb503372010-05-27 20:51:26 +00001287 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001288 {
1289 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1290 p++;
1291 q+=quantum_info->pad;
1292 }
1293 break;
1294 }
1295 }
1296 default:
1297 {
1298 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001299 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001300 {
1301 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1302 p->green,range),q);
1303 p++;
1304 q+=quantum_info->pad;
1305 }
1306 break;
1307 }
1308 }
1309 break;
1310 }
1311 case BlueQuantum:
1312 case YellowQuantum:
1313 {
1314 switch (quantum_info->depth)
1315 {
1316 case 8:
1317 {
1318 register unsigned char
1319 pixel;
1320
cristybb503372010-05-27 20:51:26 +00001321 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001322 {
cristyce70c172010-01-07 17:15:30 +00001323 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001324 q=PopCharPixel(pixel,q);
1325 p++;
1326 q+=quantum_info->pad;
1327 }
1328 break;
1329 }
1330 case 16:
1331 {
1332 register unsigned short
1333 pixel;
1334
cristyc9672a92010-01-06 00:57:45 +00001335 if (quantum_info->format == FloatingPointQuantumFormat)
1336 {
cristybb503372010-05-27 20:51:26 +00001337 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001338 {
cristy2a4d01c2010-01-10 21:14:51 +00001339 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001340 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001341 q=PopShortPixel(endian,pixel,q);
1342 p++;
1343 q+=quantum_info->pad;
1344 }
1345 break;
1346 }
cristybb503372010-05-27 20:51:26 +00001347 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001348 {
cristyce70c172010-01-07 17:15:30 +00001349 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001350 q=PopShortPixel(endian,pixel,q);
1351 p++;
1352 q+=quantum_info->pad;
1353 }
1354 break;
1355 }
1356 case 32:
1357 {
cristy4cb162a2010-05-30 03:04:47 +00001358 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001359 pixel;
1360
1361 if (quantum_info->format == FloatingPointQuantumFormat)
1362 {
cristybb503372010-05-27 20:51:26 +00001363 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001364 {
1365 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1366 p++;
1367 q+=quantum_info->pad;
1368 }
1369 break;
1370 }
cristybb503372010-05-27 20:51:26 +00001371 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001372 {
cristyce70c172010-01-07 17:15:30 +00001373 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001374 q=PopLongPixel(endian,pixel,q);
1375 p++;
1376 q+=quantum_info->pad;
1377 }
1378 break;
1379 }
1380 case 64:
1381 {
1382 if (quantum_info->format == FloatingPointQuantumFormat)
1383 {
cristybb503372010-05-27 20:51:26 +00001384 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001385 {
1386 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1387 p++;
1388 q+=quantum_info->pad;
1389 }
1390 break;
1391 }
1392 }
1393 default:
1394 {
1395 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001396 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001397 {
1398 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1399 p->blue,range),q);
1400 p++;
1401 q+=quantum_info->pad;
1402 }
1403 break;
1404 }
1405 }
1406 break;
1407 }
1408 case AlphaQuantum:
1409 {
1410 switch (quantum_info->depth)
1411 {
1412 case 8:
1413 {
1414 register unsigned char
1415 pixel;
1416
cristybb503372010-05-27 20:51:26 +00001417 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001418 {
cristyce70c172010-01-07 17:15:30 +00001419 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1420 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001421 q=PopCharPixel(pixel,q);
1422 p++;
1423 q+=quantum_info->pad;
1424 }
1425 break;
1426 }
1427 case 16:
1428 {
1429 register unsigned short
1430 pixel;
1431
cristyc9672a92010-01-06 00:57:45 +00001432 if (quantum_info->format == FloatingPointQuantumFormat)
1433 {
cristybb503372010-05-27 20:51:26 +00001434 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001435 {
cristy2a4d01c2010-01-10 21:14:51 +00001436 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001437 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001438 q=PopShortPixel(endian,pixel,q);
1439 p++;
1440 q+=quantum_info->pad;
1441 }
1442 break;
1443 }
cristybb503372010-05-27 20:51:26 +00001444 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001445 {
cristyce70c172010-01-07 17:15:30 +00001446 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1447 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001448 q=PopShortPixel(endian,pixel,q);
1449 p++;
1450 q+=quantum_info->pad;
1451 }
1452 break;
1453 }
1454 case 32:
1455 {
cristy4cb162a2010-05-30 03:04:47 +00001456 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001457 pixel;
1458
1459 if (quantum_info->format == FloatingPointQuantumFormat)
1460 {
cristybb503372010-05-27 20:51:26 +00001461 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001462 {
1463 float
1464 pixel;
1465
cristy46f08202010-01-10 04:04:21 +00001466 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001467 q=PopFloatPixel(&quantum_state,pixel,q);
1468 p++;
1469 q+=quantum_info->pad;
1470 }
1471 break;
1472 }
cristybb503372010-05-27 20:51:26 +00001473 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001474 {
cristyce70c172010-01-07 17:15:30 +00001475 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
1476 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00001477 q=PopLongPixel(endian,pixel,q);
1478 p++;
1479 q+=quantum_info->pad;
1480 }
1481 break;
1482 }
1483 case 64:
1484 {
1485 if (quantum_info->format == FloatingPointQuantumFormat)
1486 {
cristybb503372010-05-27 20:51:26 +00001487 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001488 {
1489 double
1490 pixel;
1491
cristy46f08202010-01-10 04:04:21 +00001492 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001493 q=PopDoublePixel(&quantum_state,pixel,q);
1494 p++;
1495 q+=quantum_info->pad;
1496 }
1497 break;
1498 }
1499 }
1500 default:
1501 {
1502 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001503 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001504 {
1505 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristy46f08202010-01-10 04:04:21 +00001506 (Quantum) (GetAlphaPixelComponent(p)),range),q);
cristy3ed852e2009-09-05 21:47:34 +00001507 p++;
1508 q+=quantum_info->pad;
1509 }
1510 break;
1511 }
1512 }
1513 break;
1514 }
1515 case OpacityQuantum:
1516 {
1517 switch (quantum_info->depth)
1518 {
1519 case 8:
1520 {
1521 register unsigned char
1522 pixel;
1523
cristybb503372010-05-27 20:51:26 +00001524 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001525 {
cristyce70c172010-01-07 17:15:30 +00001526 pixel=ScaleQuantumToChar(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001527 q=PopCharPixel(pixel,q);
1528 p++;
1529 q+=quantum_info->pad;
1530 }
1531 break;
1532 }
1533 case 16:
1534 {
1535 register unsigned short
1536 pixel;
1537
cristyc9672a92010-01-06 00:57:45 +00001538 if (quantum_info->format == FloatingPointQuantumFormat)
1539 {
cristybb503372010-05-27 20:51:26 +00001540 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001541 {
cristy2a4d01c2010-01-10 21:14:51 +00001542 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001543 GetOpacityPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001544 q=PopShortPixel(endian,pixel,q);
1545 p++;
1546 q+=quantum_info->pad;
1547 }
1548 break;
1549 }
cristybb503372010-05-27 20:51:26 +00001550 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001551 {
cristyce70c172010-01-07 17:15:30 +00001552 pixel=ScaleQuantumToShort(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001553 q=PopShortPixel(endian,pixel,q);
1554 p++;
1555 q+=quantum_info->pad;
1556 }
1557 break;
1558 }
1559 case 32:
1560 {
cristy4cb162a2010-05-30 03:04:47 +00001561 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001562 pixel;
1563
1564 if (quantum_info->format == FloatingPointQuantumFormat)
1565 {
cristybb503372010-05-27 20:51:26 +00001566 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001567 {
1568 q=PopFloatPixel(&quantum_state,(float) p->opacity,q);
1569 p++;
1570 q+=quantum_info->pad;
1571 }
1572 break;
1573 }
cristybb503372010-05-27 20:51:26 +00001574 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001575 {
cristyce70c172010-01-07 17:15:30 +00001576 pixel=ScaleQuantumToLong(GetOpacityPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001577 q=PopLongPixel(endian,pixel,q);
1578 p++;
1579 q+=quantum_info->pad;
1580 }
1581 break;
1582 }
1583 case 64:
1584 {
1585 if (quantum_info->format == FloatingPointQuantumFormat)
1586 {
cristybb503372010-05-27 20:51:26 +00001587 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001588 {
1589 q=PopDoublePixel(&quantum_state,(double) p->opacity,q);
1590 p++;
1591 q+=quantum_info->pad;
1592 }
1593 break;
1594 }
1595 }
1596 default:
1597 {
1598 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001599 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001600 {
1601 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1602 p->opacity,range),q);
1603 p++;
1604 q+=quantum_info->pad;
1605 }
1606 break;
1607 }
1608 }
1609 break;
1610 }
1611 case BlackQuantum:
1612 {
1613 if (image->colorspace != CMYKColorspace)
1614 {
1615 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1616 "ColorSeparatedImageRequired","`%s'",image->filename);
1617 return(extent);
1618 }
1619 switch (quantum_info->depth)
1620 {
1621 case 8:
1622 {
1623 register unsigned char
1624 pixel;
1625
cristybb503372010-05-27 20:51:26 +00001626 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001627 {
1628 pixel=ScaleQuantumToChar(indexes[x]);
1629 q=PopCharPixel(pixel,q);
1630 p++;
1631 q+=quantum_info->pad;
1632 }
1633 break;
1634 }
1635 case 16:
1636 {
1637 register unsigned short
1638 pixel;
1639
cristyc9672a92010-01-06 00:57:45 +00001640 if (quantum_info->format == FloatingPointQuantumFormat)
1641 {
cristybb503372010-05-27 20:51:26 +00001642 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001643 {
cristy2a4d01c2010-01-10 21:14:51 +00001644 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00001645 q=PopShortPixel(endian,pixel,q);
1646 p++;
1647 q+=quantum_info->pad;
1648 }
1649 break;
1650 }
cristybb503372010-05-27 20:51:26 +00001651 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001652 {
1653 pixel=ScaleQuantumToShort(indexes[x]);
1654 q=PopShortPixel(endian,pixel,q);
1655 p++;
1656 q+=quantum_info->pad;
1657 }
1658 break;
1659 }
1660 case 32:
1661 {
cristy4cb162a2010-05-30 03:04:47 +00001662 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001663 pixel;
1664
1665 if (quantum_info->format == FloatingPointQuantumFormat)
1666 {
cristybb503372010-05-27 20:51:26 +00001667 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001668 {
1669 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
1670 p++;
1671 q+=quantum_info->pad;
1672 }
1673 break;
1674 }
cristybb503372010-05-27 20:51:26 +00001675 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001676 {
1677 pixel=ScaleQuantumToLong(indexes[x]);
1678 q=PopLongPixel(endian,pixel,q);
1679 p++;
1680 q+=quantum_info->pad;
1681 }
1682 break;
1683 }
1684 case 64:
1685 {
1686 if (quantum_info->format == FloatingPointQuantumFormat)
1687 {
cristybb503372010-05-27 20:51:26 +00001688 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001689 {
1690 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
1691 p++;
1692 q+=quantum_info->pad;
1693 }
1694 break;
1695 }
1696 }
1697 default:
1698 {
1699 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001700 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001701 {
1702 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1703 (Quantum) indexes[x],range),q);
1704 p++;
1705 q+=quantum_info->pad;
1706 }
1707 break;
1708 }
1709 }
1710 break;
1711 }
1712 case RGBQuantum:
1713 case CbYCrQuantum:
1714 {
1715 switch (quantum_info->depth)
1716 {
1717 case 8:
1718 {
cristybb503372010-05-27 20:51:26 +00001719 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001720 {
cristyce70c172010-01-07 17:15:30 +00001721 q=PopCharPixel(ScaleQuantumToChar(GetRedPixelComponent(p)),q);
1722 q=PopCharPixel(ScaleQuantumToChar(GetGreenPixelComponent(p)),q);
1723 q=PopCharPixel(ScaleQuantumToChar(GetBluePixelComponent(p)),q);
cristy3ed852e2009-09-05 21:47:34 +00001724 p++;
1725 q+=quantum_info->pad;
1726 }
1727 break;
1728 }
1729 case 10:
1730 {
cristy4cb162a2010-05-30 03:04:47 +00001731 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001732 pixel;
1733
1734 range=GetQuantumRange(image->depth);
1735 if (quantum_info->pack == MagickFalse)
1736 {
cristybb503372010-05-27 20:51:26 +00001737 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001738 {
cristy4cb162a2010-05-30 03:04:47 +00001739 pixel=(unsigned int) (ScaleQuantumToAny(p->red,range) << 22 |
cristyff024b42010-02-21 22:55:09 +00001740 ScaleQuantumToAny(p->green,range) << 12 |
cristy3ed852e2009-09-05 21:47:34 +00001741 ScaleQuantumToAny(p->blue,range) << 2);
1742 q=PopLongPixel(endian,pixel,q);
1743 p++;
1744 q+=quantum_info->pad;
1745 }
1746 break;
1747 }
1748 if (quantum_info->quantum == 32UL)
1749 {
cristybb503372010-05-27 20:51:26 +00001750 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001751 {
cristy4cb162a2010-05-30 03:04:47 +00001752 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001753 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001754 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001755 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001756 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001757 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1758 p++;
1759 q+=quantum_info->pad;
1760 }
1761 break;
1762 }
cristybb503372010-05-27 20:51:26 +00001763 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001764 {
cristy4cb162a2010-05-30 03:04:47 +00001765 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001766 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001767 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001768 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001769 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001770 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1771 p++;
1772 q+=quantum_info->pad;
1773 }
1774 break;
1775 }
1776 case 12:
1777 {
cristy4cb162a2010-05-30 03:04:47 +00001778 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001779 pixel;
1780
1781 range=GetQuantumRange(image->depth);
1782 if (quantum_info->pack == MagickFalse)
1783 {
cristybb503372010-05-27 20:51:26 +00001784 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001785 {
1786 switch (x % 3)
1787 {
1788 default:
1789 case 0:
1790 {
cristy4cb162a2010-05-30 03:04:47 +00001791 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001792 break;
1793 }
1794 case 1:
1795 {
cristy4cb162a2010-05-30 03:04:47 +00001796 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001797 break;
1798 }
1799 case 2:
1800 {
cristy4cb162a2010-05-30 03:04:47 +00001801 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001802 p++;
1803 break;
1804 }
1805 }
1806 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1807 switch ((x+1) % 3)
1808 {
1809 default:
1810 case 0:
1811 {
cristy4cb162a2010-05-30 03:04:47 +00001812 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001813 break;
1814 }
1815 case 1:
1816 {
cristy4cb162a2010-05-30 03:04:47 +00001817 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001818 break;
1819 }
1820 case 2:
1821 {
cristy4cb162a2010-05-30 03:04:47 +00001822 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001823 p++;
1824 break;
1825 }
1826 }
1827 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1828 q+=quantum_info->pad;
1829 }
cristybb503372010-05-27 20:51:26 +00001830 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001831 {
1832 switch ((x+bit) % 3)
1833 {
1834 default:
1835 case 0:
1836 {
cristy4cb162a2010-05-30 03:04:47 +00001837 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001838 break;
1839 }
1840 case 1:
1841 {
cristy4cb162a2010-05-30 03:04:47 +00001842 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001843 break;
1844 }
1845 case 2:
1846 {
cristy4cb162a2010-05-30 03:04:47 +00001847 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001848 p++;
1849 break;
1850 }
1851 }
1852 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1853 q+=quantum_info->pad;
1854 }
1855 if (bit != 0)
1856 p++;
1857 break;
1858 }
1859 if (quantum_info->quantum == 32UL)
1860 {
cristybb503372010-05-27 20:51:26 +00001861 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001862 {
cristy4cb162a2010-05-30 03:04:47 +00001863 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001864 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001865 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001866 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001867 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001868 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1869 p++;
1870 q+=quantum_info->pad;
1871 }
1872 break;
1873 }
cristybb503372010-05-27 20:51:26 +00001874 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001875 {
cristy4cb162a2010-05-30 03:04:47 +00001876 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy3ed852e2009-09-05 21:47:34 +00001877 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001878 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy3ed852e2009-09-05 21:47:34 +00001879 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00001880 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy3ed852e2009-09-05 21:47:34 +00001881 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1882 p++;
1883 q+=quantum_info->pad;
1884 }
1885 break;
1886 }
1887 case 16:
1888 {
1889 register unsigned short
1890 pixel;
1891
cristyc9672a92010-01-06 00:57:45 +00001892 if (quantum_info->format == FloatingPointQuantumFormat)
1893 {
cristybb503372010-05-27 20:51:26 +00001894 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001895 {
cristy2a4d01c2010-01-10 21:14:51 +00001896 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001897 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001898 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00001899 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001900 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001901 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00001902 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00001903 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00001904 q=PopShortPixel(endian,pixel,q);
1905 p++;
1906 q+=quantum_info->pad;
1907 }
1908 break;
1909 }
cristybb503372010-05-27 20:51:26 +00001910 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001911 {
cristyce70c172010-01-07 17:15:30 +00001912 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001913 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001914 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001915 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001916 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001917 q=PopShortPixel(endian,pixel,q);
1918 p++;
1919 q+=quantum_info->pad;
1920 }
1921 break;
1922 }
1923 case 32:
1924 {
cristy4cb162a2010-05-30 03:04:47 +00001925 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001926 pixel;
1927
1928 if (quantum_info->format == FloatingPointQuantumFormat)
1929 {
cristybb503372010-05-27 20:51:26 +00001930 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001931 {
1932 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1933 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1934 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1935 p++;
1936 q+=quantum_info->pad;
1937 }
1938 break;
1939 }
cristybb503372010-05-27 20:51:26 +00001940 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001941 {
cristyce70c172010-01-07 17:15:30 +00001942 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001943 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001944 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001945 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00001946 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00001947 q=PopLongPixel(endian,pixel,q);
1948 p++;
1949 q+=quantum_info->pad;
1950 }
1951 break;
1952 }
1953 case 64:
1954 {
1955 if (quantum_info->format == FloatingPointQuantumFormat)
1956 {
cristybb503372010-05-27 20:51:26 +00001957 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001958 {
1959 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1960 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1961 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1962 p++;
1963 q+=quantum_info->pad;
1964 }
1965 break;
1966 }
1967 }
1968 default:
1969 {
1970 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001971 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001972 {
1973 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1974 p->red,range),q);
1975 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1976 p->green,range),q);
1977 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1978 p->blue,range),q);
1979 p++;
1980 q+=quantum_info->pad;
1981 }
1982 break;
1983 }
1984 }
1985 break;
1986 }
1987 case RGBAQuantum:
1988 case RGBOQuantum:
1989 case CbYCrAQuantum:
1990 {
1991 switch (quantum_info->depth)
1992 {
1993 case 8:
1994 {
1995 register unsigned char
1996 pixel;
1997
cristybb503372010-05-27 20:51:26 +00001998 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001999 {
cristyce70c172010-01-07 17:15:30 +00002000 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002001 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002002 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002003 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002004 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002005 q=PopCharPixel(pixel,q);
cristycee97112010-05-28 00:44:52 +00002006 pixel=ScaleQuantumToChar((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002007 q=PopCharPixel(pixel,q);
2008 p++;
2009 q+=quantum_info->pad;
2010 }
2011 break;
2012 }
cristy891dc792010-03-04 01:47:16 +00002013 case 10:
2014 {
cristy4cb162a2010-05-30 03:04:47 +00002015 register unsigned int
cristy891dc792010-03-04 01:47:16 +00002016 pixel;
2017
2018 range=GetQuantumRange(image->depth);
2019 if (quantum_info->pack == MagickFalse)
2020 {
cristybb503372010-05-27 20:51:26 +00002021 ssize_t
cristy891dc792010-03-04 01:47:16 +00002022 n;
2023
cristybb503372010-05-27 20:51:26 +00002024 register ssize_t
cristy891dc792010-03-04 01:47:16 +00002025 i;
2026
cristybb503372010-05-27 20:51:26 +00002027 size_t
cristy891dc792010-03-04 01:47:16 +00002028 quantum;
2029
2030 n=0;
2031 quantum=0;
2032 pixel=0;
cristybb503372010-05-27 20:51:26 +00002033 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002034 {
2035 for (i=0; i < 4; i++)
2036 {
2037 switch (i)
2038 {
2039 case 0: quantum=p->red; break;
2040 case 1: quantum=p->green; break;
2041 case 2: quantum=p->blue; break;
cristycee97112010-05-28 00:44:52 +00002042 case 3: quantum=(Quantum) (QuantumRange-p->opacity); break;
cristy891dc792010-03-04 01:47:16 +00002043 }
2044 switch (n % 3)
2045 {
2046 case 0:
2047 {
cristycee97112010-05-28 00:44:52 +00002048 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002049 range) << 22);
2050 break;
2051 }
2052 case 1:
2053 {
cristycee97112010-05-28 00:44:52 +00002054 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002055 range) << 12);
2056 break;
2057 }
2058 case 2:
2059 {
cristycee97112010-05-28 00:44:52 +00002060 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
cristy891dc792010-03-04 01:47:16 +00002061 range) << 2);
2062 q=PopLongPixel(endian,pixel,q);
2063 pixel=0;
2064 break;
2065 }
2066 }
2067 n++;
2068 }
2069 p++;
2070 q+=quantum_info->pad;
2071 }
2072 break;
2073 }
2074 if (quantum_info->quantum == 32UL)
2075 {
cristybb503372010-05-27 20:51:26 +00002076 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002077 {
cristy4cb162a2010-05-30 03:04:47 +00002078 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy891dc792010-03-04 01:47:16 +00002079 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002080 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy891dc792010-03-04 01:47:16 +00002081 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002082 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy891dc792010-03-04 01:47:16 +00002083 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002084 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
cristycee97112010-05-28 00:44:52 +00002085 p->opacity),range);
cristy891dc792010-03-04 01:47:16 +00002086 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
2087 p++;
2088 q+=quantum_info->pad;
2089 }
2090 break;
2091 }
cristybb503372010-05-27 20:51:26 +00002092 for (x=0; x < (ssize_t) number_pixels; x++)
cristy891dc792010-03-04 01:47:16 +00002093 {
cristy4cb162a2010-05-30 03:04:47 +00002094 pixel=(unsigned int) ScaleQuantumToAny(p->red,range);
cristy891dc792010-03-04 01:47:16 +00002095 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002096 pixel=(unsigned int) ScaleQuantumToAny(p->green,range);
cristy891dc792010-03-04 01:47:16 +00002097 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002098 pixel=(unsigned int) ScaleQuantumToAny(p->blue,range);
cristy891dc792010-03-04 01:47:16 +00002099 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
cristy4cb162a2010-05-30 03:04:47 +00002100 pixel=(unsigned int) ScaleQuantumToAny((Quantum) (QuantumRange-
cristycee97112010-05-28 00:44:52 +00002101 p->opacity),range);
cristy891dc792010-03-04 01:47:16 +00002102 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
2103 p++;
2104 q+=quantum_info->pad;
2105 }
2106 break;
2107 }
cristy3ed852e2009-09-05 21:47:34 +00002108 case 16:
2109 {
2110 register unsigned short
2111 pixel;
2112
cristyc9672a92010-01-06 00:57:45 +00002113 if (quantum_info->format == FloatingPointQuantumFormat)
2114 {
cristybb503372010-05-27 20:51:26 +00002115 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002116 {
cristy2a4d01c2010-01-10 21:14:51 +00002117 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002118 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002119 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002120 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002121 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002122 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002123 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002124 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002125 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002126 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002127 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002128 q=PopShortPixel(endian,pixel,q);
2129 p++;
2130 q+=quantum_info->pad;
2131 }
2132 break;
2133 }
cristybb503372010-05-27 20:51:26 +00002134 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002135 {
cristyce70c172010-01-07 17:15:30 +00002136 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002137 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002138 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002139 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002140 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002141 q=PopShortPixel(endian,pixel,q);
cristycee97112010-05-28 00:44:52 +00002142 pixel=ScaleQuantumToShort((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002143 q=PopShortPixel(endian,pixel,q);
2144 p++;
2145 q+=quantum_info->pad;
2146 }
2147 break;
2148 }
2149 case 32:
2150 {
cristy4cb162a2010-05-30 03:04:47 +00002151 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002152 pixel;
2153
2154 if (quantum_info->format == FloatingPointQuantumFormat)
2155 {
cristybb503372010-05-27 20:51:26 +00002156 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002157 {
2158 float
2159 pixel;
2160
2161 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2162 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2163 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
cristycee97112010-05-28 00:44:52 +00002164 pixel=(float) GetAlphaPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002165 q=PopFloatPixel(&quantum_state,pixel,q);
2166 p++;
2167 q+=quantum_info->pad;
2168 }
2169 break;
2170 }
cristybb503372010-05-27 20:51:26 +00002171 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002172 {
cristyce70c172010-01-07 17:15:30 +00002173 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002174 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002175 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002176 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002177 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002178 q=PopLongPixel(endian,pixel,q);
cristycee97112010-05-28 00:44:52 +00002179 pixel=ScaleQuantumToLong((Quantum) GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002180 q=PopLongPixel(endian,pixel,q);
2181 p++;
2182 q+=quantum_info->pad;
2183 }
2184 break;
2185 }
2186 case 64:
2187 {
2188 if (quantum_info->format == FloatingPointQuantumFormat)
2189 {
2190 double
2191 pixel;
2192
cristybb503372010-05-27 20:51:26 +00002193 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002194 {
2195 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2196 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2197 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
cristyeec18db2010-03-03 21:15:45 +00002198 pixel=(double) GetAlphaPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002199 q=PopDoublePixel(&quantum_state,pixel,q);
2200 p++;
2201 q+=quantum_info->pad;
2202 }
2203 break;
2204 }
2205 }
2206 default:
2207 {
2208 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002209 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002210 {
2211 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristyeec18db2010-03-03 21:15:45 +00002212 GetRedPixelComponent(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002213 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristyeec18db2010-03-03 21:15:45 +00002214 GetGreenPixelComponent(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002215 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristyeec18db2010-03-03 21:15:45 +00002216 GetBluePixelComponent(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002217 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
cristycee97112010-05-28 00:44:52 +00002218 (Quantum) GetAlphaPixelComponent(p),range),q);
cristy3ed852e2009-09-05 21:47:34 +00002219 p++;
2220 q+=quantum_info->pad;
2221 }
2222 break;
2223 }
2224 }
2225 break;
2226 }
2227 case CMYKQuantum:
2228 {
2229 if (image->colorspace != CMYKColorspace)
2230 {
2231 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2232 "ColorSeparatedImageRequired","`%s'",image->filename);
2233 return(extent);
2234 }
2235 switch (quantum_info->depth)
2236 {
2237 case 8:
2238 {
2239 register unsigned char
2240 pixel;
2241
cristybb503372010-05-27 20:51:26 +00002242 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002243 {
cristyce70c172010-01-07 17:15:30 +00002244 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002245 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002246 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002247 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002248 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002249 q=PopCharPixel(pixel,q);
2250 pixel=ScaleQuantumToChar(indexes[x]);
2251 q=PopCharPixel(pixel,q);
2252 p++;
2253 q+=quantum_info->pad;
2254 }
2255 break;
2256 }
2257 case 16:
2258 {
2259 register unsigned short
2260 pixel;
2261
cristyc9672a92010-01-06 00:57:45 +00002262 if (quantum_info->format == FloatingPointQuantumFormat)
2263 {
cristybb503372010-05-27 20:51:26 +00002264 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002265 {
cristy2a4d01c2010-01-10 21:14:51 +00002266 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002267 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002268 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002269 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002270 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002271 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002272 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002273 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002274 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002275 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00002276 q=PopShortPixel(endian,pixel,q);
2277 p++;
2278 q+=quantum_info->pad;
2279 }
2280 break;
2281 }
cristybb503372010-05-27 20:51:26 +00002282 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002283 {
cristyce70c172010-01-07 17:15:30 +00002284 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002285 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002286 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002287 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002288 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002289 q=PopShortPixel(endian,pixel,q);
2290 pixel=ScaleQuantumToShort(indexes[x]);
2291 q=PopShortPixel(endian,pixel,q);
2292 p++;
2293 q+=quantum_info->pad;
2294 }
2295 break;
2296 }
2297 case 32:
2298 {
cristy4cb162a2010-05-30 03:04:47 +00002299 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002300 pixel;
2301
2302 if (quantum_info->format == FloatingPointQuantumFormat)
2303 {
cristybb503372010-05-27 20:51:26 +00002304 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002305 {
2306 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2307 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2308 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2309 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
2310 p++;
2311 q+=quantum_info->pad;
2312 }
2313 break;
2314 }
cristybb503372010-05-27 20:51:26 +00002315 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002316 {
cristyce70c172010-01-07 17:15:30 +00002317 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002318 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002319 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002320 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002321 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002322 q=PopLongPixel(endian,pixel,q);
2323 pixel=ScaleQuantumToLong(indexes[x]);
2324 q=PopLongPixel(endian,pixel,q);
2325 p++;
2326 q+=quantum_info->pad;
2327 }
2328 break;
2329 }
2330 case 64:
2331 {
2332 if (quantum_info->format == FloatingPointQuantumFormat)
2333 {
cristybb503372010-05-27 20:51:26 +00002334 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002335 {
2336 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2337 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2338 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2339 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
2340 p++;
2341 q+=quantum_info->pad;
2342 }
2343 break;
2344 }
2345 }
2346 default:
2347 {
2348 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002349 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002350 {
2351 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2352 p->red,range),q);
2353 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2354 p->green,range),q);
2355 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2356 p->blue,range),q);
2357 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2358 indexes[x],range),q);
2359 p++;
2360 q+=quantum_info->pad;
2361 }
2362 break;
2363 }
2364 }
2365 break;
2366 }
2367 case CMYKAQuantum:
2368 case CMYKOQuantum:
2369 {
2370 if (image->colorspace != CMYKColorspace)
2371 {
2372 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2373 "ColorSeparatedImageRequired","`%s'",image->filename);
2374 return(extent);
2375 }
2376 switch (quantum_info->depth)
2377 {
2378 case 8:
2379 {
2380 register unsigned char
2381 pixel;
2382
cristybb503372010-05-27 20:51:26 +00002383 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002384 {
cristyce70c172010-01-07 17:15:30 +00002385 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002386 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002387 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002388 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002389 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002390 q=PopCharPixel(pixel,q);
2391 pixel=ScaleQuantumToChar(indexes[x]);
2392 q=PopCharPixel(pixel,q);
cristyce70c172010-01-07 17:15:30 +00002393 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
2394 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002395 q=PopCharPixel(pixel,q);
2396 p++;
2397 q+=quantum_info->pad;
2398 }
2399 break;
2400 }
2401 case 16:
2402 {
2403 register unsigned short
2404 pixel;
2405
cristyc9672a92010-01-06 00:57:45 +00002406 if (quantum_info->format == FloatingPointQuantumFormat)
2407 {
cristybb503372010-05-27 20:51:26 +00002408 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002409 {
cristy2a4d01c2010-01-10 21:14:51 +00002410 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002411 GetRedPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002412 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002413 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002414 GetGreenPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002415 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002416 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002417 GetBluePixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002418 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002419 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
cristyc9672a92010-01-06 00:57:45 +00002420 q=PopShortPixel(endian,pixel,q);
cristy2a4d01c2010-01-10 21:14:51 +00002421 pixel=SinglePrecisionToHalf(QuantumScale*
cristy24fb7dc2010-01-10 20:15:51 +00002422 GetAlphaPixelComponent(p));
cristyc9672a92010-01-06 00:57:45 +00002423 q=PopShortPixel(endian,pixel,q);
2424 p++;
2425 q+=quantum_info->pad;
2426 }
2427 break;
2428 }
cristybb503372010-05-27 20:51:26 +00002429 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002430 {
cristyce70c172010-01-07 17:15:30 +00002431 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002432 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002433 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002434 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002435 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002436 q=PopShortPixel(endian,pixel,q);
2437 pixel=ScaleQuantumToShort(indexes[x]);
2438 q=PopShortPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002439 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
2440 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002441 q=PopShortPixel(endian,pixel,q);
2442 p++;
2443 q+=quantum_info->pad;
2444 }
2445 break;
2446 }
2447 case 32:
2448 {
cristy4cb162a2010-05-30 03:04:47 +00002449 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002450 pixel;
2451
2452 if (quantum_info->format == FloatingPointQuantumFormat)
2453 {
cristybb503372010-05-27 20:51:26 +00002454 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002455 {
2456 float
2457 pixel;
2458
2459 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2460 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2461 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2462 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +00002463 pixel=(float) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002464 q=PopFloatPixel(&quantum_state,pixel,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 pixel=ScaleQuantumToLong(indexes[x]);
2479 q=PopLongPixel(endian,pixel,q);
cristyce70c172010-01-07 17:15:30 +00002480 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
2481 GetOpacityPixelComponent(p)));
cristy3ed852e2009-09-05 21:47:34 +00002482 q=PopLongPixel(endian,pixel,q);
2483 p++;
2484 q+=quantum_info->pad;
2485 }
2486 break;
2487 }
2488 case 64:
2489 {
2490 if (quantum_info->format == FloatingPointQuantumFormat)
2491 {
2492 double
2493 pixel;
2494
cristybb503372010-05-27 20:51:26 +00002495 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002496 {
2497 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2498 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2499 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2500 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
cristy46f08202010-01-10 04:04:21 +00002501 pixel=(double) (GetAlphaPixelComponent(p));
cristy3ed852e2009-09-05 21:47:34 +00002502 q=PopDoublePixel(&quantum_state,pixel,q);
2503 p++;
2504 q+=quantum_info->pad;
2505 }
2506 break;
2507 }
2508 }
2509 default:
2510 {
2511 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002512 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002513 {
2514 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2515 p->red,range),q);
2516 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2517 p->green,range),q);
2518 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2519 p->blue,range),q);
2520 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2521 indexes[x],range),q);
2522 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2523 p->opacity,range),q);
2524 p++;
2525 q+=quantum_info->pad;
2526 }
2527 break;
2528 }
2529 }
2530 break;
2531 }
2532 case CbYCrYQuantum:
2533 {
cristybb503372010-05-27 20:51:26 +00002534 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002535 n;
2536
2537 Quantum
2538 cbcr[4];
2539
cristybb503372010-05-27 20:51:26 +00002540 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002541 i;
2542
cristy4cb162a2010-05-30 03:04:47 +00002543 register unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002544 pixel;
2545
cristybb503372010-05-27 20:51:26 +00002546 size_t
cristy3ed852e2009-09-05 21:47:34 +00002547 quantum;
2548
2549 n=0;
2550 quantum=0;
2551 range=GetQuantumRange(image->depth);
2552 switch (quantum_info->depth)
2553 {
2554 case 10:
2555 {
2556 if (quantum_info->pack == MagickFalse)
2557 {
cristybb503372010-05-27 20:51:26 +00002558 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002559 {
2560 for (i=0; i < 4; i++)
2561 {
2562 switch (n % 3)
2563 {
2564 case 0:
2565 {
cristyce70c172010-01-07 17:15:30 +00002566 quantum=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002567 break;
2568 }
2569 case 1:
2570 {
cristyce70c172010-01-07 17:15:30 +00002571 quantum=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002572 break;
2573 }
2574 case 2:
2575 {
cristyce70c172010-01-07 17:15:30 +00002576 quantum=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002577 break;
2578 }
2579 }
2580 cbcr[i]=(Quantum) quantum;
2581 n++;
2582 }
cristy4cb162a2010-05-30 03:04:47 +00002583 pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 |
cristybb503372010-05-27 20:51:26 +00002584 (size_t) (cbcr[0]) << 12 |
2585 (size_t) (cbcr[2]) << 2);
cristy3ed852e2009-09-05 21:47:34 +00002586 q=PopLongPixel(endian,pixel,q);
2587 p++;
cristy4cb162a2010-05-30 03:04:47 +00002588 pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 |
cristybb503372010-05-27 20:51:26 +00002589 (size_t) (cbcr[0]) << 12 |
2590 (size_t) (cbcr[2]) << 2);
cristy3ed852e2009-09-05 21:47:34 +00002591 q=PopLongPixel(endian,pixel,q);
2592 p++;
2593 q+=quantum_info->pad;
2594 }
2595 break;
2596 }
2597 break;
2598 }
2599 default:
2600 {
cristybb503372010-05-27 20:51:26 +00002601 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002602 {
2603 for (i=0; i < 4; i++)
2604 {
2605 switch (n % 3)
2606 {
2607 case 0:
2608 {
cristyce70c172010-01-07 17:15:30 +00002609 quantum=GetRedPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002610 break;
2611 }
2612 case 1:
2613 {
cristyce70c172010-01-07 17:15:30 +00002614 quantum=GetGreenPixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002615 break;
2616 }
2617 case 2:
2618 {
cristyce70c172010-01-07 17:15:30 +00002619 quantum=GetBluePixelComponent(p);
cristy3ed852e2009-09-05 21:47:34 +00002620 break;
2621 }
2622 }
2623 cbcr[i]=(Quantum) quantum;
2624 n++;
2625 }
2626 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2627 cbcr[1],range),q);
2628 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2629 cbcr[0],range),q);
2630 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2631 cbcr[2],range),q);
2632 p++;
2633 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2634 cbcr[3],range),q);
2635 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2636 cbcr[0],range),q);
2637 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2638 cbcr[2],range),q);
2639 p++;
2640 q+=quantum_info->pad;
2641 }
2642 break;
2643 }
2644 }
2645 break;
2646 }
2647 default:
2648 break;
2649 }
2650 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2651 {
2652 Quantum
2653 quantum;
2654
2655 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002656 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002657
2658 q=GetAuthenticPixelQueue(image);
2659 if (image_view != (CacheView *) NULL)
2660 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002661 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002662 {
2663 quantum=q->red;
2664 q->red=q->green;
2665 q->green=quantum;
2666 q++;
2667 }
2668 }
2669 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2670 {
2671 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002672 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002673
2674 q=GetAuthenticPixelQueue(image);
2675 if (image_view != (CacheView *) NULL)
2676 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002677 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002678 {
cristy46f08202010-01-10 04:04:21 +00002679 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00002680 q++;
2681 }
2682 }
2683 return(extent);
2684}