2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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 %
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 %
16 % IIIII M M P OOO R R T %
18 % MagickCore Methods to Import Quantum Pixels %
25 % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
31 % http://www.imagemagick.org/script/license.php %
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. %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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"
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % I m p o r t Q u a n t u m P i x e l s %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
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.
90 % The format of the ImportQuantumPixels method is:
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)
96 % A description of each parameter follows:
100 % o image_view: the image cache view.
102 % o quantum_info: the quantum info.
104 % o quantum_type: Declare which pixel components to transfer (red, green,
105 % blue, opacity, RGB, or RGBA).
107 % o pixels: The pixel components are transferred from this buffer.
109 % o exception: return any errors or warnings in this structure.
113 static inline IndexPacket PushColormapIndex(Image *image,
114 const unsigned long index,MagickBooleanType *range_exception)
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
122 static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
131 if (quantum_state->endian != LSBEndian)
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;
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
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;
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
162 static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
171 if (quantum_state->endian != LSBEndian)
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
194 static inline const unsigned char *PushQuantumPixel(
195 QuantumState *quantum_state,const unsigned long depth,
196 const unsigned char *pixels,unsigned long *quantum)
201 register unsigned long
204 *quantum=(QuantumAny) 0;
205 for (i=(long) depth; i > 0L; )
207 if (quantum_state->bits == 0UL)
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
212 quantum_bits=(unsigned long) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218 quantum_state->bits) &~ ((~0UL) << quantum_bits));
223 static inline const unsigned char *PushQuantumLongPixel(
224 QuantumState *quantum_state,const unsigned long depth,
225 const unsigned char *pixels,unsigned long *quantum)
230 register unsigned long
234 for (i=(long) depth; i > 0; )
236 if (quantum_state->bits == 0)
238 pixels=PushLongPixel(quantum_state->endian,pixels,
239 &quantum_state->pixel);
240 quantum_state->bits=32UL;
242 quantum_bits=(unsigned long) i;
243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
245 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246 quantum_state->mask[quantum_bits]) << (depth-i));
248 quantum_state->bits-=quantum_bits;
253 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
254 const QuantumInfo *quantum_info,const QuantumType quantum_type,
255 const unsigned char *pixels,ExceptionInfo *exception)
272 register const unsigned char
290 assert(image != (Image *) NULL);
291 assert(image->signature == MagickSignature);
292 if (image->debug != MagickFalse)
293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
294 assert(quantum_info != (QuantumInfo *) NULL);
295 assert(quantum_info->signature == MagickSignature);
296 if (pixels == (const unsigned char *) NULL)
297 pixels=GetQuantumPixels(quantum_info);
300 number_pixels=GetImageExtent(image);
301 q=GetAuthenticPixelQueue(image);
302 indexes=GetAuthenticIndexQueue(image);
303 if (image_view != (CacheView *) NULL)
305 number_pixels=GetCacheViewExtent(image_view);
306 q=GetCacheViewAuthenticPixelQueue(image_view);
307 indexes=GetCacheViewAuthenticIndexQueue(image_view);
309 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
310 extent=GetQuantumExtent(image,quantum_info,quantum_type);
311 endian=quantum_state.endian;
312 switch (quantum_type)
319 if (image->storage_class != PseudoClass)
321 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
322 "ColormappedImageRequired","`%s'",image->filename);
325 range_exception=MagickFalse;
326 switch (quantum_info->depth)
330 register unsigned char
333 for (x=0; x < ((long) number_pixels-7); x+=8)
335 for (bit=0; bit < 8; bit++)
337 if (quantum_info->min_is_white == MagickFalse)
338 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
343 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
344 *q=image->colormap[(long) indexes[x+bit]];
349 for (bit=0; bit < (long) (number_pixels % 8); bit++)
351 if (quantum_info->min_is_white == MagickFalse)
352 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
357 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
358 *q=image->colormap[(long) indexes[x+bit]];
365 register unsigned char
368 for (x=0; x < ((long) number_pixels-1); x+=2)
370 pixel=(unsigned char) ((*p >> 4) & 0xf);
371 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
372 *q=image->colormap[(long) indexes[x]];
374 pixel=(unsigned char) ((*p) & 0xf);
375 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
376 *q=image->colormap[(long) indexes[x+1]];
380 for (bit=0; bit < (long) (number_pixels % 2); bit++)
382 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
383 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
384 *q=image->colormap[(long) indexes[x+bit]];
394 for (x=0; x < (long) number_pixels; x++)
396 p=PushCharPixel(p,&pixel);
397 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
398 *q=image->colormap[(long) indexes[x]];
399 p+=quantum_info->pad;
409 if (quantum_info->format == FloatingPointQuantumFormat)
411 for (x=0; x < (long) number_pixels; x++)
413 p=PushShortPixel(endian,p,&pixel);
414 indexes[x]=PushColormapIndex(image,ClampToQuantum(
415 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
417 *q=image->colormap[(long) indexes[x]];
418 p+=quantum_info->pad;
423 for (x=0; x < (long) number_pixels; x++)
425 p=PushShortPixel(endian,p,&pixel);
426 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
427 *q=image->colormap[(long) indexes[x]];
428 p+=quantum_info->pad;
438 if (quantum_info->format == FloatingPointQuantumFormat)
443 for (x=0; x < (long) number_pixels; x++)
445 p=PushFloatPixel(&quantum_state,p,&pixel);
446 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
448 *q=image->colormap[(long) indexes[x]];
449 p+=quantum_info->pad;
454 for (x=0; x < (long) number_pixels; x++)
456 p=PushLongPixel(endian,p,&pixel);
457 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
458 *q=image->colormap[(long) indexes[x]];
459 p+=quantum_info->pad;
466 if (quantum_info->format == FloatingPointQuantumFormat)
471 for (x=0; x < (long) number_pixels; x++)
473 p=PushDoublePixel(&quantum_state,p,&pixel);
474 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
476 *q=image->colormap[(long) indexes[x]];
477 p+=quantum_info->pad;
485 for (x=0; x < (long) number_pixels; x++)
487 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
488 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
489 *q=image->colormap[(long) indexes[x]];
490 p+=quantum_info->pad;
496 if (range_exception != MagickFalse)
497 (void) ThrowMagickException(exception,GetMagickModule(),
498 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
501 case IndexAlphaQuantum:
506 if (image->storage_class != PseudoClass)
508 (void) ThrowMagickException(exception,GetMagickModule(),
509 ImageError,"ColormappedImageRequired","`%s'",image->filename);
512 range_exception=MagickFalse;
513 switch (quantum_info->depth)
517 register unsigned char
520 for (x=0; x < ((long) number_pixels-3); x+=4)
522 for (bit=0; bit < 8; bit+=2)
524 if (quantum_info->min_is_white == MagickFalse)
525 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
530 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
531 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
534 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
535 == 0 ? TransparentOpacity : OpaqueOpacity);
539 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
541 if (quantum_info->min_is_white == MagickFalse)
542 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
545 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
547 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
548 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
551 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
552 0 ? TransparentOpacity : OpaqueOpacity);
559 register unsigned char
562 range=GetQuantumRange(image->depth);
563 for (x=0; x < (long) number_pixels; x++)
565 pixel=(unsigned char) ((*p >> 4) & 0xf);
566 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
567 *q=image->colormap[(long) indexes[x]];
568 pixel=(unsigned char) ((*p) & 0xf);
569 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
580 for (x=0; x < (long) number_pixels; x++)
582 p=PushCharPixel(p,&pixel);
583 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
584 *q=image->colormap[(long) indexes[x]];
585 p=PushCharPixel(p,&pixel);
586 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
587 p+=quantum_info->pad;
597 if (quantum_info->format == FloatingPointQuantumFormat)
599 for (x=0; x < (long) number_pixels; x++)
601 p=PushShortPixel(endian,p,&pixel);
602 indexes[x]=PushColormapIndex(image,ClampToQuantum(
603 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
605 *q=image->colormap[(long) indexes[x]];
606 p=PushShortPixel(endian,p,&pixel);
607 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
608 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
609 p+=quantum_info->pad;
614 for (x=0; x < (long) number_pixels; x++)
616 p=PushShortPixel(endian,p,&pixel);
617 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
618 *q=image->colormap[(long) indexes[x]];
619 p=PushShortPixel(endian,p,&pixel);
620 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
621 p+=quantum_info->pad;
631 if (quantum_info->format == FloatingPointQuantumFormat)
636 for (x=0; x < (long) number_pixels; x++)
638 p=PushFloatPixel(&quantum_state,p,&pixel);
639 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
641 *q=image->colormap[(long) indexes[x]];
642 p=PushFloatPixel(&quantum_state,p,&pixel);
643 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
644 p+=quantum_info->pad;
649 for (x=0; x < (long) number_pixels; x++)
651 p=PushLongPixel(endian,p,&pixel);
652 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
653 *q=image->colormap[(long) indexes[x]];
654 p=PushLongPixel(endian,p,&pixel);
655 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
656 p+=quantum_info->pad;
663 if (quantum_info->format == FloatingPointQuantumFormat)
668 for (x=0; x < (long) number_pixels; x++)
670 p=PushDoublePixel(&quantum_state,p,&pixel);
671 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
673 *q=image->colormap[(long) indexes[x]];
674 p=PushDoublePixel(&quantum_state,p,&pixel);
675 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
676 p+=quantum_info->pad;
684 range=GetQuantumRange(image->depth);
685 for (x=0; x < (long) number_pixels; x++)
687 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
688 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
689 *q=image->colormap[(long) indexes[x]];
690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
691 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
692 p+=quantum_info->pad;
698 if (range_exception != MagickFalse)
699 (void) ThrowMagickException(exception,GetMagickModule(),
700 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
705 switch (quantum_info->depth)
714 white=(Quantum) QuantumRange;
715 if (quantum_info->min_is_white != MagickFalse)
717 black=(Quantum) QuantumRange;
720 for (x=0; x < ((long) number_pixels-7); x+=8)
722 for (bit=0; bit < 8; bit++)
724 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
731 for (bit=0; bit < (long) (number_pixels % 8); bit++)
733 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
744 register unsigned char
747 range=GetQuantumRange(image->depth);
748 for (x=0; x < ((long) number_pixels-1); x+=2)
750 pixel=(unsigned char) ((*p >> 4) & 0xf);
751 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
755 pixel=(unsigned char) ((*p) & 0xf);
756 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
762 for (bit=0; bit < (long) (number_pixels % 2); bit++)
764 pixel=(unsigned char) (*p++ >> 4);
765 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
777 if (quantum_info->min_is_white != MagickFalse)
779 for (x=0; x < (long) number_pixels; x++)
781 p=PushCharPixel(p,&pixel);
782 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
785 SetOpacityPixelComponent(q,OpaqueOpacity);
786 p+=quantum_info->pad;
791 for (x=0; x < (long) number_pixels; x++)
793 p=PushCharPixel(p,&pixel);
794 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
797 SetOpacityPixelComponent(q,OpaqueOpacity);
798 p+=quantum_info->pad;
805 range=GetQuantumRange(image->depth);
806 if (quantum_info->pack == MagickFalse)
808 if (image->endian != LSBEndian)
810 for (x=0; x < (long) number_pixels/3; x++)
812 p=PushLongPixel(endian,p,&pixel);
813 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
817 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
821 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
824 p+=quantum_info->pad;
829 for (x=0; x < (long) number_pixels/3; x++)
831 p=PushLongPixel(endian,p,&pixel);
832 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
836 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
840 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
843 p+=quantum_info->pad;
848 for (x=0; x < (long) number_pixels; x++)
850 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
851 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
854 p+=quantum_info->pad;
861 range=GetQuantumRange(image->depth);
862 if (quantum_info->pack == MagickFalse)
867 for (x=0; x < (long) (number_pixels-1); x+=2)
869 p=PushShortPixel(endian,p,&pixel);
870 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
874 p=PushShortPixel(endian,p,&pixel);
875 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
878 p+=quantum_info->pad;
881 for (bit=0; bit < (long) (number_pixels % 2); bit++)
883 p=PushShortPixel(endian,p,&pixel);
884 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
887 p+=quantum_info->pad;
894 for (x=0; x < (long) number_pixels; x++)
896 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
897 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
900 p+=quantum_info->pad;
910 if (quantum_info->min_is_white != MagickFalse)
912 for (x=0; x < (long) number_pixels; x++)
914 p=PushShortPixel(endian,p,&pixel);
915 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
918 p+=quantum_info->pad;
923 if (quantum_info->format == FloatingPointQuantumFormat)
925 for (x=0; x < (long) number_pixels; x++)
927 p=PushShortPixel(endian,p,&pixel);
928 q->red=ClampToQuantum((MagickRealType) QuantumRange*
929 HalfToSinglePrecision(pixel));
932 p+=quantum_info->pad;
937 for (x=0; x < (long) number_pixels; x++)
939 p=PushShortPixel(endian,p,&pixel);
940 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
943 p+=quantum_info->pad;
953 if (quantum_info->format == FloatingPointQuantumFormat)
958 for (x=0; x < (long) number_pixels; x++)
960 p=PushFloatPixel(&quantum_state,p,&pixel);
961 q->red=ClampToQuantum(pixel);
964 p+=quantum_info->pad;
969 for (x=0; x < (long) number_pixels; x++)
971 p=PushLongPixel(endian,p,&pixel);
972 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
975 p+=quantum_info->pad;
982 if (quantum_info->format == FloatingPointQuantumFormat)
987 for (x=0; x < (long) number_pixels; x++)
989 p=PushDoublePixel(&quantum_state,p,&pixel);
990 q->red=ClampToQuantum(pixel);
993 p+=quantum_info->pad;
1001 range=GetQuantumRange(image->depth);
1002 for (x=0; x < (long) number_pixels; x++)
1004 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1005 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1008 p+=quantum_info->pad;
1016 case GrayAlphaQuantum:
1018 switch (quantum_info->depth)
1022 register unsigned char
1025 for (x=0; x < ((long) number_pixels-3); x+=4)
1027 for (bit=0; bit < 8; bit+=2)
1029 pixel=(unsigned char)
1030 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1031 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1034 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1035 == 0 ? TransparentOpacity : OpaqueOpacity);
1040 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
1042 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1043 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1046 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1047 ? TransparentOpacity : OpaqueOpacity);
1056 register unsigned char
1059 range=GetQuantumRange(image->depth);
1060 for (x=0; x < (long) number_pixels; x++)
1062 pixel=(unsigned char) ((*p >> 4) & 0xf);
1063 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1066 pixel=(unsigned char) ((*p) & 0xf);
1067 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1078 for (x=0; x < (long) number_pixels; x++)
1080 p=PushCharPixel(p,&pixel);
1081 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1084 p=PushCharPixel(p,&pixel);
1085 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1086 p+=quantum_info->pad;
1093 range=GetQuantumRange(image->depth);
1094 for (x=0; x < (long) number_pixels; x++)
1096 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1097 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1100 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1101 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1102 p+=quantum_info->pad;
1109 range=GetQuantumRange(image->depth);
1110 for (x=0; x < (long) number_pixels; x++)
1112 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1113 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1116 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1117 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1118 p+=quantum_info->pad;
1128 if (quantum_info->format == FloatingPointQuantumFormat)
1130 for (x=0; x < (long) number_pixels; x++)
1132 p=PushShortPixel(endian,p,&pixel);
1133 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1134 HalfToSinglePrecision(pixel));
1137 p=PushShortPixel(endian,p,&pixel);
1138 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1139 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1140 p+=quantum_info->pad;
1145 for (x=0; x < (long) number_pixels; x++)
1147 p=PushShortPixel(endian,p,&pixel);
1148 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1151 p=PushShortPixel(endian,p,&pixel);
1152 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1153 p+=quantum_info->pad;
1163 if (quantum_info->format == FloatingPointQuantumFormat)
1168 for (x=0; x < (long) number_pixels; x++)
1170 p=PushFloatPixel(&quantum_state,p,&pixel);
1171 q->red=ClampToQuantum(pixel);
1174 p=PushFloatPixel(&quantum_state,p,&pixel);
1175 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1176 p+=quantum_info->pad;
1181 for (x=0; x < (long) number_pixels; x++)
1183 p=PushLongPixel(endian,p,&pixel);
1184 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1187 p=PushLongPixel(endian,p,&pixel);
1188 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1189 p+=quantum_info->pad;
1196 if (quantum_info->format == FloatingPointQuantumFormat)
1201 for (x=0; x < (long) number_pixels; x++)
1203 p=PushDoublePixel(&quantum_state,p,&pixel);
1204 q->red=ClampToQuantum(pixel);
1207 p=PushDoublePixel(&quantum_state,p,&pixel);
1208 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1209 p+=quantum_info->pad;
1217 range=GetQuantumRange(image->depth);
1218 for (x=0; x < (long) number_pixels; x++)
1220 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1221 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1224 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1225 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1226 p+=quantum_info->pad;
1237 switch (quantum_info->depth)
1244 for (x=0; x < (long) number_pixels; x++)
1246 p=PushCharPixel(p,&pixel);
1247 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1248 p+=quantum_info->pad;
1258 if (quantum_info->format == FloatingPointQuantumFormat)
1260 for (x=0; x < (long) number_pixels; x++)
1262 p=PushShortPixel(endian,p,&pixel);
1263 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1264 HalfToSinglePrecision(pixel));
1265 p+=quantum_info->pad;
1270 for (x=0; x < (long) number_pixels; x++)
1272 p=PushShortPixel(endian,p,&pixel);
1273 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1274 p+=quantum_info->pad;
1284 if (quantum_info->format == FloatingPointQuantumFormat)
1289 for (x=0; x < (long) number_pixels; x++)
1291 p=PushFloatPixel(&quantum_state,p,&pixel);
1292 q->red=ClampToQuantum(pixel);
1293 p+=quantum_info->pad;
1298 for (x=0; x < (long) number_pixels; x++)
1300 p=PushLongPixel(endian,p,&pixel);
1301 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1302 p+=quantum_info->pad;
1309 if (quantum_info->format == FloatingPointQuantumFormat)
1314 for (x=0; x < (long) number_pixels; x++)
1316 p=PushDoublePixel(&quantum_state,p,&pixel);
1317 q->red=ClampToQuantum(pixel);
1318 p+=quantum_info->pad;
1326 range=GetQuantumRange(image->depth);
1327 for (x=0; x < (long) number_pixels; x++)
1329 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1330 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1331 p+=quantum_info->pad;
1340 case MagentaQuantum:
1342 switch (quantum_info->depth)
1349 for (x=0; x < (long) number_pixels; x++)
1351 p=PushCharPixel(p,&pixel);
1352 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1353 p+=quantum_info->pad;
1363 if (quantum_info->format == FloatingPointQuantumFormat)
1365 for (x=0; x < (long) number_pixels; x++)
1367 p=PushShortPixel(endian,p,&pixel);
1368 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1369 HalfToSinglePrecision(pixel));
1370 p+=quantum_info->pad;
1375 for (x=0; x < (long) number_pixels; x++)
1377 p=PushShortPixel(endian,p,&pixel);
1378 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1379 p+=quantum_info->pad;
1389 if (quantum_info->format == FloatingPointQuantumFormat)
1394 for (x=0; x < (long) number_pixels; x++)
1396 p=PushFloatPixel(&quantum_state,p,&pixel);
1397 q->green=ClampToQuantum(pixel);
1398 p+=quantum_info->pad;
1403 for (x=0; x < (long) number_pixels; x++)
1405 p=PushLongPixel(endian,p,&pixel);
1406 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1407 p+=quantum_info->pad;
1414 if (quantum_info->format == FloatingPointQuantumFormat)
1419 for (x=0; x < (long) number_pixels; x++)
1421 p=PushDoublePixel(&quantum_state,p,&pixel);
1422 q->green=ClampToQuantum(pixel);
1423 p+=quantum_info->pad;
1431 range=GetQuantumRange(image->depth);
1432 for (x=0; x < (long) number_pixels; x++)
1434 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1435 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1436 p+=quantum_info->pad;
1447 switch (quantum_info->depth)
1454 for (x=0; x < (long) number_pixels; x++)
1456 p=PushCharPixel(p,&pixel);
1457 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1458 p+=quantum_info->pad;
1468 if (quantum_info->format == FloatingPointQuantumFormat)
1470 for (x=0; x < (long) number_pixels; x++)
1472 p=PushShortPixel(endian,p,&pixel);
1473 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1474 HalfToSinglePrecision(pixel));
1475 p+=quantum_info->pad;
1480 for (x=0; x < (long) number_pixels; x++)
1482 p=PushShortPixel(endian,p,&pixel);
1483 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1484 p+=quantum_info->pad;
1494 if (quantum_info->format == FloatingPointQuantumFormat)
1499 for (x=0; x < (long) number_pixels; x++)
1501 p=PushFloatPixel(&quantum_state,p,&pixel);
1502 q->blue=ClampToQuantum(pixel);
1503 p+=quantum_info->pad;
1508 for (x=0; x < (long) number_pixels; x++)
1510 p=PushLongPixel(endian,p,&pixel);
1511 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1512 p+=quantum_info->pad;
1519 if (quantum_info->format == FloatingPointQuantumFormat)
1524 for (x=0; x < (long) number_pixels; x++)
1526 p=PushDoublePixel(&quantum_state,p,&pixel);
1527 q->blue=ClampToQuantum(pixel);
1528 p+=quantum_info->pad;
1536 range=GetQuantumRange(image->depth);
1537 for (x=0; x < (long) number_pixels; x++)
1539 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1540 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1541 p+=quantum_info->pad;
1551 switch (quantum_info->depth)
1558 for (x=0; x < (long) number_pixels; x++)
1560 p=PushCharPixel(p,&pixel);
1561 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1562 p+=quantum_info->pad;
1572 if (quantum_info->format == FloatingPointQuantumFormat)
1574 for (x=0; x < (long) number_pixels; x++)
1576 p=PushShortPixel(endian,p,&pixel);
1577 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1578 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1579 p+=quantum_info->pad;
1584 for (x=0; x < (long) number_pixels; x++)
1586 p=PushShortPixel(endian,p,&pixel);
1587 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1588 p+=quantum_info->pad;
1598 if (quantum_info->format == FloatingPointQuantumFormat)
1603 for (x=0; x < (long) number_pixels; x++)
1605 p=PushFloatPixel(&quantum_state,p,&pixel);
1606 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1607 p+=quantum_info->pad;
1612 for (x=0; x < (long) number_pixels; x++)
1614 p=PushLongPixel(endian,p,&pixel);
1615 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1616 p+=quantum_info->pad;
1623 if (quantum_info->format == FloatingPointQuantumFormat)
1628 for (x=0; x < (long) number_pixels; x++)
1630 p=PushDoublePixel(&quantum_state,p,&pixel);
1631 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1632 p+=quantum_info->pad;
1640 range=GetQuantumRange(image->depth);
1641 for (x=0; x < (long) number_pixels; x++)
1643 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1644 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1645 p+=quantum_info->pad;
1655 if (image->colorspace != CMYKColorspace)
1657 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1658 "ColorSeparatedImageRequired","`%s'",image->filename);
1661 switch (quantum_info->depth)
1668 for (x=0; x < (long) number_pixels; x++)
1670 p=PushCharPixel(p,&pixel);
1671 indexes[x]=ScaleCharToQuantum(pixel);
1672 p+=quantum_info->pad;
1681 if (quantum_info->format == FloatingPointQuantumFormat)
1683 for (x=0; x < (long) number_pixels; x++)
1685 p=PushShortPixel(endian,p,&pixel);
1686 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
1687 HalfToSinglePrecision(pixel));
1688 p+=quantum_info->pad;
1692 for (x=0; x < (long) number_pixels; x++)
1694 p=PushShortPixel(endian,p,&pixel);
1695 indexes[x]=ScaleShortToQuantum(pixel);
1696 p+=quantum_info->pad;
1705 if (quantum_info->format == FloatingPointQuantumFormat)
1710 for (x=0; x < (long) number_pixels; x++)
1712 p=PushFloatPixel(&quantum_state,p,&pixel);
1713 indexes[x]=ClampToQuantum(pixel);
1714 p+=quantum_info->pad;
1719 for (x=0; x < (long) number_pixels; x++)
1721 p=PushLongPixel(endian,p,&pixel);
1722 indexes[x]=ScaleLongToQuantum(pixel);
1723 p+=quantum_info->pad;
1730 if (quantum_info->format == FloatingPointQuantumFormat)
1735 for (x=0; x < (long) number_pixels; x++)
1737 p=PushDoublePixel(&quantum_state,p,&pixel);
1738 indexes[x]=ClampToQuantum(pixel);
1739 p+=quantum_info->pad;
1747 range=GetQuantumRange(image->depth);
1748 for (x=0; x < (long) number_pixels; x++)
1750 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1751 indexes[x]=ScaleAnyToQuantum(pixel,range);
1752 p+=quantum_info->pad;
1763 switch (quantum_info->depth)
1770 for (x=0; x < (long) number_pixels; x++)
1772 p=PushCharPixel(p,&pixel);
1773 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1774 p=PushCharPixel(p,&pixel);
1775 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1776 p=PushCharPixel(p,&pixel);
1777 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1778 SetOpacityPixelComponent(q,OpaqueOpacity);
1779 p+=quantum_info->pad;
1786 range=GetQuantumRange(image->depth);
1787 if (quantum_info->pack == MagickFalse)
1789 for (x=0; x < (long) number_pixels; x++)
1791 p=PushLongPixel(endian,p,&pixel);
1792 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1793 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1794 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1795 p+=quantum_info->pad;
1800 if (quantum_info->quantum == 32UL)
1802 for (x=0; x < (long) number_pixels; x++)
1804 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1805 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1806 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1807 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1808 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1809 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1814 for (x=0; x < (long) number_pixels; x++)
1816 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1817 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1818 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1819 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1820 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1821 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1828 range=GetQuantumRange(image->depth);
1829 if (quantum_info->pack == MagickFalse)
1834 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1836 p=PushShortPixel(endian,p,&pixel);
1842 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1847 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1852 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1857 p=PushShortPixel(endian,p,&pixel);
1863 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1868 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1873 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1878 p+=quantum_info->pad;
1880 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1882 p=PushShortPixel(endian,p,&pixel);
1883 switch ((x+bit) % 3)
1888 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1893 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1898 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1903 p+=quantum_info->pad;
1909 if (quantum_info->quantum == 32UL)
1911 for (x=0; x < (long) number_pixels; x++)
1913 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1914 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1915 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1916 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1917 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1918 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1923 for (x=0; x < (long) number_pixels; x++)
1925 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1926 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1927 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1928 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1929 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1930 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1940 if (quantum_info->format == FloatingPointQuantumFormat)
1942 for (x=0; x < (long) number_pixels; x++)
1944 p=PushShortPixel(endian,p,&pixel);
1945 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1946 HalfToSinglePrecision(pixel));
1947 p=PushShortPixel(endian,p,&pixel);
1948 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1949 HalfToSinglePrecision(pixel));
1950 p=PushShortPixel(endian,p,&pixel);
1951 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1952 HalfToSinglePrecision(pixel));
1953 p+=quantum_info->pad;
1958 for (x=0; x < (long) number_pixels; x++)
1960 p=PushShortPixel(endian,p,&pixel);
1961 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1962 p=PushShortPixel(endian,p,&pixel);
1963 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1964 p=PushShortPixel(endian,p,&pixel);
1965 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1966 p+=quantum_info->pad;
1976 if (quantum_info->format == FloatingPointQuantumFormat)
1981 for (x=0; x < (long) number_pixels; x++)
1983 p=PushFloatPixel(&quantum_state,p,&pixel);
1984 q->red=ClampToQuantum(pixel);
1985 p=PushFloatPixel(&quantum_state,p,&pixel);
1986 q->green=ClampToQuantum(pixel);
1987 p=PushFloatPixel(&quantum_state,p,&pixel);
1988 q->blue=ClampToQuantum(pixel);
1989 p+=quantum_info->pad;
1994 for (x=0; x < (long) number_pixels; x++)
1996 p=PushLongPixel(endian,p,&pixel);
1997 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1998 p=PushLongPixel(endian,p,&pixel);
1999 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2000 p=PushLongPixel(endian,p,&pixel);
2001 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2002 p+=quantum_info->pad;
2009 if (quantum_info->format == FloatingPointQuantumFormat)
2014 for (x=0; x < (long) number_pixels; x++)
2016 p=PushDoublePixel(&quantum_state,p,&pixel);
2017 q->red=ClampToQuantum(pixel);
2018 p=PushDoublePixel(&quantum_state,p,&pixel);
2019 q->green=ClampToQuantum(pixel);
2020 p=PushDoublePixel(&quantum_state,p,&pixel);
2021 q->blue=ClampToQuantum(pixel);
2022 p+=quantum_info->pad;
2030 range=GetQuantumRange(image->depth);
2031 for (x=0; x < (long) number_pixels; x++)
2033 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2034 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2035 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2036 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2037 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2038 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2050 switch (quantum_info->depth)
2057 for (x=0; x < (long) number_pixels; x++)
2059 p=PushCharPixel(p,&pixel);
2060 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2061 p=PushCharPixel(p,&pixel);
2062 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2063 p=PushCharPixel(p,&pixel);
2064 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2065 p=PushCharPixel(p,&pixel);
2066 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2067 p+=quantum_info->pad;
2075 if (quantum_info->pack == MagickFalse)
2088 for (x=0; x < (long) number_pixels; x++)
2090 for (i=0; i < 4; i++)
2096 p=PushLongPixel(endian,p,&pixel);
2097 quantum=(unsigned long) (ScaleShortToQuantum(
2098 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2103 quantum=(unsigned long) (ScaleShortToQuantum(
2104 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2109 quantum=(unsigned long) (ScaleShortToQuantum(
2110 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2116 case 0: q->red=(Quantum) (quantum); break;
2117 case 1: q->green=(Quantum) (quantum); break;
2118 case 2: q->blue=(Quantum) (quantum); break;
2119 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2123 p+=quantum_info->pad;
2128 for (x=0; x < (long) number_pixels; x++)
2130 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2131 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2132 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2133 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2134 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2135 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2136 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2137 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2138 (unsigned short) (pixel << 6)));
2148 if (quantum_info->format == FloatingPointQuantumFormat)
2150 for (x=0; x < (long) number_pixels; x++)
2152 p=PushShortPixel(endian,p,&pixel);
2153 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2154 HalfToSinglePrecision(pixel));
2155 p=PushShortPixel(endian,p,&pixel);
2156 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2157 HalfToSinglePrecision(pixel));
2158 p=PushShortPixel(endian,p,&pixel);
2159 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2160 HalfToSinglePrecision(pixel));
2161 p=PushShortPixel(endian,p,&pixel);
2162 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2163 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2164 p+=quantum_info->pad;
2169 for (x=0; x < (long) number_pixels; x++)
2171 p=PushShortPixel(endian,p,&pixel);
2172 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2173 p=PushShortPixel(endian,p,&pixel);
2174 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2175 p=PushShortPixel(endian,p,&pixel);
2176 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2177 p=PushShortPixel(endian,p,&pixel);
2178 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2179 p+=quantum_info->pad;
2189 if (quantum_info->format == FloatingPointQuantumFormat)
2194 for (x=0; x < (long) number_pixels; x++)
2196 p=PushFloatPixel(&quantum_state,p,&pixel);
2197 q->red=ClampToQuantum(pixel);
2198 p=PushFloatPixel(&quantum_state,p,&pixel);
2199 q->green=ClampToQuantum(pixel);
2200 p=PushFloatPixel(&quantum_state,p,&pixel);
2201 q->blue=ClampToQuantum(pixel);
2202 p=PushFloatPixel(&quantum_state,p,&pixel);
2203 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2204 p+=quantum_info->pad;
2209 for (x=0; x < (long) number_pixels; x++)
2211 p=PushLongPixel(endian,p,&pixel);
2212 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2213 p=PushLongPixel(endian,p,&pixel);
2214 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2215 p=PushLongPixel(endian,p,&pixel);
2216 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2217 p=PushLongPixel(endian,p,&pixel);
2218 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2219 p+=quantum_info->pad;
2226 if (quantum_info->format == FloatingPointQuantumFormat)
2231 for (x=0; x < (long) number_pixels; x++)
2233 p=PushDoublePixel(&quantum_state,p,&pixel);
2234 q->red=ClampToQuantum(pixel);
2235 p=PushDoublePixel(&quantum_state,p,&pixel);
2236 q->green=ClampToQuantum(pixel);
2237 p=PushDoublePixel(&quantum_state,p,&pixel);
2238 q->blue=ClampToQuantum(pixel);
2239 p=PushDoublePixel(&quantum_state,p,&pixel);
2240 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2241 p+=quantum_info->pad;
2249 range=GetQuantumRange(image->depth);
2250 for (x=0; x < (long) number_pixels; x++)
2252 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2253 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2254 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2255 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2256 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2257 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2258 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2259 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2269 if (image->colorspace != CMYKColorspace)
2271 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2272 "ColorSeparatedImageRequired","`%s'",image->filename);
2275 switch (quantum_info->depth)
2282 for (x=0; x < (long) number_pixels; x++)
2284 p=PushCharPixel(p,&pixel);
2285 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2286 p=PushCharPixel(p,&pixel);
2287 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2288 p=PushCharPixel(p,&pixel);
2289 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2290 p=PushCharPixel(p,&pixel);
2291 indexes[x]=ScaleCharToQuantum(pixel);
2292 p+=quantum_info->pad;
2302 if (quantum_info->format == FloatingPointQuantumFormat)
2304 for (x=0; x < (long) number_pixels; x++)
2306 p=PushShortPixel(endian,p,&pixel);
2307 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2308 HalfToSinglePrecision(pixel));
2309 p=PushShortPixel(endian,p,&pixel);
2310 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2311 HalfToSinglePrecision(pixel));
2312 p=PushShortPixel(endian,p,&pixel);
2313 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2314 HalfToSinglePrecision(pixel));
2315 p=PushShortPixel(endian,p,&pixel);
2316 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2317 HalfToSinglePrecision(pixel));
2318 p+=quantum_info->pad;
2323 for (x=0; x < (long) number_pixels; x++)
2325 p=PushShortPixel(endian,p,&pixel);
2326 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2327 p=PushShortPixel(endian,p,&pixel);
2328 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2329 p=PushShortPixel(endian,p,&pixel);
2330 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2331 p=PushShortPixel(endian,p,&pixel);
2332 indexes[x]=ScaleShortToQuantum(pixel);
2333 p+=quantum_info->pad;
2343 if (quantum_info->format == FloatingPointQuantumFormat)
2348 for (x=0; x < (long) number_pixels; x++)
2350 p=PushFloatPixel(&quantum_state,p,&pixel);
2351 q->red=ClampToQuantum(pixel);
2352 p=PushFloatPixel(&quantum_state,p,&pixel);
2353 q->green=ClampToQuantum(pixel);
2354 p=PushFloatPixel(&quantum_state,p,&pixel);
2355 q->blue=ClampToQuantum(pixel);
2356 p=PushFloatPixel(&quantum_state,p,&pixel);
2357 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2358 p+=quantum_info->pad;
2363 for (x=0; x < (long) number_pixels; x++)
2365 p=PushLongPixel(endian,p,&pixel);
2366 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2367 p=PushLongPixel(endian,p,&pixel);
2368 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2369 p=PushLongPixel(endian,p,&pixel);
2370 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2371 p=PushLongPixel(endian,p,&pixel);
2372 indexes[x]=ScaleLongToQuantum(pixel);
2373 p+=quantum_info->pad;
2380 if (quantum_info->format == FloatingPointQuantumFormat)
2385 for (x=0; x < (long) number_pixels; x++)
2387 p=PushDoublePixel(&quantum_state,p,&pixel);
2388 q->red=ClampToQuantum(pixel);
2389 p=PushDoublePixel(&quantum_state,p,&pixel);
2390 q->green=ClampToQuantum(pixel);
2391 p=PushDoublePixel(&quantum_state,p,&pixel);
2392 q->blue=ClampToQuantum(pixel);
2393 p=PushDoublePixel(&quantum_state,p,&pixel);
2394 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2395 p+=quantum_info->pad;
2403 range=GetQuantumRange(image->depth);
2404 for (x=0; x < (long) number_pixels; x++)
2406 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2407 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2408 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2409 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2410 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2411 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2412 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2413 indexes[x]=ScaleAnyToQuantum(pixel,range);
2424 if (image->colorspace != CMYKColorspace)
2426 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2427 "ColorSeparatedImageRequired","`%s'",image->filename);
2430 switch (quantum_info->depth)
2437 for (x=0; x < (long) number_pixels; x++)
2439 p=PushCharPixel(p,&pixel);
2440 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2441 p=PushCharPixel(p,&pixel);
2442 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2443 p=PushCharPixel(p,&pixel);
2444 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2445 p=PushCharPixel(p,&pixel);
2446 indexes[x]=ScaleCharToQuantum(pixel);
2447 p=PushCharPixel(p,&pixel);
2448 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2449 p+=quantum_info->pad;
2459 if (quantum_info->format == FloatingPointQuantumFormat)
2461 for (x=0; x < (long) number_pixels; x++)
2463 p=PushShortPixel(endian,p,&pixel);
2464 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2465 HalfToSinglePrecision(pixel));
2466 p=PushShortPixel(endian,p,&pixel);
2467 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2468 HalfToSinglePrecision(pixel));
2469 p=PushShortPixel(endian,p,&pixel);
2470 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2471 HalfToSinglePrecision(pixel));
2472 p=PushShortPixel(endian,p,&pixel);
2473 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2474 HalfToSinglePrecision(pixel));
2475 p=PushShortPixel(endian,p,&pixel);
2476 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2477 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2478 p+=quantum_info->pad;
2483 for (x=0; x < (long) number_pixels; x++)
2485 p=PushShortPixel(endian,p,&pixel);
2486 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2487 p=PushShortPixel(endian,p,&pixel);
2488 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2489 p=PushShortPixel(endian,p,&pixel);
2490 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2491 p=PushShortPixel(endian,p,&pixel);
2492 indexes[x]=ScaleShortToQuantum(pixel);
2493 p=PushShortPixel(endian,p,&pixel);
2494 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2495 p+=quantum_info->pad;
2505 if (quantum_info->format == FloatingPointQuantumFormat)
2510 for (x=0; x < (long) number_pixels; x++)
2512 p=PushFloatPixel(&quantum_state,p,&pixel);
2513 q->red=ClampToQuantum(pixel);
2514 p=PushFloatPixel(&quantum_state,p,&pixel);
2515 q->green=ClampToQuantum(pixel);
2516 p=PushFloatPixel(&quantum_state,p,&pixel);
2517 q->blue=ClampToQuantum(pixel);
2518 p=PushFloatPixel(&quantum_state,p,&pixel);
2519 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2520 p=PushFloatPixel(&quantum_state,p,&pixel);
2521 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2522 p+=quantum_info->pad;
2527 for (x=0; x < (long) number_pixels; x++)
2529 p=PushLongPixel(endian,p,&pixel);
2530 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2531 p=PushLongPixel(endian,p,&pixel);
2532 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2533 p=PushLongPixel(endian,p,&pixel);
2534 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2535 p=PushLongPixel(endian,p,&pixel);
2536 indexes[x]=ScaleLongToQuantum(pixel);
2537 p=PushLongPixel(endian,p,&pixel);
2538 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2539 p+=quantum_info->pad;
2546 if (quantum_info->format == FloatingPointQuantumFormat)
2551 for (x=0; x < (long) number_pixels; x++)
2553 p=PushDoublePixel(&quantum_state,p,&pixel);
2554 q->red=ClampToQuantum(pixel);
2555 p=PushDoublePixel(&quantum_state,p,&pixel);
2556 q->green=ClampToQuantum(pixel);
2557 p=PushDoublePixel(&quantum_state,p,&pixel);
2558 q->blue=ClampToQuantum(pixel);
2559 p=PushDoublePixel(&quantum_state,p,&pixel);
2560 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2561 p=PushDoublePixel(&quantum_state,p,&pixel);
2562 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2563 p=PushDoublePixel(&quantum_state,p,&pixel);
2564 p+=quantum_info->pad;
2572 range=GetQuantumRange(image->depth);
2573 for (x=0; x < (long) number_pixels; x++)
2575 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2576 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2577 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2578 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2579 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2580 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2581 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2582 indexes[x]=ScaleAnyToQuantum(pixel,range);
2583 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2584 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2594 switch (quantum_info->depth)
2602 if (quantum_info->pack == MagickFalse)
2615 for (x=0; x < (long) number_pixels; x+=2)
2617 for (i=0; i < 4; i++)
2623 p=PushLongPixel(endian,p,&pixel);
2624 quantum=(unsigned long) (ScaleShortToQuantum(
2625 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2630 quantum=(unsigned long) (ScaleShortToQuantum(
2631 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2636 quantum=(unsigned long) (ScaleShortToQuantum(
2637 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2641 cbcr[i]=(Quantum) (quantum);
2644 p+=quantum_info->pad;
2659 range=GetQuantumRange(image->depth);
2660 for (x=0; x < (long) number_pixels; x++)
2662 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2663 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2664 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2665 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2676 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2681 register PixelPacket
2684 q=GetAuthenticPixelQueue(image);
2685 if (image_view != (CacheView *) NULL)
2686 q=GetCacheViewAuthenticPixelQueue(image_view);
2687 for (x=0; x < (long) number_pixels; x++)
2695 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2697 register PixelPacket
2700 q=GetAuthenticPixelQueue(image);
2701 if (image_view != (CacheView *) NULL)
2702 q=GetCacheViewAuthenticPixelQueue(image_view);
2703 for (x=0; x < (long) number_pixels; x++)
2705 q->opacity=(Quantum) GetAlphaPixelComponent(q);
2709 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2714 register PixelPacket
2720 q=GetAuthenticPixelQueue(image);
2721 if (image_view != (CacheView *) NULL)
2722 q=GetCacheViewAuthenticPixelQueue(image_view);
2723 for (x=0; x < (long) number_pixels; x++)
2725 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2726 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2727 q->red=ClampToQuantum(alpha*q->red);
2728 q->green=ClampToQuantum(alpha*q->green);
2729 q->blue=ClampToQuantum(alpha*q->blue);