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