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,unsigned int *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=(unsigned int) ((*quantum << quantum_bits) |
218 ((quantum_state->pixel >> quantum_state->bits) &~ ((~0UL) <<
224 static inline const unsigned char *PushQuantumLongPixel(
225 QuantumState *quantum_state,const size_t depth,
226 const unsigned char *pixels,unsigned int *quantum)
235 for (i=(ssize_t) depth; i > 0; )
237 if (quantum_state->bits == 0)
239 pixels=PushLongPixel(quantum_state->endian,pixels,
240 &quantum_state->pixel);
241 quantum_state->bits=32U;
243 quantum_bits=(size_t) i;
244 if (quantum_bits > quantum_state->bits)
245 quantum_bits=quantum_state->bits;
246 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
247 quantum_state->mask[quantum_bits]) << (depth-i));
248 i-=(ssize_t) quantum_bits;
249 quantum_state->bits-=quantum_bits;
254 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
255 const QuantumInfo *quantum_info,const QuantumType quantum_type,
256 const unsigned char *pixels,ExceptionInfo *exception)
273 register const unsigned char
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
295 assert(quantum_info != (QuantumInfo *) NULL);
296 assert(quantum_info->signature == MagickSignature);
297 if (pixels == (const unsigned char *) NULL)
298 pixels=GetQuantumPixels(quantum_info);
301 if (image_view == (CacheView *) NULL)
303 number_pixels=GetImageExtent(image);
304 q=GetAuthenticPixelQueue(image);
305 indexes=GetAuthenticIndexQueue(image);
309 number_pixels=GetCacheViewExtent(image_view);
310 q=GetCacheViewAuthenticPixelQueue(image_view);
311 indexes=GetCacheViewAuthenticIndexQueue(image_view);
313 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
314 extent=GetQuantumExtent(image,quantum_info,quantum_type);
315 endian=quantum_state.endian;
316 switch (quantum_type)
323 if (image->storage_class != PseudoClass)
325 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
326 "ColormappedImageRequired","`%s'",image->filename);
329 range_exception=MagickFalse;
330 switch (quantum_info->depth)
334 register unsigned char
337 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
339 for (bit=0; bit < 8; bit++)
341 if (quantum_info->min_is_white == MagickFalse)
342 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
345 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
347 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
348 *q=image->colormap[(ssize_t) indexes[x+bit]];
353 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
355 if (quantum_info->min_is_white == MagickFalse)
356 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
359 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
361 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
362 *q=image->colormap[(ssize_t) indexes[x+bit]];
369 register unsigned char
372 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
374 pixel=(unsigned char) ((*p >> 4) & 0xf);
375 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
376 *q=image->colormap[(ssize_t) indexes[x]];
378 pixel=(unsigned char) ((*p) & 0xf);
379 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
380 *q=image->colormap[(ssize_t) indexes[x+1]];
384 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
386 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
387 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
388 *q=image->colormap[(ssize_t) indexes[x+bit]];
398 for (x=0; x < (ssize_t) number_pixels; x++)
400 p=PushCharPixel(p,&pixel);
401 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
402 *q=image->colormap[(ssize_t) indexes[x]];
403 p+=quantum_info->pad;
413 if (quantum_info->format == FloatingPointQuantumFormat)
415 for (x=0; x < (ssize_t) number_pixels; x++)
417 p=PushShortPixel(endian,p,&pixel);
418 indexes[x]=PushColormapIndex(image,ClampToQuantum(
419 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
421 *q=image->colormap[(ssize_t) indexes[x]];
422 p+=quantum_info->pad;
427 for (x=0; x < (ssize_t) number_pixels; x++)
429 p=PushShortPixel(endian,p,&pixel);
430 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
431 *q=image->colormap[(ssize_t) indexes[x]];
432 p+=quantum_info->pad;
442 if (quantum_info->format == FloatingPointQuantumFormat)
447 for (x=0; x < (ssize_t) number_pixels; x++)
449 p=PushFloatPixel(&quantum_state,p,&pixel);
450 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
452 *q=image->colormap[(ssize_t) indexes[x]];
453 p+=quantum_info->pad;
458 for (x=0; x < (ssize_t) number_pixels; x++)
460 p=PushLongPixel(endian,p,&pixel);
461 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
462 *q=image->colormap[(ssize_t) indexes[x]];
463 p+=quantum_info->pad;
470 if (quantum_info->format == FloatingPointQuantumFormat)
475 for (x=0; x < (ssize_t) number_pixels; x++)
477 p=PushDoublePixel(&quantum_state,p,&pixel);
478 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
480 *q=image->colormap[(ssize_t) indexes[x]];
481 p+=quantum_info->pad;
489 for (x=0; x < (ssize_t) number_pixels; x++)
491 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
492 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
493 *q=image->colormap[(ssize_t) indexes[x]];
494 p+=quantum_info->pad;
500 if (range_exception != MagickFalse)
501 (void) ThrowMagickException(exception,GetMagickModule(),
502 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
505 case IndexAlphaQuantum:
510 if (image->storage_class != PseudoClass)
512 (void) ThrowMagickException(exception,GetMagickModule(),
513 ImageError,"ColormappedImageRequired","`%s'",image->filename);
516 range_exception=MagickFalse;
517 switch (quantum_info->depth)
521 register unsigned char
524 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
526 for (bit=0; bit < 8; bit+=2)
528 if (quantum_info->min_is_white == MagickFalse)
529 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
532 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
534 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
535 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
538 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
539 == 0 ? TransparentOpacity : OpaqueOpacity);
543 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
545 if (quantum_info->min_is_white == MagickFalse)
546 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
549 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
551 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
552 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
555 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
556 0 ? TransparentOpacity : OpaqueOpacity);
563 register unsigned char
566 range=GetQuantumRange(image->depth);
567 for (x=0; x < (ssize_t) number_pixels; x++)
569 pixel=(unsigned char) ((*p >> 4) & 0xf);
570 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
571 *q=image->colormap[(ssize_t) indexes[x]];
572 pixel=(unsigned char) ((*p) & 0xf);
573 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
584 for (x=0; x < (ssize_t) number_pixels; x++)
586 p=PushCharPixel(p,&pixel);
587 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
588 *q=image->colormap[(ssize_t) indexes[x]];
589 p=PushCharPixel(p,&pixel);
590 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
591 p+=quantum_info->pad;
601 if (quantum_info->format == FloatingPointQuantumFormat)
603 for (x=0; x < (ssize_t) number_pixels; x++)
605 p=PushShortPixel(endian,p,&pixel);
606 indexes[x]=PushColormapIndex(image,ClampToQuantum(
607 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
609 *q=image->colormap[(ssize_t) indexes[x]];
610 p=PushShortPixel(endian,p,&pixel);
611 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
612 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
613 p+=quantum_info->pad;
618 for (x=0; x < (ssize_t) number_pixels; x++)
620 p=PushShortPixel(endian,p,&pixel);
621 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
622 *q=image->colormap[(ssize_t) indexes[x]];
623 p=PushShortPixel(endian,p,&pixel);
624 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
625 p+=quantum_info->pad;
635 if (quantum_info->format == FloatingPointQuantumFormat)
640 for (x=0; x < (ssize_t) number_pixels; x++)
642 p=PushFloatPixel(&quantum_state,p,&pixel);
643 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
645 *q=image->colormap[(ssize_t) indexes[x]];
646 p=PushFloatPixel(&quantum_state,p,&pixel);
647 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
648 p+=quantum_info->pad;
653 for (x=0; x < (ssize_t) number_pixels; x++)
655 p=PushLongPixel(endian,p,&pixel);
656 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
657 *q=image->colormap[(ssize_t) indexes[x]];
658 p=PushLongPixel(endian,p,&pixel);
659 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
660 p+=quantum_info->pad;
667 if (quantum_info->format == FloatingPointQuantumFormat)
672 for (x=0; x < (ssize_t) number_pixels; x++)
674 p=PushDoublePixel(&quantum_state,p,&pixel);
675 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
677 *q=image->colormap[(ssize_t) indexes[x]];
678 p=PushDoublePixel(&quantum_state,p,&pixel);
679 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
680 p+=quantum_info->pad;
688 range=GetQuantumRange(image->depth);
689 for (x=0; x < (ssize_t) number_pixels; x++)
691 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
692 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
693 *q=image->colormap[(ssize_t) indexes[x]];
694 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
695 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
696 p+=quantum_info->pad;
702 if (range_exception != MagickFalse)
703 (void) ThrowMagickException(exception,GetMagickModule(),
704 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
709 switch (quantum_info->depth)
718 white=(Quantum) QuantumRange;
719 if (quantum_info->min_is_white != MagickFalse)
721 black=(Quantum) QuantumRange;
724 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
726 for (bit=0; bit < 8; bit++)
728 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
735 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
737 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
748 register unsigned char
751 range=GetQuantumRange(image->depth);
752 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
754 pixel=(unsigned char) ((*p >> 4) & 0xf);
755 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
759 pixel=(unsigned char) ((*p) & 0xf);
760 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
766 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
768 pixel=(unsigned char) (*p++ >> 4);
769 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
781 if (quantum_info->min_is_white != MagickFalse)
783 for (x=0; x < (ssize_t) number_pixels; x++)
785 p=PushCharPixel(p,&pixel);
786 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
789 SetOpacityPixelComponent(q,OpaqueOpacity);
790 p+=quantum_info->pad;
795 for (x=0; x < (ssize_t) number_pixels; x++)
797 p=PushCharPixel(p,&pixel);
798 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
801 SetOpacityPixelComponent(q,OpaqueOpacity);
802 p+=quantum_info->pad;
809 range=GetQuantumRange(image->depth);
810 if (quantum_info->pack == MagickFalse)
812 if (image->endian != LSBEndian)
814 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
816 p=PushLongPixel(endian,p,&pixel);
817 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
821 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
825 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
828 p+=quantum_info->pad;
831 p=PushLongPixel(endian,p,&pixel);
832 if (x++ < (ssize_t) (number_pixels-1))
834 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
839 if (x++ < (ssize_t) number_pixels)
841 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
848 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
850 p=PushLongPixel(endian,p,&pixel);
851 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
855 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
859 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
862 p+=quantum_info->pad;
865 p=PushLongPixel(endian,p,&pixel);
866 if (x++ < (ssize_t) (number_pixels-1))
868 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
873 if (x++ < (ssize_t) number_pixels)
875 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
882 for (x=0; x < (ssize_t) number_pixels; x++)
884 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
885 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
888 p+=quantum_info->pad;
895 range=GetQuantumRange(image->depth);
896 if (quantum_info->pack == MagickFalse)
901 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
903 p=PushShortPixel(endian,p,&pixel);
904 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
908 p=PushShortPixel(endian,p,&pixel);
909 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
912 p+=quantum_info->pad;
915 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
917 p=PushShortPixel(endian,p,&pixel);
918 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
921 p+=quantum_info->pad;
928 for (x=0; x < (ssize_t) number_pixels; x++)
930 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
931 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
934 p+=quantum_info->pad;
944 if (quantum_info->min_is_white != MagickFalse)
946 for (x=0; x < (ssize_t) number_pixels; x++)
948 p=PushShortPixel(endian,p,&pixel);
949 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
952 p+=quantum_info->pad;
957 if (quantum_info->format == FloatingPointQuantumFormat)
959 for (x=0; x < (ssize_t) number_pixels; x++)
961 p=PushShortPixel(endian,p,&pixel);
962 q->red=ClampToQuantum((MagickRealType) QuantumRange*
963 HalfToSinglePrecision(pixel));
966 p+=quantum_info->pad;
971 for (x=0; x < (ssize_t) number_pixels; x++)
973 p=PushShortPixel(endian,p,&pixel);
974 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
977 p+=quantum_info->pad;
987 if (quantum_info->format == FloatingPointQuantumFormat)
992 for (x=0; x < (ssize_t) number_pixels; x++)
994 p=PushFloatPixel(&quantum_state,p,&pixel);
995 q->red=ClampToQuantum(pixel);
998 p+=quantum_info->pad;
1003 for (x=0; x < (ssize_t) number_pixels; x++)
1005 p=PushLongPixel(endian,p,&pixel);
1006 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1009 p+=quantum_info->pad;
1016 if (quantum_info->format == FloatingPointQuantumFormat)
1021 for (x=0; x < (ssize_t) number_pixels; x++)
1023 p=PushDoublePixel(&quantum_state,p,&pixel);
1024 q->red=ClampToQuantum(pixel);
1027 p+=quantum_info->pad;
1035 range=GetQuantumRange(image->depth);
1036 for (x=0; x < (ssize_t) number_pixels; x++)
1038 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1039 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1042 p+=quantum_info->pad;
1050 case GrayAlphaQuantum:
1052 switch (quantum_info->depth)
1056 register unsigned char
1059 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
1061 for (bit=0; bit < 8; bit+=2)
1063 pixel=(unsigned char)
1064 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1065 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1068 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1069 == 0 ? TransparentOpacity : OpaqueOpacity);
1074 for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
1076 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1077 q->red=(Quantum) (pixel != 0 ? 0 : QuantumRange);
1080 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1081 == 0 ? TransparentOpacity : OpaqueOpacity);
1090 register unsigned char
1093 range=GetQuantumRange(image->depth);
1094 for (x=0; x < (ssize_t) number_pixels; x++)
1096 pixel=(unsigned char) ((*p >> 4) & 0xf);
1097 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1100 pixel=(unsigned char) ((*p) & 0xf);
1101 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1112 for (x=0; x < (ssize_t) number_pixels; x++)
1114 p=PushCharPixel(p,&pixel);
1115 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1118 p=PushCharPixel(p,&pixel);
1119 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1120 p+=quantum_info->pad;
1127 range=GetQuantumRange(image->depth);
1128 for (x=0; x < (ssize_t) number_pixels; x++)
1130 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1131 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1134 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1135 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1136 p+=quantum_info->pad;
1143 range=GetQuantumRange(image->depth);
1144 for (x=0; x < (ssize_t) number_pixels; x++)
1146 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1147 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1150 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1151 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1152 p+=quantum_info->pad;
1162 if (quantum_info->format == FloatingPointQuantumFormat)
1164 for (x=0; x < (ssize_t) number_pixels; x++)
1166 p=PushShortPixel(endian,p,&pixel);
1167 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1168 HalfToSinglePrecision(pixel));
1171 p=PushShortPixel(endian,p,&pixel);
1172 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1173 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1174 p+=quantum_info->pad;
1179 for (x=0; x < (ssize_t) number_pixels; x++)
1181 p=PushShortPixel(endian,p,&pixel);
1182 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1185 p=PushShortPixel(endian,p,&pixel);
1186 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1187 p+=quantum_info->pad;
1197 if (quantum_info->format == FloatingPointQuantumFormat)
1202 for (x=0; x < (ssize_t) number_pixels; x++)
1204 p=PushFloatPixel(&quantum_state,p,&pixel);
1205 q->red=ClampToQuantum(pixel);
1208 p=PushFloatPixel(&quantum_state,p,&pixel);
1209 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1210 p+=quantum_info->pad;
1215 for (x=0; x < (ssize_t) number_pixels; x++)
1217 p=PushLongPixel(endian,p,&pixel);
1218 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1221 p=PushLongPixel(endian,p,&pixel);
1222 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1223 p+=quantum_info->pad;
1230 if (quantum_info->format == FloatingPointQuantumFormat)
1235 for (x=0; x < (ssize_t) number_pixels; x++)
1237 p=PushDoublePixel(&quantum_state,p,&pixel);
1238 q->red=ClampToQuantum(pixel);
1241 p=PushDoublePixel(&quantum_state,p,&pixel);
1242 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1243 p+=quantum_info->pad;
1251 range=GetQuantumRange(image->depth);
1252 for (x=0; x < (ssize_t) number_pixels; x++)
1254 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1255 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1258 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1259 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1260 p+=quantum_info->pad;
1271 switch (quantum_info->depth)
1278 for (x=0; x < (ssize_t) number_pixels; x++)
1280 p=PushCharPixel(p,&pixel);
1281 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1282 p+=quantum_info->pad;
1292 if (quantum_info->format == FloatingPointQuantumFormat)
1294 for (x=0; x < (ssize_t) number_pixels; x++)
1296 p=PushShortPixel(endian,p,&pixel);
1297 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1298 HalfToSinglePrecision(pixel));
1299 p+=quantum_info->pad;
1304 for (x=0; x < (ssize_t) number_pixels; x++)
1306 p=PushShortPixel(endian,p,&pixel);
1307 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1308 p+=quantum_info->pad;
1318 if (quantum_info->format == FloatingPointQuantumFormat)
1323 for (x=0; x < (ssize_t) number_pixels; x++)
1325 p=PushFloatPixel(&quantum_state,p,&pixel);
1326 q->red=ClampToQuantum(pixel);
1327 p+=quantum_info->pad;
1332 for (x=0; x < (ssize_t) number_pixels; x++)
1334 p=PushLongPixel(endian,p,&pixel);
1335 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1336 p+=quantum_info->pad;
1343 if (quantum_info->format == FloatingPointQuantumFormat)
1348 for (x=0; x < (ssize_t) number_pixels; x++)
1350 p=PushDoublePixel(&quantum_state,p,&pixel);
1351 q->red=ClampToQuantum(pixel);
1352 p+=quantum_info->pad;
1360 range=GetQuantumRange(image->depth);
1361 for (x=0; x < (ssize_t) number_pixels; x++)
1363 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1364 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1365 p+=quantum_info->pad;
1374 case MagentaQuantum:
1376 switch (quantum_info->depth)
1383 for (x=0; x < (ssize_t) number_pixels; x++)
1385 p=PushCharPixel(p,&pixel);
1386 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1387 p+=quantum_info->pad;
1397 if (quantum_info->format == FloatingPointQuantumFormat)
1399 for (x=0; x < (ssize_t) number_pixels; x++)
1401 p=PushShortPixel(endian,p,&pixel);
1402 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1403 HalfToSinglePrecision(pixel));
1404 p+=quantum_info->pad;
1409 for (x=0; x < (ssize_t) number_pixels; x++)
1411 p=PushShortPixel(endian,p,&pixel);
1412 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1413 p+=quantum_info->pad;
1423 if (quantum_info->format == FloatingPointQuantumFormat)
1428 for (x=0; x < (ssize_t) number_pixels; x++)
1430 p=PushFloatPixel(&quantum_state,p,&pixel);
1431 q->green=ClampToQuantum(pixel);
1432 p+=quantum_info->pad;
1437 for (x=0; x < (ssize_t) number_pixels; x++)
1439 p=PushLongPixel(endian,p,&pixel);
1440 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1441 p+=quantum_info->pad;
1448 if (quantum_info->format == FloatingPointQuantumFormat)
1453 for (x=0; x < (ssize_t) number_pixels; x++)
1455 p=PushDoublePixel(&quantum_state,p,&pixel);
1456 q->green=ClampToQuantum(pixel);
1457 p+=quantum_info->pad;
1465 range=GetQuantumRange(image->depth);
1466 for (x=0; x < (ssize_t) number_pixels; x++)
1468 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1469 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1470 p+=quantum_info->pad;
1481 switch (quantum_info->depth)
1488 for (x=0; x < (ssize_t) number_pixels; x++)
1490 p=PushCharPixel(p,&pixel);
1491 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1492 p+=quantum_info->pad;
1502 if (quantum_info->format == FloatingPointQuantumFormat)
1504 for (x=0; x < (ssize_t) number_pixels; x++)
1506 p=PushShortPixel(endian,p,&pixel);
1507 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1508 HalfToSinglePrecision(pixel));
1509 p+=quantum_info->pad;
1514 for (x=0; x < (ssize_t) number_pixels; x++)
1516 p=PushShortPixel(endian,p,&pixel);
1517 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1518 p+=quantum_info->pad;
1528 if (quantum_info->format == FloatingPointQuantumFormat)
1533 for (x=0; x < (ssize_t) number_pixels; x++)
1535 p=PushFloatPixel(&quantum_state,p,&pixel);
1536 q->blue=ClampToQuantum(pixel);
1537 p+=quantum_info->pad;
1542 for (x=0; x < (ssize_t) number_pixels; x++)
1544 p=PushLongPixel(endian,p,&pixel);
1545 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1546 p+=quantum_info->pad;
1553 if (quantum_info->format == FloatingPointQuantumFormat)
1558 for (x=0; x < (ssize_t) number_pixels; x++)
1560 p=PushDoublePixel(&quantum_state,p,&pixel);
1561 q->blue=ClampToQuantum(pixel);
1562 p+=quantum_info->pad;
1570 range=GetQuantumRange(image->depth);
1571 for (x=0; x < (ssize_t) number_pixels; x++)
1573 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1574 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1575 p+=quantum_info->pad;
1585 switch (quantum_info->depth)
1592 for (x=0; x < (ssize_t) number_pixels; x++)
1594 p=PushCharPixel(p,&pixel);
1595 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1596 p+=quantum_info->pad;
1606 if (quantum_info->format == FloatingPointQuantumFormat)
1608 for (x=0; x < (ssize_t) number_pixels; x++)
1610 p=PushShortPixel(endian,p,&pixel);
1611 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1612 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1613 p+=quantum_info->pad;
1618 for (x=0; x < (ssize_t) number_pixels; x++)
1620 p=PushShortPixel(endian,p,&pixel);
1621 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1622 p+=quantum_info->pad;
1632 if (quantum_info->format == FloatingPointQuantumFormat)
1637 for (x=0; x < (ssize_t) number_pixels; x++)
1639 p=PushFloatPixel(&quantum_state,p,&pixel);
1640 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1641 p+=quantum_info->pad;
1646 for (x=0; x < (ssize_t) number_pixels; x++)
1648 p=PushLongPixel(endian,p,&pixel);
1649 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1650 p+=quantum_info->pad;
1657 if (quantum_info->format == FloatingPointQuantumFormat)
1662 for (x=0; x < (ssize_t) number_pixels; x++)
1664 p=PushDoublePixel(&quantum_state,p,&pixel);
1665 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1666 p+=quantum_info->pad;
1674 range=GetQuantumRange(image->depth);
1675 for (x=0; x < (ssize_t) number_pixels; x++)
1677 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1678 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1679 p+=quantum_info->pad;
1689 if (image->colorspace != CMYKColorspace)
1691 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1692 "ColorSeparatedImageRequired","`%s'",image->filename);
1695 switch (quantum_info->depth)
1702 for (x=0; x < (ssize_t) number_pixels; x++)
1704 p=PushCharPixel(p,&pixel);
1705 indexes[x]=ScaleCharToQuantum(pixel);
1706 p+=quantum_info->pad;
1715 if (quantum_info->format == FloatingPointQuantumFormat)
1717 for (x=0; x < (ssize_t) number_pixels; x++)
1719 p=PushShortPixel(endian,p,&pixel);
1720 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
1721 HalfToSinglePrecision(pixel));
1722 p+=quantum_info->pad;
1726 for (x=0; x < (ssize_t) number_pixels; x++)
1728 p=PushShortPixel(endian,p,&pixel);
1729 indexes[x]=ScaleShortToQuantum(pixel);
1730 p+=quantum_info->pad;
1739 if (quantum_info->format == FloatingPointQuantumFormat)
1744 for (x=0; x < (ssize_t) number_pixels; x++)
1746 p=PushFloatPixel(&quantum_state,p,&pixel);
1747 indexes[x]=ClampToQuantum(pixel);
1748 p+=quantum_info->pad;
1753 for (x=0; x < (ssize_t) number_pixels; x++)
1755 p=PushLongPixel(endian,p,&pixel);
1756 indexes[x]=ScaleLongToQuantum(pixel);
1757 p+=quantum_info->pad;
1764 if (quantum_info->format == FloatingPointQuantumFormat)
1769 for (x=0; x < (ssize_t) number_pixels; x++)
1771 p=PushDoublePixel(&quantum_state,p,&pixel);
1772 indexes[x]=ClampToQuantum(pixel);
1773 p+=quantum_info->pad;
1781 range=GetQuantumRange(image->depth);
1782 for (x=0; x < (ssize_t) number_pixels; x++)
1784 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1785 indexes[x]=ScaleAnyToQuantum(pixel,range);
1786 p+=quantum_info->pad;
1797 switch (quantum_info->depth)
1804 for (x=0; x < (ssize_t) number_pixels; x++)
1806 p=PushCharPixel(p,&pixel);
1807 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1808 p=PushCharPixel(p,&pixel);
1809 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1810 p=PushCharPixel(p,&pixel);
1811 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1812 SetOpacityPixelComponent(q,OpaqueOpacity);
1813 p+=quantum_info->pad;
1820 range=GetQuantumRange(image->depth);
1821 if (quantum_info->pack == MagickFalse)
1823 for (x=0; x < (ssize_t) number_pixels; x++)
1825 p=PushLongPixel(endian,p,&pixel);
1826 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1827 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1828 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1829 p+=quantum_info->pad;
1834 if (quantum_info->quantum == 32U)
1836 for (x=0; x < (ssize_t) number_pixels; x++)
1838 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1839 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1840 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1841 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1842 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1843 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1848 for (x=0; x < (ssize_t) number_pixels; x++)
1850 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1851 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1852 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1853 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1854 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1855 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1862 range=GetQuantumRange(image->depth);
1863 if (quantum_info->pack == MagickFalse)
1868 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
1870 p=PushShortPixel(endian,p,&pixel);
1876 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1881 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1886 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1891 p=PushShortPixel(endian,p,&pixel);
1897 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1902 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1907 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1912 p+=quantum_info->pad;
1914 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
1916 p=PushShortPixel(endian,p,&pixel);
1917 switch ((x+bit) % 3)
1922 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1927 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1932 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1937 p+=quantum_info->pad;
1943 if (quantum_info->quantum == 32U)
1945 for (x=0; x < (ssize_t) number_pixels; x++)
1947 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1948 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1949 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1950 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1951 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1952 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1957 for (x=0; x < (ssize_t) number_pixels; x++)
1959 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1960 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1961 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1962 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1963 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1964 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1974 if (quantum_info->format == FloatingPointQuantumFormat)
1976 for (x=0; x < (ssize_t) number_pixels; x++)
1978 p=PushShortPixel(endian,p,&pixel);
1979 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1980 HalfToSinglePrecision(pixel));
1981 p=PushShortPixel(endian,p,&pixel);
1982 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1983 HalfToSinglePrecision(pixel));
1984 p=PushShortPixel(endian,p,&pixel);
1985 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1986 HalfToSinglePrecision(pixel));
1987 p+=quantum_info->pad;
1992 for (x=0; x < (ssize_t) number_pixels; x++)
1994 p=PushShortPixel(endian,p,&pixel);
1995 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1996 p=PushShortPixel(endian,p,&pixel);
1997 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1998 p=PushShortPixel(endian,p,&pixel);
1999 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2000 p+=quantum_info->pad;
2010 if (quantum_info->format == FloatingPointQuantumFormat)
2015 for (x=0; x < (ssize_t) number_pixels; x++)
2017 p=PushFloatPixel(&quantum_state,p,&pixel);
2018 q->red=ClampToQuantum(pixel);
2019 p=PushFloatPixel(&quantum_state,p,&pixel);
2020 q->green=ClampToQuantum(pixel);
2021 p=PushFloatPixel(&quantum_state,p,&pixel);
2022 q->blue=ClampToQuantum(pixel);
2023 p+=quantum_info->pad;
2028 for (x=0; x < (ssize_t) number_pixels; x++)
2030 p=PushLongPixel(endian,p,&pixel);
2031 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2032 p=PushLongPixel(endian,p,&pixel);
2033 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2034 p=PushLongPixel(endian,p,&pixel);
2035 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2036 p+=quantum_info->pad;
2043 if (quantum_info->format == FloatingPointQuantumFormat)
2048 for (x=0; x < (ssize_t) number_pixels; x++)
2050 p=PushDoublePixel(&quantum_state,p,&pixel);
2051 q->red=ClampToQuantum(pixel);
2052 p=PushDoublePixel(&quantum_state,p,&pixel);
2053 q->green=ClampToQuantum(pixel);
2054 p=PushDoublePixel(&quantum_state,p,&pixel);
2055 q->blue=ClampToQuantum(pixel);
2056 p+=quantum_info->pad;
2064 range=GetQuantumRange(image->depth);
2065 for (x=0; x < (ssize_t) number_pixels; x++)
2067 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2068 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2069 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2070 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2071 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2072 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2084 switch (quantum_info->depth)
2091 for (x=0; x < (ssize_t) number_pixels; x++)
2093 p=PushCharPixel(p,&pixel);
2094 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2095 p=PushCharPixel(p,&pixel);
2096 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2097 p=PushCharPixel(p,&pixel);
2098 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2099 p=PushCharPixel(p,&pixel);
2100 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2101 p+=quantum_info->pad;
2109 if (quantum_info->pack == MagickFalse)
2122 for (x=0; x < (ssize_t) number_pixels; x++)
2124 for (i=0; i < 4; i++)
2130 p=PushLongPixel(endian,p,&pixel);
2131 quantum=(size_t) (ScaleShortToQuantum(
2132 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2137 quantum=(size_t) (ScaleShortToQuantum(
2138 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2143 quantum=(size_t) (ScaleShortToQuantum(
2144 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2150 case 0: q->red=(Quantum) (quantum); break;
2151 case 1: q->green=(Quantum) (quantum); break;
2152 case 2: q->blue=(Quantum) (quantum); break;
2153 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2157 p+=quantum_info->pad;
2162 for (x=0; x < (ssize_t) number_pixels; x++)
2164 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2165 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2166 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2167 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2168 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2169 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2170 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2171 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2172 (unsigned short) (pixel << 6)));
2182 if (quantum_info->format == FloatingPointQuantumFormat)
2184 for (x=0; x < (ssize_t) number_pixels; x++)
2186 p=PushShortPixel(endian,p,&pixel);
2187 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2188 HalfToSinglePrecision(pixel));
2189 p=PushShortPixel(endian,p,&pixel);
2190 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2191 HalfToSinglePrecision(pixel));
2192 p=PushShortPixel(endian,p,&pixel);
2193 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2194 HalfToSinglePrecision(pixel));
2195 p=PushShortPixel(endian,p,&pixel);
2196 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2197 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2198 p+=quantum_info->pad;
2203 for (x=0; x < (ssize_t) number_pixels; x++)
2205 p=PushShortPixel(endian,p,&pixel);
2206 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2207 p=PushShortPixel(endian,p,&pixel);
2208 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2209 p=PushShortPixel(endian,p,&pixel);
2210 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2211 p=PushShortPixel(endian,p,&pixel);
2212 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2213 p+=quantum_info->pad;
2223 if (quantum_info->format == FloatingPointQuantumFormat)
2228 for (x=0; x < (ssize_t) number_pixels; x++)
2230 p=PushFloatPixel(&quantum_state,p,&pixel);
2231 q->red=ClampToQuantum(pixel);
2232 p=PushFloatPixel(&quantum_state,p,&pixel);
2233 q->green=ClampToQuantum(pixel);
2234 p=PushFloatPixel(&quantum_state,p,&pixel);
2235 q->blue=ClampToQuantum(pixel);
2236 p=PushFloatPixel(&quantum_state,p,&pixel);
2237 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2238 p+=quantum_info->pad;
2243 for (x=0; x < (ssize_t) number_pixels; x++)
2245 p=PushLongPixel(endian,p,&pixel);
2246 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2247 p=PushLongPixel(endian,p,&pixel);
2248 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2249 p=PushLongPixel(endian,p,&pixel);
2250 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2251 p=PushLongPixel(endian,p,&pixel);
2252 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2253 p+=quantum_info->pad;
2260 if (quantum_info->format == FloatingPointQuantumFormat)
2265 for (x=0; x < (ssize_t) number_pixels; x++)
2267 p=PushDoublePixel(&quantum_state,p,&pixel);
2268 q->red=ClampToQuantum(pixel);
2269 p=PushDoublePixel(&quantum_state,p,&pixel);
2270 q->green=ClampToQuantum(pixel);
2271 p=PushDoublePixel(&quantum_state,p,&pixel);
2272 q->blue=ClampToQuantum(pixel);
2273 p=PushDoublePixel(&quantum_state,p,&pixel);
2274 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2275 p+=quantum_info->pad;
2283 range=GetQuantumRange(image->depth);
2284 for (x=0; x < (ssize_t) number_pixels; x++)
2286 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2287 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2288 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2289 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2290 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2291 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2292 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2293 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2303 if (image->colorspace != CMYKColorspace)
2305 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2306 "ColorSeparatedImageRequired","`%s'",image->filename);
2309 switch (quantum_info->depth)
2316 for (x=0; x < (ssize_t) number_pixels; x++)
2318 p=PushCharPixel(p,&pixel);
2319 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2320 p=PushCharPixel(p,&pixel);
2321 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2322 p=PushCharPixel(p,&pixel);
2323 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2324 p=PushCharPixel(p,&pixel);
2325 indexes[x]=ScaleCharToQuantum(pixel);
2326 p+=quantum_info->pad;
2336 if (quantum_info->format == FloatingPointQuantumFormat)
2338 for (x=0; x < (ssize_t) number_pixels; x++)
2340 p=PushShortPixel(endian,p,&pixel);
2341 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2342 HalfToSinglePrecision(pixel));
2343 p=PushShortPixel(endian,p,&pixel);
2344 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2345 HalfToSinglePrecision(pixel));
2346 p=PushShortPixel(endian,p,&pixel);
2347 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2348 HalfToSinglePrecision(pixel));
2349 p=PushShortPixel(endian,p,&pixel);
2350 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2351 HalfToSinglePrecision(pixel));
2352 p+=quantum_info->pad;
2357 for (x=0; x < (ssize_t) number_pixels; x++)
2359 p=PushShortPixel(endian,p,&pixel);
2360 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2361 p=PushShortPixel(endian,p,&pixel);
2362 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2363 p=PushShortPixel(endian,p,&pixel);
2364 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2365 p=PushShortPixel(endian,p,&pixel);
2366 indexes[x]=ScaleShortToQuantum(pixel);
2367 p+=quantum_info->pad;
2377 if (quantum_info->format == FloatingPointQuantumFormat)
2382 for (x=0; x < (ssize_t) number_pixels; x++)
2384 p=PushFloatPixel(&quantum_state,p,&pixel);
2385 q->red=ClampToQuantum(pixel);
2386 p=PushFloatPixel(&quantum_state,p,&pixel);
2387 q->green=ClampToQuantum(pixel);
2388 p=PushFloatPixel(&quantum_state,p,&pixel);
2389 q->blue=ClampToQuantum(pixel);
2390 p=PushFloatPixel(&quantum_state,p,&pixel);
2391 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2392 p+=quantum_info->pad;
2397 for (x=0; x < (ssize_t) number_pixels; x++)
2399 p=PushLongPixel(endian,p,&pixel);
2400 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2401 p=PushLongPixel(endian,p,&pixel);
2402 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2403 p=PushLongPixel(endian,p,&pixel);
2404 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2405 p=PushLongPixel(endian,p,&pixel);
2406 indexes[x]=ScaleLongToQuantum(pixel);
2407 p+=quantum_info->pad;
2414 if (quantum_info->format == FloatingPointQuantumFormat)
2419 for (x=0; x < (ssize_t) number_pixels; x++)
2421 p=PushDoublePixel(&quantum_state,p,&pixel);
2422 q->red=ClampToQuantum(pixel);
2423 p=PushDoublePixel(&quantum_state,p,&pixel);
2424 q->green=ClampToQuantum(pixel);
2425 p=PushDoublePixel(&quantum_state,p,&pixel);
2426 q->blue=ClampToQuantum(pixel);
2427 p=PushDoublePixel(&quantum_state,p,&pixel);
2428 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2429 p+=quantum_info->pad;
2437 range=GetQuantumRange(image->depth);
2438 for (x=0; x < (ssize_t) number_pixels; x++)
2440 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2441 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2442 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2443 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2444 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2445 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2446 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2447 indexes[x]=ScaleAnyToQuantum(pixel,range);
2458 if (image->colorspace != CMYKColorspace)
2460 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2461 "ColorSeparatedImageRequired","`%s'",image->filename);
2464 switch (quantum_info->depth)
2471 for (x=0; x < (ssize_t) number_pixels; x++)
2473 p=PushCharPixel(p,&pixel);
2474 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2475 p=PushCharPixel(p,&pixel);
2476 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2477 p=PushCharPixel(p,&pixel);
2478 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2479 p=PushCharPixel(p,&pixel);
2480 indexes[x]=ScaleCharToQuantum(pixel);
2481 p=PushCharPixel(p,&pixel);
2482 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2483 p+=quantum_info->pad;
2493 if (quantum_info->format == FloatingPointQuantumFormat)
2495 for (x=0; x < (ssize_t) number_pixels; x++)
2497 p=PushShortPixel(endian,p,&pixel);
2498 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2499 HalfToSinglePrecision(pixel));
2500 p=PushShortPixel(endian,p,&pixel);
2501 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2502 HalfToSinglePrecision(pixel));
2503 p=PushShortPixel(endian,p,&pixel);
2504 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2505 HalfToSinglePrecision(pixel));
2506 p=PushShortPixel(endian,p,&pixel);
2507 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2508 HalfToSinglePrecision(pixel));
2509 p=PushShortPixel(endian,p,&pixel);
2510 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2511 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2512 p+=quantum_info->pad;
2517 for (x=0; x < (ssize_t) number_pixels; x++)
2519 p=PushShortPixel(endian,p,&pixel);
2520 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2521 p=PushShortPixel(endian,p,&pixel);
2522 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2523 p=PushShortPixel(endian,p,&pixel);
2524 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2525 p=PushShortPixel(endian,p,&pixel);
2526 indexes[x]=ScaleShortToQuantum(pixel);
2527 p=PushShortPixel(endian,p,&pixel);
2528 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2529 p+=quantum_info->pad;
2539 if (quantum_info->format == FloatingPointQuantumFormat)
2544 for (x=0; x < (ssize_t) number_pixels; x++)
2546 p=PushFloatPixel(&quantum_state,p,&pixel);
2547 q->red=ClampToQuantum(pixel);
2548 p=PushFloatPixel(&quantum_state,p,&pixel);
2549 q->green=ClampToQuantum(pixel);
2550 p=PushFloatPixel(&quantum_state,p,&pixel);
2551 q->blue=ClampToQuantum(pixel);
2552 p=PushFloatPixel(&quantum_state,p,&pixel);
2553 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2554 p=PushFloatPixel(&quantum_state,p,&pixel);
2555 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2556 p+=quantum_info->pad;
2561 for (x=0; x < (ssize_t) number_pixels; x++)
2563 p=PushLongPixel(endian,p,&pixel);
2564 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2565 p=PushLongPixel(endian,p,&pixel);
2566 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2567 p=PushLongPixel(endian,p,&pixel);
2568 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2569 p=PushLongPixel(endian,p,&pixel);
2570 indexes[x]=ScaleLongToQuantum(pixel);
2571 p=PushLongPixel(endian,p,&pixel);
2572 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2573 p+=quantum_info->pad;
2580 if (quantum_info->format == FloatingPointQuantumFormat)
2585 for (x=0; x < (ssize_t) number_pixels; x++)
2587 p=PushDoublePixel(&quantum_state,p,&pixel);
2588 q->red=ClampToQuantum(pixel);
2589 p=PushDoublePixel(&quantum_state,p,&pixel);
2590 q->green=ClampToQuantum(pixel);
2591 p=PushDoublePixel(&quantum_state,p,&pixel);
2592 q->blue=ClampToQuantum(pixel);
2593 p=PushDoublePixel(&quantum_state,p,&pixel);
2594 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2595 p=PushDoublePixel(&quantum_state,p,&pixel);
2596 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2597 p=PushDoublePixel(&quantum_state,p,&pixel);
2598 p+=quantum_info->pad;
2606 range=GetQuantumRange(image->depth);
2607 for (x=0; x < (ssize_t) number_pixels; x++)
2609 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2610 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2611 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2612 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2613 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2614 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2615 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2616 indexes[x]=ScaleAnyToQuantum(pixel,range);
2617 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2618 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2628 switch (quantum_info->depth)
2636 if (quantum_info->pack == MagickFalse)
2649 for (x=0; x < (ssize_t) number_pixels; x+=2)
2651 for (i=0; i < 4; i++)
2657 p=PushLongPixel(endian,p,&pixel);
2658 quantum=(size_t) (ScaleShortToQuantum(
2659 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2664 quantum=(size_t) (ScaleShortToQuantum(
2665 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2670 quantum=(size_t) (ScaleShortToQuantum(
2671 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2675 cbcr[i]=(Quantum) (quantum);
2678 p+=quantum_info->pad;
2693 range=GetQuantumRange(image->depth);
2694 for (x=0; x < (ssize_t) number_pixels; x++)
2696 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2697 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2698 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2699 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2710 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2715 register PixelPacket
2718 q=GetAuthenticPixelQueue(image);
2719 if (image_view != (CacheView *) NULL)
2720 q=GetCacheViewAuthenticPixelQueue(image_view);
2721 for (x=0; x < (ssize_t) number_pixels; x++)
2729 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2731 register PixelPacket
2734 q=GetAuthenticPixelQueue(image);
2735 if (image_view != (CacheView *) NULL)
2736 q=GetCacheViewAuthenticPixelQueue(image_view);
2737 for (x=0; x < (ssize_t) number_pixels; x++)
2739 q->opacity=(Quantum) GetAlphaPixelComponent(q);
2743 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2748 register PixelPacket
2754 q=GetAuthenticPixelQueue(image);
2755 if (image_view != (CacheView *) NULL)
2756 q=GetCacheViewAuthenticPixelQueue(image_view);
2757 for (x=0; x < (ssize_t) number_pixels; x++)
2759 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2760 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2761 q->red=ClampToQuantum(alpha*q->red);
2762 q->green=ClampToQuantum(alpha*q->green);
2763 q->blue=ClampToQuantum(alpha*q->blue);