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