blob: 9d705aa4b8ba24548226257459c47757ca533fff [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,
114 const unsigned long index,MagickBooleanType *range_exception)
115{
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(
195 QuantumState *quantum_state,const unsigned long depth,
196 const unsigned char *pixels,unsigned long *quantum)
197{
198 register long
199 i;
200
201 register unsigned long
202 quantum_bits;
203
204 *quantum=(QuantumAny) 0;
205 for (i=(long) depth; i > 0L; )
206 {
207 if (quantum_state->bits == 0UL)
208 {
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
211 }
212 quantum_bits=(unsigned long) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
215 i-=quantum_bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218 quantum_state->bits) &~ ((~0UL) << quantum_bits));
219 }
220 return(pixels);
221}
222
223static inline const unsigned char *PushQuantumLongPixel(
224 QuantumState *quantum_state,const unsigned long depth,
225 const unsigned char *pixels,unsigned long *quantum)
226{
227 register long
228 i;
229
230 register unsigned long
231 quantum_bits;
232
233 *quantum=0UL;
234 for (i=(long) depth; i > 0; )
235 {
236 if (quantum_state->bits == 0)
237 {
238 pixels=PushLongPixel(quantum_state->endian,pixels,
239 &quantum_state->pixel);
240 quantum_state->bits=32UL;
241 }
242 quantum_bits=(unsigned long) i;
243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
245 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246 quantum_state->mask[quantum_bits]) << (depth-i));
247 i-=quantum_bits;
248 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
260 long
261 bit;
262
263 MagickSizeType
264 number_pixels;
265
266 QuantumAny
267 range;
268
269 QuantumState
270 quantum_state;
271
272 register const unsigned char
273 *p;
274
275 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000276 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000277
278 register long
279 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
287 unsigned long
288 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;
300 number_pixels=GetImageExtent(image);
301 q=GetAuthenticPixelQueue(image);
302 indexes=GetAuthenticIndexQueue(image);
303 if (image_view != (CacheView *) NULL)
304 {
305 number_pixels=GetCacheViewExtent(image_view);
306 q=GetCacheViewAuthenticPixelQueue(image_view);
307 indexes=GetCacheViewAuthenticIndexQueue(image_view);
308 }
309 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
310 extent=GetQuantumExtent(image,quantum_info,quantum_type);
311 endian=quantum_state.endian;
312 switch (quantum_type)
313 {
314 case IndexQuantum:
315 {
316 MagickBooleanType
317 range_exception;
318
319 if (image->storage_class != PseudoClass)
320 {
321 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
322 "ColormappedImageRequired","`%s'",image->filename);
323 return(extent);
324 }
325 range_exception=MagickFalse;
326 switch (quantum_info->depth)
327 {
328 case 1:
329 {
330 register unsigned char
331 pixel;
332
333 for (x=0; x < ((long) number_pixels-7); x+=8)
334 {
335 for (bit=0; bit < 8; bit++)
336 {
337 if (quantum_info->min_is_white == MagickFalse)
338 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
339 0x00 : 0x01);
340 else
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
342 0x00 : 0x01);
343 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
344 *q=image->colormap[(long) indexes[x+bit]];
345 q++;
346 }
347 p++;
348 }
349 for (bit=0; bit < (long) (number_pixels % 8); bit++)
350 {
351 if (quantum_info->min_is_white == MagickFalse)
352 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
353 0x00 : 0x01);
354 else
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
356 0x00 : 0x01);
357 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
358 *q=image->colormap[(long) indexes[x+bit]];
359 q++;
360 }
361 break;
362 }
363 case 4:
364 {
365 register unsigned char
366 pixel;
367
368 for (x=0; x < ((long) number_pixels-1); x+=2)
369 {
370 pixel=(unsigned char) ((*p >> 4) & 0xf);
371 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
372 *q=image->colormap[(long) indexes[x]];
373 q++;
374 pixel=(unsigned char) ((*p) & 0xf);
375 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
376 *q=image->colormap[(long) indexes[x+1]];
377 p++;
378 q++;
379 }
380 for (bit=0; bit < (long) (number_pixels % 2); bit++)
381 {
382 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
383 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
384 *q=image->colormap[(long) indexes[x+bit]];
385 q++;
386 }
387 break;
388 }
389 case 8:
390 {
391 unsigned char
392 pixel;
393
394 for (x=0; x < (long) number_pixels; x++)
395 {
396 p=PushCharPixel(p,&pixel);
397 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
398 *q=image->colormap[(long) indexes[x]];
399 p+=quantum_info->pad;
400 q++;
401 }
402 break;
403 }
404 case 16:
405 {
406 unsigned short
407 pixel;
408
409 for (x=0; x < (long) number_pixels; x++)
410 {
411 p=PushShortPixel(endian,p,&pixel);
412 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
413 *q=image->colormap[(long) indexes[x]];
414 p+=quantum_info->pad;
415 q++;
416 }
417 break;
418 }
419 case 32:
420 {
421 unsigned long
422 pixel;
423
424 if (quantum_info->format == FloatingPointQuantumFormat)
425 {
426 float
427 pixel;
428
429 for (x=0; x < (long) number_pixels; x++)
430 {
431 p=PushFloatPixel(&quantum_state,p,&pixel);
432 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
433 &range_exception);
434 *q=image->colormap[(long) indexes[x]];
435 p+=quantum_info->pad;
436 q++;
437 }
438 break;
439 }
440 for (x=0; x < (long) number_pixels; x++)
441 {
442 p=PushLongPixel(endian,p,&pixel);
443 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
444 *q=image->colormap[(long) indexes[x]];
445 p+=quantum_info->pad;
446 q++;
447 }
448 break;
449 }
450 case 64:
451 {
452 if (quantum_info->format == FloatingPointQuantumFormat)
453 {
454 double
455 pixel;
456
457 for (x=0; x < (long) number_pixels; x++)
458 {
459 p=PushDoublePixel(&quantum_state,p,&pixel);
460 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
461 &range_exception);
462 *q=image->colormap[(long) indexes[x]];
463 p+=quantum_info->pad;
464 q++;
465 }
466 break;
467 }
468 }
469 default:
470 {
471 for (x=0; x < (long) number_pixels; x++)
472 {
473 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
474 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
475 *q=image->colormap[(long) indexes[x]];
476 p+=quantum_info->pad;
477 q++;
478 }
479 break;
480 }
481 }
482 if (range_exception != MagickFalse)
483 (void) ThrowMagickException(exception,GetMagickModule(),
484 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
485 break;
486 }
487 case IndexAlphaQuantum:
488 {
489 MagickBooleanType
490 range_exception;
491
492 if (image->storage_class != PseudoClass)
493 {
494 (void) ThrowMagickException(exception,GetMagickModule(),
495 ImageError,"ColormappedImageRequired","`%s'",image->filename);
496 return(extent);
497 }
498 range_exception=MagickFalse;
499 switch (quantum_info->depth)
500 {
501 case 1:
502 {
503 register unsigned char
504 pixel;
505
506 for (x=0; x < ((long) number_pixels-3); x+=4)
507 {
508 for (bit=0; bit < 8; bit+=2)
509 {
510 if (quantum_info->min_is_white == MagickFalse)
511 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
512 0x00 : 0x01);
513 else
514 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
515 0x00 : 0x01);
516 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
517 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
518 q->green=q->red;
519 q->blue=q->red;
520 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
521 == 0 ? TransparentOpacity : OpaqueOpacity);
522 q++;
523 }
524 }
525 for (bit=0; bit < (long) (number_pixels % 4); 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 break;
542 }
543 case 4:
544 {
545 register unsigned char
546 pixel;
547
548 range=GetQuantumRange(image->depth);
549 for (x=0; x < (long) number_pixels; x++)
550 {
551 pixel=(unsigned char) ((*p >> 4) & 0xf);
552 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
553 *q=image->colormap[(long) indexes[x]];
554 pixel=(unsigned char) ((*p) & 0xf);
555 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
556 p++;
557 q++;
558 }
559 break;
560 }
561 case 8:
562 {
563 unsigned char
564 pixel;
565
566 for (x=0; x < (long) number_pixels; x++)
567 {
568 p=PushCharPixel(p,&pixel);
569 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
570 *q=image->colormap[(long) indexes[x]];
571 p=PushCharPixel(p,&pixel);
572 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
573 p+=quantum_info->pad;
574 q++;
575 }
576 break;
577 }
578 case 16:
579 {
580 unsigned short
581 pixel;
582
583 for (x=0; x < (long) number_pixels; x++)
584 {
585 p=PushShortPixel(endian,p,&pixel);
586 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
587 *q=image->colormap[(long) indexes[x]];
588 p=PushShortPixel(endian,p,&pixel);
589 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
590 p+=quantum_info->pad;
591 q++;
592 }
593 break;
594 }
595 case 32:
596 {
597 unsigned long
598 pixel;
599
600 if (quantum_info->format == FloatingPointQuantumFormat)
601 {
602 float
603 pixel;
604
605 for (x=0; x < (long) number_pixels; x++)
606 {
607 p=PushFloatPixel(&quantum_state,p,&pixel);
608 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
609 &range_exception);
610 *q=image->colormap[(long) indexes[x]];
611 p=PushFloatPixel(&quantum_state,p,&pixel);
612 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
613 p+=quantum_info->pad;
614 q++;
615 }
616 break;
617 }
618 for (x=0; x < (long) number_pixels; x++)
619 {
620 p=PushLongPixel(endian,p,&pixel);
621 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
622 *q=image->colormap[(long) indexes[x]];
623 p=PushLongPixel(endian,p,&pixel);
624 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
625 p+=quantum_info->pad;
626 q++;
627 }
628 break;
629 }
630 case 64:
631 {
632 if (quantum_info->format == FloatingPointQuantumFormat)
633 {
634 double
635 pixel;
636
637 for (x=0; x < (long) number_pixels; x++)
638 {
639 p=PushDoublePixel(&quantum_state,p,&pixel);
640 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
641 &range_exception);
642 *q=image->colormap[(long) indexes[x]];
643 p=PushDoublePixel(&quantum_state,p,&pixel);
644 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
645 p+=quantum_info->pad;
646 q++;
647 }
648 break;
649 }
650 }
651 default:
652 {
653 range=GetQuantumRange(image->depth);
654 for (x=0; x < (long) number_pixels; x++)
655 {
656 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
657 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
658 *q=image->colormap[(long) indexes[x]];
659 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
660 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
661 p+=quantum_info->pad;
662 q++;
663 }
664 break;
665 }
666 }
667 if (range_exception != MagickFalse)
668 (void) ThrowMagickException(exception,GetMagickModule(),
669 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
670 break;
671 }
672 case GrayQuantum:
673 {
674 switch (quantum_info->depth)
675 {
676 case 1:
677 {
678 register Quantum
679 black,
680 white;
681
682 black=0;
683 white=(Quantum) QuantumRange;
684 if (quantum_info->min_is_white != MagickFalse)
685 {
686 black=(Quantum) QuantumRange;
687 white=0;
688 }
689 for (x=0; x < ((long) number_pixels-7); x+=8)
690 {
691 for (bit=0; bit < 8; bit++)
692 {
693 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
694 q->green=q->red;
695 q->blue=q->red;
696 q++;
697 }
698 p++;
699 }
700 for (bit=0; bit < (long) (number_pixels % 8); bit++)
701 {
702 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
703 q->green=q->red;
704 q->blue=q->red;
705 q++;
706 }
707 if (bit != 0)
708 p++;
709 break;
710 }
711 case 4:
712 {
713 register unsigned char
714 pixel;
715
716 range=GetQuantumRange(image->depth);
717 for (x=0; x < ((long) number_pixels-1); x+=2)
718 {
719 pixel=(unsigned char) ((*p >> 4) & 0xf);
720 q->red=ScaleAnyToQuantum(pixel,range);
721 q->green=q->red;
722 q->blue=q->red;
723 q++;
724 pixel=(unsigned char) ((*p) & 0xf);
725 q->red=ScaleAnyToQuantum(pixel,range);
726 q->green=q->red;
727 q->blue=q->red;
728 p++;
729 q++;
730 }
731 for (bit=0; bit < (long) (number_pixels % 2); bit++)
732 {
733 pixel=(unsigned char) (*p++ >> 4);
734 q->red=ScaleAnyToQuantum(pixel,range);
735 q->green=q->red;
736 q->blue=q->red;
737 q++;
738 }
739 break;
740 }
741 case 8:
742 {
743 unsigned char
744 pixel;
745
746 if (quantum_info->min_is_white != MagickFalse)
747 {
748 for (x=0; x < (long) number_pixels; x++)
749 {
750 p=PushCharPixel(p,&pixel);
751 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
752 q->green=q->red;
753 q->blue=q->red;
754 q->opacity=OpaqueOpacity;
755 p+=quantum_info->pad;
756 q++;
757 }
758 break;
759 }
760 for (x=0; x < (long) number_pixels; x++)
761 {
762 p=PushCharPixel(p,&pixel);
763 q->red=ScaleCharToQuantum(pixel);
764 q->green=q->red;
765 q->blue=q->red;
766 q->opacity=OpaqueOpacity;
767 p+=quantum_info->pad;
768 q++;
769 }
770 break;
771 }
772 case 10:
773 {
774 range=GetQuantumRange(image->depth);
775 if (quantum_info->pack == MagickFalse)
776 {
777 if (image->endian != LSBEndian)
778 {
779 for (x=0; x < (long) number_pixels/3; x++)
780 {
781 p=PushLongPixel(endian,p,&pixel);
782 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
783 q->green=q->red;
784 q->blue=q->red;
785 q++;
786 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
787 q->green=q->red;
788 q->blue=q->red;
789 q++;
790 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
791 q->green=q->red;
792 q->blue=q->red;
793 p+=quantum_info->pad;
794 q++;
795 }
796 break;
797 }
798 for (x=0; x < (long) number_pixels/3; x++)
799 {
800 p=PushLongPixel(endian,p,&pixel);
801 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
802 q->green=q->red;
803 q->blue=q->red;
804 q++;
805 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
806 q->green=q->red;
807 q->blue=q->red;
808 q++;
809 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
810 q->green=q->red;
811 q->blue=q->red;
812 p+=quantum_info->pad;
813 q++;
814 }
815 break;
816 }
817 for (x=0; x < (long) number_pixels; x++)
818 {
819 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
820 q->red=ScaleAnyToQuantum(pixel,range);
821 q->green=q->red;
822 q->blue=q->red;
823 p+=quantum_info->pad;
824 q++;
825 }
826 break;
827 }
828 case 12:
829 {
830 range=GetQuantumRange(image->depth);
831 if (quantum_info->pack == MagickFalse)
832 {
833 unsigned short
834 pixel;
835
836 for (x=0; x < (long) (number_pixels-1); x+=2)
837 {
838 p=PushShortPixel(endian,p,&pixel);
839 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
840 q->green=q->red;
841 q->blue=q->red;
842 q++;
843 p=PushShortPixel(endian,p,&pixel);
844 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
845 q->green=q->red;
846 q->blue=q->red;
847 p+=quantum_info->pad;
848 q++;
849 }
850 for (bit=0; bit < (long) (number_pixels % 2); bit++)
851 {
852 p=PushShortPixel(endian,p,&pixel);
853 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
854 q->green=q->red;
855 q->blue=q->red;
856 p+=quantum_info->pad;
857 q++;
858 }
859 if (bit != 0)
860 p++;
861 break;
862 }
863 for (x=0; x < (long) number_pixels; x++)
864 {
865 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
866 q->red=ScaleAnyToQuantum(pixel,range);
867 q->green=q->red;
868 q->blue=q->red;
869 p+=quantum_info->pad;
870 q++;
871 }
872 break;
873 }
874 case 16:
875 {
876 unsigned short
877 pixel;
878
879 if (quantum_info->min_is_white != MagickFalse)
880 {
881 for (x=0; x < (long) number_pixels; x++)
882 {
883 p=PushShortPixel(endian,p,&pixel);
884 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
885 q->green=q->red;
886 q->blue=q->red;
887 p+=quantum_info->pad;
888 q++;
889 }
890 break;
891 }
892 for (x=0; x < (long) number_pixels; x++)
893 {
894 p=PushShortPixel(endian,p,&pixel);
895 q->red=ScaleShortToQuantum(pixel);
896 q->green=q->red;
897 q->blue=q->red;
898 p+=quantum_info->pad;
899 q++;
900 }
901 break;
902 }
903 case 32:
904 {
905 unsigned long
906 pixel;
907
908 if (quantum_info->format == FloatingPointQuantumFormat)
909 {
910 float
911 pixel;
912
913 for (x=0; x < (long) number_pixels; x++)
914 {
915 p=PushFloatPixel(&quantum_state,p,&pixel);
916 q->red=RoundToQuantum(pixel);
917 q->green=q->red;
918 q->blue=q->red;
919 p+=quantum_info->pad;
920 q++;
921 }
922 break;
923 }
924 for (x=0; x < (long) number_pixels; x++)
925 {
926 p=PushLongPixel(endian,p,&pixel);
927 q->red=ScaleLongToQuantum(pixel);
928 q->green=q->red;
929 q->blue=q->red;
930 p+=quantum_info->pad;
931 q++;
932 }
933 break;
934 }
935 case 64:
936 {
937 if (quantum_info->format == FloatingPointQuantumFormat)
938 {
939 double
940 pixel;
941
942 for (x=0; x < (long) number_pixels; x++)
943 {
944 p=PushDoublePixel(&quantum_state,p,&pixel);
945 q->red=RoundToQuantum(pixel);
946 q->green=q->red;
947 q->blue=q->red;
948 p+=quantum_info->pad;
949 q++;
950 }
951 break;
952 }
953 }
954 default:
955 {
956 range=GetQuantumRange(image->depth);
957 for (x=0; x < (long) number_pixels; x++)
958 {
959 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
960 q->red=ScaleAnyToQuantum(pixel,range);
961 q->green=q->red;
962 q->blue=q->red;
963 p+=quantum_info->pad;
964 q++;
965 }
966 break;
967 }
968 }
969 break;
970 }
971 case GrayAlphaQuantum:
972 {
973 switch (quantum_info->depth)
974 {
975 case 1:
976 {
977 register unsigned char
978 pixel;
979
980 for (x=0; x < ((long) number_pixels-3); x+=4)
981 {
982 for (bit=0; bit < 8; bit+=2)
983 {
984 pixel=(unsigned char)
985 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
986 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
987 q->green=q->red;
988 q->blue=q->red;
989 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
990 == 0 ? TransparentOpacity : OpaqueOpacity);
991 q++;
992 }
993 p++;
994 }
995 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
996 {
997 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
998 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
999 q->green=q->red;
1000 q->blue=q->red;
1001 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1002 ? TransparentOpacity : OpaqueOpacity);
1003 q++;
1004 }
1005 if (bit != 0)
1006 p++;
1007 break;
1008 }
1009 case 4:
1010 {
1011 register unsigned char
1012 pixel;
1013
1014 range=GetQuantumRange(image->depth);
1015 for (x=0; x < (long) number_pixels; x++)
1016 {
1017 pixel=(unsigned char) ((*p >> 4) & 0xf);
1018 q->red=ScaleAnyToQuantum(pixel,range);
1019 q->green=q->red;
1020 q->blue=q->red;
1021 pixel=(unsigned char) ((*p) & 0xf);
1022 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1023 p++;
1024 q++;
1025 }
1026 break;
1027 }
1028 case 8:
1029 {
1030 unsigned char
1031 pixel;
1032
1033 for (x=0; x < (long) number_pixels; x++)
1034 {
1035 p=PushCharPixel(p,&pixel);
1036 q->red=ScaleCharToQuantum(pixel);
1037 q->green=q->red;
1038 q->blue=q->red;
1039 p=PushCharPixel(p,&pixel);
1040 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1041 p+=quantum_info->pad;
1042 q++;
1043 }
1044 break;
1045 }
1046 case 10:
1047 {
1048 range=GetQuantumRange(image->depth);
1049 for (x=0; x < (long) number_pixels; x++)
1050 {
1051 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1052 q->red=ScaleAnyToQuantum(pixel,range);
1053 q->green=q->red;
1054 q->blue=q->red;
1055 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1056 q->opacity=ScaleAnyToQuantum(pixel,range);
1057 p+=quantum_info->pad;
1058 q++;
1059 }
1060 break;
1061 }
1062 case 12:
1063 {
1064 range=GetQuantumRange(image->depth);
1065 for (x=0; x < (long) number_pixels; x++)
1066 {
1067 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1068 q->red=ScaleAnyToQuantum(pixel,range);
1069 q->green=q->red;
1070 q->blue=q->red;
1071 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1072 q->opacity=ScaleAnyToQuantum(pixel,range);
1073 p+=quantum_info->pad;
1074 q++;
1075 }
1076 break;
1077 }
1078 case 16:
1079 {
1080 unsigned short
1081 pixel;
1082
1083 for (x=0; x < (long) number_pixels; x++)
1084 {
1085 p=PushShortPixel(endian,p,&pixel);
1086 q->red=ScaleShortToQuantum(pixel);
1087 q->green=q->red;
1088 q->blue=q->red;
1089 p=PushShortPixel(endian,p,&pixel);
1090 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1091 p+=quantum_info->pad;
1092 q++;
1093 }
1094 break;
1095 }
1096 case 32:
1097 {
1098 unsigned long
1099 pixel;
1100
1101 if (quantum_info->format == FloatingPointQuantumFormat)
1102 {
1103 float
1104 pixel;
1105
1106 for (x=0; x < (long) number_pixels; x++)
1107 {
1108 p=PushFloatPixel(&quantum_state,p,&pixel);
1109 q->red=RoundToQuantum(pixel);
1110 q->green=q->red;
1111 q->blue=q->red;
1112 p=PushFloatPixel(&quantum_state,p,&pixel);
1113 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1114 p+=quantum_info->pad;
1115 q++;
1116 }
1117 break;
1118 }
1119 for (x=0; x < (long) number_pixels; x++)
1120 {
1121 p=PushLongPixel(endian,p,&pixel);
1122 q->red=ScaleLongToQuantum(pixel);
1123 q->green=q->red;
1124 q->blue=q->red;
1125 p=PushLongPixel(endian,p,&pixel);
1126 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1127 p+=quantum_info->pad;
1128 q++;
1129 }
1130 break;
1131 }
1132 case 64:
1133 {
1134 if (quantum_info->format == FloatingPointQuantumFormat)
1135 {
1136 double
1137 pixel;
1138
1139 for (x=0; x < (long) number_pixels; x++)
1140 {
1141 p=PushDoublePixel(&quantum_state,p,&pixel);
1142 q->red=RoundToQuantum(pixel);
1143 q->green=q->red;
1144 q->blue=q->red;
1145 p=PushDoublePixel(&quantum_state,p,&pixel);
1146 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1147 p+=quantum_info->pad;
1148 q++;
1149 }
1150 break;
1151 }
1152 }
1153 default:
1154 {
1155 range=GetQuantumRange(image->depth);
1156 for (x=0; x < (long) number_pixels; x++)
1157 {
1158 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1159 q->red=ScaleAnyToQuantum(pixel,range);
1160 q->green=q->red;
1161 q->blue=q->red;
1162 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1163 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1164 p+=quantum_info->pad;
1165 q++;
1166 }
1167 break;
1168 }
1169 }
1170 break;
1171 }
1172 case RedQuantum:
1173 case CyanQuantum:
1174 {
1175 switch (quantum_info->depth)
1176 {
1177 case 8:
1178 {
1179 unsigned char
1180 pixel;
1181
1182 for (x=0; x < (long) number_pixels; x++)
1183 {
1184 p=PushCharPixel(p,&pixel);
1185 q->red=ScaleCharToQuantum(pixel);
1186 p+=quantum_info->pad;
1187 q++;
1188 }
1189 break;
1190 }
1191 case 16:
1192 {
1193 unsigned short
1194 pixel;
1195
1196 for (x=0; x < (long) number_pixels; x++)
1197 {
1198 p=PushShortPixel(endian,p,&pixel);
1199 q->red=ScaleShortToQuantum(pixel);
1200 p+=quantum_info->pad;
1201 q++;
1202 }
1203 break;
1204 }
1205 case 32:
1206 {
1207 unsigned long
1208 pixel;
1209
1210 if (quantum_info->format == FloatingPointQuantumFormat)
1211 {
1212 float
1213 pixel;
1214
1215 for (x=0; x < (long) number_pixels; x++)
1216 {
1217 p=PushFloatPixel(&quantum_state,p,&pixel);
1218 q->red=RoundToQuantum(pixel);
1219 p+=quantum_info->pad;
1220 q++;
1221 }
1222 break;
1223 }
1224 for (x=0; x < (long) number_pixels; x++)
1225 {
1226 p=PushLongPixel(endian,p,&pixel);
1227 q->red=ScaleLongToQuantum(pixel);
1228 p+=quantum_info->pad;
1229 q++;
1230 }
1231 break;
1232 }
1233 case 64:
1234 {
1235 if (quantum_info->format == FloatingPointQuantumFormat)
1236 {
1237 double
1238 pixel;
1239
1240 for (x=0; x < (long) number_pixels; x++)
1241 {
1242 p=PushDoublePixel(&quantum_state,p,&pixel);
1243 q->red=RoundToQuantum(pixel);
1244 p+=quantum_info->pad;
1245 q++;
1246 }
1247 break;
1248 }
1249 }
1250 default:
1251 {
1252 range=GetQuantumRange(image->depth);
1253 for (x=0; x < (long) number_pixels; x++)
1254 {
1255 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1256 q->red=ScaleAnyToQuantum(pixel,range);
1257 p+=quantum_info->pad;
1258 q++;
1259 }
1260 break;
1261 }
1262 }
1263 break;
1264 }
1265 case GreenQuantum:
1266 case MagentaQuantum:
1267 {
1268 switch (quantum_info->depth)
1269 {
1270 case 8:
1271 {
1272 unsigned char
1273 pixel;
1274
1275 for (x=0; x < (long) number_pixels; x++)
1276 {
1277 p=PushCharPixel(p,&pixel);
1278 q->green=ScaleCharToQuantum(pixel);
1279 p+=quantum_info->pad;
1280 q++;
1281 }
1282 break;
1283 }
1284 case 16:
1285 {
1286 unsigned short
1287 pixel;
1288
1289 for (x=0; x < (long) number_pixels; x++)
1290 {
1291 p=PushShortPixel(endian,p,&pixel);
1292 q->green=ScaleShortToQuantum(pixel);
1293 p+=quantum_info->pad;
1294 q++;
1295 }
1296 break;
1297 }
1298 case 32:
1299 {
1300 unsigned long
1301 pixel;
1302
1303 if (quantum_info->format == FloatingPointQuantumFormat)
1304 {
1305 float
1306 pixel;
1307
1308 for (x=0; x < (long) number_pixels; x++)
1309 {
1310 p=PushFloatPixel(&quantum_state,p,&pixel);
1311 q->green=RoundToQuantum(pixel);
1312 p+=quantum_info->pad;
1313 q++;
1314 }
1315 break;
1316 }
1317 for (x=0; x < (long) number_pixels; x++)
1318 {
1319 p=PushLongPixel(endian,p,&pixel);
1320 q->green=ScaleLongToQuantum(pixel);
1321 p+=quantum_info->pad;
1322 q++;
1323 }
1324 break;
1325 }
1326 case 64:
1327 {
1328 if (quantum_info->format == FloatingPointQuantumFormat)
1329 {
1330 double
1331 pixel;
1332
1333 for (x=0; x < (long) number_pixels; x++)
1334 {
1335 p=PushDoublePixel(&quantum_state,p,&pixel);
1336 q->green=RoundToQuantum(pixel);
1337 p+=quantum_info->pad;
1338 q++;
1339 }
1340 break;
1341 }
1342 }
1343 default:
1344 {
1345 range=GetQuantumRange(image->depth);
1346 for (x=0; x < (long) number_pixels; x++)
1347 {
1348 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1349 q->green=ScaleAnyToQuantum(pixel,range);
1350 p+=quantum_info->pad;
1351 q++;
1352 }
1353 break;
1354 }
1355 }
1356 break;
1357 }
1358 case BlueQuantum:
1359 case YellowQuantum:
1360 {
1361 switch (quantum_info->depth)
1362 {
1363 case 8:
1364 {
1365 unsigned char
1366 pixel;
1367
1368 for (x=0; x < (long) number_pixels; x++)
1369 {
1370 p=PushCharPixel(p,&pixel);
1371 q->blue=ScaleCharToQuantum(pixel);
1372 p+=quantum_info->pad;
1373 q++;
1374 }
1375 break;
1376 }
1377 case 16:
1378 {
1379 unsigned short
1380 pixel;
1381
1382 for (x=0; x < (long) number_pixels; x++)
1383 {
1384 p=PushShortPixel(endian,p,&pixel);
1385 q->blue=ScaleShortToQuantum(pixel);
1386 p+=quantum_info->pad;
1387 q++;
1388 }
1389 break;
1390 }
1391 case 32:
1392 {
1393 unsigned long
1394 pixel;
1395
1396 if (quantum_info->format == FloatingPointQuantumFormat)
1397 {
1398 float
1399 pixel;
1400
1401 for (x=0; x < (long) number_pixels; x++)
1402 {
1403 p=PushFloatPixel(&quantum_state,p,&pixel);
1404 q->blue=RoundToQuantum(pixel);
1405 p+=quantum_info->pad;
1406 q++;
1407 }
1408 break;
1409 }
1410 for (x=0; x < (long) number_pixels; x++)
1411 {
1412 p=PushLongPixel(endian,p,&pixel);
1413 q->blue=ScaleLongToQuantum(pixel);
1414 p+=quantum_info->pad;
1415 q++;
1416 }
1417 break;
1418 }
1419 case 64:
1420 {
1421 if (quantum_info->format == FloatingPointQuantumFormat)
1422 {
1423 double
1424 pixel;
1425
1426 for (x=0; x < (long) number_pixels; x++)
1427 {
1428 p=PushDoublePixel(&quantum_state,p,&pixel);
1429 q->blue=RoundToQuantum(pixel);
1430 p+=quantum_info->pad;
1431 q++;
1432 }
1433 break;
1434 }
1435 }
1436 default:
1437 {
1438 range=GetQuantumRange(image->depth);
1439 for (x=0; x < (long) number_pixels; x++)
1440 {
1441 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1442 q->blue=ScaleAnyToQuantum(pixel,range);
1443 p+=quantum_info->pad;
1444 q++;
1445 }
1446 break;
1447 }
1448 }
1449 break;
1450 }
1451 case AlphaQuantum:
1452 {
1453 switch (quantum_info->depth)
1454 {
1455 case 8:
1456 {
1457 unsigned char
1458 pixel;
1459
1460 for (x=0; x < (long) number_pixels; x++)
1461 {
1462 p=PushCharPixel(p,&pixel);
1463 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1464 p+=quantum_info->pad;
1465 q++;
1466 }
1467 break;
1468 }
1469 case 16:
1470 {
1471 unsigned short
1472 pixel;
1473
1474 for (x=0; x < (long) number_pixels; x++)
1475 {
1476 p=PushShortPixel(endian,p,&pixel);
1477 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1478 p+=quantum_info->pad;
1479 q++;
1480 }
1481 break;
1482 }
1483 case 32:
1484 {
1485 unsigned long
1486 pixel;
1487
1488 if (quantum_info->format == FloatingPointQuantumFormat)
1489 {
1490 float
1491 pixel;
1492
1493 for (x=0; x < (long) number_pixels; x++)
1494 {
1495 p=PushFloatPixel(&quantum_state,p,&pixel);
1496 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1497 p+=quantum_info->pad;
1498 q++;
1499 }
1500 break;
1501 }
1502 for (x=0; x < (long) number_pixels; x++)
1503 {
1504 p=PushLongPixel(endian,p,&pixel);
1505 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1506 p+=quantum_info->pad;
1507 q++;
1508 }
1509 break;
1510 }
1511 case 64:
1512 {
1513 if (quantum_info->format == FloatingPointQuantumFormat)
1514 {
1515 double
1516 pixel;
1517
1518 for (x=0; x < (long) number_pixels; x++)
1519 {
1520 p=PushDoublePixel(&quantum_state,p,&pixel);
1521 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1522 p+=quantum_info->pad;
1523 q++;
1524 }
1525 break;
1526 }
1527 }
1528 default:
1529 {
1530 range=GetQuantumRange(image->depth);
1531 for (x=0; x < (long) number_pixels; x++)
1532 {
1533 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1534 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1535 p+=quantum_info->pad;
1536 q++;
1537 }
1538 break;
1539 }
1540 }
1541 break;
1542 }
1543 case BlackQuantum:
1544 {
1545 if (image->colorspace != CMYKColorspace)
1546 {
1547 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1548 "ColorSeparatedImageRequired","`%s'",image->filename);
1549 return(extent);
1550 }
1551 switch (quantum_info->depth)
1552 {
1553 case 8:
1554 {
1555 unsigned char
1556 pixel;
1557
1558 for (x=0; x < (long) number_pixels; x++)
1559 {
1560 p=PushCharPixel(p,&pixel);
1561 indexes[x]=ScaleCharToQuantum(pixel);
1562 p+=quantum_info->pad;
1563 }
1564 break;
1565 }
1566 case 16:
1567 {
1568 unsigned short
1569 pixel;
1570
1571 for (x=0; x < (long) number_pixels; x++)
1572 {
1573 p=PushShortPixel(endian,p,&pixel);
1574 indexes[x]=ScaleShortToQuantum(pixel);
1575 p+=quantum_info->pad;
1576 }
1577 break;
1578 }
1579 case 32:
1580 {
1581 unsigned long
1582 pixel;
1583
1584 if (quantum_info->format == FloatingPointQuantumFormat)
1585 {
1586 float
1587 pixel;
1588
1589 for (x=0; x < (long) number_pixels; x++)
1590 {
1591 p=PushFloatPixel(&quantum_state,p,&pixel);
1592 indexes[x]=RoundToQuantum(pixel);
1593 p+=quantum_info->pad;
1594 q++;
1595 }
1596 break;
1597 }
1598 for (x=0; x < (long) number_pixels; x++)
1599 {
1600 p=PushLongPixel(endian,p,&pixel);
1601 indexes[x]=ScaleLongToQuantum(pixel);
1602 p+=quantum_info->pad;
1603 q++;
1604 }
1605 break;
1606 }
1607 case 64:
1608 {
1609 if (quantum_info->format == FloatingPointQuantumFormat)
1610 {
1611 double
1612 pixel;
1613
1614 for (x=0; x < (long) number_pixels; x++)
1615 {
1616 p=PushDoublePixel(&quantum_state,p,&pixel);
1617 indexes[x]=RoundToQuantum(pixel);
1618 p+=quantum_info->pad;
1619 q++;
1620 }
1621 break;
1622 }
1623 }
1624 default:
1625 {
1626 range=GetQuantumRange(image->depth);
1627 for (x=0; x < (long) number_pixels; x++)
1628 {
1629 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1630 indexes[x]=ScaleAnyToQuantum(pixel,range);
1631 p+=quantum_info->pad;
1632 q++;
1633 }
1634 break;
1635 }
1636 }
1637 break;
1638 }
1639 case RGBQuantum:
1640 case CbYCrQuantum:
1641 {
1642 switch (quantum_info->depth)
1643 {
1644 case 8:
1645 {
1646 unsigned char
1647 pixel;
1648
1649 for (x=0; x < (long) number_pixels; x++)
1650 {
1651 p=PushCharPixel(p,&pixel);
1652 q->red=ScaleCharToQuantum(pixel);
1653 p=PushCharPixel(p,&pixel);
1654 q->green=ScaleCharToQuantum(pixel);
1655 p=PushCharPixel(p,&pixel);
1656 q->blue=ScaleCharToQuantum(pixel);
1657 q->opacity=OpaqueOpacity;
1658 p+=quantum_info->pad;
1659 q++;
1660 }
1661 break;
1662 }
1663 case 10:
1664 {
1665 range=GetQuantumRange(image->depth);
1666 if (quantum_info->pack == MagickFalse)
1667 {
1668 for (x=0; x < (long) number_pixels; x++)
1669 {
1670 p=PushLongPixel(endian,p,&pixel);
1671 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1672 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1673 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1674 p+=quantum_info->pad;
1675 q++;
1676 }
1677 break;
1678 }
1679 if (quantum_info->quantum == 32UL)
1680 {
1681 for (x=0; x < (long) number_pixels; x++)
1682 {
1683 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1684 q->red=ScaleAnyToQuantum(pixel,range);
1685 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1686 q->green=ScaleAnyToQuantum(pixel,range);
1687 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1688 q->blue=ScaleAnyToQuantum(pixel,range);
1689 q++;
1690 }
1691 break;
1692 }
1693 for (x=0; x < (long) number_pixels; x++)
1694 {
1695 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1696 q->red=ScaleAnyToQuantum(pixel,range);
1697 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1698 q->green=ScaleAnyToQuantum(pixel,range);
1699 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1700 q->blue=ScaleAnyToQuantum(pixel,range);
1701 q++;
1702 }
1703 break;
1704 }
1705 case 12:
1706 {
1707 range=GetQuantumRange(image->depth);
1708 if (quantum_info->pack == MagickFalse)
1709 {
1710 unsigned short
1711 pixel;
1712
1713 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1714 {
1715 p=PushShortPixel(endian,p,&pixel);
1716 switch (x % 3)
1717 {
1718 default:
1719 case 0:
1720 {
1721 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1722 break;
1723 }
1724 case 1:
1725 {
1726 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1727 break;
1728 }
1729 case 2:
1730 {
1731 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1732 q++;
1733 break;
1734 }
1735 }
1736 p=PushShortPixel(endian,p,&pixel);
1737 switch ((x+1) % 3)
1738 {
1739 default:
1740 case 0:
1741 {
1742 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1743 break;
1744 }
1745 case 1:
1746 {
1747 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1748 break;
1749 }
1750 case 2:
1751 {
1752 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1753 q++;
1754 break;
1755 }
1756 }
1757 p+=quantum_info->pad;
1758 }
1759 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1760 {
1761 p=PushShortPixel(endian,p,&pixel);
1762 switch ((x+bit) % 3)
1763 {
1764 default:
1765 case 0:
1766 {
1767 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1768 break;
1769 }
1770 case 1:
1771 {
1772 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1773 break;
1774 }
1775 case 2:
1776 {
1777 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1778 q++;
1779 break;
1780 }
1781 }
1782 p+=quantum_info->pad;
1783 }
1784 if (bit != 0)
1785 p++;
1786 break;
1787 }
1788 if (quantum_info->quantum == 32UL)
1789 {
1790 for (x=0; x < (long) number_pixels; x++)
1791 {
1792 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1793 q->red=ScaleAnyToQuantum(pixel,range);
1794 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1795 q->green=ScaleAnyToQuantum(pixel,range);
1796 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1797 q->blue=ScaleAnyToQuantum(pixel,range);
1798 q++;
1799 }
1800 break;
1801 }
1802 for (x=0; x < (long) number_pixels; x++)
1803 {
1804 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1805 q->red=ScaleAnyToQuantum(pixel,range);
1806 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1807 q->green=ScaleAnyToQuantum(pixel,range);
1808 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1809 q->blue=ScaleAnyToQuantum(pixel,range);
1810 q++;
1811 }
1812 break;
1813 }
1814 case 16:
1815 {
1816 unsigned short
1817 pixel;
1818
1819 for (x=0; x < (long) number_pixels; x++)
1820 {
1821 p=PushShortPixel(endian,p,&pixel);
1822 q->red=ScaleShortToQuantum(pixel);
1823 p=PushShortPixel(endian,p,&pixel);
1824 q->green=ScaleShortToQuantum(pixel);
1825 p=PushShortPixel(endian,p,&pixel);
1826 q->blue=ScaleShortToQuantum(pixel);
1827 p+=quantum_info->pad;
1828 q++;
1829 }
1830 break;
1831 }
1832 case 32:
1833 {
1834 unsigned long
1835 pixel;
1836
1837 if (quantum_info->format == FloatingPointQuantumFormat)
1838 {
1839 float
1840 pixel;
1841
1842 for (x=0; x < (long) number_pixels; x++)
1843 {
1844 p=PushFloatPixel(&quantum_state,p,&pixel);
1845 q->red=RoundToQuantum(pixel);
1846 p=PushFloatPixel(&quantum_state,p,&pixel);
1847 q->green=RoundToQuantum(pixel);
1848 p=PushFloatPixel(&quantum_state,p,&pixel);
1849 q->blue=RoundToQuantum(pixel);
1850 p+=quantum_info->pad;
1851 q++;
1852 }
1853 break;
1854 }
1855 for (x=0; x < (long) number_pixels; x++)
1856 {
1857 p=PushLongPixel(endian,p,&pixel);
1858 q->red=ScaleLongToQuantum(pixel);
1859 p=PushLongPixel(endian,p,&pixel);
1860 q->green=ScaleLongToQuantum(pixel);
1861 p=PushLongPixel(endian,p,&pixel);
1862 q->blue=ScaleLongToQuantum(pixel);
1863 p+=quantum_info->pad;
1864 q++;
1865 }
1866 break;
1867 }
1868 case 64:
1869 {
1870 if (quantum_info->format == FloatingPointQuantumFormat)
1871 {
1872 double
1873 pixel;
1874
1875 for (x=0; x < (long) number_pixels; x++)
1876 {
1877 p=PushDoublePixel(&quantum_state,p,&pixel);
1878 q->red=RoundToQuantum(pixel);
1879 p=PushDoublePixel(&quantum_state,p,&pixel);
1880 q->green=RoundToQuantum(pixel);
1881 p=PushDoublePixel(&quantum_state,p,&pixel);
1882 q->blue=RoundToQuantum(pixel);
1883 p+=quantum_info->pad;
1884 q++;
1885 }
1886 break;
1887 }
1888 }
1889 default:
1890 {
1891 range=GetQuantumRange(image->depth);
1892 for (x=0; x < (long) number_pixels; x++)
1893 {
1894 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1895 q->red=ScaleAnyToQuantum(pixel,range);
1896 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1897 q->green=ScaleAnyToQuantum(pixel,range);
1898 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1899 q->blue=ScaleAnyToQuantum(pixel,range);
1900 q++;
1901 }
1902 break;
1903 }
1904 }
1905 break;
1906 }
1907 case RGBAQuantum:
1908 case RGBOQuantum:
1909 case CbYCrAQuantum:
1910 {
1911 switch (quantum_info->depth)
1912 {
1913 case 8:
1914 {
1915 unsigned char
1916 pixel;
1917
1918 for (x=0; x < (long) number_pixels; x++)
1919 {
1920 p=PushCharPixel(p,&pixel);
1921 q->red=ScaleCharToQuantum(pixel);
1922 p=PushCharPixel(p,&pixel);
1923 q->green=ScaleCharToQuantum(pixel);
1924 p=PushCharPixel(p,&pixel);
1925 q->blue=ScaleCharToQuantum(pixel);
1926 p=PushCharPixel(p,&pixel);
1927 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1928 p+=quantum_info->pad;
1929 q++;
1930 }
1931 break;
1932 }
1933 case 10:
1934 {
1935 pixel=0;
1936 if (quantum_info->pack == MagickFalse)
1937 {
1938 long
1939 n;
1940
1941 register long
1942 i;
1943
1944 unsigned long
1945 quantum;
1946
1947 n=0;
1948 quantum=0;
1949 for (x=0; x < (long) number_pixels; x++)
1950 {
1951 for (i=0; i < 4; i++)
1952 {
1953 switch (n % 3)
1954 {
1955 case 0:
1956 {
1957 p=PushLongPixel(endian,p,&pixel);
1958 quantum=(unsigned long) (ScaleShortToQuantum(
1959 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
1960 break;
1961 }
1962 case 1:
1963 {
1964 quantum=(unsigned long) (ScaleShortToQuantum(
1965 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
1966 break;
1967 }
1968 case 2:
1969 {
1970 quantum=(unsigned long) (ScaleShortToQuantum(
1971 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
1972 break;
1973 }
1974 }
1975 switch (i)
1976 {
1977 case 0: q->red=(Quantum) (quantum); break;
1978 case 1: q->green=(Quantum) (quantum); break;
1979 case 2: q->blue=(Quantum) (quantum); break;
1980 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
1981 }
1982 n++;
1983 }
1984 p+=quantum_info->pad;
1985 q++;
1986 }
1987 break;
1988 }
1989 for (x=0; x < (long) number_pixels; x++)
1990 {
1991 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1992 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
1993 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1994 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
1995 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1996 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
1997 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1998 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
1999 (unsigned short) (pixel << 6)));
2000 q++;
2001 }
2002 break;
2003 }
2004 case 16:
2005 {
2006 unsigned short
2007 pixel;
2008
2009 for (x=0; x < (long) number_pixels; x++)
2010 {
2011 p=PushShortPixel(endian,p,&pixel);
2012 q->red=ScaleShortToQuantum(pixel);
2013 p=PushShortPixel(endian,p,&pixel);
2014 q->green=ScaleShortToQuantum(pixel);
2015 p=PushShortPixel(endian,p,&pixel);
2016 q->blue=ScaleShortToQuantum(pixel);
2017 p=PushShortPixel(endian,p,&pixel);
2018 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2019 p+=quantum_info->pad;
2020 q++;
2021 }
2022 break;
2023 }
2024 case 32:
2025 {
2026 unsigned long
2027 pixel;
2028
2029 if (quantum_info->format == FloatingPointQuantumFormat)
2030 {
2031 float
2032 pixel;
2033
2034 for (x=0; x < (long) number_pixels; x++)
2035 {
2036 p=PushFloatPixel(&quantum_state,p,&pixel);
2037 q->red=RoundToQuantum(pixel);
2038 p=PushFloatPixel(&quantum_state,p,&pixel);
2039 q->green=RoundToQuantum(pixel);
2040 p=PushFloatPixel(&quantum_state,p,&pixel);
2041 q->blue=RoundToQuantum(pixel);
2042 p=PushFloatPixel(&quantum_state,p,&pixel);
2043 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2044 p+=quantum_info->pad;
2045 q++;
2046 }
2047 break;
2048 }
2049 for (x=0; x < (long) number_pixels; x++)
2050 {
2051 p=PushLongPixel(endian,p,&pixel);
2052 q->red=ScaleLongToQuantum(pixel);
2053 p=PushLongPixel(endian,p,&pixel);
2054 q->green=ScaleLongToQuantum(pixel);
2055 p=PushLongPixel(endian,p,&pixel);
2056 q->blue=ScaleLongToQuantum(pixel);
2057 p=PushLongPixel(endian,p,&pixel);
2058 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2059 p+=quantum_info->pad;
2060 q++;
2061 }
2062 break;
2063 }
2064 case 64:
2065 {
2066 if (quantum_info->format == FloatingPointQuantumFormat)
2067 {
2068 double
2069 pixel;
2070
2071 for (x=0; x < (long) number_pixels; x++)
2072 {
2073 p=PushDoublePixel(&quantum_state,p,&pixel);
2074 q->red=RoundToQuantum(pixel);
2075 p=PushDoublePixel(&quantum_state,p,&pixel);
2076 q->green=RoundToQuantum(pixel);
2077 p=PushDoublePixel(&quantum_state,p,&pixel);
2078 q->blue=RoundToQuantum(pixel);
2079 p=PushDoublePixel(&quantum_state,p,&pixel);
2080 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2081 p+=quantum_info->pad;
2082 q++;
2083 }
2084 break;
2085 }
2086 }
2087 default:
2088 {
2089 range=GetQuantumRange(image->depth);
2090 for (x=0; x < (long) number_pixels; x++)
2091 {
2092 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2093 q->red=ScaleAnyToQuantum(pixel,range);
2094 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2095 q->green=ScaleAnyToQuantum(pixel,range);
2096 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2097 q->blue=ScaleAnyToQuantum(pixel,range);
2098 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2099 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2100 q++;
2101 }
2102 break;
2103 }
2104 }
2105 break;
2106 }
2107 case CMYKQuantum:
2108 {
2109 if (image->colorspace != CMYKColorspace)
2110 {
2111 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2112 "ColorSeparatedImageRequired","`%s'",image->filename);
2113 return(extent);
2114 }
2115 switch (quantum_info->depth)
2116 {
2117 case 8:
2118 {
2119 unsigned char
2120 pixel;
2121
2122 for (x=0; x < (long) number_pixels; x++)
2123 {
2124 p=PushCharPixel(p,&pixel);
2125 q->red=ScaleCharToQuantum(pixel);
2126 p=PushCharPixel(p,&pixel);
2127 q->green=ScaleCharToQuantum(pixel);
2128 p=PushCharPixel(p,&pixel);
2129 q->blue=ScaleCharToQuantum(pixel);
2130 p=PushCharPixel(p,&pixel);
2131 indexes[x]=ScaleCharToQuantum(pixel);
2132 p+=quantum_info->pad;
2133 q++;
2134 }
2135 break;
2136 }
2137 case 16:
2138 {
2139 unsigned short
2140 pixel;
2141
2142 for (x=0; x < (long) number_pixels; x++)
2143 {
2144 p=PushShortPixel(endian,p,&pixel);
2145 q->red=ScaleShortToQuantum(pixel);
2146 p=PushShortPixel(endian,p,&pixel);
2147 q->green=ScaleShortToQuantum(pixel);
2148 p=PushShortPixel(endian,p,&pixel);
2149 q->blue=ScaleShortToQuantum(pixel);
2150 p=PushShortPixel(endian,p,&pixel);
2151 indexes[x]=ScaleShortToQuantum(pixel);
2152 p+=quantum_info->pad;
2153 q++;
2154 }
2155 break;
2156 }
2157 case 32:
2158 {
2159 unsigned long
2160 pixel;
2161
2162 if (quantum_info->format == FloatingPointQuantumFormat)
2163 {
2164 float
2165 pixel;
2166
2167 for (x=0; x < (long) number_pixels; x++)
2168 {
2169 p=PushFloatPixel(&quantum_state,p,&pixel);
2170 q->red=RoundToQuantum(pixel);
2171 p=PushFloatPixel(&quantum_state,p,&pixel);
2172 q->green=RoundToQuantum(pixel);
2173 p=PushFloatPixel(&quantum_state,p,&pixel);
2174 q->blue=RoundToQuantum(pixel);
2175 p=PushFloatPixel(&quantum_state,p,&pixel);
2176 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2177 p+=quantum_info->pad;
2178 q++;
2179 }
2180 break;
2181 }
2182 for (x=0; x < (long) number_pixels; x++)
2183 {
2184 p=PushLongPixel(endian,p,&pixel);
2185 q->red=ScaleLongToQuantum(pixel);
2186 p=PushLongPixel(endian,p,&pixel);
2187 q->green=ScaleLongToQuantum(pixel);
2188 p=PushLongPixel(endian,p,&pixel);
2189 q->blue=ScaleLongToQuantum(pixel);
2190 p=PushLongPixel(endian,p,&pixel);
2191 indexes[x]=ScaleLongToQuantum(pixel);
2192 p+=quantum_info->pad;
2193 q++;
2194 }
2195 break;
2196 }
2197 case 64:
2198 {
2199 if (quantum_info->format == FloatingPointQuantumFormat)
2200 {
2201 double
2202 pixel;
2203
2204 for (x=0; x < (long) number_pixels; x++)
2205 {
2206 p=PushDoublePixel(&quantum_state,p,&pixel);
2207 q->red=RoundToQuantum(pixel);
2208 p=PushDoublePixel(&quantum_state,p,&pixel);
2209 q->green=RoundToQuantum(pixel);
2210 p=PushDoublePixel(&quantum_state,p,&pixel);
2211 q->blue=RoundToQuantum(pixel);
2212 p=PushDoublePixel(&quantum_state,p,&pixel);
2213 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2214 p+=quantum_info->pad;
2215 q++;
2216 }
2217 break;
2218 }
2219 }
2220 default:
2221 {
2222 range=GetQuantumRange(image->depth);
2223 for (x=0; x < (long) number_pixels; x++)
2224 {
2225 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2226 q->red=ScaleAnyToQuantum(pixel,range);
2227 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2228 q->green=ScaleAnyToQuantum(pixel,range);
2229 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2230 q->blue=ScaleAnyToQuantum(pixel,range);
2231 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2232 indexes[x]=ScaleAnyToQuantum(pixel,range);
2233 q++;
2234 }
2235 break;
2236 }
2237 }
2238 break;
2239 }
2240 case CMYKAQuantum:
2241 case CMYKOQuantum:
2242 {
2243 if (image->colorspace != CMYKColorspace)
2244 {
2245 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2246 "ColorSeparatedImageRequired","`%s'",image->filename);
2247 return(extent);
2248 }
2249 switch (quantum_info->depth)
2250 {
2251 case 8:
2252 {
2253 unsigned char
2254 pixel;
2255
2256 for (x=0; x < (long) number_pixels; x++)
2257 {
2258 p=PushCharPixel(p,&pixel);
2259 q->red=ScaleCharToQuantum(pixel);
2260 p=PushCharPixel(p,&pixel);
2261 q->green=ScaleCharToQuantum(pixel);
2262 p=PushCharPixel(p,&pixel);
2263 q->blue=ScaleCharToQuantum(pixel);
2264 p=PushCharPixel(p,&pixel);
2265 indexes[x]=ScaleCharToQuantum(pixel);
2266 p=PushCharPixel(p,&pixel);
2267 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2268 p+=quantum_info->pad;
2269 q++;
2270 }
2271 break;
2272 }
2273 case 16:
2274 {
2275 unsigned short
2276 pixel;
2277
2278 for (x=0; x < (long) number_pixels; x++)
2279 {
2280 p=PushShortPixel(endian,p,&pixel);
2281 q->red=ScaleShortToQuantum(pixel);
2282 p=PushShortPixel(endian,p,&pixel);
2283 q->green=ScaleShortToQuantum(pixel);
2284 p=PushShortPixel(endian,p,&pixel);
2285 q->blue=ScaleShortToQuantum(pixel);
2286 p=PushShortPixel(endian,p,&pixel);
2287 indexes[x]=ScaleShortToQuantum(pixel);
2288 p=PushShortPixel(endian,p,&pixel);
2289 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2290 p+=quantum_info->pad;
2291 q++;
2292 }
2293 break;
2294 }
2295 case 32:
2296 {
2297 unsigned long
2298 pixel;
2299
2300 if (quantum_info->format == FloatingPointQuantumFormat)
2301 {
2302 float
2303 pixel;
2304
2305 for (x=0; x < (long) number_pixels; x++)
2306 {
2307 p=PushFloatPixel(&quantum_state,p,&pixel);
2308 q->red=RoundToQuantum(pixel);
2309 p=PushFloatPixel(&quantum_state,p,&pixel);
2310 q->green=RoundToQuantum(pixel);
2311 p=PushFloatPixel(&quantum_state,p,&pixel);
2312 q->blue=RoundToQuantum(pixel);
2313 p=PushFloatPixel(&quantum_state,p,&pixel);
2314 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2315 p=PushFloatPixel(&quantum_state,p,&pixel);
2316 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2317 p+=quantum_info->pad;
2318 q++;
2319 }
2320 break;
2321 }
2322 for (x=0; x < (long) number_pixels; x++)
2323 {
2324 p=PushLongPixel(endian,p,&pixel);
2325 q->red=ScaleLongToQuantum(pixel);
2326 p=PushLongPixel(endian,p,&pixel);
2327 q->green=ScaleLongToQuantum(pixel);
2328 p=PushLongPixel(endian,p,&pixel);
2329 q->blue=ScaleLongToQuantum(pixel);
2330 p=PushLongPixel(endian,p,&pixel);
2331 indexes[x]=ScaleLongToQuantum(pixel);
2332 p=PushLongPixel(endian,p,&pixel);
2333 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2334 p+=quantum_info->pad;
2335 q++;
2336 }
2337 break;
2338 }
2339 case 64:
2340 {
2341 if (quantum_info->format == FloatingPointQuantumFormat)
2342 {
2343 double
2344 pixel;
2345
2346 for (x=0; x < (long) number_pixels; x++)
2347 {
2348 p=PushDoublePixel(&quantum_state,p,&pixel);
2349 q->red=RoundToQuantum(pixel);
2350 p=PushDoublePixel(&quantum_state,p,&pixel);
2351 q->green=RoundToQuantum(pixel);
2352 p=PushDoublePixel(&quantum_state,p,&pixel);
2353 q->blue=RoundToQuantum(pixel);
2354 p=PushDoublePixel(&quantum_state,p,&pixel);
2355 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2356 p=PushDoublePixel(&quantum_state,p,&pixel);
2357 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2358 p=PushDoublePixel(&quantum_state,p,&pixel);
2359 p+=quantum_info->pad;
2360 q++;
2361 }
2362 break;
2363 }
2364 }
2365 default:
2366 {
2367 range=GetQuantumRange(image->depth);
2368 for (x=0; x < (long) number_pixels; x++)
2369 {
2370 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2371 q->red=ScaleAnyToQuantum(pixel,range);
2372 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2373 q->green=ScaleAnyToQuantum(pixel,range);
2374 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2375 q->blue=ScaleAnyToQuantum(pixel,range);
2376 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2377 indexes[x]=ScaleAnyToQuantum(pixel,range);
2378 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2379 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2380 q++;
2381 }
2382 break;
2383 }
2384 }
2385 break;
2386 }
2387 case CbYCrYQuantum:
2388 {
2389 switch (quantum_info->depth)
2390 {
2391 case 10:
2392 {
2393 Quantum
2394 cbcr[4];
2395
2396 pixel=0;
2397 if (quantum_info->pack == MagickFalse)
2398 {
2399 long
2400 n;
2401
2402 register long
2403 i;
2404
2405 unsigned long
2406 quantum;
2407
2408 n=0;
2409 quantum=0;
2410 for (x=0; x < (long) number_pixels; x+=2)
2411 {
2412 for (i=0; i < 4; i++)
2413 {
2414 switch (n % 3)
2415 {
2416 case 0:
2417 {
2418 p=PushLongPixel(endian,p,&pixel);
2419 quantum=(unsigned long) (ScaleShortToQuantum(
2420 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2421 break;
2422 }
2423 case 1:
2424 {
2425 quantum=(unsigned long) (ScaleShortToQuantum(
2426 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2427 break;
2428 }
2429 case 2:
2430 {
2431 quantum=(unsigned long) (ScaleShortToQuantum(
2432 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2433 break;
2434 }
2435 }
2436 cbcr[i]=(Quantum) (quantum);
2437 n++;
2438 }
2439 p+=quantum_info->pad;
2440 q->red=cbcr[1];
2441 q->green=cbcr[0];
2442 q->blue=cbcr[2];
2443 q++;
2444 q->red=cbcr[3];
2445 q->green=cbcr[0];
2446 q->blue=cbcr[2];
2447 q++;
2448 }
2449 break;
2450 }
2451 }
2452 default:
2453 {
2454 range=GetQuantumRange(image->depth);
2455 for (x=0; x < (long) number_pixels; x++)
2456 {
2457 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2458 q->red=ScaleAnyToQuantum(pixel,range);
2459 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2460 q->green=ScaleAnyToQuantum(pixel,range);
2461 q++;
2462 }
2463 break;
2464 }
2465 }
2466 break;
2467 }
2468 default:
2469 break;
2470 }
2471 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2472 {
2473 Quantum
2474 quantum;
2475
2476 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002477 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002478
2479 q=GetAuthenticPixelQueue(image);
2480 if (image_view != (CacheView *) NULL)
2481 q=GetCacheViewAuthenticPixelQueue(image_view);
2482 for (x=0; x < (long) number_pixels; x++)
2483 {
2484 quantum=q->red;
2485 q->red=q->green;
2486 q->green=quantum;
2487 q++;
2488 }
2489 }
2490 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2491 {
2492 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002493 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002494
2495 q=GetAuthenticPixelQueue(image);
2496 if (image_view != (CacheView *) NULL)
2497 q=GetCacheViewAuthenticPixelQueue(image_view);
2498 for (x=0; x < (long) number_pixels; x++)
2499 {
2500 q->opacity=(Quantum) (QuantumRange-q->opacity);
2501 q++;
2502 }
2503 }
2504 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2505 {
2506 MagickRealType
2507 alpha;
2508
2509 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002510 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002511
2512 /*
2513 Disassociate alpha.
2514 */
2515 q=GetAuthenticPixelQueue(image);
2516 if (image_view != (CacheView *) NULL)
2517 q=GetCacheViewAuthenticPixelQueue(image_view);
2518 for (x=0; x < (long) number_pixels; x++)
2519 {
2520 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2521 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2522 q->red=RoundToQuantum(alpha*q->red);
2523 q->green=RoundToQuantum(alpha*q->green);
2524 q->blue=RoundToQuantum(alpha*q->blue);
2525 q++;
2526 }
2527 }
2528 return(extent);
2529}