blob: 465589c068368d46712dff363ada2f12af43c933 [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
cristybb503372010-05-27 20:51:26 +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++);
cristy4cb162a2010-05-30 03:04:47 +0000210 quantum_state->bits=8U;
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;
cristyeaedf062010-05-29 22:36:02 +0000215 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
cristy4cb162a2010-05-30 03:04:47 +0000218 quantum_state->bits) &~ ((~0U) << quantum_bits));
cristy3ed852e2009-09-05 21:47:34 +0000219 }
220 return(pixels);
221}
222
223static inline const unsigned char *PushQuantumLongPixel(
cristybb503372010-05-27 20:51:26 +0000224 QuantumState *quantum_state,const size_t depth,
cristy4cb162a2010-05-30 03:04:47 +0000225 const unsigned char *pixels,unsigned int *quantum)
cristy3ed852e2009-09-05 21:47:34 +0000226{
cristybb503372010-05-27 20:51:26 +0000227 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000228 i;
229
cristybb503372010-05-27 20:51:26 +0000230 register size_t
cristy3ed852e2009-09-05 21:47:34 +0000231 quantum_bits;
232
233 *quantum=0UL;
cristybb503372010-05-27 20:51:26 +0000234 for (i=(ssize_t) depth; i > 0; )
cristy3ed852e2009-09-05 21:47:34 +0000235 {
236 if (quantum_state->bits == 0)
237 {
238 pixels=PushLongPixel(quantum_state->endian,pixels,
239 &quantum_state->pixel);
cristy4cb162a2010-05-30 03:04:47 +0000240 quantum_state->bits=32U;
cristy3ed852e2009-09-05 21:47:34 +0000241 }
cristybb503372010-05-27 20:51:26 +0000242 quantum_bits=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
cristy4cb162a2010-05-30 03:04:47 +0000245 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
cristy3ed852e2009-09-05 21:47:34 +0000246 quantum_state->mask[quantum_bits]) << (depth-i));
cristyeaedf062010-05-29 22:36:02 +0000247 i-=(ssize_t) quantum_bits;
cristy3ed852e2009-09-05 21:47:34 +0000248 quantum_state->bits-=quantum_bits;
249 }
250 return(pixels);
251}
252
253MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
254 const QuantumInfo *quantum_info,const QuantumType quantum_type,
255 const unsigned char *pixels,ExceptionInfo *exception)
256{
257 EndianType
258 endian;
259
cristybb503372010-05-27 20:51:26 +0000260 ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000261 bit;
262
263 MagickSizeType
264 number_pixels;
265
266 QuantumAny
267 range;
268
269 QuantumState
270 quantum_state;
271
272 register const unsigned char
cristyaebafa22009-11-26 01:48:56 +0000273 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000274
275 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000276 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000277
cristybb503372010-05-27 20:51:26 +0000278 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000279 x;
280
281 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000282 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000283
284 size_t
285 extent;
286
cristy4cb162a2010-05-30 03:04:47 +0000287 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000288 pixel;
289
290 assert(image != (Image *) NULL);
291 assert(image->signature == MagickSignature);
292 if (image->debug != MagickFalse)
293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
294 assert(quantum_info != (QuantumInfo *) NULL);
295 assert(quantum_info->signature == MagickSignature);
296 if (pixels == (const unsigned char *) NULL)
297 pixels=GetQuantumPixels(quantum_info);
298 x=0;
299 p=pixels;
cristy8a7ea362010-03-10 20:31:43 +0000300 if (image_view == (CacheView *) NULL)
301 {
302 number_pixels=GetImageExtent(image);
303 q=GetAuthenticPixelQueue(image);
304 indexes=GetAuthenticIndexQueue(image);
305 }
306 else
cristy3ed852e2009-09-05 21:47:34 +0000307 {
308 number_pixels=GetCacheViewExtent(image_view);
309 q=GetCacheViewAuthenticPixelQueue(image_view);
310 indexes=GetCacheViewAuthenticIndexQueue(image_view);
311 }
312 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
313 extent=GetQuantumExtent(image,quantum_info,quantum_type);
314 endian=quantum_state.endian;
315 switch (quantum_type)
316 {
317 case IndexQuantum:
318 {
319 MagickBooleanType
320 range_exception;
321
322 if (image->storage_class != PseudoClass)
323 {
324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
325 "ColormappedImageRequired","`%s'",image->filename);
326 return(extent);
327 }
328 range_exception=MagickFalse;
329 switch (quantum_info->depth)
330 {
331 case 1:
332 {
333 register unsigned char
334 pixel;
335
cristybb503372010-05-27 20:51:26 +0000336 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000337 {
338 for (bit=0; bit < 8; bit++)
339 {
340 if (quantum_info->min_is_white == MagickFalse)
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
342 0x00 : 0x01);
343 else
344 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
345 0x00 : 0x01);
346 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000347 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000348 q++;
349 }
350 p++;
351 }
cristybb503372010-05-27 20:51:26 +0000352 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000353 {
354 if (quantum_info->min_is_white == MagickFalse)
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
356 0x00 : 0x01);
357 else
358 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
359 0x00 : 0x01);
360 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000361 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000362 q++;
363 }
364 break;
365 }
366 case 4:
367 {
368 register unsigned char
369 pixel;
370
cristybb503372010-05-27 20:51:26 +0000371 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000372 {
373 pixel=(unsigned char) ((*p >> 4) & 0xf);
374 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000375 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000376 q++;
377 pixel=(unsigned char) ((*p) & 0xf);
378 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000379 *q=image->colormap[(ssize_t) indexes[x+1]];
cristy3ed852e2009-09-05 21:47:34 +0000380 p++;
381 q++;
382 }
cristybb503372010-05-27 20:51:26 +0000383 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000384 {
385 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
386 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000387 *q=image->colormap[(ssize_t) indexes[x+bit]];
cristy3ed852e2009-09-05 21:47:34 +0000388 q++;
389 }
390 break;
391 }
392 case 8:
393 {
394 unsigned char
395 pixel;
396
cristybb503372010-05-27 20:51:26 +0000397 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000398 {
399 p=PushCharPixel(p,&pixel);
400 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000401 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000402 p+=quantum_info->pad;
403 q++;
404 }
405 break;
406 }
407 case 16:
408 {
409 unsigned short
410 pixel;
411
cristyc9672a92010-01-06 00:57:45 +0000412 if (quantum_info->format == FloatingPointQuantumFormat)
413 {
cristybb503372010-05-27 20:51:26 +0000414 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000415 {
416 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000417 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000418 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
419 &range_exception);
cristybb503372010-05-27 20:51:26 +0000420 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000421 p+=quantum_info->pad;
422 q++;
423 }
424 break;
425 }
cristybb503372010-05-27 20:51:26 +0000426 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000427 {
428 p=PushShortPixel(endian,p,&pixel);
429 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000430 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000431 p+=quantum_info->pad;
432 q++;
433 }
434 break;
435 }
436 case 32:
437 {
cristy4cb162a2010-05-30 03:04:47 +0000438 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000439 pixel;
440
441 if (quantum_info->format == FloatingPointQuantumFormat)
442 {
443 float
444 pixel;
445
cristybb503372010-05-27 20:51:26 +0000446 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000447 {
448 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000449 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000450 &range_exception);
cristybb503372010-05-27 20:51:26 +0000451 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000452 p+=quantum_info->pad;
453 q++;
454 }
455 break;
456 }
cristybb503372010-05-27 20:51:26 +0000457 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000458 {
459 p=PushLongPixel(endian,p,&pixel);
460 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000461 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000462 p+=quantum_info->pad;
463 q++;
464 }
465 break;
466 }
467 case 64:
468 {
469 if (quantum_info->format == FloatingPointQuantumFormat)
470 {
471 double
472 pixel;
473
cristybb503372010-05-27 20:51:26 +0000474 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000475 {
476 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000477 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000478 &range_exception);
cristybb503372010-05-27 20:51:26 +0000479 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000480 p+=quantum_info->pad;
481 q++;
482 }
483 break;
484 }
485 }
486 default:
487 {
cristybb503372010-05-27 20:51:26 +0000488 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000489 {
490 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
491 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000492 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000493 p+=quantum_info->pad;
494 q++;
495 }
496 break;
497 }
498 }
499 if (range_exception != MagickFalse)
500 (void) ThrowMagickException(exception,GetMagickModule(),
501 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
502 break;
503 }
504 case IndexAlphaQuantum:
505 {
506 MagickBooleanType
507 range_exception;
508
509 if (image->storage_class != PseudoClass)
510 {
511 (void) ThrowMagickException(exception,GetMagickModule(),
512 ImageError,"ColormappedImageRequired","`%s'",image->filename);
513 return(extent);
514 }
515 range_exception=MagickFalse;
516 switch (quantum_info->depth)
517 {
518 case 1:
519 {
520 register unsigned char
521 pixel;
522
cristybb503372010-05-27 20:51:26 +0000523 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +0000524 {
525 for (bit=0; bit < 8; bit+=2)
526 {
527 if (quantum_info->min_is_white == MagickFalse)
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
529 0x00 : 0x01);
530 else
531 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
532 0x00 : 0x01);
533 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
534 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
535 q->green=q->red;
536 q->blue=q->red;
537 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
538 == 0 ? TransparentOpacity : OpaqueOpacity);
539 q++;
540 }
541 }
cristybb503372010-05-27 20:51:26 +0000542 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +0000543 {
544 if (quantum_info->min_is_white == MagickFalse)
545 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
546 0x00 : 0x01);
547 else
548 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
549 0x00 : 0x01);
550 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
551 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
552 q->green=q->red;
553 q->blue=q->red;
554 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
555 0 ? TransparentOpacity : OpaqueOpacity);
556 q++;
557 }
558 break;
559 }
560 case 4:
561 {
562 register unsigned char
563 pixel;
564
565 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000566 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000567 {
568 pixel=(unsigned char) ((*p >> 4) & 0xf);
569 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000570 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000571 pixel=(unsigned char) ((*p) & 0xf);
572 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
573 p++;
574 q++;
575 }
576 break;
577 }
578 case 8:
579 {
580 unsigned char
581 pixel;
582
cristybb503372010-05-27 20:51:26 +0000583 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000584 {
585 p=PushCharPixel(p,&pixel);
586 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000587 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000588 p=PushCharPixel(p,&pixel);
589 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
590 p+=quantum_info->pad;
591 q++;
592 }
593 break;
594 }
595 case 16:
596 {
597 unsigned short
598 pixel;
599
cristyc9672a92010-01-06 00:57:45 +0000600 if (quantum_info->format == FloatingPointQuantumFormat)
601 {
cristybb503372010-05-27 20:51:26 +0000602 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000603 {
604 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000605 indexes[x]=PushColormapIndex(image,ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000606 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
607 &range_exception);
cristybb503372010-05-27 20:51:26 +0000608 *q=image->colormap[(ssize_t) indexes[x]];
cristyc9672a92010-01-06 00:57:45 +0000609 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000610 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +0000611 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +0000612 p+=quantum_info->pad;
613 q++;
614 }
615 break;
616 }
cristybb503372010-05-27 20:51:26 +0000617 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000618 {
619 p=PushShortPixel(endian,p,&pixel);
620 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000621 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000622 p=PushShortPixel(endian,p,&pixel);
623 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
624 p+=quantum_info->pad;
625 q++;
626 }
627 break;
628 }
629 case 32:
630 {
cristy4cb162a2010-05-30 03:04:47 +0000631 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000632 pixel;
633
634 if (quantum_info->format == FloatingPointQuantumFormat)
635 {
636 float
637 pixel;
638
cristybb503372010-05-27 20:51:26 +0000639 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000640 {
641 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000642 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000643 &range_exception);
cristybb503372010-05-27 20:51:26 +0000644 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000645 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000646 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000647 p+=quantum_info->pad;
648 q++;
649 }
650 break;
651 }
cristybb503372010-05-27 20:51:26 +0000652 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000653 {
654 p=PushLongPixel(endian,p,&pixel);
655 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000656 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000657 p=PushLongPixel(endian,p,&pixel);
658 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
659 p+=quantum_info->pad;
660 q++;
661 }
662 break;
663 }
664 case 64:
665 {
666 if (quantum_info->format == FloatingPointQuantumFormat)
667 {
668 double
669 pixel;
670
cristybb503372010-05-27 20:51:26 +0000671 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000672 {
673 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000674 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
cristy3ed852e2009-09-05 21:47:34 +0000675 &range_exception);
cristybb503372010-05-27 20:51:26 +0000676 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000677 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000678 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000679 p+=quantum_info->pad;
680 q++;
681 }
682 break;
683 }
684 }
685 default:
686 {
687 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000688 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000689 {
690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
691 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
cristybb503372010-05-27 20:51:26 +0000692 *q=image->colormap[(ssize_t) indexes[x]];
cristy3ed852e2009-09-05 21:47:34 +0000693 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
694 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
695 p+=quantum_info->pad;
696 q++;
697 }
698 break;
699 }
700 }
701 if (range_exception != MagickFalse)
702 (void) ThrowMagickException(exception,GetMagickModule(),
703 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
704 break;
705 }
706 case GrayQuantum:
707 {
708 switch (quantum_info->depth)
709 {
710 case 1:
711 {
712 register Quantum
713 black,
714 white;
715
716 black=0;
717 white=(Quantum) QuantumRange;
718 if (quantum_info->min_is_white != MagickFalse)
719 {
720 black=(Quantum) QuantumRange;
721 white=0;
722 }
cristybb503372010-05-27 20:51:26 +0000723 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
cristy3ed852e2009-09-05 21:47:34 +0000724 {
725 for (bit=0; bit < 8; bit++)
726 {
727 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
728 q->green=q->red;
729 q->blue=q->red;
730 q++;
731 }
732 p++;
733 }
cristybb503372010-05-27 20:51:26 +0000734 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000735 {
736 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
737 q->green=q->red;
738 q->blue=q->red;
739 q++;
740 }
741 if (bit != 0)
742 p++;
743 break;
744 }
745 case 4:
746 {
747 register unsigned char
748 pixel;
749
750 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +0000751 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000752 {
753 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +0000754 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000755 q->green=q->red;
756 q->blue=q->red;
757 q++;
758 pixel=(unsigned char) ((*p) & 0xf);
cristyce70c172010-01-07 17:15:30 +0000759 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000760 q->green=q->red;
761 q->blue=q->red;
762 p++;
763 q++;
764 }
cristybb503372010-05-27 20:51:26 +0000765 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000766 {
767 pixel=(unsigned char) (*p++ >> 4);
cristyce70c172010-01-07 17:15:30 +0000768 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000769 q->green=q->red;
770 q->blue=q->red;
771 q++;
772 }
773 break;
774 }
775 case 8:
776 {
777 unsigned char
778 pixel;
779
780 if (quantum_info->min_is_white != MagickFalse)
781 {
cristybb503372010-05-27 20:51:26 +0000782 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000783 {
784 p=PushCharPixel(p,&pixel);
785 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
786 q->green=q->red;
787 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +0000788 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000789 p+=quantum_info->pad;
790 q++;
791 }
792 break;
793 }
cristybb503372010-05-27 20:51:26 +0000794 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000795 {
796 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000797 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000798 q->green=q->red;
799 q->blue=q->red;
cristyce70c172010-01-07 17:15:30 +0000800 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +0000801 p+=quantum_info->pad;
802 q++;
803 }
804 break;
805 }
806 case 10:
807 {
808 range=GetQuantumRange(image->depth);
809 if (quantum_info->pack == MagickFalse)
810 {
811 if (image->endian != LSBEndian)
812 {
cristybb503372010-05-27 20:51:26 +0000813 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +0000814 {
815 p=PushLongPixel(endian,p,&pixel);
cristyff024b42010-02-21 22:55:09 +0000816 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000817 q->green=q->red;
818 q->blue=q->red;
819 q++;
cristyff024b42010-02-21 22:55:09 +0000820 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000821 q->green=q->red;
822 q->blue=q->red;
823 q++;
cristyff024b42010-02-21 22:55:09 +0000824 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
cristy3ed852e2009-09-05 21:47:34 +0000825 q->green=q->red;
826 q->blue=q->red;
827 p+=quantum_info->pad;
828 q++;
829 }
cristy69702dd2010-02-22 15:26:39 +0000830 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +0000831 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +0000832 {
833 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
834 q->green=q->red;
835 q->blue=q->red;
836 q++;
837 }
cristybb503372010-05-27 20:51:26 +0000838 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +0000839 {
840 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
841 q->green=q->red;
842 q->blue=q->red;
843 q++;
844 }
cristy3ed852e2009-09-05 21:47:34 +0000845 break;
846 }
cristybb503372010-05-27 20:51:26 +0000847 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
cristy3ed852e2009-09-05 21:47:34 +0000848 {
849 p=PushLongPixel(endian,p,&pixel);
850 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
851 q->green=q->red;
852 q->blue=q->red;
853 q++;
854 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
855 q->green=q->red;
856 q->blue=q->red;
857 q++;
858 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
859 q->green=q->red;
860 q->blue=q->red;
861 p+=quantum_info->pad;
862 q++;
863 }
cristy69702dd2010-02-22 15:26:39 +0000864 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +0000865 if (x++ < (ssize_t) (number_pixels-1))
cristy69702dd2010-02-22 15:26:39 +0000866 {
867 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
868 q->green=q->red;
869 q->blue=q->red;
870 q++;
871 }
cristybb503372010-05-27 20:51:26 +0000872 if (x++ < (ssize_t) number_pixels)
cristy69702dd2010-02-22 15:26:39 +0000873 {
874 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
875 q->green=q->red;
876 q->blue=q->red;
877 q++;
878 }
cristy3ed852e2009-09-05 21:47:34 +0000879 break;
880 }
cristybb503372010-05-27 20:51:26 +0000881 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000882 {
883 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000884 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000885 q->green=q->red;
886 q->blue=q->red;
887 p+=quantum_info->pad;
888 q++;
889 }
890 break;
891 }
892 case 12:
893 {
894 range=GetQuantumRange(image->depth);
895 if (quantum_info->pack == MagickFalse)
896 {
897 unsigned short
898 pixel;
899
cristybb503372010-05-27 20:51:26 +0000900 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +0000901 {
902 p=PushShortPixel(endian,p,&pixel);
903 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
904 q->green=q->red;
905 q->blue=q->red;
906 q++;
907 p=PushShortPixel(endian,p,&pixel);
908 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
909 q->green=q->red;
910 q->blue=q->red;
911 p+=quantum_info->pad;
912 q++;
913 }
cristybb503372010-05-27 20:51:26 +0000914 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +0000915 {
916 p=PushShortPixel(endian,p,&pixel);
917 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
918 q->green=q->red;
919 q->blue=q->red;
920 p+=quantum_info->pad;
921 q++;
922 }
923 if (bit != 0)
924 p++;
925 break;
926 }
cristybb503372010-05-27 20:51:26 +0000927 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000928 {
929 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000930 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +0000931 q->green=q->red;
932 q->blue=q->red;
933 p+=quantum_info->pad;
934 q++;
935 }
936 break;
937 }
938 case 16:
939 {
940 unsigned short
941 pixel;
942
943 if (quantum_info->min_is_white != MagickFalse)
944 {
cristybb503372010-05-27 20:51:26 +0000945 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000946 {
947 p=PushShortPixel(endian,p,&pixel);
948 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
949 q->green=q->red;
950 q->blue=q->red;
951 p+=quantum_info->pad;
952 q++;
953 }
954 break;
955 }
cristyc9672a92010-01-06 00:57:45 +0000956 if (quantum_info->format == FloatingPointQuantumFormat)
957 {
cristybb503372010-05-27 20:51:26 +0000958 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +0000959 {
960 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000961 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +0000962 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +0000963 q->green=q->red;
964 q->blue=q->red;
965 p+=quantum_info->pad;
966 q++;
967 }
968 break;
969 }
cristybb503372010-05-27 20:51:26 +0000970 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000971 {
972 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000973 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +0000974 q->green=q->red;
975 q->blue=q->red;
976 p+=quantum_info->pad;
977 q++;
978 }
979 break;
980 }
981 case 32:
982 {
cristy4cb162a2010-05-30 03:04:47 +0000983 unsigned int
cristy3ed852e2009-09-05 21:47:34 +0000984 pixel;
985
986 if (quantum_info->format == FloatingPointQuantumFormat)
987 {
988 float
989 pixel;
990
cristybb503372010-05-27 20:51:26 +0000991 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +0000992 {
993 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +0000994 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +0000995 q->green=q->red;
996 q->blue=q->red;
997 p+=quantum_info->pad;
998 q++;
999 }
1000 break;
1001 }
cristybb503372010-05-27 20:51:26 +00001002 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001003 {
1004 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001005 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001006 q->green=q->red;
1007 q->blue=q->red;
1008 p+=quantum_info->pad;
1009 q++;
1010 }
1011 break;
1012 }
1013 case 64:
1014 {
1015 if (quantum_info->format == FloatingPointQuantumFormat)
1016 {
1017 double
1018 pixel;
1019
cristybb503372010-05-27 20:51:26 +00001020 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001021 {
1022 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001023 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001024 q->green=q->red;
1025 q->blue=q->red;
1026 p+=quantum_info->pad;
1027 q++;
1028 }
1029 break;
1030 }
1031 }
1032 default:
1033 {
1034 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001035 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001036 {
1037 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001038 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001039 q->green=q->red;
1040 q->blue=q->red;
1041 p+=quantum_info->pad;
1042 q++;
1043 }
1044 break;
1045 }
1046 }
1047 break;
1048 }
1049 case GrayAlphaQuantum:
1050 {
1051 switch (quantum_info->depth)
1052 {
1053 case 1:
1054 {
1055 register unsigned char
1056 pixel;
1057
cristybb503372010-05-27 20:51:26 +00001058 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
cristy3ed852e2009-09-05 21:47:34 +00001059 {
1060 for (bit=0; bit < 8; bit+=2)
1061 {
1062 pixel=(unsigned char)
1063 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1064 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1065 q->green=q->red;
1066 q->blue=q->red;
1067 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1068 == 0 ? TransparentOpacity : OpaqueOpacity);
1069 q++;
1070 }
1071 p++;
1072 }
cristybb503372010-05-27 20:51:26 +00001073 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
cristy3ed852e2009-09-05 21:47:34 +00001074 {
1075 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1076 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1077 q->green=q->red;
1078 q->blue=q->red;
1079 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1080 ? TransparentOpacity : OpaqueOpacity);
1081 q++;
1082 }
1083 if (bit != 0)
1084 p++;
1085 break;
1086 }
1087 case 4:
1088 {
1089 register unsigned char
1090 pixel;
1091
1092 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001093 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001094 {
1095 pixel=(unsigned char) ((*p >> 4) & 0xf);
cristyce70c172010-01-07 17:15:30 +00001096 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001097 q->green=q->red;
1098 q->blue=q->red;
1099 pixel=(unsigned char) ((*p) & 0xf);
1100 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1101 p++;
1102 q++;
1103 }
1104 break;
1105 }
1106 case 8:
1107 {
1108 unsigned char
1109 pixel;
1110
cristybb503372010-05-27 20:51:26 +00001111 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001112 {
1113 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001114 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001115 q->green=q->red;
1116 q->blue=q->red;
1117 p=PushCharPixel(p,&pixel);
1118 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1119 p+=quantum_info->pad;
1120 q++;
1121 }
1122 break;
1123 }
1124 case 10:
1125 {
1126 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001127 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001128 {
1129 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001130 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001131 q->green=q->red;
1132 q->blue=q->red;
1133 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001134 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001135 p+=quantum_info->pad;
1136 q++;
1137 }
1138 break;
1139 }
1140 case 12:
1141 {
1142 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001143 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001144 {
1145 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001146 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001147 q->green=q->red;
1148 q->blue=q->red;
1149 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001150 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001151 p+=quantum_info->pad;
1152 q++;
1153 }
1154 break;
1155 }
1156 case 16:
1157 {
1158 unsigned short
1159 pixel;
1160
cristyc9672a92010-01-06 00:57:45 +00001161 if (quantum_info->format == FloatingPointQuantumFormat)
1162 {
cristybb503372010-05-27 20:51:26 +00001163 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001164 {
1165 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001166 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001167 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001168 q->green=q->red;
1169 q->blue=q->red;
1170 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001171 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00001172 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00001173 p+=quantum_info->pad;
1174 q++;
1175 }
1176 break;
1177 }
cristybb503372010-05-27 20:51:26 +00001178 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001179 {
1180 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001181 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001182 q->green=q->red;
1183 q->blue=q->red;
1184 p=PushShortPixel(endian,p,&pixel);
1185 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1186 p+=quantum_info->pad;
1187 q++;
1188 }
1189 break;
1190 }
1191 case 32:
1192 {
cristy4cb162a2010-05-30 03:04:47 +00001193 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001194 pixel;
1195
1196 if (quantum_info->format == FloatingPointQuantumFormat)
1197 {
1198 float
1199 pixel;
1200
cristybb503372010-05-27 20:51:26 +00001201 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001202 {
1203 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001204 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001205 q->green=q->red;
1206 q->blue=q->red;
1207 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001208 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001209 p+=quantum_info->pad;
1210 q++;
1211 }
1212 break;
1213 }
cristybb503372010-05-27 20:51:26 +00001214 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001215 {
1216 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001217 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001218 q->green=q->red;
1219 q->blue=q->red;
1220 p=PushLongPixel(endian,p,&pixel);
1221 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1222 p+=quantum_info->pad;
1223 q++;
1224 }
1225 break;
1226 }
1227 case 64:
1228 {
1229 if (quantum_info->format == FloatingPointQuantumFormat)
1230 {
1231 double
1232 pixel;
1233
cristybb503372010-05-27 20:51:26 +00001234 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001235 {
1236 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001237 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001238 q->green=q->red;
1239 q->blue=q->red;
1240 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001241 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001242 p+=quantum_info->pad;
1243 q++;
1244 }
1245 break;
1246 }
1247 }
1248 default:
1249 {
1250 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001251 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001252 {
1253 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001254 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001255 q->green=q->red;
1256 q->blue=q->red;
1257 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1258 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1259 p+=quantum_info->pad;
1260 q++;
1261 }
1262 break;
1263 }
1264 }
1265 break;
1266 }
1267 case RedQuantum:
1268 case CyanQuantum:
1269 {
1270 switch (quantum_info->depth)
1271 {
1272 case 8:
1273 {
1274 unsigned char
1275 pixel;
1276
cristybb503372010-05-27 20:51:26 +00001277 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001278 {
1279 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001280 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001281 p+=quantum_info->pad;
1282 q++;
1283 }
1284 break;
1285 }
1286 case 16:
1287 {
1288 unsigned short
1289 pixel;
1290
cristyc9672a92010-01-06 00:57:45 +00001291 if (quantum_info->format == FloatingPointQuantumFormat)
1292 {
cristybb503372010-05-27 20:51:26 +00001293 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001294 {
1295 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001296 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001297 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001298 p+=quantum_info->pad;
1299 q++;
1300 }
1301 break;
1302 }
cristybb503372010-05-27 20:51:26 +00001303 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001304 {
1305 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001306 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001307 p+=quantum_info->pad;
1308 q++;
1309 }
1310 break;
1311 }
1312 case 32:
1313 {
cristy4cb162a2010-05-30 03:04:47 +00001314 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001315 pixel;
1316
1317 if (quantum_info->format == FloatingPointQuantumFormat)
1318 {
1319 float
1320 pixel;
1321
cristybb503372010-05-27 20:51:26 +00001322 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001323 {
1324 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001325 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001326 p+=quantum_info->pad;
1327 q++;
1328 }
1329 break;
1330 }
cristybb503372010-05-27 20:51:26 +00001331 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001332 {
1333 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001334 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001335 p+=quantum_info->pad;
1336 q++;
1337 }
1338 break;
1339 }
1340 case 64:
1341 {
1342 if (quantum_info->format == FloatingPointQuantumFormat)
1343 {
1344 double
1345 pixel;
1346
cristybb503372010-05-27 20:51:26 +00001347 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001348 {
1349 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001350 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001351 p+=quantum_info->pad;
1352 q++;
1353 }
1354 break;
1355 }
1356 }
1357 default:
1358 {
1359 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001360 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001361 {
1362 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001363 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001364 p+=quantum_info->pad;
1365 q++;
1366 }
1367 break;
1368 }
1369 }
1370 break;
1371 }
1372 case GreenQuantum:
1373 case MagentaQuantum:
1374 {
1375 switch (quantum_info->depth)
1376 {
1377 case 8:
1378 {
1379 unsigned char
1380 pixel;
1381
cristybb503372010-05-27 20:51:26 +00001382 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001383 {
1384 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001385 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001386 p+=quantum_info->pad;
1387 q++;
1388 }
1389 break;
1390 }
1391 case 16:
1392 {
1393 unsigned short
1394 pixel;
1395
cristyc9672a92010-01-06 00:57:45 +00001396 if (quantum_info->format == FloatingPointQuantumFormat)
1397 {
cristybb503372010-05-27 20:51:26 +00001398 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001399 {
1400 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001401 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001402 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001403 p+=quantum_info->pad;
1404 q++;
1405 }
1406 break;
1407 }
cristybb503372010-05-27 20:51:26 +00001408 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001409 {
1410 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001411 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001412 p+=quantum_info->pad;
1413 q++;
1414 }
1415 break;
1416 }
1417 case 32:
1418 {
cristy4cb162a2010-05-30 03:04:47 +00001419 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001420 pixel;
1421
1422 if (quantum_info->format == FloatingPointQuantumFormat)
1423 {
1424 float
1425 pixel;
1426
cristybb503372010-05-27 20:51:26 +00001427 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001428 {
1429 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001430 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001431 p+=quantum_info->pad;
1432 q++;
1433 }
1434 break;
1435 }
cristybb503372010-05-27 20:51:26 +00001436 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001437 {
1438 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001439 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001440 p+=quantum_info->pad;
1441 q++;
1442 }
1443 break;
1444 }
1445 case 64:
1446 {
1447 if (quantum_info->format == FloatingPointQuantumFormat)
1448 {
1449 double
1450 pixel;
1451
cristybb503372010-05-27 20:51:26 +00001452 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001453 {
1454 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001455 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001456 p+=quantum_info->pad;
1457 q++;
1458 }
1459 break;
1460 }
1461 }
1462 default:
1463 {
1464 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001465 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001466 {
1467 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001468 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001469 p+=quantum_info->pad;
1470 q++;
1471 }
1472 break;
1473 }
1474 }
1475 break;
1476 }
1477 case BlueQuantum:
1478 case YellowQuantum:
1479 {
1480 switch (quantum_info->depth)
1481 {
1482 case 8:
1483 {
1484 unsigned char
1485 pixel;
1486
cristybb503372010-05-27 20:51:26 +00001487 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001488 {
1489 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001490 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001491 p+=quantum_info->pad;
1492 q++;
1493 }
1494 break;
1495 }
1496 case 16:
1497 {
1498 unsigned short
1499 pixel;
1500
cristyc9672a92010-01-06 00:57:45 +00001501 if (quantum_info->format == FloatingPointQuantumFormat)
1502 {
cristybb503372010-05-27 20:51:26 +00001503 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001504 {
1505 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001506 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001507 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001508 p+=quantum_info->pad;
1509 q++;
1510 }
1511 break;
1512 }
cristybb503372010-05-27 20:51:26 +00001513 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001514 {
1515 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001516 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001517 p+=quantum_info->pad;
1518 q++;
1519 }
1520 break;
1521 }
1522 case 32:
1523 {
cristy4cb162a2010-05-30 03:04:47 +00001524 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001525 pixel;
1526
1527 if (quantum_info->format == FloatingPointQuantumFormat)
1528 {
1529 float
1530 pixel;
1531
cristybb503372010-05-27 20:51:26 +00001532 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001533 {
1534 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001535 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001536 p+=quantum_info->pad;
1537 q++;
1538 }
1539 break;
1540 }
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=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001544 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001545 p+=quantum_info->pad;
1546 q++;
1547 }
1548 break;
1549 }
1550 case 64:
1551 {
1552 if (quantum_info->format == FloatingPointQuantumFormat)
1553 {
1554 double
1555 pixel;
1556
cristybb503372010-05-27 20:51:26 +00001557 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001558 {
1559 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001560 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001561 p+=quantum_info->pad;
1562 q++;
1563 }
1564 break;
1565 }
1566 }
1567 default:
1568 {
1569 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001570 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001571 {
1572 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001573 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001574 p+=quantum_info->pad;
1575 q++;
1576 }
1577 break;
1578 }
1579 }
1580 break;
1581 }
1582 case AlphaQuantum:
1583 {
1584 switch (quantum_info->depth)
1585 {
1586 case 8:
1587 {
1588 unsigned char
1589 pixel;
1590
cristybb503372010-05-27 20:51:26 +00001591 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001592 {
1593 p=PushCharPixel(p,&pixel);
1594 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1595 p+=quantum_info->pad;
1596 q++;
1597 }
1598 break;
1599 }
1600 case 16:
1601 {
1602 unsigned short
1603 pixel;
1604
cristyc9672a92010-01-06 00:57:45 +00001605 if (quantum_info->format == FloatingPointQuantumFormat)
1606 {
cristybb503372010-05-27 20:51:26 +00001607 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001608 {
1609 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001610 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00001611 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00001612 p+=quantum_info->pad;
1613 q++;
1614 }
1615 break;
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=PushShortPixel(endian,p,&pixel);
1620 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1621 p+=quantum_info->pad;
1622 q++;
1623 }
1624 break;
1625 }
1626 case 32:
1627 {
cristy4cb162a2010-05-30 03:04:47 +00001628 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001629 pixel;
1630
1631 if (quantum_info->format == FloatingPointQuantumFormat)
1632 {
1633 float
1634 pixel;
1635
cristybb503372010-05-27 20:51:26 +00001636 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001637 {
1638 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001639 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001640 p+=quantum_info->pad;
1641 q++;
1642 }
1643 break;
1644 }
cristybb503372010-05-27 20:51:26 +00001645 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001646 {
1647 p=PushLongPixel(endian,p,&pixel);
1648 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1649 p+=quantum_info->pad;
1650 q++;
1651 }
1652 break;
1653 }
1654 case 64:
1655 {
1656 if (quantum_info->format == FloatingPointQuantumFormat)
1657 {
1658 double
1659 pixel;
1660
cristybb503372010-05-27 20:51:26 +00001661 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001662 {
1663 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001664 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001665 p+=quantum_info->pad;
1666 q++;
1667 }
1668 break;
1669 }
1670 }
1671 default:
1672 {
1673 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001674 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001675 {
1676 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1677 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1678 p+=quantum_info->pad;
1679 q++;
1680 }
1681 break;
1682 }
1683 }
1684 break;
1685 }
1686 case BlackQuantum:
1687 {
1688 if (image->colorspace != CMYKColorspace)
1689 {
1690 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1691 "ColorSeparatedImageRequired","`%s'",image->filename);
1692 return(extent);
1693 }
1694 switch (quantum_info->depth)
1695 {
1696 case 8:
1697 {
1698 unsigned char
1699 pixel;
1700
cristybb503372010-05-27 20:51:26 +00001701 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001702 {
1703 p=PushCharPixel(p,&pixel);
1704 indexes[x]=ScaleCharToQuantum(pixel);
1705 p+=quantum_info->pad;
1706 }
1707 break;
1708 }
1709 case 16:
1710 {
1711 unsigned short
1712 pixel;
1713
cristyc9672a92010-01-06 00:57:45 +00001714 if (quantum_info->format == FloatingPointQuantumFormat)
1715 {
cristybb503372010-05-27 20:51:26 +00001716 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001717 {
1718 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001719 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001720 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001721 p+=quantum_info->pad;
1722 }
1723 break;
1724 }
cristybb503372010-05-27 20:51:26 +00001725 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001726 {
1727 p=PushShortPixel(endian,p,&pixel);
1728 indexes[x]=ScaleShortToQuantum(pixel);
1729 p+=quantum_info->pad;
1730 }
1731 break;
1732 }
1733 case 32:
1734 {
cristy4cb162a2010-05-30 03:04:47 +00001735 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00001736 pixel;
1737
1738 if (quantum_info->format == FloatingPointQuantumFormat)
1739 {
1740 float
1741 pixel;
1742
cristybb503372010-05-27 20:51:26 +00001743 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001744 {
1745 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001746 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001747 p+=quantum_info->pad;
1748 q++;
1749 }
1750 break;
1751 }
cristybb503372010-05-27 20:51:26 +00001752 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001753 {
1754 p=PushLongPixel(endian,p,&pixel);
1755 indexes[x]=ScaleLongToQuantum(pixel);
1756 p+=quantum_info->pad;
1757 q++;
1758 }
1759 break;
1760 }
1761 case 64:
1762 {
1763 if (quantum_info->format == FloatingPointQuantumFormat)
1764 {
1765 double
1766 pixel;
1767
cristybb503372010-05-27 20:51:26 +00001768 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001769 {
1770 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001771 indexes[x]=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00001772 p+=quantum_info->pad;
1773 q++;
1774 }
1775 break;
1776 }
1777 }
1778 default:
1779 {
1780 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00001781 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001782 {
1783 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1784 indexes[x]=ScaleAnyToQuantum(pixel,range);
1785 p+=quantum_info->pad;
1786 q++;
1787 }
1788 break;
1789 }
1790 }
1791 break;
1792 }
1793 case RGBQuantum:
1794 case CbYCrQuantum:
1795 {
1796 switch (quantum_info->depth)
1797 {
1798 case 8:
1799 {
1800 unsigned char
1801 pixel;
1802
cristybb503372010-05-27 20:51:26 +00001803 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001804 {
1805 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001806 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001807 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001808 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001809 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001810 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1811 SetOpacityPixelComponent(q,OpaqueOpacity);
cristy3ed852e2009-09-05 21:47:34 +00001812 p+=quantum_info->pad;
1813 q++;
1814 }
1815 break;
1816 }
1817 case 10:
1818 {
1819 range=GetQuantumRange(image->depth);
1820 if (quantum_info->pack == MagickFalse)
1821 {
cristybb503372010-05-27 20:51:26 +00001822 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001823 {
1824 p=PushLongPixel(endian,p,&pixel);
1825 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1826 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1827 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1828 p+=quantum_info->pad;
1829 q++;
1830 }
1831 break;
1832 }
cristy4cb162a2010-05-30 03:04:47 +00001833 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00001834 {
cristybb503372010-05-27 20:51:26 +00001835 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001836 {
1837 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001838 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001839 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001840 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001841 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001842 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001843 q++;
1844 }
1845 break;
1846 }
cristybb503372010-05-27 20:51:26 +00001847 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001848 {
1849 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001850 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001851 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001852 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001853 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001854 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001855 q++;
1856 }
1857 break;
1858 }
1859 case 12:
1860 {
1861 range=GetQuantumRange(image->depth);
1862 if (quantum_info->pack == MagickFalse)
1863 {
1864 unsigned short
1865 pixel;
1866
cristybb503372010-05-27 20:51:26 +00001867 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
cristy3ed852e2009-09-05 21:47:34 +00001868 {
1869 p=PushShortPixel(endian,p,&pixel);
1870 switch (x % 3)
1871 {
1872 default:
1873 case 0:
1874 {
1875 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1876 break;
1877 }
1878 case 1:
1879 {
1880 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1881 break;
1882 }
1883 case 2:
1884 {
1885 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1886 q++;
1887 break;
1888 }
1889 }
1890 p=PushShortPixel(endian,p,&pixel);
1891 switch ((x+1) % 3)
1892 {
1893 default:
1894 case 0:
1895 {
1896 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1897 break;
1898 }
1899 case 1:
1900 {
1901 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1902 break;
1903 }
1904 case 2:
1905 {
1906 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1907 q++;
1908 break;
1909 }
1910 }
1911 p+=quantum_info->pad;
1912 }
cristybb503372010-05-27 20:51:26 +00001913 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
cristy3ed852e2009-09-05 21:47:34 +00001914 {
1915 p=PushShortPixel(endian,p,&pixel);
1916 switch ((x+bit) % 3)
1917 {
1918 default:
1919 case 0:
1920 {
1921 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1922 break;
1923 }
1924 case 1:
1925 {
1926 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1927 break;
1928 }
1929 case 2:
1930 {
1931 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1932 q++;
1933 break;
1934 }
1935 }
1936 p+=quantum_info->pad;
1937 }
1938 if (bit != 0)
1939 p++;
1940 break;
1941 }
cristy4cb162a2010-05-30 03:04:47 +00001942 if (quantum_info->quantum == 32U)
cristy3ed852e2009-09-05 21:47:34 +00001943 {
cristybb503372010-05-27 20:51:26 +00001944 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001945 {
1946 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001947 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001948 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001949 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001950 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001951 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001952 q++;
1953 }
1954 break;
1955 }
cristybb503372010-05-27 20:51:26 +00001956 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001957 {
1958 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001959 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001960 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001961 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001962 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001963 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00001964 q++;
1965 }
1966 break;
1967 }
1968 case 16:
1969 {
1970 unsigned short
1971 pixel;
1972
cristyc9672a92010-01-06 00:57:45 +00001973 if (quantum_info->format == FloatingPointQuantumFormat)
1974 {
cristybb503372010-05-27 20:51:26 +00001975 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00001976 {
1977 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001978 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001979 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001980 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001981 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001982 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001983 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001984 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00001985 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00001986 p+=quantum_info->pad;
1987 q++;
1988 }
1989 break;
1990 }
cristybb503372010-05-27 20:51:26 +00001991 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00001992 {
1993 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001994 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001995 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001996 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001997 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00001998 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00001999 p+=quantum_info->pad;
2000 q++;
2001 }
2002 break;
2003 }
2004 case 32:
2005 {
cristy4cb162a2010-05-30 03:04:47 +00002006 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002007 pixel;
2008
2009 if (quantum_info->format == FloatingPointQuantumFormat)
2010 {
2011 float
2012 pixel;
2013
cristybb503372010-05-27 20:51:26 +00002014 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002015 {
2016 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002017 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002018 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002019 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002020 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002021 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002022 p+=quantum_info->pad;
2023 q++;
2024 }
2025 break;
2026 }
cristybb503372010-05-27 20:51:26 +00002027 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002028 {
2029 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002030 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002031 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002032 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002033 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002034 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002035 p+=quantum_info->pad;
2036 q++;
2037 }
2038 break;
2039 }
2040 case 64:
2041 {
2042 if (quantum_info->format == FloatingPointQuantumFormat)
2043 {
2044 double
2045 pixel;
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=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002050 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002051 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002052 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002053 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002054 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002055 p+=quantum_info->pad;
2056 q++;
2057 }
2058 break;
2059 }
2060 }
2061 default:
2062 {
2063 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002064 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002065 {
2066 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002067 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002068 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002069 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002070 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002071 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002072 q++;
2073 }
2074 break;
2075 }
2076 }
2077 break;
2078 }
2079 case RGBAQuantum:
2080 case RGBOQuantum:
2081 case CbYCrAQuantum:
2082 {
2083 switch (quantum_info->depth)
2084 {
2085 case 8:
2086 {
2087 unsigned char
2088 pixel;
2089
cristybb503372010-05-27 20:51:26 +00002090 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002091 {
2092 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002093 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002094 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002095 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002096 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002097 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002098 p=PushCharPixel(p,&pixel);
2099 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2100 p+=quantum_info->pad;
2101 q++;
2102 }
2103 break;
2104 }
2105 case 10:
2106 {
2107 pixel=0;
2108 if (quantum_info->pack == MagickFalse)
2109 {
cristybb503372010-05-27 20:51:26 +00002110 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002111 n;
2112
cristybb503372010-05-27 20:51:26 +00002113 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002114 i;
2115
cristybb503372010-05-27 20:51:26 +00002116 size_t
cristy3ed852e2009-09-05 21:47:34 +00002117 quantum;
2118
2119 n=0;
2120 quantum=0;
cristybb503372010-05-27 20:51:26 +00002121 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002122 {
2123 for (i=0; i < 4; i++)
2124 {
2125 switch (n % 3)
2126 {
2127 case 0:
2128 {
2129 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00002130 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002131 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2132 break;
2133 }
2134 case 1:
2135 {
cristybb503372010-05-27 20:51:26 +00002136 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002137 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2138 break;
2139 }
2140 case 2:
2141 {
cristybb503372010-05-27 20:51:26 +00002142 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002143 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2144 break;
2145 }
2146 }
2147 switch (i)
2148 {
2149 case 0: q->red=(Quantum) (quantum); break;
2150 case 1: q->green=(Quantum) (quantum); break;
2151 case 2: q->blue=(Quantum) (quantum); break;
2152 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2153 }
2154 n++;
2155 }
2156 p+=quantum_info->pad;
2157 q++;
2158 }
2159 break;
2160 }
cristybb503372010-05-27 20:51:26 +00002161 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002162 {
2163 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2164 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2165 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2166 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2167 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2168 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2169 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2170 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2171 (unsigned short) (pixel << 6)));
2172 q++;
2173 }
2174 break;
2175 }
2176 case 16:
2177 {
2178 unsigned short
2179 pixel;
2180
cristyc9672a92010-01-06 00:57:45 +00002181 if (quantum_info->format == FloatingPointQuantumFormat)
2182 {
cristybb503372010-05-27 20:51:26 +00002183 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002184 {
2185 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002186 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002187 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002188 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002189 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002190 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002191 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002192 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002193 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002194 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002195 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002196 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002197 p+=quantum_info->pad;
2198 q++;
2199 }
2200 break;
2201 }
cristybb503372010-05-27 20:51:26 +00002202 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002203 {
2204 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002205 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002206 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002207 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002208 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002209 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002210 p=PushShortPixel(endian,p,&pixel);
2211 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2212 p+=quantum_info->pad;
2213 q++;
2214 }
2215 break;
2216 }
2217 case 32:
2218 {
cristy4cb162a2010-05-30 03:04:47 +00002219 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002220 pixel;
2221
2222 if (quantum_info->format == FloatingPointQuantumFormat)
2223 {
2224 float
2225 pixel;
2226
cristybb503372010-05-27 20:51:26 +00002227 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002228 {
2229 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002230 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002231 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002232 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002233 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002234 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002235 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002236 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002237 p+=quantum_info->pad;
2238 q++;
2239 }
2240 break;
2241 }
cristybb503372010-05-27 20:51:26 +00002242 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002243 {
2244 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002245 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002246 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002247 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002248 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002249 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002250 p=PushLongPixel(endian,p,&pixel);
2251 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2252 p+=quantum_info->pad;
2253 q++;
2254 }
2255 break;
2256 }
2257 case 64:
2258 {
2259 if (quantum_info->format == FloatingPointQuantumFormat)
2260 {
2261 double
2262 pixel;
2263
cristybb503372010-05-27 20:51:26 +00002264 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002265 {
2266 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002267 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002268 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002269 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002270 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002271 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002272 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002273 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002274 p+=quantum_info->pad;
2275 q++;
2276 }
2277 break;
2278 }
2279 }
2280 default:
2281 {
2282 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002283 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002284 {
2285 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002286 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002287 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002288 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002289 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002290 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002291 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2292 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2293 q++;
2294 }
2295 break;
2296 }
2297 }
2298 break;
2299 }
2300 case CMYKQuantum:
2301 {
2302 if (image->colorspace != CMYKColorspace)
2303 {
2304 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2305 "ColorSeparatedImageRequired","`%s'",image->filename);
2306 return(extent);
2307 }
2308 switch (quantum_info->depth)
2309 {
2310 case 8:
2311 {
2312 unsigned char
2313 pixel;
2314
cristybb503372010-05-27 20:51:26 +00002315 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002316 {
2317 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002318 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002319 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002320 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002321 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002322 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002323 p=PushCharPixel(p,&pixel);
2324 indexes[x]=ScaleCharToQuantum(pixel);
2325 p+=quantum_info->pad;
2326 q++;
2327 }
2328 break;
2329 }
2330 case 16:
2331 {
2332 unsigned short
2333 pixel;
2334
cristyc9672a92010-01-06 00:57:45 +00002335 if (quantum_info->format == FloatingPointQuantumFormat)
2336 {
cristybb503372010-05-27 20:51:26 +00002337 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002338 {
2339 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002340 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002341 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002342 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002343 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002344 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002345 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002346 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002347 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002348 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002349 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002350 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002351 p+=quantum_info->pad;
2352 q++;
2353 }
2354 break;
2355 }
cristybb503372010-05-27 20:51:26 +00002356 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002357 {
2358 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002359 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002360 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002361 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002362 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002363 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002364 p=PushShortPixel(endian,p,&pixel);
2365 indexes[x]=ScaleShortToQuantum(pixel);
2366 p+=quantum_info->pad;
2367 q++;
2368 }
2369 break;
2370 }
2371 case 32:
2372 {
cristy4cb162a2010-05-30 03:04:47 +00002373 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002374 pixel;
2375
2376 if (quantum_info->format == FloatingPointQuantumFormat)
2377 {
2378 float
2379 pixel;
2380
cristybb503372010-05-27 20:51:26 +00002381 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002382 {
2383 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002384 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002385 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002386 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002387 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002388 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002389 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002390 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002391 p+=quantum_info->pad;
2392 q++;
2393 }
2394 break;
2395 }
cristybb503372010-05-27 20:51:26 +00002396 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002397 {
2398 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002399 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002400 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002401 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002402 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002403 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002404 p=PushLongPixel(endian,p,&pixel);
2405 indexes[x]=ScaleLongToQuantum(pixel);
2406 p+=quantum_info->pad;
2407 q++;
2408 }
2409 break;
2410 }
2411 case 64:
2412 {
2413 if (quantum_info->format == FloatingPointQuantumFormat)
2414 {
2415 double
2416 pixel;
2417
cristybb503372010-05-27 20:51:26 +00002418 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002419 {
2420 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002421 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002422 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002423 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002424 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002425 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002426 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002427 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002428 p+=quantum_info->pad;
2429 q++;
2430 }
2431 break;
2432 }
2433 }
2434 default:
2435 {
2436 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002437 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002438 {
2439 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002440 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002441 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002442 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002443 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002444 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002445 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2446 indexes[x]=ScaleAnyToQuantum(pixel,range);
2447 q++;
2448 }
2449 break;
2450 }
2451 }
2452 break;
2453 }
2454 case CMYKAQuantum:
2455 case CMYKOQuantum:
2456 {
2457 if (image->colorspace != CMYKColorspace)
2458 {
2459 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2460 "ColorSeparatedImageRequired","`%s'",image->filename);
2461 return(extent);
2462 }
2463 switch (quantum_info->depth)
2464 {
2465 case 8:
2466 {
2467 unsigned char
2468 pixel;
2469
cristybb503372010-05-27 20:51:26 +00002470 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002471 {
2472 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002473 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002474 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002475 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002476 p=PushCharPixel(p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002477 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002478 p=PushCharPixel(p,&pixel);
2479 indexes[x]=ScaleCharToQuantum(pixel);
2480 p=PushCharPixel(p,&pixel);
2481 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2482 p+=quantum_info->pad;
2483 q++;
2484 }
2485 break;
2486 }
2487 case 16:
2488 {
2489 unsigned short
2490 pixel;
2491
cristyc9672a92010-01-06 00:57:45 +00002492 if (quantum_info->format == FloatingPointQuantumFormat)
2493 {
cristybb503372010-05-27 20:51:26 +00002494 for (x=0; x < (ssize_t) number_pixels; x++)
cristyc9672a92010-01-06 00:57:45 +00002495 {
2496 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002497 q->red=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002498 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002499 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002500 q->green=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002501 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002502 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002503 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002504 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002505 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002506 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
cristy2a4d01c2010-01-10 21:14:51 +00002507 HalfToSinglePrecision(pixel));
cristyc9672a92010-01-06 00:57:45 +00002508 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002509 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
cristy2a4d01c2010-01-10 21:14:51 +00002510 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
cristyc9672a92010-01-06 00:57:45 +00002511 p+=quantum_info->pad;
2512 q++;
2513 }
2514 break;
2515 }
cristybb503372010-05-27 20:51:26 +00002516 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002517 {
2518 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002519 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002520 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002521 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002522 p=PushShortPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002523 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002524 p=PushShortPixel(endian,p,&pixel);
2525 indexes[x]=ScaleShortToQuantum(pixel);
2526 p=PushShortPixel(endian,p,&pixel);
2527 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2528 p+=quantum_info->pad;
2529 q++;
2530 }
2531 break;
2532 }
2533 case 32:
2534 {
cristy4cb162a2010-05-30 03:04:47 +00002535 unsigned int
cristy3ed852e2009-09-05 21:47:34 +00002536 pixel;
2537
2538 if (quantum_info->format == FloatingPointQuantumFormat)
2539 {
2540 float
2541 pixel;
2542
cristybb503372010-05-27 20:51:26 +00002543 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002544 {
2545 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002546 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002547 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002548 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002549 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002550 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002551 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002552 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002553 p=PushFloatPixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002554 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002555 p+=quantum_info->pad;
2556 q++;
2557 }
2558 break;
2559 }
cristybb503372010-05-27 20:51:26 +00002560 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002561 {
2562 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002563 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002564 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002565 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002566 p=PushLongPixel(endian,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002567 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002568 p=PushLongPixel(endian,p,&pixel);
2569 indexes[x]=ScaleLongToQuantum(pixel);
2570 p=PushLongPixel(endian,p,&pixel);
2571 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2572 p+=quantum_info->pad;
2573 q++;
2574 }
2575 break;
2576 }
2577 case 64:
2578 {
2579 if (quantum_info->format == FloatingPointQuantumFormat)
2580 {
2581 double
2582 pixel;
2583
cristybb503372010-05-27 20:51:26 +00002584 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002585 {
2586 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002587 q->red=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002588 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002589 q->green=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002590 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002591 q->blue=ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002592 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002593 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
cristy3ed852e2009-09-05 21:47:34 +00002594 p=PushDoublePixel(&quantum_state,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002595 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
cristy3ed852e2009-09-05 21:47:34 +00002596 p=PushDoublePixel(&quantum_state,p,&pixel);
2597 p+=quantum_info->pad;
2598 q++;
2599 }
2600 break;
2601 }
2602 }
2603 default:
2604 {
2605 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002606 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002607 {
2608 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002609 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002610 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002611 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002612 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002613 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002614 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2615 indexes[x]=ScaleAnyToQuantum(pixel,range);
2616 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2617 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2618 q++;
2619 }
2620 break;
2621 }
2622 }
2623 break;
2624 }
2625 case CbYCrYQuantum:
2626 {
2627 switch (quantum_info->depth)
2628 {
2629 case 10:
2630 {
2631 Quantum
2632 cbcr[4];
2633
2634 pixel=0;
2635 if (quantum_info->pack == MagickFalse)
2636 {
cristybb503372010-05-27 20:51:26 +00002637 ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002638 n;
2639
cristybb503372010-05-27 20:51:26 +00002640 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00002641 i;
2642
cristybb503372010-05-27 20:51:26 +00002643 size_t
cristy3ed852e2009-09-05 21:47:34 +00002644 quantum;
2645
2646 n=0;
2647 quantum=0;
cristybb503372010-05-27 20:51:26 +00002648 for (x=0; x < (ssize_t) number_pixels; x+=2)
cristy3ed852e2009-09-05 21:47:34 +00002649 {
2650 for (i=0; i < 4; i++)
2651 {
2652 switch (n % 3)
2653 {
2654 case 0:
2655 {
2656 p=PushLongPixel(endian,p,&pixel);
cristybb503372010-05-27 20:51:26 +00002657 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002658 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2659 break;
2660 }
2661 case 1:
2662 {
cristybb503372010-05-27 20:51:26 +00002663 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002664 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2665 break;
2666 }
2667 case 2:
2668 {
cristybb503372010-05-27 20:51:26 +00002669 quantum=(size_t) (ScaleShortToQuantum(
cristy3ed852e2009-09-05 21:47:34 +00002670 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2671 break;
2672 }
2673 }
2674 cbcr[i]=(Quantum) (quantum);
2675 n++;
2676 }
2677 p+=quantum_info->pad;
2678 q->red=cbcr[1];
2679 q->green=cbcr[0];
2680 q->blue=cbcr[2];
2681 q++;
2682 q->red=cbcr[3];
2683 q->green=cbcr[0];
2684 q->blue=cbcr[2];
2685 q++;
2686 }
2687 break;
2688 }
2689 }
2690 default:
2691 {
2692 range=GetQuantumRange(image->depth);
cristybb503372010-05-27 20:51:26 +00002693 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002694 {
2695 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002696 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002697 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
cristyce70c172010-01-07 17:15:30 +00002698 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
cristy3ed852e2009-09-05 21:47:34 +00002699 q++;
2700 }
2701 break;
2702 }
2703 }
2704 break;
2705 }
2706 default:
2707 break;
2708 }
2709 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2710 {
2711 Quantum
2712 quantum;
2713
2714 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002715 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002716
2717 q=GetAuthenticPixelQueue(image);
2718 if (image_view != (CacheView *) NULL)
2719 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002720 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002721 {
2722 quantum=q->red;
2723 q->red=q->green;
2724 q->green=quantum;
2725 q++;
2726 }
2727 }
2728 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2729 {
2730 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002731 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002732
2733 q=GetAuthenticPixelQueue(image);
2734 if (image_view != (CacheView *) NULL)
2735 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002736 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002737 {
cristy46f08202010-01-10 04:04:21 +00002738 q->opacity=(Quantum) GetAlphaPixelComponent(q);
cristy3ed852e2009-09-05 21:47:34 +00002739 q++;
2740 }
2741 }
2742 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2743 {
2744 MagickRealType
2745 alpha;
2746
2747 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002748 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002749
2750 /*
2751 Disassociate alpha.
2752 */
2753 q=GetAuthenticPixelQueue(image);
2754 if (image_view != (CacheView *) NULL)
2755 q=GetCacheViewAuthenticPixelQueue(image_view);
cristybb503372010-05-27 20:51:26 +00002756 for (x=0; x < (ssize_t) number_pixels; x++)
cristy3ed852e2009-09-05 21:47:34 +00002757 {
2758 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2759 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
cristyce70c172010-01-07 17:15:30 +00002760 q->red=ClampToQuantum(alpha*q->red);
2761 q->green=ClampToQuantum(alpha*q->green);
2762 q->blue=ClampToQuantum(alpha*q->blue);
cristy3ed852e2009-09-05 21:47:34 +00002763 q++;
2764 }
2765 }
2766 return(extent);
2767}