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 size_t 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 size_t depth,
196 const unsigned char *pixels,size_t *quantum)
204 *quantum=(QuantumAny) 0;
205 for (i=(ssize_t) depth; i > 0L; )
207 if (quantum_state->bits == 0UL)
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
212 quantum_bits=(size_t) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
215 i-=(ssize_t) quantum_bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218 quantum_state->bits) &~ ((~0UL) << quantum_bits));
223 static inline const unsigned char *PushQuantumLongPixel(
224 QuantumState *quantum_state,const size_t depth,
225 const unsigned char *pixels,size_t *quantum)
234 for (i=(ssize_t) 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=(size_t) i;
243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
245 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246 quantum_state->mask[quantum_bits]) << (depth-i));
247 i-=(ssize_t) quantum_bits;
248 quantum_state->bits-=quantum_bits;
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 if (image_view == (CacheView *) NULL)
302 number_pixels=GetImageExtent(image);
303 q=GetAuthenticPixelQueue(image);
304 indexes=GetAuthenticIndexQueue(image);
308 number_pixels=GetCacheViewExtent(image_view);
309 q=GetCacheViewAuthenticPixelQueue(image_view);
310 indexes=GetCacheViewAuthenticIndexQueue(image_view);
312 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
313 extent=GetQuantumExtent(image,quantum_info,quantum_type);
314 endian=quantum_state.endian;
315 switch (quantum_type)
322 if (image->storage_class != PseudoClass)
324 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
325 "ColormappedImageRequired","`%s'",image->filename);
328 range_exception=MagickFalse;
329 switch (quantum_info->depth)
333 register unsigned char
336 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
338 for (bit=0; bit < 8; bit++)
340 if (quantum_info->min_is_white == MagickFalse)
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
344 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
346 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
347 *q=image->colormap[(ssize_t) indexes[x+bit]];
352 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
354 if (quantum_info->min_is_white == MagickFalse)
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
358 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
360 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
361 *q=image->colormap[(ssize_t) indexes[x+bit]];
368 register unsigned char
371 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
373 pixel=(unsigned char) ((*p >> 4) & 0xf);
374 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
375 *q=image->colormap[(ssize_t) indexes[x]];
377 pixel=(unsigned char) ((*p) & 0xf);
378 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
379 *q=image->colormap[(ssize_t) indexes[x+1]];
383 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
385 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
386 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
387 *q=image->colormap[(ssize_t) indexes[x+bit]];
397 for (x=0; x < (ssize_t) number_pixels; x++)
399 p=PushCharPixel(p,&pixel);
400 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
401 *q=image->colormap[(ssize_t) indexes[x]];
402 p+=quantum_info->pad;
412 if (quantum_info->format == FloatingPointQuantumFormat)
414 for (x=0; x < (ssize_t) number_pixels; x++)
416 p=PushShortPixel(endian,p,&pixel);
417 indexes[x]=PushColormapIndex(image,ClampToQuantum(
418 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
420 *q=image->colormap[(ssize_t) indexes[x]];
421 p+=quantum_info->pad;
426 for (x=0; x < (ssize_t) number_pixels; x++)
428 p=PushShortPixel(endian,p,&pixel);
429 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
430 *q=image->colormap[(ssize_t) indexes[x]];
431 p+=quantum_info->pad;
441 if (quantum_info->format == FloatingPointQuantumFormat)
446 for (x=0; x < (ssize_t) number_pixels; x++)
448 p=PushFloatPixel(&quantum_state,p,&pixel);
449 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
451 *q=image->colormap[(ssize_t) indexes[x]];
452 p+=quantum_info->pad;
457 for (x=0; x < (ssize_t) number_pixels; x++)
459 p=PushLongPixel(endian,p,&pixel);
460 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
461 *q=image->colormap[(ssize_t) indexes[x]];
462 p+=quantum_info->pad;
469 if (quantum_info->format == FloatingPointQuantumFormat)
474 for (x=0; x < (ssize_t) number_pixels; x++)
476 p=PushDoublePixel(&quantum_state,p,&pixel);
477 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
479 *q=image->colormap[(ssize_t) indexes[x]];
480 p+=quantum_info->pad;
488 for (x=0; x < (ssize_t) number_pixels; x++)
490 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
491 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
492 *q=image->colormap[(ssize_t) indexes[x]];
493 p+=quantum_info->pad;
499 if (range_exception != MagickFalse)
500 (void) ThrowMagickException(exception,GetMagickModule(),
501 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
504 case IndexAlphaQuantum:
509 if (image->storage_class != PseudoClass)
511 (void) ThrowMagickException(exception,GetMagickModule(),
512 ImageError,"ColormappedImageRequired","`%s'",image->filename);
515 range_exception=MagickFalse;
516 switch (quantum_info->depth)
520 register unsigned char
523 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
525 for (bit=0; bit < 8; bit+=2)
527 if (quantum_info->min_is_white == MagickFalse)
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
531 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
533 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
534 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
537 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
538 == 0 ? TransparentOpacity : OpaqueOpacity);
542 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
544 if (quantum_info->min_is_white == MagickFalse)
545 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
548 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
550 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
551 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
554 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
555 0 ? TransparentOpacity : OpaqueOpacity);
562 register unsigned char
565 range=GetQuantumRange(image->depth);
566 for (x=0; x < (ssize_t) number_pixels; x++)
568 pixel=(unsigned char) ((*p >> 4) & 0xf);
569 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
570 *q=image->colormap[(ssize_t) indexes[x]];
571 pixel=(unsigned char) ((*p) & 0xf);
572 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
583 for (x=0; x < (ssize_t) number_pixels; x++)
585 p=PushCharPixel(p,&pixel);
586 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
587 *q=image->colormap[(ssize_t) indexes[x]];
588 p=PushCharPixel(p,&pixel);
589 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
590 p+=quantum_info->pad;
600 if (quantum_info->format == FloatingPointQuantumFormat)
602 for (x=0; x < (ssize_t) number_pixels; x++)
604 p=PushShortPixel(endian,p,&pixel);
605 indexes[x]=PushColormapIndex(image,ClampToQuantum(
606 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
608 *q=image->colormap[(ssize_t) indexes[x]];
609 p=PushShortPixel(endian,p,&pixel);
610 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
611 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
612 p+=quantum_info->pad;
617 for (x=0; x < (ssize_t) number_pixels; x++)
619 p=PushShortPixel(endian,p,&pixel);
620 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
621 *q=image->colormap[(ssize_t) indexes[x]];
622 p=PushShortPixel(endian,p,&pixel);
623 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
624 p+=quantum_info->pad;
634 if (quantum_info->format == FloatingPointQuantumFormat)
639 for (x=0; x < (ssize_t) number_pixels; x++)
641 p=PushFloatPixel(&quantum_state,p,&pixel);
642 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
644 *q=image->colormap[(ssize_t) indexes[x]];
645 p=PushFloatPixel(&quantum_state,p,&pixel);
646 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
647 p+=quantum_info->pad;
652 for (x=0; x < (ssize_t) number_pixels; x++)
654 p=PushLongPixel(endian,p,&pixel);
655 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
656 *q=image->colormap[(ssize_t) indexes[x]];
657 p=PushLongPixel(endian,p,&pixel);
658 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
659 p+=quantum_info->pad;
666 if (quantum_info->format == FloatingPointQuantumFormat)
671 for (x=0; x < (ssize_t) number_pixels; x++)
673 p=PushDoublePixel(&quantum_state,p,&pixel);
674 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
676 *q=image->colormap[(ssize_t) indexes[x]];
677 p=PushDoublePixel(&quantum_state,p,&pixel);
678 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
679 p+=quantum_info->pad;
687 range=GetQuantumRange(image->depth);
688 for (x=0; x < (ssize_t) number_pixels; x++)
690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
691 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
692 *q=image->colormap[(ssize_t) indexes[x]];
693 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
694 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
695 p+=quantum_info->pad;
701 if (range_exception != MagickFalse)
702 (void) ThrowMagickException(exception,GetMagickModule(),
703 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
708 switch (quantum_info->depth)
717 white=(Quantum) QuantumRange;
718 if (quantum_info->min_is_white != MagickFalse)
720 black=(Quantum) QuantumRange;
723 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
725 for (bit=0; bit < 8; bit++)
727 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
734 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
736 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
747 register unsigned char
750 range=GetQuantumRange(image->depth);
751 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
753 pixel=(unsigned char) ((*p >> 4) & 0xf);
754 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
758 pixel=(unsigned char) ((*p) & 0xf);
759 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
765 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
767 pixel=(unsigned char) (*p++ >> 4);
768 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
780 if (quantum_info->min_is_white != MagickFalse)
782 for (x=0; x < (ssize_t) number_pixels; x++)
784 p=PushCharPixel(p,&pixel);
785 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
788 SetOpacityPixelComponent(q,OpaqueOpacity);
789 p+=quantum_info->pad;
794 for (x=0; x < (ssize_t) number_pixels; x++)
796 p=PushCharPixel(p,&pixel);
797 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
800 SetOpacityPixelComponent(q,OpaqueOpacity);
801 p+=quantum_info->pad;
808 range=GetQuantumRange(image->depth);
809 if (quantum_info->pack == MagickFalse)
811 if (image->endian != LSBEndian)
813 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
815 p=PushLongPixel(endian,p,&pixel);
816 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
820 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
824 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
827 p+=quantum_info->pad;
830 p=PushLongPixel(endian,p,&pixel);
831 if (x++ < (ssize_t) (number_pixels-1))
833 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
838 if (x++ < (ssize_t) number_pixels)
840 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
847 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
849 p=PushLongPixel(endian,p,&pixel);
850 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
854 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
858 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
861 p+=quantum_info->pad;
864 p=PushLongPixel(endian,p,&pixel);
865 if (x++ < (ssize_t) (number_pixels-1))
867 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
872 if (x++ < (ssize_t) number_pixels)
874 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
881 for (x=0; x < (ssize_t) number_pixels; x++)
883 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
884 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
887 p+=quantum_info->pad;
894 range=GetQuantumRange(image->depth);
895 if (quantum_info->pack == MagickFalse)
900 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
902 p=PushShortPixel(endian,p,&pixel);
903 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
907 p=PushShortPixel(endian,p,&pixel);
908 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
911 p+=quantum_info->pad;
914 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
916 p=PushShortPixel(endian,p,&pixel);
917 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
920 p+=quantum_info->pad;
927 for (x=0; x < (ssize_t) number_pixels; x++)
929 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
930 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
933 p+=quantum_info->pad;
943 if (quantum_info->min_is_white != MagickFalse)
945 for (x=0; x < (ssize_t) number_pixels; x++)
947 p=PushShortPixel(endian,p,&pixel);
948 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
951 p+=quantum_info->pad;
956 if (quantum_info->format == FloatingPointQuantumFormat)
958 for (x=0; x < (ssize_t) number_pixels; x++)
960 p=PushShortPixel(endian,p,&pixel);
961 q->red=ClampToQuantum((MagickRealType) QuantumRange*
962 HalfToSinglePrecision(pixel));
965 p+=quantum_info->pad;
970 for (x=0; x < (ssize_t) number_pixels; x++)
972 p=PushShortPixel(endian,p,&pixel);
973 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
976 p+=quantum_info->pad;
986 if (quantum_info->format == FloatingPointQuantumFormat)
991 for (x=0; x < (ssize_t) number_pixels; x++)
993 p=PushFloatPixel(&quantum_state,p,&pixel);
994 q->red=ClampToQuantum(pixel);
997 p+=quantum_info->pad;
1002 for (x=0; x < (ssize_t) number_pixels; x++)
1004 p=PushLongPixel(endian,p,&pixel);
1005 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1008 p+=quantum_info->pad;
1015 if (quantum_info->format == FloatingPointQuantumFormat)
1020 for (x=0; x < (ssize_t) number_pixels; x++)
1022 p=PushDoublePixel(&quantum_state,p,&pixel);
1023 q->red=ClampToQuantum(pixel);
1026 p+=quantum_info->pad;
1034 range=GetQuantumRange(image->depth);
1035 for (x=0; x < (ssize_t) number_pixels; x++)
1037 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1038 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1041 p+=quantum_info->pad;
1049 case GrayAlphaQuantum:
1051 switch (quantum_info->depth)
1055 register unsigned char
1058 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
1060 for (bit=0; bit < 8; bit+=2)
1062 pixel=(unsigned char)
1063 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1064 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1067 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1068 == 0 ? TransparentOpacity : OpaqueOpacity);
1073 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
1075 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1076 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1079 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1080 ? TransparentOpacity : OpaqueOpacity);
1089 register unsigned char
1092 range=GetQuantumRange(image->depth);
1093 for (x=0; x < (ssize_t) number_pixels; x++)
1095 pixel=(unsigned char) ((*p >> 4) & 0xf);
1096 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1099 pixel=(unsigned char) ((*p) & 0xf);
1100 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1111 for (x=0; x < (ssize_t) number_pixels; x++)
1113 p=PushCharPixel(p,&pixel);
1114 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1117 p=PushCharPixel(p,&pixel);
1118 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1119 p+=quantum_info->pad;
1126 range=GetQuantumRange(image->depth);
1127 for (x=0; x < (ssize_t) number_pixels; x++)
1129 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1130 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1133 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1134 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1135 p+=quantum_info->pad;
1142 range=GetQuantumRange(image->depth);
1143 for (x=0; x < (ssize_t) number_pixels; x++)
1145 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1146 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1149 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1150 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1151 p+=quantum_info->pad;
1161 if (quantum_info->format == FloatingPointQuantumFormat)
1163 for (x=0; x < (ssize_t) number_pixels; x++)
1165 p=PushShortPixel(endian,p,&pixel);
1166 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1167 HalfToSinglePrecision(pixel));
1170 p=PushShortPixel(endian,p,&pixel);
1171 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1172 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1173 p+=quantum_info->pad;
1178 for (x=0; x < (ssize_t) number_pixels; x++)
1180 p=PushShortPixel(endian,p,&pixel);
1181 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1184 p=PushShortPixel(endian,p,&pixel);
1185 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1186 p+=quantum_info->pad;
1196 if (quantum_info->format == FloatingPointQuantumFormat)
1201 for (x=0; x < (ssize_t) number_pixels; x++)
1203 p=PushFloatPixel(&quantum_state,p,&pixel);
1204 q->red=ClampToQuantum(pixel);
1207 p=PushFloatPixel(&quantum_state,p,&pixel);
1208 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1209 p+=quantum_info->pad;
1214 for (x=0; x < (ssize_t) number_pixels; x++)
1216 p=PushLongPixel(endian,p,&pixel);
1217 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1220 p=PushLongPixel(endian,p,&pixel);
1221 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1222 p+=quantum_info->pad;
1229 if (quantum_info->format == FloatingPointQuantumFormat)
1234 for (x=0; x < (ssize_t) number_pixels; x++)
1236 p=PushDoublePixel(&quantum_state,p,&pixel);
1237 q->red=ClampToQuantum(pixel);
1240 p=PushDoublePixel(&quantum_state,p,&pixel);
1241 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1242 p+=quantum_info->pad;
1250 range=GetQuantumRange(image->depth);
1251 for (x=0; x < (ssize_t) number_pixels; x++)
1253 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1254 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1257 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1258 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1259 p+=quantum_info->pad;
1270 switch (quantum_info->depth)
1277 for (x=0; x < (ssize_t) number_pixels; x++)
1279 p=PushCharPixel(p,&pixel);
1280 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1281 p+=quantum_info->pad;
1291 if (quantum_info->format == FloatingPointQuantumFormat)
1293 for (x=0; x < (ssize_t) number_pixels; x++)
1295 p=PushShortPixel(endian,p,&pixel);
1296 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1297 HalfToSinglePrecision(pixel));
1298 p+=quantum_info->pad;
1303 for (x=0; x < (ssize_t) number_pixels; x++)
1305 p=PushShortPixel(endian,p,&pixel);
1306 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1307 p+=quantum_info->pad;
1317 if (quantum_info->format == FloatingPointQuantumFormat)
1322 for (x=0; x < (ssize_t) number_pixels; x++)
1324 p=PushFloatPixel(&quantum_state,p,&pixel);
1325 q->red=ClampToQuantum(pixel);
1326 p+=quantum_info->pad;
1331 for (x=0; x < (ssize_t) number_pixels; x++)
1333 p=PushLongPixel(endian,p,&pixel);
1334 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1335 p+=quantum_info->pad;
1342 if (quantum_info->format == FloatingPointQuantumFormat)
1347 for (x=0; x < (ssize_t) number_pixels; x++)
1349 p=PushDoublePixel(&quantum_state,p,&pixel);
1350 q->red=ClampToQuantum(pixel);
1351 p+=quantum_info->pad;
1359 range=GetQuantumRange(image->depth);
1360 for (x=0; x < (ssize_t) number_pixels; x++)
1362 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1363 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1364 p+=quantum_info->pad;
1373 case MagentaQuantum:
1375 switch (quantum_info->depth)
1382 for (x=0; x < (ssize_t) number_pixels; x++)
1384 p=PushCharPixel(p,&pixel);
1385 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1386 p+=quantum_info->pad;
1396 if (quantum_info->format == FloatingPointQuantumFormat)
1398 for (x=0; x < (ssize_t) number_pixels; x++)
1400 p=PushShortPixel(endian,p,&pixel);
1401 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1402 HalfToSinglePrecision(pixel));
1403 p+=quantum_info->pad;
1408 for (x=0; x < (ssize_t) number_pixels; x++)
1410 p=PushShortPixel(endian,p,&pixel);
1411 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1412 p+=quantum_info->pad;
1422 if (quantum_info->format == FloatingPointQuantumFormat)
1427 for (x=0; x < (ssize_t) number_pixels; x++)
1429 p=PushFloatPixel(&quantum_state,p,&pixel);
1430 q->green=ClampToQuantum(pixel);
1431 p+=quantum_info->pad;
1436 for (x=0; x < (ssize_t) number_pixels; x++)
1438 p=PushLongPixel(endian,p,&pixel);
1439 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1440 p+=quantum_info->pad;
1447 if (quantum_info->format == FloatingPointQuantumFormat)
1452 for (x=0; x < (ssize_t) number_pixels; x++)
1454 p=PushDoublePixel(&quantum_state,p,&pixel);
1455 q->green=ClampToQuantum(pixel);
1456 p+=quantum_info->pad;
1464 range=GetQuantumRange(image->depth);
1465 for (x=0; x < (ssize_t) number_pixels; x++)
1467 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1468 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1469 p+=quantum_info->pad;
1480 switch (quantum_info->depth)
1487 for (x=0; x < (ssize_t) number_pixels; x++)
1489 p=PushCharPixel(p,&pixel);
1490 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1491 p+=quantum_info->pad;
1501 if (quantum_info->format == FloatingPointQuantumFormat)
1503 for (x=0; x < (ssize_t) number_pixels; x++)
1505 p=PushShortPixel(endian,p,&pixel);
1506 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1507 HalfToSinglePrecision(pixel));
1508 p+=quantum_info->pad;
1513 for (x=0; x < (ssize_t) number_pixels; x++)
1515 p=PushShortPixel(endian,p,&pixel);
1516 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1517 p+=quantum_info->pad;
1527 if (quantum_info->format == FloatingPointQuantumFormat)
1532 for (x=0; x < (ssize_t) number_pixels; x++)
1534 p=PushFloatPixel(&quantum_state,p,&pixel);
1535 q->blue=ClampToQuantum(pixel);
1536 p+=quantum_info->pad;
1541 for (x=0; x < (ssize_t) number_pixels; x++)
1543 p=PushLongPixel(endian,p,&pixel);
1544 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1545 p+=quantum_info->pad;
1552 if (quantum_info->format == FloatingPointQuantumFormat)
1557 for (x=0; x < (ssize_t) number_pixels; x++)
1559 p=PushDoublePixel(&quantum_state,p,&pixel);
1560 q->blue=ClampToQuantum(pixel);
1561 p+=quantum_info->pad;
1569 range=GetQuantumRange(image->depth);
1570 for (x=0; x < (ssize_t) number_pixels; x++)
1572 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1573 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1574 p+=quantum_info->pad;
1584 switch (quantum_info->depth)
1591 for (x=0; x < (ssize_t) number_pixels; x++)
1593 p=PushCharPixel(p,&pixel);
1594 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1595 p+=quantum_info->pad;
1605 if (quantum_info->format == FloatingPointQuantumFormat)
1607 for (x=0; x < (ssize_t) number_pixels; x++)
1609 p=PushShortPixel(endian,p,&pixel);
1610 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1611 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1612 p+=quantum_info->pad;
1617 for (x=0; x < (ssize_t) number_pixels; x++)
1619 p=PushShortPixel(endian,p,&pixel);
1620 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1621 p+=quantum_info->pad;
1631 if (quantum_info->format == FloatingPointQuantumFormat)
1636 for (x=0; x < (ssize_t) number_pixels; x++)
1638 p=PushFloatPixel(&quantum_state,p,&pixel);
1639 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1640 p+=quantum_info->pad;
1645 for (x=0; x < (ssize_t) number_pixels; x++)
1647 p=PushLongPixel(endian,p,&pixel);
1648 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1649 p+=quantum_info->pad;
1656 if (quantum_info->format == FloatingPointQuantumFormat)
1661 for (x=0; x < (ssize_t) number_pixels; x++)
1663 p=PushDoublePixel(&quantum_state,p,&pixel);
1664 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1665 p+=quantum_info->pad;
1673 range=GetQuantumRange(image->depth);
1674 for (x=0; x < (ssize_t) number_pixels; x++)
1676 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1677 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1678 p+=quantum_info->pad;
1688 if (image->colorspace != CMYKColorspace)
1690 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1691 "ColorSeparatedImageRequired","`%s'",image->filename);
1694 switch (quantum_info->depth)
1701 for (x=0; x < (ssize_t) number_pixels; x++)
1703 p=PushCharPixel(p,&pixel);
1704 indexes[x]=ScaleCharToQuantum(pixel);
1705 p+=quantum_info->pad;
1714 if (quantum_info->format == FloatingPointQuantumFormat)
1716 for (x=0; x < (ssize_t) number_pixels; x++)
1718 p=PushShortPixel(endian,p,&pixel);
1719 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
1720 HalfToSinglePrecision(pixel));
1721 p+=quantum_info->pad;
1725 for (x=0; x < (ssize_t) number_pixels; x++)
1727 p=PushShortPixel(endian,p,&pixel);
1728 indexes[x]=ScaleShortToQuantum(pixel);
1729 p+=quantum_info->pad;
1738 if (quantum_info->format == FloatingPointQuantumFormat)
1743 for (x=0; x < (ssize_t) number_pixels; x++)
1745 p=PushFloatPixel(&quantum_state,p,&pixel);
1746 indexes[x]=ClampToQuantum(pixel);
1747 p+=quantum_info->pad;
1752 for (x=0; x < (ssize_t) number_pixels; x++)
1754 p=PushLongPixel(endian,p,&pixel);
1755 indexes[x]=ScaleLongToQuantum(pixel);
1756 p+=quantum_info->pad;
1763 if (quantum_info->format == FloatingPointQuantumFormat)
1768 for (x=0; x < (ssize_t) number_pixels; x++)
1770 p=PushDoublePixel(&quantum_state,p,&pixel);
1771 indexes[x]=ClampToQuantum(pixel);
1772 p+=quantum_info->pad;
1780 range=GetQuantumRange(image->depth);
1781 for (x=0; x < (ssize_t) number_pixels; x++)
1783 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1784 indexes[x]=ScaleAnyToQuantum(pixel,range);
1785 p+=quantum_info->pad;
1796 switch (quantum_info->depth)
1803 for (x=0; x < (ssize_t) number_pixels; x++)
1805 p=PushCharPixel(p,&pixel);
1806 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1807 p=PushCharPixel(p,&pixel);
1808 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1809 p=PushCharPixel(p,&pixel);
1810 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1811 SetOpacityPixelComponent(q,OpaqueOpacity);
1812 p+=quantum_info->pad;
1819 range=GetQuantumRange(image->depth);
1820 if (quantum_info->pack == MagickFalse)
1822 for (x=0; x < (ssize_t) number_pixels; x++)
1824 p=PushLongPixel(endian,p,&pixel);
1825 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1826 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1827 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1828 p+=quantum_info->pad;
1833 if (quantum_info->quantum == 32UL)
1835 for (x=0; x < (ssize_t) number_pixels; x++)
1837 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1838 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1839 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1840 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1841 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1842 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1847 for (x=0; x < (ssize_t) number_pixels; x++)
1849 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1850 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1851 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1852 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1853 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1854 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1861 range=GetQuantumRange(image->depth);
1862 if (quantum_info->pack == MagickFalse)
1867 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
1869 p=PushShortPixel(endian,p,&pixel);
1875 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1880 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1885 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1890 p=PushShortPixel(endian,p,&pixel);
1896 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1901 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1906 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1911 p+=quantum_info->pad;
1913 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
1915 p=PushShortPixel(endian,p,&pixel);
1916 switch ((x+bit) % 3)
1921 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1926 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1931 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1936 p+=quantum_info->pad;
1942 if (quantum_info->quantum == 32UL)
1944 for (x=0; x < (ssize_t) number_pixels; x++)
1946 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1947 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1948 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1949 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1950 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1951 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1956 for (x=0; x < (ssize_t) number_pixels; x++)
1958 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1959 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1960 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1961 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1962 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1963 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1973 if (quantum_info->format == FloatingPointQuantumFormat)
1975 for (x=0; x < (ssize_t) number_pixels; x++)
1977 p=PushShortPixel(endian,p,&pixel);
1978 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1979 HalfToSinglePrecision(pixel));
1980 p=PushShortPixel(endian,p,&pixel);
1981 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1982 HalfToSinglePrecision(pixel));
1983 p=PushShortPixel(endian,p,&pixel);
1984 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1985 HalfToSinglePrecision(pixel));
1986 p+=quantum_info->pad;
1991 for (x=0; x < (ssize_t) number_pixels; x++)
1993 p=PushShortPixel(endian,p,&pixel);
1994 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1995 p=PushShortPixel(endian,p,&pixel);
1996 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1997 p=PushShortPixel(endian,p,&pixel);
1998 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1999 p+=quantum_info->pad;
2009 if (quantum_info->format == FloatingPointQuantumFormat)
2014 for (x=0; x < (ssize_t) number_pixels; x++)
2016 p=PushFloatPixel(&quantum_state,p,&pixel);
2017 q->red=ClampToQuantum(pixel);
2018 p=PushFloatPixel(&quantum_state,p,&pixel);
2019 q->green=ClampToQuantum(pixel);
2020 p=PushFloatPixel(&quantum_state,p,&pixel);
2021 q->blue=ClampToQuantum(pixel);
2022 p+=quantum_info->pad;
2027 for (x=0; x < (ssize_t) number_pixels; x++)
2029 p=PushLongPixel(endian,p,&pixel);
2030 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2031 p=PushLongPixel(endian,p,&pixel);
2032 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2033 p=PushLongPixel(endian,p,&pixel);
2034 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2035 p+=quantum_info->pad;
2042 if (quantum_info->format == FloatingPointQuantumFormat)
2047 for (x=0; x < (ssize_t) number_pixels; x++)
2049 p=PushDoublePixel(&quantum_state,p,&pixel);
2050 q->red=ClampToQuantum(pixel);
2051 p=PushDoublePixel(&quantum_state,p,&pixel);
2052 q->green=ClampToQuantum(pixel);
2053 p=PushDoublePixel(&quantum_state,p,&pixel);
2054 q->blue=ClampToQuantum(pixel);
2055 p+=quantum_info->pad;
2063 range=GetQuantumRange(image->depth);
2064 for (x=0; x < (ssize_t) number_pixels; x++)
2066 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2067 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2068 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2069 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2070 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2071 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2083 switch (quantum_info->depth)
2090 for (x=0; x < (ssize_t) number_pixels; x++)
2092 p=PushCharPixel(p,&pixel);
2093 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2094 p=PushCharPixel(p,&pixel);
2095 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2096 p=PushCharPixel(p,&pixel);
2097 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2098 p=PushCharPixel(p,&pixel);
2099 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2100 p+=quantum_info->pad;
2108 if (quantum_info->pack == MagickFalse)
2121 for (x=0; x < (ssize_t) number_pixels; x++)
2123 for (i=0; i < 4; i++)
2129 p=PushLongPixel(endian,p,&pixel);
2130 quantum=(size_t) (ScaleShortToQuantum(
2131 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2136 quantum=(size_t) (ScaleShortToQuantum(
2137 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2142 quantum=(size_t) (ScaleShortToQuantum(
2143 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2149 case 0: q->red=(Quantum) (quantum); break;
2150 case 1: q->green=(Quantum) (quantum); break;
2151 case 2: q->blue=(Quantum) (quantum); break;
2152 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2156 p+=quantum_info->pad;
2161 for (x=0; x < (ssize_t) number_pixels; x++)
2163 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2164 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2165 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2166 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2167 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2168 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2169 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2170 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2171 (unsigned short) (pixel << 6)));
2181 if (quantum_info->format == FloatingPointQuantumFormat)
2183 for (x=0; x < (ssize_t) number_pixels; x++)
2185 p=PushShortPixel(endian,p,&pixel);
2186 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2187 HalfToSinglePrecision(pixel));
2188 p=PushShortPixel(endian,p,&pixel);
2189 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2190 HalfToSinglePrecision(pixel));
2191 p=PushShortPixel(endian,p,&pixel);
2192 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2193 HalfToSinglePrecision(pixel));
2194 p=PushShortPixel(endian,p,&pixel);
2195 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2196 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2197 p+=quantum_info->pad;
2202 for (x=0; x < (ssize_t) number_pixels; x++)
2204 p=PushShortPixel(endian,p,&pixel);
2205 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2206 p=PushShortPixel(endian,p,&pixel);
2207 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2208 p=PushShortPixel(endian,p,&pixel);
2209 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2210 p=PushShortPixel(endian,p,&pixel);
2211 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2212 p+=quantum_info->pad;
2222 if (quantum_info->format == FloatingPointQuantumFormat)
2227 for (x=0; x < (ssize_t) number_pixels; x++)
2229 p=PushFloatPixel(&quantum_state,p,&pixel);
2230 q->red=ClampToQuantum(pixel);
2231 p=PushFloatPixel(&quantum_state,p,&pixel);
2232 q->green=ClampToQuantum(pixel);
2233 p=PushFloatPixel(&quantum_state,p,&pixel);
2234 q->blue=ClampToQuantum(pixel);
2235 p=PushFloatPixel(&quantum_state,p,&pixel);
2236 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2237 p+=quantum_info->pad;
2242 for (x=0; x < (ssize_t) number_pixels; x++)
2244 p=PushLongPixel(endian,p,&pixel);
2245 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2246 p=PushLongPixel(endian,p,&pixel);
2247 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2248 p=PushLongPixel(endian,p,&pixel);
2249 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2250 p=PushLongPixel(endian,p,&pixel);
2251 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2252 p+=quantum_info->pad;
2259 if (quantum_info->format == FloatingPointQuantumFormat)
2264 for (x=0; x < (ssize_t) number_pixels; x++)
2266 p=PushDoublePixel(&quantum_state,p,&pixel);
2267 q->red=ClampToQuantum(pixel);
2268 p=PushDoublePixel(&quantum_state,p,&pixel);
2269 q->green=ClampToQuantum(pixel);
2270 p=PushDoublePixel(&quantum_state,p,&pixel);
2271 q->blue=ClampToQuantum(pixel);
2272 p=PushDoublePixel(&quantum_state,p,&pixel);
2273 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2274 p+=quantum_info->pad;
2282 range=GetQuantumRange(image->depth);
2283 for (x=0; x < (ssize_t) number_pixels; x++)
2285 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2286 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2287 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2288 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2289 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2290 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2291 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2292 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2302 if (image->colorspace != CMYKColorspace)
2304 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2305 "ColorSeparatedImageRequired","`%s'",image->filename);
2308 switch (quantum_info->depth)
2315 for (x=0; x < (ssize_t) number_pixels; x++)
2317 p=PushCharPixel(p,&pixel);
2318 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2319 p=PushCharPixel(p,&pixel);
2320 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2321 p=PushCharPixel(p,&pixel);
2322 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2323 p=PushCharPixel(p,&pixel);
2324 indexes[x]=ScaleCharToQuantum(pixel);
2325 p+=quantum_info->pad;
2335 if (quantum_info->format == FloatingPointQuantumFormat)
2337 for (x=0; x < (ssize_t) number_pixels; x++)
2339 p=PushShortPixel(endian,p,&pixel);
2340 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2341 HalfToSinglePrecision(pixel));
2342 p=PushShortPixel(endian,p,&pixel);
2343 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2344 HalfToSinglePrecision(pixel));
2345 p=PushShortPixel(endian,p,&pixel);
2346 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2347 HalfToSinglePrecision(pixel));
2348 p=PushShortPixel(endian,p,&pixel);
2349 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2350 HalfToSinglePrecision(pixel));
2351 p+=quantum_info->pad;
2356 for (x=0; x < (ssize_t) number_pixels; x++)
2358 p=PushShortPixel(endian,p,&pixel);
2359 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2360 p=PushShortPixel(endian,p,&pixel);
2361 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2362 p=PushShortPixel(endian,p,&pixel);
2363 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2364 p=PushShortPixel(endian,p,&pixel);
2365 indexes[x]=ScaleShortToQuantum(pixel);
2366 p+=quantum_info->pad;
2376 if (quantum_info->format == FloatingPointQuantumFormat)
2381 for (x=0; x < (ssize_t) number_pixels; x++)
2383 p=PushFloatPixel(&quantum_state,p,&pixel);
2384 q->red=ClampToQuantum(pixel);
2385 p=PushFloatPixel(&quantum_state,p,&pixel);
2386 q->green=ClampToQuantum(pixel);
2387 p=PushFloatPixel(&quantum_state,p,&pixel);
2388 q->blue=ClampToQuantum(pixel);
2389 p=PushFloatPixel(&quantum_state,p,&pixel);
2390 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2391 p+=quantum_info->pad;
2396 for (x=0; x < (ssize_t) number_pixels; x++)
2398 p=PushLongPixel(endian,p,&pixel);
2399 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2400 p=PushLongPixel(endian,p,&pixel);
2401 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2402 p=PushLongPixel(endian,p,&pixel);
2403 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2404 p=PushLongPixel(endian,p,&pixel);
2405 indexes[x]=ScaleLongToQuantum(pixel);
2406 p+=quantum_info->pad;
2413 if (quantum_info->format == FloatingPointQuantumFormat)
2418 for (x=0; x < (ssize_t) number_pixels; x++)
2420 p=PushDoublePixel(&quantum_state,p,&pixel);
2421 q->red=ClampToQuantum(pixel);
2422 p=PushDoublePixel(&quantum_state,p,&pixel);
2423 q->green=ClampToQuantum(pixel);
2424 p=PushDoublePixel(&quantum_state,p,&pixel);
2425 q->blue=ClampToQuantum(pixel);
2426 p=PushDoublePixel(&quantum_state,p,&pixel);
2427 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2428 p+=quantum_info->pad;
2436 range=GetQuantumRange(image->depth);
2437 for (x=0; x < (ssize_t) number_pixels; x++)
2439 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2440 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2441 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2442 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2443 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2444 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2445 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2446 indexes[x]=ScaleAnyToQuantum(pixel,range);
2457 if (image->colorspace != CMYKColorspace)
2459 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2460 "ColorSeparatedImageRequired","`%s'",image->filename);
2463 switch (quantum_info->depth)
2470 for (x=0; x < (ssize_t) number_pixels; x++)
2472 p=PushCharPixel(p,&pixel);
2473 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2474 p=PushCharPixel(p,&pixel);
2475 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2476 p=PushCharPixel(p,&pixel);
2477 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2478 p=PushCharPixel(p,&pixel);
2479 indexes[x]=ScaleCharToQuantum(pixel);
2480 p=PushCharPixel(p,&pixel);
2481 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2482 p+=quantum_info->pad;
2492 if (quantum_info->format == FloatingPointQuantumFormat)
2494 for (x=0; x < (ssize_t) number_pixels; x++)
2496 p=PushShortPixel(endian,p,&pixel);
2497 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2498 HalfToSinglePrecision(pixel));
2499 p=PushShortPixel(endian,p,&pixel);
2500 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2501 HalfToSinglePrecision(pixel));
2502 p=PushShortPixel(endian,p,&pixel);
2503 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2504 HalfToSinglePrecision(pixel));
2505 p=PushShortPixel(endian,p,&pixel);
2506 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2507 HalfToSinglePrecision(pixel));
2508 p=PushShortPixel(endian,p,&pixel);
2509 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2510 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2511 p+=quantum_info->pad;
2516 for (x=0; x < (ssize_t) number_pixels; x++)
2518 p=PushShortPixel(endian,p,&pixel);
2519 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2520 p=PushShortPixel(endian,p,&pixel);
2521 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2522 p=PushShortPixel(endian,p,&pixel);
2523 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2524 p=PushShortPixel(endian,p,&pixel);
2525 indexes[x]=ScaleShortToQuantum(pixel);
2526 p=PushShortPixel(endian,p,&pixel);
2527 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2528 p+=quantum_info->pad;
2538 if (quantum_info->format == FloatingPointQuantumFormat)
2543 for (x=0; x < (ssize_t) number_pixels; x++)
2545 p=PushFloatPixel(&quantum_state,p,&pixel);
2546 q->red=ClampToQuantum(pixel);
2547 p=PushFloatPixel(&quantum_state,p,&pixel);
2548 q->green=ClampToQuantum(pixel);
2549 p=PushFloatPixel(&quantum_state,p,&pixel);
2550 q->blue=ClampToQuantum(pixel);
2551 p=PushFloatPixel(&quantum_state,p,&pixel);
2552 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2553 p=PushFloatPixel(&quantum_state,p,&pixel);
2554 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2555 p+=quantum_info->pad;
2560 for (x=0; x < (ssize_t) number_pixels; x++)
2562 p=PushLongPixel(endian,p,&pixel);
2563 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2564 p=PushLongPixel(endian,p,&pixel);
2565 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2566 p=PushLongPixel(endian,p,&pixel);
2567 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2568 p=PushLongPixel(endian,p,&pixel);
2569 indexes[x]=ScaleLongToQuantum(pixel);
2570 p=PushLongPixel(endian,p,&pixel);
2571 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2572 p+=quantum_info->pad;
2579 if (quantum_info->format == FloatingPointQuantumFormat)
2584 for (x=0; x < (ssize_t) number_pixels; x++)
2586 p=PushDoublePixel(&quantum_state,p,&pixel);
2587 q->red=ClampToQuantum(pixel);
2588 p=PushDoublePixel(&quantum_state,p,&pixel);
2589 q->green=ClampToQuantum(pixel);
2590 p=PushDoublePixel(&quantum_state,p,&pixel);
2591 q->blue=ClampToQuantum(pixel);
2592 p=PushDoublePixel(&quantum_state,p,&pixel);
2593 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2594 p=PushDoublePixel(&quantum_state,p,&pixel);
2595 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2596 p=PushDoublePixel(&quantum_state,p,&pixel);
2597 p+=quantum_info->pad;
2605 range=GetQuantumRange(image->depth);
2606 for (x=0; x < (ssize_t) number_pixels; x++)
2608 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2609 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2610 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2611 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2612 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2613 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2614 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2615 indexes[x]=ScaleAnyToQuantum(pixel,range);
2616 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2617 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2627 switch (quantum_info->depth)
2635 if (quantum_info->pack == MagickFalse)
2648 for (x=0; x < (ssize_t) number_pixels; x+=2)
2650 for (i=0; i < 4; i++)
2656 p=PushLongPixel(endian,p,&pixel);
2657 quantum=(size_t) (ScaleShortToQuantum(
2658 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2663 quantum=(size_t) (ScaleShortToQuantum(
2664 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2669 quantum=(size_t) (ScaleShortToQuantum(
2670 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2674 cbcr[i]=(Quantum) (quantum);
2677 p+=quantum_info->pad;
2692 range=GetQuantumRange(image->depth);
2693 for (x=0; x < (ssize_t) number_pixels; x++)
2695 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2696 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2697 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2698 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2709 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2714 register PixelPacket
2717 q=GetAuthenticPixelQueue(image);
2718 if (image_view != (CacheView *) NULL)
2719 q=GetCacheViewAuthenticPixelQueue(image_view);
2720 for (x=0; x < (ssize_t) number_pixels; x++)
2728 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2730 register PixelPacket
2733 q=GetAuthenticPixelQueue(image);
2734 if (image_view != (CacheView *) NULL)
2735 q=GetCacheViewAuthenticPixelQueue(image_view);
2736 for (x=0; x < (ssize_t) number_pixels; x++)
2738 q->opacity=(Quantum) GetAlphaPixelComponent(q);
2742 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2747 register PixelPacket
2753 q=GetAuthenticPixelQueue(image);
2754 if (image_view != (CacheView *) NULL)
2755 q=GetCacheViewAuthenticPixelQueue(image_view);
2756 for (x=0; x < (ssize_t) number_pixels; x++)
2758 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2759 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2760 q->red=ClampToQuantum(alpha*q->red);
2761 q->green=ClampToQuantum(alpha*q->green);
2762 q->blue=ClampToQuantum(alpha*q->blue);