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 % EEEEE X X PPPP OOO RRRR TTTTT %
13 % E X X P P O O R R T %
14 % EEE X PPPP O O RRRR T %
16 % EEEEE X X P OOO R R T %
18 % MagickCore Methods to Export 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 + E x p o r t Q u a n t u m P i x e l s %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % ExportQuantumPixels() transfers one or more pixel components from the image
86 % pixel cache to a user supplied buffer. The pixels are returned in network
87 % byte order. MagickTrue is returned if the pixels are successfully
88 % transferred, otherwise MagickFalse.
90 % The format of the ExportQuantumPixels method is:
92 % size_t ExportQuantumPixels(const Image *image,
93 % const CacheView *image_view,const QuantumInfo *quantum_info,
94 % const QuantumType quantum_type,unsigned char *pixels,
95 % ExceptionInfo *exception)
97 % A description of each parameter follows:
101 % o image_view: the image cache view.
103 % o quantum_info: the quantum info.
105 % o quantum_type: Declare which pixel components to transfer (RGB, RGBA,
108 % o pixels: The components are transferred to this buffer.
110 % o exception: return any errors or warnings in this structure.
114 static inline unsigned char *PopDoublePixel(const QuantumState *quantum_state,
115 const double pixel,unsigned char *pixels)
123 p=(double *) quantum;
124 *p=(double) (pixel*quantum_state->inverse_scale+quantum_state->minimum);
125 if (quantum_state->endian != LSBEndian)
127 *pixels++=quantum[7];
128 *pixels++=quantum[6];
129 *pixels++=quantum[5];
130 *pixels++=quantum[4];
131 *pixels++=quantum[3];
132 *pixels++=quantum[2];
133 *pixels++=quantum[1];
134 *pixels++=quantum[0];
137 *pixels++=quantum[0];
138 *pixels++=quantum[1];
139 *pixels++=quantum[2];
140 *pixels++=quantum[3];
141 *pixels++=quantum[4];
142 *pixels++=quantum[5];
143 *pixels++=quantum[6];
144 *pixels++=quantum[7];
148 static inline unsigned char *PopFloatPixel(const QuantumState *quantum_state,
149 const float pixel,unsigned char *pixels)
158 *p=(float) ((double) pixel*quantum_state->inverse_scale+
159 quantum_state->minimum);
160 if (quantum_state->endian != LSBEndian)
162 *pixels++=quantum[3];
163 *pixels++=quantum[2];
164 *pixels++=quantum[1];
165 *pixels++=quantum[0];
168 *pixels++=quantum[0];
169 *pixels++=quantum[1];
170 *pixels++=quantum[2];
171 *pixels++=quantum[3];
175 static inline unsigned char *PopQuantumPixel(QuantumState *quantum_state,
176 const unsigned long depth,const QuantumAny pixel,unsigned char *pixels)
181 register unsigned long
184 if (quantum_state->bits == 0UL)
185 quantum_state->bits=8UL;
186 for (i=(long) depth; i > 0L; )
188 quantum_bits=(unsigned long) i;
189 if (quantum_bits > quantum_state->bits)
190 quantum_bits=quantum_state->bits;
192 if (quantum_state->bits == 8)
194 quantum_state->bits-=quantum_bits;
195 *pixels|=(((pixel >> i) &~ ((~0UL) << quantum_bits)) <<
196 quantum_state->bits);
197 if (quantum_state->bits == 0UL)
200 quantum_state->bits=8UL;
206 static inline unsigned char *PopQuantumLongPixel(QuantumState *quantum_state,
207 const unsigned long depth,const unsigned long pixel,unsigned char *pixels)
215 if (quantum_state->bits == 0UL)
216 quantum_state->bits=32UL;
217 for (i=(long) depth; i > 0; )
219 quantum_bits=(unsigned long) i;
220 if (quantum_bits > quantum_state->bits)
221 quantum_bits=quantum_state->bits;
222 quantum_state->pixel|=(((pixel >> (depth-i)) &
223 quantum_state->mask[quantum_bits]) << (32UL-quantum_state->bits));
225 quantum_state->bits-=quantum_bits;
226 if (quantum_state->bits == 0U)
228 pixels=PopLongPixel(quantum_state->endian,quantum_state->pixel,pixels);
229 quantum_state->pixel=0U;
230 quantum_state->bits=32UL;
236 MagickExport size_t ExportQuantumPixels(const Image *image,
237 const CacheView *image_view,const QuantumInfo *quantum_info,
238 const QuantumType quantum_type,unsigned char *pixels,ExceptionInfo *exception)
258 register const IndexPacket
261 register const PixelPacket
267 register unsigned char
273 assert(image != (Image *) NULL);
274 assert(image->signature == MagickSignature);
275 if (image->debug != MagickFalse)
276 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
277 assert(quantum_info != (QuantumInfo *) NULL);
278 assert(quantum_info->signature == MagickSignature);
279 if (pixels == (unsigned char *) NULL)
280 pixels=GetQuantumPixels(quantum_info);
281 if (image_view == (CacheView *) NULL)
283 number_pixels=GetImageExtent(image);
284 p=GetVirtualPixelQueue(image);
285 indexes=GetVirtualIndexQueue(image);
289 number_pixels=GetCacheViewExtent(image_view);
290 p=GetCacheViewVirtualPixelQueue(image_view);
291 indexes=GetCacheViewVirtualIndexQueue(image_view);
293 if (quantum_info->alpha_type == AssociatedQuantumAlpha)
301 q=GetAuthenticPixelQueue(image);
302 if (image_view != (CacheView *) NULL)
303 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
304 for (x=0; x < (long) image->columns; x++)
306 alpha=QuantumScale*((double) QuantumRange-q->opacity);
307 q->red=ClampToQuantum(alpha*q->red);
308 q->green=ClampToQuantum(alpha*q->green);
309 q->blue=ClampToQuantum(alpha*q->blue);
313 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
318 q=GetAuthenticPixelQueue(image);
319 if (image_view != (CacheView *) NULL)
320 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
321 for (x=0; x < (long) number_pixels; x++)
323 q->opacity=(Quantum) GetAlphaPixelComponent(q);
327 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
335 q=GetAuthenticPixelQueue(image);
336 if (image_view != (CacheView *) NULL)
337 q=GetAuthenticPixelQueue(image);
338 for (x=0; x < (long) number_pixels; x++)
348 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
349 extent=GetQuantumExtent(image,quantum_info,quantum_type);
350 endian=quantum_state.endian;
351 switch (quantum_type)
355 if (image->storage_class != PseudoClass)
357 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
358 "ColormappedImageRequired","`%s'",image->filename);
361 switch (quantum_info->depth)
365 register unsigned char
368 for (x=((long) number_pixels-7); x > 0; x-=8)
370 pixel=(unsigned char) *indexes++;
371 *q=((pixel & 0x01) << 7);
372 pixel=(unsigned char) *indexes++;
373 *q|=((pixel & 0x01) << 6);
374 pixel=(unsigned char) *indexes++;
375 *q|=((pixel & 0x01) << 5);
376 pixel=(unsigned char) *indexes++;
377 *q|=((pixel & 0x01) << 4);
378 pixel=(unsigned char) *indexes++;
379 *q|=((pixel & 0x01) << 3);
380 pixel=(unsigned char) *indexes++;
381 *q|=((pixel & 0x01) << 2);
382 pixel=(unsigned char) *indexes++;
383 *q|=((pixel & 0x01) << 1);
384 pixel=(unsigned char) *indexes++;
385 *q|=((pixel & 0x01) << 0);
388 if ((number_pixels % 8) != 0)
391 for (bit=7; bit >= (long) (8-(number_pixels % 8)); bit--)
393 pixel=(unsigned char) *indexes++;
394 *q|=((pixel & 0x01) << (unsigned char) bit);
402 register unsigned char
405 for (x=0; x < (long) (number_pixels-1) ; x+=2)
407 pixel=(unsigned char) *indexes++;
408 *q=((pixel & 0xf) << 4);
409 pixel=(unsigned char) *indexes++;
410 *q|=((pixel & 0xf) << 0);
413 if ((number_pixels % 2) != 0)
415 pixel=(unsigned char) *indexes++;
416 *q=((pixel & 0xf) << 4);
423 for (x=0; x < (long) number_pixels; x++)
425 q=PopCharPixel((unsigned char) indexes[x],q);
426 q+=quantum_info->pad;
432 if (quantum_info->format == FloatingPointQuantumFormat)
434 for (x=0; x < (long) number_pixels; x++)
436 q=PopShortPixel(endian,SinglePrecisionToHalf(QuantumScale*
438 q+=quantum_info->pad;
442 for (x=0; x < (long) number_pixels; x++)
444 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
445 q+=quantum_info->pad;
451 if (quantum_info->format == FloatingPointQuantumFormat)
453 for (x=0; x < (long) number_pixels; x++)
455 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
457 q+=quantum_info->pad;
461 for (x=0; x < (long) number_pixels; x++)
463 q=PopLongPixel(endian,(unsigned long) indexes[x],q);
464 q+=quantum_info->pad;
470 if (quantum_info->format == FloatingPointQuantumFormat)
472 for (x=0; x < (long) number_pixels; x++)
474 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
476 q+=quantum_info->pad;
483 for (x=0; x < (long) number_pixels; x++)
485 q=PopQuantumPixel(&quantum_state,image->depth,indexes[x],q);
487 q+=quantum_info->pad;
494 case IndexAlphaQuantum:
496 if (image->storage_class != PseudoClass)
498 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
499 "ColormappedImageRequired","`%s'",image->filename);
502 switch (quantum_info->depth)
506 register unsigned char
509 for (x=((long) number_pixels-3); x > 0; x-=4)
511 pixel=(unsigned char) *indexes++;
512 *q=((pixel & 0x01) << 7);
513 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
515 *q|=((pixel & 0x01) << 6);
517 pixel=(unsigned char) *indexes++;
518 *q|=((pixel & 0x01) << 5);
519 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
521 *q|=((pixel & 0x01) << 4);
523 pixel=(unsigned char) *indexes++;
524 *q|=((pixel & 0x01) << 3);
525 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
527 *q|=((pixel & 0x01) << 2);
529 pixel=(unsigned char) *indexes++;
530 *q|=((pixel & 0x01) << 1);
531 pixel=(unsigned char) (p->opacity == (Quantum) TransparentOpacity ?
533 *q|=((pixel & 0x01) << 0);
537 if ((number_pixels % 4) != 0)
540 for (bit=3; bit >= (long) (4-(number_pixels % 4)); bit-=2)
542 pixel=(unsigned char) *indexes++;
543 *q|=((pixel & 0x01) << (unsigned char) (bit+4));
544 pixel=(unsigned char) (p->opacity == (Quantum)
545 TransparentOpacity ? 1 : 0);
546 *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
555 register unsigned char
558 for (x=0; x < (long) number_pixels ; x++)
560 pixel=(unsigned char) *indexes++;
561 *q=((pixel & 0xf) << 4);
562 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
563 GetOpacityPixelComponent(p)))+0.5);
564 *q|=((pixel & 0xf) << 0);
572 register unsigned char
575 for (x=0; x < (long) number_pixels; x++)
577 q=PopCharPixel((unsigned char) indexes[x],q);
578 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
579 GetOpacityPixelComponent(p)));
580 q=PopCharPixel(pixel,q);
582 q+=quantum_info->pad;
588 register unsigned short
591 if (quantum_info->format == FloatingPointQuantumFormat)
593 for (x=0; x < (long) number_pixels; x++)
595 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
596 pixel=SinglePrecisionToHalf(QuantumScale*
597 GetAlphaPixelComponent(p));
598 q=PopShortPixel(endian,pixel,q);
600 q+=quantum_info->pad;
604 for (x=0; x < (long) number_pixels; x++)
606 q=PopShortPixel(endian,(unsigned short) indexes[x],q);
607 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
608 GetOpacityPixelComponent(p)));
609 q=PopShortPixel(endian,pixel,q);
611 q+=quantum_info->pad;
617 register unsigned long
620 if (quantum_info->format == FloatingPointQuantumFormat)
622 for (x=0; x < (long) number_pixels; x++)
627 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
628 pixel=(float) (GetAlphaPixelComponent(p));
629 q=PopFloatPixel(&quantum_state,pixel,q);
631 q+=quantum_info->pad;
635 for (x=0; x < (long) number_pixels; x++)
637 q=PopLongPixel(endian,(unsigned long) indexes[x],q);
638 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
639 GetOpacityPixelComponent(p)));
640 q=PopLongPixel(endian,pixel,q);
642 q+=quantum_info->pad;
648 if (quantum_info->format == FloatingPointQuantumFormat)
650 for (x=0; x < (long) number_pixels; x++)
655 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
656 pixel=(double) (GetAlphaPixelComponent(p));
657 q=PopDoublePixel(&quantum_state,pixel,q);
659 q+=quantum_info->pad;
666 range=GetQuantumRange(image->depth);
667 for (x=0; x < (long) number_pixels; x++)
669 q=PopQuantumPixel(&quantum_state,image->depth,indexes[x],q);
670 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
671 (Quantum) (GetAlphaPixelComponent(p)),range),q);
673 q+=quantum_info->pad;
682 switch (quantum_info->depth)
689 register unsigned char
695 if (quantum_info->min_is_white != MagickFalse)
700 threshold=(Quantum) (QuantumRange/2);
701 for (x=((long) number_pixels-7); x > 0; x-=8)
704 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 7;
706 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 6;
708 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 5;
710 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 4;
712 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 3;
714 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 2;
716 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 1;
718 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 0;
722 if ((number_pixels % 8) != 0)
725 for (bit=7; bit >= (long) (8-(number_pixels % 8)); bit--)
727 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) <<
737 register unsigned char
740 for (x=0; x < (long) (number_pixels-1) ; x+=2)
742 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
743 *q=(((pixel >> 4) & 0xf) << 4);
745 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
750 if ((number_pixels % 2) != 0)
752 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
753 *q=(((pixel >> 4) & 0xf) << 4);
761 register unsigned char
764 for (x=0; x < (long) number_pixels; x++)
766 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
767 q=PopCharPixel(pixel,q);
769 q+=quantum_info->pad;
775 range=GetQuantumRange(image->depth);
776 if (quantum_info->pack == MagickFalse)
778 register unsigned long
781 for (x=0; x < (long) (number_pixels-2); x+=3)
783 pixel=(unsigned long) (
784 ScaleQuantumToAny(PixelIntensityToQuantum(p+2),range) << 22 |
785 ScaleQuantumToAny(PixelIntensityToQuantum(p+1),range) << 12 |
786 ScaleQuantumToAny(PixelIntensityToQuantum(p+0),range) << 2);
787 q=PopLongPixel(endian,pixel,q);
789 q+=quantum_info->pad;
792 if (x++ < (long) (number_pixels-1))
793 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+1),
795 if (x++ < (long) number_pixels)
796 pixel|=ScaleQuantumToAny(PixelIntensityToQuantum(p+0),
798 q=PopLongPixel(endian,pixel,q);
801 for (x=0; x < (long) number_pixels; x++)
803 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
804 PixelIntensityToQuantum(p),range),q);
806 q+=quantum_info->pad;
812 register unsigned short
815 range=GetQuantumRange(image->depth);
816 if (quantum_info->pack == MagickFalse)
818 for (x=0; x < (long) number_pixels; x++)
820 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
821 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
823 q+=quantum_info->pad;
827 for (x=0; x < (long) number_pixels; x++)
829 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
830 PixelIntensityToQuantum(p),range),q);
832 q+=quantum_info->pad;
838 register unsigned short
841 if (quantum_info->format == FloatingPointQuantumFormat)
843 for (x=0; x < (long) number_pixels; x++)
845 pixel=SinglePrecisionToHalf(QuantumScale*
846 PixelIntensityToQuantum(p));
847 q=PopShortPixel(endian,pixel,q);
849 q+=quantum_info->pad;
853 for (x=0; x < (long) number_pixels; x++)
855 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
856 q=PopShortPixel(endian,pixel,q);
858 q+=quantum_info->pad;
864 register unsigned long
867 if (quantum_info->format == FloatingPointQuantumFormat)
869 for (x=0; x < (long) number_pixels; x++)
874 pixel=(float) PixelIntensityToQuantum(p);
875 q=PopFloatPixel(&quantum_state,pixel,q);
877 q+=quantum_info->pad;
881 for (x=0; x < (long) number_pixels; x++)
883 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
884 q=PopLongPixel(endian,pixel,q);
886 q+=quantum_info->pad;
892 if (quantum_info->format == FloatingPointQuantumFormat)
894 for (x=0; x < (long) number_pixels; x++)
899 pixel=(double) PixelIntensityToQuantum(p);
900 q=PopDoublePixel(&quantum_state,pixel,q);
902 q+=quantum_info->pad;
909 range=GetQuantumRange(image->depth);
910 for (x=0; x < (long) number_pixels; x++)
912 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
913 PixelIntensityToQuantum(p),range),q);
915 q+=quantum_info->pad;
922 case GrayAlphaQuantum:
924 switch (quantum_info->depth)
931 register unsigned char
938 if (quantum_info->min_is_white == MagickFalse)
943 threshold=(Quantum) (QuantumRange/2);
944 for (x=((long) number_pixels-3); x > 0; x-=4)
947 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 7;
948 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
949 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
951 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 5;
952 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
953 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
955 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 3;
956 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
957 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
959 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) << 1;
960 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 : 0x01);
961 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
965 if ((number_pixels % 4) != 0)
968 for (bit=3; bit >= (long) (4-(number_pixels % 4)); bit-=2)
970 *q|=(PixelIntensityToQuantum(p) < threshold ? black : white) <<
972 pixel=(unsigned char) (p->opacity == OpaqueOpacity ? 0x00 :
974 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
984 register unsigned char
987 for (x=0; x < (long) number_pixels ; x++)
989 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
990 *q=(((pixel >> 4) & 0xf) << 4);
991 pixel=(unsigned char) (16*QuantumScale*((Quantum) (QuantumRange-
992 GetOpacityPixelComponent(p)))+0.5);
1001 register unsigned char
1004 for (x=0; x < (long) number_pixels; x++)
1006 pixel=ScaleQuantumToChar(PixelIntensityToQuantum(p));
1007 q=PopCharPixel(pixel,q);
1008 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1009 GetOpacityPixelComponent(p)));
1010 q=PopCharPixel(pixel,q);
1012 q+=quantum_info->pad;
1018 register unsigned short
1021 if (quantum_info->format == FloatingPointQuantumFormat)
1023 for (x=0; x < (long) number_pixels; x++)
1025 pixel=SinglePrecisionToHalf(QuantumScale*
1026 PixelIntensityToQuantum(p));
1027 q=PopShortPixel(endian,pixel,q);
1028 pixel=SinglePrecisionToHalf(QuantumScale*
1029 GetAlphaPixelComponent(p));
1030 q=PopShortPixel(endian,pixel,q);
1032 q+=quantum_info->pad;
1036 for (x=0; x < (long) number_pixels; x++)
1038 pixel=ScaleQuantumToShort(PixelIntensityToQuantum(p));
1039 q=PopShortPixel(endian,pixel,q);
1040 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1041 GetOpacityPixelComponent(p)));
1042 q=PopShortPixel(endian,pixel,q);
1044 q+=quantum_info->pad;
1050 register unsigned long
1053 if (quantum_info->format == FloatingPointQuantumFormat)
1055 for (x=0; x < (long) number_pixels; x++)
1060 pixel=(float) PixelIntensityToQuantum(p);
1061 q=PopFloatPixel(&quantum_state,pixel,q);
1062 pixel=(float) (GetAlphaPixelComponent(p));
1063 q=PopFloatPixel(&quantum_state,pixel,q);
1065 q+=quantum_info->pad;
1069 for (x=0; x < (long) number_pixels; x++)
1071 pixel=ScaleQuantumToLong(PixelIntensityToQuantum(p));
1072 q=PopLongPixel(endian,pixel,q);
1073 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
1074 GetOpacityPixelComponent(p)));
1075 q=PopLongPixel(endian,pixel,q);
1077 q+=quantum_info->pad;
1083 if (quantum_info->format == FloatingPointQuantumFormat)
1085 for (x=0; x < (long) number_pixels; x++)
1090 pixel=(double) PixelIntensityToQuantum(p);
1091 q=PopDoublePixel(&quantum_state,pixel,q);
1092 pixel=(double) (GetAlphaPixelComponent(p));
1093 q=PopDoublePixel(&quantum_state,pixel,q);
1095 q+=quantum_info->pad;
1102 range=GetQuantumRange(image->depth);
1103 for (x=0; x < (long) number_pixels; x++)
1105 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1106 PixelIntensityToQuantum(p),range),q);
1107 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1108 (Quantum) (GetAlphaPixelComponent(p)),range),q);
1110 q+=quantum_info->pad;
1120 switch (quantum_info->depth)
1124 register unsigned char
1127 for (x=0; x < (long) number_pixels; x++)
1129 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
1130 q=PopCharPixel(pixel,q);
1132 q+=quantum_info->pad;
1138 register unsigned short
1141 if (quantum_info->format == FloatingPointQuantumFormat)
1143 for (x=0; x < (long) number_pixels; x++)
1145 pixel=SinglePrecisionToHalf(QuantumScale*
1146 GetRedPixelComponent(p));
1147 q=PopShortPixel(endian,pixel,q);
1149 q+=quantum_info->pad;
1153 for (x=0; x < (long) number_pixels; x++)
1155 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
1156 q=PopShortPixel(endian,pixel,q);
1158 q+=quantum_info->pad;
1164 register unsigned long
1167 if (quantum_info->format == FloatingPointQuantumFormat)
1169 for (x=0; x < (long) number_pixels; x++)
1171 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1173 q+=quantum_info->pad;
1177 for (x=0; x < (long) number_pixels; x++)
1179 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
1180 q=PopLongPixel(endian,pixel,q);
1182 q+=quantum_info->pad;
1188 if (quantum_info->format == FloatingPointQuantumFormat)
1190 for (x=0; x < (long) number_pixels; x++)
1192 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1194 q+=quantum_info->pad;
1201 range=GetQuantumRange(image->depth);
1202 for (x=0; x < (long) number_pixels; x++)
1204 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1207 q+=quantum_info->pad;
1215 case MagentaQuantum:
1217 switch (quantum_info->depth)
1221 register unsigned char
1224 for (x=0; x < (long) number_pixels; x++)
1226 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
1227 q=PopCharPixel(pixel,q);
1229 q+=quantum_info->pad;
1235 register unsigned short
1238 if (quantum_info->format == FloatingPointQuantumFormat)
1240 for (x=0; x < (long) number_pixels; x++)
1242 pixel=SinglePrecisionToHalf(QuantumScale*
1243 GetGreenPixelComponent(p));
1244 q=PopShortPixel(endian,pixel,q);
1246 q+=quantum_info->pad;
1250 for (x=0; x < (long) number_pixels; x++)
1252 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
1253 q=PopShortPixel(endian,pixel,q);
1255 q+=quantum_info->pad;
1261 register unsigned long
1264 if (quantum_info->format == FloatingPointQuantumFormat)
1266 for (x=0; x < (long) number_pixels; x++)
1268 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1270 q+=quantum_info->pad;
1274 for (x=0; x < (long) number_pixels; x++)
1276 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
1277 q=PopLongPixel(endian,pixel,q);
1279 q+=quantum_info->pad;
1285 if (quantum_info->format == FloatingPointQuantumFormat)
1287 for (x=0; x < (long) number_pixels; x++)
1289 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1291 q+=quantum_info->pad;
1298 range=GetQuantumRange(image->depth);
1299 for (x=0; x < (long) number_pixels; x++)
1301 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1304 q+=quantum_info->pad;
1314 switch (quantum_info->depth)
1318 register unsigned char
1321 for (x=0; x < (long) number_pixels; x++)
1323 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
1324 q=PopCharPixel(pixel,q);
1326 q+=quantum_info->pad;
1332 register unsigned short
1335 if (quantum_info->format == FloatingPointQuantumFormat)
1337 for (x=0; x < (long) number_pixels; x++)
1339 pixel=SinglePrecisionToHalf(QuantumScale*
1340 GetBluePixelComponent(p));
1341 q=PopShortPixel(endian,pixel,q);
1343 q+=quantum_info->pad;
1347 for (x=0; x < (long) number_pixels; x++)
1349 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
1350 q=PopShortPixel(endian,pixel,q);
1352 q+=quantum_info->pad;
1358 register unsigned long
1361 if (quantum_info->format == FloatingPointQuantumFormat)
1363 for (x=0; x < (long) number_pixels; x++)
1365 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1367 q+=quantum_info->pad;
1371 for (x=0; x < (long) number_pixels; x++)
1373 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
1374 q=PopLongPixel(endian,pixel,q);
1376 q+=quantum_info->pad;
1382 if (quantum_info->format == FloatingPointQuantumFormat)
1384 for (x=0; x < (long) number_pixels; x++)
1386 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1388 q+=quantum_info->pad;
1395 range=GetQuantumRange(image->depth);
1396 for (x=0; x < (long) number_pixels; x++)
1398 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1401 q+=quantum_info->pad;
1410 switch (quantum_info->depth)
1414 register unsigned char
1417 for (x=0; x < (long) number_pixels; x++)
1419 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
1420 GetOpacityPixelComponent(p)));
1421 q=PopCharPixel(pixel,q);
1423 q+=quantum_info->pad;
1429 register unsigned short
1432 if (quantum_info->format == FloatingPointQuantumFormat)
1434 for (x=0; x < (long) number_pixels; x++)
1436 pixel=SinglePrecisionToHalf(QuantumScale*
1437 GetAlphaPixelComponent(p));
1438 q=PopShortPixel(endian,pixel,q);
1440 q+=quantum_info->pad;
1444 for (x=0; x < (long) number_pixels; x++)
1446 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
1447 GetOpacityPixelComponent(p)));
1448 q=PopShortPixel(endian,pixel,q);
1450 q+=quantum_info->pad;
1456 register unsigned long
1459 if (quantum_info->format == FloatingPointQuantumFormat)
1461 for (x=0; x < (long) number_pixels; x++)
1466 pixel=(float) (GetAlphaPixelComponent(p));
1467 q=PopFloatPixel(&quantum_state,pixel,q);
1469 q+=quantum_info->pad;
1473 for (x=0; x < (long) number_pixels; x++)
1475 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
1476 GetOpacityPixelComponent(p)));
1477 q=PopLongPixel(endian,pixel,q);
1479 q+=quantum_info->pad;
1485 if (quantum_info->format == FloatingPointQuantumFormat)
1487 for (x=0; x < (long) number_pixels; x++)
1492 pixel=(double) (GetAlphaPixelComponent(p));
1493 q=PopDoublePixel(&quantum_state,pixel,q);
1495 q+=quantum_info->pad;
1502 range=GetQuantumRange(image->depth);
1503 for (x=0; x < (long) number_pixels; x++)
1505 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1506 (Quantum) (GetAlphaPixelComponent(p)),range),q);
1508 q+=quantum_info->pad;
1515 case OpacityQuantum:
1517 switch (quantum_info->depth)
1521 register unsigned char
1524 for (x=0; x < (long) number_pixels; x++)
1526 pixel=ScaleQuantumToChar(GetOpacityPixelComponent(p));
1527 q=PopCharPixel(pixel,q);
1529 q+=quantum_info->pad;
1535 register unsigned short
1538 if (quantum_info->format == FloatingPointQuantumFormat)
1540 for (x=0; x < (long) number_pixels; x++)
1542 pixel=SinglePrecisionToHalf(QuantumScale*
1543 GetOpacityPixelComponent(p));
1544 q=PopShortPixel(endian,pixel,q);
1546 q+=quantum_info->pad;
1550 for (x=0; x < (long) number_pixels; x++)
1552 pixel=ScaleQuantumToShort(GetOpacityPixelComponent(p));
1553 q=PopShortPixel(endian,pixel,q);
1555 q+=quantum_info->pad;
1561 register unsigned long
1564 if (quantum_info->format == FloatingPointQuantumFormat)
1566 for (x=0; x < (long) number_pixels; x++)
1568 q=PopFloatPixel(&quantum_state,(float) p->opacity,q);
1570 q+=quantum_info->pad;
1574 for (x=0; x < (long) number_pixels; x++)
1576 pixel=ScaleQuantumToLong(GetOpacityPixelComponent(p));
1577 q=PopLongPixel(endian,pixel,q);
1579 q+=quantum_info->pad;
1585 if (quantum_info->format == FloatingPointQuantumFormat)
1587 for (x=0; x < (long) number_pixels; x++)
1589 q=PopDoublePixel(&quantum_state,(double) p->opacity,q);
1591 q+=quantum_info->pad;
1598 range=GetQuantumRange(image->depth);
1599 for (x=0; x < (long) number_pixels; x++)
1601 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1602 p->opacity,range),q);
1604 q+=quantum_info->pad;
1613 if (image->colorspace != CMYKColorspace)
1615 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1616 "ColorSeparatedImageRequired","`%s'",image->filename);
1619 switch (quantum_info->depth)
1623 register unsigned char
1626 for (x=0; x < (long) number_pixels; x++)
1628 pixel=ScaleQuantumToChar(indexes[x]);
1629 q=PopCharPixel(pixel,q);
1631 q+=quantum_info->pad;
1637 register unsigned short
1640 if (quantum_info->format == FloatingPointQuantumFormat)
1642 for (x=0; x < (long) number_pixels; x++)
1644 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
1645 q=PopShortPixel(endian,pixel,q);
1647 q+=quantum_info->pad;
1651 for (x=0; x < (long) number_pixels; x++)
1653 pixel=ScaleQuantumToShort(indexes[x]);
1654 q=PopShortPixel(endian,pixel,q);
1656 q+=quantum_info->pad;
1662 register unsigned long
1665 if (quantum_info->format == FloatingPointQuantumFormat)
1667 for (x=0; x < (long) number_pixels; x++)
1669 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
1671 q+=quantum_info->pad;
1675 for (x=0; x < (long) number_pixels; x++)
1677 pixel=ScaleQuantumToLong(indexes[x]);
1678 q=PopLongPixel(endian,pixel,q);
1680 q+=quantum_info->pad;
1686 if (quantum_info->format == FloatingPointQuantumFormat)
1688 for (x=0; x < (long) number_pixels; x++)
1690 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
1692 q+=quantum_info->pad;
1699 range=GetQuantumRange(image->depth);
1700 for (x=0; x < (long) number_pixels; x++)
1702 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1703 (Quantum) indexes[x],range),q);
1705 q+=quantum_info->pad;
1715 switch (quantum_info->depth)
1719 for (x=0; x < (long) number_pixels; x++)
1721 q=PopCharPixel(ScaleQuantumToChar(GetRedPixelComponent(p)),q);
1722 q=PopCharPixel(ScaleQuantumToChar(GetGreenPixelComponent(p)),q);
1723 q=PopCharPixel(ScaleQuantumToChar(GetBluePixelComponent(p)),q);
1725 q+=quantum_info->pad;
1731 register unsigned long
1734 range=GetQuantumRange(image->depth);
1735 if (quantum_info->pack == MagickFalse)
1737 for (x=0; x < (long) number_pixels; x++)
1739 pixel=(unsigned long) (ScaleQuantumToAny(p->red,range) << 22 |
1740 ScaleQuantumToAny(p->green,range) << 12 |
1741 ScaleQuantumToAny(p->blue,range) << 2);
1742 q=PopLongPixel(endian,pixel,q);
1744 q+=quantum_info->pad;
1748 if (quantum_info->quantum == 32UL)
1750 for (x=0; x < (long) number_pixels; x++)
1752 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1753 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1754 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1755 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1756 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1757 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1759 q+=quantum_info->pad;
1763 for (x=0; x < (long) number_pixels; x++)
1765 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1766 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1767 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1768 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1769 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1770 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1772 q+=quantum_info->pad;
1778 register unsigned long
1781 range=GetQuantumRange(image->depth);
1782 if (quantum_info->pack == MagickFalse)
1784 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1791 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1796 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1801 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1806 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1812 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1817 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1822 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1827 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1828 q+=quantum_info->pad;
1830 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1832 switch ((x+bit) % 3)
1837 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1842 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1847 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1852 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
1853 q+=quantum_info->pad;
1859 if (quantum_info->quantum == 32UL)
1861 for (x=0; x < (long) number_pixels; x++)
1863 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1864 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1865 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1866 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1867 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1868 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
1870 q+=quantum_info->pad;
1874 for (x=0; x < (long) number_pixels; x++)
1876 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
1877 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1878 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
1879 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1880 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
1881 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
1883 q+=quantum_info->pad;
1889 register unsigned short
1892 if (quantum_info->format == FloatingPointQuantumFormat)
1894 for (x=0; x < (long) number_pixels; x++)
1896 pixel=SinglePrecisionToHalf(QuantumScale*
1897 GetRedPixelComponent(p));
1898 q=PopShortPixel(endian,pixel,q);
1899 pixel=SinglePrecisionToHalf(QuantumScale*
1900 GetGreenPixelComponent(p));
1901 q=PopShortPixel(endian,pixel,q);
1902 pixel=SinglePrecisionToHalf(QuantumScale*
1903 GetBluePixelComponent(p));
1904 q=PopShortPixel(endian,pixel,q);
1906 q+=quantum_info->pad;
1910 for (x=0; x < (long) number_pixels; x++)
1912 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
1913 q=PopShortPixel(endian,pixel,q);
1914 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
1915 q=PopShortPixel(endian,pixel,q);
1916 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
1917 q=PopShortPixel(endian,pixel,q);
1919 q+=quantum_info->pad;
1925 register unsigned long
1928 if (quantum_info->format == FloatingPointQuantumFormat)
1930 for (x=0; x < (long) number_pixels; x++)
1932 q=PopFloatPixel(&quantum_state,(float) p->red,q);
1933 q=PopFloatPixel(&quantum_state,(float) p->green,q);
1934 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
1936 q+=quantum_info->pad;
1940 for (x=0; x < (long) number_pixels; x++)
1942 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
1943 q=PopLongPixel(endian,pixel,q);
1944 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
1945 q=PopLongPixel(endian,pixel,q);
1946 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
1947 q=PopLongPixel(endian,pixel,q);
1949 q+=quantum_info->pad;
1955 if (quantum_info->format == FloatingPointQuantumFormat)
1957 for (x=0; x < (long) number_pixels; x++)
1959 q=PopDoublePixel(&quantum_state,(double) p->red,q);
1960 q=PopDoublePixel(&quantum_state,(double) p->green,q);
1961 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
1963 q+=quantum_info->pad;
1970 range=GetQuantumRange(image->depth);
1971 for (x=0; x < (long) number_pixels; x++)
1973 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1975 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1977 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
1980 q+=quantum_info->pad;
1991 switch (quantum_info->depth)
1995 register unsigned char
1998 for (x=0; x < (long) number_pixels; x++)
2000 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
2001 q=PopCharPixel(pixel,q);
2002 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
2003 q=PopCharPixel(pixel,q);
2004 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
2005 q=PopCharPixel(pixel,q);
2006 pixel=ScaleQuantumToChar(GetAlphaPixelComponent(p));
2007 q=PopCharPixel(pixel,q);
2009 q+=quantum_info->pad;
2015 register unsigned long
2018 range=GetQuantumRange(image->depth);
2019 if (quantum_info->pack == MagickFalse)
2033 for (x=0; x < (long) number_pixels; x++)
2035 for (i=0; i < 4; i++)
2039 case 0: quantum=p->red; break;
2040 case 1: quantum=p->green; break;
2041 case 2: quantum=p->blue; break;
2042 case 3: quantum=QuantumRange-p->opacity; break;
2048 pixel|=(unsigned long) (ScaleQuantumToAny(quantum,
2054 pixel|=(unsigned long) (ScaleQuantumToAny(quantum,
2060 pixel|=(unsigned long) (ScaleQuantumToAny(quantum,
2062 q=PopLongPixel(endian,pixel,q);
2070 q+=quantum_info->pad;
2074 if (quantum_info->quantum == 32UL)
2076 for (x=0; x < (long) number_pixels; x++)
2078 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
2079 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
2080 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
2081 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
2082 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
2083 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
2084 pixel=(unsigned long) ScaleQuantumToAny(QuantumRange-p->opacity,
2086 q=PopQuantumLongPixel(&quantum_state,image->depth,pixel,q);
2088 q+=quantum_info->pad;
2092 for (x=0; x < (long) number_pixels; x++)
2094 pixel=(unsigned long) ScaleQuantumToAny(p->red,range);
2095 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
2096 pixel=(unsigned long) ScaleQuantumToAny(p->green,range);
2097 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
2098 pixel=(unsigned long) ScaleQuantumToAny(p->blue,range);
2099 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
2100 pixel=(unsigned long) ScaleQuantumToAny(QuantumRange-
2102 q=PopQuantumPixel(&quantum_state,image->depth,pixel,q);
2104 q+=quantum_info->pad;
2110 register unsigned short
2113 if (quantum_info->format == FloatingPointQuantumFormat)
2115 for (x=0; x < (long) number_pixels; x++)
2117 pixel=SinglePrecisionToHalf(QuantumScale*
2118 GetRedPixelComponent(p));
2119 q=PopShortPixel(endian,pixel,q);
2120 pixel=SinglePrecisionToHalf(QuantumScale*
2121 GetGreenPixelComponent(p));
2122 q=PopShortPixel(endian,pixel,q);
2123 pixel=SinglePrecisionToHalf(QuantumScale*
2124 GetBluePixelComponent(p));
2125 q=PopShortPixel(endian,pixel,q);
2126 pixel=SinglePrecisionToHalf(QuantumScale*
2127 GetAlphaPixelComponent(p));
2128 q=PopShortPixel(endian,pixel,q);
2130 q+=quantum_info->pad;
2134 for (x=0; x < (long) number_pixels; x++)
2136 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
2137 q=PopShortPixel(endian,pixel,q);
2138 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
2139 q=PopShortPixel(endian,pixel,q);
2140 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
2141 q=PopShortPixel(endian,pixel,q);
2142 pixel=ScaleQuantumToShort(GetAlphaPixelComponent(p));
2143 q=PopShortPixel(endian,pixel,q);
2145 q+=quantum_info->pad;
2151 register unsigned long
2154 if (quantum_info->format == FloatingPointQuantumFormat)
2156 for (x=0; x < (long) number_pixels; x++)
2161 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2162 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2163 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2164 pixel=GetAlphaPixelComponent(p);
2165 q=PopFloatPixel(&quantum_state,pixel,q);
2167 q+=quantum_info->pad;
2171 for (x=0; x < (long) number_pixels; x++)
2173 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
2174 q=PopLongPixel(endian,pixel,q);
2175 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
2176 q=PopLongPixel(endian,pixel,q);
2177 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
2178 q=PopLongPixel(endian,pixel,q);
2179 pixel=ScaleQuantumToLong(GetAlphaPixelComponent(p));
2180 q=PopLongPixel(endian,pixel,q);
2182 q+=quantum_info->pad;
2188 if (quantum_info->format == FloatingPointQuantumFormat)
2193 for (x=0; x < (long) number_pixels; x++)
2195 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2196 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2197 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2198 pixel=(double) GetAlphaPixelComponent(p);
2199 q=PopDoublePixel(&quantum_state,pixel,q);
2201 q+=quantum_info->pad;
2208 range=GetQuantumRange(image->depth);
2209 for (x=0; x < (long) number_pixels; x++)
2211 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2212 GetRedPixelComponent(p),range),q);
2213 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2214 GetGreenPixelComponent(p),range),q);
2215 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2216 GetBluePixelComponent(p),range),q);
2217 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2218 GetAlphaPixelComponent(p),range),q);
2220 q+=quantum_info->pad;
2229 if (image->colorspace != CMYKColorspace)
2231 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2232 "ColorSeparatedImageRequired","`%s'",image->filename);
2235 switch (quantum_info->depth)
2239 register unsigned char
2242 for (x=0; x < (long) number_pixels; x++)
2244 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
2245 q=PopCharPixel(pixel,q);
2246 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
2247 q=PopCharPixel(pixel,q);
2248 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
2249 q=PopCharPixel(pixel,q);
2250 pixel=ScaleQuantumToChar(indexes[x]);
2251 q=PopCharPixel(pixel,q);
2253 q+=quantum_info->pad;
2259 register unsigned short
2262 if (quantum_info->format == FloatingPointQuantumFormat)
2264 for (x=0; x < (long) number_pixels; x++)
2266 pixel=SinglePrecisionToHalf(QuantumScale*
2267 GetRedPixelComponent(p));
2268 q=PopShortPixel(endian,pixel,q);
2269 pixel=SinglePrecisionToHalf(QuantumScale*
2270 GetGreenPixelComponent(p));
2271 q=PopShortPixel(endian,pixel,q);
2272 pixel=SinglePrecisionToHalf(QuantumScale*
2273 GetBluePixelComponent(p));
2274 q=PopShortPixel(endian,pixel,q);
2275 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
2276 q=PopShortPixel(endian,pixel,q);
2278 q+=quantum_info->pad;
2282 for (x=0; x < (long) number_pixels; x++)
2284 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
2285 q=PopShortPixel(endian,pixel,q);
2286 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
2287 q=PopShortPixel(endian,pixel,q);
2288 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
2289 q=PopShortPixel(endian,pixel,q);
2290 pixel=ScaleQuantumToShort(indexes[x]);
2291 q=PopShortPixel(endian,pixel,q);
2293 q+=quantum_info->pad;
2299 register unsigned long
2302 if (quantum_info->format == FloatingPointQuantumFormat)
2304 for (x=0; x < (long) number_pixels; x++)
2306 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2307 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2308 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2309 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
2311 q+=quantum_info->pad;
2315 for (x=0; x < (long) number_pixels; x++)
2317 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
2318 q=PopLongPixel(endian,pixel,q);
2319 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
2320 q=PopLongPixel(endian,pixel,q);
2321 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
2322 q=PopLongPixel(endian,pixel,q);
2323 pixel=ScaleQuantumToLong(indexes[x]);
2324 q=PopLongPixel(endian,pixel,q);
2326 q+=quantum_info->pad;
2332 if (quantum_info->format == FloatingPointQuantumFormat)
2334 for (x=0; x < (long) number_pixels; x++)
2336 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2337 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2338 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2339 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
2341 q+=quantum_info->pad;
2348 range=GetQuantumRange(image->depth);
2349 for (x=0; x < (long) number_pixels; x++)
2351 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2353 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2355 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2357 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2358 indexes[x],range),q);
2360 q+=quantum_info->pad;
2370 if (image->colorspace != CMYKColorspace)
2372 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2373 "ColorSeparatedImageRequired","`%s'",image->filename);
2376 switch (quantum_info->depth)
2380 register unsigned char
2383 for (x=0; x < (long) number_pixels; x++)
2385 pixel=ScaleQuantumToChar(GetRedPixelComponent(p));
2386 q=PopCharPixel(pixel,q);
2387 pixel=ScaleQuantumToChar(GetGreenPixelComponent(p));
2388 q=PopCharPixel(pixel,q);
2389 pixel=ScaleQuantumToChar(GetBluePixelComponent(p));
2390 q=PopCharPixel(pixel,q);
2391 pixel=ScaleQuantumToChar(indexes[x]);
2392 q=PopCharPixel(pixel,q);
2393 pixel=ScaleQuantumToChar((Quantum) (QuantumRange-
2394 GetOpacityPixelComponent(p)));
2395 q=PopCharPixel(pixel,q);
2397 q+=quantum_info->pad;
2403 register unsigned short
2406 if (quantum_info->format == FloatingPointQuantumFormat)
2408 for (x=0; x < (long) number_pixels; x++)
2410 pixel=SinglePrecisionToHalf(QuantumScale*
2411 GetRedPixelComponent(p));
2412 q=PopShortPixel(endian,pixel,q);
2413 pixel=SinglePrecisionToHalf(QuantumScale*
2414 GetGreenPixelComponent(p));
2415 q=PopShortPixel(endian,pixel,q);
2416 pixel=SinglePrecisionToHalf(QuantumScale*
2417 GetBluePixelComponent(p));
2418 q=PopShortPixel(endian,pixel,q);
2419 pixel=SinglePrecisionToHalf(QuantumScale*indexes[x]);
2420 q=PopShortPixel(endian,pixel,q);
2421 pixel=SinglePrecisionToHalf(QuantumScale*
2422 GetAlphaPixelComponent(p));
2423 q=PopShortPixel(endian,pixel,q);
2425 q+=quantum_info->pad;
2429 for (x=0; x < (long) number_pixels; x++)
2431 pixel=ScaleQuantumToShort(GetRedPixelComponent(p));
2432 q=PopShortPixel(endian,pixel,q);
2433 pixel=ScaleQuantumToShort(GetGreenPixelComponent(p));
2434 q=PopShortPixel(endian,pixel,q);
2435 pixel=ScaleQuantumToShort(GetBluePixelComponent(p));
2436 q=PopShortPixel(endian,pixel,q);
2437 pixel=ScaleQuantumToShort(indexes[x]);
2438 q=PopShortPixel(endian,pixel,q);
2439 pixel=ScaleQuantumToShort((Quantum) (QuantumRange-
2440 GetOpacityPixelComponent(p)));
2441 q=PopShortPixel(endian,pixel,q);
2443 q+=quantum_info->pad;
2449 register unsigned long
2452 if (quantum_info->format == FloatingPointQuantumFormat)
2454 for (x=0; x < (long) number_pixels; x++)
2459 q=PopFloatPixel(&quantum_state,(float) p->red,q);
2460 q=PopFloatPixel(&quantum_state,(float) p->green,q);
2461 q=PopFloatPixel(&quantum_state,(float) p->blue,q);
2462 q=PopFloatPixel(&quantum_state,(float) indexes[x],q);
2463 pixel=(float) (GetAlphaPixelComponent(p));
2464 q=PopFloatPixel(&quantum_state,pixel,q);
2466 q+=quantum_info->pad;
2470 for (x=0; x < (long) number_pixels; x++)
2472 pixel=ScaleQuantumToLong(GetRedPixelComponent(p));
2473 q=PopLongPixel(endian,pixel,q);
2474 pixel=ScaleQuantumToLong(GetGreenPixelComponent(p));
2475 q=PopLongPixel(endian,pixel,q);
2476 pixel=ScaleQuantumToLong(GetBluePixelComponent(p));
2477 q=PopLongPixel(endian,pixel,q);
2478 pixel=ScaleQuantumToLong(indexes[x]);
2479 q=PopLongPixel(endian,pixel,q);
2480 pixel=ScaleQuantumToLong((Quantum) (QuantumRange-
2481 GetOpacityPixelComponent(p)));
2482 q=PopLongPixel(endian,pixel,q);
2484 q+=quantum_info->pad;
2490 if (quantum_info->format == FloatingPointQuantumFormat)
2495 for (x=0; x < (long) number_pixels; x++)
2497 q=PopDoublePixel(&quantum_state,(double) p->red,q);
2498 q=PopDoublePixel(&quantum_state,(double) p->green,q);
2499 q=PopDoublePixel(&quantum_state,(double) p->blue,q);
2500 q=PopDoublePixel(&quantum_state,(double) indexes[x],q);
2501 pixel=(double) (GetAlphaPixelComponent(p));
2502 q=PopDoublePixel(&quantum_state,pixel,q);
2504 q+=quantum_info->pad;
2511 range=GetQuantumRange(image->depth);
2512 for (x=0; x < (long) number_pixels; x++)
2514 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2516 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2518 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2520 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2521 indexes[x],range),q);
2522 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2523 p->opacity,range),q);
2525 q+=quantum_info->pad;
2543 register unsigned long
2551 range=GetQuantumRange(image->depth);
2552 switch (quantum_info->depth)
2556 if (quantum_info->pack == MagickFalse)
2558 for (x=0; x < (long) number_pixels; x+=2)
2560 for (i=0; i < 4; i++)
2566 quantum=GetRedPixelComponent(p);
2571 quantum=GetGreenPixelComponent(p);
2576 quantum=GetBluePixelComponent(p);
2580 cbcr[i]=(Quantum) quantum;
2583 pixel=(unsigned long) ((unsigned long) (cbcr[1]) << 22 |
2584 (unsigned long) (cbcr[0]) << 12 |
2585 (unsigned long) (cbcr[2]) << 2);
2586 q=PopLongPixel(endian,pixel,q);
2588 pixel=(unsigned long) ((unsigned long) (cbcr[3]) << 22 |
2589 (unsigned long) (cbcr[0]) << 12 |
2590 (unsigned long) (cbcr[2]) << 2);
2591 q=PopLongPixel(endian,pixel,q);
2593 q+=quantum_info->pad;
2601 for (x=0; x < (long) number_pixels; x+=2)
2603 for (i=0; i < 4; i++)
2609 quantum=GetRedPixelComponent(p);
2614 quantum=GetGreenPixelComponent(p);
2619 quantum=GetBluePixelComponent(p);
2623 cbcr[i]=(Quantum) quantum;
2626 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2628 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2630 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2633 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2635 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2637 q=PopQuantumPixel(&quantum_state,image->depth,ScaleQuantumToAny(
2640 q+=quantum_info->pad;
2650 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2655 register PixelPacket
2658 q=GetAuthenticPixelQueue(image);
2659 if (image_view != (CacheView *) NULL)
2660 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
2661 for (x=0; x < (long) number_pixels; x++)
2669 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2671 register PixelPacket
2674 q=GetAuthenticPixelQueue(image);
2675 if (image_view != (CacheView *) NULL)
2676 q=(PixelPacket *) GetCacheViewVirtualPixelQueue(image_view);
2677 for (x=0; x < (long) number_pixels; x++)
2679 q->opacity=(Quantum) GetAlphaPixelComponent(q);