]> granicus.if.org Git - imagemagick/blob - magick/quantum-import.c
(no commit message)
[imagemagick] / magick / 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-2008 ImageMagick Studio LLC, a non-profit organization      %
26 %  dedicated to making software imaging solutions freely available.           %
27 %                                                                             %
28 %  You may not use this file except in compliance with the License.  You may  %
29 %  obtain a copy of the License at                                            %
30 %                                                                             %
31 %    http://www.imagemagick.org/script/license.php                            %
32 %                                                                             %
33 %  Unless required by applicable law or agreed to in writing, software        %
34 %  distributed under the License is distributed on an "AS IS" BASIS,          %
35 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
36 %  See the License for the specific language governing permissions and        %
37 %  limitations under the License.                                             %
38 %                                                                             %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %
41 %
42 */
43 \f
44 /*
45   Include declarations.
46 */
47 #include "magick/studio.h"
48 #include "magick/property.h"
49 #include "magick/blob.h"
50 #include "magick/blob-private.h"
51 #include "magick/color-private.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/cache.h"
55 #include "magick/constitute.h"
56 #include "magick/delegate.h"
57 #include "magick/geometry.h"
58 #include "magick/list.h"
59 #include "magick/magick.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/option.h"
63 #include "magick/pixel.h"
64 #include "magick/pixel-private.h"
65 #include "magick/quantum.h"
66 #include "magick/quantum-private.h"
67 #include "magick/resource_.h"
68 #include "magick/semaphore.h"
69 #include "magick/statistic.h"
70 #include "magick/stream.h"
71 #include "magick/string_.h"
72 #include "magick/utility.h"
73 \f
74 /*
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 %                                                                             %
77 %                                                                             %
78 %                                                                             %
79 %   I m p o r t Q u a n t u m P i x e l s                                     %
80 %                                                                             %
81 %                                                                             %
82 %                                                                             %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84 %
85 %  ImportQuantumPixels() transfers one or more pixel components from a user
86 %  supplied buffer into the image pixel cache of an image.  The pixels are
87 %  expected in network byte order.  It returns MagickTrue if the pixels are
88 %  successfully transferred, otherwise MagickFalse.
89 %
90 %  The format of the ImportQuantumPixels method is:
91 %
92 %      size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93 %        const QuantumInfo *quantum_info,const QuantumType quantum_type,
94 %        const unsigned char *pixels,ExceptionInfo *exception)
95 %
96 %  A description of each parameter follows:
97 %
98 %    o image: the image.
99 %
100 %    o image_view: the image cache view.
101 %
102 %    o quantum_info: the quantum info.
103 %
104 %    o quantum_type: Declare which pixel components to transfer (red, green,
105 %      blue, opacity, RGB, or RGBA).
106 %
107 %    o pixels:  The pixel components are transferred from this buffer.
108 %
109 %    o exception: return any errors or warnings in this structure.
110 %
111 */
112
113 static inline IndexPacket PushColormapIndex(Image *image,
114   const unsigned long index,MagickBooleanType *range_exception)
115 {
116   if (index < image->colors)
117     return((IndexPacket) index);
118   *range_exception=MagickTrue;
119   return((IndexPacket) 0);
120 }
121
122 static inline const unsigned char *PushDoublePixel(
123   const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
124 {
125   double
126     *p;
127
128   unsigned char
129     quantum[8];
130
131   if (quantum_state->endian != LSBEndian)
132     {
133       quantum[7]=(*pixels++);
134       quantum[6]=(*pixels++);
135       quantum[5]=(*pixels++);
136       quantum[5]=(*pixels++);
137       quantum[3]=(*pixels++);
138       quantum[2]=(*pixels++);
139       quantum[1]=(*pixels++);
140       quantum[0]=(*pixels++);
141       p=(double *) quantum;
142       *pixel=(*p);
143       *pixel-=quantum_state->minimum;
144       *pixel*=quantum_state->scale;
145       return(pixels);
146     }
147   quantum[0]=(*pixels++);
148   quantum[1]=(*pixels++);
149   quantum[2]=(*pixels++);
150   quantum[3]=(*pixels++);
151   quantum[4]=(*pixels++);
152   quantum[5]=(*pixels++);
153   quantum[6]=(*pixels++);
154   quantum[7]=(*pixels++);
155   p=(double *) quantum;
156   *pixel=(*p);
157   *pixel-=quantum_state->minimum;
158   *pixel*=quantum_state->scale;
159   return(pixels);
160 }
161
162 static inline const unsigned char *PushFloatPixel(
163   const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
164 {
165   float
166     *p;
167
168   unsigned char
169     quantum[4];
170
171   if (quantum_state->endian != LSBEndian)
172     {
173       quantum[3]=(*pixels++);
174       quantum[2]=(*pixels++);
175       quantum[1]=(*pixels++);
176       quantum[0]=(*pixels++);
177       p=(float *) quantum;
178       *pixel=(*p);
179       *pixel-=quantum_state->minimum;
180       *pixel*=quantum_state->scale;
181       return(pixels);
182     }
183   quantum[0]=(*pixels++);
184   quantum[1]=(*pixels++);
185   quantum[2]=(*pixels++);
186   quantum[3]=(*pixels++);
187   p=(float *) quantum;
188   *pixel=(*p);
189   *pixel-=quantum_state->minimum;
190   *pixel*=quantum_state->scale;
191   return(pixels);
192 }
193
194 static inline const unsigned char *PushQuantumPixel(
195   QuantumState *quantum_state,const unsigned long depth,
196   const unsigned char *pixels,unsigned long *quantum)
197 {
198   register long
199     i;
200
201   register unsigned long
202     quantum_bits;
203
204   *quantum=(QuantumAny) 0;
205   for (i=(long) depth; i > 0L; )
206   {
207     if (quantum_state->bits == 0UL)
208       {
209         quantum_state->pixel=(*pixels++);
210         quantum_state->bits=8UL;
211       }
212     quantum_bits=(unsigned long) i;
213     if (quantum_bits > quantum_state->bits)
214       quantum_bits=quantum_state->bits;
215     i-=quantum_bits;
216     quantum_state->bits-=quantum_bits;
217     *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218       quantum_state->bits) &~ ((~0UL) << quantum_bits));
219   }
220   return(pixels);
221 }
222
223 static inline const unsigned char *PushQuantumLongPixel(
224   QuantumState *quantum_state,const unsigned long depth,
225   const unsigned char *pixels,unsigned long *quantum)
226 {
227   register long
228     i;
229
230   register unsigned long
231     quantum_bits;
232
233   *quantum=0UL;
234   for (i=(long) depth; i > 0; )
235   {
236     if (quantum_state->bits == 0)
237       {
238         pixels=PushLongPixel(quantum_state->endian,pixels,
239           &quantum_state->pixel);
240         quantum_state->bits=32UL;
241       }
242     quantum_bits=(unsigned long) i;
243     if (quantum_bits > quantum_state->bits)
244       quantum_bits=quantum_state->bits;
245     *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246       quantum_state->mask[quantum_bits]) << (depth-i));
247     i-=quantum_bits;
248     quantum_state->bits-=quantum_bits;
249   }
250   return(pixels);
251 }
252
253 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
254   const QuantumInfo *quantum_info,const QuantumType quantum_type,
255   const unsigned char *pixels,ExceptionInfo *exception)
256 {
257   EndianType
258     endian;
259
260   long
261     bit;
262
263   MagickSizeType
264     number_pixels;
265
266   QuantumAny
267     range;
268
269   QuantumState
270     quantum_state;
271
272   register const unsigned char
273     *restrict p;
274
275   register IndexPacket
276     *restrict indexes;
277
278   register long
279     x;
280
281   register PixelPacket
282     *restrict q;
283
284   size_t
285     extent;
286
287   unsigned long
288     pixel;
289
290   assert(image != (Image *) NULL);
291   assert(image->signature == MagickSignature);
292   if (image->debug != MagickFalse)
293     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
294   assert(quantum_info != (QuantumInfo *) NULL);
295   assert(quantum_info->signature == MagickSignature);
296   if (pixels == (const unsigned char *) NULL)
297     pixels=GetQuantumPixels(quantum_info);
298   x=0;
299   p=pixels;
300   number_pixels=GetImageExtent(image);
301   q=GetAuthenticPixelQueue(image);
302   indexes=GetAuthenticIndexQueue(image);
303   if (image_view != (CacheView *) NULL)
304     {
305       number_pixels=GetCacheViewExtent(image_view);
306       q=GetCacheViewAuthenticPixelQueue(image_view);
307       indexes=GetCacheViewAuthenticIndexQueue(image_view);
308     }
309   InitializeQuantumState(quantum_info,image->endian,&quantum_state);
310   extent=GetQuantumExtent(image,quantum_info,quantum_type);
311   endian=quantum_state.endian;
312   switch (quantum_type)
313   {
314     case IndexQuantum:
315     {
316       MagickBooleanType
317         range_exception;
318
319       if (image->storage_class != PseudoClass)
320         {
321           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
322             "ColormappedImageRequired","`%s'",image->filename);
323           return(extent);
324         }
325       range_exception=MagickFalse;
326       switch (quantum_info->depth)
327       {
328         case 1:
329         {
330           register unsigned char
331             pixel;
332
333           for (x=0; x < ((long) number_pixels-7); x+=8)
334           {
335             for (bit=0; bit < 8; bit++)
336             {
337               if (quantum_info->min_is_white == MagickFalse)
338                 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
339                   0x00 : 0x01);
340               else
341                 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
342                   0x00 : 0x01);
343               indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
344               *q=image->colormap[(long) indexes[x+bit]];
345               q++;
346             }
347             p++;
348           }
349           for (bit=0; bit < (long) (number_pixels % 8); bit++)
350           {
351             if (quantum_info->min_is_white == MagickFalse)
352               pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
353                 0x00 : 0x01);
354             else
355               pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
356                 0x00 : 0x01);
357             indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
358             *q=image->colormap[(long) indexes[x+bit]];
359             q++;
360           }
361           break;
362         }
363         case 4:
364         {
365           register unsigned char
366             pixel;
367
368           for (x=0; x < ((long) number_pixels-1); x+=2)
369           {
370             pixel=(unsigned char) ((*p >> 4) & 0xf);
371             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
372             *q=image->colormap[(long) indexes[x]];
373             q++;
374             pixel=(unsigned char) ((*p) & 0xf);
375             indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
376             *q=image->colormap[(long) indexes[x+1]];
377             p++;
378             q++;
379           }
380           for (bit=0; bit < (long) (number_pixels % 2); bit++)
381           {
382             pixel=(unsigned char) ((*p++ >> 4) & 0xf);
383             indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
384             *q=image->colormap[(long) indexes[x+bit]];
385             q++;
386           }
387           break;
388         }
389         case 8:
390         {
391           unsigned char
392             pixel;
393
394           for (x=0; x < (long) number_pixels; x++)
395           {
396             p=PushCharPixel(p,&pixel);
397             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
398             *q=image->colormap[(long) indexes[x]];
399             p+=quantum_info->pad;
400             q++;
401           }
402           break;
403         }
404         case 16:
405         {
406           unsigned short
407             pixel;
408
409           if (quantum_info->format == FloatingPointQuantumFormat)
410             {
411               for (x=0; x < (long) number_pixels; x++)
412               {
413                 p=PushShortPixel(endian,p,&pixel);
414                 indexes[x]=PushColormapIndex(image,ClampToQuantum(
415                   (MagickRealType) QuantumRange*
416                   Binary16ToSinglePrecision(pixel)),&range_exception);
417                 *q=image->colormap[(long) indexes[x]];
418                 p+=quantum_info->pad;
419                 q++;
420               }
421               break;
422             }
423           for (x=0; x < (long) number_pixels; x++)
424           {
425             p=PushShortPixel(endian,p,&pixel);
426             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
427             *q=image->colormap[(long) indexes[x]];
428             p+=quantum_info->pad;
429             q++;
430           }
431           break;
432         }
433         case 32:
434         {
435           unsigned long
436             pixel;
437
438           if (quantum_info->format == FloatingPointQuantumFormat)
439             {
440               float
441                 pixel;
442
443               for (x=0; x < (long) number_pixels; x++)
444               {
445                 p=PushFloatPixel(&quantum_state,p,&pixel);
446                 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
447                   &range_exception);
448                 *q=image->colormap[(long) indexes[x]];
449                 p+=quantum_info->pad;
450                 q++;
451               }
452               break;
453             }
454           for (x=0; x < (long) number_pixels; x++)
455           {
456             p=PushLongPixel(endian,p,&pixel);
457             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
458             *q=image->colormap[(long) indexes[x]];
459             p+=quantum_info->pad;
460             q++;
461           }
462           break;
463         }
464         case 64:
465         {
466           if (quantum_info->format == FloatingPointQuantumFormat)
467             {
468               double
469                 pixel;
470
471               for (x=0; x < (long) number_pixels; x++)
472               {
473                 p=PushDoublePixel(&quantum_state,p,&pixel);
474                 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
475                   &range_exception);
476                 *q=image->colormap[(long) indexes[x]];
477                 p+=quantum_info->pad;
478                 q++;
479               }
480               break;
481             }
482         }
483         default:
484         {
485           for (x=0; x < (long) number_pixels; x++)
486           {
487             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
488             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
489             *q=image->colormap[(long) indexes[x]];
490             p+=quantum_info->pad;
491             q++;
492           }
493           break;
494         }
495       }
496       if (range_exception != MagickFalse)
497         (void) ThrowMagickException(exception,GetMagickModule(),
498           CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
499       break;
500     }
501     case IndexAlphaQuantum:
502     {
503       MagickBooleanType
504         range_exception;
505
506       if (image->storage_class != PseudoClass)
507         {
508           (void) ThrowMagickException(exception,GetMagickModule(),
509             ImageError,"ColormappedImageRequired","`%s'",image->filename);
510           return(extent);
511         }
512       range_exception=MagickFalse;
513       switch (quantum_info->depth)
514       {
515         case 1:
516         {
517           register unsigned char
518             pixel;
519
520           for (x=0; x < ((long) number_pixels-3); x+=4)
521           {
522             for (bit=0; bit < 8; bit+=2)
523             {
524               if (quantum_info->min_is_white == MagickFalse)
525                 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
526                   0x00 : 0x01);
527               else
528                 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
529                   0x00 : 0x01);
530               indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
531               q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
532               q->green=q->red;
533               q->blue=q->red;
534               q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
535                 == 0 ? TransparentOpacity : OpaqueOpacity);
536               q++;
537             }
538           }
539           for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
540           {
541             if (quantum_info->min_is_white == MagickFalse)
542               pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
543                 0x00 : 0x01);
544             else
545               pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
546                 0x00 : 0x01);
547             indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
548             q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
549             q->green=q->red;
550             q->blue=q->red;
551             q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
552               0 ? TransparentOpacity : OpaqueOpacity);
553             q++;
554           }
555           break;
556         }
557         case 4:
558         {
559           register unsigned char
560             pixel;
561
562           range=GetQuantumRange(image->depth);
563           for (x=0; x < (long) number_pixels; x++)
564           {
565             pixel=(unsigned char) ((*p >> 4) & 0xf);
566             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
567             *q=image->colormap[(long) indexes[x]];
568             pixel=(unsigned char) ((*p) & 0xf);
569             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
570             p++;
571             q++;
572           }
573           break;
574         }
575         case 8:
576         {
577           unsigned char
578             pixel;
579
580           for (x=0; x < (long) number_pixels; x++)
581           {
582             p=PushCharPixel(p,&pixel);
583             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
584             *q=image->colormap[(long) indexes[x]];
585             p=PushCharPixel(p,&pixel);
586             q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
587             p+=quantum_info->pad;
588             q++;
589           }
590           break;
591         }
592         case 16:
593         {
594           unsigned short
595             pixel;
596
597           if (quantum_info->format == FloatingPointQuantumFormat)
598             {
599               for (x=0; x < (long) number_pixels; x++)
600               {
601                 p=PushShortPixel(endian,p,&pixel);
602                 indexes[x]=PushColormapIndex(image,ClampToQuantum(
603                   (MagickRealType) QuantumRange*
604                   Binary16ToSinglePrecision(pixel)),&range_exception);
605                 *q=image->colormap[(long) indexes[x]];
606                 p=PushShortPixel(endian,p,&pixel);
607                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
608                   (MagickRealType) QuantumRange*
609                   Binary16ToSinglePrecision(pixel)));
610                 p+=quantum_info->pad;
611                 q++;
612               }
613               break;
614             }
615           for (x=0; x < (long) number_pixels; x++)
616           {
617             p=PushShortPixel(endian,p,&pixel);
618             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
619             *q=image->colormap[(long) indexes[x]];
620             p=PushShortPixel(endian,p,&pixel);
621             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
622             p+=quantum_info->pad;
623             q++;
624           }
625           break;
626         }
627         case 32:
628         {
629           unsigned long
630             pixel;
631
632           if (quantum_info->format == FloatingPointQuantumFormat)
633             {
634               float
635                 pixel;
636
637               for (x=0; x < (long) number_pixels; x++)
638               {
639                 p=PushFloatPixel(&quantum_state,p,&pixel);
640                 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
641                   &range_exception);
642                 *q=image->colormap[(long) indexes[x]];
643                 p=PushFloatPixel(&quantum_state,p,&pixel);
644                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
645                 p+=quantum_info->pad;
646                 q++;
647               }
648               break;
649             }
650           for (x=0; x < (long) number_pixels; x++)
651           {
652             p=PushLongPixel(endian,p,&pixel);
653             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
654             *q=image->colormap[(long) indexes[x]];
655             p=PushLongPixel(endian,p,&pixel);
656             q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
657             p+=quantum_info->pad;
658             q++;
659           }
660           break;
661         }
662         case 64:
663         {
664           if (quantum_info->format == FloatingPointQuantumFormat)
665             {
666               double
667                 pixel;
668
669               for (x=0; x < (long) number_pixels; x++)
670               {
671                 p=PushDoublePixel(&quantum_state,p,&pixel);
672                 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
673                   &range_exception);
674                 *q=image->colormap[(long) indexes[x]];
675                 p=PushDoublePixel(&quantum_state,p,&pixel);
676                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
677                 p+=quantum_info->pad;
678                 q++;
679               }
680               break;
681             }
682         }
683         default:
684         {
685           range=GetQuantumRange(image->depth);
686           for (x=0; x < (long) number_pixels; x++)
687           {
688             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
689             indexes[x]=PushColormapIndex(image,pixel,&range_exception);
690             *q=image->colormap[(long) indexes[x]];
691             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
692             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
693             p+=quantum_info->pad;
694             q++;
695           }
696           break;
697         }
698       }
699       if (range_exception != MagickFalse)
700         (void) ThrowMagickException(exception,GetMagickModule(),
701           CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
702       break;
703     }
704     case GrayQuantum:
705     {
706       switch (quantum_info->depth)
707       {
708         case 1:
709         {
710           register Quantum
711             black,
712             white;
713
714           black=0;
715           white=(Quantum) QuantumRange;
716           if (quantum_info->min_is_white != MagickFalse)
717             {
718               black=(Quantum) QuantumRange;
719               white=0;
720             }
721           for (x=0; x < ((long) number_pixels-7); x+=8)
722           {
723             for (bit=0; bit < 8; bit++)
724             {
725               q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
726               q->green=q->red;
727               q->blue=q->red;
728               q++;
729             }
730             p++;
731           }
732           for (bit=0; bit < (long) (number_pixels % 8); bit++)
733           {
734             q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
735             q->green=q->red;
736             q->blue=q->red;
737             q++;
738           }
739           if (bit != 0)
740             p++;
741           break;
742         }
743         case 4:
744         {
745           register unsigned char
746             pixel;
747
748           range=GetQuantumRange(image->depth);
749           for (x=0; x < ((long) number_pixels-1); x+=2)
750           {
751             pixel=(unsigned char) ((*p >> 4) & 0xf);
752             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
753             q->green=q->red;
754             q->blue=q->red;
755             q++;
756             pixel=(unsigned char) ((*p) & 0xf);
757             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
758             q->green=q->red;
759             q->blue=q->red;
760             p++;
761             q++;
762           }
763           for (bit=0; bit < (long) (number_pixels % 2); bit++)
764           {
765             pixel=(unsigned char) (*p++ >> 4);
766             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
767             q->green=q->red;
768             q->blue=q->red;
769             q++;
770           }
771           break;
772         }
773         case 8:
774         {
775           unsigned char
776             pixel;
777
778           if (quantum_info->min_is_white != MagickFalse)
779             {
780               for (x=0; x < (long) number_pixels; x++)
781               {
782                 p=PushCharPixel(p,&pixel);
783                 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
784                 q->green=q->red;
785                 q->blue=q->red;
786                 SetOpacityPixelComponent(q,OpaqueOpacity);
787                 p+=quantum_info->pad;
788                 q++;
789               }
790               break;
791             }
792           for (x=0; x < (long) number_pixels; x++)
793           {
794             p=PushCharPixel(p,&pixel);
795             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
796             q->green=q->red;
797             q->blue=q->red;
798             SetOpacityPixelComponent(q,OpaqueOpacity);
799             p+=quantum_info->pad;
800             q++;
801           }
802           break;
803         }
804         case 10:
805         {
806           range=GetQuantumRange(image->depth);
807           if (quantum_info->pack == MagickFalse)
808             {
809               if (image->endian != LSBEndian)
810                 {
811                   for (x=0; x < (long) number_pixels/3; x++)
812                   {
813                     p=PushLongPixel(endian,p,&pixel);
814                     q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
815                     q->green=q->red;
816                     q->blue=q->red;
817                     q++;
818                     q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
819                     q->green=q->red;
820                     q->blue=q->red;
821                     q++;
822                     q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
823                     q->green=q->red;
824                     q->blue=q->red;
825                     p+=quantum_info->pad;
826                     q++;
827                   }
828                   break;
829                 }
830               for (x=0; x < (long) number_pixels/3; x++)
831               {
832                 p=PushLongPixel(endian,p,&pixel);
833                 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
834                 q->green=q->red;
835                 q->blue=q->red;
836                 q++;
837                 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
838                 q->green=q->red;
839                 q->blue=q->red;
840                 q++;
841                 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
842                 q->green=q->red;
843                 q->blue=q->red;
844                 p+=quantum_info->pad;
845                 q++;
846               }
847               break;
848             }
849           for (x=0; x < (long) number_pixels; x++)
850           {
851             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
852             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
853             q->green=q->red;
854             q->blue=q->red;
855             p+=quantum_info->pad;
856             q++;
857           }
858           break;
859         }
860         case 12:
861         {
862           range=GetQuantumRange(image->depth);
863           if (quantum_info->pack == MagickFalse)
864             {
865               unsigned short
866                 pixel;
867
868               for (x=0; x < (long) (number_pixels-1); x+=2)
869               {
870                 p=PushShortPixel(endian,p,&pixel);
871                 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
872                 q->green=q->red;
873                 q->blue=q->red;
874                 q++;
875                 p=PushShortPixel(endian,p,&pixel);
876                 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
877                 q->green=q->red;
878                 q->blue=q->red;
879                 p+=quantum_info->pad;
880                 q++;
881               }
882               for (bit=0; bit < (long) (number_pixels % 2); bit++)
883               {
884                 p=PushShortPixel(endian,p,&pixel);
885                 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
886                 q->green=q->red;
887                 q->blue=q->red;
888                 p+=quantum_info->pad;
889                 q++;
890               }
891               if (bit != 0)
892                 p++;
893               break;
894             }
895           for (x=0; x < (long) number_pixels; x++)
896           {
897             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
898             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
899             q->green=q->red;
900             q->blue=q->red;
901             p+=quantum_info->pad;
902             q++;
903           }
904           break;
905         }
906         case 16:
907         {
908           unsigned short
909             pixel;
910
911           if (quantum_info->min_is_white != MagickFalse)
912             {
913               for (x=0; x < (long) number_pixels; x++)
914               {
915                 p=PushShortPixel(endian,p,&pixel);
916                 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
917                 q->green=q->red;
918                 q->blue=q->red;
919                 p+=quantum_info->pad;
920                 q++;
921               }
922               break;
923             }
924           if (quantum_info->format == FloatingPointQuantumFormat)
925             {
926               for (x=0; x < (long) number_pixels; x++)
927               {
928                 p=PushShortPixel(endian,p,&pixel);
929                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
930                   Binary16ToSinglePrecision(pixel));
931                 q->green=q->red;
932                 q->blue=q->red;
933                 p+=quantum_info->pad;
934                 q++;
935               }
936               break;
937             }
938           for (x=0; x < (long) number_pixels; x++)
939           {
940             p=PushShortPixel(endian,p,&pixel);
941             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
942             q->green=q->red;
943             q->blue=q->red;
944             p+=quantum_info->pad;
945             q++;
946           }
947           break;
948         }
949         case 32:
950         {
951           unsigned long
952             pixel;
953
954           if (quantum_info->format == FloatingPointQuantumFormat)
955             {
956               float
957                 pixel;
958
959               for (x=0; x < (long) number_pixels; x++)
960               {
961                 p=PushFloatPixel(&quantum_state,p,&pixel);
962                 q->red=ClampToQuantum(pixel);
963                 q->green=q->red;
964                 q->blue=q->red;
965                 p+=quantum_info->pad;
966                 q++;
967               }
968               break;
969             }
970           for (x=0; x < (long) number_pixels; x++)
971           {
972             p=PushLongPixel(endian,p,&pixel);
973             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
974             q->green=q->red;
975             q->blue=q->red;
976             p+=quantum_info->pad;
977             q++;
978           }
979           break;
980         }
981         case 64:
982         {
983           if (quantum_info->format == FloatingPointQuantumFormat)
984             {
985               double
986                 pixel;
987
988               for (x=0; x < (long) number_pixels; x++)
989               {
990                 p=PushDoublePixel(&quantum_state,p,&pixel);
991                 q->red=ClampToQuantum(pixel);
992                 q->green=q->red;
993                 q->blue=q->red;
994                 p+=quantum_info->pad;
995                 q++;
996               }
997               break;
998             }
999         }
1000         default:
1001         {
1002           range=GetQuantumRange(image->depth);
1003           for (x=0; x < (long) number_pixels; x++)
1004           {
1005             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1006             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1007             q->green=q->red;
1008             q->blue=q->red;
1009             p+=quantum_info->pad;
1010             q++;
1011           }
1012           break;
1013         }
1014       }
1015       break;
1016     }
1017     case GrayAlphaQuantum:
1018     {
1019       switch (quantum_info->depth)
1020       {
1021         case 1:
1022         {
1023           register unsigned char
1024             pixel;
1025
1026           for (x=0; x < ((long) number_pixels-3); x+=4)
1027           {
1028             for (bit=0; bit < 8; bit+=2)
1029             {
1030               pixel=(unsigned char)
1031                 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1032               q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1033               q->green=q->red;
1034               q->blue=q->red;
1035               q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1036                 == 0 ? TransparentOpacity : OpaqueOpacity);
1037               q++;
1038             }
1039             p++;
1040           }
1041           for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
1042           {
1043             pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1044             q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1045             q->green=q->red;
1046             q->blue=q->red;
1047             q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1048               ? TransparentOpacity : OpaqueOpacity);
1049             q++;
1050           }
1051           if (bit != 0)
1052             p++;
1053           break;
1054         }
1055         case 4:
1056         {
1057           register unsigned char
1058             pixel;
1059
1060           range=GetQuantumRange(image->depth);
1061           for (x=0; x < (long) number_pixels; x++)
1062           {
1063             pixel=(unsigned char) ((*p >> 4) & 0xf);
1064             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1065             q->green=q->red;
1066             q->blue=q->red;
1067             pixel=(unsigned char) ((*p) & 0xf);
1068             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1069             p++;
1070             q++;
1071           }
1072           break;
1073         }
1074         case 8:
1075         {
1076           unsigned char
1077             pixel;
1078
1079           for (x=0; x < (long) number_pixels; x++)
1080           {
1081             p=PushCharPixel(p,&pixel);
1082             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1083             q->green=q->red;
1084             q->blue=q->red;
1085             p=PushCharPixel(p,&pixel);
1086             q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1087             p+=quantum_info->pad;
1088             q++;
1089           }
1090           break;
1091         }
1092         case 10:
1093         {
1094           range=GetQuantumRange(image->depth);
1095           for (x=0; x < (long) number_pixels; x++)
1096           {
1097             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1098             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1099             q->green=q->red;
1100             q->blue=q->red;
1101             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1102             SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1103             p+=quantum_info->pad;
1104             q++;
1105           }
1106           break;
1107         }
1108         case 12:
1109         {
1110           range=GetQuantumRange(image->depth);
1111           for (x=0; x < (long) number_pixels; x++)
1112           {
1113             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1114             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1115             q->green=q->red;
1116             q->blue=q->red;
1117             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1118             SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1119             p+=quantum_info->pad;
1120             q++;
1121           }
1122           break;
1123         }
1124         case 16:
1125         {
1126           unsigned short
1127             pixel;
1128
1129           if (quantum_info->format == FloatingPointQuantumFormat)
1130             {
1131               for (x=0; x < (long) number_pixels; x++)
1132               {
1133                 p=PushShortPixel(endian,p,&pixel);
1134                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1135                   Binary16ToSinglePrecision(pixel));
1136                 q->green=q->red;
1137                 q->blue=q->red;
1138                 p=PushShortPixel(endian,p,&pixel);
1139                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1140                   (MagickRealType) QuantumRange*
1141                   Binary16ToSinglePrecision(pixel)));
1142                 p+=quantum_info->pad;
1143                 q++;
1144               }
1145               break;
1146             }
1147           for (x=0; x < (long) number_pixels; x++)
1148           {
1149             p=PushShortPixel(endian,p,&pixel);
1150             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1151             q->green=q->red;
1152             q->blue=q->red;
1153             p=PushShortPixel(endian,p,&pixel);
1154             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1155             p+=quantum_info->pad;
1156             q++;
1157           }
1158           break;
1159         }
1160         case 32:
1161         {
1162           unsigned long
1163             pixel;
1164
1165           if (quantum_info->format == FloatingPointQuantumFormat)
1166             {
1167               float
1168                 pixel;
1169
1170               for (x=0; x < (long) number_pixels; x++)
1171               {
1172                 p=PushFloatPixel(&quantum_state,p,&pixel);
1173                 q->red=ClampToQuantum(pixel);
1174                 q->green=q->red;
1175                 q->blue=q->red;
1176                 p=PushFloatPixel(&quantum_state,p,&pixel);
1177                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1178                 p+=quantum_info->pad;
1179                 q++;
1180               }
1181               break;
1182             }
1183           for (x=0; x < (long) number_pixels; x++)
1184           {
1185             p=PushLongPixel(endian,p,&pixel);
1186             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1187             q->green=q->red;
1188             q->blue=q->red;
1189             p=PushLongPixel(endian,p,&pixel);
1190             q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1191             p+=quantum_info->pad;
1192             q++;
1193           }
1194           break;
1195         }
1196         case 64:
1197         {
1198           if (quantum_info->format == FloatingPointQuantumFormat)
1199             {
1200               double
1201                 pixel;
1202
1203               for (x=0; x < (long) number_pixels; x++)
1204               {
1205                 p=PushDoublePixel(&quantum_state,p,&pixel);
1206                 q->red=ClampToQuantum(pixel);
1207                 q->green=q->red;
1208                 q->blue=q->red;
1209                 p=PushDoublePixel(&quantum_state,p,&pixel);
1210                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1211                 p+=quantum_info->pad;
1212                 q++;
1213               }
1214               break;
1215             }
1216         }
1217         default:
1218         {
1219           range=GetQuantumRange(image->depth);
1220           for (x=0; x < (long) number_pixels; x++)
1221           {
1222             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1223             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1224             q->green=q->red;
1225             q->blue=q->red;
1226             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1227             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1228             p+=quantum_info->pad;
1229             q++;
1230           }
1231           break;
1232         }
1233       }
1234       break;
1235     }
1236     case RedQuantum:
1237     case CyanQuantum:
1238     {
1239       switch (quantum_info->depth)
1240       {
1241         case 8:
1242         {
1243           unsigned char
1244             pixel;
1245
1246           for (x=0; x < (long) number_pixels; x++)
1247           {
1248             p=PushCharPixel(p,&pixel);
1249             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1250             p+=quantum_info->pad;
1251             q++;
1252           }
1253           break;
1254         }
1255         case 16:
1256         {
1257           unsigned short
1258             pixel;
1259
1260           if (quantum_info->format == FloatingPointQuantumFormat)
1261             {
1262               for (x=0; x < (long) number_pixels; x++)
1263               {
1264                 p=PushShortPixel(endian,p,&pixel);
1265                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1266                   Binary16ToSinglePrecision(pixel));
1267                 p+=quantum_info->pad;
1268                 q++;
1269               }
1270               break;
1271             }
1272           for (x=0; x < (long) number_pixels; x++)
1273           {
1274             p=PushShortPixel(endian,p,&pixel);
1275             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1276             p+=quantum_info->pad;
1277             q++;
1278           }
1279           break;
1280         }
1281         case 32:
1282         {
1283           unsigned long
1284             pixel;
1285
1286           if (quantum_info->format == FloatingPointQuantumFormat)
1287             {
1288               float
1289                 pixel;
1290
1291               for (x=0; x < (long) number_pixels; x++)
1292               {
1293                 p=PushFloatPixel(&quantum_state,p,&pixel);
1294                 q->red=ClampToQuantum(pixel);
1295                 p+=quantum_info->pad;
1296                 q++;
1297               }
1298               break;
1299             }
1300           for (x=0; x < (long) number_pixels; x++)
1301           {
1302             p=PushLongPixel(endian,p,&pixel);
1303             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1304             p+=quantum_info->pad;
1305             q++;
1306           }
1307           break;
1308         }
1309         case 64:
1310         {
1311           if (quantum_info->format == FloatingPointQuantumFormat)
1312             {
1313               double
1314                 pixel;
1315
1316               for (x=0; x < (long) number_pixels; x++)
1317               {
1318                 p=PushDoublePixel(&quantum_state,p,&pixel);
1319                 q->red=ClampToQuantum(pixel);
1320                 p+=quantum_info->pad;
1321                 q++;
1322               }
1323               break;
1324             }
1325         }
1326         default:
1327         {
1328           range=GetQuantumRange(image->depth);
1329           for (x=0; x < (long) number_pixels; x++)
1330           {
1331             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1332             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1333             p+=quantum_info->pad;
1334             q++;
1335           }
1336           break;
1337         }
1338       }
1339       break;
1340     }
1341     case GreenQuantum:
1342     case MagentaQuantum:
1343     {
1344       switch (quantum_info->depth)
1345       {
1346         case 8:
1347         {
1348           unsigned char
1349             pixel;
1350
1351           for (x=0; x < (long) number_pixels; x++)
1352           {
1353             p=PushCharPixel(p,&pixel);
1354             SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1355             p+=quantum_info->pad;
1356             q++;
1357           }
1358           break;
1359         }
1360         case 16:
1361         {
1362           unsigned short
1363             pixel;
1364
1365           if (quantum_info->format == FloatingPointQuantumFormat)
1366             {
1367               for (x=0; x < (long) number_pixels; x++)
1368               {
1369                 p=PushShortPixel(endian,p,&pixel);
1370                 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1371                   Binary16ToSinglePrecision(pixel));
1372                 p+=quantum_info->pad;
1373                 q++;
1374               }
1375               break;
1376             }
1377           for (x=0; x < (long) number_pixels; x++)
1378           {
1379             p=PushShortPixel(endian,p,&pixel);
1380             SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1381             p+=quantum_info->pad;
1382             q++;
1383           }
1384           break;
1385         }
1386         case 32:
1387         {
1388           unsigned long
1389             pixel;
1390
1391           if (quantum_info->format == FloatingPointQuantumFormat)
1392             {
1393               float
1394                 pixel;
1395
1396               for (x=0; x < (long) number_pixels; x++)
1397               {
1398                 p=PushFloatPixel(&quantum_state,p,&pixel);
1399                 q->green=ClampToQuantum(pixel);
1400                 p+=quantum_info->pad;
1401                 q++;
1402               }
1403               break;
1404             }
1405           for (x=0; x < (long) number_pixels; x++)
1406           {
1407             p=PushLongPixel(endian,p,&pixel);
1408             SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1409             p+=quantum_info->pad;
1410             q++;
1411           }
1412           break;
1413         }
1414         case 64:
1415         {
1416           if (quantum_info->format == FloatingPointQuantumFormat)
1417             {
1418               double
1419                 pixel;
1420
1421               for (x=0; x < (long) number_pixels; x++)
1422               {
1423                 p=PushDoublePixel(&quantum_state,p,&pixel);
1424                 q->green=ClampToQuantum(pixel);
1425                 p+=quantum_info->pad;
1426                 q++;
1427               }
1428               break;
1429             }
1430         }
1431         default:
1432         {
1433           range=GetQuantumRange(image->depth);
1434           for (x=0; x < (long) number_pixels; x++)
1435           {
1436             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1437             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1438             p+=quantum_info->pad;
1439             q++;
1440           }
1441           break;
1442         }
1443       }
1444       break;
1445     }
1446     case BlueQuantum:
1447     case YellowQuantum:
1448     {
1449       switch (quantum_info->depth)
1450       {
1451         case 8:
1452         {
1453           unsigned char
1454             pixel;
1455
1456           for (x=0; x < (long) number_pixels; x++)
1457           {
1458             p=PushCharPixel(p,&pixel);
1459             SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1460             p+=quantum_info->pad;
1461             q++;
1462           }
1463           break;
1464         }
1465         case 16:
1466         {
1467           unsigned short
1468             pixel;
1469
1470           if (quantum_info->format == FloatingPointQuantumFormat)
1471             {
1472               for (x=0; x < (long) number_pixels; x++)
1473               {
1474                 p=PushShortPixel(endian,p,&pixel);
1475                 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1476                   Binary16ToSinglePrecision(pixel));
1477                 p+=quantum_info->pad;
1478                 q++;
1479               }
1480               break;
1481             }
1482           for (x=0; x < (long) number_pixels; x++)
1483           {
1484             p=PushShortPixel(endian,p,&pixel);
1485             SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1486             p+=quantum_info->pad;
1487             q++;
1488           }
1489           break;
1490         }
1491         case 32:
1492         {
1493           unsigned long
1494             pixel;
1495
1496           if (quantum_info->format == FloatingPointQuantumFormat)
1497             {
1498               float
1499                 pixel;
1500
1501               for (x=0; x < (long) number_pixels; x++)
1502               {
1503                 p=PushFloatPixel(&quantum_state,p,&pixel);
1504                 q->blue=ClampToQuantum(pixel);
1505                 p+=quantum_info->pad;
1506                 q++;
1507               }
1508               break;
1509             }
1510           for (x=0; x < (long) number_pixels; x++)
1511           {
1512             p=PushLongPixel(endian,p,&pixel);
1513             SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1514             p+=quantum_info->pad;
1515             q++;
1516           }
1517           break;
1518         }
1519         case 64:
1520         {
1521           if (quantum_info->format == FloatingPointQuantumFormat)
1522             {
1523               double
1524                 pixel;
1525
1526               for (x=0; x < (long) number_pixels; x++)
1527               {
1528                 p=PushDoublePixel(&quantum_state,p,&pixel);
1529                 q->blue=ClampToQuantum(pixel);
1530                 p+=quantum_info->pad;
1531                 q++;
1532               }
1533               break;
1534             }
1535         }
1536         default:
1537         {
1538           range=GetQuantumRange(image->depth);
1539           for (x=0; x < (long) number_pixels; x++)
1540           {
1541             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1542             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1543             p+=quantum_info->pad;
1544             q++;
1545           }
1546           break;
1547         }
1548       }
1549       break;
1550     }
1551     case AlphaQuantum:
1552     {
1553       switch (quantum_info->depth)
1554       {
1555         case 8:
1556         {
1557           unsigned char
1558             pixel;
1559
1560           for (x=0; x < (long) number_pixels; x++)
1561           {
1562             p=PushCharPixel(p,&pixel);
1563             q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1564             p+=quantum_info->pad;
1565             q++;
1566           }
1567           break;
1568         }
1569         case 16:
1570         {
1571           unsigned short
1572             pixel;
1573
1574           if (quantum_info->format == FloatingPointQuantumFormat)
1575             {
1576               for (x=0; x < (long) number_pixels; x++)
1577               {
1578                 p=PushShortPixel(endian,p,&pixel);
1579                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1580                   (MagickRealType) QuantumRange*
1581                   Binary16ToSinglePrecision(pixel)));
1582                 p+=quantum_info->pad;
1583                 q++;
1584               }
1585               break;
1586             }
1587           for (x=0; x < (long) number_pixels; x++)
1588           {
1589             p=PushShortPixel(endian,p,&pixel);
1590             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1591             p+=quantum_info->pad;
1592             q++;
1593           }
1594           break;
1595         }
1596         case 32:
1597         {
1598           unsigned long
1599             pixel;
1600
1601           if (quantum_info->format == FloatingPointQuantumFormat)
1602             {
1603               float
1604                 pixel;
1605
1606               for (x=0; x < (long) number_pixels; x++)
1607               {
1608                 p=PushFloatPixel(&quantum_state,p,&pixel);
1609                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1610                 p+=quantum_info->pad;
1611                 q++;
1612               }
1613               break;
1614             }
1615           for (x=0; x < (long) number_pixels; x++)
1616           {
1617             p=PushLongPixel(endian,p,&pixel);
1618             q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1619             p+=quantum_info->pad;
1620             q++;
1621           }
1622           break;
1623         }
1624         case 64:
1625         {
1626           if (quantum_info->format == FloatingPointQuantumFormat)
1627             {
1628               double
1629                 pixel;
1630
1631               for (x=0; x < (long) number_pixels; x++)
1632               {
1633                 p=PushDoublePixel(&quantum_state,p,&pixel);
1634                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1635                 p+=quantum_info->pad;
1636                 q++;
1637               }
1638               break;
1639             }
1640         }
1641         default:
1642         {
1643           range=GetQuantumRange(image->depth);
1644           for (x=0; x < (long) number_pixels; x++)
1645           {
1646             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1647             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1648             p+=quantum_info->pad;
1649             q++;
1650           }
1651           break;
1652         }
1653       }
1654       break;
1655     }
1656     case BlackQuantum:
1657     {
1658       if (image->colorspace != CMYKColorspace)
1659         {
1660           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1661             "ColorSeparatedImageRequired","`%s'",image->filename);
1662           return(extent);
1663         }
1664       switch (quantum_info->depth)
1665       {
1666         case 8:
1667         {
1668           unsigned char
1669             pixel;
1670
1671           for (x=0; x < (long) number_pixels; x++)
1672           {
1673             p=PushCharPixel(p,&pixel);
1674             indexes[x]=ScaleCharToQuantum(pixel);
1675             p+=quantum_info->pad;
1676           }
1677           break;
1678         }
1679         case 16:
1680         {
1681           unsigned short
1682             pixel;
1683
1684           if (quantum_info->format == FloatingPointQuantumFormat)
1685             {
1686               for (x=0; x < (long) number_pixels; x++)
1687               {
1688                 p=PushShortPixel(endian,p,&pixel);
1689                 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
1690                   Binary16ToSinglePrecision(pixel));
1691                 p+=quantum_info->pad;
1692               }
1693               break;
1694             }
1695           for (x=0; x < (long) number_pixels; x++)
1696           {
1697             p=PushShortPixel(endian,p,&pixel);
1698             indexes[x]=ScaleShortToQuantum(pixel);
1699             p+=quantum_info->pad;
1700           }
1701           break;
1702         }
1703         case 32:
1704         {
1705           unsigned long
1706             pixel;
1707
1708           if (quantum_info->format == FloatingPointQuantumFormat)
1709             {
1710               float
1711                 pixel;
1712
1713               for (x=0; x < (long) number_pixels; x++)
1714               {
1715                 p=PushFloatPixel(&quantum_state,p,&pixel);
1716                 indexes[x]=ClampToQuantum(pixel);
1717                 p+=quantum_info->pad;
1718                 q++;
1719               }
1720               break;
1721             }
1722           for (x=0; x < (long) number_pixels; x++)
1723           {
1724             p=PushLongPixel(endian,p,&pixel);
1725             indexes[x]=ScaleLongToQuantum(pixel);
1726             p+=quantum_info->pad;
1727             q++;
1728           }
1729           break;
1730         }
1731         case 64:
1732         {
1733           if (quantum_info->format == FloatingPointQuantumFormat)
1734             {
1735               double
1736                 pixel;
1737
1738               for (x=0; x < (long) number_pixels; x++)
1739               {
1740                 p=PushDoublePixel(&quantum_state,p,&pixel);
1741                 indexes[x]=ClampToQuantum(pixel);
1742                 p+=quantum_info->pad;
1743                 q++;
1744               }
1745               break;
1746             }
1747         }
1748         default:
1749         {
1750           range=GetQuantumRange(image->depth);
1751           for (x=0; x < (long) number_pixels; x++)
1752           {
1753             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1754             indexes[x]=ScaleAnyToQuantum(pixel,range);
1755             p+=quantum_info->pad;
1756             q++;
1757           }
1758           break;
1759         }
1760       }
1761       break;
1762     }
1763     case RGBQuantum:
1764     case CbYCrQuantum:
1765     {
1766       switch (quantum_info->depth)
1767       {
1768         case 8:
1769         {
1770           unsigned char
1771             pixel;
1772
1773           for (x=0; x < (long) number_pixels; x++)
1774           {
1775             p=PushCharPixel(p,&pixel);
1776             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1777             p=PushCharPixel(p,&pixel);
1778             SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1779             p=PushCharPixel(p,&pixel);
1780             SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1781             SetOpacityPixelComponent(q,OpaqueOpacity);
1782             p+=quantum_info->pad;
1783             q++;
1784           }
1785           break;
1786         }
1787         case 10:
1788         {
1789           range=GetQuantumRange(image->depth);
1790           if (quantum_info->pack == MagickFalse)
1791             {
1792               for (x=0; x < (long) number_pixels; x++)
1793               {
1794                 p=PushLongPixel(endian,p,&pixel);
1795                 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1796                 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1797                 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1798                 p+=quantum_info->pad;
1799                 q++;
1800               }
1801               break;
1802             }
1803           if (quantum_info->quantum == 32UL)
1804             {
1805               for (x=0; x < (long) number_pixels; x++)
1806               {
1807                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1808                 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1809                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1810                 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1811                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1812                 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1813                 q++;
1814               }
1815               break;
1816             }
1817           for (x=0; x < (long) number_pixels; x++)
1818           {
1819             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1820             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1821             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1822             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1823             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1824             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1825             q++;
1826           }
1827           break;
1828         }
1829         case 12:
1830         {
1831           range=GetQuantumRange(image->depth);
1832           if (quantum_info->pack == MagickFalse)
1833             {
1834               unsigned short
1835                 pixel;
1836
1837               for (x=0; x < (long) (3*number_pixels-1); x+=2)
1838               {
1839                 p=PushShortPixel(endian,p,&pixel);
1840                 switch (x % 3)
1841                 {
1842                   default:
1843                   case 0:
1844                   {
1845                     q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1846                     break;
1847                   }
1848                   case 1:
1849                   {
1850                     q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1851                     break;
1852                   }
1853                   case 2:
1854                   {
1855                     q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1856                     q++;
1857                     break;
1858                   }
1859                 }
1860                 p=PushShortPixel(endian,p,&pixel);
1861                 switch ((x+1) % 3)
1862                 {
1863                   default:
1864                   case 0:
1865                   {
1866                     q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1867                     break;
1868                   }
1869                   case 1:
1870                   {
1871                     q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1872                     break;
1873                   }
1874                   case 2:
1875                   {
1876                     q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1877                     q++;
1878                     break;
1879                   }
1880                 }
1881                 p+=quantum_info->pad;
1882               }
1883               for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1884               {
1885                 p=PushShortPixel(endian,p,&pixel);
1886                 switch ((x+bit) % 3)
1887                 {
1888                   default:
1889                   case 0:
1890                   {
1891                     q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1892                     break;
1893                   }
1894                   case 1:
1895                   {
1896                     q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1897                     break;
1898                   }
1899                   case 2:
1900                   {
1901                     q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1902                     q++;
1903                     break;
1904                   }
1905                 }
1906                 p+=quantum_info->pad;
1907               }
1908               if (bit != 0)
1909                 p++;
1910               break;
1911             }
1912           if (quantum_info->quantum == 32UL)
1913             {
1914               for (x=0; x < (long) number_pixels; x++)
1915               {
1916                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1917                 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1918                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1919                 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1920                 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1921                 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1922                 q++;
1923               }
1924               break;
1925             }
1926           for (x=0; x < (long) number_pixels; x++)
1927           {
1928             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1929             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1930             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1931             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1932             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1933             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1934             q++;
1935           }
1936           break;
1937         }
1938         case 16:
1939         {
1940           unsigned short
1941             pixel;
1942
1943           if (quantum_info->format == FloatingPointQuantumFormat)
1944             {
1945               for (x=0; x < (long) number_pixels; x++)
1946               {
1947                 p=PushShortPixel(endian,p,&pixel);
1948                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1949                   Binary16ToSinglePrecision(pixel));
1950                 p=PushShortPixel(endian,p,&pixel);
1951                 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1952                   Binary16ToSinglePrecision(pixel));
1953                 p=PushShortPixel(endian,p,&pixel);
1954                 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1955                   Binary16ToSinglePrecision(pixel));
1956                 p+=quantum_info->pad;
1957                 q++;
1958               }
1959               break;
1960             }
1961           for (x=0; x < (long) number_pixels; x++)
1962           {
1963             p=PushShortPixel(endian,p,&pixel);
1964             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1965             p=PushShortPixel(endian,p,&pixel);
1966             SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1967             p=PushShortPixel(endian,p,&pixel);
1968             SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1969             p+=quantum_info->pad;
1970             q++;
1971           }
1972           break;
1973         }
1974         case 32:
1975         {
1976           unsigned long
1977             pixel;
1978
1979           if (quantum_info->format == FloatingPointQuantumFormat)
1980             {
1981               float
1982                 pixel;
1983
1984               for (x=0; x < (long) number_pixels; x++)
1985               {
1986                 p=PushFloatPixel(&quantum_state,p,&pixel);
1987                 q->red=ClampToQuantum(pixel);
1988                 p=PushFloatPixel(&quantum_state,p,&pixel);
1989                 q->green=ClampToQuantum(pixel);
1990                 p=PushFloatPixel(&quantum_state,p,&pixel);
1991                 q->blue=ClampToQuantum(pixel);
1992                 p+=quantum_info->pad;
1993                 q++;
1994               }
1995               break;
1996             }
1997           for (x=0; x < (long) number_pixels; x++)
1998           {
1999             p=PushLongPixel(endian,p,&pixel);
2000             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2001             p=PushLongPixel(endian,p,&pixel);
2002             SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2003             p=PushLongPixel(endian,p,&pixel);
2004             SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2005             p+=quantum_info->pad;
2006             q++;
2007           }
2008           break;
2009         }
2010         case 64:
2011         {
2012           if (quantum_info->format == FloatingPointQuantumFormat)
2013             {
2014               double
2015                 pixel;
2016
2017               for (x=0; x < (long) number_pixels; x++)
2018               {
2019                 p=PushDoublePixel(&quantum_state,p,&pixel);
2020                 q->red=ClampToQuantum(pixel);
2021                 p=PushDoublePixel(&quantum_state,p,&pixel);
2022                 q->green=ClampToQuantum(pixel);
2023                 p=PushDoublePixel(&quantum_state,p,&pixel);
2024                 q->blue=ClampToQuantum(pixel);
2025                 p+=quantum_info->pad;
2026                 q++;
2027               }
2028               break;
2029             }
2030         }
2031         default:
2032         {
2033           range=GetQuantumRange(image->depth);
2034           for (x=0; x < (long) number_pixels; x++)
2035           {
2036             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2037             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2038             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2039             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2040             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2041             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2042             q++;
2043           }
2044           break;
2045         }
2046       }
2047       break;
2048     }
2049     case RGBAQuantum:
2050     case RGBOQuantum:
2051     case CbYCrAQuantum:
2052     {
2053       switch (quantum_info->depth)
2054       {
2055         case 8:
2056         {
2057           unsigned char
2058             pixel;
2059
2060           for (x=0; x < (long) number_pixels; x++)
2061           {
2062             p=PushCharPixel(p,&pixel);
2063             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2064             p=PushCharPixel(p,&pixel);
2065             SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2066             p=PushCharPixel(p,&pixel);
2067             SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2068             p=PushCharPixel(p,&pixel);
2069             q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2070             p+=quantum_info->pad;
2071             q++;
2072           }
2073           break;
2074         }
2075         case 10:
2076         {
2077           pixel=0;
2078           if (quantum_info->pack == MagickFalse)
2079             {
2080               long
2081                 n;
2082
2083               register long
2084                 i;
2085
2086               unsigned long
2087                 quantum;
2088
2089               n=0;
2090               quantum=0;
2091               for (x=0; x < (long) number_pixels; x++)
2092               {
2093                 for (i=0; i < 4; i++)
2094                 {
2095                   switch (n % 3)
2096                   {
2097                     case 0:
2098                     {
2099                       p=PushLongPixel(endian,p,&pixel);
2100                       quantum=(unsigned long) (ScaleShortToQuantum(
2101                         (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2102                       break;
2103                     }
2104                     case 1:
2105                     {
2106                       quantum=(unsigned long) (ScaleShortToQuantum(
2107                         (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2108                       break;
2109                     }
2110                     case 2:
2111                     {
2112                       quantum=(unsigned long) (ScaleShortToQuantum(
2113                         (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2114                       break;
2115                     }
2116                   }
2117                   switch (i)
2118                   {
2119                     case 0: q->red=(Quantum) (quantum); break;
2120                     case 1: q->green=(Quantum) (quantum); break;
2121                     case 2: q->blue=(Quantum) (quantum); break;
2122                     case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2123                   }
2124                   n++;
2125                 }
2126                 p+=quantum_info->pad;
2127                 q++;
2128               }
2129               break;
2130             }
2131           for (x=0; x < (long) number_pixels; x++)
2132           {
2133             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2134             q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2135             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2136             q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2137             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2138             q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2139             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2140             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2141               (unsigned short) (pixel << 6)));
2142             q++;
2143           }
2144           break;
2145         }
2146         case 16:
2147         {
2148           unsigned short
2149             pixel;
2150
2151           if (quantum_info->format == FloatingPointQuantumFormat)
2152             {
2153               for (x=0; x < (long) number_pixels; x++)
2154               {
2155                 p=PushShortPixel(endian,p,&pixel);
2156                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2157                   Binary16ToSinglePrecision(pixel));
2158                 p=PushShortPixel(endian,p,&pixel);
2159                 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2160                   Binary16ToSinglePrecision(pixel));
2161                 p=PushShortPixel(endian,p,&pixel);
2162                 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2163                   Binary16ToSinglePrecision(pixel));
2164                 p=PushShortPixel(endian,p,&pixel);
2165                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2166                   (MagickRealType) QuantumRange*
2167                   Binary16ToSinglePrecision(pixel)));
2168                 p+=quantum_info->pad;
2169                 q++;
2170               }
2171               break;
2172             }
2173           for (x=0; x < (long) number_pixels; x++)
2174           {
2175             p=PushShortPixel(endian,p,&pixel);
2176             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2177             p=PushShortPixel(endian,p,&pixel);
2178             SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2179             p=PushShortPixel(endian,p,&pixel);
2180             SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2181             p=PushShortPixel(endian,p,&pixel);
2182             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2183             p+=quantum_info->pad;
2184             q++;
2185           }
2186           break;
2187         }
2188         case 32:
2189         {
2190           unsigned long
2191             pixel;
2192
2193           if (quantum_info->format == FloatingPointQuantumFormat)
2194             {
2195               float
2196                 pixel;
2197
2198               for (x=0; x < (long) number_pixels; x++)
2199               {
2200                 p=PushFloatPixel(&quantum_state,p,&pixel);
2201                 q->red=ClampToQuantum(pixel);
2202                 p=PushFloatPixel(&quantum_state,p,&pixel);
2203                 q->green=ClampToQuantum(pixel);
2204                 p=PushFloatPixel(&quantum_state,p,&pixel);
2205                 q->blue=ClampToQuantum(pixel);
2206                 p=PushFloatPixel(&quantum_state,p,&pixel);
2207                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2208                 p+=quantum_info->pad;
2209                 q++;
2210               }
2211               break;
2212             }
2213           for (x=0; x < (long) number_pixels; x++)
2214           {
2215             p=PushLongPixel(endian,p,&pixel);
2216             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2217             p=PushLongPixel(endian,p,&pixel);
2218             SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2219             p=PushLongPixel(endian,p,&pixel);
2220             SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2221             p=PushLongPixel(endian,p,&pixel);
2222             q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2223             p+=quantum_info->pad;
2224             q++;
2225           }
2226           break;
2227         }
2228         case 64:
2229         {
2230           if (quantum_info->format == FloatingPointQuantumFormat)
2231             {
2232               double
2233                 pixel;
2234
2235               for (x=0; x < (long) number_pixels; x++)
2236               {
2237                 p=PushDoublePixel(&quantum_state,p,&pixel);
2238                 q->red=ClampToQuantum(pixel);
2239                 p=PushDoublePixel(&quantum_state,p,&pixel);
2240                 q->green=ClampToQuantum(pixel);
2241                 p=PushDoublePixel(&quantum_state,p,&pixel);
2242                 q->blue=ClampToQuantum(pixel);
2243                 p=PushDoublePixel(&quantum_state,p,&pixel);
2244                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2245                 p+=quantum_info->pad;
2246                 q++;
2247               }
2248               break;
2249             }
2250         }
2251         default:
2252         {
2253           range=GetQuantumRange(image->depth);
2254           for (x=0; x < (long) number_pixels; x++)
2255           {
2256             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2257             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2258             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2259             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2260             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2261             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2262             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2263             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2264             q++;
2265           }
2266           break;
2267         }
2268       }
2269       break;
2270     }
2271     case CMYKQuantum:
2272     {
2273       if (image->colorspace != CMYKColorspace)
2274         {
2275           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2276             "ColorSeparatedImageRequired","`%s'",image->filename);
2277           return(extent);
2278         }
2279       switch (quantum_info->depth)
2280       {
2281         case 8:
2282         {
2283           unsigned char
2284             pixel;
2285
2286           for (x=0; x < (long) number_pixels; x++)
2287           {
2288             p=PushCharPixel(p,&pixel);
2289             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2290             p=PushCharPixel(p,&pixel);
2291             SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2292             p=PushCharPixel(p,&pixel);
2293             SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2294             p=PushCharPixel(p,&pixel);
2295             indexes[x]=ScaleCharToQuantum(pixel);
2296             p+=quantum_info->pad;
2297             q++;
2298           }
2299           break;
2300         }
2301         case 16:
2302         {
2303           unsigned short
2304             pixel;
2305
2306           if (quantum_info->format == FloatingPointQuantumFormat)
2307             {
2308               for (x=0; x < (long) number_pixels; x++)
2309               {
2310                 p=PushShortPixel(endian,p,&pixel);
2311                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2312                   Binary16ToSinglePrecision(pixel));
2313                 p=PushShortPixel(endian,p,&pixel);
2314                 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2315                   Binary16ToSinglePrecision(pixel));
2316                 p=PushShortPixel(endian,p,&pixel);
2317                 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2318                   Binary16ToSinglePrecision(pixel));
2319                 p=PushShortPixel(endian,p,&pixel);
2320                 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2321                   Binary16ToSinglePrecision(pixel));
2322                 p+=quantum_info->pad;
2323                 q++;
2324               }
2325               break;
2326             }
2327           for (x=0; x < (long) number_pixels; x++)
2328           {
2329             p=PushShortPixel(endian,p,&pixel);
2330             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2331             p=PushShortPixel(endian,p,&pixel);
2332             SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2333             p=PushShortPixel(endian,p,&pixel);
2334             SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2335             p=PushShortPixel(endian,p,&pixel);
2336             indexes[x]=ScaleShortToQuantum(pixel);
2337             p+=quantum_info->pad;
2338             q++;
2339           }
2340           break;
2341         }
2342         case 32:
2343         {
2344           unsigned long
2345             pixel;
2346
2347           if (quantum_info->format == FloatingPointQuantumFormat)
2348             {
2349               float
2350                 pixel;
2351
2352               for (x=0; x < (long) number_pixels; x++)
2353               {
2354                 p=PushFloatPixel(&quantum_state,p,&pixel);
2355                 q->red=ClampToQuantum(pixel);
2356                 p=PushFloatPixel(&quantum_state,p,&pixel);
2357                 q->green=ClampToQuantum(pixel);
2358                 p=PushFloatPixel(&quantum_state,p,&pixel);
2359                 q->blue=ClampToQuantum(pixel);
2360                 p=PushFloatPixel(&quantum_state,p,&pixel);
2361                 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2362                 p+=quantum_info->pad;
2363                 q++;
2364               }
2365               break;
2366             }
2367           for (x=0; x < (long) number_pixels; x++)
2368           {
2369             p=PushLongPixel(endian,p,&pixel);
2370             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2371             p=PushLongPixel(endian,p,&pixel);
2372             SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2373             p=PushLongPixel(endian,p,&pixel);
2374             SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2375             p=PushLongPixel(endian,p,&pixel);
2376             indexes[x]=ScaleLongToQuantum(pixel);
2377             p+=quantum_info->pad;
2378             q++;
2379           }
2380           break;
2381         }
2382         case 64:
2383         {
2384           if (quantum_info->format == FloatingPointQuantumFormat)
2385             {
2386               double
2387                 pixel;
2388
2389               for (x=0; x < (long) number_pixels; x++)
2390               {
2391                 p=PushDoublePixel(&quantum_state,p,&pixel);
2392                 q->red=ClampToQuantum(pixel);
2393                 p=PushDoublePixel(&quantum_state,p,&pixel);
2394                 q->green=ClampToQuantum(pixel);
2395                 p=PushDoublePixel(&quantum_state,p,&pixel);
2396                 q->blue=ClampToQuantum(pixel);
2397                 p=PushDoublePixel(&quantum_state,p,&pixel);
2398                 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2399                 p+=quantum_info->pad;
2400                 q++;
2401               }
2402               break;
2403             }
2404         }
2405         default:
2406         {
2407           range=GetQuantumRange(image->depth);
2408           for (x=0; x < (long) number_pixels; x++)
2409           {
2410             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2411             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2412             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2413             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2414             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2415             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2416             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2417             indexes[x]=ScaleAnyToQuantum(pixel,range);
2418             q++;
2419           }
2420           break;
2421         }
2422       }
2423       break;
2424     }
2425     case CMYKAQuantum:
2426     case CMYKOQuantum:
2427     {
2428       if (image->colorspace != CMYKColorspace)
2429         {
2430           (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2431             "ColorSeparatedImageRequired","`%s'",image->filename);
2432           return(extent);
2433         }
2434       switch (quantum_info->depth)
2435       {
2436         case 8:
2437         {
2438           unsigned char
2439             pixel;
2440
2441           for (x=0; x < (long) number_pixels; x++)
2442           {
2443             p=PushCharPixel(p,&pixel);
2444             SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2445             p=PushCharPixel(p,&pixel);
2446             SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2447             p=PushCharPixel(p,&pixel);
2448             SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2449             p=PushCharPixel(p,&pixel);
2450             indexes[x]=ScaleCharToQuantum(pixel);
2451             p=PushCharPixel(p,&pixel);
2452             q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2453             p+=quantum_info->pad;
2454             q++;
2455           }
2456           break;
2457         }
2458         case 16:
2459         {
2460           unsigned short
2461             pixel;
2462
2463           if (quantum_info->format == FloatingPointQuantumFormat)
2464             {
2465               for (x=0; x < (long) number_pixels; x++)
2466               {
2467                 p=PushShortPixel(endian,p,&pixel);
2468                 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2469                   Binary16ToSinglePrecision(pixel));
2470                 p=PushShortPixel(endian,p,&pixel);
2471                 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2472                   Binary16ToSinglePrecision(pixel));
2473                 p=PushShortPixel(endian,p,&pixel);
2474                 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2475                   Binary16ToSinglePrecision(pixel));
2476                 p=PushShortPixel(endian,p,&pixel);
2477                 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2478                   Binary16ToSinglePrecision(pixel));
2479                 p=PushShortPixel(endian,p,&pixel);
2480                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2481                   (MagickRealType) QuantumRange*Binary16ToSinglePrecision(pixel)));
2482                 p+=quantum_info->pad;
2483                 q++;
2484               }
2485               break;
2486             }
2487           for (x=0; x < (long) number_pixels; x++)
2488           {
2489             p=PushShortPixel(endian,p,&pixel);
2490             SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2491             p=PushShortPixel(endian,p,&pixel);
2492             SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2493             p=PushShortPixel(endian,p,&pixel);
2494             SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2495             p=PushShortPixel(endian,p,&pixel);
2496             indexes[x]=ScaleShortToQuantum(pixel);
2497             p=PushShortPixel(endian,p,&pixel);
2498             q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2499             p+=quantum_info->pad;
2500             q++;
2501           }
2502           break;
2503         }
2504         case 32:
2505         {
2506           unsigned long
2507             pixel;
2508
2509           if (quantum_info->format == FloatingPointQuantumFormat)
2510             {
2511               float
2512                 pixel;
2513
2514               for (x=0; x < (long) number_pixels; x++)
2515               {
2516                 p=PushFloatPixel(&quantum_state,p,&pixel);
2517                 q->red=ClampToQuantum(pixel);
2518                 p=PushFloatPixel(&quantum_state,p,&pixel);
2519                 q->green=ClampToQuantum(pixel);
2520                 p=PushFloatPixel(&quantum_state,p,&pixel);
2521                 q->blue=ClampToQuantum(pixel);
2522                 p=PushFloatPixel(&quantum_state,p,&pixel);
2523                 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2524                 p=PushFloatPixel(&quantum_state,p,&pixel);
2525                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2526                 p+=quantum_info->pad;
2527                 q++;
2528               }
2529               break;
2530             }
2531           for (x=0; x < (long) number_pixels; x++)
2532           {
2533             p=PushLongPixel(endian,p,&pixel);
2534             SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2535             p=PushLongPixel(endian,p,&pixel);
2536             SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2537             p=PushLongPixel(endian,p,&pixel);
2538             SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2539             p=PushLongPixel(endian,p,&pixel);
2540             indexes[x]=ScaleLongToQuantum(pixel);
2541             p=PushLongPixel(endian,p,&pixel);
2542             q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2543             p+=quantum_info->pad;
2544             q++;
2545           }
2546           break;
2547         }
2548         case 64:
2549         {
2550           if (quantum_info->format == FloatingPointQuantumFormat)
2551             {
2552               double
2553                 pixel;
2554
2555               for (x=0; x < (long) number_pixels; x++)
2556               {
2557                 p=PushDoublePixel(&quantum_state,p,&pixel);
2558                 q->red=ClampToQuantum(pixel);
2559                 p=PushDoublePixel(&quantum_state,p,&pixel);
2560                 q->green=ClampToQuantum(pixel);
2561                 p=PushDoublePixel(&quantum_state,p,&pixel);
2562                 q->blue=ClampToQuantum(pixel);
2563                 p=PushDoublePixel(&quantum_state,p,&pixel);
2564                 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2565                 p=PushDoublePixel(&quantum_state,p,&pixel);
2566                 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2567                 p=PushDoublePixel(&quantum_state,p,&pixel);
2568                 p+=quantum_info->pad;
2569                 q++;
2570               }
2571               break;
2572             }
2573         }
2574         default:
2575         {
2576           range=GetQuantumRange(image->depth);
2577           for (x=0; x < (long) number_pixels; x++)
2578           {
2579             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2580             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2581             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2582             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2583             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2584             SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2585             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2586             indexes[x]=ScaleAnyToQuantum(pixel,range);
2587             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2588             q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2589             q++;
2590           }
2591           break;
2592         }
2593       }
2594       break;
2595     }
2596     case CbYCrYQuantum:
2597     {
2598       switch (quantum_info->depth)
2599       {
2600         case 10:
2601         {
2602           Quantum
2603             cbcr[4];
2604
2605           pixel=0;
2606           if (quantum_info->pack == MagickFalse)
2607             {
2608               long
2609                 n;
2610
2611               register long
2612                 i;
2613
2614               unsigned long
2615                 quantum;
2616
2617               n=0;
2618               quantum=0;
2619               for (x=0; x < (long) number_pixels; x+=2)
2620               {
2621                 for (i=0; i < 4; i++)
2622                 {
2623                   switch (n % 3)
2624                   {
2625                     case 0:
2626                     {
2627                       p=PushLongPixel(endian,p,&pixel);
2628                       quantum=(unsigned long) (ScaleShortToQuantum(
2629                         (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2630                       break;
2631                     }
2632                     case 1:
2633                     {
2634                       quantum=(unsigned long) (ScaleShortToQuantum(
2635                         (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2636                       break;
2637                     }
2638                     case 2:
2639                     {
2640                       quantum=(unsigned long) (ScaleShortToQuantum(
2641                         (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2642                       break;
2643                     }
2644                   }
2645                   cbcr[i]=(Quantum) (quantum);
2646                   n++;
2647                 }
2648                 p+=quantum_info->pad;
2649                 q->red=cbcr[1];
2650                 q->green=cbcr[0];
2651                 q->blue=cbcr[2];
2652                 q++;
2653                 q->red=cbcr[3];
2654                 q->green=cbcr[0];
2655                 q->blue=cbcr[2];
2656                 q++;
2657               }
2658               break;
2659             }
2660         }
2661         default:
2662         {
2663           range=GetQuantumRange(image->depth);
2664           for (x=0; x < (long) number_pixels; x++)
2665           {
2666             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2667             SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2668             p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2669             SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2670             q++;
2671           }
2672           break;
2673         }
2674       }
2675       break;
2676     }
2677     default:
2678       break;
2679   }
2680   if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2681     {
2682       Quantum
2683         quantum;
2684
2685       register PixelPacket
2686         *restrict q;
2687
2688       q=GetAuthenticPixelQueue(image);
2689       if (image_view != (CacheView *) NULL)
2690         q=GetCacheViewAuthenticPixelQueue(image_view);
2691       for (x=0; x < (long) number_pixels; x++)
2692       {
2693         quantum=q->red;
2694         q->red=q->green;
2695         q->green=quantum;
2696         q++;
2697       }
2698     }
2699   if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2700     {
2701       register PixelPacket
2702         *restrict q;
2703
2704       q=GetAuthenticPixelQueue(image);
2705       if (image_view != (CacheView *) NULL)
2706         q=GetCacheViewAuthenticPixelQueue(image_view);
2707       for (x=0; x < (long) number_pixels; x++)
2708       {
2709         q->opacity=(Quantum) GetAlphaPixelComponent(q);
2710         q++;
2711       }
2712     }
2713   if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2714     {
2715       MagickRealType
2716         alpha;
2717
2718       register PixelPacket
2719         *restrict q;
2720
2721       /*
2722         Disassociate alpha.
2723       */
2724       q=GetAuthenticPixelQueue(image);
2725       if (image_view != (CacheView *) NULL)
2726         q=GetCacheViewAuthenticPixelQueue(image_view);
2727       for (x=0; x < (long) number_pixels; x++)
2728       {
2729         alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2730         alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2731         q->red=ClampToQuantum(alpha*q->red);
2732         q->green=ClampToQuantum(alpha*q->green);
2733         q->blue=ClampToQuantum(alpha*q->blue);
2734         q++;
2735       }
2736     }
2737   return(extent);
2738 }