blob: 242183b07803995b29f7c40a6586a077a5be2b7a [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% QQQ U U AAA N N TTTTT U U M M %
7% Q Q U U A A NN N T U U MM MM %
8% Q Q U U AAAAA N N N T U U M M M %
9% Q QQ U U A A N NN T U U M M %
10% QQQQ UUU A A N N T UUU M M %
11% %
12% IIIII M M PPPP OOO RRRR TTTTT %
13% I MM MM P P O O R R T %
14% I M M M PPPP O O RRRR T %
15% I M M P O O R R T %
16% IIIII M M P OOO R R T %
17% %
18% MagickCore Methods to Import Quantum Pixels %
19% %
20% Software Design %
21% John Cristy %
22% October 1998 %
23% %
24% %
25% Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
26% dedicated to making software imaging solutions freely available. %
27% %
28% You may not use this file except in compliance with the License. You may %
29% obtain a copy of the License at %
30% %
31% http://www.imagemagick.org/script/license.php %
32% %
33% Unless required by applicable law or agreed to in writing, software %
34% distributed under the License is distributed on an "AS IS" BASIS, %
35% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36% See the License for the specific language governing permissions and %
37% limitations under the License. %
38% %
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40%
41%
42*/
43
44/*
45 Include declarations.
46*/
47#include "magick/studio.h"
48#include "magick/property.h"
49#include "magick/blob.h"
50#include "magick/blob-private.h"
51#include "magick/color-private.h"
52#include "magick/exception.h"
53#include "magick/exception-private.h"
54#include "magick/cache.h"
55#include "magick/constitute.h"
56#include "magick/delegate.h"
57#include "magick/geometry.h"
58#include "magick/list.h"
59#include "magick/magick.h"
60#include "magick/memory_.h"
61#include "magick/monitor.h"
62#include "magick/option.h"
63#include "magick/pixel.h"
64#include "magick/pixel-private.h"
65#include "magick/quantum.h"
66#include "magick/quantum-private.h"
67#include "magick/resource_.h"
68#include "magick/semaphore.h"
69#include "magick/statistic.h"
70#include "magick/stream.h"
71#include "magick/string_.h"
72#include "magick/utility.h"
73
74/*
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76% %
77% %
78% %
79% I m p o r t Q u a n t u m P i x e l s %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
85% ImportQuantumPixels() transfers one or more pixel components from a user
86% supplied buffer into the image pixel cache of an image. The pixels are
87% expected in network byte order. It returns MagickTrue if the pixels are
88% successfully transferred, otherwise MagickFalse.
89%
90% The format of the ImportQuantumPixels method is:
91%
92% size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93% const QuantumInfo *quantum_info,const QuantumType quantum_type,
94% const unsigned char *pixels,ExceptionInfo *exception)
95%
96% A description of each parameter follows:
97%
98% o image: the image.
99%
100% o image_view: the image cache view.
101%
102% o quantum_info: the quantum info.
103%
104% o quantum_type: Declare which pixel components to transfer (red, green,
105% blue, opacity, RGB, or RGBA).
106%
107% o pixels: The pixel components are transferred from this buffer.
108%
109% o exception: return any errors or warnings in this structure.
110%
111*/
112
113static inline IndexPacket PushColormapIndex(Image *image,
cristybb503372010-05-27 20:51:26 +0000114 const size_t index,MagickBooleanType *range_exception)
cristy3ed852e2009-09-05 21:47:34 +0000115{
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
120}
121
122static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
124{
125 double
126 *p;
127
128 unsigned char
129 quantum[8];
130
131 if (quantum_state->endian != LSBEndian)
132 {
133 quantum[7]=(*pixels++);
134 quantum[6]=(*pixels++);
135 quantum[5]=(*pixels++);
136 quantum[5]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[2]=(*pixels++);
139 quantum[1]=(*pixels++);
140 quantum[0]=(*pixels++);
141 p=(double *) quantum;
142 *pixel=(*p);
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
145 return(pixels);
146 }
147 quantum[0]=(*pixels++);
148 quantum[1]=(*pixels++);
149 quantum[2]=(*pixels++);
150 quantum[3]=(*pixels++);
151 quantum[4]=(*pixels++);
152 quantum[5]=(*pixels++);
153 quantum[6]=(*pixels++);
154 quantum[7]=(*pixels++);
155 p=(double *) quantum;
156 *pixel=(*p);
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
159 return(pixels);
160}
161
162static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
164{
165 float
166 *p;
167
168 unsigned char
169 quantum[4];
170
171 if (quantum_state->endian != LSBEndian)
172 {
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
177 p=(float *) quantum;
178 *pixel=(*p);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
181 return(pixels);
182 }
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
187 p=(float *) quantum;
188 *pixel=(*p);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
191 return(pixels);
192}
193
194static inline const unsigned char *PushQuantumPixel(
cristybb503372010-05-27 20:51:26 +0000195 QuantumState *quantum_state,const size_t depth,
cristy4cb162a2010-05-30 03:04:47 +0000196 const unsigned char *pixels,unsigned int *quantum)
cristy3ed852e2009-09-05 21:47:34 +0000197{
cristybb503372010-05-27 20:51:26 +0000198 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000199 i;
200
cristy6b825f92010-06-04 02:01:10 +0000201 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000202 quantum_bits;
203
204 *quantum=(QuantumAny) 0;
cristybb503372010-05-27 20:51:26 +0000205 for (i=(ssize_t) depth; i > 0L; )
cristy3ed852e2009-09-05 21:47:34 +0000206 {
207 if (quantum_state->bits == 0UL)
208 {
209 quantum_state->pixel=(*pixels++);
cristy6b825f92010-06-04 02:01:10 +0000210 quantum_state->bits=8UL;
cristy3ed852e2009-09-05 21:47:34 +0000211 }
cristybb503372010-05-27 20:51:26 +0000212 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
cristyebdf07a2010-06-04 14:48:53 +0000215 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000216 quantum_state->bits-=quantum_bits;
cristy6b825f92010-06-04 02:01:10 +0000217 *quantum=(unsigned int) ((*quantum << quantum_bits) |
218 ((quantum_state->pixel >> quantum_state->bits) &~ ((~0UL) <<
219 quantum_bits)));
cristy3ed852e2009-09-05 21:47:34 +0000220 }
221 return(pixels);
222}
223
224static inline const unsigned char *PushQuantumLongPixel(
cristybb503372010-05-27 20:51:26 +0000225 QuantumState *quantum_state,const size_t depth,
cristy4cb162a2010-05-30 03:04:47 +0000226 const unsigned char *pixels,unsigned int *quantum)
cristy3ed852e2009-09-05 21:47:34 +0000227{
cristybb503372010-05-27 20:51:26 +0000228 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000229 i;
230
cristybb503372010-05-27 20:51:26 +0000231 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000232 quantum_bits;
233
234 *quantum=0UL;
cristybb503372010-05-27 20:51:26 +0000235 for (i=(ssize_t) depth; i > 0; )
cristy3ed852e2009-09-05 21:47:34 +0000236 {
237 if (quantum_state->bits == 0)
238 {
239 pixels=PushLongPixel(quantum_state->endian,pixels,
240 &quantum_state->pixel);
cristy4cb162a2010-05-30 03:04:47 +0000241 quantum_state->bits=32U;
cristy3ed852e2009-09-05 21:47:34 +0000242 }
cristybb503372010-05-27 20:51:26 +0000243 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000244 if (quantum_bits > quantum_state->bits)
245 quantum_bits=quantum_state->bits;
cristy4cb162a2010-05-30 03:04:47 +0000246 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
cristy3ed852e2009-09-05 21:47:34 +0000247 quantum_state->mask[quantum_bits]) << (depth-i));
cristyeaedf062010-05-29 22:36:02 +0000248 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000249 quantum_state->bits-=quantum_bits;
250 }
251 return(pixels);
252}
253
254MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
255 const QuantumInfo *quantum_info,const QuantumType quantum_type,
256 const unsigned char *pixels,ExceptionInfo *exception)
257{
258 EndianType
259 endian;
260
cristybb503372010-05-27 20:51:26 +0000261 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000262 bit;
263
264 MagickSizeType
265 number_pixels;
266
267 QuantumAny
268 range;
269
270 QuantumState
271 quantum_state;
272
273 register const unsigned char
cristyaebafa22009-11-26 01:48:56 +0000274 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000275
276 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000277 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000278
cristybb503372010-05-27 20:51:26 +0000279 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000280 x;
281
282 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000283 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000284
285 size_t
286 extent;
287
cristy4cb162a2010-05-30 03:04:47 +0000288 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000289 pixel;
290
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
295 assert(quantum_info != (QuantumInfo *) NULL);
296 assert(quantum_info->signature == MagickSignature);
297 if (pixels == (const unsigned char *) NULL)
298 pixels=GetQuantumPixels(quantum_info);
299 x=0;
300 p=pixels;
cristy8a7ea362010-03-10 20:31:43 +0000301 if (image_view == (CacheView *) NULL)
302 {
303 number_pixels=GetImageExtent(image);
304 q=GetAuthenticPixelQueue(image);
305 indexes=GetAuthenticIndexQueue(image);
306 }
307 else
cristy3ed852e2009-09-05 21:47:34 +0000308 {
309 number_pixels=GetCacheViewExtent(image_view);
310 q=GetCacheViewAuthenticPixelQueue(image_view);
311 indexes=GetCacheViewAuthenticIndexQueue(image_view);
312 }
313 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
314 extent=GetQuantumExtent(image,quantum_info,quantum_type);
315 endian=quantum_state.endian;
316 switch (quantum_type)
317 {
318 case IndexQuantum:
319 {
320 MagickBooleanType
321 range_exception;
322
323 if (image->storage_class != PseudoClass)
324 {
325 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
326 "ColormappedImageRequired","`%s'",image->filename);
327 return(extent);
328 }
329 range_exception=MagickFalse;
330 switch (quantum_info->depth)
331 {
332 case 1:
333 {
334 register unsigned char
335 pixel;
336
cristybb503372010-05-27 20:51:26 +0000337 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000338 {
339 for (bit=0; bit < 8; bit++)
340 {
341 if (quantum_info->min_is_white == MagickFalse)
342 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
343 0x00 : 0x01);
344 else
345 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
346 0x00 : 0x01);
347 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000348 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000349 q++;
350 }
351 p++;
352 }
cristybb503372010-05-27 20:51:26 +0000353 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000354 {
355 if (quantum_info->min_is_white == MagickFalse)
356 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
357 0x00 : 0x01);
358 else
359 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
360 0x00 : 0x01);
361 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000362 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000363 q++;
364 }
365 break;
366 }
367 case 4:
368 {
369 register unsigned char
370 pixel;
371
cristybb503372010-05-27 20:51:26 +0000372 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000373 {
374 pixel=(unsigned char) ((*p >> 4) & 0xf);
375 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000376 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000377 q++;
378 pixel=(unsigned char) ((*p) & 0xf);
379 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000380 *q=image->colormap[(ssize_t) indexes[x+1]];
cristy3ed852e2009-09-05 21:47:34 +0000381 p++;
382 q++;
383 }
cristybb503372010-05-27 20:51:26 +0000384 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000385 {
386 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
387 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000388 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000389 q++;
390 }
391 break;
392 }
393 case 8:
394 {
395 unsigned char
396 pixel;
397
cristybb503372010-05-27 20:51:26 +0000398 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000399 {
400 p=PushCharPixel(p,&pixel);
401 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000402 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000403 p+=quantum_info->pad;
404 q++;
405 }
406 break;
407 }
408 case 16:
409 {
410 unsigned short
411 pixel;
412
cristyc9672a92010-01-06 00:57:45 +0000413 if (quantum_info->format == FloatingPointQuantumFormat)
414 {
cristybb503372010-05-27 20:51:26 +0000415 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000416 {
417 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000418 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000419 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
420 &range_exception);
cristybb503372010-05-27 20:51:26 +0000421 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000422 p+=quantum_info->pad;
423 q++;
424 }
425 break;
426 }
cristybb503372010-05-27 20:51:26 +0000427 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000428 {
429 p=PushShortPixel(endian,p,&pixel);
430 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000431 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000432 p+=quantum_info->pad;
433 q++;
434 }
435 break;
436 }
437 case 32:
438 {
cristy4cb162a2010-05-30 03:04:47 +0000439 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000440 pixel;
441
442 if (quantum_info->format == FloatingPointQuantumFormat)
443 {
444 float
445 pixel;
446
cristybb503372010-05-27 20:51:26 +0000447 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000448 {
449 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000450 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000451 &range_exception);
cristybb503372010-05-27 20:51:26 +0000452 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000453 p+=quantum_info->pad;
454 q++;
455 }
456 break;
457 }
cristybb503372010-05-27 20:51:26 +0000458 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000459 {
460 p=PushLongPixel(endian,p,&pixel);
461 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000462 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000463 p+=quantum_info->pad;
464 q++;
465 }
466 break;
467 }
468 case 64:
469 {
470 if (quantum_info->format == FloatingPointQuantumFormat)
471 {
472 double
473 pixel;
474
cristybb503372010-05-27 20:51:26 +0000475 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000476 {
477 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000478 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000479 &range_exception);
cristybb503372010-05-27 20:51:26 +0000480 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000481 p+=quantum_info->pad;
482 q++;
483 }
484 break;
485 }
486 }
487 default:
488 {
cristybb503372010-05-27 20:51:26 +0000489 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000490 {
491 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
492 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000493 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000494 p+=quantum_info->pad;
495 q++;
496 }
497 break;
498 }
499 }
500 if (range_exception != MagickFalse)
501 (void) ThrowMagickException(exception,GetMagickModule(),
502 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
503 break;
504 }
505 case IndexAlphaQuantum:
506 {
507 MagickBooleanType
508 range_exception;
509
510 if (image->storage_class != PseudoClass)
511 {
512 (void) ThrowMagickException(exception,GetMagickModule(),
513 ImageError,"ColormappedImageRequired","`%s'",image->filename);
514 return(extent);
515 }
516 range_exception=MagickFalse;
517 switch (quantum_info->depth)
518 {
519 case 1:
520 {
521 register unsigned char
522 pixel;
523
cristybb503372010-05-27 20:51:26 +0000524 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +0000525 {
526 for (bit=0; bit < 8; bit+=2)
527 {
528 if (quantum_info->min_is_white == MagickFalse)
529 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
530 0x00 : 0x01);
531 else
532 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
533 0x00 : 0x01);
534 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
535 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
536 q->green=q->red;
537 q->blue=q->red;
538 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
539 == 0 ? TransparentOpacity : OpaqueOpacity);
540 q++;
541 }
542 }
cristybb503372010-05-27 20:51:26 +0000543 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +0000544 {
545 if (quantum_info->min_is_white == MagickFalse)
546 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
547 0x00 : 0x01);
548 else
549 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
550 0x00 : 0x01);
551 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
552 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
553 q->green=q->red;
554 q->blue=q->red;
555 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
556 0 ? TransparentOpacity : OpaqueOpacity);
557 q++;
558 }
559 break;
560 }
561 case 4:
562 {
563 register unsigned char
564 pixel;
565
566 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000567 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000568 {
569 pixel=(unsigned char) ((*p >> 4) & 0xf);
570 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000571 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000572 pixel=(unsigned char) ((*p) & 0xf);
573 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
574 p++;
575 q++;
576 }
577 break;
578 }
579 case 8:
580 {
581 unsigned char
582 pixel;
583
cristybb503372010-05-27 20:51:26 +0000584 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000585 {
586 p=PushCharPixel(p,&pixel);
587 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000588 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000589 p=PushCharPixel(p,&pixel);
590 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
591 p+=quantum_info->pad;
592 q++;
593 }
594 break;
595 }
596 case 16:
597 {
598 unsigned short
599 pixel;
600
cristyc9672a92010-01-06 00:57:45 +0000601 if (quantum_info->format == FloatingPointQuantumFormat)
602 {
cristybb503372010-05-27 20:51:26 +0000603 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000604 {
605 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000606 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000607 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
608 &range_exception);
cristybb503372010-05-27 20:51:26 +0000609 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000610 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000611 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000612 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +0000613 p+=quantum_info->pad;
614 q++;
615 }
616 break;
617 }
cristybb503372010-05-27 20:51:26 +0000618 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000619 {
620 p=PushShortPixel(endian,p,&pixel);
621 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000622 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000623 p=PushShortPixel(endian,p,&pixel);
624 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
625 p+=quantum_info->pad;
626 q++;
627 }
628 break;
629 }
630 case 32:
631 {
cristy4cb162a2010-05-30 03:04:47 +0000632 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000633 pixel;
634
635 if (quantum_info->format == FloatingPointQuantumFormat)
636 {
637 float
638 pixel;
639
cristybb503372010-05-27 20:51:26 +0000640 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000641 {
642 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000643 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000644 &range_exception);
cristybb503372010-05-27 20:51:26 +0000645 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000646 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000647 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000648 p+=quantum_info->pad;
649 q++;
650 }
651 break;
652 }
cristybb503372010-05-27 20:51:26 +0000653 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000654 {
655 p=PushLongPixel(endian,p,&pixel);
656 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000657 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000658 p=PushLongPixel(endian,p,&pixel);
659 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
660 p+=quantum_info->pad;
661 q++;
662 }
663 break;
664 }
665 case 64:
666 {
667 if (quantum_info->format == FloatingPointQuantumFormat)
668 {
669 double
670 pixel;
671
cristybb503372010-05-27 20:51:26 +0000672 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000673 {
674 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000675 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000676 &range_exception);
cristybb503372010-05-27 20:51:26 +0000677 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000678 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +0000679 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000680 p+=quantum_info->pad;
681 q++;
682 }
683 break;
684 }
685 }
686 default:
687 {
688 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000689 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000690 {
691 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
692 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000693 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000694 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
695 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
696 p+=quantum_info->pad;
697 q++;
698 }
699 break;
700 }
701 }
702 if (range_exception != MagickFalse)
703 (void) ThrowMagickException(exception,GetMagickModule(),
704 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
705 break;
706 }
cristya6a96a12010-08-23 13:37:35 +0000707 case BGRQuantum:
708 {
709 switch (quantum_info->depth)
710 {
711 case 8:
712 {
713 unsigned char
714 pixel;
715
716 for (x=0; x < (ssize_t) number_pixels; x++)
717 {
718 p=PushCharPixel(p,&pixel);
719 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
720 p=PushCharPixel(p,&pixel);
721 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
722 p=PushCharPixel(p,&pixel);
723 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
724 SetOpacityPixelComponent(q,OpaqueOpacity);
725 p+=quantum_info->pad;
726 q++;
727 }
728 break;
729 }
730 case 10:
731 {
732 range=GetQuantumRange(image->depth);
733 if (quantum_info->pack == MagickFalse)
734 {
735 for (x=0; x < (ssize_t) number_pixels; x++)
736 {
737 p=PushLongPixel(endian,p,&pixel);
738 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
739 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
740 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
741 p+=quantum_info->pad;
742 q++;
743 }
744 break;
745 }
746 if (quantum_info->quantum == 32U)
747 {
748 for (x=0; x < (ssize_t) number_pixels; x++)
749 {
750 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
751 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
752 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
753 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
754 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
755 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
756 q++;
757 }
758 break;
759 }
760 for (x=0; x < (ssize_t) number_pixels; x++)
761 {
762 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
763 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
764 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
765 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
766 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
767 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
768 q++;
769 }
770 break;
771 }
772 case 12:
773 {
774 range=GetQuantumRange(image->depth);
775 if (quantum_info->pack == MagickFalse)
776 {
777 unsigned short
778 pixel;
779
780 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
781 {
782 p=PushShortPixel(endian,p,&pixel);
783 switch (x % 3)
784 {
785 default:
786 case 0:
787 {
788 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
789 break;
790 }
791 case 1:
792 {
793 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
794 break;
795 }
796 case 2:
797 {
798 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
799 q++;
800 break;
801 }
802 }
803 p=PushShortPixel(endian,p,&pixel);
804 switch ((x+1) % 3)
805 {
806 default:
807 case 0:
808 {
809 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
810 break;
811 }
812 case 1:
813 {
814 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
815 break;
816 }
817 case 2:
818 {
819 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
820 q++;
821 break;
822 }
823 }
824 p+=quantum_info->pad;
825 }
826 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
827 {
828 p=PushShortPixel(endian,p,&pixel);
829 switch ((x+bit) % 3)
830 {
831 default:
832 case 0:
833 {
834 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
835 break;
836 }
837 case 1:
838 {
839 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
840 break;
841 }
842 case 2:
843 {
844 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
845 q++;
846 break;
847 }
848 }
849 p+=quantum_info->pad;
850 }
851 if (bit != 0)
852 p++;
853 break;
854 }
855 if (quantum_info->quantum == 32U)
856 {
857 for (x=0; x < (ssize_t) number_pixels; x++)
858 {
859 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
860 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
861 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
862 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
863 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
864 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
865 q++;
866 }
867 break;
868 }
869 for (x=0; x < (ssize_t) number_pixels; x++)
870 {
871 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
872 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
873 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
874 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
875 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
876 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
877 q++;
878 }
879 break;
880 }
881 case 16:
882 {
883 unsigned short
884 pixel;
885
886 if (quantum_info->format == FloatingPointQuantumFormat)
887 {
888 for (x=0; x < (ssize_t) number_pixels; x++)
889 {
890 p=PushShortPixel(endian,p,&pixel);
891 q->red=ClampToQuantum((MagickRealType) QuantumRange*
892 HalfToSinglePrecision(pixel));
893 p=PushShortPixel(endian,p,&pixel);
894 q->green=ClampToQuantum((MagickRealType) QuantumRange*
895 HalfToSinglePrecision(pixel));
896 p=PushShortPixel(endian,p,&pixel);
897 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
898 HalfToSinglePrecision(pixel));
899 p+=quantum_info->pad;
900 q++;
901 }
902 break;
903 }
904 for (x=0; x < (ssize_t) number_pixels; x++)
905 {
906 p=PushShortPixel(endian,p,&pixel);
907 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
908 p=PushShortPixel(endian,p,&pixel);
909 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
910 p=PushShortPixel(endian,p,&pixel);
911 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
912 p+=quantum_info->pad;
913 q++;
914 }
915 break;
916 }
917 case 32:
918 {
919 unsigned int
920 pixel;
921
922 if (quantum_info->format == FloatingPointQuantumFormat)
923 {
924 float
925 pixel;
926
927 for (x=0; x < (ssize_t) number_pixels; x++)
928 {
929 p=PushFloatPixel(&quantum_state,p,&pixel);
930 q->red=ClampToQuantum(pixel);
931 p=PushFloatPixel(&quantum_state,p,&pixel);
932 q->green=ClampToQuantum(pixel);
933 p=PushFloatPixel(&quantum_state,p,&pixel);
934 q->blue=ClampToQuantum(pixel);
935 p+=quantum_info->pad;
936 q++;
937 }
938 break;
939 }
940 for (x=0; x < (ssize_t) number_pixels; x++)
941 {
942 p=PushLongPixel(endian,p,&pixel);
943 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
944 p=PushLongPixel(endian,p,&pixel);
945 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
946 p=PushLongPixel(endian,p,&pixel);
947 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
948 p+=quantum_info->pad;
949 q++;
950 }
951 break;
952 }
953 case 64:
954 {
955 if (quantum_info->format == FloatingPointQuantumFormat)
956 {
957 double
958 pixel;
959
960 for (x=0; x < (ssize_t) number_pixels; x++)
961 {
962 p=PushDoublePixel(&quantum_state,p,&pixel);
963 q->red=ClampToQuantum(pixel);
964 p=PushDoublePixel(&quantum_state,p,&pixel);
965 q->green=ClampToQuantum(pixel);
966 p=PushDoublePixel(&quantum_state,p,&pixel);
967 q->blue=ClampToQuantum(pixel);
968 p+=quantum_info->pad;
969 q++;
970 }
971 break;
972 }
973 }
974 default:
975 {
976 range=GetQuantumRange(image->depth);
977 for (x=0; x < (ssize_t) number_pixels; x++)
978 {
979 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
980 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
981 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
982 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
983 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
984 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
985 q++;
986 }
987 break;
988 }
989 }
990 break;
991 }
992 case BGRAQuantum:
993 case BGROQuantum:
994 {
995 switch (quantum_info->depth)
996 {
997 case 8:
998 {
999 unsigned char
1000 pixel;
1001
1002 for (x=0; x < (ssize_t) number_pixels; x++)
1003 {
1004 p=PushCharPixel(p,&pixel);
1005 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1006 p=PushCharPixel(p,&pixel);
1007 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1008 p=PushCharPixel(p,&pixel);
1009 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1010 p=PushCharPixel(p,&pixel);
1011 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1012 p+=quantum_info->pad;
1013 q++;
1014 }
1015 break;
1016 }
1017 case 10:
1018 {
1019 pixel=0;
1020 if (quantum_info->pack == MagickFalse)
1021 {
1022 ssize_t
1023 n;
1024
1025 register ssize_t
1026 i;
1027
1028 size_t
1029 quantum;
1030
1031 n=0;
1032 quantum=0;
1033 for (x=0; x < (ssize_t) number_pixels; x++)
1034 {
1035 for (i=0; i < 4; i++)
1036 {
1037 switch (n % 3)
1038 {
1039 case 0:
1040 {
1041 p=PushLongPixel(endian,p,&pixel);
1042 quantum=(size_t) (ScaleShortToQuantum(
1043 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
1044 break;
1045 }
1046 case 1:
1047 {
1048 quantum=(size_t) (ScaleShortToQuantum(
1049 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
1050 break;
1051 }
1052 case 2:
1053 {
1054 quantum=(size_t) (ScaleShortToQuantum(
1055 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
1056 break;
1057 }
1058 }
1059 switch (i)
1060 {
1061 case 0: q->red=(Quantum) (quantum); break;
1062 case 1: q->green=(Quantum) (quantum); break;
1063 case 2: q->blue=(Quantum) (quantum); break;
1064 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
1065 }
1066 n++;
1067 }
1068 p+=quantum_info->pad;
1069 q++;
1070 }
1071 break;
1072 }
1073 for (x=0; x < (ssize_t) number_pixels; x++)
1074 {
1075 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1076 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
1077 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1078 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
1079 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1080 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
1081 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1082 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
1083 (unsigned short) (pixel << 6)));
1084 q++;
1085 }
1086 break;
1087 }
1088 case 16:
1089 {
1090 unsigned short
1091 pixel;
1092
1093 if (quantum_info->format == FloatingPointQuantumFormat)
1094 {
1095 for (x=0; x < (ssize_t) number_pixels; x++)
1096 {
1097 p=PushShortPixel(endian,p,&pixel);
1098 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1099 HalfToSinglePrecision(pixel));
1100 p=PushShortPixel(endian,p,&pixel);
1101 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1102 HalfToSinglePrecision(pixel));
1103 p=PushShortPixel(endian,p,&pixel);
1104 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1105 HalfToSinglePrecision(pixel));
1106 p=PushShortPixel(endian,p,&pixel);
1107 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1108 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1109 p+=quantum_info->pad;
1110 q++;
1111 }
1112 break;
1113 }
1114 for (x=0; x < (ssize_t) number_pixels; x++)
1115 {
1116 p=PushShortPixel(endian,p,&pixel);
1117 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1118 p=PushShortPixel(endian,p,&pixel);
1119 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1120 p=PushShortPixel(endian,p,&pixel);
1121 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1122 p=PushShortPixel(endian,p,&pixel);
1123 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1124 p+=quantum_info->pad;
1125 q++;
1126 }
1127 break;
1128 }
1129 case 32:
1130 {
1131 unsigned int
1132 pixel;
1133
1134 if (quantum_info->format == FloatingPointQuantumFormat)
1135 {
1136 float
1137 pixel;
1138
1139 for (x=0; x < (ssize_t) number_pixels; x++)
1140 {
1141 p=PushFloatPixel(&quantum_state,p,&pixel);
1142 q->red=ClampToQuantum(pixel);
1143 p=PushFloatPixel(&quantum_state,p,&pixel);
1144 q->green=ClampToQuantum(pixel);
1145 p=PushFloatPixel(&quantum_state,p,&pixel);
1146 q->blue=ClampToQuantum(pixel);
1147 p=PushFloatPixel(&quantum_state,p,&pixel);
1148 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1149 p+=quantum_info->pad;
1150 q++;
1151 }
1152 break;
1153 }
1154 for (x=0; x < (ssize_t) number_pixels; x++)
1155 {
1156 p=PushLongPixel(endian,p,&pixel);
1157 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1158 p=PushLongPixel(endian,p,&pixel);
1159 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1160 p=PushLongPixel(endian,p,&pixel);
1161 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1162 p=PushLongPixel(endian,p,&pixel);
1163 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1164 p+=quantum_info->pad;
1165 q++;
1166 }
1167 break;
1168 }
1169 case 64:
1170 {
1171 if (quantum_info->format == FloatingPointQuantumFormat)
1172 {
1173 double
1174 pixel;
1175
1176 for (x=0; x < (ssize_t) number_pixels; x++)
1177 {
1178 p=PushDoublePixel(&quantum_state,p,&pixel);
1179 q->red=ClampToQuantum(pixel);
1180 p=PushDoublePixel(&quantum_state,p,&pixel);
1181 q->green=ClampToQuantum(pixel);
1182 p=PushDoublePixel(&quantum_state,p,&pixel);
1183 q->blue=ClampToQuantum(pixel);
1184 p=PushDoublePixel(&quantum_state,p,&pixel);
1185 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1186 p+=quantum_info->pad;
1187 q++;
1188 }
1189 break;
1190 }
1191 }
1192 default:
1193 {
1194 range=GetQuantumRange(image->depth);
1195 for (x=0; x < (ssize_t) number_pixels; x++)
1196 {
1197 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1198 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1199 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1200 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1201 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1202 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1203 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1204 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1205 q++;
1206 }
1207 break;
1208 }
1209 }
1210 break;
1211 }
cristy3ed852e2009-09-05 21:47:34 +00001212 case GrayQuantum:
1213 {
1214 switch (quantum_info->depth)
1215 {
1216 case 1:
1217 {
1218 register Quantum
1219 black,
1220 white;
1221
1222 black=0;
1223 white=(Quantum) QuantumRange;
1224 if (quantum_info->min_is_white != MagickFalse)
1225 {
1226 black=(Quantum) QuantumRange;
1227 white=0;
1228 }
cristybb503372010-05-27 20:51:26 +00001229 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +00001230 {
1231 for (bit=0; bit < 8; bit++)
1232 {
1233 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
1234 q->green=q->red;
1235 q->blue=q->red;
1236 q++;
1237 }
1238 p++;
1239 }
cristybb503372010-05-27 20:51:26 +00001240 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001241 {
cristy3b004082010-08-12 19:56:38 +00001242 q->red=(((*p) & (0x01 << (7-bit))) == 0 ? black : white);
cristy3ed852e2009-09-05 21:47:34 +00001243 q->green=q->red;
1244 q->blue=q->red;
1245 q++;
1246 }
1247 if (bit != 0)
1248 p++;
1249 break;
1250 }
1251 case 4:
1252 {
1253 register unsigned char
1254 pixel;
1255
1256 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001257 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001258 {
1259 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +00001260 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001261 q->green=q->red;
1262 q->blue=q->red;
1263 q++;
1264 pixel=(unsigned char) ((*p) & 0xf);
cristyce70c172010-01-07 17:15:30 +00001265 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001266 q->green=q->red;
1267 q->blue=q->red;
1268 p++;
1269 q++;
1270 }
cristybb503372010-05-27 20:51:26 +00001271 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001272 {
1273 pixel=(unsigned char) (*p++ >> 4);
cristyce70c172010-01-07 17:15:30 +00001274 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001275 q->green=q->red;
1276 q->blue=q->red;
1277 q++;
1278 }
1279 break;
1280 }
1281 case 8:
1282 {
1283 unsigned char
1284 pixel;
1285
1286 if (quantum_info->min_is_white != MagickFalse)
1287 {
cristybb503372010-05-27 20:51:26 +00001288 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001289 {
1290 p=PushCharPixel(p,&pixel);
1291 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1292 q->green=q->red;
1293 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +00001294 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001295 p+=quantum_info->pad;
1296 q++;
1297 }
1298 break;
1299 }
cristybb503372010-05-27 20:51:26 +00001300 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001301 {
1302 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001303 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001304 q->green=q->red;
1305 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +00001306 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001307 p+=quantum_info->pad;
1308 q++;
1309 }
1310 break;
1311 }
1312 case 10:
1313 {
1314 range=GetQuantumRange(image->depth);
1315 if (quantum_info->pack == MagickFalse)
1316 {
1317 if (image->endian != LSBEndian)
1318 {
cristybb503372010-05-27 20:51:26 +00001319 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +00001320 {
1321 p=PushLongPixel(endian,p,&pixel);
cristyff024b42010-02-21 22:55:09 +00001322 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +00001323 q->green=q->red;
1324 q->blue=q->red;
1325 q++;
cristyff024b42010-02-21 22:55:09 +00001326 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +00001327 q->green=q->red;
1328 q->blue=q->red;
1329 q++;
cristyff024b42010-02-21 22:55:09 +00001330 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +00001331 q->green=q->red;
1332 q->blue=q->red;
1333 p+=quantum_info->pad;
1334 q++;
1335 }
cristy69702dd2010-02-22 15:26:39 +00001336 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00001337 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +00001338 {
1339 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1340 q->green=q->red;
1341 q->blue=q->red;
1342 q++;
1343 }
cristybb503372010-05-27 20:51:26 +00001344 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +00001345 {
1346 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1347 q->green=q->red;
1348 q->blue=q->red;
1349 q++;
1350 }
cristy3ed852e2009-09-05 21:47:34 +00001351 break;
1352 }
cristybb503372010-05-27 20:51:26 +00001353 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +00001354 {
1355 p=PushLongPixel(endian,p,&pixel);
1356 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1357 q->green=q->red;
1358 q->blue=q->red;
1359 q++;
1360 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1361 q->green=q->red;
1362 q->blue=q->red;
1363 q++;
1364 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1365 q->green=q->red;
1366 q->blue=q->red;
1367 p+=quantum_info->pad;
1368 q++;
1369 }
cristy69702dd2010-02-22 15:26:39 +00001370 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00001371 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +00001372 {
1373 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1374 q->green=q->red;
1375 q->blue=q->red;
1376 q++;
1377 }
cristybb503372010-05-27 20:51:26 +00001378 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +00001379 {
1380 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1381 q->green=q->red;
1382 q->blue=q->red;
1383 q++;
1384 }
cristy3ed852e2009-09-05 21:47:34 +00001385 break;
1386 }
cristybb503372010-05-27 20:51:26 +00001387 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001388 {
1389 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001390 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001391 q->green=q->red;
1392 q->blue=q->red;
1393 p+=quantum_info->pad;
1394 q++;
1395 }
1396 break;
1397 }
1398 case 12:
1399 {
1400 range=GetQuantumRange(image->depth);
1401 if (quantum_info->pack == MagickFalse)
1402 {
1403 unsigned short
1404 pixel;
1405
cristybb503372010-05-27 20:51:26 +00001406 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001407 {
1408 p=PushShortPixel(endian,p,&pixel);
1409 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1410 q->green=q->red;
1411 q->blue=q->red;
1412 q++;
1413 p=PushShortPixel(endian,p,&pixel);
1414 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1415 q->green=q->red;
1416 q->blue=q->red;
1417 p+=quantum_info->pad;
1418 q++;
1419 }
cristybb503372010-05-27 20:51:26 +00001420 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001421 {
1422 p=PushShortPixel(endian,p,&pixel);
1423 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1424 q->green=q->red;
1425 q->blue=q->red;
1426 p+=quantum_info->pad;
1427 q++;
1428 }
1429 if (bit != 0)
1430 p++;
1431 break;
1432 }
cristybb503372010-05-27 20:51:26 +00001433 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001434 {
1435 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001436 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001437 q->green=q->red;
1438 q->blue=q->red;
1439 p+=quantum_info->pad;
1440 q++;
1441 }
1442 break;
1443 }
1444 case 16:
1445 {
1446 unsigned short
1447 pixel;
1448
1449 if (quantum_info->min_is_white != MagickFalse)
1450 {
cristybb503372010-05-27 20:51:26 +00001451 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001452 {
1453 p=PushShortPixel(endian,p,&pixel);
1454 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1455 q->green=q->red;
1456 q->blue=q->red;
1457 p+=quantum_info->pad;
1458 q++;
1459 }
1460 break;
1461 }
cristyc9672a92010-01-06 00:57:45 +00001462 if (quantum_info->format == FloatingPointQuantumFormat)
1463 {
cristybb503372010-05-27 20:51:26 +00001464 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001465 {
1466 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001467 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001468 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001469 q->green=q->red;
1470 q->blue=q->red;
1471 p+=quantum_info->pad;
1472 q++;
1473 }
1474 break;
1475 }
cristybb503372010-05-27 20:51:26 +00001476 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001477 {
1478 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001479 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001480 q->green=q->red;
1481 q->blue=q->red;
1482 p+=quantum_info->pad;
1483 q++;
1484 }
1485 break;
1486 }
1487 case 32:
1488 {
cristy4cb162a2010-05-30 03:04:47 +00001489 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001490 pixel;
1491
1492 if (quantum_info->format == FloatingPointQuantumFormat)
1493 {
1494 float
1495 pixel;
1496
cristybb503372010-05-27 20:51:26 +00001497 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001498 {
1499 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001500 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001501 q->green=q->red;
1502 q->blue=q->red;
1503 p+=quantum_info->pad;
1504 q++;
1505 }
1506 break;
1507 }
cristybb503372010-05-27 20:51:26 +00001508 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001509 {
1510 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001511 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001512 q->green=q->red;
1513 q->blue=q->red;
1514 p+=quantum_info->pad;
1515 q++;
1516 }
1517 break;
1518 }
1519 case 64:
1520 {
1521 if (quantum_info->format == FloatingPointQuantumFormat)
1522 {
1523 double
1524 pixel;
1525
cristybb503372010-05-27 20:51:26 +00001526 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001527 {
1528 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001529 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001530 q->green=q->red;
1531 q->blue=q->red;
1532 p+=quantum_info->pad;
1533 q++;
1534 }
1535 break;
1536 }
1537 }
1538 default:
1539 {
1540 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001541 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001542 {
1543 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001544 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001545 q->green=q->red;
1546 q->blue=q->red;
1547 p+=quantum_info->pad;
1548 q++;
1549 }
1550 break;
1551 }
1552 }
1553 break;
1554 }
1555 case GrayAlphaQuantum:
1556 {
1557 switch (quantum_info->depth)
1558 {
1559 case 1:
1560 {
1561 register unsigned char
1562 pixel;
1563
cristybb503372010-05-27 20:51:26 +00001564 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +00001565 {
1566 for (bit=0; bit < 8; bit+=2)
1567 {
1568 pixel=(unsigned char)
1569 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1570 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1571 q->green=q->red;
1572 q->blue=q->red;
1573 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
cristybfe29252010-08-10 02:12:17 +00001574 == 0 ? TransparentOpacity : OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001575 q++;
1576 }
1577 p++;
1578 }
cristy2837bcc2010-08-07 23:57:39 +00001579 for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +00001580 {
1581 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
cristy2837bcc2010-08-07 23:57:39 +00001582 q->red=(Quantum) (pixel != 0 ? 0 : QuantumRange);
cristy3ed852e2009-09-05 21:47:34 +00001583 q->green=q->red;
1584 q->blue=q->red;
cristybfe29252010-08-10 02:12:17 +00001585 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1586 == 0 ? TransparentOpacity : OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001587 q++;
1588 }
1589 if (bit != 0)
1590 p++;
1591 break;
1592 }
1593 case 4:
1594 {
1595 register unsigned char
1596 pixel;
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 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +00001602 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001603 q->green=q->red;
1604 q->blue=q->red;
1605 pixel=(unsigned char) ((*p) & 0xf);
1606 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1607 p++;
1608 q++;
1609 }
1610 break;
1611 }
1612 case 8:
1613 {
1614 unsigned char
1615 pixel;
1616
cristybb503372010-05-27 20:51:26 +00001617 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001618 {
1619 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001620 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001621 q->green=q->red;
1622 q->blue=q->red;
1623 p=PushCharPixel(p,&pixel);
1624 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1625 p+=quantum_info->pad;
1626 q++;
1627 }
1628 break;
1629 }
1630 case 10:
1631 {
1632 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001633 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001634 {
1635 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001636 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001637 q->green=q->red;
1638 q->blue=q->red;
1639 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001640 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001641 p+=quantum_info->pad;
1642 q++;
1643 }
1644 break;
1645 }
1646 case 12:
1647 {
1648 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001649 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001650 {
1651 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001652 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001653 q->green=q->red;
1654 q->blue=q->red;
1655 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001656 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001657 p+=quantum_info->pad;
1658 q++;
1659 }
1660 break;
1661 }
1662 case 16:
1663 {
1664 unsigned short
1665 pixel;
1666
cristyc9672a92010-01-06 00:57:45 +00001667 if (quantum_info->format == FloatingPointQuantumFormat)
1668 {
cristybb503372010-05-27 20:51:26 +00001669 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001670 {
1671 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001672 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001673 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001674 q->green=q->red;
1675 q->blue=q->red;
1676 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001677 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00001678 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00001679 p+=quantum_info->pad;
1680 q++;
1681 }
1682 break;
1683 }
cristybb503372010-05-27 20:51:26 +00001684 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001685 {
1686 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001687 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001688 q->green=q->red;
1689 q->blue=q->red;
1690 p=PushShortPixel(endian,p,&pixel);
1691 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1692 p+=quantum_info->pad;
1693 q++;
1694 }
1695 break;
1696 }
1697 case 32:
1698 {
cristy4cb162a2010-05-30 03:04:47 +00001699 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001700 pixel;
1701
1702 if (quantum_info->format == FloatingPointQuantumFormat)
1703 {
1704 float
1705 pixel;
1706
cristybb503372010-05-27 20:51:26 +00001707 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001708 {
1709 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001710 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001711 q->green=q->red;
1712 q->blue=q->red;
1713 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001714 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001715 p+=quantum_info->pad;
1716 q++;
1717 }
1718 break;
1719 }
cristybb503372010-05-27 20:51:26 +00001720 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001721 {
1722 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001723 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001724 q->green=q->red;
1725 q->blue=q->red;
1726 p=PushLongPixel(endian,p,&pixel);
1727 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1728 p+=quantum_info->pad;
1729 q++;
1730 }
1731 break;
1732 }
1733 case 64:
1734 {
1735 if (quantum_info->format == FloatingPointQuantumFormat)
1736 {
1737 double
1738 pixel;
1739
cristybb503372010-05-27 20:51:26 +00001740 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001741 {
1742 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001743 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001744 q->green=q->red;
1745 q->blue=q->red;
1746 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001747 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001748 p+=quantum_info->pad;
1749 q++;
1750 }
1751 break;
1752 }
1753 }
1754 default:
1755 {
1756 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001757 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001758 {
1759 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001760 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001761 q->green=q->red;
1762 q->blue=q->red;
1763 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1764 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1765 p+=quantum_info->pad;
1766 q++;
1767 }
1768 break;
1769 }
1770 }
1771 break;
1772 }
1773 case RedQuantum:
1774 case CyanQuantum:
1775 {
1776 switch (quantum_info->depth)
1777 {
1778 case 8:
1779 {
1780 unsigned char
1781 pixel;
1782
cristybb503372010-05-27 20:51:26 +00001783 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001784 {
1785 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001786 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001787 p+=quantum_info->pad;
1788 q++;
1789 }
1790 break;
1791 }
1792 case 16:
1793 {
1794 unsigned short
1795 pixel;
1796
cristyc9672a92010-01-06 00:57:45 +00001797 if (quantum_info->format == FloatingPointQuantumFormat)
1798 {
cristybb503372010-05-27 20:51:26 +00001799 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001800 {
1801 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001802 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001803 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001804 p+=quantum_info->pad;
1805 q++;
1806 }
1807 break;
1808 }
cristybb503372010-05-27 20:51:26 +00001809 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001810 {
1811 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001812 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001813 p+=quantum_info->pad;
1814 q++;
1815 }
1816 break;
1817 }
1818 case 32:
1819 {
cristy4cb162a2010-05-30 03:04:47 +00001820 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001821 pixel;
1822
1823 if (quantum_info->format == FloatingPointQuantumFormat)
1824 {
1825 float
1826 pixel;
1827
cristybb503372010-05-27 20:51:26 +00001828 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001829 {
1830 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001831 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001832 p+=quantum_info->pad;
1833 q++;
1834 }
1835 break;
1836 }
cristybb503372010-05-27 20:51:26 +00001837 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001838 {
1839 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001840 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001841 p+=quantum_info->pad;
1842 q++;
1843 }
1844 break;
1845 }
1846 case 64:
1847 {
1848 if (quantum_info->format == FloatingPointQuantumFormat)
1849 {
1850 double
1851 pixel;
1852
cristybb503372010-05-27 20:51:26 +00001853 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001854 {
1855 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001856 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001857 p+=quantum_info->pad;
1858 q++;
1859 }
1860 break;
1861 }
1862 }
1863 default:
1864 {
1865 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001866 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001867 {
1868 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001869 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001870 p+=quantum_info->pad;
1871 q++;
1872 }
1873 break;
1874 }
1875 }
1876 break;
1877 }
1878 case GreenQuantum:
1879 case MagentaQuantum:
1880 {
1881 switch (quantum_info->depth)
1882 {
1883 case 8:
1884 {
1885 unsigned char
1886 pixel;
1887
cristybb503372010-05-27 20:51:26 +00001888 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001889 {
1890 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001891 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001892 p+=quantum_info->pad;
1893 q++;
1894 }
1895 break;
1896 }
1897 case 16:
1898 {
1899 unsigned short
1900 pixel;
1901
cristyc9672a92010-01-06 00:57:45 +00001902 if (quantum_info->format == FloatingPointQuantumFormat)
1903 {
cristybb503372010-05-27 20:51:26 +00001904 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001905 {
1906 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001907 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001908 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001909 p+=quantum_info->pad;
1910 q++;
1911 }
1912 break;
1913 }
cristybb503372010-05-27 20:51:26 +00001914 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001915 {
1916 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001917 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001918 p+=quantum_info->pad;
1919 q++;
1920 }
1921 break;
1922 }
1923 case 32:
1924 {
cristy4cb162a2010-05-30 03:04:47 +00001925 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001926 pixel;
1927
1928 if (quantum_info->format == FloatingPointQuantumFormat)
1929 {
1930 float
1931 pixel;
1932
cristybb503372010-05-27 20:51:26 +00001933 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001934 {
1935 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001936 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001937 p+=quantum_info->pad;
1938 q++;
1939 }
1940 break;
1941 }
cristybb503372010-05-27 20:51:26 +00001942 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001943 {
1944 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001945 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001946 p+=quantum_info->pad;
1947 q++;
1948 }
1949 break;
1950 }
1951 case 64:
1952 {
1953 if (quantum_info->format == FloatingPointQuantumFormat)
1954 {
1955 double
1956 pixel;
1957
cristybb503372010-05-27 20:51:26 +00001958 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001959 {
1960 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00001961 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001962 p+=quantum_info->pad;
1963 q++;
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 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001974 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001975 p+=quantum_info->pad;
1976 q++;
1977 }
1978 break;
1979 }
1980 }
1981 break;
1982 }
1983 case BlueQuantum:
1984 case YellowQuantum:
1985 {
1986 switch (quantum_info->depth)
1987 {
1988 case 8:
1989 {
1990 unsigned char
1991 pixel;
1992
cristybb503372010-05-27 20:51:26 +00001993 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001994 {
1995 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001996 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001997 p+=quantum_info->pad;
1998 q++;
1999 }
2000 break;
2001 }
2002 case 16:
2003 {
2004 unsigned short
2005 pixel;
2006
cristyc9672a92010-01-06 00:57:45 +00002007 if (quantum_info->format == FloatingPointQuantumFormat)
2008 {
cristybb503372010-05-27 20:51:26 +00002009 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002010 {
2011 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002012 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002013 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002014 p+=quantum_info->pad;
2015 q++;
2016 }
2017 break;
2018 }
cristybb503372010-05-27 20:51:26 +00002019 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002020 {
2021 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002022 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002023 p+=quantum_info->pad;
2024 q++;
2025 }
2026 break;
2027 }
2028 case 32:
2029 {
cristy4cb162a2010-05-30 03:04:47 +00002030 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002031 pixel;
2032
2033 if (quantum_info->format == FloatingPointQuantumFormat)
2034 {
2035 float
2036 pixel;
2037
cristybb503372010-05-27 20:51:26 +00002038 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002039 {
2040 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002041 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002042 p+=quantum_info->pad;
2043 q++;
2044 }
2045 break;
2046 }
cristybb503372010-05-27 20:51:26 +00002047 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002048 {
2049 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002050 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002051 p+=quantum_info->pad;
2052 q++;
2053 }
2054 break;
2055 }
2056 case 64:
2057 {
2058 if (quantum_info->format == FloatingPointQuantumFormat)
2059 {
2060 double
2061 pixel;
2062
cristybb503372010-05-27 20:51:26 +00002063 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002064 {
2065 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002066 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002067 p+=quantum_info->pad;
2068 q++;
2069 }
2070 break;
2071 }
2072 }
2073 default:
2074 {
2075 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002076 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002077 {
2078 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002079 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002080 p+=quantum_info->pad;
2081 q++;
2082 }
2083 break;
2084 }
2085 }
2086 break;
2087 }
2088 case AlphaQuantum:
2089 {
2090 switch (quantum_info->depth)
2091 {
2092 case 8:
2093 {
2094 unsigned char
2095 pixel;
2096
cristybb503372010-05-27 20:51:26 +00002097 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002098 {
2099 p=PushCharPixel(p,&pixel);
2100 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2101 p+=quantum_info->pad;
2102 q++;
2103 }
2104 break;
2105 }
2106 case 16:
2107 {
2108 unsigned short
2109 pixel;
2110
cristyc9672a92010-01-06 00:57:45 +00002111 if (quantum_info->format == FloatingPointQuantumFormat)
2112 {
cristybb503372010-05-27 20:51:26 +00002113 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002114 {
2115 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002116 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002117 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002118 p+=quantum_info->pad;
2119 q++;
2120 }
2121 break;
2122 }
cristybb503372010-05-27 20:51:26 +00002123 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002124 {
2125 p=PushShortPixel(endian,p,&pixel);
2126 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2127 p+=quantum_info->pad;
2128 q++;
2129 }
2130 break;
2131 }
2132 case 32:
2133 {
cristy4cb162a2010-05-30 03:04:47 +00002134 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002135 pixel;
2136
2137 if (quantum_info->format == FloatingPointQuantumFormat)
2138 {
2139 float
2140 pixel;
2141
cristybb503372010-05-27 20:51:26 +00002142 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002143 {
2144 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002145 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002146 p+=quantum_info->pad;
2147 q++;
2148 }
2149 break;
2150 }
cristybb503372010-05-27 20:51:26 +00002151 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002152 {
2153 p=PushLongPixel(endian,p,&pixel);
2154 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2155 p+=quantum_info->pad;
2156 q++;
2157 }
2158 break;
2159 }
2160 case 64:
2161 {
2162 if (quantum_info->format == FloatingPointQuantumFormat)
2163 {
2164 double
2165 pixel;
2166
cristybb503372010-05-27 20:51:26 +00002167 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002168 {
2169 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002170 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002171 p+=quantum_info->pad;
2172 q++;
2173 }
2174 break;
2175 }
2176 }
2177 default:
2178 {
2179 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002180 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002181 {
2182 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2183 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2184 p+=quantum_info->pad;
2185 q++;
2186 }
2187 break;
2188 }
2189 }
2190 break;
2191 }
2192 case BlackQuantum:
2193 {
2194 if (image->colorspace != CMYKColorspace)
2195 {
2196 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2197 "ColorSeparatedImageRequired","`%s'",image->filename);
2198 return(extent);
2199 }
2200 switch (quantum_info->depth)
2201 {
2202 case 8:
2203 {
2204 unsigned char
2205 pixel;
2206
cristybb503372010-05-27 20:51:26 +00002207 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002208 {
2209 p=PushCharPixel(p,&pixel);
2210 indexes[x]=ScaleCharToQuantum(pixel);
2211 p+=quantum_info->pad;
2212 }
2213 break;
2214 }
2215 case 16:
2216 {
2217 unsigned short
2218 pixel;
2219
cristyc9672a92010-01-06 00:57:45 +00002220 if (quantum_info->format == FloatingPointQuantumFormat)
2221 {
cristybb503372010-05-27 20:51:26 +00002222 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002223 {
2224 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002225 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002226 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002227 p+=quantum_info->pad;
2228 }
2229 break;
2230 }
cristybb503372010-05-27 20:51:26 +00002231 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002232 {
2233 p=PushShortPixel(endian,p,&pixel);
2234 indexes[x]=ScaleShortToQuantum(pixel);
2235 p+=quantum_info->pad;
2236 }
2237 break;
2238 }
2239 case 32:
2240 {
cristy4cb162a2010-05-30 03:04:47 +00002241 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002242 pixel;
2243
2244 if (quantum_info->format == FloatingPointQuantumFormat)
2245 {
2246 float
2247 pixel;
2248
cristybb503372010-05-27 20:51:26 +00002249 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002250 {
2251 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002252 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002253 p+=quantum_info->pad;
2254 q++;
2255 }
2256 break;
2257 }
cristybb503372010-05-27 20:51:26 +00002258 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002259 {
2260 p=PushLongPixel(endian,p,&pixel);
2261 indexes[x]=ScaleLongToQuantum(pixel);
2262 p+=quantum_info->pad;
2263 q++;
2264 }
2265 break;
2266 }
2267 case 64:
2268 {
2269 if (quantum_info->format == FloatingPointQuantumFormat)
2270 {
2271 double
2272 pixel;
2273
cristybb503372010-05-27 20:51:26 +00002274 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002275 {
2276 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002277 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002278 p+=quantum_info->pad;
2279 q++;
2280 }
2281 break;
2282 }
2283 }
2284 default:
2285 {
2286 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002287 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002288 {
2289 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2290 indexes[x]=ScaleAnyToQuantum(pixel,range);
2291 p+=quantum_info->pad;
2292 q++;
2293 }
2294 break;
2295 }
2296 }
2297 break;
2298 }
2299 case RGBQuantum:
2300 case CbYCrQuantum:
2301 {
2302 switch (quantum_info->depth)
2303 {
2304 case 8:
2305 {
2306 unsigned char
2307 pixel;
2308
cristybb503372010-05-27 20:51:26 +00002309 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002310 {
2311 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002312 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002313 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002314 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002315 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002316 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2317 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00002318 p+=quantum_info->pad;
2319 q++;
2320 }
2321 break;
2322 }
2323 case 10:
2324 {
2325 range=GetQuantumRange(image->depth);
2326 if (quantum_info->pack == MagickFalse)
2327 {
cristybb503372010-05-27 20:51:26 +00002328 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002329 {
2330 p=PushLongPixel(endian,p,&pixel);
2331 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
2332 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
2333 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
2334 p+=quantum_info->pad;
2335 q++;
2336 }
2337 break;
2338 }
cristy4cb162a2010-05-30 03:04:47 +00002339 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00002340 {
cristybb503372010-05-27 20:51:26 +00002341 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002342 {
2343 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002344 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002345 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002346 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002347 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002348 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002349 q++;
2350 }
2351 break;
2352 }
cristybb503372010-05-27 20:51:26 +00002353 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002354 {
2355 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002356 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002357 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002358 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002359 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002360 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002361 q++;
2362 }
2363 break;
2364 }
2365 case 12:
2366 {
2367 range=GetQuantumRange(image->depth);
2368 if (quantum_info->pack == MagickFalse)
2369 {
2370 unsigned short
2371 pixel;
2372
cristybb503372010-05-27 20:51:26 +00002373 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002374 {
2375 p=PushShortPixel(endian,p,&pixel);
2376 switch (x % 3)
2377 {
2378 default:
2379 case 0:
2380 {
2381 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2382 break;
2383 }
2384 case 1:
2385 {
2386 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2387 break;
2388 }
2389 case 2:
2390 {
2391 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2392 q++;
2393 break;
2394 }
2395 }
2396 p=PushShortPixel(endian,p,&pixel);
2397 switch ((x+1) % 3)
2398 {
2399 default:
2400 case 0:
2401 {
2402 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2403 break;
2404 }
2405 case 1:
2406 {
2407 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2408 break;
2409 }
2410 case 2:
2411 {
2412 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2413 q++;
2414 break;
2415 }
2416 }
2417 p+=quantum_info->pad;
2418 }
cristybb503372010-05-27 20:51:26 +00002419 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00002420 {
2421 p=PushShortPixel(endian,p,&pixel);
2422 switch ((x+bit) % 3)
2423 {
2424 default:
2425 case 0:
2426 {
2427 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2428 break;
2429 }
2430 case 1:
2431 {
2432 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2433 break;
2434 }
2435 case 2:
2436 {
2437 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
2438 q++;
2439 break;
2440 }
2441 }
2442 p+=quantum_info->pad;
2443 }
2444 if (bit != 0)
2445 p++;
2446 break;
2447 }
cristy4cb162a2010-05-30 03:04:47 +00002448 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00002449 {
cristybb503372010-05-27 20:51:26 +00002450 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002451 {
2452 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002453 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002454 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002455 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002456 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002457 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002458 q++;
2459 }
2460 break;
2461 }
cristybb503372010-05-27 20:51:26 +00002462 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002463 {
2464 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002465 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002466 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002467 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002468 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002469 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002470 q++;
2471 }
2472 break;
2473 }
2474 case 16:
2475 {
2476 unsigned short
2477 pixel;
2478
cristyc9672a92010-01-06 00:57:45 +00002479 if (quantum_info->format == FloatingPointQuantumFormat)
2480 {
cristybb503372010-05-27 20:51:26 +00002481 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002482 {
2483 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002484 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002485 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002486 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002487 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002488 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002489 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002490 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002491 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002492 p+=quantum_info->pad;
2493 q++;
2494 }
2495 break;
2496 }
cristybb503372010-05-27 20:51:26 +00002497 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002498 {
2499 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002500 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002501 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002502 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002503 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002504 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002505 p+=quantum_info->pad;
2506 q++;
2507 }
2508 break;
2509 }
2510 case 32:
2511 {
cristy4cb162a2010-05-30 03:04:47 +00002512 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002513 pixel;
2514
2515 if (quantum_info->format == FloatingPointQuantumFormat)
2516 {
2517 float
2518 pixel;
2519
cristybb503372010-05-27 20:51:26 +00002520 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002521 {
2522 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002523 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002524 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002525 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002526 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002527 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002528 p+=quantum_info->pad;
2529 q++;
2530 }
2531 break;
2532 }
cristybb503372010-05-27 20:51:26 +00002533 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002534 {
2535 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002536 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002537 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002538 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002539 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002540 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002541 p+=quantum_info->pad;
2542 q++;
2543 }
2544 break;
2545 }
2546 case 64:
2547 {
2548 if (quantum_info->format == FloatingPointQuantumFormat)
2549 {
2550 double
2551 pixel;
2552
cristybb503372010-05-27 20:51:26 +00002553 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002554 {
2555 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002556 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002557 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002558 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002559 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002560 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002561 p+=quantum_info->pad;
2562 q++;
2563 }
2564 break;
2565 }
2566 }
2567 default:
2568 {
2569 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002570 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002571 {
2572 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002573 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002574 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002575 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002576 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002577 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002578 q++;
2579 }
2580 break;
2581 }
2582 }
2583 break;
2584 }
2585 case RGBAQuantum:
2586 case RGBOQuantum:
2587 case CbYCrAQuantum:
2588 {
2589 switch (quantum_info->depth)
2590 {
2591 case 8:
2592 {
2593 unsigned char
2594 pixel;
2595
cristybb503372010-05-27 20:51:26 +00002596 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002597 {
2598 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002599 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002600 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002601 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002602 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002603 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002604 p=PushCharPixel(p,&pixel);
2605 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2606 p+=quantum_info->pad;
2607 q++;
2608 }
2609 break;
2610 }
2611 case 10:
2612 {
2613 pixel=0;
2614 if (quantum_info->pack == MagickFalse)
2615 {
cristybb503372010-05-27 20:51:26 +00002616 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002617 n;
2618
cristybb503372010-05-27 20:51:26 +00002619 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002620 i;
2621
cristybb503372010-05-27 20:51:26 +00002622 size_t
cristy3ed852e2009-09-05 21:47:34 +00002623 quantum;
2624
2625 n=0;
2626 quantum=0;
cristybb503372010-05-27 20:51:26 +00002627 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002628 {
2629 for (i=0; i < 4; i++)
2630 {
2631 switch (n % 3)
2632 {
2633 case 0:
2634 {
2635 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00002636 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002637 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2638 break;
2639 }
2640 case 1:
2641 {
cristybb503372010-05-27 20:51:26 +00002642 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002643 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2644 break;
2645 }
2646 case 2:
2647 {
cristybb503372010-05-27 20:51:26 +00002648 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002649 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2650 break;
2651 }
2652 }
2653 switch (i)
2654 {
2655 case 0: q->red=(Quantum) (quantum); break;
2656 case 1: q->green=(Quantum) (quantum); break;
2657 case 2: q->blue=(Quantum) (quantum); break;
2658 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2659 }
2660 n++;
2661 }
2662 p+=quantum_info->pad;
2663 q++;
2664 }
2665 break;
2666 }
cristybb503372010-05-27 20:51:26 +00002667 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002668 {
2669 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2670 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2671 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2672 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2673 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2674 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2675 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2676 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2677 (unsigned short) (pixel << 6)));
2678 q++;
2679 }
2680 break;
2681 }
2682 case 16:
2683 {
2684 unsigned short
2685 pixel;
2686
cristyc9672a92010-01-06 00:57:45 +00002687 if (quantum_info->format == FloatingPointQuantumFormat)
2688 {
cristybb503372010-05-27 20:51:26 +00002689 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002690 {
2691 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002692 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002693 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002694 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002695 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002696 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002697 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002698 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002699 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002700 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002701 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002702 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002703 p+=quantum_info->pad;
2704 q++;
2705 }
2706 break;
2707 }
cristybb503372010-05-27 20:51:26 +00002708 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002709 {
2710 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002711 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002712 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002713 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002714 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002715 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002716 p=PushShortPixel(endian,p,&pixel);
2717 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2718 p+=quantum_info->pad;
2719 q++;
2720 }
2721 break;
2722 }
2723 case 32:
2724 {
cristy4cb162a2010-05-30 03:04:47 +00002725 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002726 pixel;
2727
2728 if (quantum_info->format == FloatingPointQuantumFormat)
2729 {
2730 float
2731 pixel;
2732
cristybb503372010-05-27 20:51:26 +00002733 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002734 {
2735 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002736 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002737 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002738 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002739 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002740 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002741 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002742 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002743 p+=quantum_info->pad;
2744 q++;
2745 }
2746 break;
2747 }
cristybb503372010-05-27 20:51:26 +00002748 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002749 {
2750 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002751 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002752 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002753 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002754 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002755 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002756 p=PushLongPixel(endian,p,&pixel);
2757 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2758 p+=quantum_info->pad;
2759 q++;
2760 }
2761 break;
2762 }
2763 case 64:
2764 {
2765 if (quantum_info->format == FloatingPointQuantumFormat)
2766 {
2767 double
2768 pixel;
2769
cristybb503372010-05-27 20:51:26 +00002770 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002771 {
2772 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002773 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002774 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002775 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002776 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002777 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002778 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002779 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002780 p+=quantum_info->pad;
2781 q++;
2782 }
2783 break;
2784 }
2785 }
2786 default:
2787 {
2788 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002789 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002790 {
2791 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002792 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002793 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002794 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002795 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002796 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002797 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2798 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2799 q++;
2800 }
2801 break;
2802 }
2803 }
2804 break;
2805 }
2806 case CMYKQuantum:
2807 {
2808 if (image->colorspace != CMYKColorspace)
2809 {
2810 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2811 "ColorSeparatedImageRequired","`%s'",image->filename);
2812 return(extent);
2813 }
2814 switch (quantum_info->depth)
2815 {
2816 case 8:
2817 {
2818 unsigned char
2819 pixel;
2820
cristybb503372010-05-27 20:51:26 +00002821 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002822 {
2823 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002824 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002825 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002826 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002827 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002828 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002829 p=PushCharPixel(p,&pixel);
2830 indexes[x]=ScaleCharToQuantum(pixel);
2831 p+=quantum_info->pad;
2832 q++;
2833 }
2834 break;
2835 }
2836 case 16:
2837 {
2838 unsigned short
2839 pixel;
2840
cristyc9672a92010-01-06 00:57:45 +00002841 if (quantum_info->format == FloatingPointQuantumFormat)
2842 {
cristybb503372010-05-27 20:51:26 +00002843 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002844 {
2845 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002846 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002847 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002848 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002849 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002850 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002851 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002852 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002853 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002854 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002855 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002856 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002857 p+=quantum_info->pad;
2858 q++;
2859 }
2860 break;
2861 }
cristybb503372010-05-27 20:51:26 +00002862 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002863 {
2864 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002865 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002866 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002867 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002868 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002869 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002870 p=PushShortPixel(endian,p,&pixel);
2871 indexes[x]=ScaleShortToQuantum(pixel);
2872 p+=quantum_info->pad;
2873 q++;
2874 }
2875 break;
2876 }
2877 case 32:
2878 {
cristy4cb162a2010-05-30 03:04:47 +00002879 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002880 pixel;
2881
2882 if (quantum_info->format == FloatingPointQuantumFormat)
2883 {
2884 float
2885 pixel;
2886
cristybb503372010-05-27 20:51:26 +00002887 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002888 {
2889 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002890 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002891 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002892 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002893 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002894 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002895 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002896 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002897 p+=quantum_info->pad;
2898 q++;
2899 }
2900 break;
2901 }
cristybb503372010-05-27 20:51:26 +00002902 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002903 {
2904 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002905 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002906 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002907 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002908 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002909 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002910 p=PushLongPixel(endian,p,&pixel);
2911 indexes[x]=ScaleLongToQuantum(pixel);
2912 p+=quantum_info->pad;
2913 q++;
2914 }
2915 break;
2916 }
2917 case 64:
2918 {
2919 if (quantum_info->format == FloatingPointQuantumFormat)
2920 {
2921 double
2922 pixel;
2923
cristybb503372010-05-27 20:51:26 +00002924 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002925 {
2926 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002927 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002928 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002929 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002930 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002931 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002932 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00002933 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002934 p+=quantum_info->pad;
2935 q++;
2936 }
2937 break;
2938 }
2939 }
2940 default:
2941 {
2942 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002943 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002944 {
2945 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002946 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002947 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002948 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002949 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002950 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002951 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2952 indexes[x]=ScaleAnyToQuantum(pixel,range);
2953 q++;
2954 }
2955 break;
2956 }
2957 }
2958 break;
2959 }
2960 case CMYKAQuantum:
2961 case CMYKOQuantum:
2962 {
2963 if (image->colorspace != CMYKColorspace)
2964 {
2965 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2966 "ColorSeparatedImageRequired","`%s'",image->filename);
2967 return(extent);
2968 }
2969 switch (quantum_info->depth)
2970 {
2971 case 8:
2972 {
2973 unsigned char
2974 pixel;
2975
cristybb503372010-05-27 20:51:26 +00002976 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002977 {
2978 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002979 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002980 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002981 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002982 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002983 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002984 p=PushCharPixel(p,&pixel);
2985 indexes[x]=ScaleCharToQuantum(pixel);
2986 p=PushCharPixel(p,&pixel);
2987 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2988 p+=quantum_info->pad;
2989 q++;
2990 }
2991 break;
2992 }
2993 case 16:
2994 {
2995 unsigned short
2996 pixel;
2997
cristyc9672a92010-01-06 00:57:45 +00002998 if (quantum_info->format == FloatingPointQuantumFormat)
2999 {
cristybb503372010-05-27 20:51:26 +00003000 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00003001 {
3002 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003003 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00003004 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00003005 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003006 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00003007 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00003008 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003009 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00003010 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00003011 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003012 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00003013 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00003014 p=PushShortPixel(endian,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003015 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00003016 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00003017 p+=quantum_info->pad;
3018 q++;
3019 }
3020 break;
3021 }
cristybb503372010-05-27 20:51:26 +00003022 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003023 {
3024 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003025 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003026 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003027 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003028 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003029 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003030 p=PushShortPixel(endian,p,&pixel);
3031 indexes[x]=ScaleShortToQuantum(pixel);
3032 p=PushShortPixel(endian,p,&pixel);
3033 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
3034 p+=quantum_info->pad;
3035 q++;
3036 }
3037 break;
3038 }
3039 case 32:
3040 {
cristy4cb162a2010-05-30 03:04:47 +00003041 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00003042 pixel;
3043
3044 if (quantum_info->format == FloatingPointQuantumFormat)
3045 {
3046 float
3047 pixel;
3048
cristybb503372010-05-27 20:51:26 +00003049 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003050 {
3051 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003052 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003053 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003054 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003055 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003056 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003057 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003058 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003059 p=PushFloatPixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003060 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003061 p+=quantum_info->pad;
3062 q++;
3063 }
3064 break;
3065 }
cristybb503372010-05-27 20:51:26 +00003066 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003067 {
3068 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003069 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003070 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003071 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003072 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003073 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003074 p=PushLongPixel(endian,p,&pixel);
3075 indexes[x]=ScaleLongToQuantum(pixel);
3076 p=PushLongPixel(endian,p,&pixel);
3077 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
3078 p+=quantum_info->pad;
3079 q++;
3080 }
3081 break;
3082 }
3083 case 64:
3084 {
3085 if (quantum_info->format == FloatingPointQuantumFormat)
3086 {
3087 double
3088 pixel;
3089
cristybb503372010-05-27 20:51:26 +00003090 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003091 {
3092 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003093 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003094 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003095 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003096 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003097 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003098 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003099 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00003100 p=PushDoublePixel(&quantum_state,p,&pixel);
cristye85007d2010-06-06 22:51:36 +00003101 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00003102 p=PushDoublePixel(&quantum_state,p,&pixel);
3103 p+=quantum_info->pad;
3104 q++;
3105 }
3106 break;
3107 }
3108 }
3109 default:
3110 {
3111 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00003112 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003113 {
3114 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003115 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00003116 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003117 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00003118 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003119 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00003120 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3121 indexes[x]=ScaleAnyToQuantum(pixel,range);
3122 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3123 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
3124 q++;
3125 }
3126 break;
3127 }
3128 }
3129 break;
3130 }
3131 case CbYCrYQuantum:
3132 {
3133 switch (quantum_info->depth)
3134 {
3135 case 10:
3136 {
3137 Quantum
3138 cbcr[4];
3139
3140 pixel=0;
3141 if (quantum_info->pack == MagickFalse)
3142 {
cristybb503372010-05-27 20:51:26 +00003143 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003144 n;
3145
cristybb503372010-05-27 20:51:26 +00003146 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00003147 i;
3148
cristybb503372010-05-27 20:51:26 +00003149 size_t
cristy3ed852e2009-09-05 21:47:34 +00003150 quantum;
3151
3152 n=0;
3153 quantum=0;
cristybb503372010-05-27 20:51:26 +00003154 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00003155 {
3156 for (i=0; i < 4; i++)
3157 {
3158 switch (n % 3)
3159 {
3160 case 0:
3161 {
3162 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00003163 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00003164 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
3165 break;
3166 }
3167 case 1:
3168 {
cristybb503372010-05-27 20:51:26 +00003169 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00003170 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
3171 break;
3172 }
3173 case 2:
3174 {
cristybb503372010-05-27 20:51:26 +00003175 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00003176 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
3177 break;
3178 }
3179 }
3180 cbcr[i]=(Quantum) (quantum);
3181 n++;
3182 }
3183 p+=quantum_info->pad;
3184 q->red=cbcr[1];
3185 q->green=cbcr[0];
3186 q->blue=cbcr[2];
3187 q++;
3188 q->red=cbcr[3];
3189 q->green=cbcr[0];
3190 q->blue=cbcr[2];
3191 q++;
3192 }
3193 break;
3194 }
3195 }
3196 default:
3197 {
3198 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00003199 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003200 {
3201 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003202 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00003203 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00003204 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00003205 q++;
3206 }
3207 break;
3208 }
3209 }
3210 break;
3211 }
3212 default:
3213 break;
3214 }
3215 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3216 {
3217 Quantum
3218 quantum;
3219
3220 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003221 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003222
3223 q=GetAuthenticPixelQueue(image);
3224 if (image_view != (CacheView *) NULL)
3225 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003226 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003227 {
3228 quantum=q->red;
3229 q->red=q->green;
3230 q->green=quantum;
3231 q++;
3232 }
3233 }
3234 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
3235 {
3236 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003237 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003238
3239 q=GetAuthenticPixelQueue(image);
3240 if (image_view != (CacheView *) NULL)
3241 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003242 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003243 {
cristy46f08202010-01-10 04:04:21 +00003244 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00003245 q++;
3246 }
3247 }
3248 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
3249 {
3250 MagickRealType
3251 alpha;
3252
3253 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00003254 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00003255
3256 /*
3257 Disassociate alpha.
3258 */
3259 q=GetAuthenticPixelQueue(image);
3260 if (image_view != (CacheView *) NULL)
3261 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00003262 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00003263 {
3264 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
3265 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
cristye85007d2010-06-06 22:51:36 +00003266 q->red=ClampToQuantum(alpha*q->red);
3267 q->green=ClampToQuantum(alpha*q->green);
3268 q->blue=ClampToQuantum(alpha*q->blue);
cristy3ed852e2009-09-05 21:47:34 +00003269 q++;
3270 }
3271 }
3272 return(extent);
3273}