2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % QQQ U U AAA N N TTTTT U U M M %
7 % Q Q U U A A NN N T U U MM MM %
8 % Q Q U U AAAAA N N N T U U M M M %
9 % Q QQ U U A A N NN T U U M M %
10 % QQQQ UUU A A N N T UUU M M %
12 % IIIII M M PPPP OOO RRRR TTTTT %
13 % I MM MM P P O O R R T %
14 % I M M M PPPP O O RRRR T %
16 % IIIII M M P OOO R R T %
18 % MagickCore Methods to Import Quantum Pixels %
25 % Copyright 1999-2008 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
31 % http://www.imagemagick.org/script/license.php %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 #include "magick/studio.h"
48 #include "magick/property.h"
49 #include "magick/blob.h"
50 #include "magick/blob-private.h"
51 #include "magick/color-private.h"
52 #include "magick/exception.h"
53 #include "magick/exception-private.h"
54 #include "magick/cache.h"
55 #include "magick/constitute.h"
56 #include "magick/delegate.h"
57 #include "magick/geometry.h"
58 #include "magick/list.h"
59 #include "magick/magick.h"
60 #include "magick/memory_.h"
61 #include "magick/monitor.h"
62 #include "magick/option.h"
63 #include "magick/pixel.h"
64 #include "magick/pixel-private.h"
65 #include "magick/quantum.h"
66 #include "magick/quantum-private.h"
67 #include "magick/resource_.h"
68 #include "magick/semaphore.h"
69 #include "magick/statistic.h"
70 #include "magick/stream.h"
71 #include "magick/string_.h"
72 #include "magick/utility.h"
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 % I m p o r t Q u a n t u m P i x e l s %
83 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 % ImportQuantumPixels() transfers one or more pixel components from a user
86 % supplied buffer into the image pixel cache of an image. The pixels are
87 % expected in network byte order. It returns MagickTrue if the pixels are
88 % successfully transferred, otherwise MagickFalse.
90 % The format of the ImportQuantumPixels method is:
92 % size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93 % const QuantumInfo *quantum_info,const QuantumType quantum_type,
94 % const unsigned char *pixels,ExceptionInfo *exception)
96 % A description of each parameter follows:
100 % o image_view: the image cache view.
102 % o quantum_info: the quantum info.
104 % o quantum_type: Declare which pixel components to transfer (red, green,
105 % blue, opacity, RGB, or RGBA).
107 % o pixels: The pixel components are transferred from this buffer.
109 % o exception: return any errors or warnings in this structure.
113 static inline IndexPacket PushColormapIndex(Image *image,
114 const size_t index,MagickBooleanType *range_exception)
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
122 static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
131 if (quantum_state->endian != LSBEndian)
133 quantum[7]=(*pixels++);
134 quantum[6]=(*pixels++);
135 quantum[5]=(*pixels++);
136 quantum[5]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[2]=(*pixels++);
139 quantum[1]=(*pixels++);
140 quantum[0]=(*pixels++);
141 p=(double *) quantum;
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
147 quantum[0]=(*pixels++);
148 quantum[1]=(*pixels++);
149 quantum[2]=(*pixels++);
150 quantum[3]=(*pixels++);
151 quantum[4]=(*pixels++);
152 quantum[5]=(*pixels++);
153 quantum[6]=(*pixels++);
154 quantum[7]=(*pixels++);
155 p=(double *) quantum;
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
162 static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
171 if (quantum_state->endian != LSBEndian)
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
194 static inline const unsigned char *PushQuantumPixel(
195 QuantumState *quantum_state,const size_t depth,
196 const unsigned char *pixels,unsigned int *quantum)
204 *quantum=(QuantumAny) 0;
205 for (i=(ssize_t) depth; i > 0L; )
207 if (quantum_state->bits == 0UL)
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
212 quantum_bits=(size_t) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
215 i-=(ssize_t) quantum_bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(unsigned int) ((*quantum << quantum_bits) |
218 ((quantum_state->pixel >> quantum_state->bits) &~ ((~0UL) <<
224 static inline const unsigned char *PushQuantumLongPixel(
225 QuantumState *quantum_state,const size_t depth,
226 const unsigned char *pixels,unsigned int *quantum)
235 for (i=(ssize_t) depth; i > 0; )
237 if (quantum_state->bits == 0)
239 pixels=PushLongPixel(quantum_state->endian,pixels,
240 &quantum_state->pixel);
241 quantum_state->bits=32U;
243 quantum_bits=(size_t) i;
244 if (quantum_bits > quantum_state->bits)
245 quantum_bits=quantum_state->bits;
246 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
247 quantum_state->mask[quantum_bits]) << (depth-i));
248 i-=(ssize_t) quantum_bits;
249 quantum_state->bits-=quantum_bits;
254 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
255 const QuantumInfo *quantum_info,const QuantumType quantum_type,
256 const unsigned char *pixels,ExceptionInfo *exception)
270 register const unsigned char
291 assert(image != (Image *) NULL);
292 assert(image->signature == MagickSignature);
293 if (image->debug != MagickFalse)
294 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
295 assert(quantum_info != (QuantumInfo *) NULL);
296 assert(quantum_info->signature == MagickSignature);
297 if (pixels == (const unsigned char *) NULL)
298 pixels=GetQuantumPixels(quantum_info);
301 if (image_view == (CacheView *) NULL)
303 number_pixels=GetImageExtent(image);
304 q=GetAuthenticPixelQueue(image);
305 indexes=GetAuthenticIndexQueue(image);
309 number_pixels=GetCacheViewExtent(image_view);
310 q=GetCacheViewAuthenticPixelQueue(image_view);
311 indexes=GetCacheViewAuthenticIndexQueue(image_view);
313 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
314 extent=GetQuantumExtent(image,quantum_info,quantum_type);
315 endian=quantum_state.endian;
316 switch (quantum_type)
323 if (image->storage_class != PseudoClass)
325 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
326 "ColormappedImageRequired","`%s'",image->filename);
329 range_exception=MagickFalse;
330 switch (quantum_info->depth)
334 register unsigned char
337 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
339 for (bit=0; bit < 8; bit++)
341 if (quantum_info->min_is_white == MagickFalse)
342 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
345 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
347 SetIndexPixelComponent(indexes+x+bit,PushColormapIndex(image,
348 pixel,&range_exception));
349 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
350 GetIndexPixelComponent(indexes+x+bit));
355 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
357 if (quantum_info->min_is_white == MagickFalse)
358 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
361 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
363 SetIndexPixelComponent(indexes+x+bit,PushColormapIndex(image,pixel,
365 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
366 GetIndexPixelComponent(indexes+x+bit));
373 register unsigned char
376 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
378 pixel=(unsigned char) ((*p >> 4) & 0xf);
379 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
381 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
382 GetIndexPixelComponent(indexes+x));
384 pixel=(unsigned char) ((*p) & 0xf);
385 SetIndexPixelComponent(indexes+x+1,PushColormapIndex(image,pixel,
387 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
388 GetIndexPixelComponent(indexes+x+1));
392 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
394 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
395 SetIndexPixelComponent(indexes+x+bit,PushColormapIndex(image,pixel,
397 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
398 GetIndexPixelComponent(indexes+x+bit));
408 for (x=0; x < (ssize_t) number_pixels; x++)
410 p=PushCharPixel(p,&pixel);
411 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
413 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
414 GetIndexPixelComponent(indexes+x));
415 p+=quantum_info->pad;
425 if (quantum_info->format == FloatingPointQuantumFormat)
427 for (x=0; x < (ssize_t) number_pixels; x++)
429 p=PushShortPixel(endian,p,&pixel);
430 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
431 ClampToQuantum((MagickRealType) QuantumRange*
432 HalfToSinglePrecision(pixel)),&range_exception));
433 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
434 GetIndexPixelComponent(indexes+x));
435 p+=quantum_info->pad;
440 for (x=0; x < (ssize_t) number_pixels; x++)
442 p=PushShortPixel(endian,p,&pixel);
443 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
445 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
446 GetIndexPixelComponent(indexes+x));
447 p+=quantum_info->pad;
457 if (quantum_info->format == FloatingPointQuantumFormat)
462 for (x=0; x < (ssize_t) number_pixels; x++)
464 p=PushFloatPixel(&quantum_state,p,&pixel);
465 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
466 ClampToQuantum(pixel),&range_exception));
467 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
468 GetIndexPixelComponent(indexes+x));
469 p+=quantum_info->pad;
474 for (x=0; x < (ssize_t) number_pixels; x++)
476 p=PushLongPixel(endian,p,&pixel);
477 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
479 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
480 GetIndexPixelComponent(indexes+x));
481 p+=quantum_info->pad;
488 if (quantum_info->format == FloatingPointQuantumFormat)
493 for (x=0; x < (ssize_t) number_pixels; x++)
495 p=PushDoublePixel(&quantum_state,p,&pixel);
496 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
497 ClampToQuantum(pixel),&range_exception));
498 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
499 GetIndexPixelComponent(indexes+x));
500 p+=quantum_info->pad;
508 for (x=0; x < (ssize_t) number_pixels; x++)
510 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
511 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
513 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
514 GetIndexPixelComponent(indexes+x));
515 p+=quantum_info->pad;
521 if (range_exception != MagickFalse)
522 (void) ThrowMagickException(exception,GetMagickModule(),
523 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
526 case IndexAlphaQuantum:
531 if (image->storage_class != PseudoClass)
533 (void) ThrowMagickException(exception,GetMagickModule(),
534 ImageError,"ColormappedImageRequired","`%s'",image->filename);
537 range_exception=MagickFalse;
538 switch (quantum_info->depth)
542 register unsigned char
545 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
547 for (bit=0; bit < 8; bit+=2)
549 if (quantum_info->min_is_white == MagickFalse)
550 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
553 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
555 SetIndexPixelComponent(indexes+x+bit/2,pixel == 0 ? 0 : 1);
556 SetRedPixelComponent(q,pixel == 0 ? 0 : QuantumRange);
557 SetGreenPixelComponent(q,GetRedPixelComponent(q));
558 SetBluePixelComponent(q,GetRedPixelComponent(q));
559 SetOpacityPixelComponent(q,((*p) & (1UL << (unsigned char)
560 (6-bit))) == 0 ? TransparentOpacity : OpaqueOpacity);
564 for (bit=0; bit < (ssize_t) (number_pixels % 4); bit+=2)
566 if (quantum_info->min_is_white == MagickFalse)
567 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
570 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
572 SetIndexPixelComponent(indexes+x+bit/2,pixel == 0 ? 0 : 1);
573 SetRedPixelComponent(q,pixel == 0 ? 0 : QuantumRange);
574 SetGreenPixelComponent(q,GetRedPixelComponent(q));
575 SetBluePixelComponent(q,GetRedPixelComponent(q));
576 SetOpacityPixelComponent(q,((*p) & (1UL << (unsigned char)
577 (6-bit))) == 0 ? TransparentOpacity : OpaqueOpacity);
584 register unsigned char
587 range=GetQuantumRange(image->depth);
588 for (x=0; x < (ssize_t) number_pixels; x++)
590 pixel=(unsigned char) ((*p >> 4) & 0xf);
591 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
593 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
594 GetIndexPixelComponent(indexes+x));
595 pixel=(unsigned char) ((*p) & 0xf);
596 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
607 for (x=0; x < (ssize_t) number_pixels; x++)
609 p=PushCharPixel(p,&pixel);
610 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
612 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
613 GetIndexPixelComponent(indexes+x));
614 p=PushCharPixel(p,&pixel);
615 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
616 p+=quantum_info->pad;
626 if (quantum_info->format == FloatingPointQuantumFormat)
628 for (x=0; x < (ssize_t) number_pixels; x++)
630 p=PushShortPixel(endian,p,&pixel);
631 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
632 ClampToQuantum((MagickRealType) QuantumRange*
633 HalfToSinglePrecision(pixel)),&range_exception));
634 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
635 GetIndexPixelComponent(indexes+x));
636 p=PushShortPixel(endian,p,&pixel);
637 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
638 QuantumRange*HalfToSinglePrecision(pixel)));
639 p+=quantum_info->pad;
644 for (x=0; x < (ssize_t) number_pixels; x++)
646 p=PushShortPixel(endian,p,&pixel);
647 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
649 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
650 GetIndexPixelComponent(indexes+x));
651 p=PushShortPixel(endian,p,&pixel);
652 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
653 p+=quantum_info->pad;
663 if (quantum_info->format == FloatingPointQuantumFormat)
668 for (x=0; x < (ssize_t) number_pixels; x++)
670 p=PushFloatPixel(&quantum_state,p,&pixel);
671 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
672 ClampToQuantum(pixel),&range_exception));
673 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
674 GetIndexPixelComponent(indexes+x));
675 p=PushFloatPixel(&quantum_state,p,&pixel);
676 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
677 p+=quantum_info->pad;
682 for (x=0; x < (ssize_t) number_pixels; x++)
684 p=PushLongPixel(endian,p,&pixel);
685 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
687 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
688 GetIndexPixelComponent(indexes+x));
689 p=PushLongPixel(endian,p,&pixel);
690 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
691 p+=quantum_info->pad;
698 if (quantum_info->format == FloatingPointQuantumFormat)
703 for (x=0; x < (ssize_t) number_pixels; x++)
705 p=PushDoublePixel(&quantum_state,p,&pixel);
706 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,
707 ClampToQuantum(pixel),&range_exception));
708 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
709 GetIndexPixelComponent(indexes+x));
710 p=PushDoublePixel(&quantum_state,p,&pixel);
711 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
712 p+=quantum_info->pad;
720 range=GetQuantumRange(image->depth);
721 for (x=0; x < (ssize_t) number_pixels; x++)
723 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
724 SetIndexPixelComponent(indexes+x,PushColormapIndex(image,pixel,
726 SetRGBOPixelComponents(q,image->colormap+(ssize_t)
727 GetIndexPixelComponent(indexes+x));
728 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
729 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
730 p+=quantum_info->pad;
736 if (range_exception != MagickFalse)
737 (void) ThrowMagickException(exception,GetMagickModule(),
738 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
743 switch (quantum_info->depth)
750 for (x=0; x < (ssize_t) number_pixels; x++)
752 p=PushCharPixel(p,&pixel);
753 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
754 p=PushCharPixel(p,&pixel);
755 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
756 p=PushCharPixel(p,&pixel);
757 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
758 SetOpacityPixelComponent(q,OpaqueOpacity);
759 p+=quantum_info->pad;
766 range=GetQuantumRange(image->depth);
767 if (quantum_info->pack == MagickFalse)
769 for (x=0; x < (ssize_t) number_pixels; x++)
771 p=PushLongPixel(endian,p,&pixel);
772 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
774 SetGreenPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
776 SetBluePixelComponent(q,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
778 p+=quantum_info->pad;
783 if (quantum_info->quantum == 32U)
785 for (x=0; x < (ssize_t) number_pixels; x++)
787 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
788 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
789 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
790 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
791 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
792 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
797 for (x=0; x < (ssize_t) number_pixels; x++)
799 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
800 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
801 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
802 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
803 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
804 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
811 range=GetQuantumRange(image->depth);
812 if (quantum_info->pack == MagickFalse)
817 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
819 p=PushShortPixel(endian,p,&pixel);
825 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
826 (pixel >> 4),range));
831 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
832 (pixel >> 4),range));
837 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
838 (pixel >> 4),range));
843 p=PushShortPixel(endian,p,&pixel);
849 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
850 (pixel >> 4),range));
855 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
856 (pixel >> 4),range));
861 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
862 (pixel >> 4),range));
867 p+=quantum_info->pad;
869 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
871 p=PushShortPixel(endian,p,&pixel);
877 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
878 (pixel >> 4),range));
883 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
884 (pixel >> 4),range));
889 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
890 (pixel >> 4),range));
895 p+=quantum_info->pad;
901 if (quantum_info->quantum == 32U)
903 for (x=0; x < (ssize_t) number_pixels; x++)
905 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
906 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
907 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
908 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
909 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
910 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
915 for (x=0; x < (ssize_t) number_pixels; x++)
917 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
918 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
919 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
920 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
921 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
922 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
932 if (quantum_info->format == FloatingPointQuantumFormat)
934 for (x=0; x < (ssize_t) number_pixels; x++)
936 p=PushShortPixel(endian,p,&pixel);
937 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
938 QuantumRange*HalfToSinglePrecision(pixel)));
939 p=PushShortPixel(endian,p,&pixel);
940 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
941 QuantumRange*HalfToSinglePrecision(pixel)));
942 p=PushShortPixel(endian,p,&pixel);
943 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
944 QuantumRange*HalfToSinglePrecision(pixel)));
945 p+=quantum_info->pad;
950 for (x=0; x < (ssize_t) number_pixels; x++)
952 p=PushShortPixel(endian,p,&pixel);
953 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
954 p=PushShortPixel(endian,p,&pixel);
955 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
956 p=PushShortPixel(endian,p,&pixel);
957 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
958 p+=quantum_info->pad;
968 if (quantum_info->format == FloatingPointQuantumFormat)
973 for (x=0; x < (ssize_t) number_pixels; x++)
975 p=PushFloatPixel(&quantum_state,p,&pixel);
976 SetRedPixelComponent(q,ClampToQuantum(pixel));
977 p=PushFloatPixel(&quantum_state,p,&pixel);
978 SetGreenPixelComponent(q,ClampToQuantum(pixel));
979 p=PushFloatPixel(&quantum_state,p,&pixel);
980 SetBluePixelComponent(q,ClampToQuantum(pixel));
981 p+=quantum_info->pad;
986 for (x=0; x < (ssize_t) number_pixels; x++)
988 p=PushLongPixel(endian,p,&pixel);
989 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
990 p=PushLongPixel(endian,p,&pixel);
991 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
992 p=PushLongPixel(endian,p,&pixel);
993 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
994 p+=quantum_info->pad;
1001 if (quantum_info->format == FloatingPointQuantumFormat)
1006 for (x=0; x < (ssize_t) number_pixels; x++)
1008 p=PushDoublePixel(&quantum_state,p,&pixel);
1009 SetRedPixelComponent(q,ClampToQuantum(pixel));
1010 p=PushDoublePixel(&quantum_state,p,&pixel);
1011 SetGreenPixelComponent(q,ClampToQuantum(pixel));
1012 p=PushDoublePixel(&quantum_state,p,&pixel);
1013 SetBluePixelComponent(q,ClampToQuantum(pixel));
1014 p+=quantum_info->pad;
1022 range=GetQuantumRange(image->depth);
1023 for (x=0; x < (ssize_t) number_pixels; x++)
1025 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1026 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1027 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1028 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1029 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1030 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1041 switch (quantum_info->depth)
1048 for (x=0; x < (ssize_t) number_pixels; x++)
1050 p=PushCharPixel(p,&pixel);
1051 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
1052 p=PushCharPixel(p,&pixel);
1053 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1054 p=PushCharPixel(p,&pixel);
1055 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1056 p=PushCharPixel(p,&pixel);
1057 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
1058 p+=quantum_info->pad;
1066 if (quantum_info->pack == MagickFalse)
1079 for (x=0; x < (ssize_t) number_pixels; x++)
1081 for (i=0; i < 4; i++)
1087 p=PushLongPixel(endian,p,&pixel);
1088 quantum=(size_t) (ScaleShortToQuantum(
1089 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
1094 quantum=(size_t) (ScaleShortToQuantum(
1095 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
1100 quantum=(size_t) (ScaleShortToQuantum(
1101 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
1107 case 0: SetRedPixelComponent(q,quantum); break;
1108 case 1: SetGreenPixelComponent(q,quantum); break;
1109 case 2: SetBluePixelComponent(q,quantum); break;
1110 case 3: SetAlphaPixelComponent(q,quantum); break;
1114 p+=quantum_info->pad;
1119 for (x=0; x < (ssize_t) number_pixels; x++)
1121 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1122 SetRedPixelComponent(q,ScaleShortToQuantum((unsigned short)
1124 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1125 SetGreenPixelComponent(q,ScaleShortToQuantum((unsigned short)
1127 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1128 SetBluePixelComponent(q,ScaleShortToQuantum((unsigned short)
1130 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1131 SetAlphaPixelComponent(q,ScaleShortToQuantum((unsigned short)
1142 if (quantum_info->format == FloatingPointQuantumFormat)
1144 for (x=0; x < (ssize_t) number_pixels; x++)
1146 p=PushShortPixel(endian,p,&pixel);
1147 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
1148 QuantumRange*HalfToSinglePrecision(pixel)));
1149 p=PushShortPixel(endian,p,&pixel);
1150 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
1151 QuantumRange*HalfToSinglePrecision(pixel)));
1152 p=PushShortPixel(endian,p,&pixel);
1153 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
1154 QuantumRange*HalfToSinglePrecision(pixel)));
1155 p=PushShortPixel(endian,p,&pixel);
1156 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
1157 QuantumRange*HalfToSinglePrecision(pixel)));
1158 p+=quantum_info->pad;
1163 for (x=0; x < (ssize_t) number_pixels; x++)
1165 p=PushShortPixel(endian,p,&pixel);
1166 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
1167 p=PushShortPixel(endian,p,&pixel);
1168 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1169 p=PushShortPixel(endian,p,&pixel);
1170 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1171 p=PushShortPixel(endian,p,&pixel);
1172 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
1173 p+=quantum_info->pad;
1183 if (quantum_info->format == FloatingPointQuantumFormat)
1188 for (x=0; x < (ssize_t) number_pixels; x++)
1190 p=PushFloatPixel(&quantum_state,p,&pixel);
1191 SetRedPixelComponent(q,ClampToQuantum(pixel));
1192 p=PushFloatPixel(&quantum_state,p,&pixel);
1193 SetGreenPixelComponent(q,ClampToQuantum(pixel));
1194 p=PushFloatPixel(&quantum_state,p,&pixel);
1195 SetBluePixelComponent(q,ClampToQuantum(pixel));
1196 p=PushFloatPixel(&quantum_state,p,&pixel);
1197 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
1198 p+=quantum_info->pad;
1203 for (x=0; x < (ssize_t) number_pixels; x++)
1205 p=PushLongPixel(endian,p,&pixel);
1206 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
1207 p=PushLongPixel(endian,p,&pixel);
1208 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
1209 p=PushLongPixel(endian,p,&pixel);
1210 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1211 p=PushLongPixel(endian,p,&pixel);
1212 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
1213 p+=quantum_info->pad;
1220 if (quantum_info->format == FloatingPointQuantumFormat)
1225 for (x=0; x < (ssize_t) number_pixels; x++)
1227 p=PushDoublePixel(&quantum_state,p,&pixel);
1228 SetRedPixelComponent(q,ClampToQuantum(pixel));
1229 p=PushDoublePixel(&quantum_state,p,&pixel);
1230 SetGreenPixelComponent(q,ClampToQuantum(pixel));
1231 p=PushDoublePixel(&quantum_state,p,&pixel);
1232 SetBluePixelComponent(q,ClampToQuantum(pixel));
1233 p=PushDoublePixel(&quantum_state,p,&pixel);
1234 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
1235 p+=quantum_info->pad;
1243 range=GetQuantumRange(image->depth);
1244 for (x=0; x < (ssize_t) number_pixels; x++)
1246 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1247 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
1248 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1249 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1250 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1251 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1252 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1253 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1263 switch (quantum_info->depth)
1272 white=(Quantum) QuantumRange;
1273 if (quantum_info->min_is_white != MagickFalse)
1275 black=(Quantum) QuantumRange;
1278 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
1280 for (bit=0; bit < 8; bit++)
1282 SetRedPixelComponent(q,((*p) & (1 << (7-bit))) == 0 ?
1284 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1285 SetBluePixelComponent(q,GetRedPixelComponent(q));
1290 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
1292 SetRedPixelComponent(q,((*p) & (0x01 << (7-bit))) == 0 ?
1294 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1295 SetBluePixelComponent(q,GetRedPixelComponent(q));
1304 register unsigned char
1307 range=GetQuantumRange(image->depth);
1308 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
1310 pixel=(unsigned char) ((*p >> 4) & 0xf);
1311 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1312 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1313 SetBluePixelComponent(q,GetRedPixelComponent(q));
1315 pixel=(unsigned char) ((*p) & 0xf);
1316 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1317 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1318 SetBluePixelComponent(q,GetRedPixelComponent(q));
1322 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1324 pixel=(unsigned char) (*p++ >> 4);
1325 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1326 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1327 SetBluePixelComponent(q,GetRedPixelComponent(q));
1337 if (quantum_info->min_is_white != MagickFalse)
1339 for (x=0; x < (ssize_t) number_pixels; x++)
1341 p=PushCharPixel(p,&pixel);
1342 SetRedPixelComponent(q,QuantumRange-ScaleCharToQuantum(pixel));
1343 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1344 SetBluePixelComponent(q,GetRedPixelComponent(q));
1345 SetOpacityPixelComponent(q,OpaqueOpacity);
1346 p+=quantum_info->pad;
1351 for (x=0; x < (ssize_t) number_pixels; x++)
1353 p=PushCharPixel(p,&pixel);
1354 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1355 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1356 SetBluePixelComponent(q,GetRedPixelComponent(q));
1357 SetOpacityPixelComponent(q,OpaqueOpacity);
1358 p+=quantum_info->pad;
1365 range=GetQuantumRange(image->depth);
1366 if (quantum_info->pack == MagickFalse)
1368 if (image->endian != LSBEndian)
1370 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1372 p=PushLongPixel(endian,p,&pixel);
1373 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 2) &
1375 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1376 SetBluePixelComponent(q,GetRedPixelComponent(q));
1378 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
1380 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1381 SetBluePixelComponent(q,GetRedPixelComponent(q));
1383 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 22) &
1385 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1386 SetBluePixelComponent(q,GetRedPixelComponent(q));
1387 p+=quantum_info->pad;
1390 p=PushLongPixel(endian,p,&pixel);
1391 if (x++ < (ssize_t) (number_pixels-1))
1393 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 2) &
1395 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1396 SetBluePixelComponent(q,GetRedPixelComponent(q));
1399 if (x++ < (ssize_t) number_pixels)
1401 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
1403 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1404 SetBluePixelComponent(q,GetRedPixelComponent(q));
1409 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1411 p=PushLongPixel(endian,p,&pixel);
1412 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 22) &
1414 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1415 SetBluePixelComponent(q,GetRedPixelComponent(q));
1417 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
1419 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1420 SetBluePixelComponent(q,GetRedPixelComponent(q));
1422 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 2) &
1424 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1425 SetBluePixelComponent(q,GetRedPixelComponent(q));
1426 p+=quantum_info->pad;
1429 p=PushLongPixel(endian,p,&pixel);
1430 if (x++ < (ssize_t) (number_pixels-1))
1432 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 22) &
1434 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1435 SetBluePixelComponent(q,GetRedPixelComponent(q));
1438 if (x++ < (ssize_t) number_pixels)
1440 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
1442 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1443 SetBluePixelComponent(q,GetRedPixelComponent(q));
1448 for (x=0; x < (ssize_t) number_pixels; x++)
1450 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1451 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1452 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1453 SetBluePixelComponent(q,GetRedPixelComponent(q));
1454 p+=quantum_info->pad;
1461 range=GetQuantumRange(image->depth);
1462 if (quantum_info->pack == MagickFalse)
1467 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
1469 p=PushShortPixel(endian,p,&pixel);
1470 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
1471 (pixel >> 4),range));
1472 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1473 SetBluePixelComponent(q,GetRedPixelComponent(q));
1475 p=PushShortPixel(endian,p,&pixel);
1476 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
1477 (pixel >> 4),range));
1478 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1479 SetBluePixelComponent(q,GetRedPixelComponent(q));
1480 p+=quantum_info->pad;
1483 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1485 p=PushShortPixel(endian,p,&pixel);
1486 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
1487 (pixel >> 4),range));
1488 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1489 SetBluePixelComponent(q,GetRedPixelComponent(q));
1490 p+=quantum_info->pad;
1497 for (x=0; x < (ssize_t) number_pixels; x++)
1499 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1500 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1501 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1502 SetBluePixelComponent(q,GetRedPixelComponent(q));
1503 p+=quantum_info->pad;
1513 if (quantum_info->min_is_white != MagickFalse)
1515 for (x=0; x < (ssize_t) number_pixels; x++)
1517 p=PushShortPixel(endian,p,&pixel);
1518 SetRedPixelComponent(q,QuantumRange-ScaleShortToQuantum(pixel));
1519 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1520 SetBluePixelComponent(q,GetRedPixelComponent(q));
1521 p+=quantum_info->pad;
1526 if (quantum_info->format == FloatingPointQuantumFormat)
1528 for (x=0; x < (ssize_t) number_pixels; x++)
1530 p=PushShortPixel(endian,p,&pixel);
1531 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
1532 QuantumRange*HalfToSinglePrecision(pixel)));
1533 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1534 SetBluePixelComponent(q,GetRedPixelComponent(q));
1535 p+=quantum_info->pad;
1540 for (x=0; x < (ssize_t) number_pixels; x++)
1542 p=PushShortPixel(endian,p,&pixel);
1543 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1544 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1545 SetBluePixelComponent(q,GetRedPixelComponent(q));
1546 p+=quantum_info->pad;
1556 if (quantum_info->format == FloatingPointQuantumFormat)
1561 for (x=0; x < (ssize_t) number_pixels; x++)
1563 p=PushFloatPixel(&quantum_state,p,&pixel);
1564 SetRedPixelComponent(q,ClampToQuantum(pixel));
1565 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1566 SetBluePixelComponent(q,GetRedPixelComponent(q));
1567 p+=quantum_info->pad;
1572 for (x=0; x < (ssize_t) number_pixels; x++)
1574 p=PushLongPixel(endian,p,&pixel);
1575 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1576 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1577 SetBluePixelComponent(q,GetRedPixelComponent(q));
1578 p+=quantum_info->pad;
1585 if (quantum_info->format == FloatingPointQuantumFormat)
1590 for (x=0; x < (ssize_t) number_pixels; x++)
1592 p=PushDoublePixel(&quantum_state,p,&pixel);
1593 SetRedPixelComponent(q,ClampToQuantum(pixel));
1594 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1595 SetBluePixelComponent(q,GetRedPixelComponent(q));
1596 p+=quantum_info->pad;
1604 range=GetQuantumRange(image->depth);
1605 for (x=0; x < (ssize_t) number_pixels; x++)
1607 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1608 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1609 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1610 SetBluePixelComponent(q,GetRedPixelComponent(q));
1611 p+=quantum_info->pad;
1619 case GrayAlphaQuantum:
1621 switch (quantum_info->depth)
1625 register unsigned char
1628 for (x=0; x < ((ssize_t) number_pixels-3); x+=4)
1630 for (bit=0; bit < 8; bit+=2)
1632 pixel=(unsigned char)
1633 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1634 SetRedPixelComponent(q,pixel == 0 ? 0 : QuantumRange);
1635 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1636 SetBluePixelComponent(q,GetRedPixelComponent(q));
1637 SetOpacityPixelComponent(q,((*p) & (1UL << (unsigned char)
1638 (6-bit))) == 0 ? TransparentOpacity : OpaqueOpacity);
1643 for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
1645 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1646 SetRedPixelComponent(q,pixel != 0 ? 0 : QuantumRange);
1647 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1648 SetBluePixelComponent(q,GetRedPixelComponent(q));
1649 SetOpacityPixelComponent(q,((*p) & (1UL << (unsigned char)
1650 (6-bit))) == 0 ? TransparentOpacity : OpaqueOpacity);
1659 register unsigned char
1662 range=GetQuantumRange(image->depth);
1663 for (x=0; x < (ssize_t) number_pixels; x++)
1665 pixel=(unsigned char) ((*p >> 4) & 0xf);
1666 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1667 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1668 SetBluePixelComponent(q,GetRedPixelComponent(q));
1669 pixel=(unsigned char) ((*p) & 0xf);
1670 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1681 for (x=0; x < (ssize_t) number_pixels; x++)
1683 p=PushCharPixel(p,&pixel);
1684 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1685 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1686 SetBluePixelComponent(q,GetRedPixelComponent(q));
1687 p=PushCharPixel(p,&pixel);
1688 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
1689 p+=quantum_info->pad;
1696 range=GetQuantumRange(image->depth);
1697 for (x=0; x < (ssize_t) number_pixels; x++)
1699 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1700 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1701 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1702 SetBluePixelComponent(q,GetRedPixelComponent(q));
1703 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1704 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1705 p+=quantum_info->pad;
1712 range=GetQuantumRange(image->depth);
1713 for (x=0; x < (ssize_t) number_pixels; x++)
1715 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1716 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1717 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1718 SetBluePixelComponent(q,GetRedPixelComponent(q));
1719 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1720 SetOpacityPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1721 p+=quantum_info->pad;
1731 if (quantum_info->format == FloatingPointQuantumFormat)
1733 for (x=0; x < (ssize_t) number_pixels; x++)
1735 p=PushShortPixel(endian,p,&pixel);
1736 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
1737 QuantumRange*HalfToSinglePrecision(pixel)));
1738 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1739 SetBluePixelComponent(q,GetRedPixelComponent(q));
1740 p=PushShortPixel(endian,p,&pixel);
1741 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
1742 QuantumRange*HalfToSinglePrecision(pixel)));
1743 p+=quantum_info->pad;
1748 for (x=0; x < (ssize_t) number_pixels; x++)
1750 p=PushShortPixel(endian,p,&pixel);
1751 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1752 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1753 SetBluePixelComponent(q,GetRedPixelComponent(q));
1754 p=PushShortPixel(endian,p,&pixel);
1755 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
1756 p+=quantum_info->pad;
1766 if (quantum_info->format == FloatingPointQuantumFormat)
1771 for (x=0; x < (ssize_t) number_pixels; x++)
1773 p=PushFloatPixel(&quantum_state,p,&pixel);
1774 SetRedPixelComponent(q,ClampToQuantum(pixel));
1775 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1776 SetBluePixelComponent(q,GetRedPixelComponent(q));
1777 p=PushFloatPixel(&quantum_state,p,&pixel);
1778 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
1779 p+=quantum_info->pad;
1784 for (x=0; x < (ssize_t) number_pixels; x++)
1786 p=PushLongPixel(endian,p,&pixel);
1787 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1788 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1789 SetBluePixelComponent(q,GetRedPixelComponent(q));
1790 p=PushLongPixel(endian,p,&pixel);
1791 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
1792 p+=quantum_info->pad;
1799 if (quantum_info->format == FloatingPointQuantumFormat)
1804 for (x=0; x < (ssize_t) number_pixels; x++)
1806 p=PushDoublePixel(&quantum_state,p,&pixel);
1807 SetRedPixelComponent(q,ClampToQuantum(pixel));
1808 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1809 SetBluePixelComponent(q,GetRedPixelComponent(q));
1810 p=PushDoublePixel(&quantum_state,p,&pixel);
1811 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
1812 p+=quantum_info->pad;
1820 range=GetQuantumRange(image->depth);
1821 for (x=0; x < (ssize_t) number_pixels; x++)
1823 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1824 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1825 SetGreenPixelComponent(q,GetRedPixelComponent(q));
1826 SetBluePixelComponent(q,GetRedPixelComponent(q));
1827 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1828 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1829 p+=quantum_info->pad;
1840 switch (quantum_info->depth)
1847 for (x=0; x < (ssize_t) number_pixels; x++)
1849 p=PushCharPixel(p,&pixel);
1850 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
1851 p+=quantum_info->pad;
1861 if (quantum_info->format == FloatingPointQuantumFormat)
1863 for (x=0; x < (ssize_t) number_pixels; x++)
1865 p=PushShortPixel(endian,p,&pixel);
1866 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
1867 QuantumRange*HalfToSinglePrecision(pixel)));
1868 p+=quantum_info->pad;
1873 for (x=0; x < (ssize_t) number_pixels; x++)
1875 p=PushShortPixel(endian,p,&pixel);
1876 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
1877 p+=quantum_info->pad;
1887 if (quantum_info->format == FloatingPointQuantumFormat)
1892 for (x=0; x < (ssize_t) number_pixels; x++)
1894 p=PushFloatPixel(&quantum_state,p,&pixel);
1895 SetRedPixelComponent(q,ClampToQuantum(pixel));
1896 p+=quantum_info->pad;
1901 for (x=0; x < (ssize_t) number_pixels; x++)
1903 p=PushLongPixel(endian,p,&pixel);
1904 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
1905 p+=quantum_info->pad;
1912 if (quantum_info->format == FloatingPointQuantumFormat)
1917 for (x=0; x < (ssize_t) number_pixels; x++)
1919 p=PushDoublePixel(&quantum_state,p,&pixel);
1920 SetRedPixelComponent(q,ClampToQuantum(pixel));
1921 p+=quantum_info->pad;
1929 range=GetQuantumRange(image->depth);
1930 for (x=0; x < (ssize_t) number_pixels; x++)
1932 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1933 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
1934 p+=quantum_info->pad;
1943 case MagentaQuantum:
1945 switch (quantum_info->depth)
1952 for (x=0; x < (ssize_t) number_pixels; x++)
1954 p=PushCharPixel(p,&pixel);
1955 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
1956 p+=quantum_info->pad;
1966 if (quantum_info->format == FloatingPointQuantumFormat)
1968 for (x=0; x < (ssize_t) number_pixels; x++)
1970 p=PushShortPixel(endian,p,&pixel);
1971 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
1972 QuantumRange*HalfToSinglePrecision(pixel)));
1973 p+=quantum_info->pad;
1978 for (x=0; x < (ssize_t) number_pixels; x++)
1980 p=PushShortPixel(endian,p,&pixel);
1981 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
1982 p+=quantum_info->pad;
1992 if (quantum_info->format == FloatingPointQuantumFormat)
1997 for (x=0; x < (ssize_t) number_pixels; x++)
1999 p=PushFloatPixel(&quantum_state,p,&pixel);
2000 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2001 p+=quantum_info->pad;
2006 for (x=0; x < (ssize_t) number_pixels; x++)
2008 p=PushLongPixel(endian,p,&pixel);
2009 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2010 p+=quantum_info->pad;
2017 if (quantum_info->format == FloatingPointQuantumFormat)
2022 for (x=0; x < (ssize_t) number_pixels; x++)
2024 p=PushDoublePixel(&quantum_state,p,&pixel);
2025 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2026 p+=quantum_info->pad;
2034 range=GetQuantumRange(image->depth);
2035 for (x=0; x < (ssize_t) number_pixels; x++)
2037 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2038 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2039 p+=quantum_info->pad;
2050 switch (quantum_info->depth)
2057 for (x=0; x < (ssize_t) number_pixels; x++)
2059 p=PushCharPixel(p,&pixel);
2060 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2061 p+=quantum_info->pad;
2071 if (quantum_info->format == FloatingPointQuantumFormat)
2073 for (x=0; x < (ssize_t) number_pixels; x++)
2075 p=PushShortPixel(endian,p,&pixel);
2076 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
2077 QuantumRange*HalfToSinglePrecision(pixel)));
2078 p+=quantum_info->pad;
2083 for (x=0; x < (ssize_t) number_pixels; x++)
2085 p=PushShortPixel(endian,p,&pixel);
2086 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2087 p+=quantum_info->pad;
2097 if (quantum_info->format == FloatingPointQuantumFormat)
2102 for (x=0; x < (ssize_t) number_pixels; x++)
2104 p=PushFloatPixel(&quantum_state,p,&pixel);
2105 SetBluePixelComponent(q,ClampToQuantum(pixel));
2106 p+=quantum_info->pad;
2111 for (x=0; x < (ssize_t) number_pixels; x++)
2113 p=PushLongPixel(endian,p,&pixel);
2114 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2115 p+=quantum_info->pad;
2122 if (quantum_info->format == FloatingPointQuantumFormat)
2127 for (x=0; x < (ssize_t) number_pixels; x++)
2129 p=PushDoublePixel(&quantum_state,p,&pixel);
2130 SetBluePixelComponent(q,ClampToQuantum(pixel));
2131 p+=quantum_info->pad;
2139 range=GetQuantumRange(image->depth);
2140 for (x=0; x < (ssize_t) number_pixels; x++)
2142 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2143 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2144 p+=quantum_info->pad;
2154 switch (quantum_info->depth)
2161 for (x=0; x < (ssize_t) number_pixels; x++)
2163 p=PushCharPixel(p,&pixel);
2164 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
2165 p+=quantum_info->pad;
2175 if (quantum_info->format == FloatingPointQuantumFormat)
2177 for (x=0; x < (ssize_t) number_pixels; x++)
2179 p=PushShortPixel(endian,p,&pixel);
2180 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
2181 QuantumRange*HalfToSinglePrecision(pixel)));
2182 p+=quantum_info->pad;
2187 for (x=0; x < (ssize_t) number_pixels; x++)
2189 p=PushShortPixel(endian,p,&pixel);
2190 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
2191 p+=quantum_info->pad;
2201 if (quantum_info->format == FloatingPointQuantumFormat)
2206 for (x=0; x < (ssize_t) number_pixels; x++)
2208 p=PushFloatPixel(&quantum_state,p,&pixel);
2209 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
2210 p+=quantum_info->pad;
2215 for (x=0; x < (ssize_t) number_pixels; x++)
2217 p=PushLongPixel(endian,p,&pixel);
2218 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
2219 p+=quantum_info->pad;
2226 if (quantum_info->format == FloatingPointQuantumFormat)
2231 for (x=0; x < (ssize_t) number_pixels; x++)
2233 p=PushDoublePixel(&quantum_state,p,&pixel);
2234 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
2235 p+=quantum_info->pad;
2243 range=GetQuantumRange(image->depth);
2244 for (x=0; x < (ssize_t) number_pixels; x++)
2246 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2247 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2248 p+=quantum_info->pad;
2258 if (image->colorspace != CMYKColorspace)
2260 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2261 "ColorSeparatedImageRequired","`%s'",image->filename);
2264 switch (quantum_info->depth)
2271 for (x=0; x < (ssize_t) number_pixels; x++)
2273 p=PushCharPixel(p,&pixel);
2274 SetIndexPixelComponent(indexes+x,ScaleCharToQuantum(pixel));
2275 p+=quantum_info->pad;
2284 if (quantum_info->format == FloatingPointQuantumFormat)
2286 for (x=0; x < (ssize_t) number_pixels; x++)
2288 p=PushShortPixel(endian,p,&pixel);
2289 SetIndexPixelComponent(indexes+x,ClampToQuantum((MagickRealType)
2290 QuantumRange*HalfToSinglePrecision(pixel)));
2291 p+=quantum_info->pad;
2295 for (x=0; x < (ssize_t) number_pixels; x++)
2297 p=PushShortPixel(endian,p,&pixel);
2298 SetIndexPixelComponent(indexes+x,ScaleShortToQuantum(pixel));
2299 p+=quantum_info->pad;
2308 if (quantum_info->format == FloatingPointQuantumFormat)
2313 for (x=0; x < (ssize_t) number_pixels; x++)
2315 p=PushFloatPixel(&quantum_state,p,&pixel);
2316 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
2317 p+=quantum_info->pad;
2322 for (x=0; x < (ssize_t) number_pixels; x++)
2324 p=PushLongPixel(endian,p,&pixel);
2325 SetIndexPixelComponent(indexes+x,ScaleLongToQuantum(pixel));
2326 p+=quantum_info->pad;
2333 if (quantum_info->format == FloatingPointQuantumFormat)
2338 for (x=0; x < (ssize_t) number_pixels; x++)
2340 p=PushDoublePixel(&quantum_state,p,&pixel);
2341 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
2342 p+=quantum_info->pad;
2350 range=GetQuantumRange(image->depth);
2351 for (x=0; x < (ssize_t) number_pixels; x++)
2353 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2354 SetIndexPixelComponent(indexes+x,ScaleAnyToQuantum(pixel,range));
2355 p+=quantum_info->pad;
2366 switch (quantum_info->depth)
2373 for (x=0; x < (ssize_t) number_pixels; x++)
2375 p=PushCharPixel(p,&pixel);
2376 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2377 p=PushCharPixel(p,&pixel);
2378 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2379 p=PushCharPixel(p,&pixel);
2380 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2381 SetOpacityPixelComponent(q,OpaqueOpacity);
2382 p+=quantum_info->pad;
2389 range=GetQuantumRange(image->depth);
2390 if (quantum_info->pack == MagickFalse)
2392 for (x=0; x < (ssize_t) number_pixels; x++)
2394 p=PushLongPixel(endian,p,&pixel);
2395 SetRedPixelComponent(q,ScaleAnyToQuantum((pixel >> 22) &
2397 SetGreenPixelComponent(q,ScaleAnyToQuantum((pixel >> 12) &
2399 SetBluePixelComponent(q,ScaleAnyToQuantum((pixel >> 2) &
2401 p+=quantum_info->pad;
2406 if (quantum_info->quantum == 32U)
2408 for (x=0; x < (ssize_t) number_pixels; x++)
2410 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2411 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2412 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2413 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2414 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2415 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2420 for (x=0; x < (ssize_t) number_pixels; x++)
2422 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2423 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2424 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2425 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2426 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2427 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2434 range=GetQuantumRange(image->depth);
2435 if (quantum_info->pack == MagickFalse)
2440 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
2442 p=PushShortPixel(endian,p,&pixel);
2448 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2449 (pixel >> 4),range));
2454 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2455 (pixel >> 4),range));
2460 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2461 (pixel >> 4),range));
2466 p=PushShortPixel(endian,p,&pixel);
2472 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2473 (pixel >> 4),range));
2478 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2479 (pixel >> 4),range));
2484 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2485 (pixel >> 4),range));
2490 p+=quantum_info->pad;
2492 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
2494 p=PushShortPixel(endian,p,&pixel);
2495 switch ((x+bit) % 3)
2500 SetRedPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2501 (pixel >> 4),range));
2506 SetGreenPixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2507 (pixel >> 4),range));
2512 SetBluePixelComponent(q,ScaleAnyToQuantum((QuantumAny)
2513 (pixel >> 4),range));
2518 p+=quantum_info->pad;
2524 if (quantum_info->quantum == 32U)
2526 for (x=0; x < (ssize_t) number_pixels; x++)
2528 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2529 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2530 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2531 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2532 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
2533 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2538 for (x=0; x < (ssize_t) number_pixels; x++)
2540 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2541 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2542 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2543 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2544 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2545 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2555 if (quantum_info->format == FloatingPointQuantumFormat)
2557 for (x=0; x < (ssize_t) number_pixels; x++)
2559 p=PushShortPixel(endian,p,&pixel);
2560 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
2561 QuantumRange*HalfToSinglePrecision(pixel)));
2562 p=PushShortPixel(endian,p,&pixel);
2563 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
2564 QuantumRange*HalfToSinglePrecision(pixel)));
2565 p=PushShortPixel(endian,p,&pixel);
2566 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
2567 QuantumRange*HalfToSinglePrecision(pixel)));
2568 p+=quantum_info->pad;
2573 for (x=0; x < (ssize_t) number_pixels; x++)
2575 p=PushShortPixel(endian,p,&pixel);
2576 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2577 p=PushShortPixel(endian,p,&pixel);
2578 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2579 p=PushShortPixel(endian,p,&pixel);
2580 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2581 p+=quantum_info->pad;
2591 if (quantum_info->format == FloatingPointQuantumFormat)
2596 for (x=0; x < (ssize_t) number_pixels; x++)
2598 p=PushFloatPixel(&quantum_state,p,&pixel);
2599 SetRedPixelComponent(q,ClampToQuantum(pixel));
2600 p=PushFloatPixel(&quantum_state,p,&pixel);
2601 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2602 p=PushFloatPixel(&quantum_state,p,&pixel);
2603 SetBluePixelComponent(q,ClampToQuantum(pixel));
2604 p+=quantum_info->pad;
2609 for (x=0; x < (ssize_t) number_pixels; x++)
2611 p=PushLongPixel(endian,p,&pixel);
2612 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2613 p=PushLongPixel(endian,p,&pixel);
2614 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2615 p=PushLongPixel(endian,p,&pixel);
2616 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2617 p+=quantum_info->pad;
2624 if (quantum_info->format == FloatingPointQuantumFormat)
2629 for (x=0; x < (ssize_t) number_pixels; x++)
2631 p=PushDoublePixel(&quantum_state,p,&pixel);
2632 SetRedPixelComponent(q,ClampToQuantum(pixel));
2633 p=PushDoublePixel(&quantum_state,p,&pixel);
2634 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2635 p=PushDoublePixel(&quantum_state,p,&pixel);
2636 SetBluePixelComponent(q,ClampToQuantum(pixel));
2637 p+=quantum_info->pad;
2645 range=GetQuantumRange(image->depth);
2646 for (x=0; x < (ssize_t) number_pixels; x++)
2648 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2649 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2650 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2651 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2652 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2653 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2665 switch (quantum_info->depth)
2672 for (x=0; x < (ssize_t) number_pixels; x++)
2674 p=PushCharPixel(p,&pixel);
2675 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2676 p=PushCharPixel(p,&pixel);
2677 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2678 p=PushCharPixel(p,&pixel);
2679 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2680 p=PushCharPixel(p,&pixel);
2681 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
2682 p+=quantum_info->pad;
2690 if (quantum_info->pack == MagickFalse)
2703 for (x=0; x < (ssize_t) number_pixels; x++)
2705 for (i=0; i < 4; i++)
2711 p=PushLongPixel(endian,p,&pixel);
2712 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
2713 (((pixel >> 22) & 0x3ff) << 6)));
2718 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
2719 (((pixel >> 12) & 0x3ff) << 6)));
2724 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
2725 (((pixel >> 2) & 0x3ff) << 6)));
2731 case 0: SetRedPixelComponent(q,quantum); break;
2732 case 1: SetGreenPixelComponent(q,quantum); break;
2733 case 2: SetBluePixelComponent(q,quantum); break;
2734 case 3: SetAlphaPixelComponent(q,quantum); break;
2738 p+=quantum_info->pad;
2743 for (x=0; x < (ssize_t) number_pixels; x++)
2745 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2746 SetRedPixelComponent(q,ScaleShortToQuantum((unsigned short)
2748 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2749 SetGreenPixelComponent(q,ScaleShortToQuantum((unsigned short)
2751 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2752 SetBluePixelComponent(q,ScaleShortToQuantum((unsigned short)
2754 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2755 SetAlphaPixelComponent(q,ScaleShortToQuantum((unsigned short)
2766 if (quantum_info->format == FloatingPointQuantumFormat)
2768 for (x=0; x < (ssize_t) number_pixels; x++)
2770 p=PushShortPixel(endian,p,&pixel);
2771 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
2772 QuantumRange*HalfToSinglePrecision(pixel)));
2773 p=PushShortPixel(endian,p,&pixel);
2774 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
2775 QuantumRange*HalfToSinglePrecision(pixel)));
2776 p=PushShortPixel(endian,p,&pixel);
2777 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
2778 QuantumRange*HalfToSinglePrecision(pixel)));
2779 p=PushShortPixel(endian,p,&pixel);
2780 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
2781 QuantumRange*HalfToSinglePrecision(pixel)));
2782 p+=quantum_info->pad;
2787 for (x=0; x < (ssize_t) number_pixels; x++)
2789 p=PushShortPixel(endian,p,&pixel);
2790 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2791 p=PushShortPixel(endian,p,&pixel);
2792 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2793 p=PushShortPixel(endian,p,&pixel);
2794 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2795 p=PushShortPixel(endian,p,&pixel);
2796 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
2797 p+=quantum_info->pad;
2807 if (quantum_info->format == FloatingPointQuantumFormat)
2812 for (x=0; x < (ssize_t) number_pixels; x++)
2814 p=PushFloatPixel(&quantum_state,p,&pixel);
2815 SetRedPixelComponent(q,ClampToQuantum(pixel));
2816 p=PushFloatPixel(&quantum_state,p,&pixel);
2817 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2818 p=PushFloatPixel(&quantum_state,p,&pixel);
2819 SetBluePixelComponent(q,ClampToQuantum(pixel));
2820 p=PushFloatPixel(&quantum_state,p,&pixel);
2821 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
2822 p+=quantum_info->pad;
2827 for (x=0; x < (ssize_t) number_pixels; x++)
2829 p=PushLongPixel(endian,p,&pixel);
2830 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2831 p=PushLongPixel(endian,p,&pixel);
2832 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2833 p=PushLongPixel(endian,p,&pixel);
2834 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2835 p=PushLongPixel(endian,p,&pixel);
2836 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
2837 p+=quantum_info->pad;
2844 if (quantum_info->format == FloatingPointQuantumFormat)
2849 for (x=0; x < (ssize_t) number_pixels; x++)
2851 p=PushDoublePixel(&quantum_state,p,&pixel);
2852 SetRedPixelComponent(q,ClampToQuantum(pixel));
2853 p=PushDoublePixel(&quantum_state,p,&pixel);
2854 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2855 p=PushDoublePixel(&quantum_state,p,&pixel);
2856 SetBluePixelComponent(q,ClampToQuantum(pixel));
2857 p=PushDoublePixel(&quantum_state,p,&pixel);
2858 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
2859 p+=quantum_info->pad;
2867 range=GetQuantumRange(image->depth);
2868 for (x=0; x < (ssize_t) number_pixels; x++)
2870 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2871 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2872 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2873 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2874 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2875 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
2876 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2877 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
2887 if (image->colorspace != CMYKColorspace)
2889 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2890 "ColorSeparatedImageRequired","`%s'",image->filename);
2893 switch (quantum_info->depth)
2900 for (x=0; x < (ssize_t) number_pixels; x++)
2902 p=PushCharPixel(p,&pixel);
2903 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
2904 p=PushCharPixel(p,&pixel);
2905 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
2906 p=PushCharPixel(p,&pixel);
2907 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
2908 p=PushCharPixel(p,&pixel);
2909 SetIndexPixelComponent(indexes+x,ScaleCharToQuantum(pixel));
2910 p+=quantum_info->pad;
2920 if (quantum_info->format == FloatingPointQuantumFormat)
2922 for (x=0; x < (ssize_t) number_pixels; x++)
2924 p=PushShortPixel(endian,p,&pixel);
2925 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
2926 QuantumRange*HalfToSinglePrecision(pixel)));
2927 p=PushShortPixel(endian,p,&pixel);
2928 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
2929 QuantumRange*HalfToSinglePrecision(pixel)));
2930 p=PushShortPixel(endian,p,&pixel);
2931 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
2932 QuantumRange*HalfToSinglePrecision(pixel)));
2933 p=PushShortPixel(endian,p,&pixel);
2934 SetIndexPixelComponent(indexes+x,ClampToQuantum(
2935 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
2936 p+=quantum_info->pad;
2941 for (x=0; x < (ssize_t) number_pixels; x++)
2943 p=PushShortPixel(endian,p,&pixel);
2944 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
2945 p=PushShortPixel(endian,p,&pixel);
2946 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
2947 p=PushShortPixel(endian,p,&pixel);
2948 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
2949 p=PushShortPixel(endian,p,&pixel);
2950 SetIndexPixelComponent(indexes+x,ScaleShortToQuantum(pixel));
2951 p+=quantum_info->pad;
2961 if (quantum_info->format == FloatingPointQuantumFormat)
2966 for (x=0; x < (ssize_t) number_pixels; x++)
2968 p=PushFloatPixel(&quantum_state,p,&pixel);
2969 SetRedPixelComponent(q,ClampToQuantum(pixel));
2970 p=PushFloatPixel(&quantum_state,p,&pixel);
2971 SetGreenPixelComponent(q,ClampToQuantum(pixel));
2972 p=PushFloatPixel(&quantum_state,p,&pixel);
2973 SetBluePixelComponent(q,ClampToQuantum(pixel));
2974 p=PushFloatPixel(&quantum_state,p,&pixel);
2975 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
2976 p+=quantum_info->pad;
2981 for (x=0; x < (ssize_t) number_pixels; x++)
2983 p=PushLongPixel(endian,p,&pixel);
2984 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
2985 p=PushLongPixel(endian,p,&pixel);
2986 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
2987 p=PushLongPixel(endian,p,&pixel);
2988 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
2989 p=PushLongPixel(endian,p,&pixel);
2990 SetIndexPixelComponent(indexes+x,ScaleLongToQuantum(pixel));
2991 p+=quantum_info->pad;
2998 if (quantum_info->format == FloatingPointQuantumFormat)
3003 for (x=0; x < (ssize_t) number_pixels; x++)
3005 p=PushDoublePixel(&quantum_state,p,&pixel);
3006 SetRedPixelComponent(q,ClampToQuantum(pixel));
3007 p=PushDoublePixel(&quantum_state,p,&pixel);
3008 SetGreenPixelComponent(q,ClampToQuantum(pixel));
3009 p=PushDoublePixel(&quantum_state,p,&pixel);
3010 SetBluePixelComponent(q,ClampToQuantum(pixel));
3011 p=PushDoublePixel(&quantum_state,p,&pixel);
3012 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
3013 p+=quantum_info->pad;
3021 range=GetQuantumRange(image->depth);
3022 for (x=0; x < (ssize_t) number_pixels; x++)
3024 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3025 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3026 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3027 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3028 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3029 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
3030 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3031 SetIndexPixelComponent(indexes+x,ScaleAnyToQuantum(pixel,range));
3042 if (image->colorspace != CMYKColorspace)
3044 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3045 "ColorSeparatedImageRequired","`%s'",image->filename);
3048 switch (quantum_info->depth)
3055 for (x=0; x < (ssize_t) number_pixels; x++)
3057 p=PushCharPixel(p,&pixel);
3058 SetRedPixelComponent(q,ScaleCharToQuantum(pixel));
3059 p=PushCharPixel(p,&pixel);
3060 SetGreenPixelComponent(q,ScaleCharToQuantum(pixel));
3061 p=PushCharPixel(p,&pixel);
3062 SetBluePixelComponent(q,ScaleCharToQuantum(pixel));
3063 p=PushCharPixel(p,&pixel);
3064 SetIndexPixelComponent(indexes+x,ScaleCharToQuantum(pixel));
3065 p=PushCharPixel(p,&pixel);
3066 SetAlphaPixelComponent(q,ScaleCharToQuantum(pixel));
3067 p+=quantum_info->pad;
3077 if (quantum_info->format == FloatingPointQuantumFormat)
3079 for (x=0; x < (ssize_t) number_pixels; x++)
3081 p=PushShortPixel(endian,p,&pixel);
3082 SetRedPixelComponent(q,ClampToQuantum((MagickRealType)
3083 QuantumRange*HalfToSinglePrecision(pixel)));
3084 p=PushShortPixel(endian,p,&pixel);
3085 SetGreenPixelComponent(q,ClampToQuantum((MagickRealType)
3086 QuantumRange*HalfToSinglePrecision(pixel)));
3087 p=PushShortPixel(endian,p,&pixel);
3088 SetBluePixelComponent(q,ClampToQuantum((MagickRealType)
3089 QuantumRange*HalfToSinglePrecision(pixel)));
3090 p=PushShortPixel(endian,p,&pixel);
3091 SetIndexPixelComponent(indexes+x,ClampToQuantum(
3092 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)));
3093 p=PushShortPixel(endian,p,&pixel);
3094 SetAlphaPixelComponent(q,ClampToQuantum((MagickRealType)
3095 QuantumRange*HalfToSinglePrecision(pixel)));
3096 p+=quantum_info->pad;
3101 for (x=0; x < (ssize_t) number_pixels; x++)
3103 p=PushShortPixel(endian,p,&pixel);
3104 SetRedPixelComponent(q,ScaleShortToQuantum(pixel));
3105 p=PushShortPixel(endian,p,&pixel);
3106 SetGreenPixelComponent(q,ScaleShortToQuantum(pixel));
3107 p=PushShortPixel(endian,p,&pixel);
3108 SetBluePixelComponent(q,ScaleShortToQuantum(pixel));
3109 p=PushShortPixel(endian,p,&pixel);
3110 SetIndexPixelComponent(indexes+x,ScaleShortToQuantum(pixel));
3111 p=PushShortPixel(endian,p,&pixel);
3112 SetAlphaPixelComponent(q,ScaleShortToQuantum(pixel));
3113 p+=quantum_info->pad;
3123 if (quantum_info->format == FloatingPointQuantumFormat)
3128 for (x=0; x < (ssize_t) number_pixels; x++)
3130 p=PushFloatPixel(&quantum_state,p,&pixel);
3131 SetRedPixelComponent(q,ClampToQuantum(pixel));
3132 p=PushFloatPixel(&quantum_state,p,&pixel);
3133 SetGreenPixelComponent(q,ClampToQuantum(pixel));
3134 p=PushFloatPixel(&quantum_state,p,&pixel);
3135 SetBluePixelComponent(q,ClampToQuantum(pixel));
3136 p=PushFloatPixel(&quantum_state,p,&pixel);
3137 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
3138 p=PushFloatPixel(&quantum_state,p,&pixel);
3139 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
3140 p+=quantum_info->pad;
3145 for (x=0; x < (ssize_t) number_pixels; x++)
3147 p=PushLongPixel(endian,p,&pixel);
3148 SetRedPixelComponent(q,ScaleLongToQuantum(pixel));
3149 p=PushLongPixel(endian,p,&pixel);
3150 SetGreenPixelComponent(q,ScaleLongToQuantum(pixel));
3151 p=PushLongPixel(endian,p,&pixel);
3152 SetBluePixelComponent(q,ScaleLongToQuantum(pixel));
3153 p=PushLongPixel(endian,p,&pixel);
3154 SetIndexPixelComponent(indexes+x,ScaleLongToQuantum(pixel));
3155 p=PushLongPixel(endian,p,&pixel);
3156 SetAlphaPixelComponent(q,ScaleLongToQuantum(pixel));
3157 p+=quantum_info->pad;
3164 if (quantum_info->format == FloatingPointQuantumFormat)
3169 for (x=0; x < (ssize_t) number_pixels; x++)
3171 p=PushDoublePixel(&quantum_state,p,&pixel);
3172 SetRedPixelComponent(q,ClampToQuantum(pixel));
3173 p=PushDoublePixel(&quantum_state,p,&pixel);
3174 SetGreenPixelComponent(q,ClampToQuantum(pixel));
3175 p=PushDoublePixel(&quantum_state,p,&pixel);
3176 SetBluePixelComponent(q,ClampToQuantum(pixel));
3177 p=PushDoublePixel(&quantum_state,p,&pixel);
3178 SetIndexPixelComponent(indexes+x,ClampToQuantum(pixel));
3179 p=PushDoublePixel(&quantum_state,p,&pixel);
3180 SetAlphaPixelComponent(q,ClampToQuantum(pixel));
3181 p=PushDoublePixel(&quantum_state,p,&pixel);
3182 p+=quantum_info->pad;
3190 range=GetQuantumRange(image->depth);
3191 for (x=0; x < (ssize_t) number_pixels; x++)
3193 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3194 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3195 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3196 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3197 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3198 SetBluePixelComponent(q,ScaleAnyToQuantum(pixel,range));
3199 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3200 SetIndexPixelComponent(indexes+x,ScaleAnyToQuantum(pixel,range));
3201 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3202 SetAlphaPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3212 switch (quantum_info->depth)
3220 if (quantum_info->pack == MagickFalse)
3233 for (x=0; x < (ssize_t) number_pixels; x+=2)
3235 for (i=0; i < 4; i++)
3241 p=PushLongPixel(endian,p,&pixel);
3242 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3243 (((pixel >> 22) & 0x3ff) << 6)));
3248 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3249 (((pixel >> 12) & 0x3ff) << 6)));
3254 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3255 (((pixel >> 2) & 0x3ff) << 6)));
3259 cbcr[i]=(Quantum) (quantum);
3262 p+=quantum_info->pad;
3263 SetRedPixelComponent(q,cbcr[1]);
3264 SetGreenPixelComponent(q,cbcr[0]);
3265 SetBluePixelComponent(q,cbcr[2]);
3267 SetRedPixelComponent(q,cbcr[3]);
3268 SetGreenPixelComponent(q,cbcr[0]);
3269 SetBluePixelComponent(q,cbcr[2]);
3277 range=GetQuantumRange(image->depth);
3278 for (x=0; x < (ssize_t) number_pixels; x++)
3280 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3281 SetRedPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3282 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3283 SetGreenPixelComponent(q,ScaleAnyToQuantum(pixel,range));
3294 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3299 register PixelPacket
3302 q=GetAuthenticPixelQueue(image);
3303 if (image_view != (CacheView *) NULL)
3304 q=GetCacheViewAuthenticPixelQueue(image_view);
3305 for (x=0; x < (ssize_t) number_pixels; x++)
3307 quantum=GetRedPixelComponent(q);
3308 SetRedPixelComponent(q,GetGreenPixelComponent(q));
3309 SetGreenPixelComponent(q,quantum);
3313 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
3315 register PixelPacket
3318 q=GetAuthenticPixelQueue(image);
3319 if (image_view != (CacheView *) NULL)
3320 q=GetCacheViewAuthenticPixelQueue(image_view);
3321 for (x=0; x < (ssize_t) number_pixels; x++)
3323 SetOpacityPixelComponent(q,GetAlphaPixelComponent(q));
3327 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
3332 register PixelPacket
3338 q=GetAuthenticPixelQueue(image);
3339 if (image_view != (CacheView *) NULL)
3340 q=GetCacheViewAuthenticPixelQueue(image_view);
3341 for (x=0; x < (ssize_t) number_pixels; x++)
3343 alpha=QuantumScale*GetAlphaPixelComponent(q);
3344 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
3345 SetRedPixelComponent(q,ClampToQuantum(alpha*
3346 GetRedPixelComponent(q)));
3347 SetGreenPixelComponent(q,ClampToQuantum(alpha*
3348 GetGreenPixelComponent(q)));
3349 SetBluePixelComponent(q,ClampToQuantum(alpha*
3350 GetBluePixelComponent(q)));