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