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