]> 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),range) << 22 |
1366                   ScaleQuantumToAny(GetPixelIntensity(image,p+1),range) << 12 |
1367                   ScaleQuantumToAny(GetPixelIntensity(image,p+0),range) << 2);
1368                 q=PopLongPixel(endian,pixel,q);
1369                 p+=3;
1370                 q+=quantum_info->pad;
1371               }
1372               pixel=0UL;
1373               if (x++ < (ssize_t) (number_pixels-1))
1374                 pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p+1),
1375                   range) << 12;
1376               if (x++ < (ssize_t) number_pixels)
1377                 pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p+0),
1378                   range) << 2;
1379               q=PopLongPixel(endian,pixel,q);
1380               break;
1381             }
1382           for (x=0; x < (ssize_t) number_pixels; x++)
1383           {
1384             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1385               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1386             p+=channels;
1387             q+=quantum_info->pad;
1388           }
1389           break;
1390         }
1391         case 12:
1392         {
1393           register unsigned short
1394             pixel;
1395
1396           range=GetQuantumRange(quantum_info->depth);
1397           if (quantum_info->pack == MagickFalse)
1398             {
1399               for (x=0; x < (ssize_t) number_pixels; x++)
1400               {
1401                 pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1402                 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
1403                 p+=channels;
1404                 q+=quantum_info->pad;
1405               }
1406               break;
1407             }
1408           for (x=0; x < (ssize_t) number_pixels; x++)
1409           {
1410             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1411               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1412             p+=channels;
1413             q+=quantum_info->pad;
1414           }
1415           break;
1416         }
1417         case 16:
1418         {
1419           register unsigned short
1420             pixel;
1421
1422           if (quantum_info->format == FloatingPointQuantumFormat)
1423             {
1424               for (x=0; x < (ssize_t) number_pixels; x++)
1425               {
1426                 pixel=SinglePrecisionToHalf(QuantumScale*
1427                   GetPixelIntensity(image,p));
1428                 q=PopShortPixel(endian,pixel,q);
1429                 p+=channels;
1430                 q+=quantum_info->pad;
1431               }
1432               break;
1433             }
1434           for (x=0; x < (ssize_t) number_pixels; x++)
1435           {
1436             pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1437             q=PopShortPixel(endian,pixel,q);
1438             p+=channels;
1439             q+=quantum_info->pad;
1440           }
1441           break;
1442         }
1443         case 32:
1444         {
1445           register unsigned int
1446             pixel;
1447
1448           if (quantum_info->format == FloatingPointQuantumFormat)
1449             {
1450               for (x=0; x < (ssize_t) number_pixels; x++)
1451               {
1452                 float
1453                   pixel;
1454
1455                 pixel=(float) GetPixelIntensity(image,p);
1456                 q=PopFloatPixel(&quantum_state,pixel,q);
1457                 p+=channels;
1458                 q+=quantum_info->pad;
1459               }
1460               break;
1461             }
1462           for (x=0; x < (ssize_t) number_pixels; x++)
1463           {
1464             pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1465             q=PopLongPixel(endian,pixel,q);
1466             p+=channels;
1467             q+=quantum_info->pad;
1468           }
1469           break;
1470         }
1471         case 64:
1472         {
1473           if (quantum_info->format == FloatingPointQuantumFormat)
1474             {
1475               for (x=0; x < (ssize_t) number_pixels; x++)
1476               {
1477                 double
1478                   pixel;
1479
1480                 pixel=(double) GetPixelIntensity(image,p);
1481                 q=PopDoublePixel(&quantum_state,pixel,q);
1482                 p+=channels;
1483                 q+=quantum_info->pad;
1484               }
1485               break;
1486             }
1487         }
1488         default:
1489         {
1490           range=GetQuantumRange(quantum_info->depth);
1491           for (x=0; x < (ssize_t) number_pixels; x++)
1492           {
1493             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1494               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1495             p+=channels;
1496             q+=quantum_info->pad;
1497           }
1498           break;
1499         }
1500       }
1501       break;
1502     }
1503     case GrayAlphaQuantum:
1504     {
1505       switch (quantum_info->depth)
1506       {
1507         case 1:
1508         {
1509           register Quantum
1510             threshold;
1511
1512           register unsigned char
1513             black,
1514             pixel,
1515             white;
1516
1517           black=0x00;
1518           white=0x01;
1519           if (quantum_info->min_is_white == MagickFalse)
1520             {
1521               black=0x01;
1522               white=0x00;
1523             }
1524           threshold=(Quantum) (QuantumRange/2);
1525           for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
1526           {
1527             *q='\0';
1528             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 7;
1529             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1530               0x00 : 0x01);
1531             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
1532             p+=channels;
1533             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 5;
1534             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1535               0x00 : 0x01);
1536             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
1537             p+=channels;
1538             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 3;
1539             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1540               0x00 : 0x01);
1541             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
1542             p+=channels;
1543             *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 1;
1544             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1545               0x00 : 0x01);
1546             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
1547             p+=channels;
1548             q++;
1549           }
1550           if ((number_pixels % 4) != 0)
1551             {
1552               *q='\0';
1553               for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
1554               {
1555                 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) <<
1556                   (7-bit);
1557                 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1558                   0x00 : 0x01);
1559                 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
1560                   (7-bit-1));
1561                 p+=channels;
1562               }
1563               q++;
1564             }
1565           break;
1566         }
1567         case 4:
1568         {
1569           register unsigned char
1570             pixel;
1571
1572           for (x=0; x < (ssize_t) number_pixels ; x++)
1573           {
1574             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1575             *q=(((pixel >> 4) & 0xf) << 4);
1576             pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
1577             *q|=pixel & 0xf;
1578             p+=channels;
1579             q++;
1580           }
1581           break;
1582         }
1583         case 8:
1584         {
1585           register unsigned char
1586             pixel;
1587
1588           for (x=0; x < (ssize_t) number_pixels; x++)
1589           {
1590             pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1591             q=PopCharPixel(pixel,q);
1592             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1593             q=PopCharPixel(pixel,q);
1594             p+=channels;
1595             q+=quantum_info->pad;
1596           }
1597           break;
1598         }
1599         case 16:
1600         {
1601           register unsigned short
1602             pixel;
1603
1604           if (quantum_info->format == FloatingPointQuantumFormat)
1605             {
1606               for (x=0; x < (ssize_t) number_pixels; x++)
1607               {
1608                 pixel=SinglePrecisionToHalf(QuantumScale*
1609                   GetPixelIntensity(image,p));
1610                 q=PopShortPixel(endian,pixel,q);
1611                 pixel=SinglePrecisionToHalf(QuantumScale*
1612                   GetPixelAlpha(image,p));
1613                 q=PopShortPixel(endian,pixel,q);
1614                 p+=channels;
1615                 q+=quantum_info->pad;
1616               }
1617               break;
1618             }
1619           for (x=0; x < (ssize_t) number_pixels; x++)
1620           {
1621             pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1622             q=PopShortPixel(endian,pixel,q);
1623             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1624             q=PopShortPixel(endian,pixel,q);
1625             p+=channels;
1626             q+=quantum_info->pad;
1627           }
1628           break;
1629         }
1630         case 32:
1631         {
1632           register unsigned int
1633             pixel;
1634
1635           if (quantum_info->format == FloatingPointQuantumFormat)
1636             {
1637               for (x=0; x < (ssize_t) number_pixels; x++)
1638               {
1639                 float
1640                   pixel;
1641
1642                 pixel=(float) GetPixelIntensity(image,p);
1643                 q=PopFloatPixel(&quantum_state,pixel,q);
1644                 pixel=(float) (GetPixelAlpha(image,p));
1645                 q=PopFloatPixel(&quantum_state,pixel,q);
1646                 p+=channels;
1647                 q+=quantum_info->pad;
1648               }
1649               break;
1650             }
1651           for (x=0; x < (ssize_t) number_pixels; x++)
1652           {
1653             pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1654             q=PopLongPixel(endian,pixel,q);
1655             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1656             q=PopLongPixel(endian,pixel,q);
1657             p+=channels;
1658             q+=quantum_info->pad;
1659           }
1660           break;
1661         }
1662         case 64:
1663         {
1664           if (quantum_info->format == FloatingPointQuantumFormat)
1665             {
1666               for (x=0; x < (ssize_t) number_pixels; x++)
1667               {
1668                 double
1669                   pixel;
1670
1671                 pixel=(double) GetPixelIntensity(image,p);
1672                 q=PopDoublePixel(&quantum_state,pixel,q);
1673                 pixel=(double) (GetPixelAlpha(image,p));
1674                 q=PopDoublePixel(&quantum_state,pixel,q);
1675                 p+=channels;
1676                 q+=quantum_info->pad;
1677               }
1678               break;
1679             }
1680         }
1681         default:
1682         {
1683           range=GetQuantumRange(quantum_info->depth);
1684           for (x=0; x < (ssize_t) number_pixels; x++)
1685           {
1686             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1687               ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1688             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1689               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
1690             p+=channels;
1691             q+=quantum_info->pad;
1692           }
1693           break;
1694         }
1695       }
1696       break;
1697     }
1698     case RedQuantum:
1699     case CyanQuantum:
1700     {
1701       switch (quantum_info->depth)
1702       {
1703         case 8:
1704         {
1705           register unsigned char
1706             pixel;
1707
1708           for (x=0; x < (ssize_t) number_pixels; x++)
1709           {
1710             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1711             q=PopCharPixel(pixel,q);
1712             p+=channels;
1713             q+=quantum_info->pad;
1714           }
1715           break;
1716         }
1717         case 16:
1718         {
1719           register unsigned short
1720             pixel;
1721
1722           if (quantum_info->format == FloatingPointQuantumFormat)
1723             {
1724               for (x=0; x < (ssize_t) number_pixels; x++)
1725               {
1726                 pixel=SinglePrecisionToHalf(QuantumScale*
1727                   GetPixelRed(image,p));
1728                 q=PopShortPixel(endian,pixel,q);
1729                 p+=channels;
1730                 q+=quantum_info->pad;
1731               }
1732               break;
1733             }
1734           for (x=0; x < (ssize_t) number_pixels; x++)
1735           {
1736             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1737             q=PopShortPixel(endian,pixel,q);
1738             p+=channels;
1739             q+=quantum_info->pad;
1740           }
1741           break;
1742         }
1743         case 32:
1744         {
1745           register unsigned int
1746             pixel;
1747
1748           if (quantum_info->format == FloatingPointQuantumFormat)
1749             {
1750               for (x=0; x < (ssize_t) number_pixels; x++)
1751               {
1752                 q=PopFloatPixel(&quantum_state,(float)
1753                   GetPixelRed(image,p),q);
1754                 p+=channels;
1755                 q+=quantum_info->pad;
1756               }
1757               break;
1758             }
1759           for (x=0; x < (ssize_t) number_pixels; x++)
1760           {
1761             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1762             q=PopLongPixel(endian,pixel,q);
1763             p+=channels;
1764             q+=quantum_info->pad;
1765           }
1766           break;
1767         }
1768         case 64:
1769         {
1770           if (quantum_info->format == FloatingPointQuantumFormat)
1771             {
1772               for (x=0; x < (ssize_t) number_pixels; x++)
1773               {
1774                 q=PopDoublePixel(&quantum_state,(double)
1775                   GetPixelRed(image,p),q);
1776                 p+=channels;
1777                 q+=quantum_info->pad;
1778               }
1779               break;
1780             }
1781         }
1782         default:
1783         {
1784           range=GetQuantumRange(quantum_info->depth);
1785           for (x=0; x < (ssize_t) number_pixels; x++)
1786           {
1787             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1788               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
1789             p+=channels;
1790             q+=quantum_info->pad;
1791           }
1792           break;
1793         }
1794       }
1795       break;
1796     }
1797     case GreenQuantum:
1798     case MagentaQuantum:
1799     {
1800       switch (quantum_info->depth)
1801       {
1802         case 8:
1803         {
1804           register unsigned char
1805             pixel;
1806
1807           for (x=0; x < (ssize_t) number_pixels; x++)
1808           {
1809             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1810             q=PopCharPixel(pixel,q);
1811             p+=channels;
1812             q+=quantum_info->pad;
1813           }
1814           break;
1815         }
1816         case 16:
1817         {
1818           register unsigned short
1819             pixel;
1820
1821           if (quantum_info->format == FloatingPointQuantumFormat)
1822             {
1823               for (x=0; x < (ssize_t) number_pixels; x++)
1824               {
1825                 pixel=SinglePrecisionToHalf(QuantumScale*
1826                   GetPixelGreen(image,p));
1827                 q=PopShortPixel(endian,pixel,q);
1828                 p+=channels;
1829                 q+=quantum_info->pad;
1830               }
1831               break;
1832             }
1833           for (x=0; x < (ssize_t) number_pixels; x++)
1834           {
1835             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1836             q=PopShortPixel(endian,pixel,q);
1837             p+=channels;
1838             q+=quantum_info->pad;
1839           }
1840           break;
1841         }
1842         case 32:
1843         {
1844           register unsigned int
1845             pixel;
1846
1847           if (quantum_info->format == FloatingPointQuantumFormat)
1848             {
1849               for (x=0; x < (ssize_t) number_pixels; x++)
1850               {
1851                 q=PopFloatPixel(&quantum_state,(float)
1852                   GetPixelGreen(image,p),q);
1853                 p+=channels;
1854                 q+=quantum_info->pad;
1855               }
1856               break;
1857             }
1858           for (x=0; x < (ssize_t) number_pixels; x++)
1859           {
1860             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1861             q=PopLongPixel(endian,pixel,q);
1862             p+=channels;
1863             q+=quantum_info->pad;
1864           }
1865           break;
1866         }
1867         case 64:
1868         {
1869           if (quantum_info->format == FloatingPointQuantumFormat)
1870             {
1871               for (x=0; x < (ssize_t) number_pixels; x++)
1872               {
1873                 q=PopDoublePixel(&quantum_state,(double)
1874                   GetPixelGreen(image,p),q);
1875                 p+=channels;
1876                 q+=quantum_info->pad;
1877               }
1878               break;
1879             }
1880         }
1881         default:
1882         {
1883           range=GetQuantumRange(quantum_info->depth);
1884           for (x=0; x < (ssize_t) number_pixels; x++)
1885           {
1886             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1887               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
1888             p+=channels;
1889             q+=quantum_info->pad;
1890           }
1891           break;
1892         }
1893       }
1894       break;
1895     }
1896     case BlueQuantum:
1897     case YellowQuantum:
1898     {
1899       switch (quantum_info->depth)
1900       {
1901         case 8:
1902         {
1903           register unsigned char
1904             pixel;
1905
1906           for (x=0; x < (ssize_t) number_pixels; x++)
1907           {
1908             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1909             q=PopCharPixel(pixel,q);
1910             p+=channels;
1911             q+=quantum_info->pad;
1912           }
1913           break;
1914         }
1915         case 16:
1916         {
1917           register unsigned short
1918             pixel;
1919
1920           if (quantum_info->format == FloatingPointQuantumFormat)
1921             {
1922               for (x=0; x < (ssize_t) number_pixels; x++)
1923               {
1924                 pixel=SinglePrecisionToHalf(QuantumScale*
1925                   GetPixelBlue(image,p));
1926                 q=PopShortPixel(endian,pixel,q);
1927                 p+=channels;
1928                 q+=quantum_info->pad;
1929               }
1930               break;
1931             }
1932           for (x=0; x < (ssize_t) number_pixels; x++)
1933           {
1934             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1935             q=PopShortPixel(endian,pixel,q);
1936             p+=channels;
1937             q+=quantum_info->pad;
1938           }
1939           break;
1940         }
1941         case 32:
1942         {
1943           register unsigned int
1944             pixel;
1945
1946           if (quantum_info->format == FloatingPointQuantumFormat)
1947             {
1948               for (x=0; x < (ssize_t) number_pixels; x++)
1949               {
1950                 q=PopFloatPixel(&quantum_state,(float)
1951                   GetPixelBlue(image,p),q);
1952                 p+=channels;
1953                 q+=quantum_info->pad;
1954               }
1955               break;
1956             }
1957           for (x=0; x < (ssize_t) number_pixels; x++)
1958           {
1959             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1960             q=PopLongPixel(endian,pixel,q);
1961             p+=channels;
1962             q+=quantum_info->pad;
1963           }
1964           break;
1965         }
1966         case 64:
1967         {
1968           if (quantum_info->format == FloatingPointQuantumFormat)
1969             {
1970               for (x=0; x < (ssize_t) number_pixels; x++)
1971               {
1972                 q=PopDoublePixel(&quantum_state,(double)
1973                   GetPixelBlue(image,p),q);
1974                 p+=channels;
1975                 q+=quantum_info->pad;
1976               }
1977               break;
1978             }
1979         }
1980         default:
1981         {
1982           range=GetQuantumRange(quantum_info->depth);
1983           for (x=0; x < (ssize_t) number_pixels; x++)
1984           {
1985             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1986               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
1987             p+=channels;
1988             q+=quantum_info->pad;
1989           }
1990           break;
1991         }
1992       }
1993       break;
1994     }
1995     case AlphaQuantum:
1996     {
1997       switch (quantum_info->depth)
1998       {
1999         case 8:
2000         {
2001           register unsigned char
2002             pixel;
2003
2004           for (x=0; x < (ssize_t) number_pixels; x++)
2005           {
2006             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2007             q=PopCharPixel(pixel,q);
2008             p+=channels;
2009             q+=quantum_info->pad;
2010           }
2011           break;
2012         }
2013         case 16:
2014         {
2015           register unsigned short
2016             pixel;
2017
2018           if (quantum_info->format == FloatingPointQuantumFormat)
2019             {
2020               for (x=0; x < (ssize_t) number_pixels; x++)
2021               {
2022                 pixel=SinglePrecisionToHalf(QuantumScale*
2023                   GetPixelAlpha(image,p));
2024                 q=PopShortPixel(endian,pixel,q);
2025                 p+=channels;
2026                 q+=quantum_info->pad;
2027               }
2028               break;
2029             }
2030           for (x=0; x < (ssize_t) number_pixels; x++)
2031           {
2032             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2033             q=PopShortPixel(endian,pixel,q);
2034             p+=channels;
2035             q+=quantum_info->pad;
2036           }
2037           break;
2038         }
2039         case 32:
2040         {
2041           register unsigned int
2042             pixel;
2043
2044           if (quantum_info->format == FloatingPointQuantumFormat)
2045             {
2046               for (x=0; x < (ssize_t) number_pixels; x++)
2047               {
2048                 float
2049                   pixel;
2050
2051                 pixel=(float) GetPixelAlpha(image,p);
2052                 q=PopFloatPixel(&quantum_state,pixel,q);
2053                 p+=channels;
2054                 q+=quantum_info->pad;
2055               }
2056               break;
2057             }
2058           for (x=0; x < (ssize_t) number_pixels; x++)
2059           {
2060             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2061             q=PopLongPixel(endian,pixel,q);
2062             p+=channels;
2063             q+=quantum_info->pad;
2064           }
2065           break;
2066         }
2067         case 64:
2068         {
2069           if (quantum_info->format == FloatingPointQuantumFormat)
2070             {
2071               for (x=0; x < (ssize_t) number_pixels; x++)
2072               {
2073                 double
2074                   pixel;
2075
2076                 pixel=(double) (GetPixelAlpha(image,p));
2077                 q=PopDoublePixel(&quantum_state,pixel,q);
2078                 p+=channels;
2079                 q+=quantum_info->pad;
2080               }
2081               break;
2082             }
2083         }
2084         default:
2085         {
2086           range=GetQuantumRange(quantum_info->depth);
2087           for (x=0; x < (ssize_t) number_pixels; x++)
2088           {
2089             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2090               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2091             p+=channels;
2092             q+=quantum_info->pad;
2093           }
2094           break;
2095         }
2096       }
2097       break;
2098     }
2099     case OpacityQuantum:
2100     {
2101       switch (quantum_info->depth)
2102       {
2103         case 8:
2104         {
2105           register unsigned char
2106             pixel;
2107
2108           for (x=0; x < (ssize_t) number_pixels; x++)
2109           {
2110             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2111             q=PopCharPixel(pixel,q);
2112             p+=channels;
2113             q+=quantum_info->pad;
2114           }
2115           break;
2116         }
2117         case 16:
2118         {
2119           register unsigned short
2120             pixel;
2121
2122           if (quantum_info->format == FloatingPointQuantumFormat)
2123             {
2124               for (x=0; x < (ssize_t) number_pixels; x++)
2125               {
2126                 pixel=SinglePrecisionToHalf(QuantumScale*
2127                   GetPixelAlpha(image,p));
2128                 q=PopShortPixel(endian,pixel,q);
2129                 p+=channels;
2130                 q+=quantum_info->pad;
2131               }
2132               break;
2133             }
2134           for (x=0; x < (ssize_t) number_pixels; x++)
2135           {
2136             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2137             q=PopShortPixel(endian,pixel,q);
2138             p+=channels;
2139             q+=quantum_info->pad;
2140           }
2141           break;
2142         }
2143         case 32:
2144         {
2145           register unsigned int
2146             pixel;
2147
2148           if (quantum_info->format == FloatingPointQuantumFormat)
2149             {
2150               for (x=0; x < (ssize_t) number_pixels; x++)
2151               {
2152                 q=PopFloatPixel(&quantum_state,(float)
2153                   GetPixelAlpha(image,p),q);
2154                 p+=channels;
2155                 q+=quantum_info->pad;
2156               }
2157               break;
2158             }
2159           for (x=0; x < (ssize_t) number_pixels; x++)
2160           {
2161             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2162             q=PopLongPixel(endian,pixel,q);
2163             p+=channels;
2164             q+=quantum_info->pad;
2165           }
2166           break;
2167         }
2168         case 64:
2169         {
2170           if (quantum_info->format == FloatingPointQuantumFormat)
2171             {
2172               for (x=0; x < (ssize_t) number_pixels; x++)
2173               {
2174                 q=PopDoublePixel(&quantum_state,(double)
2175                   GetPixelAlpha(image,p),q);
2176                 p+=channels;
2177                 q+=quantum_info->pad;
2178               }
2179               break;
2180             }
2181         }
2182         default:
2183         {
2184           range=GetQuantumRange(quantum_info->depth);
2185           for (x=0; x < (ssize_t) number_pixels; x++)
2186           {
2187             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2188               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2189             p+=channels;
2190             q+=quantum_info->pad;
2191           }
2192           break;
2193         }
2194       }
2195       break;
2196     }
2197     case BlackQuantum:
2198     {
2199       if (image->colorspace != CMYKColorspace)
2200         {
2201           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2202             "ColorSeparatedImageRequired","`%s'",image->filename);
2203           return(extent);
2204         }
2205       switch (quantum_info->depth)
2206       {
2207         case 8:
2208         {
2209           register unsigned char
2210             pixel;
2211
2212           for (x=0; x < (ssize_t) number_pixels; x++)
2213           {
2214             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2215             q=PopCharPixel(pixel,q);
2216             p+=channels;
2217             q+=quantum_info->pad;
2218           }
2219           break;
2220         }
2221         case 16:
2222         {
2223           register unsigned short
2224             pixel;
2225
2226           if (quantum_info->format == FloatingPointQuantumFormat)
2227             {
2228               for (x=0; x < (ssize_t) number_pixels; x++)
2229               {
2230                 pixel=SinglePrecisionToHalf(QuantumScale*
2231                   GetPixelBlack(image,p));
2232                 q=PopShortPixel(endian,pixel,q);
2233                 p+=channels;
2234                 q+=quantum_info->pad;
2235               }
2236               break;
2237             }
2238           for (x=0; x < (ssize_t) number_pixels; x++)
2239           {
2240             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2241             q=PopShortPixel(endian,pixel,q);
2242             p+=channels;
2243             q+=quantum_info->pad;
2244           }
2245           break;
2246         }
2247         case 32:
2248         {
2249           register unsigned int
2250             pixel;
2251
2252           if (quantum_info->format == FloatingPointQuantumFormat)
2253             {
2254               for (x=0; x < (ssize_t) number_pixels; x++)
2255               {
2256                 q=PopFloatPixel(&quantum_state,(float)
2257                   GetPixelBlack(image,p),q);
2258                 p+=channels;
2259                 q+=quantum_info->pad;
2260               }
2261               break;
2262             }
2263           for (x=0; x < (ssize_t) number_pixels; x++)
2264           {
2265             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2266             q=PopLongPixel(endian,pixel,q);
2267             p+=channels;
2268             q+=quantum_info->pad;
2269           }
2270           break;
2271         }
2272         case 64:
2273         {
2274           if (quantum_info->format == FloatingPointQuantumFormat)
2275             {
2276               for (x=0; x < (ssize_t) number_pixels; x++)
2277               {
2278                 q=PopDoublePixel(&quantum_state,(double)
2279                   GetPixelBlack(image,p),q);
2280                 p+=channels;
2281                 q+=quantum_info->pad;
2282               }
2283               break;
2284             }
2285         }
2286         default:
2287         {
2288           range=GetQuantumRange(quantum_info->depth);
2289           for (x=0; x < (ssize_t) number_pixels; x++)
2290           {
2291             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2292               ScaleQuantumToAny((Quantum) GetPixelBlack(image,p),range),q);
2293             p+=channels;
2294             q+=quantum_info->pad;
2295           }
2296           break;
2297         }
2298       }
2299       break;
2300     }
2301     case RGBQuantum:
2302     case CbYCrQuantum:
2303     {
2304       switch (quantum_info->depth)
2305       {
2306         case 8:
2307         {
2308           for (x=0; x < (ssize_t) number_pixels; x++)
2309           {
2310             q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
2311             q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
2312             q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
2313             p+=channels;
2314             q+=quantum_info->pad;
2315           }
2316           break;
2317         }
2318         case 10:
2319         {
2320           register unsigned int
2321             pixel;
2322
2323           range=GetQuantumRange(quantum_info->depth);
2324           if (quantum_info->pack == MagickFalse)
2325             {
2326               for (x=0; x < (ssize_t) number_pixels; x++)
2327               {
2328                 pixel=(unsigned int) (
2329                   ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
2330                   ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
2331                   ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
2332                 q=PopLongPixel(endian,pixel,q);
2333                 p+=channels;
2334                 q+=quantum_info->pad;
2335               }
2336               break;
2337             }
2338           if (quantum_info->quantum == 32UL)
2339             {
2340               for (x=0; x < (ssize_t) number_pixels; x++)
2341               {
2342                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2343                   range);
2344                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2345                   q);
2346                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2347                   range);
2348                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2349                   q);
2350                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2351                   range);
2352                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2353                   q);
2354                 p+=channels;
2355                 q+=quantum_info->pad;
2356               }
2357               break;
2358             }
2359           for (x=0; x < (ssize_t) number_pixels; x++)
2360           {
2361             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2362               range);
2363             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2364             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2365               range);
2366             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2367             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2368               range);
2369             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2370             p+=channels;
2371             q+=quantum_info->pad;
2372           }
2373           break;
2374         }
2375         case 12:
2376         {
2377           register unsigned int
2378             pixel;
2379
2380           range=GetQuantumRange(quantum_info->depth);
2381           if (quantum_info->pack == MagickFalse)
2382             {
2383               for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
2384               {
2385                 switch (x % 3)
2386                 {
2387                   default:
2388                   case 0:
2389                   {
2390                     pixel=(unsigned int) ScaleQuantumToAny(
2391                       GetPixelRed(image,p),range);
2392                     break;
2393                   }
2394                   case 1:
2395                   {
2396                     pixel=(unsigned int) ScaleQuantumToAny(
2397                       GetPixelGreen(image,p),range);
2398                     break;
2399                   }
2400                   case 2:
2401                   {
2402                     pixel=(unsigned int) ScaleQuantumToAny(
2403                       GetPixelBlue(image,p),range);
2404                     p+=channels;
2405                     break;
2406                   }
2407                 }
2408                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2409                 switch ((x+1) % 3)
2410                 {
2411                   default:
2412                   case 0:
2413                   {
2414                     pixel=(unsigned int) ScaleQuantumToAny(
2415                       GetPixelRed(image,p),range);
2416                     break;
2417                   }
2418                   case 1:
2419                   {
2420                     pixel=(unsigned int) ScaleQuantumToAny(
2421                       GetPixelGreen(image,p),range);
2422                     break;
2423                   }
2424                   case 2:
2425                   {
2426                     pixel=(unsigned int) ScaleQuantumToAny(
2427                       GetPixelBlue(image,p),range);
2428                     p+=channels;
2429                     break;
2430                   }
2431                 }
2432                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2433                 q+=quantum_info->pad;
2434               }
2435               for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
2436               {
2437                 switch ((x+bit) % 3)
2438                 {
2439                   default:
2440                   case 0:
2441                   {
2442                     pixel=(unsigned int) ScaleQuantumToAny(
2443                       GetPixelRed(image,p),range);
2444                     break;
2445                   }
2446                   case 1:
2447                   {
2448                     pixel=(unsigned int) ScaleQuantumToAny(
2449                       GetPixelGreen(image,p),range);
2450                     break;
2451                   }
2452                   case 2:
2453                   {
2454                     pixel=(unsigned int) ScaleQuantumToAny(
2455                       GetPixelBlue(image,p),range);
2456                     p+=channels;
2457                     break;
2458                   }
2459                 }
2460                 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2461                 q+=quantum_info->pad;
2462               }
2463               if (bit != 0)
2464                 p+=channels;
2465               break;
2466             }
2467           if (quantum_info->quantum == 32UL)
2468             {
2469               for (x=0; x < (ssize_t) number_pixels; x++)
2470               {
2471                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2472                   range);
2473                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2474                   q);
2475                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2476                   range);
2477                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2478                   q);
2479                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2480                   range);
2481                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2482                   q);
2483                 p+=channels;
2484                 q+=quantum_info->pad;
2485               }
2486               break;
2487             }
2488           for (x=0; x < (ssize_t) number_pixels; x++)
2489           {
2490             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2491               range);
2492             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2493             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2494               range);
2495             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2496             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2497               range);
2498             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2499             p+=channels;
2500             q+=quantum_info->pad;
2501           }
2502           break;
2503         }
2504         case 16:
2505         {
2506           register unsigned short
2507             pixel;
2508
2509           if (quantum_info->format == FloatingPointQuantumFormat)
2510             {
2511               for (x=0; x < (ssize_t) number_pixels; x++)
2512               {
2513                 pixel=SinglePrecisionToHalf(QuantumScale*
2514                   GetPixelRed(image,p));
2515                 q=PopShortPixel(endian,pixel,q);
2516                 pixel=SinglePrecisionToHalf(QuantumScale*
2517                   GetPixelGreen(image,p));
2518                 q=PopShortPixel(endian,pixel,q);
2519                 pixel=SinglePrecisionToHalf(QuantumScale*
2520                   GetPixelBlue(image,p));
2521                 q=PopShortPixel(endian,pixel,q);
2522                 p+=channels;
2523                 q+=quantum_info->pad;
2524               }
2525               break;
2526             }
2527           for (x=0; x < (ssize_t) number_pixels; x++)
2528           {
2529             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2530             q=PopShortPixel(endian,pixel,q);
2531             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2532             q=PopShortPixel(endian,pixel,q);
2533             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2534             q=PopShortPixel(endian,pixel,q);
2535             p+=channels;
2536             q+=quantum_info->pad;
2537           }
2538           break;
2539         }
2540         case 32:
2541         {
2542           register unsigned int
2543             pixel;
2544
2545           if (quantum_info->format == FloatingPointQuantumFormat)
2546             {
2547               for (x=0; x < (ssize_t) number_pixels; x++)
2548               {
2549                 q=PopFloatPixel(&quantum_state,(float)
2550                   GetPixelRed(image,p),q);
2551                 q=PopFloatPixel(&quantum_state,(float)
2552                   GetPixelGreen(image,p),q);
2553                 q=PopFloatPixel(&quantum_state,(float)
2554                   GetPixelBlue(image,p),q);
2555                 p+=channels;
2556                 q+=quantum_info->pad;
2557               }
2558               break;
2559             }
2560           for (x=0; x < (ssize_t) number_pixels; x++)
2561           {
2562             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2563             q=PopLongPixel(endian,pixel,q);
2564             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2565             q=PopLongPixel(endian,pixel,q);
2566             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2567             q=PopLongPixel(endian,pixel,q);
2568             p+=channels;
2569             q+=quantum_info->pad;
2570           }
2571           break;
2572         }
2573         case 64:
2574         {
2575           if (quantum_info->format == FloatingPointQuantumFormat)
2576             {
2577               for (x=0; x < (ssize_t) number_pixels; x++)
2578               {
2579                 q=PopDoublePixel(&quantum_state,(double)
2580                   GetPixelRed(image,p),q);
2581                 q=PopDoublePixel(&quantum_state,(double)
2582                   GetPixelGreen(image,p),q);
2583                 q=PopDoublePixel(&quantum_state,(double)
2584                   GetPixelBlue(image,p),q);
2585                 p+=channels;
2586                 q+=quantum_info->pad;
2587               }
2588               break;
2589             }
2590         }
2591         default:
2592         {
2593           range=GetQuantumRange(quantum_info->depth);
2594           for (x=0; x < (ssize_t) number_pixels; x++)
2595           {
2596             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2597               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2598             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2599               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2600             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2601               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2602             p+=channels;
2603             q+=quantum_info->pad;
2604           }
2605           break;
2606         }
2607       }
2608       break;
2609     }
2610     case RGBAQuantum:
2611     case RGBOQuantum:
2612     case CbYCrAQuantum:
2613     {
2614       switch (quantum_info->depth)
2615       {
2616         case 8:
2617         {
2618           register unsigned char
2619             pixel;
2620
2621           for (x=0; x < (ssize_t) number_pixels; x++)
2622           {
2623             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2624             q=PopCharPixel(pixel,q);
2625             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2626             q=PopCharPixel(pixel,q);
2627             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2628             q=PopCharPixel(pixel,q);
2629             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2630             q=PopCharPixel(pixel,q);
2631             p+=channels;
2632             q+=quantum_info->pad;
2633           }
2634           break;
2635         }
2636         case 10:
2637         {
2638           register unsigned int
2639             pixel;
2640
2641           range=GetQuantumRange(quantum_info->depth);
2642           if (quantum_info->pack == MagickFalse)
2643             {
2644               register ssize_t
2645                 i;
2646
2647               size_t
2648                 quantum;
2649
2650               ssize_t
2651                 n;
2652
2653               n=0;
2654               quantum=0;
2655               pixel=0;
2656               for (x=0; x < (ssize_t) number_pixels; x++)
2657               {
2658                 for (i=0; i < 4; i++)
2659                 {
2660                   switch (i)
2661                   {
2662                     case 0: quantum=GetPixelRed(image,p); break;
2663                     case 1: quantum=GetPixelGreen(image,p); break;
2664                     case 2: quantum=GetPixelBlue(image,p); break;
2665                     case 3: quantum=GetPixelAlpha(image,p); break;
2666                   }
2667                   switch (n % 3)
2668                   {
2669                     case 0:
2670                     {
2671                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2672                         range) << 22);
2673                       break;
2674                     }
2675                     case 1:
2676                     {
2677                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2678                         range) << 12);
2679                       break;
2680                     }
2681                     case 2:
2682                     {
2683                       pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2684                         range) << 2);
2685                       q=PopLongPixel(endian,pixel,q);
2686                       pixel=0;
2687                       break;
2688                     }
2689                   }
2690                   n++;
2691                 }
2692                 p+=channels;
2693                 q+=quantum_info->pad;
2694               }
2695               break;
2696             }
2697           if (quantum_info->quantum == 32UL)
2698             {
2699               for (x=0; x < (ssize_t) number_pixels; x++)
2700               {
2701                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2702                   range);
2703                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2704                   q);
2705                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2706                   range);
2707                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2708                   q);
2709                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2710                   range);
2711                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2712                   q);
2713                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2714                   range);
2715                 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2716                   q);
2717                 p+=channels;
2718                 q+=quantum_info->pad;
2719               }
2720               break;
2721             }
2722           for (x=0; x < (ssize_t) number_pixels; x++)
2723           {
2724             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
2725             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2726             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2727               range);
2728             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2729             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
2730             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2731             pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2732               range);
2733             q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2734             p+=channels;
2735             q+=quantum_info->pad;
2736           }
2737           break;
2738         }
2739         case 16:
2740         {
2741           register unsigned short
2742             pixel;
2743
2744           if (quantum_info->format == FloatingPointQuantumFormat)
2745             {
2746               for (x=0; x < (ssize_t) number_pixels; x++)
2747               {
2748                 pixel=SinglePrecisionToHalf(QuantumScale*
2749                   GetPixelRed(image,p));
2750                 q=PopShortPixel(endian,pixel,q);
2751                 pixel=SinglePrecisionToHalf(QuantumScale*
2752                   GetPixelGreen(image,p));
2753                 q=PopShortPixel(endian,pixel,q);
2754                 pixel=SinglePrecisionToHalf(QuantumScale*
2755                   GetPixelBlue(image,p));
2756                 q=PopShortPixel(endian,pixel,q);
2757                 pixel=SinglePrecisionToHalf(QuantumScale*
2758                   GetPixelAlpha(image,p));
2759                 q=PopShortPixel(endian,pixel,q);
2760                 p+=channels;
2761                 q+=quantum_info->pad;
2762               }
2763               break;
2764             }
2765           for (x=0; x < (ssize_t) number_pixels; x++)
2766           {
2767             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2768             q=PopShortPixel(endian,pixel,q);
2769             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2770             q=PopShortPixel(endian,pixel,q);
2771             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2772             q=PopShortPixel(endian,pixel,q);
2773             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2774             q=PopShortPixel(endian,pixel,q);
2775             p+=channels;
2776             q+=quantum_info->pad;
2777           }
2778           break;
2779         }
2780         case 32:
2781         {
2782           register unsigned int
2783             pixel;
2784
2785           if (quantum_info->format == FloatingPointQuantumFormat)
2786             {
2787               for (x=0; x < (ssize_t) number_pixels; x++)
2788               {
2789                 float
2790                   pixel;
2791
2792                 q=PopFloatPixel(&quantum_state,(float)
2793                   GetPixelRed(image,p),q);
2794                 q=PopFloatPixel(&quantum_state,(float)
2795                   GetPixelGreen(image,p),q);
2796                 q=PopFloatPixel(&quantum_state,(float)
2797                   GetPixelBlue(image,p),q);
2798                 pixel=(float) GetPixelAlpha(image,p);
2799                 q=PopFloatPixel(&quantum_state,pixel,q);
2800                 p+=channels;
2801                 q+=quantum_info->pad;
2802               }
2803               break;
2804             }
2805           for (x=0; x < (ssize_t) number_pixels; x++)
2806           {
2807             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2808             q=PopLongPixel(endian,pixel,q);
2809             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2810             q=PopLongPixel(endian,pixel,q);
2811             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2812             q=PopLongPixel(endian,pixel,q);
2813             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2814             q=PopLongPixel(endian,pixel,q);
2815             p+=channels;
2816             q+=quantum_info->pad;
2817           }
2818           break;
2819         }
2820         case 64:
2821         {
2822           if (quantum_info->format == FloatingPointQuantumFormat)
2823             {
2824               double
2825                 pixel;
2826
2827               for (x=0; x < (ssize_t) number_pixels; x++)
2828               {
2829                 q=PopDoublePixel(&quantum_state,(double)
2830                   GetPixelRed(image,p),q);
2831                 q=PopDoublePixel(&quantum_state,(double)
2832                   GetPixelGreen(image,p),q);
2833                 q=PopDoublePixel(&quantum_state,(double)
2834                   GetPixelBlue(image,p),q);
2835                 pixel=(double) GetPixelAlpha(image,p);
2836                 q=PopDoublePixel(&quantum_state,pixel,q);
2837                 p+=channels;
2838                 q+=quantum_info->pad;
2839               }
2840               break;
2841             }
2842         }
2843         default:
2844         {
2845           range=GetQuantumRange(quantum_info->depth);
2846           for (x=0; x < (ssize_t) number_pixels; x++)
2847           {
2848             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2849               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2850             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2851               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2852             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2853               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2854             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2855               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2856             p+=channels;
2857             q+=quantum_info->pad;
2858           }
2859           break;
2860         }
2861       }
2862       break;
2863     }
2864     case CMYKQuantum:
2865     {
2866       if (image->colorspace != CMYKColorspace)
2867         {
2868           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2869             "ColorSeparatedImageRequired","`%s'",image->filename);
2870           return(extent);
2871         }
2872       switch (quantum_info->depth)
2873       {
2874         case 8:
2875         {
2876           register unsigned char
2877             pixel;
2878
2879           for (x=0; x < (ssize_t) number_pixels; x++)
2880           {
2881             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2882             q=PopCharPixel(pixel,q);
2883             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2884             q=PopCharPixel(pixel,q);
2885             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2886             q=PopCharPixel(pixel,q);
2887             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2888             q=PopCharPixel(pixel,q);
2889             p+=channels;
2890             q+=quantum_info->pad;
2891           }
2892           break;
2893         }
2894         case 16:
2895         {
2896           register unsigned short
2897             pixel;
2898
2899           if (quantum_info->format == FloatingPointQuantumFormat)
2900             {
2901               for (x=0; x < (ssize_t) number_pixels; x++)
2902               {
2903                 pixel=SinglePrecisionToHalf(QuantumScale*
2904                   GetPixelRed(image,p));
2905                 q=PopShortPixel(endian,pixel,q);
2906                 pixel=SinglePrecisionToHalf(QuantumScale*
2907                   GetPixelGreen(image,p));
2908                 q=PopShortPixel(endian,pixel,q);
2909                 pixel=SinglePrecisionToHalf(QuantumScale*
2910                   GetPixelBlue(image,p));
2911                 q=PopShortPixel(endian,pixel,q);
2912                 pixel=SinglePrecisionToHalf(QuantumScale*
2913                   GetPixelBlack(image,p));
2914                 q=PopShortPixel(endian,pixel,q);
2915                 p+=channels;
2916                 q+=quantum_info->pad;
2917               }
2918               break;
2919             }
2920           for (x=0; x < (ssize_t) number_pixels; x++)
2921           {
2922             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2923             q=PopShortPixel(endian,pixel,q);
2924             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2925             q=PopShortPixel(endian,pixel,q);
2926             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2927             q=PopShortPixel(endian,pixel,q);
2928             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2929             q=PopShortPixel(endian,pixel,q);
2930             p+=channels;
2931             q+=quantum_info->pad;
2932           }
2933           break;
2934         }
2935         case 32:
2936         {
2937           register unsigned int
2938             pixel;
2939
2940           if (quantum_info->format == FloatingPointQuantumFormat)
2941             {
2942               for (x=0; x < (ssize_t) number_pixels; x++)
2943               {
2944                 q=PopFloatPixel(&quantum_state,(float)
2945                   GetPixelRed(image,p),q);
2946                 q=PopFloatPixel(&quantum_state,(float)
2947                   GetPixelGreen(image,p),q);
2948                 q=PopFloatPixel(&quantum_state,(float)
2949                   GetPixelBlue(image,p),q);
2950                 q=PopFloatPixel(&quantum_state,(float)
2951                   GetPixelBlack(image,p),q);
2952                 p+=channels;
2953                 q+=quantum_info->pad;
2954               }
2955               break;
2956             }
2957           for (x=0; x < (ssize_t) number_pixels; x++)
2958           {
2959             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2960             q=PopLongPixel(endian,pixel,q);
2961             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2962             q=PopLongPixel(endian,pixel,q);
2963             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2964             q=PopLongPixel(endian,pixel,q);
2965             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2966             q=PopLongPixel(endian,pixel,q);
2967             p+=channels;
2968             q+=quantum_info->pad;
2969           }
2970           break;
2971         }
2972         case 64:
2973         {
2974           if (quantum_info->format == FloatingPointQuantumFormat)
2975             {
2976               for (x=0; x < (ssize_t) number_pixels; x++)
2977               {
2978                 q=PopDoublePixel(&quantum_state,(double)
2979                   GetPixelRed(image,p),q);
2980                 q=PopDoublePixel(&quantum_state,(double)
2981                   GetPixelGreen(image,p),q);
2982                 q=PopDoublePixel(&quantum_state,(double)
2983                   GetPixelBlue(image,p),q);
2984                 q=PopDoublePixel(&quantum_state,(double)
2985                   GetPixelBlack(image,p),q);
2986                 p+=channels;
2987                 q+=quantum_info->pad;
2988               }
2989               break;
2990             }
2991         }
2992         default:
2993         {
2994           range=GetQuantumRange(quantum_info->depth);
2995           for (x=0; x < (ssize_t) number_pixels; x++)
2996           {
2997             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2998               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2999             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3000               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3001             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3002               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3003             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3004               ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3005             p+=channels;
3006             q+=quantum_info->pad;
3007           }
3008           break;
3009         }
3010       }
3011       break;
3012     }
3013     case CMYKAQuantum:
3014     case CMYKOQuantum:
3015     {
3016       if (image->colorspace != CMYKColorspace)
3017         {
3018           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3019             "ColorSeparatedImageRequired","`%s'",image->filename);
3020           return(extent);
3021         }
3022       switch (quantum_info->depth)
3023       {
3024         case 8:
3025         {
3026           register unsigned char
3027             pixel;
3028
3029           for (x=0; x < (ssize_t) number_pixels; x++)
3030           {
3031             pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3032             q=PopCharPixel(pixel,q);
3033             pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3034             q=PopCharPixel(pixel,q);
3035             pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3036             q=PopCharPixel(pixel,q);
3037             pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
3038             q=PopCharPixel(pixel,q);
3039             pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
3040             q=PopCharPixel(pixel,q);
3041             p+=channels;
3042             q+=quantum_info->pad;
3043           }
3044           break;
3045         }
3046         case 16:
3047         {
3048           register unsigned short
3049             pixel;
3050
3051           if (quantum_info->format == FloatingPointQuantumFormat)
3052             {
3053               for (x=0; x < (ssize_t) number_pixels; x++)
3054               {
3055                 pixel=SinglePrecisionToHalf(QuantumScale*
3056                   GetPixelRed(image,p));
3057                 q=PopShortPixel(endian,pixel,q);
3058                 pixel=SinglePrecisionToHalf(QuantumScale*
3059                   GetPixelGreen(image,p));
3060                 q=PopShortPixel(endian,pixel,q);
3061                 pixel=SinglePrecisionToHalf(QuantumScale*
3062                   GetPixelBlue(image,p));
3063                 q=PopShortPixel(endian,pixel,q);
3064                 pixel=SinglePrecisionToHalf(QuantumScale*
3065                   GetPixelBlack(image,p));
3066                 q=PopShortPixel(endian,pixel,q);
3067                 pixel=SinglePrecisionToHalf(QuantumScale*
3068                   GetPixelAlpha(image,p));
3069                 q=PopShortPixel(endian,pixel,q);
3070                 p+=channels;
3071                 q+=quantum_info->pad;
3072               }
3073               break;
3074             }
3075           for (x=0; x < (ssize_t) number_pixels; x++)
3076           {
3077             pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3078             q=PopShortPixel(endian,pixel,q);
3079             pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3080             q=PopShortPixel(endian,pixel,q);
3081             pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3082             q=PopShortPixel(endian,pixel,q);
3083             pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
3084             q=PopShortPixel(endian,pixel,q);
3085             pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
3086             q=PopShortPixel(endian,pixel,q);
3087             p+=channels;
3088             q+=quantum_info->pad;
3089           }
3090           break;
3091         }
3092         case 32:
3093         {
3094           register unsigned int
3095             pixel;
3096
3097           if (quantum_info->format == FloatingPointQuantumFormat)
3098             {
3099               for (x=0; x < (ssize_t) number_pixels; x++)
3100               {
3101                 float
3102                   pixel;
3103
3104                 q=PopFloatPixel(&quantum_state,(float)
3105                   GetPixelRed(image,p),q);
3106                 q=PopFloatPixel(&quantum_state,(float)
3107                   GetPixelGreen(image,p),q);
3108                 q=PopFloatPixel(&quantum_state,(float)
3109                   GetPixelBlue(image,p),q);
3110                 q=PopFloatPixel(&quantum_state,(float)
3111                   GetPixelBlack(image,p),q);
3112                 pixel=(float) (GetPixelAlpha(image,p));
3113                 q=PopFloatPixel(&quantum_state,pixel,q);
3114                 p+=channels;
3115                 q+=quantum_info->pad;
3116               }
3117               break;
3118             }
3119           for (x=0; x < (ssize_t) number_pixels; x++)
3120           {
3121             pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3122             q=PopLongPixel(endian,pixel,q);
3123             pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3124             q=PopLongPixel(endian,pixel,q);
3125             pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3126             q=PopLongPixel(endian,pixel,q);
3127             pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
3128             q=PopLongPixel(endian,pixel,q);
3129             pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
3130             q=PopLongPixel(endian,pixel,q);
3131             p+=channels;
3132             q+=quantum_info->pad;
3133           }
3134           break;
3135         }
3136         case 64:
3137         {
3138           if (quantum_info->format == FloatingPointQuantumFormat)
3139             {
3140               double
3141                 pixel;
3142
3143               for (x=0; x < (ssize_t) number_pixels; x++)
3144               {
3145                 q=PopDoublePixel(&quantum_state,(double)
3146                   GetPixelRed(image,p),q);
3147                 q=PopDoublePixel(&quantum_state,(double)
3148                   GetPixelGreen(image,p),q);
3149                 q=PopDoublePixel(&quantum_state,(double)
3150                   GetPixelBlue(image,p),q);
3151                 q=PopDoublePixel(&quantum_state,(double)
3152                   GetPixelBlack(image,p),q);
3153                 pixel=(double) (GetPixelAlpha(image,p));
3154                 q=PopDoublePixel(&quantum_state,pixel,q);
3155                 p+=channels;
3156                 q+=quantum_info->pad;
3157               }
3158               break;
3159             }
3160         }
3161         default:
3162         {
3163           range=GetQuantumRange(quantum_info->depth);
3164           for (x=0; x < (ssize_t) number_pixels; x++)
3165           {
3166             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3167               ScaleQuantumToAny(GetPixelRed(image,p),range),q);
3168             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3169               ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3170             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3171               ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3172             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3173               ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3174             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3175               ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
3176             p+=channels;
3177             q+=quantum_info->pad;
3178           }
3179           break;
3180         }
3181       }
3182       break;
3183     }
3184     case CbYCrYQuantum:
3185     {
3186       Quantum
3187         cbcr[4];
3188
3189       register ssize_t
3190         i;
3191
3192       register unsigned int
3193         pixel;
3194
3195       size_t
3196         quantum;
3197
3198      ssize_t
3199         n;
3200
3201       n=0;
3202       quantum=0;
3203       range=GetQuantumRange(quantum_info->depth);
3204       switch (quantum_info->depth)
3205       {
3206         case 10:
3207         {
3208           if (quantum_info->pack == MagickFalse)
3209             {
3210               for (x=0; x < (ssize_t) number_pixels; x+=2)
3211               {
3212                 for (i=0; i < 4; i++)
3213                 {
3214                   switch (n % 3)
3215                   {
3216                     case 0:
3217                     {
3218                       quantum=GetPixelRed(image,p);
3219                       break;
3220                     }
3221                     case 1:
3222                     {
3223                       quantum=GetPixelGreen(image,p);
3224                       break;
3225                     }
3226                     case 2:
3227                     {
3228                       quantum=GetPixelBlue(image,p);
3229                       break;
3230                     }
3231                   }
3232                   cbcr[i]=(Quantum) quantum;
3233                   n++;
3234                 }
3235                 pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 | (size_t)
3236                   (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3237                 q=PopLongPixel(endian,pixel,q);
3238                 p+=channels;
3239                 pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 | (size_t)
3240                   (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3241                 q=PopLongPixel(endian,pixel,q);
3242                 p+=channels;
3243                 q+=quantum_info->pad;
3244               }
3245               break;
3246             }
3247           break;
3248         }
3249         default:
3250         {
3251           for (x=0; x < (ssize_t) number_pixels; x+=2)
3252           {
3253             for (i=0; i < 4; i++)
3254             {
3255               switch (n % 3)
3256               {
3257                 case 0:
3258                 {
3259                   quantum=GetPixelRed(image,p);
3260                   break;
3261                 }
3262                 case 1:
3263                 {
3264                   quantum=GetPixelGreen(image,p);
3265                   break;
3266                 }
3267                 case 2:
3268                 {
3269                   quantum=GetPixelBlue(image,p);
3270                   break;
3271                 }
3272               }
3273               cbcr[i]=(Quantum) quantum;
3274               n++;
3275             }
3276             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3277               ScaleQuantumToAny(cbcr[1],range),q);
3278             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3279               ScaleQuantumToAny(cbcr[0],range),q);
3280             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3281               ScaleQuantumToAny(cbcr[2],range),q);
3282             p+=channels;
3283             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3284               ScaleQuantumToAny(cbcr[3],range),q);
3285             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3286               ScaleQuantumToAny(cbcr[0],range),q);
3287             q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3288               ScaleQuantumToAny(cbcr[2],range),q);
3289             p+=channels;
3290             q+=quantum_info->pad;
3291           }
3292           break;
3293         }
3294       }
3295       break;
3296     }
3297     default:
3298       break;
3299   }
3300   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3301     {
3302       Quantum
3303         quantum;
3304
3305       register Quantum
3306         *restrict q;
3307
3308       q=GetAuthenticPixelQueue(image);
3309       if (image_view != (CacheView *) NULL)
3310         q=GetCacheViewAuthenticPixelQueue(image_view);
3311       for (x=0; x < (ssize_t) number_pixels; x++)
3312       {
3313         quantum=GetPixelRed(image,q);
3314         SetPixelRed(image,GetPixelGreen(image,q),q);
3315         SetPixelGreen(image,quantum,q);
3316         q+=channels;
3317       }
3318     }
3319   if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
3320       (quantum_type == BGROQuantum))
3321     {
3322       register Quantum
3323         *restrict q;
3324
3325       q=GetAuthenticPixelQueue(image);
3326       if (image_view != (CacheView *) NULL)
3327         q=GetCacheViewAuthenticPixelQueue(image_view);
3328       for (x=0; x < (ssize_t) number_pixels; x++)
3329       {
3330         SetPixelAlpha(image,GetPixelAlpha(image,q),q);
3331         q+=channels;
3332       }
3333     }
3334   return(extent);
3335 }