]> granicus.if.org Git - imagemagick/blob - MagickCore/quantum-export.c
(no commit message)
[imagemagick] / MagickCore / quantum-export.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 %                   EEEEE  X   X  PPPP    OOO   RRRR   TTTTT                  %
13 %                   E       X X   P   P  O   O  R   R    T                    %
14 %                   EEE      X    PPPP   O   O  RRRR     T                    %
15 %                   E       X X   P      O   O  R R      T                    %
16 %                   EEEEE  X   X  P       OOO   R  R     T                    %
17 %                                                                             %
18 %                 MagickCore Methods to Export 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 "MagickCore/studio.h"
48 #include "MagickCore/property.h"
49 #include "MagickCore/blob.h"
50 #include "MagickCore/blob-private.h"
51 #include "MagickCore/color-private.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/cache.h"
55 #include "MagickCore/constitute.h"
56 #include "MagickCore/delegate.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/option.h"
63 #include "MagickCore/pixel.h"
64 #include "MagickCore/pixel-accessor.h"
65 #include "MagickCore/quantum.h"
66 #include "MagickCore/quantum-private.h"
67 #include "MagickCore/resource_.h"
68 #include "MagickCore/semaphore.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/stream.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/utility.h"
73 \f
74 /*
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %                                                                             %
77 %                                                                             %
78 %                                                                             %
79 +   E x p o r t Q u a n t u m P i x e l s                                     %
80 %                                                                             %
81 %                                                                             %
82 %                                                                             %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %
85 %  ExportQuantumPixels() transfers one or more pixel components from the image
86 %  pixel cache to a user supplied buffer.  The pixels are returned in network
87 %  byte order.  MagickTrue is returned if the pixels are successfully
88 %  transferred, otherwise MagickFalse.
89 %
90 %  The format of the ExportQuantumPixels method is:
91 %
92 %      size_t ExportQuantumPixels(const Image *image,
93 %        const CacheView *image_view,const QuantumInfo *quantum_info,
94 %        const QuantumType quantum_type,unsigned char *pixels,
95 %        ExceptionInfo *exception)
96 %
97 %  A description of each parameter follows:
98 %
99 %    o image: the image.
100 %
101 %    o image_view: the image cache view.
102 %
103 %    o quantum_info: the quantum info.
104 %
105 %    o quantum_type: Declare which pixel components to transfer (RGB, RGBA,
106 %      etc).
107 %
108 %    o pixels:  The components are transferred to this buffer.
109 %
110 %    o exception: return any errors or warnings in this structure.
111 %
112 */
113
114 static inline unsigned char *PopDoublePixel(const QuantumState *quantum_state,
115   const double pixel,unsigned char *pixels)
116 {
117   double
118     *p;
119
120   unsigned char
121     quantum[8];
122
123   p=(double *) quantum;
124   *p=(double) (pixel*quantum_state->inverse_scale+quantum_state->minimum);
125   if (quantum_state->endian != LSBEndian)
126     {
127       *pixels++=quantum[7];
128       *pixels++=quantum[6];
129       *pixels++=quantum[5];
130       *pixels++=quantum[4];
131       *pixels++=quantum[3];
132       *pixels++=quantum[2];
133       *pixels++=quantum[1];
134       *pixels++=quantum[0];
135       return(pixels);
136     }
137   *pixels++=quantum[0];
138   *pixels++=quantum[1];
139   *pixels++=quantum[2];
140   *pixels++=quantum[3];
141   *pixels++=quantum[4];
142   *pixels++=quantum[5];
143   *pixels++=quantum[6];
144   *pixels++=quantum[7];
145   return(pixels);
146 }
147
148 static inline unsigned char *PopFloatPixel(const QuantumState *quantum_state,
149   const float pixel,unsigned char *pixels)
150 {
151   float
152     *p;
153
154   unsigned char
155     quantum[4];
156
157   p=(float *) quantum;
158   *p=(float) ((double) pixel*quantum_state->inverse_scale+
159     quantum_state->minimum);
160   if (quantum_state->endian != LSBEndian)
161     {
162       *pixels++=quantum[3];
163       *pixels++=quantum[2];
164       *pixels++=quantum[1];
165       *pixels++=quantum[0];
166       return(pixels);
167     }
168   *pixels++=quantum[0];
169   *pixels++=quantum[1];
170   *pixels++=quantum[2];
171   *pixels++=quantum[3];
172   return(pixels);
173 }
174
175 static inline unsigned char *PopQuantumPixel(QuantumState *quantum_state,
176   const size_t depth,const QuantumAny pixel,unsigned char *pixels)
177 {
178   register ssize_t
179     i;
180
181   size_t
182     quantum_bits;
183
184   if (quantum_state->bits == 0UL)
185     quantum_state->bits=8U;
186   for (i=(ssize_t) depth; i > 0L; )
187   {
188     quantum_bits=(size_t) i;
189     if (quantum_bits > quantum_state->bits)
190       quantum_bits=quantum_state->bits;
191     i-=(ssize_t) quantum_bits;
192     if (quantum_state->bits == 8UL)
193       *pixels='\0';
194     quantum_state->bits-=quantum_bits;
195     *pixels|=(((pixel >> i) &~ ((~0UL) << quantum_bits)) <<
196       quantum_state->bits);
197     if (quantum_state->bits == 0UL)
198       {
199         pixels++;
200         quantum_state->bits=8UL;
201       }
202   }
203   return(pixels);
204 }
205
206 static inline unsigned char *PopQuantumLongPixel(QuantumState *quantum_state,
207   const size_t depth,const size_t pixel,unsigned char *pixels)
208 {
209   register ssize_t
210     i;
211
212   size_t
213     quantum_bits;
214
215   if (quantum_state->bits == 0U)
216     quantum_state->bits=32UL;
217   for (i=(ssize_t) depth; i > 0; )
218   {
219     quantum_bits=(size_t) i;
220     if (quantum_bits > quantum_state->bits)
221       quantum_bits=quantum_state->bits;
222     quantum_state->pixel|=(((pixel >> (depth-i)) &
223       quantum_state->mask[quantum_bits]) << (32U-quantum_state->bits));
224     i-=(ssize_t) quantum_bits;
225     quantum_state->bits-=quantum_bits;
226     if (quantum_state->bits == 0U)
227       {
228         pixels=PopLongPixel(quantum_state->endian,quantum_state->pixel,pixels);
229         quantum_state->pixel=0U;
230         quantum_state->bits=32U;
231       }
232   }
233   return(pixels);
234 }
235
236 MagickExport size_t ExportQuantumPixels(Image *image,CacheView *image_view,
237   const QuantumInfo *quantum_info,const QuantumType quantum_type,
238   unsigned char *pixels,ExceptionInfo *exception)
239 {
240   EndianType
241     endian;
242
243   MagickRealType
244     alpha;
245
246   MagickSizeType
247     number_pixels;
248
249   QuantumAny
250     range;
251
252   QuantumState
253     quantum_state;
254
255   register const Quantum
256     *restrict p;
257
258   register ssize_t
259     x;
260
261   register unsigned char
262     *restrict q;
263
264   size_t
265     channels,
266     extent;
267
268   ssize_t
269     bit;
270
271   assert(image != (Image *) NULL);
272   assert(image->signature == MagickSignature);
273   if (image->debug != MagickFalse)
274     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
275   assert(quantum_info != (QuantumInfo *) NULL);
276   assert(quantum_info->signature == MagickSignature);
277   if (pixels == (unsigned char *) NULL)
278     pixels=GetQuantumPixels(quantum_info);
279   if (image_view == (CacheView *) NULL)
280     {
281       number_pixels=GetImageExtent(image);
282       p=GetVirtualPixelQueue(image);
283       channels=GetPixelChannels(image);
284     }
285   else
286     {
287       number_pixels=GetCacheViewExtent(image_view);
288       p=GetCacheViewVirtualPixelQueue(image_view);
289       channels=GetPixelChannels(image);
290     }
291   if (quantum_info->alpha_type == AssociatedQuantumAlpha)
292     {
293       register Quantum
294         *restrict q;
295
296       /*
297         Associate alpha.
298       */
299       q=GetAuthenticPixelQueue(image);
300       if (image_view != (CacheView *) NULL)
301         q=GetCacheViewAuthenticPixelQueue(image_view);
302       for (x=0; x < (ssize_t) image->columns; x++)
303       {
304         alpha=QuantumScale*GetPixelAlpha(image,q);
305         SetPixelRed(image,ClampToQuantum(alpha*GetPixelRed(image,q)),q);
306         SetPixelGreen(image,ClampToQuantum(alpha*GetPixelGreen(image,q)),q);
307         SetPixelBlue(image,ClampToQuantum(alpha*GetPixelBlue(image,q)),q);
308         q++;
309       }
310     }
311   if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
312       (quantum_type == BGROQuantum))
313     {
314       register Quantum
315         *restrict q;
316
317       q=GetAuthenticPixelQueue(image);
318       if (image_view != (CacheView *) NULL)
319         q=GetCacheViewAuthenticPixelQueue(image_view);
320       for (x=0; x < (ssize_t) number_pixels; x++)
321       {
322         SetPixelAlpha(image,GetPixelAlpha(image,q),q);
323         q++;
324       }
325     }
326   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
327     {
328       Quantum
329         quantum;
330
331       register Quantum
332         *restrict q;
333
334       q=GetAuthenticPixelQueue(image);
335       if (image_view != (CacheView *) NULL)
336         q=GetAuthenticPixelQueue(image);
337       for (x=0; x < (ssize_t) number_pixels; x++)
338       {
339         quantum=GetPixelRed(image,q);
340         SetPixelRed(image,GetPixelGreen(image,q),q);
341         SetPixelGreen(image,quantum,q);
342         q+=channels;
343       }
344     }
345   x=0;
346   q=pixels;
347   InitializeQuantumState(quantum_info,image->endian,&quantum_state);
348   extent=GetQuantumExtent(image,quantum_info,quantum_type);
349   endian=quantum_state.endian;
350   switch (quantum_type)
351   {
352     case IndexQuantum:
353     {
354       if (image->storage_class != PseudoClass)
355         {
356           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
357             "ColormappedImageRequired","`%s'",image->filename);
358           return(extent);
359         }
360       switch (quantum_info->depth)
361       {
362         case 1:
363         {
364           register unsigned char
365             pixel;
366
367           for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
368           {
369             pixel=(unsigned char) GetPixelIndex(image,p);
370             *q=((pixel & 0x01) << 7);
371             p+=channels;
372             pixel=(unsigned char) GetPixelIndex(image,p);
373             *q|=((pixel & 0x01) << 6);
374             p+=channels;
375             pixel=(unsigned char) GetPixelIndex(image,p);
376             *q|=((pixel & 0x01) << 5);
377             p+=channels;
378             pixel=(unsigned char) GetPixelIndex(image,p);
379             *q|=((pixel & 0x01) << 4);
380             p+=channels;
381             pixel=(unsigned char) GetPixelIndex(image,p);
382             *q|=((pixel & 0x01) << 3);
383             p+=channels;
384             pixel=(unsigned char) GetPixelIndex(image,p);
385             *q|=((pixel & 0x01) << 2);
386             p+=channels;
387             pixel=(unsigned char) GetPixelIndex(image,p);
388             *q|=((pixel & 0x01) << 1);
389             p+=channels;
390             pixel=(unsigned char) GetPixelIndex(image,p);
391             *q|=((pixel & 0x01) << 0);
392             p+=channels;
393             q++;
394           }
395           if ((number_pixels % 8) != 0)
396             {
397               *q='\0';
398               for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
399               {
400                 pixel=(unsigned char) GetPixelIndex(image,p);
401                 *q|=((pixel & 0x01) << (unsigned char) bit);
402                 p+=channels;
403               }
404               q++;
405             }
406           break;
407         }
408         case 4:
409         {
410           register unsigned char
411             pixel;
412
413           for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
414           {
415             pixel=(unsigned char) GetPixelIndex(image,p);
416             *q=((pixel & 0xf) << 4);
417             p+=channels;
418             pixel=(unsigned char) GetPixelIndex(image,p);
419             *q|=((pixel & 0xf) << 0);
420             p+=channels;
421             q++;
422           }
423           if ((number_pixels % 2) != 0)
424             {
425               pixel=(unsigned char) GetPixelIndex(image,p);
426               *q=((pixel & 0xf) << 4);
427               p+=channels;
428               q++;
429             }
430           break;
431         }
432         case 8:
433         {
434           for (x=0; x < (ssize_t) number_pixels; x++)
435           {
436             q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
437             p+=channels;
438             q+=quantum_info->pad;
439           }
440           break;
441         }
442         case 16:
443         {
444           if (quantum_info->format == FloatingPointQuantumFormat)
445             {
446               for (x=0; x < (ssize_t) number_pixels; x++)
447               {
448                 q=PopShortPixel(endian,SinglePrecisionToHalf(QuantumScale*
449                   GetPixelIndex(image,p)),q);
450                 p+=channels;
451                 q+=quantum_info->pad;
452               }
453               break;
454             }
455           for (x=0; x < (ssize_t) number_pixels; x++)
456           {
457             q=PopShortPixel(endian,(unsigned short) GetPixelIndex(image,p),q);
458             p+=channels;
459             q+=quantum_info->pad;
460           }
461           break;
462         }
463         case 32:
464         {
465           if (quantum_info->format == FloatingPointQuantumFormat)
466             {
467               for (x=0; x < (ssize_t) number_pixels; x++)
468               {
469                 q=PopFloatPixel(&quantum_state,(float)
470                   GetPixelIndex(image,p),q);
471                 p+=channels;
472                 q+=quantum_info->pad;
473               }
474               break;
475             }
476           for (x=0; x < (ssize_t) number_pixels; x++)
477           {
478             q=PopLongPixel(endian,(unsigned int) GetPixelIndex(image,p),q);
479             p+=channels;
480             q+=quantum_info->pad;
481           }
482           break;
483         }
484         case 64:
485         {
486           if (quantum_info->format == FloatingPointQuantumFormat)
487             {
488               for (x=0; x < (ssize_t) number_pixels; x++)
489               {
490                 q=PopDoublePixel(&quantum_state,(double)
491                   GetPixelIndex(image,p),q);
492                 p+=channels;
493                 q+=quantum_info->pad;
494               }
495               break;
496             }
497         }
498         default:
499         {
500           for (x=0; x < (ssize_t) number_pixels; x++)
501           {
502             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
503               GetPixelIndex(image,p),q);
504             p+=channels;
505             q+=quantum_info->pad;
506           }
507           break;
508         }
509       }
510       break;
511     }
512     case IndexAlphaQuantum:
513     {
514       if (image->storage_class != PseudoClass)
515         {
516           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
517             "ColormappedImageRequired","`%s'",image->filename);
518           return(extent);
519         }
520       switch (quantum_info->depth)
521       {
522         case 1:
523         {
524           register unsigned char
525             pixel;
526
527           for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
528           {
529             pixel=(unsigned char) GetPixelIndex(image,p);
530             *q=((pixel & 0x01) << 7);
531             pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
532               TransparentAlpha ? 1 : 0);
533             *q|=((pixel & 0x01) << 6);
534             p+=channels;
535             pixel=(unsigned char) GetPixelIndex(image,p);
536             *q|=((pixel & 0x01) << 5);
537             pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
538               TransparentAlpha ? 1 : 0);
539             *q|=((pixel & 0x01) << 4);
540             p+=channels;
541             pixel=(unsigned char) GetPixelIndex(image,p);
542             *q|=((pixel & 0x01) << 3);
543             pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
544               TransparentAlpha ? 1 : 0);
545             *q|=((pixel & 0x01) << 2);
546             p+=channels;
547             pixel=(unsigned char) GetPixelIndex(image,p);
548             *q|=((pixel & 0x01) << 1);
549             pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
550               TransparentAlpha ? 1 : 0);
551             *q|=((pixel & 0x01) << 0);
552             p+=channels;
553             q++;
554           }
555           if ((number_pixels % 4) != 0)
556             {
557               *q='\0';
558               for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
559               {
560                 pixel=(unsigned char) GetPixelIndex(image,p);
561                 *q|=((pixel & 0x01) << (unsigned char) (bit+4));
562                 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
563                   TransparentAlpha ? 1 : 0);
564                 *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
565                 p+=channels;
566               }
567               q++;
568             }
569           break;
570         }
571         case 4:
572         {
573           register unsigned char
574             pixel;
575
576           for (x=0; x < (ssize_t) number_pixels ; x++)
577           {
578             pixel=(unsigned char) GetPixelIndex(image,p);
579             *q=((pixel & 0xf) << 4);
580             pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
581             *q|=((pixel & 0xf) << 0);
582             p+=channels;
583             q++;
584           }
585           break;
586         }
587         case 8:
588         {
589           register unsigned char
590             pixel;
591
592           for (x=0; x < (ssize_t) number_pixels; x++)
593           {
594             q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
595             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
596             q=PopCharPixel(pixel,q);
597             p+=channels;
598             q+=quantum_info->pad;
599           }
600           break;
601         }
602         case 16:
603         {
604           register unsigned short
605             pixel;
606
607           if (quantum_info->format == FloatingPointQuantumFormat)
608             {
609               for (x=0; x < (ssize_t) number_pixels; x++)
610               {
611                 q=PopShortPixel(endian,(unsigned short)
612                   GetPixelIndex(image,p),q);
613                 pixel=SinglePrecisionToHalf(QuantumScale*
614                   GetPixelAlpha(image,p));
615                 q=PopShortPixel(endian,pixel,q);
616                 p+=channels;
617                 q+=quantum_info->pad;
618               }
619               break;
620             }
621           for (x=0; x < (ssize_t) number_pixels; x++)
622           {
623             q=PopShortPixel(endian,(unsigned short) GetPixelIndex(image,p),q);
624             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
625             q=PopShortPixel(endian,pixel,q);
626             p+=channels;
627             q+=quantum_info->pad;
628           }
629           break;
630         }
631         case 32:
632         {
633           register unsigned int
634             pixel;
635
636           if (quantum_info->format == FloatingPointQuantumFormat)
637             {
638               for (x=0; x < (ssize_t) number_pixels; x++)
639               {
640                 float
641                   pixel;
642
643                 q=PopFloatPixel(&quantum_state,(float)
644                   GetPixelIndex(image,p),q);
645                 pixel=(float)  GetPixelAlpha(image,p);
646                 q=PopFloatPixel(&quantum_state,pixel,q);
647                 p+=channels;
648                 q+=quantum_info->pad;
649               }
650               break;
651             }
652           for (x=0; x < (ssize_t) number_pixels; x++)
653           {
654             q=PopLongPixel(endian,(unsigned int) GetPixelIndex(image,p),q);
655             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
656             q=PopLongPixel(endian,pixel,q);
657             p+=channels;
658             q+=quantum_info->pad;
659           }
660           break;
661         }
662         case 64:
663         {
664           if (quantum_info->format == FloatingPointQuantumFormat)
665             {
666               for (x=0; x < (ssize_t) number_pixels; x++)
667               {
668                 double
669                   pixel;
670
671                 q=PopDoublePixel(&quantum_state,(double)
672                   GetPixelIndex(image,p),q);
673                 pixel=(double) GetPixelAlpha(image,p);
674                 q=PopDoublePixel(&quantum_state,pixel,q);
675                 p+=channels;
676                 q+=quantum_info->pad;
677               }
678               break;
679             }
680         }
681         default:
682         {
683           range=GetQuantumRange(quantum_info->depth);
684           for (x=0; x < (ssize_t) number_pixels; x++)
685           {
686             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
687               GetPixelIndex(image,p),q);
688             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
689               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
690             p+=channels;
691             q+=quantum_info->pad;
692           }
693           break;
694         }
695       }
696       break;
697     }
698     case BGRQuantum:
699     {
700       switch (quantum_info->depth)
701       {
702         case 8:
703         {
704           for (x=0; x < (ssize_t) number_pixels; x++)
705           {
706             q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
707             q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
708             q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
709             p+=channels;
710             q+=quantum_info->pad;
711           }
712           break;
713         }
714         case 10:
715         {
716           register unsigned int
717             pixel;
718
719           range=GetQuantumRange(quantum_info->depth);
720           if (quantum_info->pack == MagickFalse)
721             {
722               for (x=0; x < (ssize_t) number_pixels; x++)
723               {
724                 pixel=(unsigned int) (
725                   ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
726                   ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
727                   ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
728                 q=PopLongPixel(endian,pixel,q);
729                 p+=channels;
730                 q+=quantum_info->pad;
731               }
732               break;
733             }
734           if (quantum_info->quantum == 32UL)
735             {
736               for (x=0; x < (ssize_t) number_pixels; x++)
737               {
738                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
739                   range);
740                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
741                   q);
742                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
743                   range);
744                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
745                   q);
746                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
747                   range);
748                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
749                   q);
750                 p+=channels;
751                 q+=quantum_info->pad;
752               }
753               break;
754             }
755           for (x=0; x < (ssize_t) number_pixels; x++)
756           {
757             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
758               range);
759             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
760             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
761               range);
762             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
763             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
764               range);
765             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
766             p+=channels;
767             q+=quantum_info->pad;
768           }
769           break;
770         }
771         case 12:
772         {
773           register unsigned int
774             pixel;
775
776           range=GetQuantumRange(quantum_info->depth);
777           if (quantum_info->pack == MagickFalse)
778             {
779               for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
780               {
781                 switch (x % 3)
782                 {
783                   default:
784                   case 0:
785                   {
786                     pixel=(unsigned int) ScaleQuantumToAny(
787                       GetPixelRed(image,p),range);
788                     break;
789                   }
790                   case 1:
791                   {
792                     pixel=(unsigned int) ScaleQuantumToAny(
793                       GetPixelGreen(image,p),range);
794                     break;
795                   }
796                   case 2:
797                   {
798                     pixel=(unsigned int) ScaleQuantumToAny(
799                       GetPixelBlue(image,p),range);
800                     p+=channels;
801                     break;
802                   }
803                 }
804                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
805                 switch ((x+1) % 3)
806                 {
807                   default:
808                   case 0:
809                   {
810                     pixel=(unsigned int) ScaleQuantumToAny(
811                       GetPixelRed(image,p),range);
812                     break;
813                   }
814                   case 1:
815                   {
816                     pixel=(unsigned int) ScaleQuantumToAny(
817                       GetPixelGreen(image,p),range);
818                     break;
819                   }
820                   case 2:
821                   {
822                     pixel=(unsigned int) ScaleQuantumToAny(
823                       GetPixelBlue(image,p),range);
824                     p+=channels;
825                     break;
826                   }
827                 }
828                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
829                 q+=quantum_info->pad;
830               }
831               for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
832               {
833                 switch ((x+bit) % 3)
834                 {
835                   default:
836                   case 0:
837                   {
838                     pixel=(unsigned int) ScaleQuantumToAny(
839                       GetPixelRed(image,p),range);
840                     break;
841                   }
842                   case 1:
843                   {
844                     pixel=(unsigned int) ScaleQuantumToAny(
845                       GetPixelGreen(image,p),range);
846                     break;
847                   }
848                   case 2:
849                   {
850                     pixel=(unsigned int) ScaleQuantumToAny(
851                       GetPixelBlue(image,p),range);
852                     p+=channels;
853                     break;
854                   }
855                 }
856                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
857                 q+=quantum_info->pad;
858               }
859               if (bit != 0)
860                 p+=channels;
861               break;
862             }
863           if (quantum_info->quantum == 32UL)
864             {
865               for (x=0; x < (ssize_t) number_pixels; x++)
866               {
867                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
868                   range);
869                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
870                   q);
871                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
872                   range);
873                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
874                   q);
875                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
876                   range);
877                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
878                   q);
879                 p+=channels;
880                 q+=quantum_info->pad;
881               }
882               break;
883             }
884           for (x=0; x < (ssize_t) number_pixels; x++)
885           {
886             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
887               range);
888             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
889             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
890               range);
891             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
892             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
893               range);
894             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
895             p+=channels;
896             q+=quantum_info->pad;
897           }
898           break;
899         }
900         case 16:
901         {
902           register unsigned short
903             pixel;
904
905           if (quantum_info->format == FloatingPointQuantumFormat)
906             {
907               for (x=0; x < (ssize_t) number_pixels; x++)
908               {
909                 pixel=SinglePrecisionToHalf(QuantumScale*
910                   GetPixelBlue(image,p));
911                 q=PopShortPixel(endian,pixel,q);
912                 pixel=SinglePrecisionToHalf(QuantumScale*
913                   GetPixelGreen(image,p));
914                 q=PopShortPixel(endian,pixel,q);
915                 pixel=SinglePrecisionToHalf(QuantumScale*
916                   GetPixelRed(image,p));
917                 q=PopShortPixel(endian,pixel,q);
918                 p+=channels;
919                 q+=quantum_info->pad;
920               }
921               break;
922             }
923           for (x=0; x < (ssize_t) number_pixels; x++)
924           {
925             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
926             q=PopShortPixel(endian,pixel,q);
927             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
928             q=PopShortPixel(endian,pixel,q);
929             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
930             q=PopShortPixel(endian,pixel,q);
931             p+=channels;
932             q+=quantum_info->pad;
933           }
934           break;
935         }
936         case 32:
937         {
938           register unsigned int
939             pixel;
940
941           if (quantum_info->format == FloatingPointQuantumFormat)
942             {
943               for (x=0; x < (ssize_t) number_pixels; x++)
944               {
945                 q=PopFloatPixel(&quantum_state,(float)
946                   GetPixelRed(image,p),q);
947                 q=PopFloatPixel(&quantum_state,(float)
948                   GetPixelGreen(image,p),q);
949                 q=PopFloatPixel(&quantum_state,(float)
950                   GetPixelBlue(image,p),q);
951                 p+=channels;
952                 q+=quantum_info->pad;
953               }
954               break;
955             }
956           for (x=0; x < (ssize_t) number_pixels; x++)
957           {
958             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
959             q=PopLongPixel(endian,pixel,q);
960             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
961             q=PopLongPixel(endian,pixel,q);
962             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
963             q=PopLongPixel(endian,pixel,q);
964             p+=channels;
965             q+=quantum_info->pad;
966           }
967           break;
968         }
969         case 64:
970         {
971           if (quantum_info->format == FloatingPointQuantumFormat)
972             {
973               for (x=0; x < (ssize_t) number_pixels; x++)
974               {
975                 q=PopDoublePixel(&quantum_state,(double)
976                   GetPixelRed(image,p),q);
977                 q=PopDoublePixel(&quantum_state,(double)
978                   GetPixelGreen(image,p),q);
979                 q=PopDoublePixel(&quantum_state,(double)
980                   GetPixelBlue(image,p),q);
981                 p+=channels;
982                 q+=quantum_info->pad;
983               }
984               break;
985             }
986         }
987         default:
988         {
989           range=GetQuantumRange(quantum_info->depth);
990           for (x=0; x < (ssize_t) number_pixels; x++)
991           {
992             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
993               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
994             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
995               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
996             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
997               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
998             p+=channels;
999             q+=quantum_info->pad;
1000           }
1001           break;
1002         }
1003       }
1004       break;
1005     }
1006     case BGRAQuantum:
1007     case BGROQuantum:
1008     {
1009       switch (quantum_info->depth)
1010       {
1011         case 8:
1012         {
1013           register unsigned char
1014             pixel;
1015
1016           for (x=0; x < (ssize_t) number_pixels; x++)
1017           {
1018             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1019             q=PopCharPixel(pixel,q);
1020             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1021             q=PopCharPixel(pixel,q);
1022             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1023             q=PopCharPixel(pixel,q);
1024             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1025             q=PopCharPixel(pixel,q);
1026             p+=channels;
1027             q+=quantum_info->pad;
1028           }
1029           break;
1030         }
1031         case 10:
1032         {
1033           register unsigned int
1034             pixel;
1035
1036           range=GetQuantumRange(quantum_info->depth);
1037           if (quantum_info->pack == MagickFalse)
1038             {
1039               register ssize_t
1040                 i;
1041
1042               size_t
1043                 quantum;
1044
1045               ssize_t
1046                 n;
1047
1048               n=0;
1049               quantum=0;
1050               pixel=0;
1051               for (x=0; x < (ssize_t) number_pixels; x++)
1052               {
1053                 for (i=0; i < 4; i++)
1054                 {
1055                   switch (i)
1056                   {
1057                     case 0: quantum=GetPixelRed(image,p); break;
1058                     case 1: quantum=GetPixelGreen(image,p); break;
1059                     case 2: quantum=GetPixelBlue(image,p); break;
1060                     case 3: quantum=GetPixelAlpha(image,p); break;
1061                   }
1062                   switch (n % 3)
1063                   {
1064                     case 0:
1065                     {
1066                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1067                         range) << 22);
1068                       break;
1069                     }
1070                     case 1:
1071                     {
1072                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1073                         range) << 12);
1074                       break;
1075                     }
1076                     case 2:
1077                     {
1078                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1079                         range) << 2);
1080                       q=PopLongPixel(endian,pixel,q);
1081                       pixel=0;
1082                       break;
1083                     }
1084                   }
1085                   n++;
1086                 }
1087                 p+=channels;
1088                 q+=quantum_info->pad;
1089               }
1090               break;
1091             }
1092           if (quantum_info->quantum == 32UL)
1093             {
1094               for (x=0; x < (ssize_t) number_pixels; x++)
1095               {
1096                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
1097                   range);
1098                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1099                   q);
1100                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
1101                   range);
1102                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1103                   q);
1104                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
1105                   range);
1106                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1107                   q);
1108                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
1109                   range);
1110                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1111                   q);
1112                 p+=channels;
1113                 q+=quantum_info->pad;
1114               }
1115               break;
1116             }
1117           for (x=0; x < (ssize_t) number_pixels; x++)
1118           {
1119             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
1120               range);
1121             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1122             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
1123               range);
1124             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1125             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
1126               range);
1127             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1128             pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
1129               range);
1130             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1131             p+=channels;
1132             q+=quantum_info->pad;
1133           }
1134           break;
1135         }
1136         case 16:
1137         {
1138           register unsigned short
1139             pixel;
1140
1141           if (quantum_info->format == FloatingPointQuantumFormat)
1142             {
1143               for (x=0; x < (ssize_t) number_pixels; x++)
1144               {
1145                 pixel=SinglePrecisionToHalf(QuantumScale*
1146                   GetPixelBlue(image,p));
1147                 q=PopShortPixel(endian,pixel,q);
1148                 pixel=SinglePrecisionToHalf(QuantumScale*
1149                   GetPixelGreen(image,p));
1150                 q=PopShortPixel(endian,pixel,q);
1151                 pixel=SinglePrecisionToHalf(QuantumScale*
1152                   GetPixelRed(image,p));
1153                 q=PopShortPixel(endian,pixel,q);
1154                 pixel=SinglePrecisionToHalf(QuantumScale*
1155                   GetPixelAlpha(image,p));
1156                 q=PopShortPixel(endian,pixel,q);
1157                 p+=channels;
1158                 q+=quantum_info->pad;
1159               }
1160               break;
1161             }
1162           for (x=0; x < (ssize_t) number_pixels; x++)
1163           {
1164             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1165             q=PopShortPixel(endian,pixel,q);
1166             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1167             q=PopShortPixel(endian,pixel,q);
1168             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1169             q=PopShortPixel(endian,pixel,q);
1170             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1171             q=PopShortPixel(endian,pixel,q);
1172             p+=channels;
1173             q+=quantum_info->pad;
1174           }
1175           break;
1176         }
1177         case 32:
1178         {
1179           register unsigned int
1180             pixel;
1181
1182           if (quantum_info->format == FloatingPointQuantumFormat)
1183             {
1184               for (x=0; x < (ssize_t) number_pixels; x++)
1185               {
1186                 float
1187                   pixel;
1188
1189                 q=PopFloatPixel(&quantum_state,(float)
1190                   GetPixelRed(image,p),q);
1191                 q=PopFloatPixel(&quantum_state,(float)
1192                   GetPixelGreen(image,p),q);
1193                 q=PopFloatPixel(&quantum_state,(float)
1194                   GetPixelBlue(image,p),q);
1195                 pixel=(float) GetPixelAlpha(image,p);
1196                 q=PopFloatPixel(&quantum_state,pixel,q);
1197                 p+=channels;
1198                 q+=quantum_info->pad;
1199               }
1200               break;
1201             }
1202           for (x=0; x < (ssize_t) number_pixels; x++)
1203           {
1204             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1205             q=PopLongPixel(endian,pixel,q);
1206             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1207             q=PopLongPixel(endian,pixel,q);
1208             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1209             q=PopLongPixel(endian,pixel,q);
1210             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1211             q=PopLongPixel(endian,pixel,q);
1212             p+=channels;
1213             q+=quantum_info->pad;
1214           }
1215           break;
1216         }
1217         case 64:
1218         {
1219           if (quantum_info->format == FloatingPointQuantumFormat)
1220             {
1221               double
1222                 pixel;
1223
1224               for (x=0; x < (ssize_t) number_pixels; x++)
1225               {
1226                 q=PopDoublePixel(&quantum_state,(double)
1227                   GetPixelRed(image,p),q);
1228                 q=PopDoublePixel(&quantum_state,(double)
1229                   GetPixelGreen(image,p),q);
1230                 q=PopDoublePixel(&quantum_state,(double)
1231                   GetPixelBlue(image,p),q);
1232                 pixel=(double) GetPixelAlpha(image,p);
1233                 q=PopDoublePixel(&quantum_state,pixel,q);
1234                 p+=channels;
1235                 q+=quantum_info->pad;
1236               }
1237               break;
1238             }
1239         }
1240         default:
1241         {
1242           range=GetQuantumRange(quantum_info->depth);
1243           for (x=0; x < (ssize_t) number_pixels; x++)
1244           {
1245             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1246               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
1247             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1248               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
1249             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1250               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
1251             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1252               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
1253             p+=channels;
1254             q+=quantum_info->pad;
1255           }
1256           break;
1257         }
1258       }
1259       break;
1260     }
1261     case GrayQuantum:
1262     {
1263       switch (quantum_info->depth)
1264       {
1265         case 1:
1266         {
1267           register Quantum
1268             threshold;
1269
1270           register unsigned char
1271             black,
1272             white;
1273
1274           black=0x00;
1275           white=0x01;
1276           if (quantum_info->min_is_white != MagickFalse)
1277             {
1278               black=0x01;
1279               white=0x00;
1280             }
1281           threshold=(Quantum) (QuantumRange/2);
1282           for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
1283           {
1284             *q='\0';
1285             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 7;
1286             p+=channels;
1287             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 6;
1288             p+=channels;
1289             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 5;
1290             p+=channels;
1291             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 4;
1292             p+=channels;
1293             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 3;
1294             p+=channels;
1295             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 2;
1296             p+=channels;
1297             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 1;
1298             p+=channels;
1299             *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 0;
1300             p+=channels;
1301             q++;
1302           }
1303           if ((number_pixels % 8) != 0)
1304             {
1305               *q='\0';
1306               for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
1307               {
1308                 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) <<
1309                   bit;
1310                 p+=channels;
1311               }
1312               q++;
1313             }
1314           break;
1315         }
1316         case 4:
1317         {
1318           register unsigned char
1319             pixel;
1320
1321           for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
1322           {
1323             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1324             *q=(((pixel >> 4) & 0xf) << 4);
1325             p+=channels;
1326             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1327             *q|=pixel >> 4;
1328             p+=channels;
1329             q++;
1330           }
1331           if ((number_pixels % 2) != 0)
1332             {
1333               pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1334               *q=(((pixel >> 4) & 0xf) << 4);
1335               p+=channels;
1336               q++;
1337             }
1338           break;
1339         }
1340         case 8:
1341         {
1342           register unsigned char
1343             pixel;
1344
1345           for (x=0; x < (ssize_t) number_pixels; x++)
1346           {
1347             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1348             q=PopCharPixel(pixel,q);
1349             p+=channels;
1350             q+=quantum_info->pad;
1351           }
1352           break;
1353         }
1354         case 10:
1355         {
1356           range=GetQuantumRange(quantum_info->depth);
1357           if (quantum_info->pack == MagickFalse)
1358             {
1359               register unsigned int
1360                 pixel;
1361
1362               for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1363               {
1364                 pixel=(unsigned int) (
1365                   ScaleQuantumToAny(GetPixelIntensity(image,p+2*channels),range) << 22 |
1366                   ScaleQuantumToAny(GetPixelIntensity(image,p+channels),range) << 12 |
1367                   ScaleQuantumToAny(GetPixelIntensity(image,p),range) << 2);
1368                 q=PopLongPixel(endian,pixel,q);
1369                 p+=3*channels;
1370                 q+=quantum_info->pad;
1371               }
1372               if (x < (ssize_t) number_pixels)
1373                 {
1374                   pixel=0U;
1375                   if (x++ < (ssize_t) (number_pixels-1))
1376                     pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p+channels),
1377                   range) << 12;
1378                   if (x++ < (ssize_t) number_pixels)
1379                     pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p),
1380                       range) << 2;
1381                   q=PopLongPixel(endian,pixel,q);
1382                 }
1383               break;
1384             }
1385           for (x=0; x < (ssize_t) number_pixels; x++)
1386           {
1387             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1388               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1389             p+=channels;
1390             q+=quantum_info->pad;
1391           }
1392           break;
1393         }
1394         case 12:
1395         {
1396           register unsigned short
1397             pixel;
1398
1399           range=GetQuantumRange(quantum_info->depth);
1400           if (quantum_info->pack == MagickFalse)
1401             {
1402               for (x=0; x < (ssize_t) number_pixels; x++)
1403               {
1404                 pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1405                 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
1406                 p+=channels;
1407                 q+=quantum_info->pad;
1408               }
1409               break;
1410             }
1411           for (x=0; x < (ssize_t) number_pixels; x++)
1412           {
1413             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1414               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1415             p+=channels;
1416             q+=quantum_info->pad;
1417           }
1418           break;
1419         }
1420         case 16:
1421         {
1422           register unsigned short
1423             pixel;
1424
1425           if (quantum_info->format == FloatingPointQuantumFormat)
1426             {
1427               for (x=0; x < (ssize_t) number_pixels; x++)
1428               {
1429                 pixel=SinglePrecisionToHalf(QuantumScale*
1430                   GetPixelIntensity(image,p));
1431                 q=PopShortPixel(endian,pixel,q);
1432                 p+=channels;
1433                 q+=quantum_info->pad;
1434               }
1435               break;
1436             }
1437           for (x=0; x < (ssize_t) number_pixels; x++)
1438           {
1439             pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1440             q=PopShortPixel(endian,pixel,q);
1441             p+=channels;
1442             q+=quantum_info->pad;
1443           }
1444           break;
1445         }
1446         case 32:
1447         {
1448           register unsigned int
1449             pixel;
1450
1451           if (quantum_info->format == FloatingPointQuantumFormat)
1452             {
1453               for (x=0; x < (ssize_t) number_pixels; x++)
1454               {
1455                 float
1456                   pixel;
1457
1458                 pixel=(float) GetPixelIntensity(image,p);
1459                 q=PopFloatPixel(&quantum_state,pixel,q);
1460                 p+=channels;
1461                 q+=quantum_info->pad;
1462               }
1463               break;
1464             }
1465           for (x=0; x < (ssize_t) number_pixels; x++)
1466           {
1467             pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1468             q=PopLongPixel(endian,pixel,q);
1469             p+=channels;
1470             q+=quantum_info->pad;
1471           }
1472           break;
1473         }
1474         case 64:
1475         {
1476           if (quantum_info->format == FloatingPointQuantumFormat)
1477             {
1478               for (x=0; x < (ssize_t) number_pixels; x++)
1479               {
1480                 double
1481                   pixel;
1482
1483                 pixel=(double) GetPixelIntensity(image,p);
1484                 q=PopDoublePixel(&quantum_state,pixel,q);
1485                 p+=channels;
1486                 q+=quantum_info->pad;
1487               }
1488               break;
1489             }
1490         }
1491         default:
1492         {
1493           range=GetQuantumRange(quantum_info->depth);
1494           for (x=0; x < (ssize_t) number_pixels; x++)
1495           {
1496             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1497               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1498             p+=channels;
1499             q+=quantum_info->pad;
1500           }
1501           break;
1502         }
1503       }
1504       break;
1505     }
1506     case GrayAlphaQuantum:
1507     {
1508       switch (quantum_info->depth)
1509       {
1510         case 1:
1511         {
1512           register Quantum
1513             threshold;
1514
1515           register unsigned char
1516             black,
1517             pixel,
1518             white;
1519
1520           black=0x00;
1521           white=0x01;
1522           if (quantum_info->min_is_white == MagickFalse)
1523             {
1524               black=0x01;
1525               white=0x00;
1526             }
1527           threshold=(Quantum) (QuantumRange/2);
1528           for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
1529           {
1530             *q='\0';
1531             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 7;
1532             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1533               0x00 : 0x01);
1534             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
1535             p+=channels;
1536             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 5;
1537             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1538               0x00 : 0x01);
1539             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
1540             p+=channels;
1541             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 3;
1542             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1543               0x00 : 0x01);
1544             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
1545             p+=channels;
1546             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 1;
1547             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1548               0x00 : 0x01);
1549             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
1550             p+=channels;
1551             q++;
1552           }
1553           if ((number_pixels % 4) != 0)
1554             {
1555               *q='\0';
1556               for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
1557               {
1558                 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) <<
1559                   (7-bit);
1560                 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1561                   0x00 : 0x01);
1562                 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
1563                   (7-bit-1));
1564                 p+=channels;
1565               }
1566               q++;
1567             }
1568           break;
1569         }
1570         case 4:
1571         {
1572           register unsigned char
1573             pixel;
1574
1575           for (x=0; x < (ssize_t) number_pixels ; x++)
1576           {
1577             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1578             *q=(((pixel >> 4) & 0xf) << 4);
1579             pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
1580             *q|=pixel & 0xf;
1581             p+=channels;
1582             q++;
1583           }
1584           break;
1585         }
1586         case 8:
1587         {
1588           register unsigned char
1589             pixel;
1590
1591           for (x=0; x < (ssize_t) number_pixels; x++)
1592           {
1593             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1594             q=PopCharPixel(pixel,q);
1595             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1596             q=PopCharPixel(pixel,q);
1597             p+=channels;
1598             q+=quantum_info->pad;
1599           }
1600           break;
1601         }
1602         case 16:
1603         {
1604           register unsigned short
1605             pixel;
1606
1607           if (quantum_info->format == FloatingPointQuantumFormat)
1608             {
1609               for (x=0; x < (ssize_t) number_pixels; x++)
1610               {
1611                 pixel=SinglePrecisionToHalf(QuantumScale*
1612                   GetPixelIntensity(image,p));
1613                 q=PopShortPixel(endian,pixel,q);
1614                 pixel=SinglePrecisionToHalf(QuantumScale*
1615                   GetPixelAlpha(image,p));
1616                 q=PopShortPixel(endian,pixel,q);
1617                 p+=channels;
1618                 q+=quantum_info->pad;
1619               }
1620               break;
1621             }
1622           for (x=0; x < (ssize_t) number_pixels; x++)
1623           {
1624             pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1625             q=PopShortPixel(endian,pixel,q);
1626             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1627             q=PopShortPixel(endian,pixel,q);
1628             p+=channels;
1629             q+=quantum_info->pad;
1630           }
1631           break;
1632         }
1633         case 32:
1634         {
1635           register unsigned int
1636             pixel;
1637
1638           if (quantum_info->format == FloatingPointQuantumFormat)
1639             {
1640               for (x=0; x < (ssize_t) number_pixels; x++)
1641               {
1642                 float
1643                   pixel;
1644
1645                 pixel=(float) GetPixelIntensity(image,p);
1646                 q=PopFloatPixel(&quantum_state,pixel,q);
1647                 pixel=(float) (GetPixelAlpha(image,p));
1648                 q=PopFloatPixel(&quantum_state,pixel,q);
1649                 p+=channels;
1650                 q+=quantum_info->pad;
1651               }
1652               break;
1653             }
1654           for (x=0; x < (ssize_t) number_pixels; x++)
1655           {
1656             pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1657             q=PopLongPixel(endian,pixel,q);
1658             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1659             q=PopLongPixel(endian,pixel,q);
1660             p+=channels;
1661             q+=quantum_info->pad;
1662           }
1663           break;
1664         }
1665         case 64:
1666         {
1667           if (quantum_info->format == FloatingPointQuantumFormat)
1668             {
1669               for (x=0; x < (ssize_t) number_pixels; x++)
1670               {
1671                 double
1672                   pixel;
1673
1674                 pixel=(double) GetPixelIntensity(image,p);
1675                 q=PopDoublePixel(&quantum_state,pixel,q);
1676                 pixel=(double) (GetPixelAlpha(image,p));
1677                 q=PopDoublePixel(&quantum_state,pixel,q);
1678                 p+=channels;
1679                 q+=quantum_info->pad;
1680               }
1681               break;
1682             }
1683         }
1684         default:
1685         {
1686           range=GetQuantumRange(quantum_info->depth);
1687           for (x=0; x < (ssize_t) number_pixels; x++)
1688           {
1689             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1690               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1691             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1692               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
1693             p+=channels;
1694             q+=quantum_info->pad;
1695           }
1696           break;
1697         }
1698       }
1699       break;
1700     }
1701     case RedQuantum:
1702     case CyanQuantum:
1703     {
1704       switch (quantum_info->depth)
1705       {
1706         case 8:
1707         {
1708           register unsigned char
1709             pixel;
1710
1711           for (x=0; x < (ssize_t) number_pixels; x++)
1712           {
1713             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1714             q=PopCharPixel(pixel,q);
1715             p+=channels;
1716             q+=quantum_info->pad;
1717           }
1718           break;
1719         }
1720         case 16:
1721         {
1722           register unsigned short
1723             pixel;
1724
1725           if (quantum_info->format == FloatingPointQuantumFormat)
1726             {
1727               for (x=0; x < (ssize_t) number_pixels; x++)
1728               {
1729                 pixel=SinglePrecisionToHalf(QuantumScale*
1730                   GetPixelRed(image,p));
1731                 q=PopShortPixel(endian,pixel,q);
1732                 p+=channels;
1733                 q+=quantum_info->pad;
1734               }
1735               break;
1736             }
1737           for (x=0; x < (ssize_t) number_pixels; x++)
1738           {
1739             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1740             q=PopShortPixel(endian,pixel,q);
1741             p+=channels;
1742             q+=quantum_info->pad;
1743           }
1744           break;
1745         }
1746         case 32:
1747         {
1748           register unsigned int
1749             pixel;
1750
1751           if (quantum_info->format == FloatingPointQuantumFormat)
1752             {
1753               for (x=0; x < (ssize_t) number_pixels; x++)
1754               {
1755                 q=PopFloatPixel(&quantum_state,(float)
1756                   GetPixelRed(image,p),q);
1757                 p+=channels;
1758                 q+=quantum_info->pad;
1759               }
1760               break;
1761             }
1762           for (x=0; x < (ssize_t) number_pixels; x++)
1763           {
1764             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1765             q=PopLongPixel(endian,pixel,q);
1766             p+=channels;
1767             q+=quantum_info->pad;
1768           }
1769           break;
1770         }
1771         case 64:
1772         {
1773           if (quantum_info->format == FloatingPointQuantumFormat)
1774             {
1775               for (x=0; x < (ssize_t) number_pixels; x++)
1776               {
1777                 q=PopDoublePixel(&quantum_state,(double)
1778                   GetPixelRed(image,p),q);
1779                 p+=channels;
1780                 q+=quantum_info->pad;
1781               }
1782               break;
1783             }
1784         }
1785         default:
1786         {
1787           range=GetQuantumRange(quantum_info->depth);
1788           for (x=0; x < (ssize_t) number_pixels; x++)
1789           {
1790             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1791               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
1792             p+=channels;
1793             q+=quantum_info->pad;
1794           }
1795           break;
1796         }
1797       }
1798       break;
1799     }
1800     case GreenQuantum:
1801     case MagentaQuantum:
1802     {
1803       switch (quantum_info->depth)
1804       {
1805         case 8:
1806         {
1807           register unsigned char
1808             pixel;
1809
1810           for (x=0; x < (ssize_t) number_pixels; x++)
1811           {
1812             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1813             q=PopCharPixel(pixel,q);
1814             p+=channels;
1815             q+=quantum_info->pad;
1816           }
1817           break;
1818         }
1819         case 16:
1820         {
1821           register unsigned short
1822             pixel;
1823
1824           if (quantum_info->format == FloatingPointQuantumFormat)
1825             {
1826               for (x=0; x < (ssize_t) number_pixels; x++)
1827               {
1828                 pixel=SinglePrecisionToHalf(QuantumScale*
1829                   GetPixelGreen(image,p));
1830                 q=PopShortPixel(endian,pixel,q);
1831                 p+=channels;
1832                 q+=quantum_info->pad;
1833               }
1834               break;
1835             }
1836           for (x=0; x < (ssize_t) number_pixels; x++)
1837           {
1838             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1839             q=PopShortPixel(endian,pixel,q);
1840             p+=channels;
1841             q+=quantum_info->pad;
1842           }
1843           break;
1844         }
1845         case 32:
1846         {
1847           register unsigned int
1848             pixel;
1849
1850           if (quantum_info->format == FloatingPointQuantumFormat)
1851             {
1852               for (x=0; x < (ssize_t) number_pixels; x++)
1853               {
1854                 q=PopFloatPixel(&quantum_state,(float)
1855                   GetPixelGreen(image,p),q);
1856                 p+=channels;
1857                 q+=quantum_info->pad;
1858               }
1859               break;
1860             }
1861           for (x=0; x < (ssize_t) number_pixels; x++)
1862           {
1863             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1864             q=PopLongPixel(endian,pixel,q);
1865             p+=channels;
1866             q+=quantum_info->pad;
1867           }
1868           break;
1869         }
1870         case 64:
1871         {
1872           if (quantum_info->format == FloatingPointQuantumFormat)
1873             {
1874               for (x=0; x < (ssize_t) number_pixels; x++)
1875               {
1876                 q=PopDoublePixel(&quantum_state,(double)
1877                   GetPixelGreen(image,p),q);
1878                 p+=channels;
1879                 q+=quantum_info->pad;
1880               }
1881               break;
1882             }
1883         }
1884         default:
1885         {
1886           range=GetQuantumRange(quantum_info->depth);
1887           for (x=0; x < (ssize_t) number_pixels; x++)
1888           {
1889             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1890               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
1891             p+=channels;
1892             q+=quantum_info->pad;
1893           }
1894           break;
1895         }
1896       }
1897       break;
1898     }
1899     case BlueQuantum:
1900     case YellowQuantum:
1901     {
1902       switch (quantum_info->depth)
1903       {
1904         case 8:
1905         {
1906           register unsigned char
1907             pixel;
1908
1909           for (x=0; x < (ssize_t) number_pixels; x++)
1910           {
1911             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1912             q=PopCharPixel(pixel,q);
1913             p+=channels;
1914             q+=quantum_info->pad;
1915           }
1916           break;
1917         }
1918         case 16:
1919         {
1920           register unsigned short
1921             pixel;
1922
1923           if (quantum_info->format == FloatingPointQuantumFormat)
1924             {
1925               for (x=0; x < (ssize_t) number_pixels; x++)
1926               {
1927                 pixel=SinglePrecisionToHalf(QuantumScale*
1928                   GetPixelBlue(image,p));
1929                 q=PopShortPixel(endian,pixel,q);
1930                 p+=channels;
1931                 q+=quantum_info->pad;
1932               }
1933               break;
1934             }
1935           for (x=0; x < (ssize_t) number_pixels; x++)
1936           {
1937             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1938             q=PopShortPixel(endian,pixel,q);
1939             p+=channels;
1940             q+=quantum_info->pad;
1941           }
1942           break;
1943         }
1944         case 32:
1945         {
1946           register unsigned int
1947             pixel;
1948
1949           if (quantum_info->format == FloatingPointQuantumFormat)
1950             {
1951               for (x=0; x < (ssize_t) number_pixels; x++)
1952               {
1953                 q=PopFloatPixel(&quantum_state,(float)
1954                   GetPixelBlue(image,p),q);
1955                 p+=channels;
1956                 q+=quantum_info->pad;
1957               }
1958               break;
1959             }
1960           for (x=0; x < (ssize_t) number_pixels; x++)
1961           {
1962             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1963             q=PopLongPixel(endian,pixel,q);
1964             p+=channels;
1965             q+=quantum_info->pad;
1966           }
1967           break;
1968         }
1969         case 64:
1970         {
1971           if (quantum_info->format == FloatingPointQuantumFormat)
1972             {
1973               for (x=0; x < (ssize_t) number_pixels; x++)
1974               {
1975                 q=PopDoublePixel(&quantum_state,(double)
1976                   GetPixelBlue(image,p),q);
1977                 p+=channels;
1978                 q+=quantum_info->pad;
1979               }
1980               break;
1981             }
1982         }
1983         default:
1984         {
1985           range=GetQuantumRange(quantum_info->depth);
1986           for (x=0; x < (ssize_t) number_pixels; x++)
1987           {
1988             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1989               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
1990             p+=channels;
1991             q+=quantum_info->pad;
1992           }
1993           break;
1994         }
1995       }
1996       break;
1997     }
1998     case AlphaQuantum:
1999     {
2000       switch (quantum_info->depth)
2001       {
2002         case 8:
2003         {
2004           register unsigned char
2005             pixel;
2006
2007           for (x=0; x < (ssize_t) number_pixels; x++)
2008           {
2009             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2010             q=PopCharPixel(pixel,q);
2011             p+=channels;
2012             q+=quantum_info->pad;
2013           }
2014           break;
2015         }
2016         case 16:
2017         {
2018           register unsigned short
2019             pixel;
2020
2021           if (quantum_info->format == FloatingPointQuantumFormat)
2022             {
2023               for (x=0; x < (ssize_t) number_pixels; x++)
2024               {
2025                 pixel=SinglePrecisionToHalf(QuantumScale*
2026                   GetPixelAlpha(image,p));
2027                 q=PopShortPixel(endian,pixel,q);
2028                 p+=channels;
2029                 q+=quantum_info->pad;
2030               }
2031               break;
2032             }
2033           for (x=0; x < (ssize_t) number_pixels; x++)
2034           {
2035             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2036             q=PopShortPixel(endian,pixel,q);
2037             p+=channels;
2038             q+=quantum_info->pad;
2039           }
2040           break;
2041         }
2042         case 32:
2043         {
2044           register unsigned int
2045             pixel;
2046
2047           if (quantum_info->format == FloatingPointQuantumFormat)
2048             {
2049               for (x=0; x < (ssize_t) number_pixels; x++)
2050               {
2051                 float
2052                   pixel;
2053
2054                 pixel=(float) GetPixelAlpha(image,p);
2055                 q=PopFloatPixel(&quantum_state,pixel,q);
2056                 p+=channels;
2057                 q+=quantum_info->pad;
2058               }
2059               break;
2060             }
2061           for (x=0; x < (ssize_t) number_pixels; x++)
2062           {
2063             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2064             q=PopLongPixel(endian,pixel,q);
2065             p+=channels;
2066             q+=quantum_info->pad;
2067           }
2068           break;
2069         }
2070         case 64:
2071         {
2072           if (quantum_info->format == FloatingPointQuantumFormat)
2073             {
2074               for (x=0; x < (ssize_t) number_pixels; x++)
2075               {
2076                 double
2077                   pixel;
2078
2079                 pixel=(double) (GetPixelAlpha(image,p));
2080                 q=PopDoublePixel(&quantum_state,pixel,q);
2081                 p+=channels;
2082                 q+=quantum_info->pad;
2083               }
2084               break;
2085             }
2086         }
2087         default:
2088         {
2089           range=GetQuantumRange(quantum_info->depth);
2090           for (x=0; x < (ssize_t) number_pixels; x++)
2091           {
2092             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2093               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2094             p+=channels;
2095             q+=quantum_info->pad;
2096           }
2097           break;
2098         }
2099       }
2100       break;
2101     }
2102     case OpacityQuantum:
2103     {
2104       switch (quantum_info->depth)
2105       {
2106         case 8:
2107         {
2108           register unsigned char
2109             pixel;
2110
2111           for (x=0; x < (ssize_t) number_pixels; x++)
2112           {
2113             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2114             q=PopCharPixel(pixel,q);
2115             p+=channels;
2116             q+=quantum_info->pad;
2117           }
2118           break;
2119         }
2120         case 16:
2121         {
2122           register unsigned short
2123             pixel;
2124
2125           if (quantum_info->format == FloatingPointQuantumFormat)
2126             {
2127               for (x=0; x < (ssize_t) number_pixels; x++)
2128               {
2129                 pixel=SinglePrecisionToHalf(QuantumScale*
2130                   GetPixelAlpha(image,p));
2131                 q=PopShortPixel(endian,pixel,q);
2132                 p+=channels;
2133                 q+=quantum_info->pad;
2134               }
2135               break;
2136             }
2137           for (x=0; x < (ssize_t) number_pixels; x++)
2138           {
2139             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2140             q=PopShortPixel(endian,pixel,q);
2141             p+=channels;
2142             q+=quantum_info->pad;
2143           }
2144           break;
2145         }
2146         case 32:
2147         {
2148           register unsigned int
2149             pixel;
2150
2151           if (quantum_info->format == FloatingPointQuantumFormat)
2152             {
2153               for (x=0; x < (ssize_t) number_pixels; x++)
2154               {
2155                 q=PopFloatPixel(&quantum_state,(float)
2156                   GetPixelAlpha(image,p),q);
2157                 p+=channels;
2158                 q+=quantum_info->pad;
2159               }
2160               break;
2161             }
2162           for (x=0; x < (ssize_t) number_pixels; x++)
2163           {
2164             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2165             q=PopLongPixel(endian,pixel,q);
2166             p+=channels;
2167             q+=quantum_info->pad;
2168           }
2169           break;
2170         }
2171         case 64:
2172         {
2173           if (quantum_info->format == FloatingPointQuantumFormat)
2174             {
2175               for (x=0; x < (ssize_t) number_pixels; x++)
2176               {
2177                 q=PopDoublePixel(&quantum_state,(double)
2178                   GetPixelAlpha(image,p),q);
2179                 p+=channels;
2180                 q+=quantum_info->pad;
2181               }
2182               break;
2183             }
2184         }
2185         default:
2186         {
2187           range=GetQuantumRange(quantum_info->depth);
2188           for (x=0; x < (ssize_t) number_pixels; x++)
2189           {
2190             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2191               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2192             p+=channels;
2193             q+=quantum_info->pad;
2194           }
2195           break;
2196         }
2197       }
2198       break;
2199     }
2200     case BlackQuantum:
2201     {
2202       if (image->colorspace != CMYKColorspace)
2203         {
2204           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2205             "ColorSeparatedImageRequired","`%s'",image->filename);
2206           return(extent);
2207         }
2208       switch (quantum_info->depth)
2209       {
2210         case 8:
2211         {
2212           register unsigned char
2213             pixel;
2214
2215           for (x=0; x < (ssize_t) number_pixels; x++)
2216           {
2217             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2218             q=PopCharPixel(pixel,q);
2219             p+=channels;
2220             q+=quantum_info->pad;
2221           }
2222           break;
2223         }
2224         case 16:
2225         {
2226           register unsigned short
2227             pixel;
2228
2229           if (quantum_info->format == FloatingPointQuantumFormat)
2230             {
2231               for (x=0; x < (ssize_t) number_pixels; x++)
2232               {
2233                 pixel=SinglePrecisionToHalf(QuantumScale*
2234                   GetPixelBlack(image,p));
2235                 q=PopShortPixel(endian,pixel,q);
2236                 p+=channels;
2237                 q+=quantum_info->pad;
2238               }
2239               break;
2240             }
2241           for (x=0; x < (ssize_t) number_pixels; x++)
2242           {
2243             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2244             q=PopShortPixel(endian,pixel,q);
2245             p+=channels;
2246             q+=quantum_info->pad;
2247           }
2248           break;
2249         }
2250         case 32:
2251         {
2252           register unsigned int
2253             pixel;
2254
2255           if (quantum_info->format == FloatingPointQuantumFormat)
2256             {
2257               for (x=0; x < (ssize_t) number_pixels; x++)
2258               {
2259                 q=PopFloatPixel(&quantum_state,(float)
2260                   GetPixelBlack(image,p),q);
2261                 p+=channels;
2262                 q+=quantum_info->pad;
2263               }
2264               break;
2265             }
2266           for (x=0; x < (ssize_t) number_pixels; x++)
2267           {
2268             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2269             q=PopLongPixel(endian,pixel,q);
2270             p+=channels;
2271             q+=quantum_info->pad;
2272           }
2273           break;
2274         }
2275         case 64:
2276         {
2277           if (quantum_info->format == FloatingPointQuantumFormat)
2278             {
2279               for (x=0; x < (ssize_t) number_pixels; x++)
2280               {
2281                 q=PopDoublePixel(&quantum_state,(double)
2282                   GetPixelBlack(image,p),q);
2283                 p+=channels;
2284                 q+=quantum_info->pad;
2285               }
2286               break;
2287             }
2288         }
2289         default:
2290         {
2291           range=GetQuantumRange(quantum_info->depth);
2292           for (x=0; x < (ssize_t) number_pixels; x++)
2293           {
2294             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2295               ScaleQuantumToAny((Quantum) GetPixelBlack(image,p),range),q);
2296             p+=channels;
2297             q+=quantum_info->pad;
2298           }
2299           break;
2300         }
2301       }
2302       break;
2303     }
2304     case RGBQuantum:
2305     case CbYCrQuantum:
2306     {
2307       switch (quantum_info->depth)
2308       {
2309         case 8:
2310         {
2311           for (x=0; x < (ssize_t) number_pixels; x++)
2312           {
2313             q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
2314             q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
2315             q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
2316             p+=channels;
2317             q+=quantum_info->pad;
2318           }
2319           break;
2320         }
2321         case 10:
2322         {
2323           register unsigned int
2324             pixel;
2325
2326           range=GetQuantumRange(quantum_info->depth);
2327           if (quantum_info->pack == MagickFalse)
2328             {
2329               for (x=0; x < (ssize_t) number_pixels; x++)
2330               {
2331                 pixel=(unsigned int) (
2332                   ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
2333                   ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
2334                   ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
2335                 q=PopLongPixel(endian,pixel,q);
2336                 p+=channels;
2337                 q+=quantum_info->pad;
2338               }
2339               break;
2340             }
2341           if (quantum_info->quantum == 32UL)
2342             {
2343               for (x=0; x < (ssize_t) number_pixels; x++)
2344               {
2345                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2346                   range);
2347                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2348                   q);
2349                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2350                   range);
2351                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2352                   q);
2353                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2354                   range);
2355                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2356                   q);
2357                 p+=channels;
2358                 q+=quantum_info->pad;
2359               }
2360               break;
2361             }
2362           for (x=0; x < (ssize_t) number_pixels; x++)
2363           {
2364             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2365               range);
2366             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2367             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2368               range);
2369             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2370             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2371               range);
2372             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2373             p+=channels;
2374             q+=quantum_info->pad;
2375           }
2376           break;
2377         }
2378         case 12:
2379         {
2380           register unsigned int
2381             pixel;
2382
2383           range=GetQuantumRange(quantum_info->depth);
2384           if (quantum_info->pack == MagickFalse)
2385             {
2386               for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
2387               {
2388                 switch (x % 3)
2389                 {
2390                   default:
2391                   case 0:
2392                   {
2393                     pixel=(unsigned int) ScaleQuantumToAny(
2394                       GetPixelRed(image,p),range);
2395                     break;
2396                   }
2397                   case 1:
2398                   {
2399                     pixel=(unsigned int) ScaleQuantumToAny(
2400                       GetPixelGreen(image,p),range);
2401                     break;
2402                   }
2403                   case 2:
2404                   {
2405                     pixel=(unsigned int) ScaleQuantumToAny(
2406                       GetPixelBlue(image,p),range);
2407                     p+=channels;
2408                     break;
2409                   }
2410                 }
2411                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2412                 switch ((x+1) % 3)
2413                 {
2414                   default:
2415                   case 0:
2416                   {
2417                     pixel=(unsigned int) ScaleQuantumToAny(
2418                       GetPixelRed(image,p),range);
2419                     break;
2420                   }
2421                   case 1:
2422                   {
2423                     pixel=(unsigned int) ScaleQuantumToAny(
2424                       GetPixelGreen(image,p),range);
2425                     break;
2426                   }
2427                   case 2:
2428                   {
2429                     pixel=(unsigned int) ScaleQuantumToAny(
2430                       GetPixelBlue(image,p),range);
2431                     p+=channels;
2432                     break;
2433                   }
2434                 }
2435                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2436                 q+=quantum_info->pad;
2437               }
2438               for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
2439               {
2440                 switch ((x+bit) % 3)
2441                 {
2442                   default:
2443                   case 0:
2444                   {
2445                     pixel=(unsigned int) ScaleQuantumToAny(
2446                       GetPixelRed(image,p),range);
2447                     break;
2448                   }
2449                   case 1:
2450                   {
2451                     pixel=(unsigned int) ScaleQuantumToAny(
2452                       GetPixelGreen(image,p),range);
2453                     break;
2454                   }
2455                   case 2:
2456                   {
2457                     pixel=(unsigned int) ScaleQuantumToAny(
2458                       GetPixelBlue(image,p),range);
2459                     p+=channels;
2460                     break;
2461                   }
2462                 }
2463                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2464                 q+=quantum_info->pad;
2465               }
2466               if (bit != 0)
2467                 p+=channels;
2468               break;
2469             }
2470           if (quantum_info->quantum == 32UL)
2471             {
2472               for (x=0; x < (ssize_t) number_pixels; x++)
2473               {
2474                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2475                   range);
2476                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2477                   q);
2478                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2479                   range);
2480                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2481                   q);
2482                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2483                   range);
2484                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2485                   q);
2486                 p+=channels;
2487                 q+=quantum_info->pad;
2488               }
2489               break;
2490             }
2491           for (x=0; x < (ssize_t) number_pixels; x++)
2492           {
2493             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2494               range);
2495             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2496             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2497               range);
2498             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2499             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2500               range);
2501             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2502             p+=channels;
2503             q+=quantum_info->pad;
2504           }
2505           break;
2506         }
2507         case 16:
2508         {
2509           register unsigned short
2510             pixel;
2511
2512           if (quantum_info->format == FloatingPointQuantumFormat)
2513             {
2514               for (x=0; x < (ssize_t) number_pixels; x++)
2515               {
2516                 pixel=SinglePrecisionToHalf(QuantumScale*
2517                   GetPixelRed(image,p));
2518                 q=PopShortPixel(endian,pixel,q);
2519                 pixel=SinglePrecisionToHalf(QuantumScale*
2520                   GetPixelGreen(image,p));
2521                 q=PopShortPixel(endian,pixel,q);
2522                 pixel=SinglePrecisionToHalf(QuantumScale*
2523                   GetPixelBlue(image,p));
2524                 q=PopShortPixel(endian,pixel,q);
2525                 p+=channels;
2526                 q+=quantum_info->pad;
2527               }
2528               break;
2529             }
2530           for (x=0; x < (ssize_t) number_pixels; x++)
2531           {
2532             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2533             q=PopShortPixel(endian,pixel,q);
2534             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2535             q=PopShortPixel(endian,pixel,q);
2536             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2537             q=PopShortPixel(endian,pixel,q);
2538             p+=channels;
2539             q+=quantum_info->pad;
2540           }
2541           break;
2542         }
2543         case 32:
2544         {
2545           register unsigned int
2546             pixel;
2547
2548           if (quantum_info->format == FloatingPointQuantumFormat)
2549             {
2550               for (x=0; x < (ssize_t) number_pixels; x++)
2551               {
2552                 q=PopFloatPixel(&quantum_state,(float)
2553                   GetPixelRed(image,p),q);
2554                 q=PopFloatPixel(&quantum_state,(float)
2555                   GetPixelGreen(image,p),q);
2556                 q=PopFloatPixel(&quantum_state,(float)
2557                   GetPixelBlue(image,p),q);
2558                 p+=channels;
2559                 q+=quantum_info->pad;
2560               }
2561               break;
2562             }
2563           for (x=0; x < (ssize_t) number_pixels; x++)
2564           {
2565             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2566             q=PopLongPixel(endian,pixel,q);
2567             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2568             q=PopLongPixel(endian,pixel,q);
2569             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2570             q=PopLongPixel(endian,pixel,q);
2571             p+=channels;
2572             q+=quantum_info->pad;
2573           }
2574           break;
2575         }
2576         case 64:
2577         {
2578           if (quantum_info->format == FloatingPointQuantumFormat)
2579             {
2580               for (x=0; x < (ssize_t) number_pixels; x++)
2581               {
2582                 q=PopDoublePixel(&quantum_state,(double)
2583                   GetPixelRed(image,p),q);
2584                 q=PopDoublePixel(&quantum_state,(double)
2585                   GetPixelGreen(image,p),q);
2586                 q=PopDoublePixel(&quantum_state,(double)
2587                   GetPixelBlue(image,p),q);
2588                 p+=channels;
2589                 q+=quantum_info->pad;
2590               }
2591               break;
2592             }
2593         }
2594         default:
2595         {
2596           range=GetQuantumRange(quantum_info->depth);
2597           for (x=0; x < (ssize_t) number_pixels; x++)
2598           {
2599             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2600               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2601             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2602               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2603             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2604               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2605             p+=channels;
2606             q+=quantum_info->pad;
2607           }
2608           break;
2609         }
2610       }
2611       break;
2612     }
2613     case RGBAQuantum:
2614     case RGBOQuantum:
2615     case CbYCrAQuantum:
2616     {
2617       switch (quantum_info->depth)
2618       {
2619         case 8:
2620         {
2621           register unsigned char
2622             pixel;
2623
2624           for (x=0; x < (ssize_t) number_pixels; x++)
2625           {
2626             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2627             q=PopCharPixel(pixel,q);
2628             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2629             q=PopCharPixel(pixel,q);
2630             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2631             q=PopCharPixel(pixel,q);
2632             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2633             q=PopCharPixel(pixel,q);
2634             p+=channels;
2635             q+=quantum_info->pad;
2636           }
2637           break;
2638         }
2639         case 10:
2640         {
2641           register unsigned int
2642             pixel;
2643
2644           range=GetQuantumRange(quantum_info->depth);
2645           if (quantum_info->pack == MagickFalse)
2646             {
2647               register ssize_t
2648                 i;
2649
2650               size_t
2651                 quantum;
2652
2653               ssize_t
2654                 n;
2655
2656               n=0;
2657               quantum=0;
2658               pixel=0;
2659               for (x=0; x < (ssize_t) number_pixels; x++)
2660               {
2661                 for (i=0; i < 4; i++)
2662                 {
2663                   switch (i)
2664                   {
2665                     case 0: quantum=GetPixelRed(image,p); break;
2666                     case 1: quantum=GetPixelGreen(image,p); break;
2667                     case 2: quantum=GetPixelBlue(image,p); break;
2668                     case 3: quantum=GetPixelAlpha(image,p); break;
2669                   }
2670                   switch (n % 3)
2671                   {
2672                     case 0:
2673                     {
2674                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2675                         range) << 22);
2676                       break;
2677                     }
2678                     case 1:
2679                     {
2680                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2681                         range) << 12);
2682                       break;
2683                     }
2684                     case 2:
2685                     {
2686                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2687                         range) << 2);
2688                       q=PopLongPixel(endian,pixel,q);
2689                       pixel=0;
2690                       break;
2691                     }
2692                   }
2693                   n++;
2694                 }
2695                 p+=channels;
2696                 q+=quantum_info->pad;
2697               }
2698               break;
2699             }
2700           if (quantum_info->quantum == 32UL)
2701             {
2702               for (x=0; x < (ssize_t) number_pixels; x++)
2703               {
2704                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2705                   range);
2706                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2707                   q);
2708                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2709                   range);
2710                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2711                   q);
2712                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2713                   range);
2714                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2715                   q);
2716                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2717                   range);
2718                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2719                   q);
2720                 p+=channels;
2721                 q+=quantum_info->pad;
2722               }
2723               break;
2724             }
2725           for (x=0; x < (ssize_t) number_pixels; x++)
2726           {
2727             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
2728             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2729             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2730               range);
2731             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2732             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
2733             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2734             pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2735               range);
2736             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2737             p+=channels;
2738             q+=quantum_info->pad;
2739           }
2740           break;
2741         }
2742         case 16:
2743         {
2744           register unsigned short
2745             pixel;
2746
2747           if (quantum_info->format == FloatingPointQuantumFormat)
2748             {
2749               for (x=0; x < (ssize_t) number_pixels; x++)
2750               {
2751                 pixel=SinglePrecisionToHalf(QuantumScale*
2752                   GetPixelRed(image,p));
2753                 q=PopShortPixel(endian,pixel,q);
2754                 pixel=SinglePrecisionToHalf(QuantumScale*
2755                   GetPixelGreen(image,p));
2756                 q=PopShortPixel(endian,pixel,q);
2757                 pixel=SinglePrecisionToHalf(QuantumScale*
2758                   GetPixelBlue(image,p));
2759                 q=PopShortPixel(endian,pixel,q);
2760                 pixel=SinglePrecisionToHalf(QuantumScale*
2761                   GetPixelAlpha(image,p));
2762                 q=PopShortPixel(endian,pixel,q);
2763                 p+=channels;
2764                 q+=quantum_info->pad;
2765               }
2766               break;
2767             }
2768           for (x=0; x < (ssize_t) number_pixels; x++)
2769           {
2770             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2771             q=PopShortPixel(endian,pixel,q);
2772             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2773             q=PopShortPixel(endian,pixel,q);
2774             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2775             q=PopShortPixel(endian,pixel,q);
2776             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2777             q=PopShortPixel(endian,pixel,q);
2778             p+=channels;
2779             q+=quantum_info->pad;
2780           }
2781           break;
2782         }
2783         case 32:
2784         {
2785           register unsigned int
2786             pixel;
2787
2788           if (quantum_info->format == FloatingPointQuantumFormat)
2789             {
2790               for (x=0; x < (ssize_t) number_pixels; x++)
2791               {
2792                 float
2793                   pixel;
2794
2795                 q=PopFloatPixel(&quantum_state,(float)
2796                   GetPixelRed(image,p),q);
2797                 q=PopFloatPixel(&quantum_state,(float)
2798                   GetPixelGreen(image,p),q);
2799                 q=PopFloatPixel(&quantum_state,(float)
2800                   GetPixelBlue(image,p),q);
2801                 pixel=(float) GetPixelAlpha(image,p);
2802                 q=PopFloatPixel(&quantum_state,pixel,q);
2803                 p+=channels;
2804                 q+=quantum_info->pad;
2805               }
2806               break;
2807             }
2808           for (x=0; x < (ssize_t) number_pixels; x++)
2809           {
2810             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2811             q=PopLongPixel(endian,pixel,q);
2812             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2813             q=PopLongPixel(endian,pixel,q);
2814             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2815             q=PopLongPixel(endian,pixel,q);
2816             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2817             q=PopLongPixel(endian,pixel,q);
2818             p+=channels;
2819             q+=quantum_info->pad;
2820           }
2821           break;
2822         }
2823         case 64:
2824         {
2825           if (quantum_info->format == FloatingPointQuantumFormat)
2826             {
2827               double
2828                 pixel;
2829
2830               for (x=0; x < (ssize_t) number_pixels; x++)
2831               {
2832                 q=PopDoublePixel(&quantum_state,(double)
2833                   GetPixelRed(image,p),q);
2834                 q=PopDoublePixel(&quantum_state,(double)
2835                   GetPixelGreen(image,p),q);
2836                 q=PopDoublePixel(&quantum_state,(double)
2837                   GetPixelBlue(image,p),q);
2838                 pixel=(double) GetPixelAlpha(image,p);
2839                 q=PopDoublePixel(&quantum_state,pixel,q);
2840                 p+=channels;
2841                 q+=quantum_info->pad;
2842               }
2843               break;
2844             }
2845         }
2846         default:
2847         {
2848           range=GetQuantumRange(quantum_info->depth);
2849           for (x=0; x < (ssize_t) number_pixels; x++)
2850           {
2851             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2852               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2853             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2854               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2855             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2856               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2857             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2858               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2859             p+=channels;
2860             q+=quantum_info->pad;
2861           }
2862           break;
2863         }
2864       }
2865       break;
2866     }
2867     case CMYKQuantum:
2868     {
2869       if (image->colorspace != CMYKColorspace)
2870         {
2871           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2872             "ColorSeparatedImageRequired","`%s'",image->filename);
2873           return(extent);
2874         }
2875       switch (quantum_info->depth)
2876       {
2877         case 8:
2878         {
2879           register unsigned char
2880             pixel;
2881
2882           for (x=0; x < (ssize_t) number_pixels; x++)
2883           {
2884             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2885             q=PopCharPixel(pixel,q);
2886             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2887             q=PopCharPixel(pixel,q);
2888             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2889             q=PopCharPixel(pixel,q);
2890             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2891             q=PopCharPixel(pixel,q);
2892             p+=channels;
2893             q+=quantum_info->pad;
2894           }
2895           break;
2896         }
2897         case 16:
2898         {
2899           register unsigned short
2900             pixel;
2901
2902           if (quantum_info->format == FloatingPointQuantumFormat)
2903             {
2904               for (x=0; x < (ssize_t) number_pixels; x++)
2905               {
2906                 pixel=SinglePrecisionToHalf(QuantumScale*
2907                   GetPixelRed(image,p));
2908                 q=PopShortPixel(endian,pixel,q);
2909                 pixel=SinglePrecisionToHalf(QuantumScale*
2910                   GetPixelGreen(image,p));
2911                 q=PopShortPixel(endian,pixel,q);
2912                 pixel=SinglePrecisionToHalf(QuantumScale*
2913                   GetPixelBlue(image,p));
2914                 q=PopShortPixel(endian,pixel,q);
2915                 pixel=SinglePrecisionToHalf(QuantumScale*
2916                   GetPixelBlack(image,p));
2917                 q=PopShortPixel(endian,pixel,q);
2918                 p+=channels;
2919                 q+=quantum_info->pad;
2920               }
2921               break;
2922             }
2923           for (x=0; x < (ssize_t) number_pixels; x++)
2924           {
2925             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2926             q=PopShortPixel(endian,pixel,q);
2927             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2928             q=PopShortPixel(endian,pixel,q);
2929             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2930             q=PopShortPixel(endian,pixel,q);
2931             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2932             q=PopShortPixel(endian,pixel,q);
2933             p+=channels;
2934             q+=quantum_info->pad;
2935           }
2936           break;
2937         }
2938         case 32:
2939         {
2940           register unsigned int
2941             pixel;
2942
2943           if (quantum_info->format == FloatingPointQuantumFormat)
2944             {
2945               for (x=0; x < (ssize_t) number_pixels; x++)
2946               {
2947                 q=PopFloatPixel(&quantum_state,(float)
2948                   GetPixelRed(image,p),q);
2949                 q=PopFloatPixel(&quantum_state,(float)
2950                   GetPixelGreen(image,p),q);
2951                 q=PopFloatPixel(&quantum_state,(float)
2952                   GetPixelBlue(image,p),q);
2953                 q=PopFloatPixel(&quantum_state,(float)
2954                   GetPixelBlack(image,p),q);
2955                 p+=channels;
2956                 q+=quantum_info->pad;
2957               }
2958               break;
2959             }
2960           for (x=0; x < (ssize_t) number_pixels; x++)
2961           {
2962             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2963             q=PopLongPixel(endian,pixel,q);
2964             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2965             q=PopLongPixel(endian,pixel,q);
2966             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2967             q=PopLongPixel(endian,pixel,q);
2968             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2969             q=PopLongPixel(endian,pixel,q);
2970             p+=channels;
2971             q+=quantum_info->pad;
2972           }
2973           break;
2974         }
2975         case 64:
2976         {
2977           if (quantum_info->format == FloatingPointQuantumFormat)
2978             {
2979               for (x=0; x < (ssize_t) number_pixels; x++)
2980               {
2981                 q=PopDoublePixel(&quantum_state,(double)
2982                   GetPixelRed(image,p),q);
2983                 q=PopDoublePixel(&quantum_state,(double)
2984                   GetPixelGreen(image,p),q);
2985                 q=PopDoublePixel(&quantum_state,(double)
2986                   GetPixelBlue(image,p),q);
2987                 q=PopDoublePixel(&quantum_state,(double)
2988                   GetPixelBlack(image,p),q);
2989                 p+=channels;
2990                 q+=quantum_info->pad;
2991               }
2992               break;
2993             }
2994         }
2995         default:
2996         {
2997           range=GetQuantumRange(quantum_info->depth);
2998           for (x=0; x < (ssize_t) number_pixels; x++)
2999           {
3000             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3001               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
3002             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3003               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3004             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3005               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3006             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3007               ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3008             p+=channels;
3009             q+=quantum_info->pad;
3010           }
3011           break;
3012         }
3013       }
3014       break;
3015     }
3016     case CMYKAQuantum:
3017     case CMYKOQuantum:
3018     {
3019       if (image->colorspace != CMYKColorspace)
3020         {
3021           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3022             "ColorSeparatedImageRequired","`%s'",image->filename);
3023           return(extent);
3024         }
3025       switch (quantum_info->depth)
3026       {
3027         case 8:
3028         {
3029           register unsigned char
3030             pixel;
3031
3032           for (x=0; x < (ssize_t) number_pixels; x++)
3033           {
3034             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3035             q=PopCharPixel(pixel,q);
3036             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3037             q=PopCharPixel(pixel,q);
3038             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3039             q=PopCharPixel(pixel,q);
3040             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
3041             q=PopCharPixel(pixel,q);
3042             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
3043             q=PopCharPixel(pixel,q);
3044             p+=channels;
3045             q+=quantum_info->pad;
3046           }
3047           break;
3048         }
3049         case 16:
3050         {
3051           register unsigned short
3052             pixel;
3053
3054           if (quantum_info->format == FloatingPointQuantumFormat)
3055             {
3056               for (x=0; x < (ssize_t) number_pixels; x++)
3057               {
3058                 pixel=SinglePrecisionToHalf(QuantumScale*
3059                   GetPixelRed(image,p));
3060                 q=PopShortPixel(endian,pixel,q);
3061                 pixel=SinglePrecisionToHalf(QuantumScale*
3062                   GetPixelGreen(image,p));
3063                 q=PopShortPixel(endian,pixel,q);
3064                 pixel=SinglePrecisionToHalf(QuantumScale*
3065                   GetPixelBlue(image,p));
3066                 q=PopShortPixel(endian,pixel,q);
3067                 pixel=SinglePrecisionToHalf(QuantumScale*
3068                   GetPixelBlack(image,p));
3069                 q=PopShortPixel(endian,pixel,q);
3070                 pixel=SinglePrecisionToHalf(QuantumScale*
3071                   GetPixelAlpha(image,p));
3072                 q=PopShortPixel(endian,pixel,q);
3073                 p+=channels;
3074                 q+=quantum_info->pad;
3075               }
3076               break;
3077             }
3078           for (x=0; x < (ssize_t) number_pixels; x++)
3079           {
3080             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3081             q=PopShortPixel(endian,pixel,q);
3082             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3083             q=PopShortPixel(endian,pixel,q);
3084             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3085             q=PopShortPixel(endian,pixel,q);
3086             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
3087             q=PopShortPixel(endian,pixel,q);
3088             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
3089             q=PopShortPixel(endian,pixel,q);
3090             p+=channels;
3091             q+=quantum_info->pad;
3092           }
3093           break;
3094         }
3095         case 32:
3096         {
3097           register unsigned int
3098             pixel;
3099
3100           if (quantum_info->format == FloatingPointQuantumFormat)
3101             {
3102               for (x=0; x < (ssize_t) number_pixels; x++)
3103               {
3104                 float
3105                   pixel;
3106
3107                 q=PopFloatPixel(&quantum_state,(float)
3108                   GetPixelRed(image,p),q);
3109                 q=PopFloatPixel(&quantum_state,(float)
3110                   GetPixelGreen(image,p),q);
3111                 q=PopFloatPixel(&quantum_state,(float)
3112                   GetPixelBlue(image,p),q);
3113                 q=PopFloatPixel(&quantum_state,(float)
3114                   GetPixelBlack(image,p),q);
3115                 pixel=(float) (GetPixelAlpha(image,p));
3116                 q=PopFloatPixel(&quantum_state,pixel,q);
3117                 p+=channels;
3118                 q+=quantum_info->pad;
3119               }
3120               break;
3121             }
3122           for (x=0; x < (ssize_t) number_pixels; x++)
3123           {
3124             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3125             q=PopLongPixel(endian,pixel,q);
3126             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3127             q=PopLongPixel(endian,pixel,q);
3128             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3129             q=PopLongPixel(endian,pixel,q);
3130             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
3131             q=PopLongPixel(endian,pixel,q);
3132             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
3133             q=PopLongPixel(endian,pixel,q);
3134             p+=channels;
3135             q+=quantum_info->pad;
3136           }
3137           break;
3138         }
3139         case 64:
3140         {
3141           if (quantum_info->format == FloatingPointQuantumFormat)
3142             {
3143               double
3144                 pixel;
3145
3146               for (x=0; x < (ssize_t) number_pixels; x++)
3147               {
3148                 q=PopDoublePixel(&quantum_state,(double)
3149                   GetPixelRed(image,p),q);
3150                 q=PopDoublePixel(&quantum_state,(double)
3151                   GetPixelGreen(image,p),q);
3152                 q=PopDoublePixel(&quantum_state,(double)
3153                   GetPixelBlue(image,p),q);
3154                 q=PopDoublePixel(&quantum_state,(double)
3155                   GetPixelBlack(image,p),q);
3156                 pixel=(double) (GetPixelAlpha(image,p));
3157                 q=PopDoublePixel(&quantum_state,pixel,q);
3158                 p+=channels;
3159                 q+=quantum_info->pad;
3160               }
3161               break;
3162             }
3163         }
3164         default:
3165         {
3166           range=GetQuantumRange(quantum_info->depth);
3167           for (x=0; x < (ssize_t) number_pixels; x++)
3168           {
3169             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3170               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
3171             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3172               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3173             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3174               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3175             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3176               ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3177             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3178               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
3179             p+=channels;
3180             q+=quantum_info->pad;
3181           }
3182           break;
3183         }
3184       }
3185       break;
3186     }
3187     case CbYCrYQuantum:
3188     {
3189       Quantum
3190         cbcr[4];
3191
3192       register ssize_t
3193         i;
3194
3195       register unsigned int
3196         pixel;
3197
3198       size_t
3199         quantum;
3200
3201      ssize_t
3202         n;
3203
3204       n=0;
3205       quantum=0;
3206       range=GetQuantumRange(quantum_info->depth);
3207       switch (quantum_info->depth)
3208       {
3209         case 10:
3210         {
3211           if (quantum_info->pack == MagickFalse)
3212             {
3213               for (x=0; x < (ssize_t) number_pixels; x+=2)
3214               {
3215                 for (i=0; i < 4; i++)
3216                 {
3217                   switch (n % 3)
3218                   {
3219                     case 0:
3220                     {
3221                       quantum=GetPixelRed(image,p);
3222                       break;
3223                     }
3224                     case 1:
3225                     {
3226                       quantum=GetPixelGreen(image,p);
3227                       break;
3228                     }
3229                     case 2:
3230                     {
3231                       quantum=GetPixelBlue(image,p);
3232                       break;
3233                     }
3234                   }
3235                   cbcr[i]=(Quantum) quantum;
3236                   n++;
3237                 }
3238                 pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 | (size_t)
3239                   (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3240                 q=PopLongPixel(endian,pixel,q);
3241                 p+=channels;
3242                 pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 | (size_t)
3243                   (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3244                 q=PopLongPixel(endian,pixel,q);
3245                 p+=channels;
3246                 q+=quantum_info->pad;
3247               }
3248               break;
3249             }
3250           break;
3251         }
3252         default:
3253         {
3254           for (x=0; x < (ssize_t) number_pixels; x+=2)
3255           {
3256             for (i=0; i < 4; i++)
3257             {
3258               switch (n % 3)
3259               {
3260                 case 0:
3261                 {
3262                   quantum=GetPixelRed(image,p);
3263                   break;
3264                 }
3265                 case 1:
3266                 {
3267                   quantum=GetPixelGreen(image,p);
3268                   break;
3269                 }
3270                 case 2:
3271                 {
3272                   quantum=GetPixelBlue(image,p);
3273                   break;
3274                 }
3275               }
3276               cbcr[i]=(Quantum) quantum;
3277               n++;
3278             }
3279             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3280               ScaleQuantumToAny(cbcr[1],range),q);
3281             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3282               ScaleQuantumToAny(cbcr[0],range),q);
3283             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3284               ScaleQuantumToAny(cbcr[2],range),q);
3285             p+=channels;
3286             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3287               ScaleQuantumToAny(cbcr[3],range),q);
3288             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3289               ScaleQuantumToAny(cbcr[0],range),q);
3290             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3291               ScaleQuantumToAny(cbcr[2],range),q);
3292             p+=channels;
3293             q+=quantum_info->pad;
3294           }
3295           break;
3296         }
3297       }
3298       break;
3299     }
3300     default:
3301       break;
3302   }
3303   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3304     {
3305       Quantum
3306         quantum;
3307
3308       register Quantum
3309         *restrict q;
3310
3311       q=GetAuthenticPixelQueue(image);
3312       if (image_view != (CacheView *) NULL)
3313         q=GetCacheViewAuthenticPixelQueue(image_view);
3314       for (x=0; x < (ssize_t) number_pixels; x++)
3315       {
3316         quantum=GetPixelRed(image,q);
3317         SetPixelRed(image,GetPixelGreen(image,q),q);
3318         SetPixelGreen(image,quantum,q);
3319         q+=channels;
3320       }
3321     }
3322   if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
3323       (quantum_type == BGROQuantum))
3324     {
3325       register Quantum
3326         *restrict q;
3327
3328       q=GetAuthenticPixelQueue(image);
3329       if (image_view != (CacheView *) NULL)
3330         q=GetCacheViewAuthenticPixelQueue(image_view);
3331       for (x=0; x < (ssize_t) number_pixels; x++)
3332       {
3333         SetPixelAlpha(image,GetPixelAlpha(image,q),q);
3334         q+=channels;
3335       }
3336     }
3337   return(extent);
3338 }