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