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