source: ImageMagick/trunk/magick/quantum-import.c @ 3824

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