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