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 "MagickCore/studio.h"
48 #include "MagickCore/property.h"
49 #include "MagickCore/blob.h"
50 #include "MagickCore/blob-private.h"
51 #include "MagickCore/color-private.h"
52 #include "MagickCore/exception.h"
53 #include "MagickCore/exception-private.h"
54 #include "MagickCore/cache.h"
55 #include "MagickCore/constitute.h"
56 #include "MagickCore/delegate.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/option.h"
63 #include "MagickCore/pixel.h"
64 #include "MagickCore/pixel-accessor.h"
65 #include "MagickCore/quantum.h"
66 #include "MagickCore/quantum-private.h"
67 #include "MagickCore/resource_.h"
68 #include "MagickCore/semaphore.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/stream.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/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 size_t depth,const QuantumAny pixel,unsigned char *pixels)
184 if (quantum_state->bits == 0UL)
185 quantum_state->bits=8U;
186 for (i=(ssize_t) depth; i > 0L; )
188 quantum_bits=(size_t) i;
189 if (quantum_bits > quantum_state->bits)
190 quantum_bits=quantum_state->bits;
191 i-=(ssize_t) quantum_bits;
192 if (quantum_state->bits == 8UL)
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 size_t depth,const size_t pixel,unsigned char *pixels)
215 if (quantum_state->bits == 0U)
216 quantum_state->bits=32UL;
217 for (i=(ssize_t) depth; i > 0; )
219 quantum_bits=(size_t) 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]) << (32U-quantum_state->bits));
224 i-=(ssize_t) quantum_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=32U;
236 MagickExport size_t ExportQuantumPixels(Image *image,CacheView *image_view,
237 const QuantumInfo *quantum_info,const QuantumType quantum_type,
238 unsigned char *pixels,ExceptionInfo *exception)
255 register const Quantum
261 register unsigned char
271 assert(image != (Image *) NULL);
272 assert(image->signature == MagickSignature);
273 if (image->debug != MagickFalse)
274 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
275 assert(quantum_info != (QuantumInfo *) NULL);
276 assert(quantum_info->signature == MagickSignature);
277 if (pixels == (unsigned char *) NULL)
278 pixels=GetQuantumPixels(quantum_info);
279 if (image_view == (CacheView *) NULL)
281 number_pixels=GetImageExtent(image);
282 p=GetVirtualPixelQueue(image);
283 channels=GetPixelChannels(image);
287 number_pixels=GetCacheViewExtent(image_view);
288 p=GetCacheViewVirtualPixelQueue(image_view);
289 channels=GetPixelChannels(image);
291 if (quantum_info->alpha_type == AssociatedQuantumAlpha)
299 q=GetAuthenticPixelQueue(image);
300 if (image_view != (CacheView *) NULL)
301 q=GetCacheViewAuthenticPixelQueue(image_view);
302 for (x=0; x < (ssize_t) image->columns; x++)
304 alpha=QuantumScale*GetPixelAlpha(image,q);
305 SetPixelRed(image,ClampToQuantum(alpha*GetPixelRed(image,q)),q);
306 SetPixelGreen(image,ClampToQuantum(alpha*GetPixelGreen(image,q)),q);
307 SetPixelBlue(image,ClampToQuantum(alpha*GetPixelBlue(image,q)),q);
311 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
312 (quantum_type == BGROQuantum))
317 q=GetAuthenticPixelQueue(image);
318 if (image_view != (CacheView *) NULL)
319 q=GetCacheViewAuthenticPixelQueue(image_view);
320 for (x=0; x < (ssize_t) number_pixels; x++)
322 SetPixelAlpha(image,GetPixelAlpha(image,q),q);
326 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
334 q=GetAuthenticPixelQueue(image);
335 if (image_view != (CacheView *) NULL)
336 q=GetAuthenticPixelQueue(image);
337 for (x=0; x < (ssize_t) number_pixels; x++)
339 quantum=GetPixelRed(image,q);
340 SetPixelRed(image,GetPixelGreen(image,q),q);
341 SetPixelGreen(image,quantum,q);
347 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
348 extent=GetQuantumExtent(image,quantum_info,quantum_type);
349 endian=quantum_state.endian;
350 switch (quantum_type)
354 if (image->storage_class != PseudoClass)
356 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
357 "ColormappedImageRequired","`%s'",image->filename);
360 switch (quantum_info->depth)
364 register unsigned char
367 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
369 pixel=(unsigned char) GetPixelIndex(image,p);
370 *q=((pixel & 0x01) << 7);
372 pixel=(unsigned char) GetPixelIndex(image,p);
373 *q|=((pixel & 0x01) << 6);
375 pixel=(unsigned char) GetPixelIndex(image,p);
376 *q|=((pixel & 0x01) << 5);
378 pixel=(unsigned char) GetPixelIndex(image,p);
379 *q|=((pixel & 0x01) << 4);
381 pixel=(unsigned char) GetPixelIndex(image,p);
382 *q|=((pixel & 0x01) << 3);
384 pixel=(unsigned char) GetPixelIndex(image,p);
385 *q|=((pixel & 0x01) << 2);
387 pixel=(unsigned char) GetPixelIndex(image,p);
388 *q|=((pixel & 0x01) << 1);
390 pixel=(unsigned char) GetPixelIndex(image,p);
391 *q|=((pixel & 0x01) << 0);
395 if ((number_pixels % 8) != 0)
398 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
400 pixel=(unsigned char) GetPixelIndex(image,p);
401 *q|=((pixel & 0x01) << (unsigned char) bit);
410 register unsigned char
413 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
415 pixel=(unsigned char) GetPixelIndex(image,p);
416 *q=((pixel & 0xf) << 4);
418 pixel=(unsigned char) GetPixelIndex(image,p);
419 *q|=((pixel & 0xf) << 0);
423 if ((number_pixels % 2) != 0)
425 pixel=(unsigned char) GetPixelIndex(image,p);
426 *q=((pixel & 0xf) << 4);
434 for (x=0; x < (ssize_t) number_pixels; x++)
436 q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
438 q+=quantum_info->pad;
444 if (quantum_info->format == FloatingPointQuantumFormat)
446 for (x=0; x < (ssize_t) number_pixels; x++)
448 q=PopShortPixel(endian,SinglePrecisionToHalf(QuantumScale*
449 GetPixelIndex(image,p)),q);
451 q+=quantum_info->pad;
455 for (x=0; x < (ssize_t) number_pixels; x++)
457 q=PopShortPixel(endian,(unsigned short) GetPixelIndex(image,p),q);
459 q+=quantum_info->pad;
465 if (quantum_info->format == FloatingPointQuantumFormat)
467 for (x=0; x < (ssize_t) number_pixels; x++)
469 q=PopFloatPixel(&quantum_state,(float)
470 GetPixelIndex(image,p),q);
472 q+=quantum_info->pad;
476 for (x=0; x < (ssize_t) number_pixels; x++)
478 q=PopLongPixel(endian,(unsigned int) GetPixelIndex(image,p),q);
480 q+=quantum_info->pad;
486 if (quantum_info->format == FloatingPointQuantumFormat)
488 for (x=0; x < (ssize_t) number_pixels; x++)
490 q=PopDoublePixel(&quantum_state,(double)
491 GetPixelIndex(image,p),q);
493 q+=quantum_info->pad;
500 for (x=0; x < (ssize_t) number_pixels; x++)
502 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
503 GetPixelIndex(image,p),q);
505 q+=quantum_info->pad;
512 case IndexAlphaQuantum:
514 if (image->storage_class != PseudoClass)
516 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
517 "ColormappedImageRequired","`%s'",image->filename);
520 switch (quantum_info->depth)
524 register unsigned char
527 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
529 pixel=(unsigned char) GetPixelIndex(image,p);
530 *q=((pixel & 0x01) << 7);
531 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
532 TransparentAlpha ? 1 : 0);
533 *q|=((pixel & 0x01) << 6);
535 pixel=(unsigned char) GetPixelIndex(image,p);
536 *q|=((pixel & 0x01) << 5);
537 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
538 TransparentAlpha ? 1 : 0);
539 *q|=((pixel & 0x01) << 4);
541 pixel=(unsigned char) GetPixelIndex(image,p);
542 *q|=((pixel & 0x01) << 3);
543 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
544 TransparentAlpha ? 1 : 0);
545 *q|=((pixel & 0x01) << 2);
547 pixel=(unsigned char) GetPixelIndex(image,p);
548 *q|=((pixel & 0x01) << 1);
549 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
550 TransparentAlpha ? 1 : 0);
551 *q|=((pixel & 0x01) << 0);
555 if ((number_pixels % 4) != 0)
558 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
560 pixel=(unsigned char) GetPixelIndex(image,p);
561 *q|=((pixel & 0x01) << (unsigned char) (bit+4));
562 pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
563 TransparentAlpha ? 1 : 0);
564 *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
573 register unsigned char
576 for (x=0; x < (ssize_t) number_pixels ; x++)
578 pixel=(unsigned char) GetPixelIndex(image,p);
579 *q=((pixel & 0xf) << 4);
580 pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
581 *q|=((pixel & 0xf) << 0);
589 register unsigned char
592 for (x=0; x < (ssize_t) number_pixels; x++)
594 q=PopCharPixel((unsigned char) GetPixelIndex(image,p),q);
595 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
596 q=PopCharPixel(pixel,q);
598 q+=quantum_info->pad;
604 register unsigned short
607 if (quantum_info->format == FloatingPointQuantumFormat)
609 for (x=0; x < (ssize_t) number_pixels; x++)
611 q=PopShortPixel(endian,(unsigned short)
612 GetPixelIndex(image,p),q);
613 pixel=SinglePrecisionToHalf(QuantumScale*
614 GetPixelAlpha(image,p));
615 q=PopShortPixel(endian,pixel,q);
617 q+=quantum_info->pad;
621 for (x=0; x < (ssize_t) number_pixels; x++)
623 q=PopShortPixel(endian,(unsigned short) GetPixelIndex(image,p),q);
624 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
625 q=PopShortPixel(endian,pixel,q);
627 q+=quantum_info->pad;
633 register unsigned int
636 if (quantum_info->format == FloatingPointQuantumFormat)
638 for (x=0; x < (ssize_t) number_pixels; x++)
643 q=PopFloatPixel(&quantum_state,(float)
644 GetPixelIndex(image,p),q);
645 pixel=(float) GetPixelAlpha(image,p);
646 q=PopFloatPixel(&quantum_state,pixel,q);
648 q+=quantum_info->pad;
652 for (x=0; x < (ssize_t) number_pixels; x++)
654 q=PopLongPixel(endian,(unsigned int) GetPixelIndex(image,p),q);
655 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
656 q=PopLongPixel(endian,pixel,q);
658 q+=quantum_info->pad;
664 if (quantum_info->format == FloatingPointQuantumFormat)
666 for (x=0; x < (ssize_t) number_pixels; x++)
671 q=PopDoublePixel(&quantum_state,(double)
672 GetPixelIndex(image,p),q);
673 pixel=(double) GetPixelAlpha(image,p);
674 q=PopDoublePixel(&quantum_state,pixel,q);
676 q+=quantum_info->pad;
683 range=GetQuantumRange(quantum_info->depth);
684 for (x=0; x < (ssize_t) number_pixels; x++)
686 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
687 GetPixelIndex(image,p),q);
688 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
689 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
691 q+=quantum_info->pad;
700 switch (quantum_info->depth)
704 for (x=0; x < (ssize_t) number_pixels; x++)
706 q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
707 q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
708 q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
710 q+=quantum_info->pad;
716 register unsigned int
719 range=GetQuantumRange(quantum_info->depth);
720 if (quantum_info->pack == MagickFalse)
722 for (x=0; x < (ssize_t) number_pixels; x++)
724 pixel=(unsigned int) (
725 ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
726 ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
727 ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
728 q=PopLongPixel(endian,pixel,q);
730 q+=quantum_info->pad;
734 if (quantum_info->quantum == 32UL)
736 for (x=0; x < (ssize_t) number_pixels; x++)
738 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
740 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
742 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
744 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
746 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
748 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
751 q+=quantum_info->pad;
755 for (x=0; x < (ssize_t) number_pixels; x++)
757 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
759 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
760 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
762 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
763 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
765 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
767 q+=quantum_info->pad;
773 register unsigned int
776 range=GetQuantumRange(quantum_info->depth);
777 if (quantum_info->pack == MagickFalse)
779 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
786 pixel=(unsigned int) ScaleQuantumToAny(
787 GetPixelRed(image,p),range);
792 pixel=(unsigned int) ScaleQuantumToAny(
793 GetPixelGreen(image,p),range);
798 pixel=(unsigned int) ScaleQuantumToAny(
799 GetPixelBlue(image,p),range);
804 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
810 pixel=(unsigned int) ScaleQuantumToAny(
811 GetPixelRed(image,p),range);
816 pixel=(unsigned int) ScaleQuantumToAny(
817 GetPixelGreen(image,p),range);
822 pixel=(unsigned int) ScaleQuantumToAny(
823 GetPixelBlue(image,p),range);
828 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
829 q+=quantum_info->pad;
831 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
838 pixel=(unsigned int) ScaleQuantumToAny(
839 GetPixelRed(image,p),range);
844 pixel=(unsigned int) ScaleQuantumToAny(
845 GetPixelGreen(image,p),range);
850 pixel=(unsigned int) ScaleQuantumToAny(
851 GetPixelBlue(image,p),range);
856 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
857 q+=quantum_info->pad;
863 if (quantum_info->quantum == 32UL)
865 for (x=0; x < (ssize_t) number_pixels; x++)
867 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
869 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
871 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
873 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
875 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
877 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
880 q+=quantum_info->pad;
884 for (x=0; x < (ssize_t) number_pixels; x++)
886 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
888 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
889 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
891 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
892 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
894 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
896 q+=quantum_info->pad;
902 register unsigned short
905 if (quantum_info->format == FloatingPointQuantumFormat)
907 for (x=0; x < (ssize_t) number_pixels; x++)
909 pixel=SinglePrecisionToHalf(QuantumScale*
910 GetPixelBlue(image,p));
911 q=PopShortPixel(endian,pixel,q);
912 pixel=SinglePrecisionToHalf(QuantumScale*
913 GetPixelGreen(image,p));
914 q=PopShortPixel(endian,pixel,q);
915 pixel=SinglePrecisionToHalf(QuantumScale*
916 GetPixelRed(image,p));
917 q=PopShortPixel(endian,pixel,q);
919 q+=quantum_info->pad;
923 for (x=0; x < (ssize_t) number_pixels; x++)
925 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
926 q=PopShortPixel(endian,pixel,q);
927 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
928 q=PopShortPixel(endian,pixel,q);
929 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
930 q=PopShortPixel(endian,pixel,q);
932 q+=quantum_info->pad;
938 register unsigned int
941 if (quantum_info->format == FloatingPointQuantumFormat)
943 for (x=0; x < (ssize_t) number_pixels; x++)
945 q=PopFloatPixel(&quantum_state,(float)
946 GetPixelRed(image,p),q);
947 q=PopFloatPixel(&quantum_state,(float)
948 GetPixelGreen(image,p),q);
949 q=PopFloatPixel(&quantum_state,(float)
950 GetPixelBlue(image,p),q);
952 q+=quantum_info->pad;
956 for (x=0; x < (ssize_t) number_pixels; x++)
958 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
959 q=PopLongPixel(endian,pixel,q);
960 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
961 q=PopLongPixel(endian,pixel,q);
962 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
963 q=PopLongPixel(endian,pixel,q);
965 q+=quantum_info->pad;
971 if (quantum_info->format == FloatingPointQuantumFormat)
973 for (x=0; x < (ssize_t) number_pixels; x++)
975 q=PopDoublePixel(&quantum_state,(double)
976 GetPixelRed(image,p),q);
977 q=PopDoublePixel(&quantum_state,(double)
978 GetPixelGreen(image,p),q);
979 q=PopDoublePixel(&quantum_state,(double)
980 GetPixelBlue(image,p),q);
982 q+=quantum_info->pad;
989 range=GetQuantumRange(quantum_info->depth);
990 for (x=0; x < (ssize_t) number_pixels; x++)
992 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
993 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
994 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
995 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
996 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
997 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
999 q+=quantum_info->pad;
1009 switch (quantum_info->depth)
1013 register unsigned char
1016 for (x=0; x < (ssize_t) number_pixels; x++)
1018 pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1019 q=PopCharPixel(pixel,q);
1020 pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1021 q=PopCharPixel(pixel,q);
1022 pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1023 q=PopCharPixel(pixel,q);
1024 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1025 q=PopCharPixel(pixel,q);
1027 q+=quantum_info->pad;
1033 register unsigned int
1036 range=GetQuantumRange(quantum_info->depth);
1037 if (quantum_info->pack == MagickFalse)
1051 for (x=0; x < (ssize_t) number_pixels; x++)
1053 for (i=0; i < 4; i++)
1057 case 0: quantum=GetPixelRed(image,p); break;
1058 case 1: quantum=GetPixelGreen(image,p); break;
1059 case 2: quantum=GetPixelBlue(image,p); break;
1060 case 3: quantum=GetPixelAlpha(image,p); break;
1066 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1072 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1078 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
1080 q=PopLongPixel(endian,pixel,q);
1088 q+=quantum_info->pad;
1092 if (quantum_info->quantum == 32UL)
1094 for (x=0; x < (ssize_t) number_pixels; x++)
1096 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
1098 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1100 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
1102 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1104 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
1106 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1108 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
1110 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
1113 q+=quantum_info->pad;
1117 for (x=0; x < (ssize_t) number_pixels; x++)
1119 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
1121 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1122 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
1124 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1125 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
1127 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1128 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
1130 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
1132 q+=quantum_info->pad;
1138 register unsigned short
1141 if (quantum_info->format == FloatingPointQuantumFormat)
1143 for (x=0; x < (ssize_t) number_pixels; x++)
1145 pixel=SinglePrecisionToHalf(QuantumScale*
1146 GetPixelBlue(image,p));
1147 q=PopShortPixel(endian,pixel,q);
1148 pixel=SinglePrecisionToHalf(QuantumScale*
1149 GetPixelGreen(image,p));
1150 q=PopShortPixel(endian,pixel,q);
1151 pixel=SinglePrecisionToHalf(QuantumScale*
1152 GetPixelRed(image,p));
1153 q=PopShortPixel(endian,pixel,q);
1154 pixel=SinglePrecisionToHalf(QuantumScale*
1155 GetPixelAlpha(image,p));
1156 q=PopShortPixel(endian,pixel,q);
1158 q+=quantum_info->pad;
1162 for (x=0; x < (ssize_t) number_pixels; x++)
1164 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1165 q=PopShortPixel(endian,pixel,q);
1166 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1167 q=PopShortPixel(endian,pixel,q);
1168 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1169 q=PopShortPixel(endian,pixel,q);
1170 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1171 q=PopShortPixel(endian,pixel,q);
1173 q+=quantum_info->pad;
1179 register unsigned int
1182 if (quantum_info->format == FloatingPointQuantumFormat)
1184 for (x=0; x < (ssize_t) number_pixels; x++)
1189 q=PopFloatPixel(&quantum_state,(float)
1190 GetPixelRed(image,p),q);
1191 q=PopFloatPixel(&quantum_state,(float)
1192 GetPixelGreen(image,p),q);
1193 q=PopFloatPixel(&quantum_state,(float)
1194 GetPixelBlue(image,p),q);
1195 pixel=(float) GetPixelAlpha(image,p);
1196 q=PopFloatPixel(&quantum_state,pixel,q);
1198 q+=quantum_info->pad;
1202 for (x=0; x < (ssize_t) number_pixels; x++)
1204 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1205 q=PopLongPixel(endian,pixel,q);
1206 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1207 q=PopLongPixel(endian,pixel,q);
1208 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1209 q=PopLongPixel(endian,pixel,q);
1210 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1211 q=PopLongPixel(endian,pixel,q);
1213 q+=quantum_info->pad;
1219 if (quantum_info->format == FloatingPointQuantumFormat)
1224 for (x=0; x < (ssize_t) number_pixels; x++)
1226 q=PopDoublePixel(&quantum_state,(double)
1227 GetPixelRed(image,p),q);
1228 q=PopDoublePixel(&quantum_state,(double)
1229 GetPixelGreen(image,p),q);
1230 q=PopDoublePixel(&quantum_state,(double)
1231 GetPixelBlue(image,p),q);
1232 pixel=(double) GetPixelAlpha(image,p);
1233 q=PopDoublePixel(&quantum_state,pixel,q);
1235 q+=quantum_info->pad;
1242 range=GetQuantumRange(quantum_info->depth);
1243 for (x=0; x < (ssize_t) number_pixels; x++)
1245 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1246 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
1247 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1248 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
1249 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1250 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
1251 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1252 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
1254 q+=quantum_info->pad;
1263 switch (quantum_info->depth)
1270 register unsigned char
1276 if (quantum_info->min_is_white != MagickFalse)
1281 threshold=(Quantum) (QuantumRange/2);
1282 for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
1285 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 7;
1287 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 6;
1289 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 5;
1291 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 4;
1293 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 3;
1295 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 2;
1297 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 1;
1299 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) << 0;
1303 if ((number_pixels % 8) != 0)
1306 for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
1308 *q|=(GetPixelIntensity(image,p) < threshold ? black : white) <<
1318 register unsigned char
1321 for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
1323 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1324 *q=(((pixel >> 4) & 0xf) << 4);
1326 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1331 if ((number_pixels % 2) != 0)
1333 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1334 *q=(((pixel >> 4) & 0xf) << 4);
1342 register unsigned char
1345 for (x=0; x < (ssize_t) number_pixels; x++)
1347 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1348 q=PopCharPixel(pixel,q);
1350 q+=quantum_info->pad;
1356 range=GetQuantumRange(quantum_info->depth);
1357 if (quantum_info->pack == MagickFalse)
1359 register unsigned int
1362 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1364 pixel=(unsigned int) (
1365 ScaleQuantumToAny(GetPixelIntensity(image,p+2*channels),range) << 22 |
1366 ScaleQuantumToAny(GetPixelIntensity(image,p+channels),range) << 12 |
1367 ScaleQuantumToAny(GetPixelIntensity(image,p),range) << 2);
1368 q=PopLongPixel(endian,pixel,q);
1370 q+=quantum_info->pad;
1372 if (x < (ssize_t) number_pixels)
1375 if (x++ < (ssize_t) (number_pixels-1))
1376 pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p+channels),
1378 if (x++ < (ssize_t) number_pixels)
1379 pixel|=ScaleQuantumToAny(GetPixelIntensity(image,p),
1381 q=PopLongPixel(endian,pixel,q);
1385 for (x=0; x < (ssize_t) number_pixels; x++)
1387 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1388 ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1390 q+=quantum_info->pad;
1396 register unsigned short
1399 range=GetQuantumRange(quantum_info->depth);
1400 if (quantum_info->pack == MagickFalse)
1402 for (x=0; x < (ssize_t) number_pixels; x++)
1404 pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1405 q=PopShortPixel(endian,(unsigned short) (pixel >> 4),q);
1407 q+=quantum_info->pad;
1411 for (x=0; x < (ssize_t) number_pixels; x++)
1413 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1414 ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1416 q+=quantum_info->pad;
1422 register unsigned short
1425 if (quantum_info->format == FloatingPointQuantumFormat)
1427 for (x=0; x < (ssize_t) number_pixels; x++)
1429 pixel=SinglePrecisionToHalf(QuantumScale*
1430 GetPixelIntensity(image,p));
1431 q=PopShortPixel(endian,pixel,q);
1433 q+=quantum_info->pad;
1437 for (x=0; x < (ssize_t) number_pixels; x++)
1439 pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1440 q=PopShortPixel(endian,pixel,q);
1442 q+=quantum_info->pad;
1448 register unsigned int
1451 if (quantum_info->format == FloatingPointQuantumFormat)
1453 for (x=0; x < (ssize_t) number_pixels; x++)
1458 pixel=(float) GetPixelIntensity(image,p);
1459 q=PopFloatPixel(&quantum_state,pixel,q);
1461 q+=quantum_info->pad;
1465 for (x=0; x < (ssize_t) number_pixels; x++)
1467 pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1468 q=PopLongPixel(endian,pixel,q);
1470 q+=quantum_info->pad;
1476 if (quantum_info->format == FloatingPointQuantumFormat)
1478 for (x=0; x < (ssize_t) number_pixels; x++)
1483 pixel=(double) GetPixelIntensity(image,p);
1484 q=PopDoublePixel(&quantum_state,pixel,q);
1486 q+=quantum_info->pad;
1493 range=GetQuantumRange(quantum_info->depth);
1494 for (x=0; x < (ssize_t) number_pixels; x++)
1496 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1497 ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1499 q+=quantum_info->pad;
1506 case GrayAlphaQuantum:
1508 switch (quantum_info->depth)
1515 register unsigned char
1522 if (quantum_info->min_is_white == MagickFalse)
1527 threshold=(Quantum) (QuantumRange/2);
1528 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
1531 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 7;
1532 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1534 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
1536 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 5;
1537 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1539 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
1541 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 3;
1542 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1544 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
1546 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) << 1;
1547 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1549 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
1553 if ((number_pixels % 4) != 0)
1556 for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
1558 *q|=(GetPixelIntensity(image,p) > threshold ? black : white) <<
1560 pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
1562 *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
1572 register unsigned char
1575 for (x=0; x < (ssize_t) number_pixels ; x++)
1577 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1578 *q=(((pixel >> 4) & 0xf) << 4);
1579 pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
1588 register unsigned char
1591 for (x=0; x < (ssize_t) number_pixels; x++)
1593 pixel=ScaleQuantumToChar(GetPixelIntensity(image,p));
1594 q=PopCharPixel(pixel,q);
1595 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
1596 q=PopCharPixel(pixel,q);
1598 q+=quantum_info->pad;
1604 register unsigned short
1607 if (quantum_info->format == FloatingPointQuantumFormat)
1609 for (x=0; x < (ssize_t) number_pixels; x++)
1611 pixel=SinglePrecisionToHalf(QuantumScale*
1612 GetPixelIntensity(image,p));
1613 q=PopShortPixel(endian,pixel,q);
1614 pixel=SinglePrecisionToHalf(QuantumScale*
1615 GetPixelAlpha(image,p));
1616 q=PopShortPixel(endian,pixel,q);
1618 q+=quantum_info->pad;
1622 for (x=0; x < (ssize_t) number_pixels; x++)
1624 pixel=ScaleQuantumToShort(GetPixelIntensity(image,p));
1625 q=PopShortPixel(endian,pixel,q);
1626 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
1627 q=PopShortPixel(endian,pixel,q);
1629 q+=quantum_info->pad;
1635 register unsigned int
1638 if (quantum_info->format == FloatingPointQuantumFormat)
1640 for (x=0; x < (ssize_t) number_pixels; x++)
1645 pixel=(float) GetPixelIntensity(image,p);
1646 q=PopFloatPixel(&quantum_state,pixel,q);
1647 pixel=(float) (GetPixelAlpha(image,p));
1648 q=PopFloatPixel(&quantum_state,pixel,q);
1650 q+=quantum_info->pad;
1654 for (x=0; x < (ssize_t) number_pixels; x++)
1656 pixel=ScaleQuantumToLong(GetPixelIntensity(image,p));
1657 q=PopLongPixel(endian,pixel,q);
1658 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1659 q=PopLongPixel(endian,pixel,q);
1661 q+=quantum_info->pad;
1667 if (quantum_info->format == FloatingPointQuantumFormat)
1669 for (x=0; x < (ssize_t) number_pixels; x++)
1674 pixel=(double) GetPixelIntensity(image,p);
1675 q=PopDoublePixel(&quantum_state,pixel,q);
1676 pixel=(double) (GetPixelAlpha(image,p));
1677 q=PopDoublePixel(&quantum_state,pixel,q);
1679 q+=quantum_info->pad;
1686 range=GetQuantumRange(quantum_info->depth);
1687 for (x=0; x < (ssize_t) number_pixels; x++)
1689 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1690 ScaleQuantumToAny(GetPixelIntensity(image,p),range),q);
1691 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1692 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
1694 q+=quantum_info->pad;
1704 switch (quantum_info->depth)
1708 register unsigned char
1711 for (x=0; x < (ssize_t) number_pixels; x++)
1713 pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1714 q=PopCharPixel(pixel,q);
1716 q+=quantum_info->pad;
1722 register unsigned short
1725 if (quantum_info->format == FloatingPointQuantumFormat)
1727 for (x=0; x < (ssize_t) number_pixels; x++)
1729 pixel=SinglePrecisionToHalf(QuantumScale*
1730 GetPixelRed(image,p));
1731 q=PopShortPixel(endian,pixel,q);
1733 q+=quantum_info->pad;
1737 for (x=0; x < (ssize_t) number_pixels; x++)
1739 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1740 q=PopShortPixel(endian,pixel,q);
1742 q+=quantum_info->pad;
1748 register unsigned int
1751 if (quantum_info->format == FloatingPointQuantumFormat)
1753 for (x=0; x < (ssize_t) number_pixels; x++)
1755 q=PopFloatPixel(&quantum_state,(float)
1756 GetPixelRed(image,p),q);
1758 q+=quantum_info->pad;
1762 for (x=0; x < (ssize_t) number_pixels; x++)
1764 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1765 q=PopLongPixel(endian,pixel,q);
1767 q+=quantum_info->pad;
1773 if (quantum_info->format == FloatingPointQuantumFormat)
1775 for (x=0; x < (ssize_t) number_pixels; x++)
1777 q=PopDoublePixel(&quantum_state,(double)
1778 GetPixelRed(image,p),q);
1780 q+=quantum_info->pad;
1787 range=GetQuantumRange(quantum_info->depth);
1788 for (x=0; x < (ssize_t) number_pixels; x++)
1790 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1791 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
1793 q+=quantum_info->pad;
1801 case MagentaQuantum:
1803 switch (quantum_info->depth)
1807 register unsigned char
1810 for (x=0; x < (ssize_t) number_pixels; x++)
1812 pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1813 q=PopCharPixel(pixel,q);
1815 q+=quantum_info->pad;
1821 register unsigned short
1824 if (quantum_info->format == FloatingPointQuantumFormat)
1826 for (x=0; x < (ssize_t) number_pixels; x++)
1828 pixel=SinglePrecisionToHalf(QuantumScale*
1829 GetPixelGreen(image,p));
1830 q=PopShortPixel(endian,pixel,q);
1832 q+=quantum_info->pad;
1836 for (x=0; x < (ssize_t) number_pixels; x++)
1838 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1839 q=PopShortPixel(endian,pixel,q);
1841 q+=quantum_info->pad;
1847 register unsigned int
1850 if (quantum_info->format == FloatingPointQuantumFormat)
1852 for (x=0; x < (ssize_t) number_pixels; x++)
1854 q=PopFloatPixel(&quantum_state,(float)
1855 GetPixelGreen(image,p),q);
1857 q+=quantum_info->pad;
1861 for (x=0; x < (ssize_t) number_pixels; x++)
1863 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1864 q=PopLongPixel(endian,pixel,q);
1866 q+=quantum_info->pad;
1872 if (quantum_info->format == FloatingPointQuantumFormat)
1874 for (x=0; x < (ssize_t) number_pixels; x++)
1876 q=PopDoublePixel(&quantum_state,(double)
1877 GetPixelGreen(image,p),q);
1879 q+=quantum_info->pad;
1886 range=GetQuantumRange(quantum_info->depth);
1887 for (x=0; x < (ssize_t) number_pixels; x++)
1889 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1890 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
1892 q+=quantum_info->pad;
1902 switch (quantum_info->depth)
1906 register unsigned char
1909 for (x=0; x < (ssize_t) number_pixels; x++)
1911 pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1912 q=PopCharPixel(pixel,q);
1914 q+=quantum_info->pad;
1920 register unsigned short
1923 if (quantum_info->format == FloatingPointQuantumFormat)
1925 for (x=0; x < (ssize_t) number_pixels; x++)
1927 pixel=SinglePrecisionToHalf(QuantumScale*
1928 GetPixelBlue(image,p));
1929 q=PopShortPixel(endian,pixel,q);
1931 q+=quantum_info->pad;
1935 for (x=0; x < (ssize_t) number_pixels; x++)
1937 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1938 q=PopShortPixel(endian,pixel,q);
1940 q+=quantum_info->pad;
1946 register unsigned int
1949 if (quantum_info->format == FloatingPointQuantumFormat)
1951 for (x=0; x < (ssize_t) number_pixels; x++)
1953 q=PopFloatPixel(&quantum_state,(float)
1954 GetPixelBlue(image,p),q);
1956 q+=quantum_info->pad;
1960 for (x=0; x < (ssize_t) number_pixels; x++)
1962 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1963 q=PopLongPixel(endian,pixel,q);
1965 q+=quantum_info->pad;
1971 if (quantum_info->format == FloatingPointQuantumFormat)
1973 for (x=0; x < (ssize_t) number_pixels; x++)
1975 q=PopDoublePixel(&quantum_state,(double)
1976 GetPixelBlue(image,p),q);
1978 q+=quantum_info->pad;
1985 range=GetQuantumRange(quantum_info->depth);
1986 for (x=0; x < (ssize_t) number_pixels; x++)
1988 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
1989 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
1991 q+=quantum_info->pad;
2000 switch (quantum_info->depth)
2004 register unsigned char
2007 for (x=0; x < (ssize_t) number_pixels; x++)
2009 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2010 q=PopCharPixel(pixel,q);
2012 q+=quantum_info->pad;
2018 register unsigned short
2021 if (quantum_info->format == FloatingPointQuantumFormat)
2023 for (x=0; x < (ssize_t) number_pixels; x++)
2025 pixel=SinglePrecisionToHalf(QuantumScale*
2026 GetPixelAlpha(image,p));
2027 q=PopShortPixel(endian,pixel,q);
2029 q+=quantum_info->pad;
2033 for (x=0; x < (ssize_t) number_pixels; x++)
2035 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2036 q=PopShortPixel(endian,pixel,q);
2038 q+=quantum_info->pad;
2044 register unsigned int
2047 if (quantum_info->format == FloatingPointQuantumFormat)
2049 for (x=0; x < (ssize_t) number_pixels; x++)
2054 pixel=(float) GetPixelAlpha(image,p);
2055 q=PopFloatPixel(&quantum_state,pixel,q);
2057 q+=quantum_info->pad;
2061 for (x=0; x < (ssize_t) number_pixels; x++)
2063 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2064 q=PopLongPixel(endian,pixel,q);
2066 q+=quantum_info->pad;
2072 if (quantum_info->format == FloatingPointQuantumFormat)
2074 for (x=0; x < (ssize_t) number_pixels; x++)
2079 pixel=(double) (GetPixelAlpha(image,p));
2080 q=PopDoublePixel(&quantum_state,pixel,q);
2082 q+=quantum_info->pad;
2089 range=GetQuantumRange(quantum_info->depth);
2090 for (x=0; x < (ssize_t) number_pixels; x++)
2092 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2093 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2095 q+=quantum_info->pad;
2102 case OpacityQuantum:
2104 switch (quantum_info->depth)
2108 register unsigned char
2111 for (x=0; x < (ssize_t) number_pixels; x++)
2113 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2114 q=PopCharPixel(pixel,q);
2116 q+=quantum_info->pad;
2122 register unsigned short
2125 if (quantum_info->format == FloatingPointQuantumFormat)
2127 for (x=0; x < (ssize_t) number_pixels; x++)
2129 pixel=SinglePrecisionToHalf(QuantumScale*
2130 GetPixelAlpha(image,p));
2131 q=PopShortPixel(endian,pixel,q);
2133 q+=quantum_info->pad;
2137 for (x=0; x < (ssize_t) number_pixels; x++)
2139 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2140 q=PopShortPixel(endian,pixel,q);
2142 q+=quantum_info->pad;
2148 register unsigned int
2151 if (quantum_info->format == FloatingPointQuantumFormat)
2153 for (x=0; x < (ssize_t) number_pixels; x++)
2155 q=PopFloatPixel(&quantum_state,(float)
2156 GetPixelAlpha(image,p),q);
2158 q+=quantum_info->pad;
2162 for (x=0; x < (ssize_t) number_pixels; x++)
2164 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2165 q=PopLongPixel(endian,pixel,q);
2167 q+=quantum_info->pad;
2173 if (quantum_info->format == FloatingPointQuantumFormat)
2175 for (x=0; x < (ssize_t) number_pixels; x++)
2177 q=PopDoublePixel(&quantum_state,(double)
2178 GetPixelAlpha(image,p),q);
2180 q+=quantum_info->pad;
2187 range=GetQuantumRange(quantum_info->depth);
2188 for (x=0; x < (ssize_t) number_pixels; x++)
2190 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2191 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2193 q+=quantum_info->pad;
2202 if (image->colorspace != CMYKColorspace)
2204 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2205 "ColorSeparatedImageRequired","`%s'",image->filename);
2208 switch (quantum_info->depth)
2212 register unsigned char
2215 for (x=0; x < (ssize_t) number_pixels; x++)
2217 pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2218 q=PopCharPixel(pixel,q);
2220 q+=quantum_info->pad;
2226 register unsigned short
2229 if (quantum_info->format == FloatingPointQuantumFormat)
2231 for (x=0; x < (ssize_t) number_pixels; x++)
2233 pixel=SinglePrecisionToHalf(QuantumScale*
2234 GetPixelBlack(image,p));
2235 q=PopShortPixel(endian,pixel,q);
2237 q+=quantum_info->pad;
2241 for (x=0; x < (ssize_t) number_pixels; x++)
2243 pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2244 q=PopShortPixel(endian,pixel,q);
2246 q+=quantum_info->pad;
2252 register unsigned int
2255 if (quantum_info->format == FloatingPointQuantumFormat)
2257 for (x=0; x < (ssize_t) number_pixels; x++)
2259 q=PopFloatPixel(&quantum_state,(float)
2260 GetPixelBlack(image,p),q);
2262 q+=quantum_info->pad;
2266 for (x=0; x < (ssize_t) number_pixels; x++)
2268 pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2269 q=PopLongPixel(endian,pixel,q);
2271 q+=quantum_info->pad;
2277 if (quantum_info->format == FloatingPointQuantumFormat)
2279 for (x=0; x < (ssize_t) number_pixels; x++)
2281 q=PopDoublePixel(&quantum_state,(double)
2282 GetPixelBlack(image,p),q);
2284 q+=quantum_info->pad;
2291 range=GetQuantumRange(quantum_info->depth);
2292 for (x=0; x < (ssize_t) number_pixels; x++)
2294 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2295 ScaleQuantumToAny((Quantum) GetPixelBlack(image,p),range),q);
2297 q+=quantum_info->pad;
2307 switch (quantum_info->depth)
2311 for (x=0; x < (ssize_t) number_pixels; x++)
2313 q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
2314 q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
2315 q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
2317 q+=quantum_info->pad;
2323 register unsigned int
2326 range=GetQuantumRange(quantum_info->depth);
2327 if (quantum_info->pack == MagickFalse)
2329 for (x=0; x < (ssize_t) number_pixels; x++)
2331 pixel=(unsigned int) (
2332 ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
2333 ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
2334 ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
2335 q=PopLongPixel(endian,pixel,q);
2337 q+=quantum_info->pad;
2341 if (quantum_info->quantum == 32UL)
2343 for (x=0; x < (ssize_t) number_pixels; x++)
2345 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2347 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2349 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2351 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2353 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2355 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2358 q+=quantum_info->pad;
2362 for (x=0; x < (ssize_t) number_pixels; x++)
2364 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2366 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2367 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2369 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2370 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2372 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2374 q+=quantum_info->pad;
2380 register unsigned int
2383 range=GetQuantumRange(quantum_info->depth);
2384 if (quantum_info->pack == MagickFalse)
2386 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
2393 pixel=(unsigned int) ScaleQuantumToAny(
2394 GetPixelRed(image,p),range);
2399 pixel=(unsigned int) ScaleQuantumToAny(
2400 GetPixelGreen(image,p),range);
2405 pixel=(unsigned int) ScaleQuantumToAny(
2406 GetPixelBlue(image,p),range);
2411 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2417 pixel=(unsigned int) ScaleQuantumToAny(
2418 GetPixelRed(image,p),range);
2423 pixel=(unsigned int) ScaleQuantumToAny(
2424 GetPixelGreen(image,p),range);
2429 pixel=(unsigned int) ScaleQuantumToAny(
2430 GetPixelBlue(image,p),range);
2435 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2436 q+=quantum_info->pad;
2438 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
2440 switch ((x+bit) % 3)
2445 pixel=(unsigned int) ScaleQuantumToAny(
2446 GetPixelRed(image,p),range);
2451 pixel=(unsigned int) ScaleQuantumToAny(
2452 GetPixelGreen(image,p),range);
2457 pixel=(unsigned int) ScaleQuantumToAny(
2458 GetPixelBlue(image,p),range);
2463 q=PopShortPixel(endian,(unsigned short) (pixel << 4),q);
2464 q+=quantum_info->pad;
2470 if (quantum_info->quantum == 32UL)
2472 for (x=0; x < (ssize_t) number_pixels; x++)
2474 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2476 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2478 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2480 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2482 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2484 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2487 q+=quantum_info->pad;
2491 for (x=0; x < (ssize_t) number_pixels; x++)
2493 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2495 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2496 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2498 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2499 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2501 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2503 q+=quantum_info->pad;
2509 register unsigned short
2512 if (quantum_info->format == FloatingPointQuantumFormat)
2514 for (x=0; x < (ssize_t) number_pixels; x++)
2516 pixel=SinglePrecisionToHalf(QuantumScale*
2517 GetPixelRed(image,p));
2518 q=PopShortPixel(endian,pixel,q);
2519 pixel=SinglePrecisionToHalf(QuantumScale*
2520 GetPixelGreen(image,p));
2521 q=PopShortPixel(endian,pixel,q);
2522 pixel=SinglePrecisionToHalf(QuantumScale*
2523 GetPixelBlue(image,p));
2524 q=PopShortPixel(endian,pixel,q);
2526 q+=quantum_info->pad;
2530 for (x=0; x < (ssize_t) number_pixels; x++)
2532 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2533 q=PopShortPixel(endian,pixel,q);
2534 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2535 q=PopShortPixel(endian,pixel,q);
2536 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2537 q=PopShortPixel(endian,pixel,q);
2539 q+=quantum_info->pad;
2545 register unsigned int
2548 if (quantum_info->format == FloatingPointQuantumFormat)
2550 for (x=0; x < (ssize_t) number_pixels; x++)
2552 q=PopFloatPixel(&quantum_state,(float)
2553 GetPixelRed(image,p),q);
2554 q=PopFloatPixel(&quantum_state,(float)
2555 GetPixelGreen(image,p),q);
2556 q=PopFloatPixel(&quantum_state,(float)
2557 GetPixelBlue(image,p),q);
2559 q+=quantum_info->pad;
2563 for (x=0; x < (ssize_t) number_pixels; x++)
2565 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2566 q=PopLongPixel(endian,pixel,q);
2567 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2568 q=PopLongPixel(endian,pixel,q);
2569 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2570 q=PopLongPixel(endian,pixel,q);
2572 q+=quantum_info->pad;
2578 if (quantum_info->format == FloatingPointQuantumFormat)
2580 for (x=0; x < (ssize_t) number_pixels; x++)
2582 q=PopDoublePixel(&quantum_state,(double)
2583 GetPixelRed(image,p),q);
2584 q=PopDoublePixel(&quantum_state,(double)
2585 GetPixelGreen(image,p),q);
2586 q=PopDoublePixel(&quantum_state,(double)
2587 GetPixelBlue(image,p),q);
2589 q+=quantum_info->pad;
2596 range=GetQuantumRange(quantum_info->depth);
2597 for (x=0; x < (ssize_t) number_pixels; x++)
2599 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2600 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2601 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2602 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2603 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2604 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2606 q+=quantum_info->pad;
2617 switch (quantum_info->depth)
2621 register unsigned char
2624 for (x=0; x < (ssize_t) number_pixels; x++)
2626 pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2627 q=PopCharPixel(pixel,q);
2628 pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2629 q=PopCharPixel(pixel,q);
2630 pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2631 q=PopCharPixel(pixel,q);
2632 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2633 q=PopCharPixel(pixel,q);
2635 q+=quantum_info->pad;
2641 register unsigned int
2644 range=GetQuantumRange(quantum_info->depth);
2645 if (quantum_info->pack == MagickFalse)
2659 for (x=0; x < (ssize_t) number_pixels; x++)
2661 for (i=0; i < 4; i++)
2665 case 0: quantum=GetPixelRed(image,p); break;
2666 case 1: quantum=GetPixelGreen(image,p); break;
2667 case 2: quantum=GetPixelBlue(image,p); break;
2668 case 3: quantum=GetPixelAlpha(image,p); break;
2674 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2680 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2686 pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
2688 q=PopLongPixel(endian,pixel,q);
2696 q+=quantum_info->pad;
2700 if (quantum_info->quantum == 32UL)
2702 for (x=0; x < (ssize_t) number_pixels; x++)
2704 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
2706 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2708 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2710 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2712 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
2714 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2716 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2718 q=PopQuantumLongPixel(&quantum_state,quantum_info->depth,pixel,
2721 q+=quantum_info->pad;
2725 for (x=0; x < (ssize_t) number_pixels; x++)
2727 pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
2728 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2729 pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
2731 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2732 pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
2733 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2734 pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
2736 q=PopQuantumPixel(&quantum_state,quantum_info->depth,pixel,q);
2738 q+=quantum_info->pad;
2744 register unsigned short
2747 if (quantum_info->format == FloatingPointQuantumFormat)
2749 for (x=0; x < (ssize_t) number_pixels; x++)
2751 pixel=SinglePrecisionToHalf(QuantumScale*
2752 GetPixelRed(image,p));
2753 q=PopShortPixel(endian,pixel,q);
2754 pixel=SinglePrecisionToHalf(QuantumScale*
2755 GetPixelGreen(image,p));
2756 q=PopShortPixel(endian,pixel,q);
2757 pixel=SinglePrecisionToHalf(QuantumScale*
2758 GetPixelBlue(image,p));
2759 q=PopShortPixel(endian,pixel,q);
2760 pixel=SinglePrecisionToHalf(QuantumScale*
2761 GetPixelAlpha(image,p));
2762 q=PopShortPixel(endian,pixel,q);
2764 q+=quantum_info->pad;
2768 for (x=0; x < (ssize_t) number_pixels; x++)
2770 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2771 q=PopShortPixel(endian,pixel,q);
2772 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2773 q=PopShortPixel(endian,pixel,q);
2774 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2775 q=PopShortPixel(endian,pixel,q);
2776 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2777 q=PopShortPixel(endian,pixel,q);
2779 q+=quantum_info->pad;
2785 register unsigned int
2788 if (quantum_info->format == FloatingPointQuantumFormat)
2790 for (x=0; x < (ssize_t) number_pixels; x++)
2795 q=PopFloatPixel(&quantum_state,(float)
2796 GetPixelRed(image,p),q);
2797 q=PopFloatPixel(&quantum_state,(float)
2798 GetPixelGreen(image,p),q);
2799 q=PopFloatPixel(&quantum_state,(float)
2800 GetPixelBlue(image,p),q);
2801 pixel=(float) GetPixelAlpha(image,p);
2802 q=PopFloatPixel(&quantum_state,pixel,q);
2804 q+=quantum_info->pad;
2808 for (x=0; x < (ssize_t) number_pixels; x++)
2810 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2811 q=PopLongPixel(endian,pixel,q);
2812 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2813 q=PopLongPixel(endian,pixel,q);
2814 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2815 q=PopLongPixel(endian,pixel,q);
2816 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2817 q=PopLongPixel(endian,pixel,q);
2819 q+=quantum_info->pad;
2825 if (quantum_info->format == FloatingPointQuantumFormat)
2830 for (x=0; x < (ssize_t) number_pixels; x++)
2832 q=PopDoublePixel(&quantum_state,(double)
2833 GetPixelRed(image,p),q);
2834 q=PopDoublePixel(&quantum_state,(double)
2835 GetPixelGreen(image,p),q);
2836 q=PopDoublePixel(&quantum_state,(double)
2837 GetPixelBlue(image,p),q);
2838 pixel=(double) GetPixelAlpha(image,p);
2839 q=PopDoublePixel(&quantum_state,pixel,q);
2841 q+=quantum_info->pad;
2848 range=GetQuantumRange(quantum_info->depth);
2849 for (x=0; x < (ssize_t) number_pixels; x++)
2851 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2852 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
2853 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2854 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
2855 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2856 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
2857 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
2858 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
2860 q+=quantum_info->pad;
2869 if (image->colorspace != CMYKColorspace)
2871 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2872 "ColorSeparatedImageRequired","`%s'",image->filename);
2875 switch (quantum_info->depth)
2879 register unsigned char
2882 for (x=0; x < (ssize_t) number_pixels; x++)
2884 pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2885 q=PopCharPixel(pixel,q);
2886 pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2887 q=PopCharPixel(pixel,q);
2888 pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
2889 q=PopCharPixel(pixel,q);
2890 pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
2891 q=PopCharPixel(pixel,q);
2893 q+=quantum_info->pad;
2899 register unsigned short
2902 if (quantum_info->format == FloatingPointQuantumFormat)
2904 for (x=0; x < (ssize_t) number_pixels; x++)
2906 pixel=SinglePrecisionToHalf(QuantumScale*
2907 GetPixelRed(image,p));
2908 q=PopShortPixel(endian,pixel,q);
2909 pixel=SinglePrecisionToHalf(QuantumScale*
2910 GetPixelGreen(image,p));
2911 q=PopShortPixel(endian,pixel,q);
2912 pixel=SinglePrecisionToHalf(QuantumScale*
2913 GetPixelBlue(image,p));
2914 q=PopShortPixel(endian,pixel,q);
2915 pixel=SinglePrecisionToHalf(QuantumScale*
2916 GetPixelBlack(image,p));
2917 q=PopShortPixel(endian,pixel,q);
2919 q+=quantum_info->pad;
2923 for (x=0; x < (ssize_t) number_pixels; x++)
2925 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
2926 q=PopShortPixel(endian,pixel,q);
2927 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2928 q=PopShortPixel(endian,pixel,q);
2929 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
2930 q=PopShortPixel(endian,pixel,q);
2931 pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
2932 q=PopShortPixel(endian,pixel,q);
2934 q+=quantum_info->pad;
2940 register unsigned int
2943 if (quantum_info->format == FloatingPointQuantumFormat)
2945 for (x=0; x < (ssize_t) number_pixels; x++)
2947 q=PopFloatPixel(&quantum_state,(float)
2948 GetPixelRed(image,p),q);
2949 q=PopFloatPixel(&quantum_state,(float)
2950 GetPixelGreen(image,p),q);
2951 q=PopFloatPixel(&quantum_state,(float)
2952 GetPixelBlue(image,p),q);
2953 q=PopFloatPixel(&quantum_state,(float)
2954 GetPixelBlack(image,p),q);
2956 q+=quantum_info->pad;
2960 for (x=0; x < (ssize_t) number_pixels; x++)
2962 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
2963 q=PopLongPixel(endian,pixel,q);
2964 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2965 q=PopLongPixel(endian,pixel,q);
2966 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
2967 q=PopLongPixel(endian,pixel,q);
2968 pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
2969 q=PopLongPixel(endian,pixel,q);
2971 q+=quantum_info->pad;
2977 if (quantum_info->format == FloatingPointQuantumFormat)
2979 for (x=0; x < (ssize_t) number_pixels; x++)
2981 q=PopDoublePixel(&quantum_state,(double)
2982 GetPixelRed(image,p),q);
2983 q=PopDoublePixel(&quantum_state,(double)
2984 GetPixelGreen(image,p),q);
2985 q=PopDoublePixel(&quantum_state,(double)
2986 GetPixelBlue(image,p),q);
2987 q=PopDoublePixel(&quantum_state,(double)
2988 GetPixelBlack(image,p),q);
2990 q+=quantum_info->pad;
2997 range=GetQuantumRange(quantum_info->depth);
2998 for (x=0; x < (ssize_t) number_pixels; x++)
3000 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3001 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
3002 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3003 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3004 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3005 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3006 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3007 ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3009 q+=quantum_info->pad;
3019 if (image->colorspace != CMYKColorspace)
3021 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3022 "ColorSeparatedImageRequired","`%s'",image->filename);
3025 switch (quantum_info->depth)
3029 register unsigned char
3032 for (x=0; x < (ssize_t) number_pixels; x++)
3034 pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3035 q=PopCharPixel(pixel,q);
3036 pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3037 q=PopCharPixel(pixel,q);
3038 pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3039 q=PopCharPixel(pixel,q);
3040 pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
3041 q=PopCharPixel(pixel,q);
3042 pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
3043 q=PopCharPixel(pixel,q);
3045 q+=quantum_info->pad;
3051 register unsigned short
3054 if (quantum_info->format == FloatingPointQuantumFormat)
3056 for (x=0; x < (ssize_t) number_pixels; x++)
3058 pixel=SinglePrecisionToHalf(QuantumScale*
3059 GetPixelRed(image,p));
3060 q=PopShortPixel(endian,pixel,q);
3061 pixel=SinglePrecisionToHalf(QuantumScale*
3062 GetPixelGreen(image,p));
3063 q=PopShortPixel(endian,pixel,q);
3064 pixel=SinglePrecisionToHalf(QuantumScale*
3065 GetPixelBlue(image,p));
3066 q=PopShortPixel(endian,pixel,q);
3067 pixel=SinglePrecisionToHalf(QuantumScale*
3068 GetPixelBlack(image,p));
3069 q=PopShortPixel(endian,pixel,q);
3070 pixel=SinglePrecisionToHalf(QuantumScale*
3071 GetPixelAlpha(image,p));
3072 q=PopShortPixel(endian,pixel,q);
3074 q+=quantum_info->pad;
3078 for (x=0; x < (ssize_t) number_pixels; x++)
3080 pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3081 q=PopShortPixel(endian,pixel,q);
3082 pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3083 q=PopShortPixel(endian,pixel,q);
3084 pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3085 q=PopShortPixel(endian,pixel,q);
3086 pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
3087 q=PopShortPixel(endian,pixel,q);
3088 pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
3089 q=PopShortPixel(endian,pixel,q);
3091 q+=quantum_info->pad;
3097 register unsigned int
3100 if (quantum_info->format == FloatingPointQuantumFormat)
3102 for (x=0; x < (ssize_t) number_pixels; x++)
3107 q=PopFloatPixel(&quantum_state,(float)
3108 GetPixelRed(image,p),q);
3109 q=PopFloatPixel(&quantum_state,(float)
3110 GetPixelGreen(image,p),q);
3111 q=PopFloatPixel(&quantum_state,(float)
3112 GetPixelBlue(image,p),q);
3113 q=PopFloatPixel(&quantum_state,(float)
3114 GetPixelBlack(image,p),q);
3115 pixel=(float) (GetPixelAlpha(image,p));
3116 q=PopFloatPixel(&quantum_state,pixel,q);
3118 q+=quantum_info->pad;
3122 for (x=0; x < (ssize_t) number_pixels; x++)
3124 pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3125 q=PopLongPixel(endian,pixel,q);
3126 pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3127 q=PopLongPixel(endian,pixel,q);
3128 pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3129 q=PopLongPixel(endian,pixel,q);
3130 pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
3131 q=PopLongPixel(endian,pixel,q);
3132 pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
3133 q=PopLongPixel(endian,pixel,q);
3135 q+=quantum_info->pad;
3141 if (quantum_info->format == FloatingPointQuantumFormat)
3146 for (x=0; x < (ssize_t) number_pixels; x++)
3148 q=PopDoublePixel(&quantum_state,(double)
3149 GetPixelRed(image,p),q);
3150 q=PopDoublePixel(&quantum_state,(double)
3151 GetPixelGreen(image,p),q);
3152 q=PopDoublePixel(&quantum_state,(double)
3153 GetPixelBlue(image,p),q);
3154 q=PopDoublePixel(&quantum_state,(double)
3155 GetPixelBlack(image,p),q);
3156 pixel=(double) (GetPixelAlpha(image,p));
3157 q=PopDoublePixel(&quantum_state,pixel,q);
3159 q+=quantum_info->pad;
3166 range=GetQuantumRange(quantum_info->depth);
3167 for (x=0; x < (ssize_t) number_pixels; x++)
3169 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3170 ScaleQuantumToAny(GetPixelRed(image,p),range),q);
3171 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3172 ScaleQuantumToAny(GetPixelGreen(image,p),range),q);
3173 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3174 ScaleQuantumToAny(GetPixelBlue(image,p),range),q);
3175 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3176 ScaleQuantumToAny(GetPixelBlack(image,p),range),q);
3177 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3178 ScaleQuantumToAny(GetPixelAlpha(image,p),range),q);
3180 q+=quantum_info->pad;
3195 register unsigned int
3206 range=GetQuantumRange(quantum_info->depth);
3207 switch (quantum_info->depth)
3211 if (quantum_info->pack == MagickFalse)
3213 for (x=0; x < (ssize_t) number_pixels; x+=2)
3215 for (i=0; i < 4; i++)
3221 quantum=GetPixelRed(image,p);
3226 quantum=GetPixelGreen(image,p);
3231 quantum=GetPixelBlue(image,p);
3235 cbcr[i]=(Quantum) quantum;
3238 pixel=(unsigned int) ((size_t) (cbcr[1]) << 22 | (size_t)
3239 (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3240 q=PopLongPixel(endian,pixel,q);
3242 pixel=(unsigned int) ((size_t) (cbcr[3]) << 22 | (size_t)
3243 (cbcr[0]) << 12 | (size_t) (cbcr[2]) << 2);
3244 q=PopLongPixel(endian,pixel,q);
3246 q+=quantum_info->pad;
3254 for (x=0; x < (ssize_t) number_pixels; x+=2)
3256 for (i=0; i < 4; i++)
3262 quantum=GetPixelRed(image,p);
3267 quantum=GetPixelGreen(image,p);
3272 quantum=GetPixelBlue(image,p);
3276 cbcr[i]=(Quantum) quantum;
3279 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3280 ScaleQuantumToAny(cbcr[1],range),q);
3281 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3282 ScaleQuantumToAny(cbcr[0],range),q);
3283 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3284 ScaleQuantumToAny(cbcr[2],range),q);
3286 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3287 ScaleQuantumToAny(cbcr[3],range),q);
3288 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3289 ScaleQuantumToAny(cbcr[0],range),q);
3290 q=PopQuantumPixel(&quantum_state,quantum_info->depth,
3291 ScaleQuantumToAny(cbcr[2],range),q);
3293 q+=quantum_info->pad;
3303 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3311 q=GetAuthenticPixelQueue(image);
3312 if (image_view != (CacheView *) NULL)
3313 q=GetCacheViewAuthenticPixelQueue(image_view);
3314 for (x=0; x < (ssize_t) number_pixels; x++)
3316 quantum=GetPixelRed(image,q);
3317 SetPixelRed(image,GetPixelGreen(image,q),q);
3318 SetPixelGreen(image,quantum,q);
3322 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum) ||
3323 (quantum_type == BGROQuantum))
3328 q=GetAuthenticPixelQueue(image);
3329 if (image_view != (CacheView *) NULL)
3330 q=GetCacheViewAuthenticPixelQueue(image_view);
3331 for (x=0; x < (ssize_t) number_pixels; x++)
3333 SetPixelAlpha(image,GetPixelAlpha(image,q),q);