]> 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 ExportBGROQuantum(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   assert(exception != (ExceptionInfo *) NULL);
900   assert(exception->signature == MagickSignature);
901   switch (quantum_info->depth)
902   {
903     case 8:
904     {
905       register unsigned char
906         pixel;
907
908       for (x=0; x < (ssize_t) number_pixels; x++)
909       {
910         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
911         q=PopCharPixel(pixel,q);
912         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
913         q=PopCharPixel(pixel,q);
914         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
915         q=PopCharPixel(pixel,q);
916         pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
917         q=PopCharPixel(pixel,q);
918         p+=GetPixelChannels(image);
919         q+=quantum_info->pad;
920       }
921       break;
922     }
923     case 10:
924     {
925       register unsigned int
926         pixel;
927
928       range=GetQuantumRange(quantum_info->depth);
929       if (quantum_info->pack == MagickFalse)
930         {
931           register ssize_t
932             i;
933
934           size_t
935             quantum;
936
937           ssize_t
938             n;
939
940           n=0;
941           quantum=0;
942           pixel=0;
943           for (x=0; x < (ssize_t) number_pixels; x++)
944           {
945             for (i=0; i < 4; i++)
946             {
947               switch (i)
948               {
949                 case 0: quantum=GetPixelRed(image,p); break;
950                 case 1: quantum=GetPixelGreen(image,p); break;
951                 case 2: quantum=GetPixelBlue(image,p); break;
952                 case 3: quantum=GetPixelOpacity(image,p); break;
953               }
954               switch (n % 3)
955               {
956                 case 0:
957                 {
958                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
959                     range) << 22);
960                   break;
961                 }
962                 case 1:
963                 {
964                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
965                     range) << 12);
966                   break;
967                 }
968                 case 2:
969                 {
970                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
971                     range) << 2);
972                   q=PopLongPixel(quantum_info->endian,pixel,q);
973                   pixel=0;
974                   break;
975                 }
976               }
977               n++;
978             }
979             p+=GetPixelChannels(image);
980             q+=quantum_info->pad;
981           }
982           break;
983         }
984       if (quantum_info->quantum == 32UL)
985         {
986           for (x=0; x < (ssize_t) number_pixels; x++)
987           {
988             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
989             q=PopQuantumLongPixel(quantum_info,pixel,q);
990             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
991               range);
992             q=PopQuantumLongPixel(quantum_info,pixel,q);
993             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
994             q=PopQuantumLongPixel(quantum_info,pixel,q);
995             pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),
996               range);
997             q=PopQuantumLongPixel(quantum_info,pixel,q);
998             p+=GetPixelChannels(image);
999             q+=quantum_info->pad;
1000           }
1001           break;
1002         }
1003       for (x=0; x < (ssize_t) number_pixels; x++)
1004       {
1005         pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
1006         q=PopQuantumPixel(quantum_info,pixel,q);
1007         pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
1008         q=PopQuantumPixel(quantum_info,pixel,q);
1009         pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
1010         q=PopQuantumPixel(quantum_info,pixel,q);
1011         pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),range);
1012         q=PopQuantumPixel(quantum_info,pixel,q);
1013         p+=GetPixelChannels(image);
1014         q+=quantum_info->pad;
1015       }
1016       break;
1017     }
1018     case 16:
1019     {
1020       register unsigned short
1021         pixel;
1022
1023       if (quantum_info->format == FloatingPointQuantumFormat)
1024         {
1025           for (x=0; x < (ssize_t) number_pixels; x++)
1026           {
1027             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
1028             q=PopShortPixel(quantum_info->endian,pixel,q);
1029             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
1030             q=PopShortPixel(quantum_info->endian,pixel,q);
1031             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
1032             q=PopShortPixel(quantum_info->endian,pixel,q);
1033             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelOpacity(image,p));
1034             q=PopShortPixel(quantum_info->endian,pixel,q);
1035             p+=GetPixelChannels(image);
1036             q+=quantum_info->pad;
1037           }
1038           break;
1039         }
1040       for (x=0; x < (ssize_t) number_pixels; x++)
1041       {
1042         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1043         q=PopShortPixel(quantum_info->endian,pixel,q);
1044         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1045         q=PopShortPixel(quantum_info->endian,pixel,q);
1046         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1047         q=PopShortPixel(quantum_info->endian,pixel,q);
1048         pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
1049         q=PopShortPixel(quantum_info->endian,pixel,q);
1050         p+=GetPixelChannels(image);
1051         q+=quantum_info->pad;
1052       }
1053       break;
1054     }
1055     case 32:
1056     {
1057       register unsigned int
1058         pixel;
1059
1060       if (quantum_info->format == FloatingPointQuantumFormat)
1061         {
1062           for (x=0; x < (ssize_t) number_pixels; x++)
1063           {
1064             float
1065               pixel;
1066
1067             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1068             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1069             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1070             pixel=(float) GetPixelOpacity(image,p);
1071             q=PopFloatPixel(quantum_info,pixel,q);
1072             p+=GetPixelChannels(image);
1073             q+=quantum_info->pad;
1074           }
1075           break;
1076         }
1077       for (x=0; x < (ssize_t) number_pixels; x++)
1078       {
1079         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1080         q=PopLongPixel(quantum_info->endian,pixel,q);
1081         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1082         q=PopLongPixel(quantum_info->endian,pixel,q);
1083         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1084         q=PopLongPixel(quantum_info->endian,pixel,q);
1085         pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
1086         q=PopLongPixel(quantum_info->endian,pixel,q);
1087         p+=GetPixelChannels(image);
1088         q+=quantum_info->pad;
1089       }
1090       break;
1091     }
1092     case 64:
1093     {
1094       if (quantum_info->format == FloatingPointQuantumFormat)
1095         {
1096           double
1097             pixel;
1098
1099           for (x=0; x < (ssize_t) number_pixels; x++)
1100           {
1101             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1102             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1103             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1104             pixel=(double) GetPixelOpacity(image,p);
1105             q=PopDoublePixel(quantum_info,pixel,q);
1106             p+=GetPixelChannels(image);
1107             q+=quantum_info->pad;
1108           }
1109           break;
1110         }
1111     }
1112     default:
1113     {
1114       range=GetQuantumRange(quantum_info->depth);
1115       for (x=0; x < (ssize_t) number_pixels; x++)
1116       {
1117         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1118           range),q);
1119         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1120           range),q);
1121         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1122           range),q);
1123         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p),
1124           range),q);
1125         p+=GetPixelChannels(image);
1126         q+=quantum_info->pad;
1127       }
1128       break;
1129     }
1130   }
1131 }
1132
1133 static void ExportBlackQuantum(const Image *image,QuantumInfo *quantum_info,
1134   const MagickSizeType number_pixels,const Quantum *restrict p,
1135   unsigned char *restrict q,ExceptionInfo *exception)
1136 {
1137   QuantumAny
1138     range;
1139
1140   register ssize_t
1141     x;
1142
1143   if (image->colorspace != CMYKColorspace)
1144     {
1145       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1146         "ColorSeparatedImageRequired","`%s'",image->filename);
1147       return;
1148     }
1149   switch (quantum_info->depth)
1150   {
1151     case 8:
1152     {
1153       register unsigned char
1154         pixel;
1155
1156       for (x=0; x < (ssize_t) number_pixels; x++)
1157       {
1158         pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
1159         q=PopCharPixel(pixel,q);
1160         p+=GetPixelChannels(image);
1161         q+=quantum_info->pad;
1162       }
1163       break;
1164     }
1165     case 16:
1166     {
1167       register unsigned short
1168         pixel;
1169
1170       if (quantum_info->format == FloatingPointQuantumFormat)
1171         {
1172           for (x=0; x < (ssize_t) number_pixels; x++)
1173           {
1174             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlack(image,p));
1175             q=PopShortPixel(quantum_info->endian,pixel,q);
1176             p+=GetPixelChannels(image);
1177             q+=quantum_info->pad;
1178           }
1179           break;
1180         }
1181       for (x=0; x < (ssize_t) number_pixels; x++)
1182       {
1183         pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
1184         q=PopShortPixel(quantum_info->endian,pixel,q);
1185         p+=GetPixelChannels(image);
1186         q+=quantum_info->pad;
1187       }
1188       break;
1189     }
1190     case 32:
1191     {
1192       register unsigned int
1193         pixel;
1194
1195       if (quantum_info->format == FloatingPointQuantumFormat)
1196         {
1197           for (x=0; x < (ssize_t) number_pixels; x++)
1198           {
1199             q=PopFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1200             p+=GetPixelChannels(image);
1201             q+=quantum_info->pad;
1202           }
1203           break;
1204         }
1205       for (x=0; x < (ssize_t) number_pixels; x++)
1206       {
1207         pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1208         q=PopLongPixel(quantum_info->endian,pixel,q);
1209         p+=GetPixelChannels(image);
1210         q+=quantum_info->pad;
1211       }
1212       break;
1213     }
1214     case 64:
1215     {
1216       if (quantum_info->format == FloatingPointQuantumFormat)
1217         {
1218           for (x=0; x < (ssize_t) number_pixels; x++)
1219           {
1220             q=PopDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1221             p+=GetPixelChannels(image);
1222             q+=quantum_info->pad;
1223           }
1224           break;
1225         }
1226     }
1227     default:
1228     {
1229       range=GetQuantumRange(quantum_info->depth);
1230       for (x=0; x < (ssize_t) number_pixels; x++)
1231       {
1232         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1233           range),q);
1234         p+=GetPixelChannels(image);
1235         q+=quantum_info->pad;
1236       }
1237       break;
1238     }
1239   }
1240 }
1241
1242 static void ExportBlueQuantum(const Image *image,QuantumInfo *quantum_info,
1243   const MagickSizeType number_pixels,const Quantum *restrict p,
1244   unsigned char *restrict q,ExceptionInfo *exception)
1245 {
1246   QuantumAny
1247     range;
1248
1249   register ssize_t
1250     x;
1251
1252   assert(exception != (ExceptionInfo *) NULL);
1253   assert(exception->signature == MagickSignature);
1254   switch (quantum_info->depth)
1255   {
1256     case 8:
1257     {
1258       register unsigned char
1259         pixel;
1260
1261       for (x=0; x < (ssize_t) number_pixels; x++)
1262       {
1263         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1264         q=PopCharPixel(pixel,q);
1265         p+=GetPixelChannels(image);
1266         q+=quantum_info->pad;
1267       }
1268       break;
1269     }
1270     case 16:
1271     {
1272       register unsigned short
1273         pixel;
1274
1275       if (quantum_info->format == FloatingPointQuantumFormat)
1276         {
1277           for (x=0; x < (ssize_t) number_pixels; x++)
1278           {
1279             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
1280             q=PopShortPixel(quantum_info->endian,pixel,q);
1281             p+=GetPixelChannels(image);
1282             q+=quantum_info->pad;
1283           }
1284           break;
1285         }
1286       for (x=0; x < (ssize_t) number_pixels; x++)
1287       {
1288         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1289         q=PopShortPixel(quantum_info->endian,pixel,q);
1290         p+=GetPixelChannels(image);
1291         q+=quantum_info->pad;
1292       }
1293       break;
1294     }
1295     case 32:
1296     {
1297       register unsigned int
1298         pixel;
1299
1300       if (quantum_info->format == FloatingPointQuantumFormat)
1301         {
1302           for (x=0; x < (ssize_t) number_pixels; x++)
1303           {
1304             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1305             p+=GetPixelChannels(image);
1306             q+=quantum_info->pad;
1307           }
1308           break;
1309         }
1310       for (x=0; x < (ssize_t) number_pixels; x++)
1311       {
1312         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1313         q=PopLongPixel(quantum_info->endian,pixel,q);
1314         p+=GetPixelChannels(image);
1315         q+=quantum_info->pad;
1316       }
1317       break;
1318     }
1319     case 64:
1320     {
1321       if (quantum_info->format == FloatingPointQuantumFormat)
1322         {
1323           for (x=0; x < (ssize_t) number_pixels; x++)
1324           {
1325             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1326             p+=GetPixelChannels(image);
1327             q+=quantum_info->pad;
1328           }
1329           break;
1330         }
1331     }
1332     default:
1333     {
1334       range=GetQuantumRange(quantum_info->depth);
1335       for (x=0; x < (ssize_t) number_pixels; x++)
1336       {
1337         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1338           range),q);
1339         p+=GetPixelChannels(image);
1340         q+=quantum_info->pad;
1341       }
1342       break;
1343     }
1344   }
1345 }
1346
1347 static void ExportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info,
1348   const MagickSizeType number_pixels,const Quantum *restrict p,
1349   unsigned char *restrict q,ExceptionInfo *exception)
1350 {
1351   Quantum
1352     cbcr[4];
1353
1354   register ssize_t
1355     i,
1356     x;
1357
1358   register unsigned int
1359     pixel;
1360
1361   size_t
1362     quantum;
1363
1364   ssize_t
1365     n;
1366
1367   assert(exception != (ExceptionInfo *) NULL);
1368   assert(exception->signature == MagickSignature);
1369   n=0;
1370   quantum=0;
1371   switch (quantum_info->depth)
1372   {
1373     case 10:
1374     {
1375       if (quantum_info->pack == MagickFalse)
1376         {
1377           for (x=0; x < (ssize_t) number_pixels; x+=2)
1378           {
1379             for (i=0; i < 4; i++)
1380             {
1381               switch (n % 3)
1382               {
1383                 case 0:
1384                 {
1385                   quantum=GetPixelRed(image,p);
1386                   break;
1387                 }
1388                 case 1:
1389                 {
1390                   quantum=GetPixelGreen(image,p);
1391                   break;
1392                 }
1393                 case 2:
1394                 {
1395                   quantum=GetPixelBlue(image,p);
1396                   break;
1397                 }
1398               }
1399               cbcr[i]=(Quantum) quantum;
1400               n++;
1401             }
1402             pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 | (size_t)
1403               (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
1404             q=PopLongPixel(quantum_info->endian,pixel,q);
1405             p+=GetPixelChannels(image);
1406             pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 | (size_t)
1407               (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
1408             q=PopLongPixel(quantum_info->endian,pixel,q);
1409             p+=GetPixelChannels(image);
1410             q+=quantum_info->pad;
1411           }
1412           break;
1413         }
1414       break;
1415     }
1416     default:
1417     {
1418       QuantumAny
1419         range;
1420
1421       for (x=0; x < (ssize_t) number_pixels; x+=2)
1422       {
1423         for (i=0; i < 4; i++)
1424         {
1425           switch (n % 3)
1426           {
1427             case 0:
1428             {
1429               quantum=GetPixelRed(image,p);
1430               break;
1431             }
1432             case 1:
1433             {
1434               quantum=GetPixelGreen(image,p);
1435               break;
1436             }
1437             case 2:
1438             {
1439               quantum=GetPixelBlue(image,p);
1440               break;
1441             }
1442           }
1443           cbcr[i]=(Quantum) quantum;
1444           n++;
1445         }
1446         range=GetQuantumRange(quantum_info->depth);
1447         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[1],range),q);
1448         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[0],range),q);
1449         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[2],range),q);
1450         p+=GetPixelChannels(image);
1451         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[3],range),q);
1452         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[0],range),q);
1453         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(cbcr[2],range),q);
1454         p+=GetPixelChannels(image);
1455         q+=quantum_info->pad;
1456       }
1457       break;
1458     }
1459   }
1460 }
1461
1462 static void ExportCMYKQuantum(const Image *image,QuantumInfo *quantum_info,
1463   const MagickSizeType number_pixels,const Quantum *restrict p,
1464   unsigned char *restrict q,ExceptionInfo *exception)
1465 {
1466   register ssize_t
1467     x;
1468
1469   if (image->colorspace != CMYKColorspace)
1470     {
1471       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1472         "ColorSeparatedImageRequired","`%s'",image->filename);
1473       return;
1474     }
1475   switch (quantum_info->depth)
1476   {
1477     case 8:
1478     {
1479       register unsigned char
1480         pixel;
1481
1482       for (x=0; x < (ssize_t) number_pixels; x++)
1483       {
1484         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1485         q=PopCharPixel(pixel,q);
1486         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1487         q=PopCharPixel(pixel,q);
1488         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1489         q=PopCharPixel(pixel,q);
1490         pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
1491         q=PopCharPixel(pixel,q);
1492         p+=GetPixelChannels(image);
1493         q+=quantum_info->pad;
1494       }
1495       break;
1496     }
1497     case 16:
1498     {
1499       register unsigned short
1500         pixel;
1501
1502       if (quantum_info->format == FloatingPointQuantumFormat)
1503         {
1504           for (x=0; x < (ssize_t) number_pixels; x++)
1505           {
1506             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
1507             q=PopShortPixel(quantum_info->endian,pixel,q);
1508             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
1509             q=PopShortPixel(quantum_info->endian,pixel,q);
1510             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
1511             q=PopShortPixel(quantum_info->endian,pixel,q);
1512             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlack(image,p));
1513             q=PopShortPixel(quantum_info->endian,pixel,q);
1514             p+=GetPixelChannels(image);
1515             q+=quantum_info->pad;
1516           }
1517           break;
1518         }
1519       for (x=0; x < (ssize_t) number_pixels; x++)
1520       {
1521         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1522         q=PopShortPixel(quantum_info->endian,pixel,q);
1523         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1524         q=PopShortPixel(quantum_info->endian,pixel,q);
1525         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1526         q=PopShortPixel(quantum_info->endian,pixel,q);
1527         pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
1528         q=PopShortPixel(quantum_info->endian,pixel,q);
1529         p+=GetPixelChannels(image);
1530         q+=quantum_info->pad;
1531       }
1532       break;
1533     }
1534     case 32:
1535     {
1536       register unsigned int
1537         pixel;
1538
1539       if (quantum_info->format == FloatingPointQuantumFormat)
1540         {
1541           for (x=0; x < (ssize_t) number_pixels; x++)
1542           {
1543             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1544             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1545             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1546             q=PopFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1547             p+=GetPixelChannels(image);
1548             q+=quantum_info->pad;
1549           }
1550           break;
1551         }
1552       for (x=0; x < (ssize_t) number_pixels; x++)
1553       {
1554         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1555         q=PopLongPixel(quantum_info->endian,pixel,q);
1556         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1557         q=PopLongPixel(quantum_info->endian,pixel,q);
1558         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1559         q=PopLongPixel(quantum_info->endian,pixel,q);
1560         pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1561         q=PopLongPixel(quantum_info->endian,pixel,q);
1562         p+=GetPixelChannels(image);
1563         q+=quantum_info->pad;
1564       }
1565       break;
1566     }
1567     case 64:
1568     {
1569       if (quantum_info->format == FloatingPointQuantumFormat)
1570         {
1571           for (x=0; x < (ssize_t) number_pixels; x++)
1572           {
1573             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1574             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1575             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1576             q=PopDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1577             p+=GetPixelChannels(image);
1578             q+=quantum_info->pad;
1579           }
1580           break;
1581         }
1582     }
1583     default:
1584     {
1585       QuantumAny
1586         range;
1587
1588       range=GetQuantumRange(quantum_info->depth);
1589       for (x=0; x < (ssize_t) number_pixels; x++)
1590       {
1591         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1592           range),q);
1593         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1594           range),q);
1595         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1596           range),q);
1597         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1598           range),q);
1599         p+=GetPixelChannels(image);
1600         q+=quantum_info->pad;
1601       }
1602       break;
1603     }
1604   }
1605 }
1606
1607 static void ExportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info,
1608   const MagickSizeType number_pixels,const Quantum *restrict p,
1609   unsigned char *restrict q,ExceptionInfo *exception)
1610 {
1611   register ssize_t
1612     x;
1613
1614   if (image->colorspace != CMYKColorspace)
1615     {
1616       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1617         "ColorSeparatedImageRequired","`%s'",image->filename);
1618       return;
1619     }
1620   switch (quantum_info->depth)
1621   {
1622     case 8:
1623     {
1624       register unsigned char
1625         pixel;
1626
1627       for (x=0; x < (ssize_t) number_pixels; x++)
1628       {
1629         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1630         q=PopCharPixel(pixel,q);
1631         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1632         q=PopCharPixel(pixel,q);
1633         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1634         q=PopCharPixel(pixel,q);
1635         pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
1636         q=PopCharPixel(pixel,q);
1637         pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1638         q=PopCharPixel(pixel,q);
1639         p+=GetPixelChannels(image);
1640         q+=quantum_info->pad;
1641       }
1642       break;
1643     }
1644     case 16:
1645     {
1646       register unsigned short
1647         pixel;
1648
1649       if (quantum_info->format == FloatingPointQuantumFormat)
1650         {
1651           for (x=0; x < (ssize_t) number_pixels; x++)
1652           {
1653             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
1654             q=PopShortPixel(quantum_info->endian,pixel,q);
1655             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
1656             q=PopShortPixel(quantum_info->endian,pixel,q);
1657             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
1658             q=PopShortPixel(quantum_info->endian,pixel,q);
1659             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlack(image,p));
1660             q=PopShortPixel(quantum_info->endian,pixel,q);
1661             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelAlpha(image,p));
1662             q=PopShortPixel(quantum_info->endian,pixel,q);
1663             p+=GetPixelChannels(image);
1664             q+=quantum_info->pad;
1665           }
1666           break;
1667         }
1668       for (x=0; x < (ssize_t) number_pixels; x++)
1669       {
1670         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1671         q=PopShortPixel(quantum_info->endian,pixel,q);
1672         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1673         q=PopShortPixel(quantum_info->endian,pixel,q);
1674         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1675         q=PopShortPixel(quantum_info->endian,pixel,q);
1676         pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
1677         q=PopShortPixel(quantum_info->endian,pixel,q);
1678         pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1679         q=PopShortPixel(quantum_info->endian,pixel,q);
1680         p+=GetPixelChannels(image);
1681         q+=quantum_info->pad;
1682       }
1683       break;
1684     }
1685     case 32:
1686     {
1687       register unsigned int
1688         pixel;
1689
1690       if (quantum_info->format == FloatingPointQuantumFormat)
1691         {
1692           for (x=0; x < (ssize_t) number_pixels; x++)
1693           {
1694             float
1695               pixel;
1696
1697             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1698             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1699             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1700             q=PopFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1701             pixel=(float) (GetPixelAlpha(image,p));
1702             q=PopFloatPixel(quantum_info,pixel,q);
1703             p+=GetPixelChannels(image);
1704             q+=quantum_info->pad;
1705           }
1706           break;
1707         }
1708       for (x=0; x < (ssize_t) number_pixels; x++)
1709       {
1710         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1711         q=PopLongPixel(quantum_info->endian,pixel,q);
1712         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1713         q=PopLongPixel(quantum_info->endian,pixel,q);
1714         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1715         q=PopLongPixel(quantum_info->endian,pixel,q);
1716         pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1717         q=PopLongPixel(quantum_info->endian,pixel,q);
1718         pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1719         q=PopLongPixel(quantum_info->endian,pixel,q);
1720         p+=GetPixelChannels(image);
1721         q+=quantum_info->pad;
1722       }
1723       break;
1724     }
1725     case 64:
1726     {
1727       if (quantum_info->format == FloatingPointQuantumFormat)
1728         {
1729           double
1730             pixel;
1731
1732           for (x=0; x < (ssize_t) number_pixels; x++)
1733           {
1734             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1735             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1736             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1737             q=PopDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1738             pixel=(double) (GetPixelAlpha(image,p));
1739             q=PopDoublePixel(quantum_info,pixel,q);
1740             p+=GetPixelChannels(image);
1741             q+=quantum_info->pad;
1742           }
1743           break;
1744         }
1745     }
1746     default:
1747     {
1748       QuantumAny
1749         range;
1750
1751       range=GetQuantumRange(quantum_info->depth);
1752       for (x=0; x < (ssize_t) number_pixels; x++)
1753       {
1754         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1755           range),q);
1756         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1757           range),q);
1758         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1759           range),q);
1760         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1761           range),q);
1762         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
1763           range),q);
1764         p+=GetPixelChannels(image);
1765         q+=quantum_info->pad;
1766       }
1767       break;
1768     }
1769   }
1770 }
1771
1772 static void ExportCMYKOQuantum(const Image *image,QuantumInfo *quantum_info,
1773   const MagickSizeType number_pixels,const Quantum *restrict p,
1774   unsigned char *restrict q,ExceptionInfo *exception)
1775 {
1776   register ssize_t
1777     x;
1778
1779   if (image->colorspace != CMYKColorspace)
1780     {
1781       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1782         "ColorSeparatedImageRequired","`%s'",image->filename);
1783       return;
1784     }
1785   switch (quantum_info->depth)
1786   {
1787     case 8:
1788     {
1789       register unsigned char
1790         pixel;
1791
1792       for (x=0; x < (ssize_t) number_pixels; x++)
1793       {
1794         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1795         q=PopCharPixel(pixel,q);
1796         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1797         q=PopCharPixel(pixel,q);
1798         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1799         q=PopCharPixel(pixel,q);
1800         pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
1801         q=PopCharPixel(pixel,q);
1802         pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
1803         q=PopCharPixel(pixel,q);
1804         p+=GetPixelChannels(image);
1805         q+=quantum_info->pad;
1806       }
1807       break;
1808     }
1809     case 16:
1810     {
1811       register unsigned short
1812         pixel;
1813
1814       if (quantum_info->format == FloatingPointQuantumFormat)
1815         {
1816           for (x=0; x < (ssize_t) number_pixels; x++)
1817           {
1818             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
1819             q=PopShortPixel(quantum_info->endian,pixel,q);
1820             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
1821             q=PopShortPixel(quantum_info->endian,pixel,q);
1822             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
1823             q=PopShortPixel(quantum_info->endian,pixel,q);
1824             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlack(image,p));
1825             q=PopShortPixel(quantum_info->endian,pixel,q);
1826             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelOpacity(image,p));
1827             q=PopShortPixel(quantum_info->endian,pixel,q);
1828             p+=GetPixelChannels(image);
1829             q+=quantum_info->pad;
1830           }
1831           break;
1832         }
1833       for (x=0; x < (ssize_t) number_pixels; x++)
1834       {
1835         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1836         q=PopShortPixel(quantum_info->endian,pixel,q);
1837         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1838         q=PopShortPixel(quantum_info->endian,pixel,q);
1839         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1840         q=PopShortPixel(quantum_info->endian,pixel,q);
1841         pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
1842         q=PopShortPixel(quantum_info->endian,pixel,q);
1843         pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
1844         q=PopShortPixel(quantum_info->endian,pixel,q);
1845         p+=GetPixelChannels(image);
1846         q+=quantum_info->pad;
1847       }
1848       break;
1849     }
1850     case 32:
1851     {
1852       register unsigned int
1853         pixel;
1854
1855       if (quantum_info->format == FloatingPointQuantumFormat)
1856         {
1857           for (x=0; x < (ssize_t) number_pixels; x++)
1858           {
1859             float
1860               pixel;
1861
1862             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1863             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1864             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1865             q=PopFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1866             pixel=(float) (GetPixelOpacity(image,p));
1867             q=PopFloatPixel(quantum_info,pixel,q);
1868             p+=GetPixelChannels(image);
1869             q+=quantum_info->pad;
1870           }
1871           break;
1872         }
1873       for (x=0; x < (ssize_t) number_pixels; x++)
1874       {
1875         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1876         q=PopLongPixel(quantum_info->endian,pixel,q);
1877         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1878         q=PopLongPixel(quantum_info->endian,pixel,q);
1879         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1880         q=PopLongPixel(quantum_info->endian,pixel,q);
1881         pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1882         q=PopLongPixel(quantum_info->endian,pixel,q);
1883         pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
1884         q=PopLongPixel(quantum_info->endian,pixel,q);
1885         p+=GetPixelChannels(image);
1886         q+=quantum_info->pad;
1887       }
1888       break;
1889     }
1890     case 64:
1891     {
1892       if (quantum_info->format == FloatingPointQuantumFormat)
1893         {
1894           double
1895             pixel;
1896
1897           for (x=0; x < (ssize_t) number_pixels; x++)
1898           {
1899             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1900             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1901             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1902             q=PopDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1903             pixel=(double) (GetPixelOpacity(image,p));
1904             q=PopDoublePixel(quantum_info,pixel,q);
1905             p+=GetPixelChannels(image);
1906             q+=quantum_info->pad;
1907           }
1908           break;
1909         }
1910     }
1911     default:
1912     {
1913       QuantumAny
1914         range;
1915
1916       range=GetQuantumRange(quantum_info->depth);
1917       for (x=0; x < (ssize_t) number_pixels; x++)
1918       {
1919         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1920           range),q);
1921         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1922           range),q);
1923         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1924           range),q);
1925         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1926           range),q);
1927         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p),
1928           range),q);
1929         p+=GetPixelChannels(image);
1930         q+=quantum_info->pad;
1931       }
1932       break;
1933     }
1934   }
1935 }
1936
1937 static void ExportGrayQuantum(const Image *image,QuantumInfo *quantum_info,
1938   const MagickSizeType number_pixels,const Quantum *restrict p,
1939   unsigned char *restrict q,ExceptionInfo *exception)
1940 {
1941   QuantumAny
1942     range;
1943
1944   register ssize_t
1945     x;
1946
1947   assert(exception != (ExceptionInfo *) NULL);
1948   assert(exception->signature == MagickSignature);
1949   switch (quantum_info->depth)
1950   {
1951     case 1:
1952     {
1953       register double
1954         threshold;
1955
1956       register unsigned char
1957         black,
1958         white;
1959
1960       ssize_t
1961         bit;
1962
1963       black=0x00;
1964       white=0x01;
1965       if (quantum_info->min_is_white != MagickFalse)
1966         {
1967           black=0x01;
1968           white=0x00;
1969         }
1970       threshold=QuantumRange/2.0;
1971       for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
1972       {
1973         *q='\0';
1974         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 7;
1975         p+=GetPixelChannels(image);
1976         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 6;
1977         p+=GetPixelChannels(image);
1978         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 5;
1979         p+=GetPixelChannels(image);
1980         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 4;
1981         p+=GetPixelChannels(image);
1982         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 3;
1983         p+=GetPixelChannels(image);
1984         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 2;
1985         p+=GetPixelChannels(image);
1986         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 1;
1987         p+=GetPixelChannels(image);
1988         *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 0;
1989         p+=GetPixelChannels(image);
1990         q++;
1991       }
1992       if ((number_pixels % 8) != 0)
1993         {
1994           *q='\0';
1995           for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
1996           {
1997             *q|=(GetPixelLuma(image,p) < threshold ? black : white) << bit;
1998             p+=GetPixelChannels(image);
1999           }
2000           q++;
2001         }
2002       break;
2003     }
2004     case 4:
2005     {
2006       register unsigned char
2007         pixel;
2008
2009       for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
2010       {
2011         pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2012         *q=(((pixel >> 4) & 0xf) << 4);
2013         p+=GetPixelChannels(image);
2014         pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2015         *q|=pixel >> 4;
2016         p+=GetPixelChannels(image);
2017         q++;
2018       }
2019       if ((number_pixels % 2) != 0)
2020         {
2021           pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2022           *q=(((pixel >> 4) & 0xf) << 4);
2023           p+=GetPixelChannels(image);
2024           q++;
2025         }
2026       break;
2027     }
2028     case 8:
2029     {
2030       register unsigned char
2031         pixel;
2032
2033       for (x=0; x < (ssize_t) number_pixels; x++)
2034       {
2035         pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2036         q=PopCharPixel(pixel,q);
2037         p+=GetPixelChannels(image);
2038         q+=quantum_info->pad;
2039       }
2040       break;
2041     }
2042     case 10:
2043     {
2044       range=GetQuantumRange(quantum_info->depth);
2045       if (quantum_info->pack == MagickFalse)
2046         {
2047           register unsigned int
2048             pixel;
2049
2050           for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
2051           {
2052             pixel=(unsigned int) (ScaleQuantumToAny(ClampToQuantum(
2053               GetPixelLuma(image,p+2*GetPixelChannels(image))),range) << 22 |
2054               ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+
2055               GetPixelChannels(image))),range) << 12 | ScaleQuantumToAny(
2056               ClampToQuantum(GetPixelLuma(image,p)),range) << 2);
2057             q=PopLongPixel(quantum_info->endian,pixel,q);
2058             p+=3*GetPixelChannels(image);
2059             q+=quantum_info->pad;
2060           }
2061           if (x < (ssize_t) number_pixels)
2062             {
2063               pixel=0U;
2064               if (x++ < (ssize_t) (number_pixels-1))
2065                 pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p+
2066                   GetPixelChannels(image))),range) << 12;
2067               if (x++ < (ssize_t) number_pixels)
2068                 pixel|=ScaleQuantumToAny(ClampToQuantum(GetPixelLuma(image,p)),
2069                   range) << 2;
2070               q=PopLongPixel(quantum_info->endian,pixel,q);
2071             }
2072           break;
2073         }
2074       for (x=0; x < (ssize_t) number_pixels; x++)
2075       {
2076         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
2077           GetPixelLuma(image,p)),range),q);
2078         p+=GetPixelChannels(image);
2079         q+=quantum_info->pad;
2080       }
2081       break;
2082     }
2083     case 12:
2084     {
2085       register unsigned short
2086         pixel;
2087
2088       range=GetQuantumRange(quantum_info->depth);
2089       if (quantum_info->pack == MagickFalse)
2090         {
2091           for (x=0; x < (ssize_t) number_pixels; x++)
2092           {
2093             pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2094             q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel >> 4),
2095               q);
2096             p+=GetPixelChannels(image);
2097             q+=quantum_info->pad;
2098           }
2099           break;
2100         }
2101       for (x=0; x < (ssize_t) number_pixels; x++)
2102       {
2103         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
2104           GetPixelLuma(image,p)),range),q);
2105         p+=GetPixelChannels(image);
2106         q+=quantum_info->pad;
2107       }
2108       break;
2109     }
2110     case 16:
2111     {
2112       register unsigned short
2113         pixel;
2114
2115       if (quantum_info->format == FloatingPointQuantumFormat)
2116         {
2117           for (x=0; x < (ssize_t) number_pixels; x++)
2118           {
2119             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelLuma(image,p));
2120             q=PopShortPixel(quantum_info->endian,pixel,q);
2121             p+=GetPixelChannels(image);
2122             q+=quantum_info->pad;
2123           }
2124           break;
2125         }
2126       for (x=0; x < (ssize_t) number_pixels; x++)
2127       {
2128         pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2129         q=PopShortPixel(quantum_info->endian,pixel,q);
2130         p+=GetPixelChannels(image);
2131         q+=quantum_info->pad;
2132       }
2133       break;
2134     }
2135     case 32:
2136     {
2137       register unsigned int
2138         pixel;
2139
2140       if (quantum_info->format == FloatingPointQuantumFormat)
2141         {
2142           for (x=0; x < (ssize_t) number_pixels; x++)
2143           {
2144             float
2145               pixel;
2146
2147             pixel=(float) GetPixelLuma(image,p);
2148             q=PopFloatPixel(quantum_info,pixel,q);
2149             p+=GetPixelChannels(image);
2150             q+=quantum_info->pad;
2151           }
2152           break;
2153         }
2154       for (x=0; x < (ssize_t) number_pixels; x++)
2155       {
2156         pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
2157         q=PopLongPixel(quantum_info->endian,pixel,q);
2158         p+=GetPixelChannels(image);
2159         q+=quantum_info->pad;
2160       }
2161       break;
2162     }
2163     case 64:
2164     {
2165       if (quantum_info->format == FloatingPointQuantumFormat)
2166         {
2167           for (x=0; x < (ssize_t) number_pixels; x++)
2168           {
2169             double
2170               pixel;
2171
2172             pixel=GetPixelLuma(image,p);
2173             q=PopDoublePixel(quantum_info,pixel,q);
2174             p+=GetPixelChannels(image);
2175             q+=quantum_info->pad;
2176           }
2177           break;
2178         }
2179     }
2180     default:
2181     {
2182       range=GetQuantumRange(quantum_info->depth);
2183       for (x=0; x < (ssize_t) number_pixels; x++)
2184       {
2185         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
2186           GetPixelLuma(image,p)),range),q);
2187         p+=GetPixelChannels(image);
2188         q+=quantum_info->pad;
2189       }
2190       break;
2191     }
2192   }
2193 }
2194
2195 static void ExportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
2196   const MagickSizeType number_pixels,const Quantum *restrict p,
2197   unsigned char *restrict q,ExceptionInfo *exception)
2198 {
2199   QuantumAny
2200     range;
2201
2202   register ssize_t
2203     x;
2204
2205   assert(exception != (ExceptionInfo *) NULL);
2206   assert(exception->signature == MagickSignature);
2207   switch (quantum_info->depth)
2208   {
2209     case 1:
2210     {
2211       register double
2212         threshold;
2213
2214       register unsigned char
2215         black,
2216         pixel,
2217         white;
2218
2219       ssize_t
2220         bit;
2221
2222       black=0x00;
2223       white=0x01;
2224       if (quantum_info->min_is_white == MagickFalse)
2225         {
2226           black=0x01;
2227           white=0x00;
2228         }
2229       threshold=QuantumRange/2.0;
2230       for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2231       {
2232         *q='\0';
2233         *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 7;
2234         pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2235           0x00 : 0x01);
2236         *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
2237         p+=GetPixelChannels(image);
2238         *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 5;
2239         pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2240           0x00 : 0x01);
2241         *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
2242         p+=GetPixelChannels(image);
2243         *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 3;
2244         pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2245           0x00 : 0x01);
2246         *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
2247         p+=GetPixelChannels(image);
2248         *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 1;
2249         pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2250           0x00 : 0x01);
2251         *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
2252         p+=GetPixelChannels(image);
2253         q++;
2254       }
2255       if ((number_pixels % 4) != 0)
2256         {
2257           *q='\0';
2258           for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
2259           {
2260             *q|=(GetPixelLuma(image,p) > threshold ? black : white) <<
2261               (7-bit);
2262             pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2263               0x00 : 0x01);
2264             *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
2265               (7-bit-1));
2266             p+=GetPixelChannels(image);
2267           }
2268           q++;
2269         }
2270       break;
2271     }
2272     case 4:
2273     {
2274       register unsigned char
2275         pixel;
2276
2277       for (x=0; x < (ssize_t) number_pixels ; x++)
2278       {
2279         pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2280         *q=(((pixel >> 4) & 0xf) << 4);
2281         pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
2282         *q|=pixel & 0xf;
2283         p+=GetPixelChannels(image);
2284         q++;
2285       }
2286       break;
2287     }
2288     case 8:
2289     {
2290       register unsigned char
2291         pixel;
2292
2293       for (x=0; x < (ssize_t) number_pixels; x++)
2294       {
2295         pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2296         q=PopCharPixel(pixel,q);
2297         pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2298         q=PopCharPixel(pixel,q);
2299         p+=GetPixelChannels(image);
2300         q+=quantum_info->pad;
2301       }
2302       break;
2303     }
2304     case 16:
2305     {
2306       register unsigned short
2307         pixel;
2308
2309       if (quantum_info->format == FloatingPointQuantumFormat)
2310         {
2311           for (x=0; x < (ssize_t) number_pixels; x++)
2312           {
2313             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelLuma(image,p));
2314             q=PopShortPixel(quantum_info->endian,pixel,q);
2315             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelAlpha(image,p));
2316             q=PopShortPixel(quantum_info->endian,pixel,q);
2317             p+=GetPixelChannels(image);
2318             q+=quantum_info->pad;
2319           }
2320           break;
2321         }
2322       for (x=0; x < (ssize_t) number_pixels; x++)
2323       {
2324         pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2325         q=PopShortPixel(quantum_info->endian,pixel,q);
2326         pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2327         q=PopShortPixel(quantum_info->endian,pixel,q);
2328         p+=GetPixelChannels(image);
2329         q+=quantum_info->pad;
2330       }
2331       break;
2332     }
2333     case 32:
2334     {
2335       register unsigned int
2336         pixel;
2337
2338       if (quantum_info->format == FloatingPointQuantumFormat)
2339         {
2340           for (x=0; x < (ssize_t) number_pixels; x++)
2341           {
2342             float
2343               pixel;
2344
2345             pixel=(float) GetPixelLuma(image,p);
2346             q=PopFloatPixel(quantum_info,pixel,q);
2347             pixel=(float) (GetPixelAlpha(image,p));
2348             q=PopFloatPixel(quantum_info,pixel,q);
2349             p+=GetPixelChannels(image);
2350             q+=quantum_info->pad;
2351           }
2352           break;
2353         }
2354       for (x=0; x < (ssize_t) number_pixels; x++)
2355       {
2356         pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
2357         q=PopLongPixel(quantum_info->endian,pixel,q);
2358         pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2359         q=PopLongPixel(quantum_info->endian,pixel,q);
2360         p+=GetPixelChannels(image);
2361         q+=quantum_info->pad;
2362       }
2363       break;
2364     }
2365     case 64:
2366     {
2367       if (quantum_info->format == FloatingPointQuantumFormat)
2368         {
2369           for (x=0; x < (ssize_t) number_pixels; x++)
2370           {
2371             double
2372               pixel;
2373
2374             pixel=GetPixelLuma(image,p);
2375             q=PopDoublePixel(quantum_info,pixel,q);
2376             pixel=(double) (GetPixelAlpha(image,p));
2377             q=PopDoublePixel(quantum_info,pixel,q);
2378             p+=GetPixelChannels(image);
2379             q+=quantum_info->pad;
2380           }
2381           break;
2382         }
2383     }
2384     default:
2385     {
2386       range=GetQuantumRange(quantum_info->depth);
2387       for (x=0; x < (ssize_t) number_pixels; x++)
2388       {
2389         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(ClampToQuantum(
2390           GetPixelLuma(image,p)),range),q);
2391         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
2392           range),q);
2393         p+=GetPixelChannels(image);
2394         q+=quantum_info->pad;
2395       }
2396       break;
2397     }
2398   }
2399 }
2400
2401 static void ExportGreenQuantum(const Image *image,QuantumInfo *quantum_info,
2402   const MagickSizeType number_pixels,const Quantum *restrict p,
2403   unsigned char *restrict q,ExceptionInfo *exception)
2404 {
2405   QuantumAny
2406     range;
2407
2408   register ssize_t
2409     x;
2410
2411   assert(exception != (ExceptionInfo *) NULL);
2412   assert(exception->signature == MagickSignature);
2413   switch (quantum_info->depth)
2414   {
2415     case 8:
2416     {
2417       register unsigned char
2418         pixel;
2419
2420       for (x=0; x < (ssize_t) number_pixels; x++)
2421       {
2422         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2423         q=PopCharPixel(pixel,q);
2424         p+=GetPixelChannels(image);
2425         q+=quantum_info->pad;
2426       }
2427       break;
2428     }
2429     case 16:
2430     {
2431       register unsigned short
2432         pixel;
2433
2434       if (quantum_info->format == FloatingPointQuantumFormat)
2435         {
2436           for (x=0; x < (ssize_t) number_pixels; x++)
2437           {
2438             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
2439             q=PopShortPixel(quantum_info->endian,pixel,q);
2440             p+=GetPixelChannels(image);
2441             q+=quantum_info->pad;
2442           }
2443           break;
2444         }
2445       for (x=0; x < (ssize_t) number_pixels; x++)
2446       {
2447         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2448         q=PopShortPixel(quantum_info->endian,pixel,q);
2449         p+=GetPixelChannels(image);
2450         q+=quantum_info->pad;
2451       }
2452       break;
2453     }
2454     case 32:
2455     {
2456       register unsigned int
2457         pixel;
2458
2459       if (quantum_info->format == FloatingPointQuantumFormat)
2460         {
2461           for (x=0; x < (ssize_t) number_pixels; x++)
2462           {
2463             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
2464             p+=GetPixelChannels(image);
2465             q+=quantum_info->pad;
2466           }
2467           break;
2468         }
2469       for (x=0; x < (ssize_t) number_pixels; x++)
2470       {
2471         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2472         q=PopLongPixel(quantum_info->endian,pixel,q);
2473         p+=GetPixelChannels(image);
2474         q+=quantum_info->pad;
2475       }
2476       break;
2477     }
2478     case 64:
2479     {
2480       if (quantum_info->format == FloatingPointQuantumFormat)
2481         {
2482           for (x=0; x < (ssize_t) number_pixels; x++)
2483           {
2484             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
2485             p+=GetPixelChannels(image);
2486             q+=quantum_info->pad;
2487           }
2488           break;
2489         }
2490     }
2491     default:
2492     {
2493       range=GetQuantumRange(quantum_info->depth);
2494       for (x=0; x < (ssize_t) number_pixels; x++)
2495       {
2496         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
2497           range),q);
2498         p+=GetPixelChannels(image);
2499         q+=quantum_info->pad;
2500       }
2501       break;
2502     }
2503   }
2504 }
2505
2506 static void ExportIndexQuantum(const Image *image,QuantumInfo *quantum_info,
2507   const MagickSizeType number_pixels,const Quantum *restrict p,
2508   unsigned char *restrict q,ExceptionInfo *exception)
2509 {
2510   register ssize_t
2511     x;
2512
2513   ssize_t
2514     bit;
2515
2516   if (image->storage_class != PseudoClass)
2517     {
2518       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2519         "ColormappedImageRequired","`%s'",image->filename);
2520       return;
2521     }
2522   switch (quantum_info->depth)
2523   {
2524     case 1:
2525     {
2526       register unsigned char
2527         pixel;
2528
2529       for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
2530       {
2531         pixel=(unsigned char) GetPixelIndex(image,p);
2532         *q=((pixel & 0x01) << 7);
2533         p+=GetPixelChannels(image);
2534         pixel=(unsigned char) GetPixelIndex(image,p);
2535         *q|=((pixel & 0x01) << 6);
2536         p+=GetPixelChannels(image);
2537         pixel=(unsigned char) GetPixelIndex(image,p);
2538         *q|=((pixel & 0x01) << 5);
2539         p+=GetPixelChannels(image);
2540         pixel=(unsigned char) GetPixelIndex(image,p);
2541         *q|=((pixel & 0x01) << 4);
2542         p+=GetPixelChannels(image);
2543         pixel=(unsigned char) GetPixelIndex(image,p);
2544         *q|=((pixel & 0x01) << 3);
2545         p+=GetPixelChannels(image);
2546         pixel=(unsigned char) GetPixelIndex(image,p);
2547         *q|=((pixel & 0x01) << 2);
2548         p+=GetPixelChannels(image);
2549         pixel=(unsigned char) GetPixelIndex(image,p);
2550         *q|=((pixel & 0x01) << 1);
2551         p+=GetPixelChannels(image);
2552         pixel=(unsigned char) GetPixelIndex(image,p);
2553         *q|=((pixel & 0x01) << 0);
2554         p+=GetPixelChannels(image);
2555         q++;
2556       }
2557       if ((number_pixels % 8) != 0)
2558         {
2559           *q='\0';
2560           for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
2561           {
2562             pixel=(unsigned char) GetPixelIndex(image,p);
2563             *q|=((pixel & 0x01) << (unsigned char) bit);
2564             p+=GetPixelChannels(image);
2565           }
2566           q++;
2567         }
2568       break;
2569     }
2570     case 4:
2571     {
2572       register unsigned char
2573         pixel;
2574
2575       for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
2576       {
2577         pixel=(unsigned char) GetPixelIndex(image,p);
2578         *q=((pixel & 0xf) << 4);
2579         p+=GetPixelChannels(image);
2580         pixel=(unsigned char) GetPixelIndex(image,p);
2581         *q|=((pixel & 0xf) << 0);
2582         p+=GetPixelChannels(image);
2583         q++;
2584       }
2585       if ((number_pixels % 2) != 0)
2586         {
2587           pixel=(unsigned char) GetPixelIndex(image,p);
2588           *q=((pixel & 0xf) << 4);
2589           p+=GetPixelChannels(image);
2590           q++;
2591         }
2592       break;
2593     }
2594     case 8:
2595     {
2596       for (x=0; x < (ssize_t) number_pixels; x++)
2597       {
2598         q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
2599         p+=GetPixelChannels(image);
2600         q+=quantum_info->pad;
2601       }
2602       break;
2603     }
2604     case 16:
2605     {
2606       if (quantum_info->format == FloatingPointQuantumFormat)
2607         {
2608           for (x=0; x < (ssize_t) number_pixels; x++)
2609           {
2610             q=PopShortPixel(quantum_info->endian,SinglePrecisionToHalf(
2611               QuantumScale*GetPixelIndex(image,p)),q);
2612             p+=GetPixelChannels(image);
2613             q+=quantum_info->pad;
2614           }
2615           break;
2616         }
2617       for (x=0; x < (ssize_t) number_pixels; x++)
2618       {
2619         q=PopShortPixel(quantum_info->endian,(unsigned short)
2620           GetPixelIndex(image,p),q);
2621         p+=GetPixelChannels(image);
2622         q+=quantum_info->pad;
2623       }
2624       break;
2625     }
2626     case 32:
2627     {
2628       if (quantum_info->format == FloatingPointQuantumFormat)
2629         {
2630           for (x=0; x < (ssize_t) number_pixels; x++)
2631           {
2632             q=PopFloatPixel(quantum_info,(float) GetPixelIndex(image,p),q);
2633             p+=GetPixelChannels(image);
2634             q+=quantum_info->pad;
2635           }
2636           break;
2637         }
2638       for (x=0; x < (ssize_t) number_pixels; x++)
2639       {
2640         q=PopLongPixel(quantum_info->endian,(unsigned int)
2641           GetPixelIndex(image,p),q);
2642         p+=GetPixelChannels(image);
2643         q+=quantum_info->pad;
2644       }
2645       break;
2646     }
2647     case 64:
2648     {
2649       if (quantum_info->format == FloatingPointQuantumFormat)
2650         {
2651           for (x=0; x < (ssize_t) number_pixels; x++)
2652           {
2653             q=PopDoublePixel(quantum_info,(double) GetPixelIndex(image,p),q);
2654             p+=GetPixelChannels(image);
2655             q+=quantum_info->pad;
2656           }
2657           break;
2658         }
2659     }
2660     default:
2661     {
2662       for (x=0; x < (ssize_t) number_pixels; x++)
2663       {
2664         q=PopQuantumPixel(quantum_info,GetPixelIndex(image,p),q);
2665         p+=GetPixelChannels(image);
2666         q+=quantum_info->pad;
2667       }
2668       break;
2669     }
2670   }
2671 }
2672
2673 static void ExportIndexAlphaQuantum(const Image *image,
2674   QuantumInfo *quantum_info,const MagickSizeType number_pixels,
2675   const Quantum *restrict p,unsigned char *restrict q,ExceptionInfo *exception)
2676 {
2677   register ssize_t
2678     x;
2679
2680   ssize_t
2681     bit;
2682
2683   if (image->storage_class != PseudoClass)
2684     {
2685       (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2686         "ColormappedImageRequired","`%s'",image->filename);
2687       return;
2688     }
2689   switch (quantum_info->depth)
2690   {
2691     case 1:
2692     {
2693       register unsigned char
2694         pixel;
2695
2696       for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2697       {
2698         pixel=(unsigned char) GetPixelIndex(image,p);
2699         *q=((pixel & 0x01) << 7);
2700         pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2701           TransparentAlpha ? 1 : 0);
2702         *q|=((pixel & 0x01) << 6);
2703         p+=GetPixelChannels(image);
2704         pixel=(unsigned char) GetPixelIndex(image,p);
2705         *q|=((pixel & 0x01) << 5);
2706         pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2707           TransparentAlpha ? 1 : 0);
2708         *q|=((pixel & 0x01) << 4);
2709         p+=GetPixelChannels(image);
2710         pixel=(unsigned char) GetPixelIndex(image,p);
2711         *q|=((pixel & 0x01) << 3);
2712         pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2713           TransparentAlpha ? 1 : 0);
2714         *q|=((pixel & 0x01) << 2);
2715         p+=GetPixelChannels(image);
2716         pixel=(unsigned char) GetPixelIndex(image,p);
2717         *q|=((pixel & 0x01) << 1);
2718         pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2719           TransparentAlpha ? 1 : 0);
2720         *q|=((pixel & 0x01) << 0);
2721         p+=GetPixelChannels(image);
2722         q++;
2723       }
2724       if ((number_pixels % 4) != 0)
2725         {
2726           *q='\0';
2727           for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
2728           {
2729             pixel=(unsigned char) GetPixelIndex(image,p);
2730             *q|=((pixel & 0x01) << (unsigned char) (bit+4));
2731             pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2732               TransparentAlpha ? 1 : 0);
2733             *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
2734             p+=GetPixelChannels(image);
2735           }
2736           q++;
2737         }
2738       break;
2739     }
2740     case 4:
2741     {
2742       register unsigned char
2743         pixel;
2744
2745       for (x=0; x < (ssize_t) number_pixels ; x++)
2746       {
2747         pixel=(unsigned char) GetPixelIndex(image,p);
2748         *q=((pixel & 0xf) << 4);
2749         pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
2750         *q|=((pixel & 0xf) << 0);
2751         p+=GetPixelChannels(image);
2752         q++;
2753       }
2754       break;
2755     }
2756     case 8:
2757     {
2758       register unsigned char
2759         pixel;
2760
2761       for (x=0; x < (ssize_t) number_pixels; x++)
2762       {
2763         q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
2764         pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2765         q=PopCharPixel(pixel,q);
2766         p+=GetPixelChannels(image);
2767         q+=quantum_info->pad;
2768       }
2769       break;
2770     }
2771     case 16:
2772     {
2773       register unsigned short
2774         pixel;
2775
2776       if (quantum_info->format == FloatingPointQuantumFormat)
2777         {
2778           for (x=0; x < (ssize_t) number_pixels; x++)
2779           {
2780             q=PopShortPixel(quantum_info->endian,(unsigned short)
2781               GetPixelIndex(image,p),q);
2782             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelAlpha(image,p));
2783             q=PopShortPixel(quantum_info->endian,pixel,q);
2784             p+=GetPixelChannels(image);
2785             q+=quantum_info->pad;
2786           }
2787           break;
2788         }
2789       for (x=0; x < (ssize_t) number_pixels; x++)
2790       {
2791         q=PopShortPixel(quantum_info->endian,(unsigned short)
2792               GetPixelIndex(image,p),q);
2793         pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2794         q=PopShortPixel(quantum_info->endian,pixel,q);
2795         p+=GetPixelChannels(image);
2796         q+=quantum_info->pad;
2797       }
2798       break;
2799     }
2800     case 32:
2801     {
2802       register unsigned int
2803         pixel;
2804
2805       if (quantum_info->format == FloatingPointQuantumFormat)
2806         {
2807           for (x=0; x < (ssize_t) number_pixels; x++)
2808           {
2809             float
2810               pixel;
2811
2812             q=PopFloatPixel(quantum_info,(float) GetPixelIndex(image,p),q);
2813             pixel=(float)  GetPixelAlpha(image,p);
2814             q=PopFloatPixel(quantum_info,pixel,q);
2815             p+=GetPixelChannels(image);
2816             q+=quantum_info->pad;
2817           }
2818           break;
2819         }
2820       for (x=0; x < (ssize_t) number_pixels; x++)
2821       {
2822         q=PopLongPixel(quantum_info->endian,(unsigned int)
2823           GetPixelIndex(image,p),q);
2824         pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2825         q=PopLongPixel(quantum_info->endian,pixel,q);
2826         p+=GetPixelChannels(image);
2827         q+=quantum_info->pad;
2828       }
2829       break;
2830     }
2831     case 64:
2832     {
2833       if (quantum_info->format == FloatingPointQuantumFormat)
2834         {
2835           for (x=0; x < (ssize_t) number_pixels; x++)
2836           {
2837             double
2838               pixel;
2839
2840             q=PopDoublePixel(quantum_info,(double) GetPixelIndex(image,p),q);
2841             pixel=(double) GetPixelAlpha(image,p);
2842             q=PopDoublePixel(quantum_info,pixel,q);
2843             p+=GetPixelChannels(image);
2844             q+=quantum_info->pad;
2845           }
2846           break;
2847         }
2848     }
2849     default:
2850     {
2851       QuantumAny
2852         range;
2853
2854       range=GetQuantumRange(quantum_info->depth);
2855       for (x=0; x < (ssize_t) number_pixels; x++)
2856       {
2857         q=PopQuantumPixel(quantum_info,GetPixelIndex(image,p),q);
2858         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
2859           range),q);
2860         p+=GetPixelChannels(image);
2861         q+=quantum_info->pad;
2862       }
2863       break;
2864     }
2865   }
2866 }
2867
2868 static void ExportOpacityQuantum(const Image *image,QuantumInfo *quantum_info,
2869   const MagickSizeType number_pixels,const Quantum *restrict p,
2870   unsigned char *restrict q,ExceptionInfo *exception)
2871 {
2872   QuantumAny
2873     range;
2874
2875   register ssize_t
2876     x;
2877
2878   assert(exception != (ExceptionInfo *) NULL);
2879   assert(exception->signature == MagickSignature);
2880   switch (quantum_info->depth)
2881   {
2882     case 8:
2883     {
2884       register unsigned char
2885         pixel;
2886
2887       for (x=0; x < (ssize_t) number_pixels; x++)
2888       {
2889         pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
2890         q=PopCharPixel(pixel,q);
2891         p+=GetPixelChannels(image);
2892         q+=quantum_info->pad;
2893       }
2894       break;
2895     }
2896     case 16:
2897     {
2898       register unsigned short
2899         pixel;
2900
2901       if (quantum_info->format == FloatingPointQuantumFormat)
2902         {
2903           for (x=0; x < (ssize_t) number_pixels; x++)
2904           {
2905             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelOpacity(image,p));
2906             q=PopShortPixel(quantum_info->endian,pixel,q);
2907             p+=GetPixelChannels(image);
2908             q+=quantum_info->pad;
2909           }
2910           break;
2911         }
2912       for (x=0; x < (ssize_t) number_pixels; x++)
2913       {
2914         pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
2915         q=PopShortPixel(quantum_info->endian,pixel,q);
2916         p+=GetPixelChannels(image);
2917         q+=quantum_info->pad;
2918       }
2919       break;
2920     }
2921     case 32:
2922     {
2923       register unsigned int
2924         pixel;
2925
2926       if (quantum_info->format == FloatingPointQuantumFormat)
2927         {
2928           for (x=0; x < (ssize_t) number_pixels; x++)
2929           {
2930             q=PopFloatPixel(quantum_info,(float) GetPixelOpacity(image,p),q);
2931             p+=GetPixelChannels(image);
2932             q+=quantum_info->pad;
2933           }
2934           break;
2935         }
2936       for (x=0; x < (ssize_t) number_pixels; x++)
2937       {
2938         pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
2939         q=PopLongPixel(quantum_info->endian,pixel,q);
2940         p+=GetPixelChannels(image);
2941         q+=quantum_info->pad;
2942       }
2943       break;
2944     }
2945     case 64:
2946     {
2947       if (quantum_info->format == FloatingPointQuantumFormat)
2948         {
2949           for (x=0; x < (ssize_t) number_pixels; x++)
2950           {
2951             q=PopDoublePixel(quantum_info,(double) GetPixelOpacity(image,p),q);
2952             p+=GetPixelChannels(image);
2953             q+=quantum_info->pad;
2954           }
2955           break;
2956         }
2957     }
2958     default:
2959     {
2960       range=GetQuantumRange(quantum_info->depth);
2961       for (x=0; x < (ssize_t) number_pixels; x++)
2962       {
2963         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
2964           GetPixelOpacity(image,p),range),q);
2965         p+=GetPixelChannels(image);
2966         q+=quantum_info->pad;
2967       }
2968       break;
2969     }
2970   }
2971 }
2972
2973 static void ExportRedQuantum(const Image *image,QuantumInfo *quantum_info,
2974   const MagickSizeType number_pixels,const Quantum *restrict p,
2975   unsigned char *restrict q,ExceptionInfo *exception)
2976 {
2977   QuantumAny
2978     range;
2979
2980   register ssize_t
2981     x;
2982
2983   assert(exception != (ExceptionInfo *) NULL);
2984   assert(exception->signature == MagickSignature);
2985   switch (quantum_info->depth)
2986   {
2987     case 8:
2988     {
2989       register unsigned char
2990         pixel;
2991
2992       for (x=0; x < (ssize_t) number_pixels; x++)
2993       {
2994         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2995         q=PopCharPixel(pixel,q);
2996         p+=GetPixelChannels(image);
2997         q+=quantum_info->pad;
2998       }
2999       break;
3000     }
3001     case 16:
3002     {
3003       register unsigned short
3004         pixel;
3005
3006       if (quantum_info->format == FloatingPointQuantumFormat)
3007         {
3008           for (x=0; x < (ssize_t) number_pixels; x++)
3009           {
3010             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
3011             q=PopShortPixel(quantum_info->endian,pixel,q);
3012             p+=GetPixelChannels(image);
3013             q+=quantum_info->pad;
3014           }
3015           break;
3016         }
3017       for (x=0; x < (ssize_t) number_pixels; x++)
3018       {
3019         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3020         q=PopShortPixel(quantum_info->endian,pixel,q);
3021         p+=GetPixelChannels(image);
3022         q+=quantum_info->pad;
3023       }
3024       break;
3025     }
3026     case 32:
3027     {
3028       register unsigned int
3029         pixel;
3030
3031       if (quantum_info->format == FloatingPointQuantumFormat)
3032         {
3033           for (x=0; x < (ssize_t) number_pixels; x++)
3034           {
3035             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3036             p+=GetPixelChannels(image);
3037             q+=quantum_info->pad;
3038           }
3039           break;
3040         }
3041       for (x=0; x < (ssize_t) number_pixels; x++)
3042       {
3043         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3044         q=PopLongPixel(quantum_info->endian,pixel,q);
3045         p+=GetPixelChannels(image);
3046         q+=quantum_info->pad;
3047       }
3048       break;
3049     }
3050     case 64:
3051     {
3052       if (quantum_info->format == FloatingPointQuantumFormat)
3053         {
3054           for (x=0; x < (ssize_t) number_pixels; x++)
3055           {
3056             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3057             p+=GetPixelChannels(image);
3058             q+=quantum_info->pad;
3059           }
3060           break;
3061         }
3062     }
3063     default:
3064     {
3065       range=GetQuantumRange(quantum_info->depth);
3066       for (x=0; x < (ssize_t) number_pixels; x++)
3067       {
3068         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3069           range),q);
3070         p+=GetPixelChannels(image);
3071         q+=quantum_info->pad;
3072       }
3073       break;
3074     }
3075   }
3076 }
3077
3078 static void ExportRGBQuantum(const Image *image,QuantumInfo *quantum_info,
3079   const MagickSizeType number_pixels,const Quantum *restrict p,
3080   unsigned char *restrict q,ExceptionInfo *exception)
3081 {
3082   QuantumAny
3083     range;
3084
3085   register ssize_t
3086     x;
3087
3088   ssize_t
3089     bit;
3090
3091   assert(exception != (ExceptionInfo *) NULL);
3092   assert(exception->signature == MagickSignature);
3093   switch (quantum_info->depth)
3094   {
3095     case 8:
3096     {
3097       for (x=0; x < (ssize_t) number_pixels; x++)
3098       {
3099         q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
3100         q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
3101         q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
3102         p+=GetPixelChannels(image);
3103         q+=quantum_info->pad;
3104       }
3105       break;
3106     }
3107     case 10:
3108     {
3109       register unsigned int
3110         pixel;
3111
3112       range=GetQuantumRange(quantum_info->depth);
3113       if (quantum_info->pack == MagickFalse)
3114         {
3115           for (x=0; x < (ssize_t) number_pixels; x++)
3116           {
3117             pixel=(unsigned int) (
3118               ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
3119               ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
3120               ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
3121             q=PopLongPixel(quantum_info->endian,pixel,q);
3122             p+=GetPixelChannels(image);
3123             q+=quantum_info->pad;
3124           }
3125           break;
3126         }
3127       if (quantum_info->quantum == 32UL)
3128         {
3129           for (x=0; x < (ssize_t) number_pixels; x++)
3130           {
3131             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3132             q=PopQuantumLongPixel(quantum_info,pixel,q);
3133             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3134               range);
3135             q=PopQuantumLongPixel(quantum_info,pixel,q);
3136             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3137             q=PopQuantumLongPixel(quantum_info,pixel,q);
3138             p+=GetPixelChannels(image);
3139             q+=quantum_info->pad;
3140           }
3141           break;
3142         }
3143       for (x=0; x < (ssize_t) number_pixels; x++)
3144       {
3145         pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3146         q=PopQuantumPixel(quantum_info,pixel,q);
3147         pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3148         q=PopQuantumPixel(quantum_info,pixel,q);
3149         pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3150         q=PopQuantumPixel(quantum_info,pixel,q);
3151         p+=GetPixelChannels(image);
3152         q+=quantum_info->pad;
3153       }
3154       break;
3155     }
3156     case 12:
3157     {
3158       register unsigned int
3159         pixel;
3160
3161       range=GetQuantumRange(quantum_info->depth);
3162       if (quantum_info->pack == MagickFalse)
3163         {
3164           for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
3165           {
3166             switch (x % 3)
3167             {
3168               default:
3169               case 0:
3170               {
3171                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3172                   range);
3173                 break;
3174               }
3175               case 1:
3176               {
3177                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3178                   range);
3179                 break;
3180               }
3181               case 2:
3182               {
3183                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3184                   range);
3185                 p+=GetPixelChannels(image);
3186                 break;
3187               }
3188             }
3189             q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3190               q);
3191             switch ((x+1) % 3)
3192             {
3193               default:
3194               case 0:
3195               {
3196                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3197                   range);
3198                 break;
3199               }
3200               case 1:
3201               {
3202                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3203                   range);
3204                 break;
3205               }
3206               case 2:
3207               {
3208                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3209                   range);
3210                 p+=GetPixelChannels(image);
3211                 break;
3212               }
3213             }
3214             q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3215               q);
3216             q+=quantum_info->pad;
3217           }
3218           for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
3219           {
3220             switch ((x+bit) % 3)
3221             {
3222               default:
3223               case 0:
3224               {
3225                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3226                   range);
3227                 break;
3228               }
3229               case 1:
3230               {
3231                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3232                   range);
3233                 break;
3234               }
3235               case 2:
3236               {
3237                 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3238                   range);
3239                 p+=GetPixelChannels(image);
3240                 break;
3241               }
3242             }
3243             q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3244               q);
3245             q+=quantum_info->pad;
3246           }
3247           if (bit != 0)
3248             p+=GetPixelChannels(image);
3249           break;
3250         }
3251       if (quantum_info->quantum == 32UL)
3252         {
3253           for (x=0; x < (ssize_t) number_pixels; x++)
3254           {
3255             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3256             q=PopQuantumLongPixel(quantum_info,pixel,q);
3257             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3258               range);
3259             q=PopQuantumLongPixel(quantum_info,pixel,q);
3260             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3261             q=PopQuantumLongPixel(quantum_info,pixel,q);
3262             p+=GetPixelChannels(image);
3263             q+=quantum_info->pad;
3264           }
3265           break;
3266         }
3267       for (x=0; x < (ssize_t) number_pixels; x++)
3268       {
3269         pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3270         q=PopQuantumPixel(quantum_info,pixel,q);
3271         pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3272         q=PopQuantumPixel(quantum_info,pixel,q);
3273         pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3274         q=PopQuantumPixel(quantum_info,pixel,q);
3275         p+=GetPixelChannels(image);
3276         q+=quantum_info->pad;
3277       }
3278       break;
3279     }
3280     case 16:
3281     {
3282       register unsigned short
3283         pixel;
3284
3285       if (quantum_info->format == FloatingPointQuantumFormat)
3286         {
3287           for (x=0; x < (ssize_t) number_pixels; x++)
3288           {
3289             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
3290             q=PopShortPixel(quantum_info->endian,pixel,q);
3291             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
3292             q=PopShortPixel(quantum_info->endian,pixel,q);
3293             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
3294             q=PopShortPixel(quantum_info->endian,pixel,q);
3295             p+=GetPixelChannels(image);
3296             q+=quantum_info->pad;
3297           }
3298           break;
3299         }
3300       for (x=0; x < (ssize_t) number_pixels; x++)
3301       {
3302         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3303         q=PopShortPixel(quantum_info->endian,pixel,q);
3304         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3305         q=PopShortPixel(quantum_info->endian,pixel,q);
3306         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3307         q=PopShortPixel(quantum_info->endian,pixel,q);
3308         p+=GetPixelChannels(image);
3309         q+=quantum_info->pad;
3310       }
3311       break;
3312     }
3313     case 32:
3314     {
3315       register unsigned int
3316         pixel;
3317
3318       if (quantum_info->format == FloatingPointQuantumFormat)
3319         {
3320           for (x=0; x < (ssize_t) number_pixels; x++)
3321           {
3322             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3323             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
3324             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
3325             p+=GetPixelChannels(image);
3326             q+=quantum_info->pad;
3327           }
3328           break;
3329         }
3330       for (x=0; x < (ssize_t) number_pixels; x++)
3331       {
3332         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3333         q=PopLongPixel(quantum_info->endian,pixel,q);
3334         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3335         q=PopLongPixel(quantum_info->endian,pixel,q);
3336         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3337         q=PopLongPixel(quantum_info->endian,pixel,q);
3338         p+=GetPixelChannels(image);
3339         q+=quantum_info->pad;
3340       }
3341       break;
3342     }
3343     case 64:
3344     {
3345       if (quantum_info->format == FloatingPointQuantumFormat)
3346         {
3347           for (x=0; x < (ssize_t) number_pixels; x++)
3348           {
3349             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3350             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
3351             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
3352             p+=GetPixelChannels(image);
3353             q+=quantum_info->pad;
3354           }
3355           break;
3356         }
3357     }
3358     default:
3359     {
3360       range=GetQuantumRange(quantum_info->depth);
3361       for (x=0; x < (ssize_t) number_pixels; x++)
3362       {
3363         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3364           range),q);
3365         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3366           range),q);
3367         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3368           range),q);
3369         p+=GetPixelChannels(image);
3370         q+=quantum_info->pad;
3371       }
3372       break;
3373     }
3374   }
3375 }
3376
3377 static void ExportRGBAQuantum(const Image *image,QuantumInfo *quantum_info,
3378   const MagickSizeType number_pixels,const Quantum *restrict p,
3379   unsigned char *restrict q,ExceptionInfo *exception)
3380 {
3381   QuantumAny
3382     range;
3383
3384   register ssize_t
3385     x;
3386
3387   assert(exception != (ExceptionInfo *) NULL);
3388   assert(exception->signature == MagickSignature);
3389   switch (quantum_info->depth)
3390   {
3391     case 8:
3392     {
3393       register unsigned char
3394         pixel;
3395
3396       for (x=0; x < (ssize_t) number_pixels; x++)
3397       {
3398         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3399         q=PopCharPixel(pixel,q);
3400         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3401         q=PopCharPixel(pixel,q);
3402         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3403         q=PopCharPixel(pixel,q);
3404         pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
3405         q=PopCharPixel(pixel,q);
3406         p+=GetPixelChannels(image);
3407         q+=quantum_info->pad;
3408       }
3409       break;
3410     }
3411     case 10:
3412     {
3413       register unsigned int
3414         pixel;
3415
3416       range=GetQuantumRange(quantum_info->depth);
3417       if (quantum_info->pack == MagickFalse)
3418         {
3419           register ssize_t
3420             i;
3421
3422           size_t
3423             quantum;
3424
3425           ssize_t
3426             n;
3427
3428           n=0;
3429           quantum=0;
3430           pixel=0;
3431           for (x=0; x < (ssize_t) number_pixels; x++)
3432           {
3433             for (i=0; i < 4; i++)
3434             {
3435               switch (i)
3436               {
3437                 case 0: quantum=GetPixelRed(image,p); break;
3438                 case 1: quantum=GetPixelGreen(image,p); break;
3439                 case 2: quantum=GetPixelBlue(image,p); break;
3440                 case 3: quantum=GetPixelAlpha(image,p); break;
3441               }
3442               switch (n % 3)
3443               {
3444                 case 0:
3445                 {
3446                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3447                     range) << 22);
3448                   break;
3449                 }
3450                 case 1:
3451                 {
3452                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3453                     range) << 12);
3454                   break;
3455                 }
3456                 case 2:
3457                 {
3458                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3459                     range) << 2);
3460                   q=PopLongPixel(quantum_info->endian,pixel,q);
3461                   pixel=0;
3462                   break;
3463                 }
3464               }
3465               n++;
3466             }
3467             p+=GetPixelChannels(image);
3468             q+=quantum_info->pad;
3469           }
3470           break;
3471         }
3472       if (quantum_info->quantum == 32UL)
3473         {
3474           for (x=0; x < (ssize_t) number_pixels; x++)
3475           {
3476             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3477             q=PopQuantumLongPixel(quantum_info,pixel,q);
3478             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3479               range);
3480             q=PopQuantumLongPixel(quantum_info,pixel,q);
3481             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3482             q=PopQuantumLongPixel(quantum_info,pixel,q);
3483             pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
3484               range);
3485             q=PopQuantumLongPixel(quantum_info,pixel,q);
3486             p+=GetPixelChannels(image);
3487             q+=quantum_info->pad;
3488           }
3489           break;
3490         }
3491       for (x=0; x < (ssize_t) number_pixels; x++)
3492       {
3493         pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3494         q=PopQuantumPixel(quantum_info,pixel,q);
3495         pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3496         q=PopQuantumPixel(quantum_info,pixel,q);
3497         pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3498         q=PopQuantumPixel(quantum_info,pixel,q);
3499         pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),range);
3500         q=PopQuantumPixel(quantum_info,pixel,q);
3501         p+=GetPixelChannels(image);
3502         q+=quantum_info->pad;
3503       }
3504       break;
3505     }
3506     case 16:
3507     {
3508       register unsigned short
3509         pixel;
3510
3511       if (quantum_info->format == FloatingPointQuantumFormat)
3512         {
3513           for (x=0; x < (ssize_t) number_pixels; x++)
3514           {
3515             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
3516             q=PopShortPixel(quantum_info->endian,pixel,q);
3517             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
3518             q=PopShortPixel(quantum_info->endian,pixel,q);
3519             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
3520             q=PopShortPixel(quantum_info->endian,pixel,q);
3521             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelAlpha(image,p));
3522             q=PopShortPixel(quantum_info->endian,pixel,q);
3523             p+=GetPixelChannels(image);
3524             q+=quantum_info->pad;
3525           }
3526           break;
3527         }
3528       for (x=0; x < (ssize_t) number_pixels; x++)
3529       {
3530         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3531         q=PopShortPixel(quantum_info->endian,pixel,q);
3532         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3533         q=PopShortPixel(quantum_info->endian,pixel,q);
3534         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3535         q=PopShortPixel(quantum_info->endian,pixel,q);
3536         pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
3537         q=PopShortPixel(quantum_info->endian,pixel,q);
3538         p+=GetPixelChannels(image);
3539         q+=quantum_info->pad;
3540       }
3541       break;
3542     }
3543     case 32:
3544     {
3545       register unsigned int
3546         pixel;
3547
3548       if (quantum_info->format == FloatingPointQuantumFormat)
3549         {
3550           for (x=0; x < (ssize_t) number_pixels; x++)
3551           {
3552             float
3553               pixel;
3554
3555             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3556             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
3557             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
3558             pixel=(float) GetPixelAlpha(image,p);
3559             q=PopFloatPixel(quantum_info,pixel,q);
3560             p+=GetPixelChannels(image);
3561             q+=quantum_info->pad;
3562           }
3563           break;
3564         }
3565       for (x=0; x < (ssize_t) number_pixels; x++)
3566       {
3567         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3568         q=PopLongPixel(quantum_info->endian,pixel,q);
3569         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3570         q=PopLongPixel(quantum_info->endian,pixel,q);
3571         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3572         q=PopLongPixel(quantum_info->endian,pixel,q);
3573         pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
3574         q=PopLongPixel(quantum_info->endian,pixel,q);
3575         p+=GetPixelChannels(image);
3576         q+=quantum_info->pad;
3577       }
3578       break;
3579     }
3580     case 64:
3581     {
3582       if (quantum_info->format == FloatingPointQuantumFormat)
3583         {
3584           double
3585             pixel;
3586
3587           for (x=0; x < (ssize_t) number_pixels; x++)
3588           {
3589             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3590             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
3591             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
3592             pixel=(double) GetPixelAlpha(image,p);
3593             q=PopDoublePixel(quantum_info,pixel,q);
3594             p+=GetPixelChannels(image);
3595             q+=quantum_info->pad;
3596           }
3597           break;
3598         }
3599     }
3600     default:
3601     {
3602       range=GetQuantumRange(quantum_info->depth);
3603       for (x=0; x < (ssize_t) number_pixels; x++)
3604       {
3605         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3606           range),q);
3607         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3608           range),q);
3609         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3610           range),q);
3611         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
3612           range),q);
3613         p+=GetPixelChannels(image);
3614         q+=quantum_info->pad;
3615       }
3616       break;
3617     }
3618   }
3619 }
3620
3621 static void ExportRGBOQuantum(const Image *image,QuantumInfo *quantum_info,
3622   const MagickSizeType number_pixels,const Quantum *restrict p,
3623   unsigned char *restrict q,ExceptionInfo *exception)
3624 {
3625   QuantumAny
3626     range;
3627
3628   register ssize_t
3629     x;
3630
3631   assert(exception != (ExceptionInfo *) NULL);
3632   assert(exception->signature == MagickSignature);
3633   switch (quantum_info->depth)
3634   {
3635     case 8:
3636     {
3637       register unsigned char
3638         pixel;
3639
3640       for (x=0; x < (ssize_t) number_pixels; x++)
3641       {
3642         pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3643         q=PopCharPixel(pixel,q);
3644         pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3645         q=PopCharPixel(pixel,q);
3646         pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3647         q=PopCharPixel(pixel,q);
3648         pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
3649         q=PopCharPixel(pixel,q);
3650         p+=GetPixelChannels(image);
3651         q+=quantum_info->pad;
3652       }
3653       break;
3654     }
3655     case 10:
3656     {
3657       register unsigned int
3658         pixel;
3659
3660       range=GetQuantumRange(quantum_info->depth);
3661       if (quantum_info->pack == MagickFalse)
3662         {
3663           register ssize_t
3664             i;
3665
3666           size_t
3667             quantum;
3668
3669           ssize_t
3670             n;
3671
3672           n=0;
3673           quantum=0;
3674           pixel=0;
3675           for (x=0; x < (ssize_t) number_pixels; x++)
3676           {
3677             for (i=0; i < 4; i++)
3678             {
3679               switch (i)
3680               {
3681                 case 0: quantum=GetPixelRed(image,p); break;
3682                 case 1: quantum=GetPixelGreen(image,p); break;
3683                 case 2: quantum=GetPixelBlue(image,p); break;
3684                 case 3: quantum=GetPixelOpacity(image,p); break;
3685               }
3686               switch (n % 3)
3687               {
3688                 case 0:
3689                 {
3690                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3691                     range) << 22);
3692                   break;
3693                 }
3694                 case 1:
3695                 {
3696                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3697                     range) << 12);
3698                   break;
3699                 }
3700                 case 2:
3701                 {
3702                   pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3703                     range) << 2);
3704                   q=PopLongPixel(quantum_info->endian,pixel,q);
3705                   pixel=0;
3706                   break;
3707                 }
3708               }
3709               n++;
3710             }
3711             p+=GetPixelChannels(image);
3712             q+=quantum_info->pad;
3713           }
3714           break;
3715         }
3716       if (quantum_info->quantum == 32UL)
3717         {
3718           for (x=0; x < (ssize_t) number_pixels; x++)
3719           {
3720             pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3721             q=PopQuantumLongPixel(quantum_info,pixel,q);
3722             pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3723               range);
3724             q=PopQuantumLongPixel(quantum_info,pixel,q);
3725             pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3726             q=PopQuantumLongPixel(quantum_info,pixel,q);
3727             pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),
3728               range);
3729             q=PopQuantumLongPixel(quantum_info,pixel,q);
3730             p+=GetPixelChannels(image);
3731             q+=quantum_info->pad;
3732           }
3733           break;
3734         }
3735       for (x=0; x < (ssize_t) number_pixels; x++)
3736       {
3737         pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3738         q=PopQuantumPixel(quantum_info,pixel,q);
3739         pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3740         q=PopQuantumPixel(quantum_info,pixel,q);
3741         pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3742         q=PopQuantumPixel(quantum_info,pixel,q);
3743         pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),range);
3744         q=PopQuantumPixel(quantum_info,pixel,q);
3745         p+=GetPixelChannels(image);
3746         q+=quantum_info->pad;
3747       }
3748       break;
3749     }
3750     case 16:
3751     {
3752       register unsigned short
3753         pixel;
3754
3755       if (quantum_info->format == FloatingPointQuantumFormat)
3756         {
3757           for (x=0; x < (ssize_t) number_pixels; x++)
3758           {
3759             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelRed(image,p));
3760             q=PopShortPixel(quantum_info->endian,pixel,q);
3761             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelGreen(image,p));
3762             q=PopShortPixel(quantum_info->endian,pixel,q);
3763             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelBlue(image,p));
3764             q=PopShortPixel(quantum_info->endian,pixel,q);
3765             pixel=SinglePrecisionToHalf(QuantumScale*GetPixelOpacity(image,p));
3766             q=PopShortPixel(quantum_info->endian,pixel,q);
3767             p+=GetPixelChannels(image);
3768             q+=quantum_info->pad;
3769           }
3770           break;
3771         }
3772       for (x=0; x < (ssize_t) number_pixels; x++)
3773       {
3774         pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3775         q=PopShortPixel(quantum_info->endian,pixel,q);
3776         pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3777         q=PopShortPixel(quantum_info->endian,pixel,q);
3778         pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3779         q=PopShortPixel(quantum_info->endian,pixel,q);
3780         pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
3781         q=PopShortPixel(quantum_info->endian,pixel,q);
3782         p+=GetPixelChannels(image);
3783         q+=quantum_info->pad;
3784       }
3785       break;
3786     }
3787     case 32:
3788     {
3789       register unsigned int
3790         pixel;
3791
3792       if (quantum_info->format == FloatingPointQuantumFormat)
3793         {
3794           for (x=0; x < (ssize_t) number_pixels; x++)
3795           {
3796             float
3797               pixel;
3798
3799             q=PopFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3800             q=PopFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
3801             q=PopFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
3802             pixel=(float) GetPixelOpacity(image,p);
3803             q=PopFloatPixel(quantum_info,pixel,q);
3804             p+=GetPixelChannels(image);
3805             q+=quantum_info->pad;
3806           }
3807           break;
3808         }
3809       for (x=0; x < (ssize_t) number_pixels; x++)
3810       {
3811         pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3812         q=PopLongPixel(quantum_info->endian,pixel,q);
3813         pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3814         q=PopLongPixel(quantum_info->endian,pixel,q);
3815         pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3816         q=PopLongPixel(quantum_info->endian,pixel,q);
3817         pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
3818         q=PopLongPixel(quantum_info->endian,pixel,q);
3819         p+=GetPixelChannels(image);
3820         q+=quantum_info->pad;
3821       }
3822       break;
3823     }
3824     case 64:
3825     {
3826       if (quantum_info->format == FloatingPointQuantumFormat)
3827         {
3828           double
3829             pixel;
3830
3831           for (x=0; x < (ssize_t) number_pixels; x++)
3832           {
3833             q=PopDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3834             q=PopDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
3835             q=PopDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
3836             pixel=(double) GetPixelOpacity(image,p);
3837             q=PopDoublePixel(quantum_info,pixel,q);
3838             p+=GetPixelChannels(image);
3839             q+=quantum_info->pad;
3840           }
3841           break;
3842         }
3843     }
3844     default:
3845     {
3846       range=GetQuantumRange(quantum_info->depth);
3847       for (x=0; x < (ssize_t) number_pixels; x++)
3848       {
3849         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3850           range),q);
3851         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3852           range),q);
3853         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3854           range),q);
3855         q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p),
3856           range),q);
3857         p+=GetPixelChannels(image);
3858         q+=quantum_info->pad;
3859       }
3860       break;
3861     }
3862   }
3863 }
3864
3865 MagickExport size_t ExportQuantumPixels(const Image *image,
3866   CacheView *image_view,QuantumInfo *quantum_info,
3867   const QuantumType quantum_type,unsigned char *restrict pixels,
3868   ExceptionInfo *exception)
3869 {
3870   MagickSizeType
3871     number_pixels;
3872
3873   register const Quantum
3874     *restrict p;
3875
3876   register ssize_t
3877     x;
3878
3879   register unsigned char
3880     *restrict q;
3881
3882   size_t
3883     extent;
3884
3885   assert(image != (Image *) NULL);
3886   assert(image->signature == MagickSignature);
3887   if (image->debug != MagickFalse)
3888     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3889   assert(quantum_info != (QuantumInfo *) NULL);
3890   assert(quantum_info->signature == MagickSignature);
3891   if (pixels == (unsigned char *) NULL)
3892     pixels=(unsigned char *) GetQuantumPixels(quantum_info);
3893   if (image_view == (CacheView *) NULL)
3894     {
3895       number_pixels=GetImageExtent(image);
3896       p=GetVirtualPixelQueue(image);
3897     }
3898   else
3899     {
3900       number_pixels=GetCacheViewExtent(image_view);
3901       p=GetCacheViewVirtualPixelQueue(image_view);
3902     }
3903   if (quantum_info->alpha_type == AssociatedQuantumAlpha)
3904     {
3905       double
3906         Sa;
3907
3908       register Quantum
3909         *restrict q;
3910
3911       /*
3912         Associate alpha.
3913       */
3914       q=GetAuthenticPixelQueue(image);
3915       if (image_view != (CacheView *) NULL)
3916         q=GetCacheViewAuthenticPixelQueue(image_view);
3917       for (x=0; x < (ssize_t) image->columns; x++)
3918       {
3919         register ssize_t
3920           i;
3921
3922         if (GetPixelReadMask(image,q) == 0)
3923           {
3924             q+=GetPixelChannels(image);
3925             continue;
3926           }
3927         Sa=QuantumScale*GetPixelAlpha(image,q);
3928         for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3929         {
3930           PixelChannel channel=GetPixelChannelChannel(image,i);
3931           PixelTrait traits=GetPixelChannelTraits(image,channel);
3932           if ((traits & UpdatePixelTrait) == 0)
3933             continue;
3934           q[i]=ClampToQuantum(Sa*q[i]);
3935         }
3936         q+=GetPixelChannels(image);
3937       }
3938     }
3939   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3940     {
3941       Quantum
3942         quantum;
3943
3944       register Quantum
3945         *restrict q;
3946
3947       q=GetAuthenticPixelQueue(image);
3948       if (image_view != (CacheView *) NULL)
3949         q=GetAuthenticPixelQueue(image);
3950       for (x=0; x < (ssize_t) number_pixels; x++)
3951       {
3952         quantum=GetPixelRed(image,q);
3953         SetPixelRed(image,GetPixelGreen(image,q),q);
3954         SetPixelGreen(image,quantum,q);
3955         q+=GetPixelChannels(image);
3956       }
3957     }
3958   x=0;
3959   q=pixels;
3960   ResetQuantumState(quantum_info);
3961   extent=GetQuantumExtent(image,quantum_info,quantum_type);
3962   switch (quantum_type)
3963   {
3964     case AlphaQuantum:
3965     {
3966       ExportAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
3967       break;
3968     }
3969     case BGRQuantum:
3970     {
3971       ExportBGRQuantum(image,quantum_info,number_pixels,p,q,exception);
3972       break;
3973     }
3974     case BGRAQuantum:
3975     {
3976       ExportBGRAQuantum(image,quantum_info,number_pixels,p,q,exception);
3977       break;
3978     }
3979     case BGROQuantum:
3980     {
3981       ExportBGROQuantum(image,quantum_info,number_pixels,p,q,exception);
3982       break;
3983     }
3984     case BlackQuantum:
3985     {
3986       ExportBlackQuantum(image,quantum_info,number_pixels,p,q,exception);
3987       break;
3988     }
3989     case BlueQuantum:
3990     case YellowQuantum:
3991     {
3992       ExportBlueQuantum(image,quantum_info,number_pixels,p,q,exception);
3993       break;
3994     }
3995     case CMYKQuantum:
3996     {
3997       ExportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception);
3998       break;
3999     }
4000     case CMYKAQuantum:
4001     {
4002       ExportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception);
4003       break;
4004     }
4005     case CMYKOQuantum:
4006     {
4007       ExportCMYKOQuantum(image,quantum_info,number_pixels,p,q,exception);
4008       break;
4009     }
4010     case CbYCrYQuantum:
4011     {
4012       ExportCbYCrYQuantum(image,quantum_info,number_pixels,p,q,exception);
4013       break;
4014     }
4015     case GrayQuantum:
4016     {
4017       ExportGrayQuantum(image,quantum_info,number_pixels,p,q,exception);
4018       break;
4019     }
4020     case GrayAlphaQuantum:
4021     {
4022       ExportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
4023       break;
4024     }
4025     case GreenQuantum:
4026     case MagentaQuantum:
4027     {
4028       ExportGreenQuantum(image,quantum_info,number_pixels,p,q,exception);
4029       break;
4030     }
4031     case IndexQuantum:
4032     {
4033       ExportIndexQuantum(image,quantum_info,number_pixels,p,q,exception);
4034       break;
4035     }
4036     case IndexAlphaQuantum:
4037     {
4038       ExportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
4039       break;
4040     }
4041     case RedQuantum:
4042     case CyanQuantum:
4043     {
4044       ExportRedQuantum(image,quantum_info,number_pixels,p,q,exception);
4045       break;
4046     }
4047     case OpacityQuantum:
4048     {
4049       ExportOpacityQuantum(image,quantum_info,number_pixels,p,q,exception);
4050       break;
4051     }
4052     case RGBQuantum:
4053     case CbYCrQuantum:
4054     {
4055       ExportRGBQuantum(image,quantum_info,number_pixels,p,q,exception);
4056       break;
4057     }
4058     case RGBAQuantum:
4059     case CbYCrAQuantum:
4060     {
4061       ExportRGBAQuantum(image,quantum_info,number_pixels,p,q,exception);
4062       break;
4063     }
4064     case RGBOQuantum:
4065     {
4066       ExportRGBOQuantum(image,quantum_info,number_pixels,p,q,exception);
4067       break;
4068     }
4069     default:
4070       break;
4071   }
4072   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
4073     {
4074       Quantum
4075         quantum;
4076
4077       register Quantum
4078         *restrict q;
4079
4080       q=GetAuthenticPixelQueue(image);
4081       if (image_view != (CacheView *) NULL)
4082         q=GetCacheViewAuthenticPixelQueue(image_view);
4083       for (x=0; x < (ssize_t) number_pixels; x++)
4084       {
4085         quantum=GetPixelRed(image,q);
4086         SetPixelRed(image,GetPixelGreen(image,q),q);
4087         SetPixelGreen(image,quantum,q);
4088         q+=GetPixelChannels(image);
4089       }
4090     }
4091   return(extent);
4092 }