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 for (x=0; x < (long) number_pixels; x++)
411 p=PushShortPixel(endian,p,&pixel);
412 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
413 *q=image->colormap[(long) indexes[x]];
414 p+=quantum_info->pad;
424 if (quantum_info->format == FloatingPointQuantumFormat)
429 for (x=0; x < (long) number_pixels; x++)
431 p=PushFloatPixel(&quantum_state,p,&pixel);
432 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
434 *q=image->colormap[(long) indexes[x]];
435 p+=quantum_info->pad;
440 for (x=0; x < (long) number_pixels; x++)
442 p=PushLongPixel(endian,p,&pixel);
443 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
444 *q=image->colormap[(long) indexes[x]];
445 p+=quantum_info->pad;
452 if (quantum_info->format == FloatingPointQuantumFormat)
457 for (x=0; x < (long) number_pixels; x++)
459 p=PushDoublePixel(&quantum_state,p,&pixel);
460 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
462 *q=image->colormap[(long) indexes[x]];
463 p+=quantum_info->pad;
471 for (x=0; x < (long) number_pixels; x++)
473 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
474 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
475 *q=image->colormap[(long) indexes[x]];
476 p+=quantum_info->pad;
482 if (range_exception != MagickFalse)
483 (void) ThrowMagickException(exception,GetMagickModule(),
484 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
487 case IndexAlphaQuantum:
492 if (image->storage_class != PseudoClass)
494 (void) ThrowMagickException(exception,GetMagickModule(),
495 ImageError,"ColormappedImageRequired","`%s'",image->filename);
498 range_exception=MagickFalse;
499 switch (quantum_info->depth)
503 register unsigned char
506 for (x=0; x < ((long) number_pixels-3); x+=4)
508 for (bit=0; bit < 8; bit+=2)
510 if (quantum_info->min_is_white == MagickFalse)
511 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
514 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
516 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
517 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
520 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
521 == 0 ? TransparentOpacity : OpaqueOpacity);
525 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
527 if (quantum_info->min_is_white == MagickFalse)
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
531 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
533 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
534 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
537 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
538 0 ? TransparentOpacity : OpaqueOpacity);
545 register unsigned char
548 range=GetQuantumRange(image->depth);
549 for (x=0; x < (long) number_pixels; x++)
551 pixel=(unsigned char) ((*p >> 4) & 0xf);
552 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
553 *q=image->colormap[(long) indexes[x]];
554 pixel=(unsigned char) ((*p) & 0xf);
555 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
566 for (x=0; x < (long) number_pixels; x++)
568 p=PushCharPixel(p,&pixel);
569 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
570 *q=image->colormap[(long) indexes[x]];
571 p=PushCharPixel(p,&pixel);
572 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
573 p+=quantum_info->pad;
583 for (x=0; x < (long) number_pixels; x++)
585 p=PushShortPixel(endian,p,&pixel);
586 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
587 *q=image->colormap[(long) indexes[x]];
588 p=PushShortPixel(endian,p,&pixel);
589 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
590 p+=quantum_info->pad;
600 if (quantum_info->format == FloatingPointQuantumFormat)
605 for (x=0; x < (long) number_pixels; x++)
607 p=PushFloatPixel(&quantum_state,p,&pixel);
608 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
610 *q=image->colormap[(long) indexes[x]];
611 p=PushFloatPixel(&quantum_state,p,&pixel);
612 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
613 p+=quantum_info->pad;
618 for (x=0; x < (long) number_pixels; x++)
620 p=PushLongPixel(endian,p,&pixel);
621 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
622 *q=image->colormap[(long) indexes[x]];
623 p=PushLongPixel(endian,p,&pixel);
624 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
625 p+=quantum_info->pad;
632 if (quantum_info->format == FloatingPointQuantumFormat)
637 for (x=0; x < (long) number_pixels; x++)
639 p=PushDoublePixel(&quantum_state,p,&pixel);
640 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
642 *q=image->colormap[(long) indexes[x]];
643 p=PushDoublePixel(&quantum_state,p,&pixel);
644 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
645 p+=quantum_info->pad;
653 range=GetQuantumRange(image->depth);
654 for (x=0; x < (long) number_pixels; x++)
656 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
657 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
658 *q=image->colormap[(long) indexes[x]];
659 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
660 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
661 p+=quantum_info->pad;
667 if (range_exception != MagickFalse)
668 (void) ThrowMagickException(exception,GetMagickModule(),
669 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
674 switch (quantum_info->depth)
683 white=(Quantum) QuantumRange;
684 if (quantum_info->min_is_white != MagickFalse)
686 black=(Quantum) QuantumRange;
689 for (x=0; x < ((long) number_pixels-7); x+=8)
691 for (bit=0; bit < 8; bit++)
693 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
700 for (bit=0; bit < (long) (number_pixels % 8); bit++)
702 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
713 register unsigned char
716 range=GetQuantumRange(image->depth);
717 for (x=0; x < ((long) number_pixels-1); x+=2)
719 pixel=(unsigned char) ((*p >> 4) & 0xf);
720 q->red=ScaleAnyToQuantum(pixel,range);
724 pixel=(unsigned char) ((*p) & 0xf);
725 q->red=ScaleAnyToQuantum(pixel,range);
731 for (bit=0; bit < (long) (number_pixels % 2); bit++)
733 pixel=(unsigned char) (*p++ >> 4);
734 q->red=ScaleAnyToQuantum(pixel,range);
746 if (quantum_info->min_is_white != MagickFalse)
748 for (x=0; x < (long) number_pixels; x++)
750 p=PushCharPixel(p,&pixel);
751 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
754 q->opacity=OpaqueOpacity;
755 p+=quantum_info->pad;
760 for (x=0; x < (long) number_pixels; x++)
762 p=PushCharPixel(p,&pixel);
763 q->red=ScaleCharToQuantum(pixel);
766 q->opacity=OpaqueOpacity;
767 p+=quantum_info->pad;
774 range=GetQuantumRange(image->depth);
775 if (quantum_info->pack == MagickFalse)
777 if (image->endian != LSBEndian)
779 for (x=0; x < (long) number_pixels/3; x++)
781 p=PushLongPixel(endian,p,&pixel);
782 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
786 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
790 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
793 p+=quantum_info->pad;
798 for (x=0; x < (long) number_pixels/3; x++)
800 p=PushLongPixel(endian,p,&pixel);
801 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
805 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
809 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
812 p+=quantum_info->pad;
817 for (x=0; x < (long) number_pixels; x++)
819 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
820 q->red=ScaleAnyToQuantum(pixel,range);
823 p+=quantum_info->pad;
830 range=GetQuantumRange(image->depth);
831 if (quantum_info->pack == MagickFalse)
836 for (x=0; x < (long) (number_pixels-1); x+=2)
838 p=PushShortPixel(endian,p,&pixel);
839 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
843 p=PushShortPixel(endian,p,&pixel);
844 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
847 p+=quantum_info->pad;
850 for (bit=0; bit < (long) (number_pixels % 2); bit++)
852 p=PushShortPixel(endian,p,&pixel);
853 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
856 p+=quantum_info->pad;
863 for (x=0; x < (long) number_pixels; x++)
865 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
866 q->red=ScaleAnyToQuantum(pixel,range);
869 p+=quantum_info->pad;
879 if (quantum_info->min_is_white != MagickFalse)
881 for (x=0; x < (long) number_pixels; x++)
883 p=PushShortPixel(endian,p,&pixel);
884 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
887 p+=quantum_info->pad;
892 for (x=0; x < (long) number_pixels; x++)
894 p=PushShortPixel(endian,p,&pixel);
895 q->red=ScaleShortToQuantum(pixel);
898 p+=quantum_info->pad;
908 if (quantum_info->format == FloatingPointQuantumFormat)
913 for (x=0; x < (long) number_pixels; x++)
915 p=PushFloatPixel(&quantum_state,p,&pixel);
916 q->red=RoundToQuantum(pixel);
919 p+=quantum_info->pad;
924 for (x=0; x < (long) number_pixels; x++)
926 p=PushLongPixel(endian,p,&pixel);
927 q->red=ScaleLongToQuantum(pixel);
930 p+=quantum_info->pad;
937 if (quantum_info->format == FloatingPointQuantumFormat)
942 for (x=0; x < (long) number_pixels; x++)
944 p=PushDoublePixel(&quantum_state,p,&pixel);
945 q->red=RoundToQuantum(pixel);
948 p+=quantum_info->pad;
956 range=GetQuantumRange(image->depth);
957 for (x=0; x < (long) number_pixels; x++)
959 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
960 q->red=ScaleAnyToQuantum(pixel,range);
963 p+=quantum_info->pad;
971 case GrayAlphaQuantum:
973 switch (quantum_info->depth)
977 register unsigned char
980 for (x=0; x < ((long) number_pixels-3); x+=4)
982 for (bit=0; bit < 8; bit+=2)
984 pixel=(unsigned char)
985 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
986 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
989 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
990 == 0 ? TransparentOpacity : OpaqueOpacity);
995 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
997 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
998 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1001 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1002 ? TransparentOpacity : OpaqueOpacity);
1011 register unsigned char
1014 range=GetQuantumRange(image->depth);
1015 for (x=0; x < (long) number_pixels; x++)
1017 pixel=(unsigned char) ((*p >> 4) & 0xf);
1018 q->red=ScaleAnyToQuantum(pixel,range);
1021 pixel=(unsigned char) ((*p) & 0xf);
1022 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1033 for (x=0; x < (long) number_pixels; x++)
1035 p=PushCharPixel(p,&pixel);
1036 q->red=ScaleCharToQuantum(pixel);
1039 p=PushCharPixel(p,&pixel);
1040 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1041 p+=quantum_info->pad;
1048 range=GetQuantumRange(image->depth);
1049 for (x=0; x < (long) number_pixels; x++)
1051 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1052 q->red=ScaleAnyToQuantum(pixel,range);
1055 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1056 q->opacity=ScaleAnyToQuantum(pixel,range);
1057 p+=quantum_info->pad;
1064 range=GetQuantumRange(image->depth);
1065 for (x=0; x < (long) number_pixels; x++)
1067 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1068 q->red=ScaleAnyToQuantum(pixel,range);
1071 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1072 q->opacity=ScaleAnyToQuantum(pixel,range);
1073 p+=quantum_info->pad;
1083 for (x=0; x < (long) number_pixels; x++)
1085 p=PushShortPixel(endian,p,&pixel);
1086 q->red=ScaleShortToQuantum(pixel);
1089 p=PushShortPixel(endian,p,&pixel);
1090 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1091 p+=quantum_info->pad;
1101 if (quantum_info->format == FloatingPointQuantumFormat)
1106 for (x=0; x < (long) number_pixels; x++)
1108 p=PushFloatPixel(&quantum_state,p,&pixel);
1109 q->red=RoundToQuantum(pixel);
1112 p=PushFloatPixel(&quantum_state,p,&pixel);
1113 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1114 p+=quantum_info->pad;
1119 for (x=0; x < (long) number_pixels; x++)
1121 p=PushLongPixel(endian,p,&pixel);
1122 q->red=ScaleLongToQuantum(pixel);
1125 p=PushLongPixel(endian,p,&pixel);
1126 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1127 p+=quantum_info->pad;
1134 if (quantum_info->format == FloatingPointQuantumFormat)
1139 for (x=0; x < (long) number_pixels; x++)
1141 p=PushDoublePixel(&quantum_state,p,&pixel);
1142 q->red=RoundToQuantum(pixel);
1145 p=PushDoublePixel(&quantum_state,p,&pixel);
1146 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1147 p+=quantum_info->pad;
1155 range=GetQuantumRange(image->depth);
1156 for (x=0; x < (long) number_pixels; x++)
1158 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1159 q->red=ScaleAnyToQuantum(pixel,range);
1162 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1163 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1164 p+=quantum_info->pad;
1175 switch (quantum_info->depth)
1182 for (x=0; x < (long) number_pixels; x++)
1184 p=PushCharPixel(p,&pixel);
1185 q->red=ScaleCharToQuantum(pixel);
1186 p+=quantum_info->pad;
1196 for (x=0; x < (long) number_pixels; x++)
1198 p=PushShortPixel(endian,p,&pixel);
1199 q->red=ScaleShortToQuantum(pixel);
1200 p+=quantum_info->pad;
1210 if (quantum_info->format == FloatingPointQuantumFormat)
1215 for (x=0; x < (long) number_pixels; x++)
1217 p=PushFloatPixel(&quantum_state,p,&pixel);
1218 q->red=RoundToQuantum(pixel);
1219 p+=quantum_info->pad;
1224 for (x=0; x < (long) number_pixels; x++)
1226 p=PushLongPixel(endian,p,&pixel);
1227 q->red=ScaleLongToQuantum(pixel);
1228 p+=quantum_info->pad;
1235 if (quantum_info->format == FloatingPointQuantumFormat)
1240 for (x=0; x < (long) number_pixels; x++)
1242 p=PushDoublePixel(&quantum_state,p,&pixel);
1243 q->red=RoundToQuantum(pixel);
1244 p+=quantum_info->pad;
1252 range=GetQuantumRange(image->depth);
1253 for (x=0; x < (long) number_pixels; x++)
1255 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1256 q->red=ScaleAnyToQuantum(pixel,range);
1257 p+=quantum_info->pad;
1266 case MagentaQuantum:
1268 switch (quantum_info->depth)
1275 for (x=0; x < (long) number_pixels; x++)
1277 p=PushCharPixel(p,&pixel);
1278 q->green=ScaleCharToQuantum(pixel);
1279 p+=quantum_info->pad;
1289 for (x=0; x < (long) number_pixels; x++)
1291 p=PushShortPixel(endian,p,&pixel);
1292 q->green=ScaleShortToQuantum(pixel);
1293 p+=quantum_info->pad;
1303 if (quantum_info->format == FloatingPointQuantumFormat)
1308 for (x=0; x < (long) number_pixels; x++)
1310 p=PushFloatPixel(&quantum_state,p,&pixel);
1311 q->green=RoundToQuantum(pixel);
1312 p+=quantum_info->pad;
1317 for (x=0; x < (long) number_pixels; x++)
1319 p=PushLongPixel(endian,p,&pixel);
1320 q->green=ScaleLongToQuantum(pixel);
1321 p+=quantum_info->pad;
1328 if (quantum_info->format == FloatingPointQuantumFormat)
1333 for (x=0; x < (long) number_pixels; x++)
1335 p=PushDoublePixel(&quantum_state,p,&pixel);
1336 q->green=RoundToQuantum(pixel);
1337 p+=quantum_info->pad;
1345 range=GetQuantumRange(image->depth);
1346 for (x=0; x < (long) number_pixels; x++)
1348 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1349 q->green=ScaleAnyToQuantum(pixel,range);
1350 p+=quantum_info->pad;
1361 switch (quantum_info->depth)
1368 for (x=0; x < (long) number_pixels; x++)
1370 p=PushCharPixel(p,&pixel);
1371 q->blue=ScaleCharToQuantum(pixel);
1372 p+=quantum_info->pad;
1382 for (x=0; x < (long) number_pixels; x++)
1384 p=PushShortPixel(endian,p,&pixel);
1385 q->blue=ScaleShortToQuantum(pixel);
1386 p+=quantum_info->pad;
1396 if (quantum_info->format == FloatingPointQuantumFormat)
1401 for (x=0; x < (long) number_pixels; x++)
1403 p=PushFloatPixel(&quantum_state,p,&pixel);
1404 q->blue=RoundToQuantum(pixel);
1405 p+=quantum_info->pad;
1410 for (x=0; x < (long) number_pixels; x++)
1412 p=PushLongPixel(endian,p,&pixel);
1413 q->blue=ScaleLongToQuantum(pixel);
1414 p+=quantum_info->pad;
1421 if (quantum_info->format == FloatingPointQuantumFormat)
1426 for (x=0; x < (long) number_pixels; x++)
1428 p=PushDoublePixel(&quantum_state,p,&pixel);
1429 q->blue=RoundToQuantum(pixel);
1430 p+=quantum_info->pad;
1438 range=GetQuantumRange(image->depth);
1439 for (x=0; x < (long) number_pixels; x++)
1441 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1442 q->blue=ScaleAnyToQuantum(pixel,range);
1443 p+=quantum_info->pad;
1453 switch (quantum_info->depth)
1460 for (x=0; x < (long) number_pixels; x++)
1462 p=PushCharPixel(p,&pixel);
1463 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1464 p+=quantum_info->pad;
1474 for (x=0; x < (long) number_pixels; x++)
1476 p=PushShortPixel(endian,p,&pixel);
1477 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1478 p+=quantum_info->pad;
1488 if (quantum_info->format == FloatingPointQuantumFormat)
1493 for (x=0; x < (long) number_pixels; x++)
1495 p=PushFloatPixel(&quantum_state,p,&pixel);
1496 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1497 p+=quantum_info->pad;
1502 for (x=0; x < (long) number_pixels; x++)
1504 p=PushLongPixel(endian,p,&pixel);
1505 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1506 p+=quantum_info->pad;
1513 if (quantum_info->format == FloatingPointQuantumFormat)
1518 for (x=0; x < (long) number_pixels; x++)
1520 p=PushDoublePixel(&quantum_state,p,&pixel);
1521 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1522 p+=quantum_info->pad;
1530 range=GetQuantumRange(image->depth);
1531 for (x=0; x < (long) number_pixels; x++)
1533 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1534 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1535 p+=quantum_info->pad;
1545 if (image->colorspace != CMYKColorspace)
1547 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1548 "ColorSeparatedImageRequired","`%s'",image->filename);
1551 switch (quantum_info->depth)
1558 for (x=0; x < (long) number_pixels; x++)
1560 p=PushCharPixel(p,&pixel);
1561 indexes[x]=ScaleCharToQuantum(pixel);
1562 p+=quantum_info->pad;
1571 for (x=0; x < (long) number_pixels; x++)
1573 p=PushShortPixel(endian,p,&pixel);
1574 indexes[x]=ScaleShortToQuantum(pixel);
1575 p+=quantum_info->pad;
1584 if (quantum_info->format == FloatingPointQuantumFormat)
1589 for (x=0; x < (long) number_pixels; x++)
1591 p=PushFloatPixel(&quantum_state,p,&pixel);
1592 indexes[x]=RoundToQuantum(pixel);
1593 p+=quantum_info->pad;
1598 for (x=0; x < (long) number_pixels; x++)
1600 p=PushLongPixel(endian,p,&pixel);
1601 indexes[x]=ScaleLongToQuantum(pixel);
1602 p+=quantum_info->pad;
1609 if (quantum_info->format == FloatingPointQuantumFormat)
1614 for (x=0; x < (long) number_pixels; x++)
1616 p=PushDoublePixel(&quantum_state,p,&pixel);
1617 indexes[x]=RoundToQuantum(pixel);
1618 p+=quantum_info->pad;
1626 range=GetQuantumRange(image->depth);
1627 for (x=0; x < (long) number_pixels; x++)
1629 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1630 indexes[x]=ScaleAnyToQuantum(pixel,range);
1631 p+=quantum_info->pad;
1642 switch (quantum_info->depth)
1649 for (x=0; x < (long) number_pixels; x++)
1651 p=PushCharPixel(p,&pixel);
1652 q->red=ScaleCharToQuantum(pixel);
1653 p=PushCharPixel(p,&pixel);
1654 q->green=ScaleCharToQuantum(pixel);
1655 p=PushCharPixel(p,&pixel);
1656 q->blue=ScaleCharToQuantum(pixel);
1657 q->opacity=OpaqueOpacity;
1658 p+=quantum_info->pad;
1665 range=GetQuantumRange(image->depth);
1666 if (quantum_info->pack == MagickFalse)
1668 for (x=0; x < (long) number_pixels; x++)
1670 p=PushLongPixel(endian,p,&pixel);
1671 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1672 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1673 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1674 p+=quantum_info->pad;
1679 if (quantum_info->quantum == 32UL)
1681 for (x=0; x < (long) number_pixels; x++)
1683 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1684 q->red=ScaleAnyToQuantum(pixel,range);
1685 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1686 q->green=ScaleAnyToQuantum(pixel,range);
1687 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1688 q->blue=ScaleAnyToQuantum(pixel,range);
1693 for (x=0; x < (long) number_pixels; x++)
1695 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1696 q->red=ScaleAnyToQuantum(pixel,range);
1697 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1698 q->green=ScaleAnyToQuantum(pixel,range);
1699 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1700 q->blue=ScaleAnyToQuantum(pixel,range);
1707 range=GetQuantumRange(image->depth);
1708 if (quantum_info->pack == MagickFalse)
1713 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1715 p=PushShortPixel(endian,p,&pixel);
1721 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1726 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1731 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1736 p=PushShortPixel(endian,p,&pixel);
1742 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1747 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1752 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1757 p+=quantum_info->pad;
1759 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1761 p=PushShortPixel(endian,p,&pixel);
1762 switch ((x+bit) % 3)
1767 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1772 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1777 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1782 p+=quantum_info->pad;
1788 if (quantum_info->quantum == 32UL)
1790 for (x=0; x < (long) number_pixels; x++)
1792 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1793 q->red=ScaleAnyToQuantum(pixel,range);
1794 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1795 q->green=ScaleAnyToQuantum(pixel,range);
1796 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1797 q->blue=ScaleAnyToQuantum(pixel,range);
1802 for (x=0; x < (long) number_pixels; x++)
1804 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1805 q->red=ScaleAnyToQuantum(pixel,range);
1806 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1807 q->green=ScaleAnyToQuantum(pixel,range);
1808 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1809 q->blue=ScaleAnyToQuantum(pixel,range);
1819 for (x=0; x < (long) number_pixels; x++)
1821 p=PushShortPixel(endian,p,&pixel);
1822 q->red=ScaleShortToQuantum(pixel);
1823 p=PushShortPixel(endian,p,&pixel);
1824 q->green=ScaleShortToQuantum(pixel);
1825 p=PushShortPixel(endian,p,&pixel);
1826 q->blue=ScaleShortToQuantum(pixel);
1827 p+=quantum_info->pad;
1837 if (quantum_info->format == FloatingPointQuantumFormat)
1842 for (x=0; x < (long) number_pixels; x++)
1844 p=PushFloatPixel(&quantum_state,p,&pixel);
1845 q->red=RoundToQuantum(pixel);
1846 p=PushFloatPixel(&quantum_state,p,&pixel);
1847 q->green=RoundToQuantum(pixel);
1848 p=PushFloatPixel(&quantum_state,p,&pixel);
1849 q->blue=RoundToQuantum(pixel);
1850 p+=quantum_info->pad;
1855 for (x=0; x < (long) number_pixels; x++)
1857 p=PushLongPixel(endian,p,&pixel);
1858 q->red=ScaleLongToQuantum(pixel);
1859 p=PushLongPixel(endian,p,&pixel);
1860 q->green=ScaleLongToQuantum(pixel);
1861 p=PushLongPixel(endian,p,&pixel);
1862 q->blue=ScaleLongToQuantum(pixel);
1863 p+=quantum_info->pad;
1870 if (quantum_info->format == FloatingPointQuantumFormat)
1875 for (x=0; x < (long) number_pixels; x++)
1877 p=PushDoublePixel(&quantum_state,p,&pixel);
1878 q->red=RoundToQuantum(pixel);
1879 p=PushDoublePixel(&quantum_state,p,&pixel);
1880 q->green=RoundToQuantum(pixel);
1881 p=PushDoublePixel(&quantum_state,p,&pixel);
1882 q->blue=RoundToQuantum(pixel);
1883 p+=quantum_info->pad;
1891 range=GetQuantumRange(image->depth);
1892 for (x=0; x < (long) number_pixels; x++)
1894 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1895 q->red=ScaleAnyToQuantum(pixel,range);
1896 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1897 q->green=ScaleAnyToQuantum(pixel,range);
1898 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1899 q->blue=ScaleAnyToQuantum(pixel,range);
1911 switch (quantum_info->depth)
1918 for (x=0; x < (long) number_pixels; x++)
1920 p=PushCharPixel(p,&pixel);
1921 q->red=ScaleCharToQuantum(pixel);
1922 p=PushCharPixel(p,&pixel);
1923 q->green=ScaleCharToQuantum(pixel);
1924 p=PushCharPixel(p,&pixel);
1925 q->blue=ScaleCharToQuantum(pixel);
1926 p=PushCharPixel(p,&pixel);
1927 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1928 p+=quantum_info->pad;
1936 if (quantum_info->pack == MagickFalse)
1949 for (x=0; x < (long) number_pixels; x++)
1951 for (i=0; i < 4; i++)
1957 p=PushLongPixel(endian,p,&pixel);
1958 quantum=(unsigned long) (ScaleShortToQuantum(
1959 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
1964 quantum=(unsigned long) (ScaleShortToQuantum(
1965 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
1970 quantum=(unsigned long) (ScaleShortToQuantum(
1971 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
1977 case 0: q->red=(Quantum) (quantum); break;
1978 case 1: q->green=(Quantum) (quantum); break;
1979 case 2: q->blue=(Quantum) (quantum); break;
1980 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
1984 p+=quantum_info->pad;
1989 for (x=0; x < (long) number_pixels; x++)
1991 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1992 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
1993 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1994 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
1995 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1996 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
1997 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1998 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
1999 (unsigned short) (pixel << 6)));
2009 for (x=0; x < (long) number_pixels; x++)
2011 p=PushShortPixel(endian,p,&pixel);
2012 q->red=ScaleShortToQuantum(pixel);
2013 p=PushShortPixel(endian,p,&pixel);
2014 q->green=ScaleShortToQuantum(pixel);
2015 p=PushShortPixel(endian,p,&pixel);
2016 q->blue=ScaleShortToQuantum(pixel);
2017 p=PushShortPixel(endian,p,&pixel);
2018 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2019 p+=quantum_info->pad;
2029 if (quantum_info->format == FloatingPointQuantumFormat)
2034 for (x=0; x < (long) number_pixels; x++)
2036 p=PushFloatPixel(&quantum_state,p,&pixel);
2037 q->red=RoundToQuantum(pixel);
2038 p=PushFloatPixel(&quantum_state,p,&pixel);
2039 q->green=RoundToQuantum(pixel);
2040 p=PushFloatPixel(&quantum_state,p,&pixel);
2041 q->blue=RoundToQuantum(pixel);
2042 p=PushFloatPixel(&quantum_state,p,&pixel);
2043 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2044 p+=quantum_info->pad;
2049 for (x=0; x < (long) number_pixels; x++)
2051 p=PushLongPixel(endian,p,&pixel);
2052 q->red=ScaleLongToQuantum(pixel);
2053 p=PushLongPixel(endian,p,&pixel);
2054 q->green=ScaleLongToQuantum(pixel);
2055 p=PushLongPixel(endian,p,&pixel);
2056 q->blue=ScaleLongToQuantum(pixel);
2057 p=PushLongPixel(endian,p,&pixel);
2058 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2059 p+=quantum_info->pad;
2066 if (quantum_info->format == FloatingPointQuantumFormat)
2071 for (x=0; x < (long) number_pixels; x++)
2073 p=PushDoublePixel(&quantum_state,p,&pixel);
2074 q->red=RoundToQuantum(pixel);
2075 p=PushDoublePixel(&quantum_state,p,&pixel);
2076 q->green=RoundToQuantum(pixel);
2077 p=PushDoublePixel(&quantum_state,p,&pixel);
2078 q->blue=RoundToQuantum(pixel);
2079 p=PushDoublePixel(&quantum_state,p,&pixel);
2080 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2081 p+=quantum_info->pad;
2089 range=GetQuantumRange(image->depth);
2090 for (x=0; x < (long) number_pixels; x++)
2092 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2093 q->red=ScaleAnyToQuantum(pixel,range);
2094 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2095 q->green=ScaleAnyToQuantum(pixel,range);
2096 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2097 q->blue=ScaleAnyToQuantum(pixel,range);
2098 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2099 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2109 if (image->colorspace != CMYKColorspace)
2111 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2112 "ColorSeparatedImageRequired","`%s'",image->filename);
2115 switch (quantum_info->depth)
2122 for (x=0; x < (long) number_pixels; x++)
2124 p=PushCharPixel(p,&pixel);
2125 q->red=ScaleCharToQuantum(pixel);
2126 p=PushCharPixel(p,&pixel);
2127 q->green=ScaleCharToQuantum(pixel);
2128 p=PushCharPixel(p,&pixel);
2129 q->blue=ScaleCharToQuantum(pixel);
2130 p=PushCharPixel(p,&pixel);
2131 indexes[x]=ScaleCharToQuantum(pixel);
2132 p+=quantum_info->pad;
2142 for (x=0; x < (long) number_pixels; x++)
2144 p=PushShortPixel(endian,p,&pixel);
2145 q->red=ScaleShortToQuantum(pixel);
2146 p=PushShortPixel(endian,p,&pixel);
2147 q->green=ScaleShortToQuantum(pixel);
2148 p=PushShortPixel(endian,p,&pixel);
2149 q->blue=ScaleShortToQuantum(pixel);
2150 p=PushShortPixel(endian,p,&pixel);
2151 indexes[x]=ScaleShortToQuantum(pixel);
2152 p+=quantum_info->pad;
2162 if (quantum_info->format == FloatingPointQuantumFormat)
2167 for (x=0; x < (long) number_pixels; x++)
2169 p=PushFloatPixel(&quantum_state,p,&pixel);
2170 q->red=RoundToQuantum(pixel);
2171 p=PushFloatPixel(&quantum_state,p,&pixel);
2172 q->green=RoundToQuantum(pixel);
2173 p=PushFloatPixel(&quantum_state,p,&pixel);
2174 q->blue=RoundToQuantum(pixel);
2175 p=PushFloatPixel(&quantum_state,p,&pixel);
2176 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2177 p+=quantum_info->pad;
2182 for (x=0; x < (long) number_pixels; x++)
2184 p=PushLongPixel(endian,p,&pixel);
2185 q->red=ScaleLongToQuantum(pixel);
2186 p=PushLongPixel(endian,p,&pixel);
2187 q->green=ScaleLongToQuantum(pixel);
2188 p=PushLongPixel(endian,p,&pixel);
2189 q->blue=ScaleLongToQuantum(pixel);
2190 p=PushLongPixel(endian,p,&pixel);
2191 indexes[x]=ScaleLongToQuantum(pixel);
2192 p+=quantum_info->pad;
2199 if (quantum_info->format == FloatingPointQuantumFormat)
2204 for (x=0; x < (long) number_pixels; x++)
2206 p=PushDoublePixel(&quantum_state,p,&pixel);
2207 q->red=RoundToQuantum(pixel);
2208 p=PushDoublePixel(&quantum_state,p,&pixel);
2209 q->green=RoundToQuantum(pixel);
2210 p=PushDoublePixel(&quantum_state,p,&pixel);
2211 q->blue=RoundToQuantum(pixel);
2212 p=PushDoublePixel(&quantum_state,p,&pixel);
2213 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2214 p+=quantum_info->pad;
2222 range=GetQuantumRange(image->depth);
2223 for (x=0; x < (long) number_pixels; x++)
2225 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2226 q->red=ScaleAnyToQuantum(pixel,range);
2227 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2228 q->green=ScaleAnyToQuantum(pixel,range);
2229 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2230 q->blue=ScaleAnyToQuantum(pixel,range);
2231 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2232 indexes[x]=ScaleAnyToQuantum(pixel,range);
2243 if (image->colorspace != CMYKColorspace)
2245 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2246 "ColorSeparatedImageRequired","`%s'",image->filename);
2249 switch (quantum_info->depth)
2256 for (x=0; x < (long) number_pixels; x++)
2258 p=PushCharPixel(p,&pixel);
2259 q->red=ScaleCharToQuantum(pixel);
2260 p=PushCharPixel(p,&pixel);
2261 q->green=ScaleCharToQuantum(pixel);
2262 p=PushCharPixel(p,&pixel);
2263 q->blue=ScaleCharToQuantum(pixel);
2264 p=PushCharPixel(p,&pixel);
2265 indexes[x]=ScaleCharToQuantum(pixel);
2266 p=PushCharPixel(p,&pixel);
2267 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2268 p+=quantum_info->pad;
2278 for (x=0; x < (long) number_pixels; x++)
2280 p=PushShortPixel(endian,p,&pixel);
2281 q->red=ScaleShortToQuantum(pixel);
2282 p=PushShortPixel(endian,p,&pixel);
2283 q->green=ScaleShortToQuantum(pixel);
2284 p=PushShortPixel(endian,p,&pixel);
2285 q->blue=ScaleShortToQuantum(pixel);
2286 p=PushShortPixel(endian,p,&pixel);
2287 indexes[x]=ScaleShortToQuantum(pixel);
2288 p=PushShortPixel(endian,p,&pixel);
2289 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2290 p+=quantum_info->pad;
2300 if (quantum_info->format == FloatingPointQuantumFormat)
2305 for (x=0; x < (long) number_pixels; x++)
2307 p=PushFloatPixel(&quantum_state,p,&pixel);
2308 q->red=RoundToQuantum(pixel);
2309 p=PushFloatPixel(&quantum_state,p,&pixel);
2310 q->green=RoundToQuantum(pixel);
2311 p=PushFloatPixel(&quantum_state,p,&pixel);
2312 q->blue=RoundToQuantum(pixel);
2313 p=PushFloatPixel(&quantum_state,p,&pixel);
2314 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2315 p=PushFloatPixel(&quantum_state,p,&pixel);
2316 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2317 p+=quantum_info->pad;
2322 for (x=0; x < (long) number_pixels; x++)
2324 p=PushLongPixel(endian,p,&pixel);
2325 q->red=ScaleLongToQuantum(pixel);
2326 p=PushLongPixel(endian,p,&pixel);
2327 q->green=ScaleLongToQuantum(pixel);
2328 p=PushLongPixel(endian,p,&pixel);
2329 q->blue=ScaleLongToQuantum(pixel);
2330 p=PushLongPixel(endian,p,&pixel);
2331 indexes[x]=ScaleLongToQuantum(pixel);
2332 p=PushLongPixel(endian,p,&pixel);
2333 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2334 p+=quantum_info->pad;
2341 if (quantum_info->format == FloatingPointQuantumFormat)
2346 for (x=0; x < (long) number_pixels; x++)
2348 p=PushDoublePixel(&quantum_state,p,&pixel);
2349 q->red=RoundToQuantum(pixel);
2350 p=PushDoublePixel(&quantum_state,p,&pixel);
2351 q->green=RoundToQuantum(pixel);
2352 p=PushDoublePixel(&quantum_state,p,&pixel);
2353 q->blue=RoundToQuantum(pixel);
2354 p=PushDoublePixel(&quantum_state,p,&pixel);
2355 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2356 p=PushDoublePixel(&quantum_state,p,&pixel);
2357 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2358 p=PushDoublePixel(&quantum_state,p,&pixel);
2359 p+=quantum_info->pad;
2367 range=GetQuantumRange(image->depth);
2368 for (x=0; x < (long) number_pixels; x++)
2370 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2371 q->red=ScaleAnyToQuantum(pixel,range);
2372 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2373 q->green=ScaleAnyToQuantum(pixel,range);
2374 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2375 q->blue=ScaleAnyToQuantum(pixel,range);
2376 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2377 indexes[x]=ScaleAnyToQuantum(pixel,range);
2378 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2379 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2389 switch (quantum_info->depth)
2397 if (quantum_info->pack == MagickFalse)
2410 for (x=0; x < (long) number_pixels; x+=2)
2412 for (i=0; i < 4; i++)
2418 p=PushLongPixel(endian,p,&pixel);
2419 quantum=(unsigned long) (ScaleShortToQuantum(
2420 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2425 quantum=(unsigned long) (ScaleShortToQuantum(
2426 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2431 quantum=(unsigned long) (ScaleShortToQuantum(
2432 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2436 cbcr[i]=(Quantum) (quantum);
2439 p+=quantum_info->pad;
2454 range=GetQuantumRange(image->depth);
2455 for (x=0; x < (long) number_pixels; x++)
2457 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2458 q->red=ScaleAnyToQuantum(pixel,range);
2459 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2460 q->green=ScaleAnyToQuantum(pixel,range);
2471 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2476 register PixelPacket
2479 q=GetAuthenticPixelQueue(image);
2480 if (image_view != (CacheView *) NULL)
2481 q=GetCacheViewAuthenticPixelQueue(image_view);
2482 for (x=0; x < (long) number_pixels; x++)
2490 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2492 register PixelPacket
2495 q=GetAuthenticPixelQueue(image);
2496 if (image_view != (CacheView *) NULL)
2497 q=GetCacheViewAuthenticPixelQueue(image_view);
2498 for (x=0; x < (long) number_pixels; x++)
2500 q->opacity=(Quantum) (QuantumRange-q->opacity);
2504 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2509 register PixelPacket
2515 q=GetAuthenticPixelQueue(image);
2516 if (image_view != (CacheView *) NULL)
2517 q=GetCacheViewAuthenticPixelQueue(image_view);
2518 for (x=0; x < (long) number_pixels; x++)
2520 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2521 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2522 q->red=RoundToQuantum(alpha*q->red);
2523 q->green=RoundToQuantum(alpha*q->green);
2524 q->blue=RoundToQuantum(alpha*q->blue);