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