2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % QQQ U U AAA N N TTTTT U U M M %
7 % Q Q U U A A NN N T U U MM MM %
8 % Q Q U U AAAAA N N N T U U M M M %
9 % Q QQ U U A A N NN T U U M M %
10 % QQQQ UUU A A N N T UUU M M %
12 % IIIII M M PPPP OOO RRRR TTTTT %
13 % I MM MM P P O O R R T %
14 % I M M M PPPP O O RRRR T %
16 % IIIII M M P OOO R R T %
18 % MagickCore Methods to Import Quantum Pixels %
25 % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
31 % http://www.imagemagick.org/script/license.php %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 #include "magick/studio.h"
48 #include "magick/property.h"
49 #include "magick/blob.h"
50 #include "magick/blob-private.h"
51 #include "magick/color-private.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/cache.h"
55 #include "magick/constitute.h"
56 #include "magick/delegate.h"
57 #include "magick/geometry.h"
58 #include "magick/list.h"
59 #include "magick/magick.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/option.h"
63 #include "magick/pixel.h"
64 #include "magick/pixel-private.h"
65 #include "magick/quantum.h"
66 #include "magick/quantum-private.h"
67 #include "magick/resource_.h"
68 #include "magick/semaphore.h"
69 #include "magick/statistic.h"
70 #include "magick/stream.h"
71 #include "magick/string_.h"
72 #include "magick/utility.h"
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % I m p o r t Q u a n t u m P i x e l s %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % ImportQuantumPixels() transfers one or more pixel components from a user
86 % supplied buffer into the image pixel cache of an image. The pixels are
87 % expected in network byte order. It returns MagickTrue if the pixels are
88 % successfully transferred, otherwise MagickFalse.
90 % The format of the ImportQuantumPixels method is:
92 % size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93 % const QuantumInfo *quantum_info,const QuantumType quantum_type,
94 % const unsigned char *pixels,ExceptionInfo *exception)
96 % A description of each parameter follows:
100 % o image_view: the image cache view.
102 % o quantum_info: the quantum info.
104 % o quantum_type: Declare which pixel components to transfer (red, green,
105 % blue, opacity, RGB, or RGBA).
107 % o pixels: The pixel components are transferred from this buffer.
109 % o exception: return any errors or warnings in this structure.
113 static inline IndexPacket PushColormapIndex(Image *image,
114 const unsigned long index,MagickBooleanType *range_exception)
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
122 static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
131 if (quantum_state->endian != LSBEndian)
133 quantum[7]=(*pixels++);
134 quantum[6]=(*pixels++);
135 quantum[5]=(*pixels++);
136 quantum[5]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[2]=(*pixels++);
139 quantum[1]=(*pixels++);
140 quantum[0]=(*pixels++);
141 p=(double *) quantum;
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
147 quantum[0]=(*pixels++);
148 quantum[1]=(*pixels++);
149 quantum[2]=(*pixels++);
150 quantum[3]=(*pixels++);
151 quantum[4]=(*pixels++);
152 quantum[5]=(*pixels++);
153 quantum[6]=(*pixels++);
154 quantum[7]=(*pixels++);
155 p=(double *) quantum;
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
162 static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
171 if (quantum_state->endian != LSBEndian)
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
194 static inline const unsigned char *PushQuantumPixel(
195 QuantumState *quantum_state,const unsigned long depth,
196 const unsigned char *pixels,unsigned long *quantum)
201 register unsigned long
204 *quantum=(QuantumAny) 0;
205 for (i=(long) depth; i > 0L; )
207 if (quantum_state->bits == 0UL)
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
212 quantum_bits=(unsigned long) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218 quantum_state->bits) &~ ((~0UL) << quantum_bits));
223 static inline const unsigned char *PushQuantumLongPixel(
224 QuantumState *quantum_state,const unsigned long depth,
225 const unsigned char *pixels,unsigned long *quantum)
230 register unsigned long
234 for (i=(long) depth; i > 0; )
236 if (quantum_state->bits == 0)
238 pixels=PushLongPixel(quantum_state->endian,pixels,
239 &quantum_state->pixel);
240 quantum_state->bits=32UL;
242 quantum_bits=(unsigned long) i;
243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
245 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246 quantum_state->mask[quantum_bits]) << (depth-i));
248 quantum_state->bits-=quantum_bits;
253 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
254 const QuantumInfo *quantum_info,const QuantumType quantum_type,
255 const unsigned char *pixels,ExceptionInfo *exception)
272 register const unsigned char
290 assert(image != (Image *) NULL);
291 assert(image->signature == MagickSignature);
292 if (image->debug != MagickFalse)
293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
294 assert(quantum_info != (QuantumInfo *) NULL);
295 assert(quantum_info->signature == MagickSignature);
296 if (pixels == (const unsigned char *) NULL)
297 pixels=GetQuantumPixels(quantum_info);
300 number_pixels=GetImageExtent(image);
301 q=GetAuthenticPixelQueue(image);
302 indexes=GetAuthenticIndexQueue(image);
303 if (image_view != (CacheView *) NULL)
305 number_pixels=GetCacheViewExtent(image_view);
306 q=GetCacheViewAuthenticPixelQueue(image_view);
307 indexes=GetCacheViewAuthenticIndexQueue(image_view);
309 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
310 extent=GetQuantumExtent(image,quantum_info,quantum_type);
311 endian=quantum_state.endian;
312 switch (quantum_type)
319 if (image->storage_class != PseudoClass)
321 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
322 "ColormappedImageRequired","`%s'",image->filename);
325 range_exception=MagickFalse;
326 switch (quantum_info->depth)
330 register unsigned char
333 for (x=0; x < ((long) number_pixels-7); x+=8)
335 for (bit=0; bit < 8; bit++)
337 if (quantum_info->min_is_white == MagickFalse)
338 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
343 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
344 *q=image->colormap[(long) indexes[x+bit]];
349 for (bit=0; bit < (long) (number_pixels % 8); bit++)
351 if (quantum_info->min_is_white == MagickFalse)
352 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
357 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
358 *q=image->colormap[(long) indexes[x+bit]];
365 register unsigned char
368 for (x=0; x < ((long) number_pixels-1); x+=2)
370 pixel=(unsigned char) ((*p >> 4) & 0xf);
371 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
372 *q=image->colormap[(long) indexes[x]];
374 pixel=(unsigned char) ((*p) & 0xf);
375 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
376 *q=image->colormap[(long) indexes[x+1]];
380 for (bit=0; bit < (long) (number_pixels % 2); bit++)
382 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
383 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
384 *q=image->colormap[(long) indexes[x+bit]];
394 for (x=0; x < (long) number_pixels; x++)
396 p=PushCharPixel(p,&pixel);
397 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
398 *q=image->colormap[(long) indexes[x]];
399 p+=quantum_info->pad;
409 if (quantum_info->format == FloatingPointQuantumFormat)
411 for (x=0; x < (long) number_pixels; x++)
413 p=PushShortPixel(endian,p,&pixel);
414 indexes[x]=PushColormapIndex(image,ClampToQuantum(
415 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
417 *q=image->colormap[(long) indexes[x]];
418 p+=quantum_info->pad;
423 for (x=0; x < (long) number_pixels; x++)
425 p=PushShortPixel(endian,p,&pixel);
426 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
427 *q=image->colormap[(long) indexes[x]];
428 p+=quantum_info->pad;
438 if (quantum_info->format == FloatingPointQuantumFormat)
443 for (x=0; x < (long) number_pixels; x++)
445 p=PushFloatPixel(&quantum_state,p,&pixel);
446 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
448 *q=image->colormap[(long) indexes[x]];
449 p+=quantum_info->pad;
454 for (x=0; x < (long) number_pixels; x++)
456 p=PushLongPixel(endian,p,&pixel);
457 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
458 *q=image->colormap[(long) indexes[x]];
459 p+=quantum_info->pad;
466 if (quantum_info->format == FloatingPointQuantumFormat)
471 for (x=0; x < (long) number_pixels; x++)
473 p=PushDoublePixel(&quantum_state,p,&pixel);
474 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
476 *q=image->colormap[(long) indexes[x]];
477 p+=quantum_info->pad;
485 for (x=0; x < (long) number_pixels; x++)
487 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
488 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
489 *q=image->colormap[(long) indexes[x]];
490 p+=quantum_info->pad;
496 if (range_exception != MagickFalse)
497 (void) ThrowMagickException(exception,GetMagickModule(),
498 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
501 case IndexAlphaQuantum:
506 if (image->storage_class != PseudoClass)
508 (void) ThrowMagickException(exception,GetMagickModule(),
509 ImageError,"ColormappedImageRequired","`%s'",image->filename);
512 range_exception=MagickFalse;
513 switch (quantum_info->depth)
517 register unsigned char
520 for (x=0; x < ((long) number_pixels-3); x+=4)
522 for (bit=0; bit < 8; bit+=2)
524 if (quantum_info->min_is_white == MagickFalse)
525 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
530 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
531 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
534 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
535 == 0 ? TransparentOpacity : OpaqueOpacity);
539 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
541 if (quantum_info->min_is_white == MagickFalse)
542 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
545 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
547 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
548 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
551 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
552 0 ? TransparentOpacity : OpaqueOpacity);
559 register unsigned char
562 range=GetQuantumRange(image->depth);
563 for (x=0; x < (long) number_pixels; x++)
565 pixel=(unsigned char) ((*p >> 4) & 0xf);
566 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
567 *q=image->colormap[(long) indexes[x]];
568 pixel=(unsigned char) ((*p) & 0xf);
569 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
580 for (x=0; x < (long) number_pixels; x++)
582 p=PushCharPixel(p,&pixel);
583 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
584 *q=image->colormap[(long) indexes[x]];
585 p=PushCharPixel(p,&pixel);
586 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
587 p+=quantum_info->pad;
597 if (quantum_info->format == FloatingPointQuantumFormat)
599 for (x=0; x < (long) number_pixels; x++)
601 p=PushShortPixel(endian,p,&pixel);
602 indexes[x]=PushColormapIndex(image,ClampToQuantum(
603 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
605 *q=image->colormap[(long) indexes[x]];
606 p=PushShortPixel(endian,p,&pixel);
607 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
608 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
609 p+=quantum_info->pad;
614 for (x=0; x < (long) number_pixels; x++)
616 p=PushShortPixel(endian,p,&pixel);
617 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
618 *q=image->colormap[(long) indexes[x]];
619 p=PushShortPixel(endian,p,&pixel);
620 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
621 p+=quantum_info->pad;
631 if (quantum_info->format == FloatingPointQuantumFormat)
636 for (x=0; x < (long) number_pixels; x++)
638 p=PushFloatPixel(&quantum_state,p,&pixel);
639 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
641 *q=image->colormap[(long) indexes[x]];
642 p=PushFloatPixel(&quantum_state,p,&pixel);
643 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
644 p+=quantum_info->pad;
649 for (x=0; x < (long) number_pixels; x++)
651 p=PushLongPixel(endian,p,&pixel);
652 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
653 *q=image->colormap[(long) indexes[x]];
654 p=PushLongPixel(endian,p,&pixel);
655 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
656 p+=quantum_info->pad;
663 if (quantum_info->format == FloatingPointQuantumFormat)
668 for (x=0; x < (long) number_pixels; x++)
670 p=PushDoublePixel(&quantum_state,p,&pixel);
671 indexes[x]=PushColormapIndex(image,ClampToQuantum(pixel),
673 *q=image->colormap[(long) indexes[x]];
674 p=PushDoublePixel(&quantum_state,p,&pixel);
675 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
676 p+=quantum_info->pad;
684 range=GetQuantumRange(image->depth);
685 for (x=0; x < (long) number_pixels; x++)
687 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
688 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
689 *q=image->colormap[(long) indexes[x]];
690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
691 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
692 p+=quantum_info->pad;
698 if (range_exception != MagickFalse)
699 (void) ThrowMagickException(exception,GetMagickModule(),
700 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
705 switch (quantum_info->depth)
714 white=(Quantum) QuantumRange;
715 if (quantum_info->min_is_white != MagickFalse)
717 black=(Quantum) QuantumRange;
720 for (x=0; x < ((long) number_pixels-7); x+=8)
722 for (bit=0; bit < 8; bit++)
724 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
731 for (bit=0; bit < (long) (number_pixels % 8); bit++)
733 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
744 register unsigned char
747 range=GetQuantumRange(image->depth);
748 for (x=0; x < ((long) number_pixels-1); x+=2)
750 pixel=(unsigned char) ((*p >> 4) & 0xf);
751 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
755 pixel=(unsigned char) ((*p) & 0xf);
756 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
762 for (bit=0; bit < (long) (number_pixels % 2); bit++)
764 pixel=(unsigned char) (*p++ >> 4);
765 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
777 if (quantum_info->min_is_white != MagickFalse)
779 for (x=0; x < (long) number_pixels; x++)
781 p=PushCharPixel(p,&pixel);
782 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
785 SetOpacityPixelComponent(q,OpaqueOpacity);
786 p+=quantum_info->pad;
791 for (x=0; x < (long) number_pixels; x++)
793 p=PushCharPixel(p,&pixel);
794 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
797 SetOpacityPixelComponent(q,OpaqueOpacity);
798 p+=quantum_info->pad;
805 range=GetQuantumRange(image->depth);
806 if (quantum_info->pack == MagickFalse)
808 if (image->endian != LSBEndian)
810 for (x=0; x < (long) (number_pixels-2); x+=3)
812 p=PushLongPixel(endian,p,&pixel);
813 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
817 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
821 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
824 p+=quantum_info->pad;
827 p=PushLongPixel(endian,p,&pixel);
828 if (x++ < (long) (number_pixels-1))
830 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
835 if (x++ < (long) number_pixels)
837 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
844 for (x=0; x < (long) (number_pixels-2); x+=3)
846 p=PushLongPixel(endian,p,&pixel);
847 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
851 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
855 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
858 p+=quantum_info->pad;
861 p=PushLongPixel(endian,p,&pixel);
862 if (x++ < (long) (number_pixels-1))
864 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
869 if (x++ < (long) number_pixels)
871 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
878 for (x=0; x < (long) number_pixels; x++)
880 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
881 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
884 p+=quantum_info->pad;
891 range=GetQuantumRange(image->depth);
892 if (quantum_info->pack == MagickFalse)
897 for (x=0; x < (long) (number_pixels-1); x+=2)
899 p=PushShortPixel(endian,p,&pixel);
900 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
904 p=PushShortPixel(endian,p,&pixel);
905 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
908 p+=quantum_info->pad;
911 for (bit=0; bit < (long) (number_pixels % 2); bit++)
913 p=PushShortPixel(endian,p,&pixel);
914 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
917 p+=quantum_info->pad;
924 for (x=0; x < (long) number_pixels; x++)
926 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
927 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
930 p+=quantum_info->pad;
940 if (quantum_info->min_is_white != MagickFalse)
942 for (x=0; x < (long) number_pixels; x++)
944 p=PushShortPixel(endian,p,&pixel);
945 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
948 p+=quantum_info->pad;
953 if (quantum_info->format == FloatingPointQuantumFormat)
955 for (x=0; x < (long) number_pixels; x++)
957 p=PushShortPixel(endian,p,&pixel);
958 q->red=ClampToQuantum((MagickRealType) QuantumRange*
959 HalfToSinglePrecision(pixel));
962 p+=quantum_info->pad;
967 for (x=0; x < (long) number_pixels; x++)
969 p=PushShortPixel(endian,p,&pixel);
970 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
973 p+=quantum_info->pad;
983 if (quantum_info->format == FloatingPointQuantumFormat)
988 for (x=0; x < (long) number_pixels; x++)
990 p=PushFloatPixel(&quantum_state,p,&pixel);
991 q->red=ClampToQuantum(pixel);
994 p+=quantum_info->pad;
999 for (x=0; x < (long) number_pixels; x++)
1001 p=PushLongPixel(endian,p,&pixel);
1002 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1005 p+=quantum_info->pad;
1012 if (quantum_info->format == FloatingPointQuantumFormat)
1017 for (x=0; x < (long) number_pixels; x++)
1019 p=PushDoublePixel(&quantum_state,p,&pixel);
1020 q->red=ClampToQuantum(pixel);
1023 p+=quantum_info->pad;
1031 range=GetQuantumRange(image->depth);
1032 for (x=0; x < (long) number_pixels; x++)
1034 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1035 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1038 p+=quantum_info->pad;
1046 case GrayAlphaQuantum:
1048 switch (quantum_info->depth)
1052 register unsigned char
1055 for (x=0; x < ((long) number_pixels-3); x+=4)
1057 for (bit=0; bit < 8; bit+=2)
1059 pixel=(unsigned char)
1060 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1061 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1064 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1065 == 0 ? TransparentOpacity : OpaqueOpacity);
1070 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
1072 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1073 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1076 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1077 ? TransparentOpacity : OpaqueOpacity);
1086 register unsigned char
1089 range=GetQuantumRange(image->depth);
1090 for (x=0; x < (long) number_pixels; x++)
1092 pixel=(unsigned char) ((*p >> 4) & 0xf);
1093 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1096 pixel=(unsigned char) ((*p) & 0xf);
1097 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1108 for (x=0; x < (long) number_pixels; x++)
1110 p=PushCharPixel(p,&pixel);
1111 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1114 p=PushCharPixel(p,&pixel);
1115 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1116 p+=quantum_info->pad;
1123 range=GetQuantumRange(image->depth);
1124 for (x=0; x < (long) number_pixels; x++)
1126 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1127 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1130 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1131 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1132 p+=quantum_info->pad;
1139 range=GetQuantumRange(image->depth);
1140 for (x=0; x < (long) number_pixels; x++)
1142 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1143 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1146 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1147 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1148 p+=quantum_info->pad;
1158 if (quantum_info->format == FloatingPointQuantumFormat)
1160 for (x=0; x < (long) number_pixels; x++)
1162 p=PushShortPixel(endian,p,&pixel);
1163 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1164 HalfToSinglePrecision(pixel));
1167 p=PushShortPixel(endian,p,&pixel);
1168 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1169 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1170 p+=quantum_info->pad;
1175 for (x=0; x < (long) number_pixels; x++)
1177 p=PushShortPixel(endian,p,&pixel);
1178 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1181 p=PushShortPixel(endian,p,&pixel);
1182 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1183 p+=quantum_info->pad;
1193 if (quantum_info->format == FloatingPointQuantumFormat)
1198 for (x=0; x < (long) number_pixels; x++)
1200 p=PushFloatPixel(&quantum_state,p,&pixel);
1201 q->red=ClampToQuantum(pixel);
1204 p=PushFloatPixel(&quantum_state,p,&pixel);
1205 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1206 p+=quantum_info->pad;
1211 for (x=0; x < (long) number_pixels; x++)
1213 p=PushLongPixel(endian,p,&pixel);
1214 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1217 p=PushLongPixel(endian,p,&pixel);
1218 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1219 p+=quantum_info->pad;
1226 if (quantum_info->format == FloatingPointQuantumFormat)
1231 for (x=0; x < (long) number_pixels; x++)
1233 p=PushDoublePixel(&quantum_state,p,&pixel);
1234 q->red=ClampToQuantum(pixel);
1237 p=PushDoublePixel(&quantum_state,p,&pixel);
1238 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1239 p+=quantum_info->pad;
1247 range=GetQuantumRange(image->depth);
1248 for (x=0; x < (long) number_pixels; x++)
1250 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1251 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1254 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1255 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1256 p+=quantum_info->pad;
1267 switch (quantum_info->depth)
1274 for (x=0; x < (long) number_pixels; x++)
1276 p=PushCharPixel(p,&pixel);
1277 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1278 p+=quantum_info->pad;
1288 if (quantum_info->format == FloatingPointQuantumFormat)
1290 for (x=0; x < (long) number_pixels; x++)
1292 p=PushShortPixel(endian,p,&pixel);
1293 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1294 HalfToSinglePrecision(pixel));
1295 p+=quantum_info->pad;
1300 for (x=0; x < (long) number_pixels; x++)
1302 p=PushShortPixel(endian,p,&pixel);
1303 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1304 p+=quantum_info->pad;
1314 if (quantum_info->format == FloatingPointQuantumFormat)
1319 for (x=0; x < (long) number_pixels; x++)
1321 p=PushFloatPixel(&quantum_state,p,&pixel);
1322 q->red=ClampToQuantum(pixel);
1323 p+=quantum_info->pad;
1328 for (x=0; x < (long) number_pixels; x++)
1330 p=PushLongPixel(endian,p,&pixel);
1331 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1332 p+=quantum_info->pad;
1339 if (quantum_info->format == FloatingPointQuantumFormat)
1344 for (x=0; x < (long) number_pixels; x++)
1346 p=PushDoublePixel(&quantum_state,p,&pixel);
1347 q->red=ClampToQuantum(pixel);
1348 p+=quantum_info->pad;
1356 range=GetQuantumRange(image->depth);
1357 for (x=0; x < (long) number_pixels; x++)
1359 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1360 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1361 p+=quantum_info->pad;
1370 case MagentaQuantum:
1372 switch (quantum_info->depth)
1379 for (x=0; x < (long) number_pixels; x++)
1381 p=PushCharPixel(p,&pixel);
1382 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1383 p+=quantum_info->pad;
1393 if (quantum_info->format == FloatingPointQuantumFormat)
1395 for (x=0; x < (long) number_pixels; x++)
1397 p=PushShortPixel(endian,p,&pixel);
1398 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1399 HalfToSinglePrecision(pixel));
1400 p+=quantum_info->pad;
1405 for (x=0; x < (long) number_pixels; x++)
1407 p=PushShortPixel(endian,p,&pixel);
1408 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1409 p+=quantum_info->pad;
1419 if (quantum_info->format == FloatingPointQuantumFormat)
1424 for (x=0; x < (long) number_pixels; x++)
1426 p=PushFloatPixel(&quantum_state,p,&pixel);
1427 q->green=ClampToQuantum(pixel);
1428 p+=quantum_info->pad;
1433 for (x=0; x < (long) number_pixels; x++)
1435 p=PushLongPixel(endian,p,&pixel);
1436 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1437 p+=quantum_info->pad;
1444 if (quantum_info->format == FloatingPointQuantumFormat)
1449 for (x=0; x < (long) number_pixels; x++)
1451 p=PushDoublePixel(&quantum_state,p,&pixel);
1452 q->green=ClampToQuantum(pixel);
1453 p+=quantum_info->pad;
1461 range=GetQuantumRange(image->depth);
1462 for (x=0; x < (long) number_pixels; x++)
1464 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1465 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1466 p+=quantum_info->pad;
1477 switch (quantum_info->depth)
1484 for (x=0; x < (long) number_pixels; x++)
1486 p=PushCharPixel(p,&pixel);
1487 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1488 p+=quantum_info->pad;
1498 if (quantum_info->format == FloatingPointQuantumFormat)
1500 for (x=0; x < (long) number_pixels; x++)
1502 p=PushShortPixel(endian,p,&pixel);
1503 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1504 HalfToSinglePrecision(pixel));
1505 p+=quantum_info->pad;
1510 for (x=0; x < (long) number_pixels; x++)
1512 p=PushShortPixel(endian,p,&pixel);
1513 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1514 p+=quantum_info->pad;
1524 if (quantum_info->format == FloatingPointQuantumFormat)
1529 for (x=0; x < (long) number_pixels; x++)
1531 p=PushFloatPixel(&quantum_state,p,&pixel);
1532 q->blue=ClampToQuantum(pixel);
1533 p+=quantum_info->pad;
1538 for (x=0; x < (long) number_pixels; x++)
1540 p=PushLongPixel(endian,p,&pixel);
1541 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1542 p+=quantum_info->pad;
1549 if (quantum_info->format == FloatingPointQuantumFormat)
1554 for (x=0; x < (long) number_pixels; x++)
1556 p=PushDoublePixel(&quantum_state,p,&pixel);
1557 q->blue=ClampToQuantum(pixel);
1558 p+=quantum_info->pad;
1566 range=GetQuantumRange(image->depth);
1567 for (x=0; x < (long) number_pixels; x++)
1569 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1570 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1571 p+=quantum_info->pad;
1581 switch (quantum_info->depth)
1588 for (x=0; x < (long) number_pixels; x++)
1590 p=PushCharPixel(p,&pixel);
1591 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1592 p+=quantum_info->pad;
1602 if (quantum_info->format == FloatingPointQuantumFormat)
1604 for (x=0; x < (long) number_pixels; x++)
1606 p=PushShortPixel(endian,p,&pixel);
1607 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
1608 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
1609 p+=quantum_info->pad;
1614 for (x=0; x < (long) number_pixels; x++)
1616 p=PushShortPixel(endian,p,&pixel);
1617 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1618 p+=quantum_info->pad;
1628 if (quantum_info->format == FloatingPointQuantumFormat)
1633 for (x=0; x < (long) number_pixels; x++)
1635 p=PushFloatPixel(&quantum_state,p,&pixel);
1636 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1637 p+=quantum_info->pad;
1642 for (x=0; x < (long) number_pixels; x++)
1644 p=PushLongPixel(endian,p,&pixel);
1645 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1646 p+=quantum_info->pad;
1653 if (quantum_info->format == FloatingPointQuantumFormat)
1658 for (x=0; x < (long) number_pixels; x++)
1660 p=PushDoublePixel(&quantum_state,p,&pixel);
1661 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
1662 p+=quantum_info->pad;
1670 range=GetQuantumRange(image->depth);
1671 for (x=0; x < (long) number_pixels; x++)
1673 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1674 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1675 p+=quantum_info->pad;
1685 if (image->colorspace != CMYKColorspace)
1687 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1688 "ColorSeparatedImageRequired","`%s'",image->filename);
1691 switch (quantum_info->depth)
1698 for (x=0; x < (long) number_pixels; x++)
1700 p=PushCharPixel(p,&pixel);
1701 indexes[x]=ScaleCharToQuantum(pixel);
1702 p+=quantum_info->pad;
1711 if (quantum_info->format == FloatingPointQuantumFormat)
1713 for (x=0; x < (long) number_pixels; x++)
1715 p=PushShortPixel(endian,p,&pixel);
1716 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
1717 HalfToSinglePrecision(pixel));
1718 p+=quantum_info->pad;
1722 for (x=0; x < (long) number_pixels; x++)
1724 p=PushShortPixel(endian,p,&pixel);
1725 indexes[x]=ScaleShortToQuantum(pixel);
1726 p+=quantum_info->pad;
1735 if (quantum_info->format == FloatingPointQuantumFormat)
1740 for (x=0; x < (long) number_pixels; x++)
1742 p=PushFloatPixel(&quantum_state,p,&pixel);
1743 indexes[x]=ClampToQuantum(pixel);
1744 p+=quantum_info->pad;
1749 for (x=0; x < (long) number_pixels; x++)
1751 p=PushLongPixel(endian,p,&pixel);
1752 indexes[x]=ScaleLongToQuantum(pixel);
1753 p+=quantum_info->pad;
1760 if (quantum_info->format == FloatingPointQuantumFormat)
1765 for (x=0; x < (long) number_pixels; x++)
1767 p=PushDoublePixel(&quantum_state,p,&pixel);
1768 indexes[x]=ClampToQuantum(pixel);
1769 p+=quantum_info->pad;
1777 range=GetQuantumRange(image->depth);
1778 for (x=0; x < (long) number_pixels; x++)
1780 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1781 indexes[x]=ScaleAnyToQuantum(pixel,range);
1782 p+=quantum_info->pad;
1793 switch (quantum_info->depth)
1800 for (x=0; x < (long) number_pixels; x++)
1802 p=PushCharPixel(p,&pixel);
1803 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1804 p=PushCharPixel(p,&pixel);
1805 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1806 p=PushCharPixel(p,&pixel);
1807 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1808 SetOpacityPixelComponent(q,OpaqueOpacity);
1809 p+=quantum_info->pad;
1816 range=GetQuantumRange(image->depth);
1817 if (quantum_info->pack == MagickFalse)
1819 for (x=0; x < (long) number_pixels; x++)
1821 p=PushLongPixel(endian,p,&pixel);
1822 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1823 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1824 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1825 p+=quantum_info->pad;
1830 if (quantum_info->quantum == 32UL)
1832 for (x=0; x < (long) number_pixels; x++)
1834 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1835 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1836 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1837 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1838 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1839 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1844 for (x=0; x < (long) number_pixels; x++)
1846 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1847 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1848 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1849 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1850 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1851 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1858 range=GetQuantumRange(image->depth);
1859 if (quantum_info->pack == MagickFalse)
1864 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1866 p=PushShortPixel(endian,p,&pixel);
1872 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1877 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1882 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1887 p=PushShortPixel(endian,p,&pixel);
1893 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1898 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1903 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1908 p+=quantum_info->pad;
1910 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1912 p=PushShortPixel(endian,p,&pixel);
1913 switch ((x+bit) % 3)
1918 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1923 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1928 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1933 p+=quantum_info->pad;
1939 if (quantum_info->quantum == 32UL)
1941 for (x=0; x < (long) number_pixels; x++)
1943 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1944 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1945 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1946 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1947 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1948 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1953 for (x=0; x < (long) number_pixels; x++)
1955 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1956 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1957 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1958 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1959 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1960 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1970 if (quantum_info->format == FloatingPointQuantumFormat)
1972 for (x=0; x < (long) number_pixels; x++)
1974 p=PushShortPixel(endian,p,&pixel);
1975 q->red=ClampToQuantum((MagickRealType) QuantumRange*
1976 HalfToSinglePrecision(pixel));
1977 p=PushShortPixel(endian,p,&pixel);
1978 q->green=ClampToQuantum((MagickRealType) QuantumRange*
1979 HalfToSinglePrecision(pixel));
1980 p=PushShortPixel(endian,p,&pixel);
1981 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
1982 HalfToSinglePrecision(pixel));
1983 p+=quantum_info->pad;
1988 for (x=0; x < (long) number_pixels; x++)
1990 p=PushShortPixel(endian,p,&pixel);
1991 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1992 p=PushShortPixel(endian,p,&pixel);
1993 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1994 p=PushShortPixel(endian,p,&pixel);
1995 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1996 p+=quantum_info->pad;
2006 if (quantum_info->format == FloatingPointQuantumFormat)
2011 for (x=0; x < (long) number_pixels; x++)
2013 p=PushFloatPixel(&quantum_state,p,&pixel);
2014 q->red=ClampToQuantum(pixel);
2015 p=PushFloatPixel(&quantum_state,p,&pixel);
2016 q->green=ClampToQuantum(pixel);
2017 p=PushFloatPixel(&quantum_state,p,&pixel);
2018 q->blue=ClampToQuantum(pixel);
2019 p+=quantum_info->pad;
2024 for (x=0; x < (long) number_pixels; x++)
2026 p=PushLongPixel(endian,p,&pixel);
2027 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2028 p=PushLongPixel(endian,p,&pixel);
2029 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2030 p=PushLongPixel(endian,p,&pixel);
2031 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2032 p+=quantum_info->pad;
2039 if (quantum_info->format == FloatingPointQuantumFormat)
2044 for (x=0; x < (long) number_pixels; x++)
2046 p=PushDoublePixel(&quantum_state,p,&pixel);
2047 q->red=ClampToQuantum(pixel);
2048 p=PushDoublePixel(&quantum_state,p,&pixel);
2049 q->green=ClampToQuantum(pixel);
2050 p=PushDoublePixel(&quantum_state,p,&pixel);
2051 q->blue=ClampToQuantum(pixel);
2052 p+=quantum_info->pad;
2060 range=GetQuantumRange(image->depth);
2061 for (x=0; x < (long) number_pixels; x++)
2063 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2064 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2065 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2066 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2067 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2068 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2080 switch (quantum_info->depth)
2087 for (x=0; x < (long) number_pixels; x++)
2089 p=PushCharPixel(p,&pixel);
2090 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2091 p=PushCharPixel(p,&pixel);
2092 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2093 p=PushCharPixel(p,&pixel);
2094 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2095 p=PushCharPixel(p,&pixel);
2096 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2097 p+=quantum_info->pad;
2105 if (quantum_info->pack == MagickFalse)
2118 for (x=0; x < (long) number_pixels; x++)
2120 for (i=0; i < 4; i++)
2126 p=PushLongPixel(endian,p,&pixel);
2127 quantum=(unsigned long) (ScaleShortToQuantum(
2128 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2133 quantum=(unsigned long) (ScaleShortToQuantum(
2134 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2139 quantum=(unsigned long) (ScaleShortToQuantum(
2140 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2146 case 0: q->red=(Quantum) (quantum); break;
2147 case 1: q->green=(Quantum) (quantum); break;
2148 case 2: q->blue=(Quantum) (quantum); break;
2149 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2153 p+=quantum_info->pad;
2158 for (x=0; x < (long) number_pixels; x++)
2160 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2161 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2162 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2163 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2164 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2165 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2166 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2167 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2168 (unsigned short) (pixel << 6)));
2178 if (quantum_info->format == FloatingPointQuantumFormat)
2180 for (x=0; x < (long) number_pixels; x++)
2182 p=PushShortPixel(endian,p,&pixel);
2183 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2184 HalfToSinglePrecision(pixel));
2185 p=PushShortPixel(endian,p,&pixel);
2186 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2187 HalfToSinglePrecision(pixel));
2188 p=PushShortPixel(endian,p,&pixel);
2189 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2190 HalfToSinglePrecision(pixel));
2191 p=PushShortPixel(endian,p,&pixel);
2192 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2193 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2194 p+=quantum_info->pad;
2199 for (x=0; x < (long) number_pixels; x++)
2201 p=PushShortPixel(endian,p,&pixel);
2202 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2203 p=PushShortPixel(endian,p,&pixel);
2204 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2205 p=PushShortPixel(endian,p,&pixel);
2206 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2207 p=PushShortPixel(endian,p,&pixel);
2208 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2209 p+=quantum_info->pad;
2219 if (quantum_info->format == FloatingPointQuantumFormat)
2224 for (x=0; x < (long) number_pixels; x++)
2226 p=PushFloatPixel(&quantum_state,p,&pixel);
2227 q->red=ClampToQuantum(pixel);
2228 p=PushFloatPixel(&quantum_state,p,&pixel);
2229 q->green=ClampToQuantum(pixel);
2230 p=PushFloatPixel(&quantum_state,p,&pixel);
2231 q->blue=ClampToQuantum(pixel);
2232 p=PushFloatPixel(&quantum_state,p,&pixel);
2233 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2234 p+=quantum_info->pad;
2239 for (x=0; x < (long) number_pixels; x++)
2241 p=PushLongPixel(endian,p,&pixel);
2242 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2243 p=PushLongPixel(endian,p,&pixel);
2244 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2245 p=PushLongPixel(endian,p,&pixel);
2246 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2247 p=PushLongPixel(endian,p,&pixel);
2248 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2249 p+=quantum_info->pad;
2256 if (quantum_info->format == FloatingPointQuantumFormat)
2261 for (x=0; x < (long) number_pixels; x++)
2263 p=PushDoublePixel(&quantum_state,p,&pixel);
2264 q->red=ClampToQuantum(pixel);
2265 p=PushDoublePixel(&quantum_state,p,&pixel);
2266 q->green=ClampToQuantum(pixel);
2267 p=PushDoublePixel(&quantum_state,p,&pixel);
2268 q->blue=ClampToQuantum(pixel);
2269 p=PushDoublePixel(&quantum_state,p,&pixel);
2270 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2271 p+=quantum_info->pad;
2279 range=GetQuantumRange(image->depth);
2280 for (x=0; x < (long) number_pixels; x++)
2282 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2283 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2284 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2285 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2286 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2287 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2288 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2289 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2299 if (image->colorspace != CMYKColorspace)
2301 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2302 "ColorSeparatedImageRequired","`%s'",image->filename);
2305 switch (quantum_info->depth)
2312 for (x=0; x < (long) number_pixels; x++)
2314 p=PushCharPixel(p,&pixel);
2315 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2316 p=PushCharPixel(p,&pixel);
2317 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2318 p=PushCharPixel(p,&pixel);
2319 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2320 p=PushCharPixel(p,&pixel);
2321 indexes[x]=ScaleCharToQuantum(pixel);
2322 p+=quantum_info->pad;
2332 if (quantum_info->format == FloatingPointQuantumFormat)
2334 for (x=0; x < (long) number_pixels; x++)
2336 p=PushShortPixel(endian,p,&pixel);
2337 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2338 HalfToSinglePrecision(pixel));
2339 p=PushShortPixel(endian,p,&pixel);
2340 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2341 HalfToSinglePrecision(pixel));
2342 p=PushShortPixel(endian,p,&pixel);
2343 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2344 HalfToSinglePrecision(pixel));
2345 p=PushShortPixel(endian,p,&pixel);
2346 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2347 HalfToSinglePrecision(pixel));
2348 p+=quantum_info->pad;
2353 for (x=0; x < (long) number_pixels; x++)
2355 p=PushShortPixel(endian,p,&pixel);
2356 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2357 p=PushShortPixel(endian,p,&pixel);
2358 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2359 p=PushShortPixel(endian,p,&pixel);
2360 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2361 p=PushShortPixel(endian,p,&pixel);
2362 indexes[x]=ScaleShortToQuantum(pixel);
2363 p+=quantum_info->pad;
2373 if (quantum_info->format == FloatingPointQuantumFormat)
2378 for (x=0; x < (long) number_pixels; x++)
2380 p=PushFloatPixel(&quantum_state,p,&pixel);
2381 q->red=ClampToQuantum(pixel);
2382 p=PushFloatPixel(&quantum_state,p,&pixel);
2383 q->green=ClampToQuantum(pixel);
2384 p=PushFloatPixel(&quantum_state,p,&pixel);
2385 q->blue=ClampToQuantum(pixel);
2386 p=PushFloatPixel(&quantum_state,p,&pixel);
2387 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2388 p+=quantum_info->pad;
2393 for (x=0; x < (long) number_pixels; x++)
2395 p=PushLongPixel(endian,p,&pixel);
2396 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2397 p=PushLongPixel(endian,p,&pixel);
2398 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2399 p=PushLongPixel(endian,p,&pixel);
2400 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2401 p=PushLongPixel(endian,p,&pixel);
2402 indexes[x]=ScaleLongToQuantum(pixel);
2403 p+=quantum_info->pad;
2410 if (quantum_info->format == FloatingPointQuantumFormat)
2415 for (x=0; x < (long) number_pixels; x++)
2417 p=PushDoublePixel(&quantum_state,p,&pixel);
2418 q->red=ClampToQuantum(pixel);
2419 p=PushDoublePixel(&quantum_state,p,&pixel);
2420 q->green=ClampToQuantum(pixel);
2421 p=PushDoublePixel(&quantum_state,p,&pixel);
2422 q->blue=ClampToQuantum(pixel);
2423 p=PushDoublePixel(&quantum_state,p,&pixel);
2424 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2425 p+=quantum_info->pad;
2433 range=GetQuantumRange(image->depth);
2434 for (x=0; x < (long) number_pixels; x++)
2436 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2437 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2438 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2439 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2440 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2441 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2442 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2443 indexes[x]=ScaleAnyToQuantum(pixel,range);
2454 if (image->colorspace != CMYKColorspace)
2456 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2457 "ColorSeparatedImageRequired","`%s'",image->filename);
2460 switch (quantum_info->depth)
2467 for (x=0; x < (long) number_pixels; x++)
2469 p=PushCharPixel(p,&pixel);
2470 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2471 p=PushCharPixel(p,&pixel);
2472 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2473 p=PushCharPixel(p,&pixel);
2474 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2475 p=PushCharPixel(p,&pixel);
2476 indexes[x]=ScaleCharToQuantum(pixel);
2477 p=PushCharPixel(p,&pixel);
2478 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2479 p+=quantum_info->pad;
2489 if (quantum_info->format == FloatingPointQuantumFormat)
2491 for (x=0; x < (long) number_pixels; x++)
2493 p=PushShortPixel(endian,p,&pixel);
2494 q->red=ClampToQuantum((MagickRealType) QuantumRange*
2495 HalfToSinglePrecision(pixel));
2496 p=PushShortPixel(endian,p,&pixel);
2497 q->green=ClampToQuantum((MagickRealType) QuantumRange*
2498 HalfToSinglePrecision(pixel));
2499 p=PushShortPixel(endian,p,&pixel);
2500 q->blue=ClampToQuantum((MagickRealType) QuantumRange*
2501 HalfToSinglePrecision(pixel));
2502 p=PushShortPixel(endian,p,&pixel);
2503 indexes[x]=ClampToQuantum((MagickRealType) QuantumRange*
2504 HalfToSinglePrecision(pixel));
2505 p=PushShortPixel(endian,p,&pixel);
2506 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(
2507 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2508 p+=quantum_info->pad;
2513 for (x=0; x < (long) number_pixels; x++)
2515 p=PushShortPixel(endian,p,&pixel);
2516 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2517 p=PushShortPixel(endian,p,&pixel);
2518 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2519 p=PushShortPixel(endian,p,&pixel);
2520 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2521 p=PushShortPixel(endian,p,&pixel);
2522 indexes[x]=ScaleShortToQuantum(pixel);
2523 p=PushShortPixel(endian,p,&pixel);
2524 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2525 p+=quantum_info->pad;
2535 if (quantum_info->format == FloatingPointQuantumFormat)
2540 for (x=0; x < (long) number_pixels; x++)
2542 p=PushFloatPixel(&quantum_state,p,&pixel);
2543 q->red=ClampToQuantum(pixel);
2544 p=PushFloatPixel(&quantum_state,p,&pixel);
2545 q->green=ClampToQuantum(pixel);
2546 p=PushFloatPixel(&quantum_state,p,&pixel);
2547 q->blue=ClampToQuantum(pixel);
2548 p=PushFloatPixel(&quantum_state,p,&pixel);
2549 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2550 p=PushFloatPixel(&quantum_state,p,&pixel);
2551 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2552 p+=quantum_info->pad;
2557 for (x=0; x < (long) number_pixels; x++)
2559 p=PushLongPixel(endian,p,&pixel);
2560 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2561 p=PushLongPixel(endian,p,&pixel);
2562 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2563 p=PushLongPixel(endian,p,&pixel);
2564 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2565 p=PushLongPixel(endian,p,&pixel);
2566 indexes[x]=ScaleLongToQuantum(pixel);
2567 p=PushLongPixel(endian,p,&pixel);
2568 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2569 p+=quantum_info->pad;
2576 if (quantum_info->format == FloatingPointQuantumFormat)
2581 for (x=0; x < (long) number_pixels; x++)
2583 p=PushDoublePixel(&quantum_state,p,&pixel);
2584 q->red=ClampToQuantum(pixel);
2585 p=PushDoublePixel(&quantum_state,p,&pixel);
2586 q->green=ClampToQuantum(pixel);
2587 p=PushDoublePixel(&quantum_state,p,&pixel);
2588 q->blue=ClampToQuantum(pixel);
2589 p=PushDoublePixel(&quantum_state,p,&pixel);
2590 indexes[x]=(IndexPacket) ClampToQuantum(pixel);
2591 p=PushDoublePixel(&quantum_state,p,&pixel);
2592 q->opacity=(Quantum) (QuantumRange-ClampToQuantum(pixel));
2593 p=PushDoublePixel(&quantum_state,p,&pixel);
2594 p+=quantum_info->pad;
2602 range=GetQuantumRange(image->depth);
2603 for (x=0; x < (long) number_pixels; x++)
2605 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2606 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2607 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2608 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2609 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2610 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2611 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2612 indexes[x]=ScaleAnyToQuantum(pixel,range);
2613 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2614 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2624 switch (quantum_info->depth)
2632 if (quantum_info->pack == MagickFalse)
2645 for (x=0; x < (long) number_pixels; x+=2)
2647 for (i=0; i < 4; i++)
2653 p=PushLongPixel(endian,p,&pixel);
2654 quantum=(unsigned long) (ScaleShortToQuantum(
2655 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2660 quantum=(unsigned long) (ScaleShortToQuantum(
2661 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2666 quantum=(unsigned long) (ScaleShortToQuantum(
2667 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2671 cbcr[i]=(Quantum) (quantum);
2674 p+=quantum_info->pad;
2689 range=GetQuantumRange(image->depth);
2690 for (x=0; x < (long) number_pixels; x++)
2692 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2693 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2694 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2695 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2706 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2711 register PixelPacket
2714 q=GetAuthenticPixelQueue(image);
2715 if (image_view != (CacheView *) NULL)
2716 q=GetCacheViewAuthenticPixelQueue(image_view);
2717 for (x=0; x < (long) number_pixels; x++)
2725 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2727 register PixelPacket
2730 q=GetAuthenticPixelQueue(image);
2731 if (image_view != (CacheView *) NULL)
2732 q=GetCacheViewAuthenticPixelQueue(image_view);
2733 for (x=0; x < (long) number_pixels; x++)
2735 q->opacity=(Quantum) GetAlphaPixelComponent(q);
2739 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2744 register PixelPacket
2750 q=GetAuthenticPixelQueue(image);
2751 if (image_view != (CacheView *) NULL)
2752 q=GetCacheViewAuthenticPixelQueue(image_view);
2753 for (x=0; x < (long) number_pixels; x++)
2755 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2756 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2757 q->red=ClampToQuantum(alpha*q->red);
2758 q->green=ClampToQuantum(alpha*q->green);
2759 q->blue=ClampToQuantum(alpha*q->blue);