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 "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 % 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 Quantum PushColormapIndex(const Image *image,const size_t index,
114 MagickBooleanType *range_exception)
116 if (index < image->colors)
117 return((Quantum) index);
118 *range_exception=MagickTrue;
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(QuantumState *quantum_state, const size_t depth,const unsigned char *pixels,unsigned int *quantum)
202 *quantum=(QuantumAny) 0;
203 for (i=(ssize_t) depth; i > 0L; )
205 if (quantum_state->bits == 0UL)
207 quantum_state->pixel=(*pixels++);
208 quantum_state->bits=8UL;
210 quantum_bits=(size_t) i;
211 if (quantum_bits > quantum_state->bits)
212 quantum_bits=quantum_state->bits;
213 i-=(ssize_t) quantum_bits;
214 quantum_state->bits-=quantum_bits;
215 *quantum=(unsigned int) ((*quantum << quantum_bits) |
216 ((quantum_state->pixel >> quantum_state->bits) &~ ((~0UL) <<
222 static inline const unsigned char *PushQuantumLongPixel(
223 QuantumState *quantum_state,const size_t depth,const unsigned char *pixels,
224 unsigned int *quantum)
233 for (i=(ssize_t) depth; i > 0; )
235 if (quantum_state->bits == 0)
237 pixels=PushLongPixel(quantum_state->endian,pixels,
238 &quantum_state->pixel);
239 quantum_state->bits=32U;
241 quantum_bits=(size_t) i;
242 if (quantum_bits > quantum_state->bits)
243 quantum_bits=quantum_state->bits;
244 *quantum|=(((quantum_state->pixel >> (32U-quantum_state->bits)) &
245 quantum_state->mask[quantum_bits]) << (depth-i));
246 i-=(ssize_t) quantum_bits;
247 quantum_state->bits-=quantum_bits;
252 static void ImportAlphaQuantum(const Image *image,
253 const QuantumInfo *quantum_info,QuantumState quantum_state,
254 const MagickSizeType number_pixels,const unsigned char *restrict p,
255 Quantum *restrict q,ExceptionInfo *exception)
269 endian=quantum_state.endian;
270 switch (quantum_info->depth)
277 for (x=0; x < (ssize_t) number_pixels; x++)
279 p=PushCharPixel(p,&pixel);
280 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
281 p+=quantum_info->pad;
282 q+=GetPixelChannels(image);
291 if (quantum_info->format == FloatingPointQuantumFormat)
293 for (x=0; x < (ssize_t) number_pixels; x++)
295 p=PushShortPixel(endian,p,&pixel);
296 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
297 HalfToSinglePrecision(pixel)),q);
298 p+=quantum_info->pad;
299 q+=GetPixelChannels(image);
303 for (x=0; x < (ssize_t) number_pixels; x++)
305 p=PushShortPixel(endian,p,&pixel);
306 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
307 p+=quantum_info->pad;
308 q+=GetPixelChannels(image);
317 if (quantum_info->format == FloatingPointQuantumFormat)
322 for (x=0; x < (ssize_t) number_pixels; x++)
324 p=PushFloatPixel(&quantum_state,p,&pixel);
325 SetPixelAlpha(image,ClampToQuantum(pixel),q);
326 p+=quantum_info->pad;
327 q+=GetPixelChannels(image);
331 for (x=0; x < (ssize_t) number_pixels; x++)
333 p=PushLongPixel(endian,p,&pixel);
334 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
335 p+=quantum_info->pad;
336 q+=GetPixelChannels(image);
342 if (quantum_info->format == FloatingPointQuantumFormat)
347 for (x=0; x < (ssize_t) number_pixels; x++)
349 p=PushDoublePixel(&quantum_state,p,&pixel);
350 SetPixelAlpha(image,ClampToQuantum(pixel),q);
351 p+=quantum_info->pad;
352 q+=GetPixelChannels(image);
359 range=GetQuantumRange(image->depth);
360 for (x=0; x < (ssize_t) number_pixels; x++)
362 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
363 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
364 p+=quantum_info->pad;
365 q+=GetPixelChannels(image);
372 static void ImportBGRQuantum(const Image *image,const QuantumInfo *quantum_info,
373 QuantumState quantum_state,const MagickSizeType number_pixels,
374 const unsigned char *restrict p,Quantum *restrict q,ExceptionInfo *exception)
391 endian=quantum_state.endian;
392 switch (quantum_info->depth)
399 for (x=0; x < (ssize_t) number_pixels; x++)
401 p=PushCharPixel(p,&pixel);
402 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
403 p=PushCharPixel(p,&pixel);
404 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
405 p=PushCharPixel(p,&pixel);
406 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
407 SetPixelAlpha(image,OpaqueAlpha,q);
408 p+=quantum_info->pad;
409 q+=GetPixelChannels(image);
415 range=GetQuantumRange(image->depth);
416 if (quantum_info->pack == MagickFalse)
418 for (x=0; x < (ssize_t) number_pixels; x++)
420 p=PushLongPixel(endian,p,&pixel);
421 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
422 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
424 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
425 p+=quantum_info->pad;
426 q+=GetPixelChannels(image);
430 if (quantum_info->quantum == 32U)
432 for (x=0; x < (ssize_t) number_pixels; x++)
434 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
435 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
436 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
437 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
438 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
439 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
440 q+=GetPixelChannels(image);
444 for (x=0; x < (ssize_t) number_pixels; x++)
446 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
447 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
448 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
449 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
450 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
451 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
452 q+=GetPixelChannels(image);
458 range=GetQuantumRange(image->depth);
459 if (quantum_info->pack == MagickFalse)
464 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
466 p=PushShortPixel(endian,p,&pixel);
472 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
478 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
484 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
486 q+=GetPixelChannels(image);
490 p=PushShortPixel(endian,p,&pixel);
496 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
502 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
508 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
510 q+=GetPixelChannels(image);
514 p+=quantum_info->pad;
516 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
518 p=PushShortPixel(endian,p,&pixel);
524 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
530 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
536 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
538 q+=GetPixelChannels(image);
542 p+=quantum_info->pad;
548 if (quantum_info->quantum == 32U)
550 for (x=0; x < (ssize_t) number_pixels; x++)
552 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
553 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
554 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
555 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
556 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
557 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
558 q+=GetPixelChannels(image);
562 for (x=0; x < (ssize_t) number_pixels; x++)
564 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
565 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
566 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
567 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
568 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
569 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
570 q+=GetPixelChannels(image);
579 if (quantum_info->format == FloatingPointQuantumFormat)
581 for (x=0; x < (ssize_t) number_pixels; x++)
583 p=PushShortPixel(endian,p,&pixel);
584 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
585 HalfToSinglePrecision(pixel)),q);
586 p=PushShortPixel(endian,p,&pixel);
587 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
588 HalfToSinglePrecision(pixel)),q);
589 p=PushShortPixel(endian,p,&pixel);
590 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
591 HalfToSinglePrecision(pixel)),q);
592 p+=quantum_info->pad;
593 q+=GetPixelChannels(image);
597 for (x=0; x < (ssize_t) number_pixels; x++)
599 p=PushShortPixel(endian,p,&pixel);
600 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
601 p=PushShortPixel(endian,p,&pixel);
602 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
603 p=PushShortPixel(endian,p,&pixel);
604 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
605 p+=quantum_info->pad;
606 q+=GetPixelChannels(image);
615 if (quantum_info->format == FloatingPointQuantumFormat)
620 for (x=0; x < (ssize_t) number_pixels; x++)
622 p=PushFloatPixel(&quantum_state,p,&pixel);
623 SetPixelRed(image,ClampToQuantum(pixel),q);
624 p=PushFloatPixel(&quantum_state,p,&pixel);
625 SetPixelGreen(image,ClampToQuantum(pixel),q);
626 p=PushFloatPixel(&quantum_state,p,&pixel);
627 SetPixelBlue(image,ClampToQuantum(pixel),q);
628 p+=quantum_info->pad;
629 q+=GetPixelChannels(image);
633 for (x=0; x < (ssize_t) number_pixels; x++)
635 p=PushLongPixel(endian,p,&pixel);
636 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
637 p=PushLongPixel(endian,p,&pixel);
638 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
639 p=PushLongPixel(endian,p,&pixel);
640 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
641 p+=quantum_info->pad;
642 q+=GetPixelChannels(image);
648 if (quantum_info->format == FloatingPointQuantumFormat)
653 for (x=0; x < (ssize_t) number_pixels; x++)
655 p=PushDoublePixel(&quantum_state,p,&pixel);
656 SetPixelRed(image,ClampToQuantum(pixel),q);
657 p=PushDoublePixel(&quantum_state,p,&pixel);
658 SetPixelGreen(image,ClampToQuantum(pixel),q);
659 p=PushDoublePixel(&quantum_state,p,&pixel);
660 SetPixelBlue(image,ClampToQuantum(pixel),q);
661 p+=quantum_info->pad;
662 q+=GetPixelChannels(image);
669 range=GetQuantumRange(image->depth);
670 for (x=0; x < (ssize_t) number_pixels; x++)
672 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
673 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
674 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
675 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
676 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
677 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
678 q+=GetPixelChannels(image);
685 static void ImportBGRAQuantum(const Image *image,
686 const QuantumInfo *quantum_info,QuantumState quantum_state,
687 const MagickSizeType number_pixels,const unsigned char *restrict p,
688 Quantum *restrict q,ExceptionInfo *exception)
702 endian=quantum_state.endian;
703 switch (quantum_info->depth)
710 for (x=0; x < (ssize_t) number_pixels; x++)
712 p=PushCharPixel(p,&pixel);
713 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
714 p=PushCharPixel(p,&pixel);
715 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
716 p=PushCharPixel(p,&pixel);
717 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
718 p=PushCharPixel(p,&pixel);
719 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
720 p+=quantum_info->pad;
721 q+=GetPixelChannels(image);
728 if (quantum_info->pack == MagickFalse)
741 for (x=0; x < (ssize_t) number_pixels; x++)
743 for (i=0; i < 4; i++)
749 p=PushLongPixel(endian,p,&pixel);
750 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
751 (((pixel >> 22) & 0x3ff) << 6)));
756 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
757 (((pixel >> 12) & 0x3ff) << 6)));
762 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
763 (((pixel >> 2) & 0x3ff) << 6)));
769 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
770 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
771 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
772 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
776 p+=quantum_info->pad;
777 q+=GetPixelChannels(image);
781 for (x=0; x < (ssize_t) number_pixels; x++)
783 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
784 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
785 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
786 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
788 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
789 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
791 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
792 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
794 q+=GetPixelChannels(image);
803 if (quantum_info->format == FloatingPointQuantumFormat)
805 for (x=0; x < (ssize_t) number_pixels; x++)
807 p=PushShortPixel(endian,p,&pixel);
808 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
809 HalfToSinglePrecision(pixel)),q);
810 p=PushShortPixel(endian,p,&pixel);
811 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
812 HalfToSinglePrecision(pixel)),q);
813 p=PushShortPixel(endian,p,&pixel);
814 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
815 HalfToSinglePrecision(pixel)),q);
816 p=PushShortPixel(endian,p,&pixel);
817 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
818 HalfToSinglePrecision(pixel)),q);
819 p+=quantum_info->pad;
820 q+=GetPixelChannels(image);
824 for (x=0; x < (ssize_t) number_pixels; x++)
826 p=PushShortPixel(endian,p,&pixel);
827 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
828 p=PushShortPixel(endian,p,&pixel);
829 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
830 p=PushShortPixel(endian,p,&pixel);
831 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
832 p=PushShortPixel(endian,p,&pixel);
833 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
834 p+=quantum_info->pad;
835 q+=GetPixelChannels(image);
844 if (quantum_info->format == FloatingPointQuantumFormat)
849 for (x=0; x < (ssize_t) number_pixels; x++)
851 p=PushFloatPixel(&quantum_state,p,&pixel);
852 SetPixelRed(image,ClampToQuantum(pixel),q);
853 p=PushFloatPixel(&quantum_state,p,&pixel);
854 SetPixelGreen(image,ClampToQuantum(pixel),q);
855 p=PushFloatPixel(&quantum_state,p,&pixel);
856 SetPixelBlue(image,ClampToQuantum(pixel),q);
857 p=PushFloatPixel(&quantum_state,p,&pixel);
858 SetPixelAlpha(image,ClampToQuantum(pixel),q);
859 p+=quantum_info->pad;
860 q+=GetPixelChannels(image);
864 for (x=0; x < (ssize_t) number_pixels; x++)
866 p=PushLongPixel(endian,p,&pixel);
867 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
868 p=PushLongPixel(endian,p,&pixel);
869 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
870 p=PushLongPixel(endian,p,&pixel);
871 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
872 p=PushLongPixel(endian,p,&pixel);
873 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
874 p+=quantum_info->pad;
875 q+=GetPixelChannels(image);
881 if (quantum_info->format == FloatingPointQuantumFormat)
886 for (x=0; x < (ssize_t) number_pixels; x++)
888 p=PushDoublePixel(&quantum_state,p,&pixel);
889 SetPixelRed(image,ClampToQuantum(pixel),q);
890 p=PushDoublePixel(&quantum_state,p,&pixel);
891 SetPixelGreen(image,ClampToQuantum(pixel),q);
892 p=PushDoublePixel(&quantum_state,p,&pixel);
893 SetPixelBlue(image,ClampToQuantum(pixel),q);
894 p=PushDoublePixel(&quantum_state,p,&pixel);
895 SetPixelAlpha(image,ClampToQuantum(pixel),q);
896 p+=quantum_info->pad;
897 q+=GetPixelChannels(image);
904 range=GetQuantumRange(image->depth);
905 for (x=0; x < (ssize_t) number_pixels; x++)
907 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
908 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
909 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
910 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
911 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
912 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
913 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
914 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
915 q+=GetPixelChannels(image);
922 static void ImportBlackQuantum(const Image *image,
923 const QuantumInfo *quantum_info,QuantumState quantum_state,
924 const MagickSizeType number_pixels,const unsigned char *restrict p,
925 Quantum *restrict q,ExceptionInfo *exception)
939 if (image->colorspace != CMYKColorspace)
941 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
942 "ColorSeparatedImageRequired","`%s'",image->filename);
945 endian=quantum_state.endian;
946 switch (quantum_info->depth)
953 for (x=0; x < (ssize_t) number_pixels; x++)
955 p=PushCharPixel(p,&pixel);
956 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
957 p+=quantum_info->pad;
958 q+=GetPixelChannels(image);
967 if (quantum_info->format == FloatingPointQuantumFormat)
969 for (x=0; x < (ssize_t) number_pixels; x++)
971 p=PushShortPixel(endian,p,&pixel);
972 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange*
973 HalfToSinglePrecision(pixel)),q);
974 p+=quantum_info->pad;
975 q+=GetPixelChannels(image);
979 for (x=0; x < (ssize_t) number_pixels; x++)
981 p=PushShortPixel(endian,p,&pixel);
982 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
983 p+=quantum_info->pad;
984 q+=GetPixelChannels(image);
993 if (quantum_info->format == FloatingPointQuantumFormat)
998 for (x=0; x < (ssize_t) number_pixels; x++)
1000 p=PushFloatPixel(&quantum_state,p,&pixel);
1001 SetPixelBlack(image,ClampToQuantum(pixel),q);
1002 p+=quantum_info->pad;
1003 q+=GetPixelChannels(image);
1007 for (x=0; x < (ssize_t) number_pixels; x++)
1009 p=PushLongPixel(endian,p,&pixel);
1010 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1011 p+=quantum_info->pad;
1012 q+=GetPixelChannels(image);
1018 if (quantum_info->format == FloatingPointQuantumFormat)
1023 for (x=0; x < (ssize_t) number_pixels; x++)
1025 p=PushDoublePixel(&quantum_state,p,&pixel);
1026 SetPixelBlack(image,ClampToQuantum(pixel),q);
1027 p+=quantum_info->pad;
1028 q+=GetPixelChannels(image);
1035 range=GetQuantumRange(image->depth);
1036 for (x=0; x < (ssize_t) number_pixels; x++)
1038 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1039 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1040 p+=quantum_info->pad;
1041 q+=GetPixelChannels(image);
1048 static void ImportBlueQuantum(const Image *image,
1049 const QuantumInfo *quantum_info,QuantumState quantum_state,
1050 const MagickSizeType number_pixels,const unsigned char *restrict p,
1051 Quantum *restrict q,ExceptionInfo *exception)
1065 endian=quantum_state.endian;
1066 switch (quantum_info->depth)
1073 for (x=0; x < (ssize_t) number_pixels; x++)
1075 p=PushCharPixel(p,&pixel);
1076 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1077 p+=quantum_info->pad;
1078 q+=GetPixelChannels(image);
1087 if (quantum_info->format == FloatingPointQuantumFormat)
1089 for (x=0; x < (ssize_t) number_pixels; x++)
1091 p=PushShortPixel(endian,p,&pixel);
1092 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
1093 HalfToSinglePrecision(pixel)),q);
1094 p+=quantum_info->pad;
1095 q+=GetPixelChannels(image);
1099 for (x=0; x < (ssize_t) number_pixels; x++)
1101 p=PushShortPixel(endian,p,&pixel);
1102 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1103 p+=quantum_info->pad;
1104 q+=GetPixelChannels(image);
1113 if (quantum_info->format == FloatingPointQuantumFormat)
1118 for (x=0; x < (ssize_t) number_pixels; x++)
1120 p=PushFloatPixel(&quantum_state,p,&pixel);
1121 SetPixelBlue(image,ClampToQuantum(pixel),q);
1122 p+=quantum_info->pad;
1123 q+=GetPixelChannels(image);
1127 for (x=0; x < (ssize_t) number_pixels; x++)
1129 p=PushLongPixel(endian,p,&pixel);
1130 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1131 p+=quantum_info->pad;
1132 q+=GetPixelChannels(image);
1138 if (quantum_info->format == FloatingPointQuantumFormat)
1143 for (x=0; x < (ssize_t) number_pixels; x++)
1145 p=PushDoublePixel(&quantum_state,p,&pixel);
1146 SetPixelBlue(image,ClampToQuantum(pixel),q);
1147 p+=quantum_info->pad;
1148 q+=GetPixelChannels(image);
1155 range=GetQuantumRange(image->depth);
1156 for (x=0; x < (ssize_t) number_pixels; x++)
1158 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1159 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1160 p+=quantum_info->pad;
1161 q+=GetPixelChannels(image);
1168 static void ImportCbYCrYQuantum(const Image *image,
1169 const QuantumInfo *quantum_info,QuantumState quantum_state,
1170 const MagickSizeType number_pixels,const unsigned char *restrict p,
1171 Quantum *restrict q,ExceptionInfo *exception)
1185 endian=quantum_state.endian;
1186 switch (quantum_info->depth)
1194 if (quantum_info->pack == MagickFalse)
1207 for (x=0; x < (ssize_t) number_pixels; x+=2)
1209 for (i=0; i < 4; i++)
1215 p=PushLongPixel(endian,p,&pixel);
1216 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1217 (((pixel >> 22) & 0x3ff) << 6)));
1222 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1223 (((pixel >> 12) & 0x3ff) << 6)));
1228 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1229 (((pixel >> 2) & 0x3ff) << 6)));
1233 cbcr[i]=(Quantum) (quantum);
1236 p+=quantum_info->pad;
1237 SetPixelRed(image,cbcr[1],q);
1238 SetPixelGreen(image,cbcr[0],q);
1239 SetPixelBlue(image,cbcr[2],q);
1240 q+=GetPixelChannels(image);
1241 SetPixelRed(image,cbcr[3],q);
1242 SetPixelGreen(image,cbcr[0],q);
1243 SetPixelBlue(image,cbcr[2],q);
1244 q+=GetPixelChannels(image);
1251 range=GetQuantumRange(image->depth);
1252 for (x=0; x < (ssize_t) number_pixels; x++)
1254 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1255 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1256 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1257 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1258 q+=GetPixelChannels(image);
1265 static void ImportCMYKQuantum(const Image *image,
1266 const QuantumInfo *quantum_info,QuantumState quantum_state,
1267 const MagickSizeType number_pixels,const unsigned char *restrict p,
1268 Quantum *restrict q,ExceptionInfo *exception)
1282 if (image->colorspace != CMYKColorspace)
1284 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1285 "ColorSeparatedImageRequired","`%s'",image->filename);
1288 endian=quantum_state.endian;
1289 switch (quantum_info->depth)
1296 for (x=0; x < (ssize_t) number_pixels; x++)
1298 p=PushCharPixel(p,&pixel);
1299 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1300 p=PushCharPixel(p,&pixel);
1301 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1302 p=PushCharPixel(p,&pixel);
1303 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1304 p=PushCharPixel(p,&pixel);
1305 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1306 p+=quantum_info->pad;
1307 q+=GetPixelChannels(image);
1316 if (quantum_info->format == FloatingPointQuantumFormat)
1318 for (x=0; x < (ssize_t) number_pixels; x++)
1320 p=PushShortPixel(endian,p,&pixel);
1321 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
1322 HalfToSinglePrecision(pixel)),q);
1323 p=PushShortPixel(endian,p,&pixel);
1324 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
1325 HalfToSinglePrecision(pixel)),q);
1326 p=PushShortPixel(endian,p,&pixel);
1327 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
1328 HalfToSinglePrecision(pixel)),q);
1329 p=PushShortPixel(endian,p,&pixel);
1330 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange*
1331 HalfToSinglePrecision(pixel)),q);
1332 p+=quantum_info->pad;
1333 q+=GetPixelChannels(image);
1337 for (x=0; x < (ssize_t) number_pixels; x++)
1339 p=PushShortPixel(endian,p,&pixel);
1340 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1341 p=PushShortPixel(endian,p,&pixel);
1342 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1343 p=PushShortPixel(endian,p,&pixel);
1344 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1345 p=PushShortPixel(endian,p,&pixel);
1346 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1347 p+=quantum_info->pad;
1348 q+=GetPixelChannels(image);
1357 if (quantum_info->format == FloatingPointQuantumFormat)
1362 for (x=0; x < (ssize_t) number_pixels; x++)
1364 p=PushFloatPixel(&quantum_state,p,&pixel);
1365 SetPixelRed(image,ClampToQuantum(pixel),q);
1366 p=PushFloatPixel(&quantum_state,p,&pixel);
1367 SetPixelGreen(image,ClampToQuantum(pixel),q);
1368 p=PushFloatPixel(&quantum_state,p,&pixel);
1369 SetPixelBlue(image,ClampToQuantum(pixel),q);
1370 p=PushFloatPixel(&quantum_state,p,&pixel);
1371 SetPixelBlack(image,ClampToQuantum(pixel),q);
1372 p+=quantum_info->pad;
1373 q+=GetPixelChannels(image);
1377 for (x=0; x < (ssize_t) number_pixels; x++)
1379 p=PushLongPixel(endian,p,&pixel);
1380 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1381 p=PushLongPixel(endian,p,&pixel);
1382 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1383 p=PushLongPixel(endian,p,&pixel);
1384 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1385 p=PushLongPixel(endian,p,&pixel);
1386 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1387 p+=quantum_info->pad;
1388 q+=GetPixelChannels(image);
1394 if (quantum_info->format == FloatingPointQuantumFormat)
1399 for (x=0; x < (ssize_t) number_pixels; x++)
1401 p=PushDoublePixel(&quantum_state,p,&pixel);
1402 SetPixelRed(image,ClampToQuantum(pixel),q);
1403 p=PushDoublePixel(&quantum_state,p,&pixel);
1404 SetPixelGreen(image,ClampToQuantum(pixel),q);
1405 p=PushDoublePixel(&quantum_state,p,&pixel);
1406 SetPixelBlue(image,ClampToQuantum(pixel),q);
1407 p=PushDoublePixel(&quantum_state,p,&pixel);
1408 SetPixelBlack(image,ClampToQuantum(pixel),q);
1409 p+=quantum_info->pad;
1410 q+=GetPixelChannels(image);
1417 range=GetQuantumRange(image->depth);
1418 for (x=0; x < (ssize_t) number_pixels; x++)
1420 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1421 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1422 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1423 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1424 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1425 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1426 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1427 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1428 q+=GetPixelChannels(image);
1435 static void ImportCMYKAQuantum(const Image *image,
1436 const QuantumInfo *quantum_info,QuantumState quantum_state,
1437 const MagickSizeType number_pixels,const unsigned char *restrict p,
1438 Quantum *restrict q,ExceptionInfo *exception)
1452 if (image->colorspace != CMYKColorspace)
1454 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1455 "ColorSeparatedImageRequired","`%s'",image->filename);
1458 endian=quantum_state.endian;
1459 switch (quantum_info->depth)
1466 for (x=0; x < (ssize_t) number_pixels; x++)
1468 p=PushCharPixel(p,&pixel);
1469 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1470 p=PushCharPixel(p,&pixel);
1471 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1472 p=PushCharPixel(p,&pixel);
1473 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1474 p=PushCharPixel(p,&pixel);
1475 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1476 p=PushCharPixel(p,&pixel);
1477 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
1478 p+=quantum_info->pad;
1479 q+=GetPixelChannels(image);
1488 if (quantum_info->format == FloatingPointQuantumFormat)
1490 for (x=0; x < (ssize_t) number_pixels; x++)
1492 p=PushShortPixel(endian,p,&pixel);
1493 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
1494 HalfToSinglePrecision(pixel)),q);
1495 p=PushShortPixel(endian,p,&pixel);
1496 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
1497 HalfToSinglePrecision(pixel)),q);
1498 p=PushShortPixel(endian,p,&pixel);
1499 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
1500 HalfToSinglePrecision(pixel)),q);
1501 p=PushShortPixel(endian,p,&pixel);
1502 SetPixelBlack(image,ClampToQuantum((MagickRealType) QuantumRange*
1503 HalfToSinglePrecision(pixel)),q);
1504 p=PushShortPixel(endian,p,&pixel);
1505 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
1506 HalfToSinglePrecision(pixel)),q);
1507 p+=quantum_info->pad;
1508 q+=GetPixelChannels(image);
1512 for (x=0; x < (ssize_t) number_pixels; x++)
1514 p=PushShortPixel(endian,p,&pixel);
1515 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1516 p=PushShortPixel(endian,p,&pixel);
1517 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1518 p=PushShortPixel(endian,p,&pixel);
1519 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1520 p=PushShortPixel(endian,p,&pixel);
1521 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1522 p=PushShortPixel(endian,p,&pixel);
1523 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
1524 p+=quantum_info->pad;
1525 q+=GetPixelChannels(image);
1534 if (quantum_info->format == FloatingPointQuantumFormat)
1539 for (x=0; x < (ssize_t) number_pixels; x++)
1541 p=PushFloatPixel(&quantum_state,p,&pixel);
1542 SetPixelRed(image,ClampToQuantum(pixel),q);
1543 p=PushFloatPixel(&quantum_state,p,&pixel);
1544 SetPixelGreen(image,ClampToQuantum(pixel),q);
1545 p=PushFloatPixel(&quantum_state,p,&pixel);
1546 SetPixelBlue(image,ClampToQuantum(pixel),q);
1547 p=PushFloatPixel(&quantum_state,p,&pixel);
1548 SetPixelBlack(image,ClampToQuantum(pixel),q);
1549 p=PushFloatPixel(&quantum_state,p,&pixel);
1550 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1551 p+=quantum_info->pad;
1552 q+=GetPixelChannels(image);
1556 for (x=0; x < (ssize_t) number_pixels; x++)
1558 p=PushLongPixel(endian,p,&pixel);
1559 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1560 p=PushLongPixel(endian,p,&pixel);
1561 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1562 p=PushLongPixel(endian,p,&pixel);
1563 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1564 p=PushLongPixel(endian,p,&pixel);
1565 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1566 p=PushLongPixel(endian,p,&pixel);
1567 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
1568 p+=quantum_info->pad;
1569 q+=GetPixelChannels(image);
1575 if (quantum_info->format == FloatingPointQuantumFormat)
1580 for (x=0; x < (ssize_t) number_pixels; x++)
1582 p=PushDoublePixel(&quantum_state,p,&pixel);
1583 SetPixelRed(image,ClampToQuantum(pixel),q);
1584 p=PushDoublePixel(&quantum_state,p,&pixel);
1585 SetPixelGreen(image,ClampToQuantum(pixel),q);
1586 p=PushDoublePixel(&quantum_state,p,&pixel);
1587 SetPixelBlue(image,ClampToQuantum(pixel),q);
1588 p=PushDoublePixel(&quantum_state,p,&pixel);
1589 SetPixelBlack(image,ClampToQuantum(pixel),q);
1590 p=PushDoublePixel(&quantum_state,p,&pixel);
1591 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1592 p=PushDoublePixel(&quantum_state,p,&pixel);
1593 p+=quantum_info->pad;
1594 q+=GetPixelChannels(image);
1601 range=GetQuantumRange(image->depth);
1602 for (x=0; x < (ssize_t) number_pixels; x++)
1604 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1605 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1606 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1607 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1608 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1609 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1610 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1611 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1612 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1613 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1614 q+=GetPixelChannels(image);
1621 static void ImportGrayQuantum(const Image *image,
1622 const QuantumInfo *quantum_info,QuantumState quantum_state,
1623 const MagickSizeType number_pixels,const unsigned char *restrict p,
1624 Quantum *restrict q,ExceptionInfo *exception)
1641 endian=quantum_state.endian;
1642 switch (quantum_info->depth)
1651 white=(Quantum) QuantumRange;
1652 if (quantum_info->min_is_white != MagickFalse)
1654 black=(Quantum) QuantumRange;
1657 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
1659 for (bit=0; bit < 8; bit++)
1661 SetPixelGray(image,((*p) & (1 << (7-bit))) == 0 ? black : white,q);
1662 q+=GetPixelChannels(image);
1666 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
1668 SetPixelGray(image,((*p) & (0x01 << (7-bit))) == 0 ? black : white,q);
1669 q+=GetPixelChannels(image);
1677 register unsigned char
1680 range=GetQuantumRange(image->depth);
1681 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
1683 pixel=(unsigned char) ((*p >> 4) & 0xf);
1684 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1685 q+=GetPixelChannels(image);
1686 pixel=(unsigned char) ((*p) & 0xf);
1687 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1689 q+=GetPixelChannels(image);
1691 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1693 pixel=(unsigned char) (*p++ >> 4);
1694 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1695 q+=GetPixelChannels(image);
1704 if (quantum_info->min_is_white != MagickFalse)
1706 for (x=0; x < (ssize_t) number_pixels; x++)
1708 p=PushCharPixel(p,&pixel);
1709 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
1710 SetPixelAlpha(image,OpaqueAlpha,q);
1711 p+=quantum_info->pad;
1712 q+=GetPixelChannels(image);
1716 for (x=0; x < (ssize_t) number_pixels; x++)
1718 p=PushCharPixel(p,&pixel);
1719 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
1720 SetPixelAlpha(image,OpaqueAlpha,q);
1721 p+=quantum_info->pad;
1722 q+=GetPixelChannels(image);
1728 range=GetQuantumRange(image->depth);
1729 if (quantum_info->pack == MagickFalse)
1731 if (image->endian != LSBEndian)
1733 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1735 p=PushLongPixel(endian,p,&pixel);
1736 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
1738 q+=GetPixelChannels(image);
1739 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
1741 q+=GetPixelChannels(image);
1742 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
1744 p+=quantum_info->pad;
1745 q+=GetPixelChannels(image);
1747 p=PushLongPixel(endian,p,&pixel);
1748 if (x++ < (ssize_t) (number_pixels-1))
1750 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
1752 q+=GetPixelChannels(image);
1754 if (x++ < (ssize_t) number_pixels)
1756 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
1758 q+=GetPixelChannels(image);
1762 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1764 p=PushLongPixel(endian,p,&pixel);
1765 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),
1767 q+=GetPixelChannels(image);
1768 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
1770 q+=GetPixelChannels(image);
1771 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),
1773 p+=quantum_info->pad;
1774 q+=GetPixelChannels(image);
1776 p=PushLongPixel(endian,p,&pixel);
1777 if (x++ < (ssize_t) (number_pixels-1))
1779 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),
1781 q+=GetPixelChannels(image);
1783 if (x++ < (ssize_t) number_pixels)
1785 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
1787 q+=GetPixelChannels(image);
1791 for (x=0; x < (ssize_t) number_pixels; x++)
1793 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1794 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1795 p+=quantum_info->pad;
1796 q+=GetPixelChannels(image);
1802 range=GetQuantumRange(image->depth);
1803 if (quantum_info->pack == MagickFalse)
1808 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
1810 p=PushShortPixel(endian,p,&pixel);
1811 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1813 q+=GetPixelChannels(image);
1814 p=PushShortPixel(endian,p,&pixel);
1815 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1817 p+=quantum_info->pad;
1818 q+=GetPixelChannels(image);
1820 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1822 p=PushShortPixel(endian,p,&pixel);
1823 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1825 p+=quantum_info->pad;
1826 q+=GetPixelChannels(image);
1832 for (x=0; x < (ssize_t) number_pixels; x++)
1834 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1835 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1836 p+=quantum_info->pad;
1837 q+=GetPixelChannels(image);
1846 if (quantum_info->min_is_white != MagickFalse)
1848 for (x=0; x < (ssize_t) number_pixels; x++)
1850 p=PushShortPixel(endian,p,&pixel);
1851 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
1852 p+=quantum_info->pad;
1853 q+=GetPixelChannels(image);
1857 if (quantum_info->format == FloatingPointQuantumFormat)
1859 for (x=0; x < (ssize_t) number_pixels; x++)
1861 p=PushShortPixel(endian,p,&pixel);
1862 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
1863 HalfToSinglePrecision(pixel)),q);
1864 p+=quantum_info->pad;
1865 q+=GetPixelChannels(image);
1869 for (x=0; x < (ssize_t) number_pixels; x++)
1871 p=PushShortPixel(endian,p,&pixel);
1872 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
1873 p+=quantum_info->pad;
1874 q+=GetPixelChannels(image);
1883 if (quantum_info->format == FloatingPointQuantumFormat)
1888 for (x=0; x < (ssize_t) number_pixels; x++)
1890 p=PushFloatPixel(&quantum_state,p,&pixel);
1891 SetPixelGray(image,ClampToQuantum(pixel),q);
1892 p+=quantum_info->pad;
1893 q+=GetPixelChannels(image);
1897 for (x=0; x < (ssize_t) number_pixels; x++)
1899 p=PushLongPixel(endian,p,&pixel);
1900 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
1901 p+=quantum_info->pad;
1902 q+=GetPixelChannels(image);
1908 if (quantum_info->format == FloatingPointQuantumFormat)
1913 for (x=0; x < (ssize_t) number_pixels; x++)
1915 p=PushDoublePixel(&quantum_state,p,&pixel);
1916 SetPixelGray(image,ClampToQuantum(pixel),q);
1917 p+=quantum_info->pad;
1918 q+=GetPixelChannels(image);
1925 range=GetQuantumRange(image->depth);
1926 for (x=0; x < (ssize_t) number_pixels; x++)
1928 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1929 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1930 p+=quantum_info->pad;
1931 q+=GetPixelChannels(image);
1938 static void ImportGrayAlphaQuantum(const Image *image,
1939 const QuantumInfo *quantum_info,QuantumState quantum_state,
1940 const MagickSizeType number_pixels,const unsigned char *restrict p,
1941 Quantum *restrict q,ExceptionInfo *exception)
1958 endian=quantum_state.endian;
1959 switch (quantum_info->depth)
1963 register unsigned char
1966 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
1968 for (bit=0; bit < 8; bit+=2)
1970 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1971 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
1972 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
1973 TransparentAlpha : OpaqueAlpha,q);
1974 q+=GetPixelChannels(image);
1978 if ((number_pixels % 4) != 0)
1979 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
1981 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1982 SetPixelGray(image,(Quantum) (pixel != 0 ? 0 : QuantumRange),q);
1983 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
1984 TransparentAlpha : OpaqueAlpha,q);
1985 q+=GetPixelChannels(image);
1993 register unsigned char
1996 range=GetQuantumRange(image->depth);
1997 for (x=0; x < (ssize_t) number_pixels; x++)
1999 pixel=(unsigned char) ((*p >> 4) & 0xf);
2000 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2001 pixel=(unsigned char) ((*p) & 0xf);
2002 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2004 q+=GetPixelChannels(image);
2013 for (x=0; x < (ssize_t) number_pixels; x++)
2015 p=PushCharPixel(p,&pixel);
2016 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
2017 p=PushCharPixel(p,&pixel);
2018 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
2019 p+=quantum_info->pad;
2020 q+=GetPixelChannels(image);
2026 range=GetQuantumRange(image->depth);
2027 for (x=0; x < (ssize_t) number_pixels; x++)
2029 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2030 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2031 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2032 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2033 p+=quantum_info->pad;
2034 q+=GetPixelChannels(image);
2040 range=GetQuantumRange(image->depth);
2041 for (x=0; x < (ssize_t) number_pixels; x++)
2043 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2044 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2045 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2046 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2047 p+=quantum_info->pad;
2048 q+=GetPixelChannels(image);
2057 if (quantum_info->format == FloatingPointQuantumFormat)
2059 for (x=0; x < (ssize_t) number_pixels; x++)
2061 p=PushShortPixel(endian,p,&pixel);
2062 SetPixelGray(image,ClampToQuantum((MagickRealType) QuantumRange*
2063 HalfToSinglePrecision(pixel)),q);
2064 p=PushShortPixel(endian,p,&pixel);
2065 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
2066 HalfToSinglePrecision(pixel)),q);
2067 p+=quantum_info->pad;
2068 q+=GetPixelChannels(image);
2072 for (x=0; x < (ssize_t) number_pixels; x++)
2074 p=PushShortPixel(endian,p,&pixel);
2075 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
2076 p=PushShortPixel(endian,p,&pixel);
2077 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
2078 p+=quantum_info->pad;
2079 q+=GetPixelChannels(image);
2088 if (quantum_info->format == FloatingPointQuantumFormat)
2093 for (x=0; x < (ssize_t) number_pixels; x++)
2095 p=PushFloatPixel(&quantum_state,p,&pixel);
2096 SetPixelGray(image,ClampToQuantum(pixel),q);
2097 p=PushFloatPixel(&quantum_state,p,&pixel);
2098 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2099 p+=quantum_info->pad;
2100 q+=GetPixelChannels(image);
2104 for (x=0; x < (ssize_t) number_pixels; x++)
2106 p=PushLongPixel(endian,p,&pixel);
2107 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
2108 p=PushLongPixel(endian,p,&pixel);
2109 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2110 p+=quantum_info->pad;
2111 q+=GetPixelChannels(image);
2117 if (quantum_info->format == FloatingPointQuantumFormat)
2122 for (x=0; x < (ssize_t) number_pixels; x++)
2124 p=PushDoublePixel(&quantum_state,p,&pixel);
2125 SetPixelGray(image,ClampToQuantum(pixel),q);
2126 p=PushDoublePixel(&quantum_state,p,&pixel);
2127 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2128 p+=quantum_info->pad;
2129 q+=GetPixelChannels(image);
2136 range=GetQuantumRange(image->depth);
2137 for (x=0; x < (ssize_t) number_pixels; x++)
2139 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2140 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2141 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2142 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2143 p+=quantum_info->pad;
2144 q+=GetPixelChannels(image);
2151 static void ImportGreenQuantum(const Image *image,
2152 const QuantumInfo *quantum_info,QuantumState quantum_state,
2153 const MagickSizeType number_pixels,const unsigned char *restrict p,
2154 Quantum *restrict q,ExceptionInfo *exception)
2168 endian=quantum_state.endian;
2169 switch (quantum_info->depth)
2176 for (x=0; x < (ssize_t) number_pixels; x++)
2178 p=PushCharPixel(p,&pixel);
2179 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2180 p+=quantum_info->pad;
2181 q+=GetPixelChannels(image);
2190 if (quantum_info->format == FloatingPointQuantumFormat)
2192 for (x=0; x < (ssize_t) number_pixels; x++)
2194 p=PushShortPixel(endian,p,&pixel);
2195 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
2196 HalfToSinglePrecision(pixel)),q);
2197 p+=quantum_info->pad;
2198 q+=GetPixelChannels(image);
2202 for (x=0; x < (ssize_t) number_pixels; x++)
2204 p=PushShortPixel(endian,p,&pixel);
2205 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
2206 p+=quantum_info->pad;
2207 q+=GetPixelChannels(image);
2216 if (quantum_info->format == FloatingPointQuantumFormat)
2221 for (x=0; x < (ssize_t) number_pixels; x++)
2223 p=PushFloatPixel(&quantum_state,p,&pixel);
2224 SetPixelGreen(image,ClampToQuantum(pixel),q);
2225 p+=quantum_info->pad;
2226 q+=GetPixelChannels(image);
2230 for (x=0; x < (ssize_t) number_pixels; x++)
2232 p=PushLongPixel(endian,p,&pixel);
2233 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
2234 p+=quantum_info->pad;
2235 q+=GetPixelChannels(image);
2241 if (quantum_info->format == FloatingPointQuantumFormat)
2246 for (x=0; x < (ssize_t) number_pixels; x++)
2248 p=PushDoublePixel(&quantum_state,p,&pixel);
2249 SetPixelGreen(image,ClampToQuantum(pixel),q);
2250 p+=quantum_info->pad;
2251 q+=GetPixelChannels(image);
2258 range=GetQuantumRange(image->depth);
2259 for (x=0; x < (ssize_t) number_pixels; x++)
2261 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2262 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2263 p+=quantum_info->pad;
2264 q+=GetPixelChannels(image);
2271 static void ImportIndexQuantum(const Image *image,
2272 const QuantumInfo *quantum_info,QuantumState quantum_state,
2273 const MagickSizeType number_pixels,const unsigned char *restrict p,
2274 Quantum *restrict q,ExceptionInfo *exception)
2291 if (image->storage_class != PseudoClass)
2293 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2294 "ColormappedImageRequired","`%s'",image->filename);
2297 endian=quantum_state.endian;
2298 range_exception=MagickFalse;
2299 switch (quantum_info->depth)
2303 register unsigned char
2306 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
2308 for (bit=0; bit < 8; bit++)
2310 if (quantum_info->min_is_white == MagickFalse)
2311 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
2314 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
2316 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),
2318 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2319 GetPixelIndex(image,q),q);
2320 q+=GetPixelChannels(image);
2324 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
2326 if (quantum_info->min_is_white == MagickFalse)
2327 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2329 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2330 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2331 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2332 GetPixelIndex(image,q),q);
2333 q+=GetPixelChannels(image);
2339 register unsigned char
2342 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
2344 pixel=(unsigned char) ((*p >> 4) & 0xf);
2345 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2346 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2347 GetPixelIndex(image,q),q);
2348 q+=GetPixelChannels(image);
2349 pixel=(unsigned char) ((*p) & 0xf);
2350 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2351 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2352 GetPixelIndex(image,q),q);
2354 q+=GetPixelChannels(image);
2356 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
2358 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
2359 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2360 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2361 GetPixelIndex(image,q),q);
2362 q+=GetPixelChannels(image);
2371 for (x=0; x < (ssize_t) number_pixels; x++)
2373 p=PushCharPixel(p,&pixel);
2374 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2375 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2376 GetPixelIndex(image,q),q);
2377 p+=quantum_info->pad;
2378 q+=GetPixelChannels(image);
2387 if (quantum_info->format == FloatingPointQuantumFormat)
2389 for (x=0; x < (ssize_t) number_pixels; x++)
2391 p=PushShortPixel(endian,p,&pixel);
2392 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(
2393 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
2394 &range_exception),q);
2395 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2396 GetPixelIndex(image,q),q);
2397 p+=quantum_info->pad;
2398 q+=GetPixelChannels(image);
2402 for (x=0; x < (ssize_t) number_pixels; x++)
2404 p=PushShortPixel(endian,p,&pixel);
2405 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2406 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2407 GetPixelIndex(image,q),q);
2408 p+=quantum_info->pad;
2409 q+=GetPixelChannels(image);
2418 if (quantum_info->format == FloatingPointQuantumFormat)
2423 for (x=0; x < (ssize_t) number_pixels; x++)
2425 p=PushFloatPixel(&quantum_state,p,&pixel);
2426 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2427 &range_exception),q);
2428 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2429 GetPixelIndex(image,q),q);
2430 p+=quantum_info->pad;
2431 q+=GetPixelChannels(image);
2435 for (x=0; x < (ssize_t) number_pixels; x++)
2437 p=PushLongPixel(endian,p,&pixel);
2438 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2439 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2440 GetPixelIndex(image,q),q);
2441 p+=quantum_info->pad;
2442 q+=GetPixelChannels(image);
2448 if (quantum_info->format == FloatingPointQuantumFormat)
2453 for (x=0; x < (ssize_t) number_pixels; x++)
2455 p=PushDoublePixel(&quantum_state,p,&pixel);
2456 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2457 &range_exception),q);
2458 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2459 GetPixelIndex(image,q),q);
2460 p+=quantum_info->pad;
2461 q+=GetPixelChannels(image);
2468 for (x=0; x < (ssize_t) number_pixels; x++)
2470 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2471 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2472 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2473 GetPixelIndex(image,q),q);
2474 p+=quantum_info->pad;
2475 q+=GetPixelChannels(image);
2480 if (range_exception != MagickFalse)
2481 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
2482 "InvalidColormapIndex","`%s'",image->filename);
2485 static void ImportIndexAlphaQuantum(const Image *image,
2486 const QuantumInfo *quantum_info,QuantumState quantum_state,
2487 const MagickSizeType number_pixels,const unsigned char *restrict p,
2488 Quantum *restrict q,ExceptionInfo *exception)
2508 if (image->storage_class != PseudoClass)
2510 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2511 "ColormappedImageRequired","`%s'",image->filename);
2514 endian=quantum_state.endian;
2515 range_exception=MagickFalse;
2516 switch (quantum_info->depth)
2520 register unsigned char
2523 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2525 for (bit=0; bit < 8; bit+=2)
2527 if (quantum_info->min_is_white == MagickFalse)
2528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2530 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2531 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
2532 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2533 TransparentAlpha : OpaqueAlpha,q);
2534 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
2535 q+=GetPixelChannels(image);
2538 if ((number_pixels % 4) != 0)
2539 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
2541 if (quantum_info->min_is_white == MagickFalse)
2542 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2544 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2545 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
2546 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
2547 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2548 TransparentAlpha : OpaqueAlpha,q);
2549 q+=GetPixelChannels(image);
2555 register unsigned char
2558 range=GetQuantumRange(image->depth);
2559 for (x=0; x < (ssize_t) number_pixels; x++)
2561 pixel=(unsigned char) ((*p >> 4) & 0xf);
2562 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2563 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2564 GetPixelIndex(image,q),q);
2565 pixel=(unsigned char) ((*p) & 0xf);
2566 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2568 q+=GetPixelChannels(image);
2577 for (x=0; x < (ssize_t) number_pixels; x++)
2579 p=PushCharPixel(p,&pixel);
2580 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2581 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2582 GetPixelIndex(image,q),q);
2583 p=PushCharPixel(p,&pixel);
2584 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
2585 p+=quantum_info->pad;
2586 q+=GetPixelChannels(image);
2595 if (quantum_info->format == FloatingPointQuantumFormat)
2597 for (x=0; x < (ssize_t) number_pixels; x++)
2599 p=PushShortPixel(endian,p,&pixel);
2600 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(
2601 (MagickRealType) QuantumRange*HalfToSinglePrecision(pixel)),
2602 &range_exception),q);
2603 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2604 GetPixelIndex(image,q),q);
2605 p=PushShortPixel(endian,p,&pixel);
2606 SetPixelAlpha(image,ClampToQuantum((MagickRealType)
2607 QuantumRange*HalfToSinglePrecision(pixel)),q);
2608 p+=quantum_info->pad;
2609 q+=GetPixelChannels(image);
2613 for (x=0; x < (ssize_t) number_pixels; x++)
2615 p=PushShortPixel(endian,p,&pixel);
2616 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2617 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2618 GetPixelIndex(image,q),q);
2619 p=PushShortPixel(endian,p,&pixel);
2620 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
2621 p+=quantum_info->pad;
2622 q+=GetPixelChannels(image);
2631 if (quantum_info->format == FloatingPointQuantumFormat)
2636 for (x=0; x < (ssize_t) number_pixels; x++)
2638 p=PushFloatPixel(&quantum_state,p,&pixel);
2639 SetPixelIndex(image,PushColormapIndex(image,
2640 ClampToQuantum(pixel),&range_exception),q);
2641 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2642 GetPixelIndex(image,q),q);
2643 p=PushFloatPixel(&quantum_state,p,&pixel);
2644 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2645 p+=quantum_info->pad;
2646 q+=GetPixelChannels(image);
2650 for (x=0; x < (ssize_t) number_pixels; x++)
2652 p=PushLongPixel(endian,p,&pixel);
2653 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2654 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2655 GetPixelIndex(image,q),q);
2656 p=PushLongPixel(endian,p,&pixel);
2657 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2658 p+=quantum_info->pad;
2659 q+=GetPixelChannels(image);
2665 if (quantum_info->format == FloatingPointQuantumFormat)
2670 for (x=0; x < (ssize_t) number_pixels; x++)
2672 p=PushDoublePixel(&quantum_state,p,&pixel);
2673 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2674 &range_exception),q);
2675 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2676 GetPixelIndex(image,q),q);
2677 p=PushDoublePixel(&quantum_state,p,&pixel);
2678 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2679 p+=quantum_info->pad;
2680 q+=GetPixelChannels(image);
2687 range=GetQuantumRange(image->depth);
2688 for (x=0; x < (ssize_t) number_pixels; x++)
2690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2691 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2692 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2693 GetPixelIndex(image,q),q);
2694 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2695 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2696 p+=quantum_info->pad;
2697 q+=GetPixelChannels(image);
2702 if (range_exception != MagickFalse)
2703 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
2704 "InvalidColormapIndex","`%s'",image->filename);
2707 static void ImportOpacityQuantum(const Image *image,
2708 const QuantumInfo *quantum_info,QuantumState quantum_state,
2709 const MagickSizeType number_pixels,const unsigned char *restrict p,
2710 Quantum *restrict q,ExceptionInfo *exception)
2724 endian=quantum_state.endian;
2725 switch (quantum_info->depth)
2732 for (x=0; x < (ssize_t) number_pixels; x++)
2734 p=PushCharPixel(p,&pixel);
2735 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
2736 p+=quantum_info->pad;
2737 q+=GetPixelChannels(image);
2746 if (quantum_info->format == FloatingPointQuantumFormat)
2748 for (x=0; x < (ssize_t) number_pixels; x++)
2750 p=PushShortPixel(endian,p,&pixel);
2751 SetPixelOpacity(image,ClampToQuantum((MagickRealType) QuantumRange*
2752 HalfToSinglePrecision(pixel)),q);
2753 p+=quantum_info->pad;
2754 q+=GetPixelChannels(image);
2758 for (x=0; x < (ssize_t) number_pixels; x++)
2760 p=PushShortPixel(endian,p,&pixel);
2761 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
2762 p+=quantum_info->pad;
2763 q+=GetPixelChannels(image);
2772 if (quantum_info->format == FloatingPointQuantumFormat)
2777 for (x=0; x < (ssize_t) number_pixels; x++)
2779 p=PushFloatPixel(&quantum_state,p,&pixel);
2780 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2781 p+=quantum_info->pad;
2782 q+=GetPixelChannels(image);
2786 for (x=0; x < (ssize_t) number_pixels; x++)
2788 p=PushLongPixel(endian,p,&pixel);
2789 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
2790 p+=quantum_info->pad;
2791 q+=GetPixelChannels(image);
2797 if (quantum_info->format == FloatingPointQuantumFormat)
2802 for (x=0; x < (ssize_t) number_pixels; x++)
2804 p=PushDoublePixel(&quantum_state,p,&pixel);
2805 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2806 p+=quantum_info->pad;
2807 q+=GetPixelChannels(image);
2814 range=GetQuantumRange(image->depth);
2815 for (x=0; x < (ssize_t) number_pixels; x++)
2817 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2818 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
2819 p+=quantum_info->pad;
2820 q+=GetPixelChannels(image);
2826 static void ImportRedQuantum(const Image *image,const QuantumInfo *quantum_info,
2827 QuantumState quantum_state,const MagickSizeType number_pixels,
2828 const unsigned char *restrict p,Quantum *restrict q,ExceptionInfo *exception)
2842 endian=quantum_state.endian;
2843 switch (quantum_info->depth)
2850 for (x=0; x < (ssize_t) number_pixels; x++)
2852 p=PushCharPixel(p,&pixel);
2853 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
2854 p+=quantum_info->pad;
2855 q+=GetPixelChannels(image);
2864 if (quantum_info->format == FloatingPointQuantumFormat)
2866 for (x=0; x < (ssize_t) number_pixels; x++)
2868 p=PushShortPixel(endian,p,&pixel);
2869 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
2870 HalfToSinglePrecision(pixel)),q);
2871 p+=quantum_info->pad;
2872 q+=GetPixelChannels(image);
2876 for (x=0; x < (ssize_t) number_pixels; x++)
2878 p=PushShortPixel(endian,p,&pixel);
2879 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
2880 p+=quantum_info->pad;
2881 q+=GetPixelChannels(image);
2890 if (quantum_info->format == FloatingPointQuantumFormat)
2895 for (x=0; x < (ssize_t) number_pixels; x++)
2897 p=PushFloatPixel(&quantum_state,p,&pixel);
2898 SetPixelRed(image,ClampToQuantum(pixel),q);
2899 p+=quantum_info->pad;
2900 q+=GetPixelChannels(image);
2904 for (x=0; x < (ssize_t) number_pixels; x++)
2906 p=PushLongPixel(endian,p,&pixel);
2907 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
2908 p+=quantum_info->pad;
2909 q+=GetPixelChannels(image);
2915 if (quantum_info->format == FloatingPointQuantumFormat)
2920 for (x=0; x < (ssize_t) number_pixels; x++)
2922 p=PushDoublePixel(&quantum_state,p,&pixel);
2923 SetPixelRed(image,ClampToQuantum(pixel),q);
2924 p+=quantum_info->pad;
2925 q+=GetPixelChannels(image);
2932 range=GetQuantumRange(image->depth);
2933 for (x=0; x < (ssize_t) number_pixels; x++)
2935 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2936 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2937 p+=quantum_info->pad;
2938 q+=GetPixelChannels(image);
2945 static void ImportRGBQuantum(const Image *image,const QuantumInfo *quantum_info,
2946 QuantumState quantum_state,const MagickSizeType number_pixels,
2947 const unsigned char *restrict p,Quantum *restrict q,ExceptionInfo *exception)
2964 endian=quantum_state.endian;
2965 switch (quantum_info->depth)
2972 for (x=0; x < (ssize_t) number_pixels; x++)
2974 p=PushCharPixel(p,&pixel);
2975 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
2976 p=PushCharPixel(p,&pixel);
2977 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2978 p=PushCharPixel(p,&pixel);
2979 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
2980 SetPixelAlpha(image,OpaqueAlpha,q);
2981 p+=quantum_info->pad;
2982 q+=GetPixelChannels(image);
2988 range=GetQuantumRange(image->depth);
2989 if (quantum_info->pack == MagickFalse)
2991 for (x=0; x < (ssize_t) number_pixels; x++)
2993 p=PushLongPixel(endian,p,&pixel);
2994 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
2995 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
2997 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
2998 p+=quantum_info->pad;
2999 q+=GetPixelChannels(image);
3003 if (quantum_info->quantum == 32U)
3005 for (x=0; x < (ssize_t) number_pixels; x++)
3007 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3008 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3009 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3010 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3011 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3012 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3013 q+=GetPixelChannels(image);
3017 for (x=0; x < (ssize_t) number_pixels; x++)
3019 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3020 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3021 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3022 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3023 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3024 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3025 q+=GetPixelChannels(image);
3031 range=GetQuantumRange(image->depth);
3032 if (quantum_info->pack == MagickFalse)
3037 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
3039 p=PushShortPixel(endian,p,&pixel);
3045 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3051 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3057 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3059 q+=GetPixelChannels(image);
3063 p=PushShortPixel(endian,p,&pixel);
3069 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3075 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3081 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3083 q+=GetPixelChannels(image);
3087 p+=quantum_info->pad;
3089 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
3091 p=PushShortPixel(endian,p,&pixel);
3092 switch ((x+bit) % 3)
3097 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3103 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3109 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3111 q+=GetPixelChannels(image);
3115 p+=quantum_info->pad;
3121 if (quantum_info->quantum == 32U)
3123 for (x=0; x < (ssize_t) number_pixels; x++)
3125 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3126 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3127 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3128 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3129 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
3130 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3131 q+=GetPixelChannels(image);
3135 for (x=0; x < (ssize_t) number_pixels; x++)
3137 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3138 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3139 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3140 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3141 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3142 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3143 q+=GetPixelChannels(image);
3152 if (quantum_info->format == FloatingPointQuantumFormat)
3154 for (x=0; x < (ssize_t) number_pixels; x++)
3156 p=PushShortPixel(endian,p,&pixel);
3157 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
3158 HalfToSinglePrecision(pixel)),q);
3159 p=PushShortPixel(endian,p,&pixel);
3160 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
3161 HalfToSinglePrecision(pixel)),q);
3162 p=PushShortPixel(endian,p,&pixel);
3163 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
3164 HalfToSinglePrecision(pixel)),q);
3165 p+=quantum_info->pad;
3166 q+=GetPixelChannels(image);
3170 for (x=0; x < (ssize_t) number_pixels; x++)
3172 p=PushShortPixel(endian,p,&pixel);
3173 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3174 p=PushShortPixel(endian,p,&pixel);
3175 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
3176 p=PushShortPixel(endian,p,&pixel);
3177 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
3178 p+=quantum_info->pad;
3179 q+=GetPixelChannels(image);
3188 if (quantum_info->format == FloatingPointQuantumFormat)
3193 for (x=0; x < (ssize_t) number_pixels; x++)
3195 p=PushFloatPixel(&quantum_state,p,&pixel);
3196 SetPixelRed(image,ClampToQuantum(pixel),q);
3197 p=PushFloatPixel(&quantum_state,p,&pixel);
3198 SetPixelGreen(image,ClampToQuantum(pixel),q);
3199 p=PushFloatPixel(&quantum_state,p,&pixel);
3200 SetPixelBlue(image,ClampToQuantum(pixel),q);
3201 p+=quantum_info->pad;
3202 q+=GetPixelChannels(image);
3206 for (x=0; x < (ssize_t) number_pixels; x++)
3208 p=PushLongPixel(endian,p,&pixel);
3209 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3210 p=PushLongPixel(endian,p,&pixel);
3211 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
3212 p=PushLongPixel(endian,p,&pixel);
3213 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
3214 p+=quantum_info->pad;
3215 q+=GetPixelChannels(image);
3221 if (quantum_info->format == FloatingPointQuantumFormat)
3226 for (x=0; x < (ssize_t) number_pixels; x++)
3228 p=PushDoublePixel(&quantum_state,p,&pixel);
3229 SetPixelRed(image,ClampToQuantum(pixel),q);
3230 p=PushDoublePixel(&quantum_state,p,&pixel);
3231 SetPixelGreen(image,ClampToQuantum(pixel),q);
3232 p=PushDoublePixel(&quantum_state,p,&pixel);
3233 SetPixelBlue(image,ClampToQuantum(pixel),q);
3234 p+=quantum_info->pad;
3235 q+=GetPixelChannels(image);
3242 range=GetQuantumRange(image->depth);
3243 for (x=0; x < (ssize_t) number_pixels; x++)
3245 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3246 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3247 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3248 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3249 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3250 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3251 q+=GetPixelChannels(image);
3258 static void ImportRGBAQuantum(const Image *image,
3259 const QuantumInfo *quantum_info,QuantumState quantum_state,
3260 const MagickSizeType number_pixels,const unsigned char *restrict p,
3261 Quantum *restrict q,ExceptionInfo *exception)
3275 endian=quantum_state.endian;
3276 switch (quantum_info->depth)
3283 for (x=0; x < (ssize_t) number_pixels; x++)
3285 p=PushCharPixel(p,&pixel);
3286 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3287 p=PushCharPixel(p,&pixel);
3288 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
3289 p=PushCharPixel(p,&pixel);
3290 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
3291 p=PushCharPixel(p,&pixel);
3292 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
3293 p+=quantum_info->pad;
3294 q+=GetPixelChannels(image);
3301 if (quantum_info->pack == MagickFalse)
3314 for (x=0; x < (ssize_t) number_pixels; x++)
3316 for (i=0; i < 4; i++)
3322 p=PushLongPixel(endian,p,&pixel);
3323 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3324 (((pixel >> 22) & 0x3ff) << 6)));
3329 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3330 (((pixel >> 12) & 0x3ff) << 6)));
3335 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
3336 (((pixel >> 2) & 0x3ff) << 6)));
3342 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
3343 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
3344 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
3345 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
3349 p+=quantum_info->pad;
3350 q+=GetPixelChannels(image);
3354 for (x=0; x < (ssize_t) number_pixels; x++)
3356 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3357 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
3358 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3359 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3361 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3362 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3364 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3365 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3367 q+=GetPixelChannels(image);
3376 if (quantum_info->format == FloatingPointQuantumFormat)
3378 for (x=0; x < (ssize_t) number_pixels; x++)
3380 p=PushShortPixel(endian,p,&pixel);
3381 SetPixelRed(image,ClampToQuantum((MagickRealType) QuantumRange*
3382 HalfToSinglePrecision(pixel)),q);
3383 p=PushShortPixel(endian,p,&pixel);
3384 SetPixelGreen(image,ClampToQuantum((MagickRealType) QuantumRange*
3385 HalfToSinglePrecision(pixel)),q);
3386 p=PushShortPixel(endian,p,&pixel);
3387 SetPixelBlue(image,ClampToQuantum((MagickRealType) QuantumRange*
3388 HalfToSinglePrecision(pixel)),q);
3389 p=PushShortPixel(endian,p,&pixel);
3390 SetPixelAlpha(image,ClampToQuantum((MagickRealType) QuantumRange*
3391 HalfToSinglePrecision(pixel)),q);
3392 p+=quantum_info->pad;
3393 q+=GetPixelChannels(image);
3397 for (x=0; x < (ssize_t) number_pixels; x++)
3399 p=PushShortPixel(endian,p,&pixel);
3400 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3401 p=PushShortPixel(endian,p,&pixel);
3402 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
3403 p=PushShortPixel(endian,p,&pixel);
3404 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
3405 p=PushShortPixel(endian,p,&pixel);
3406 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
3407 p+=quantum_info->pad;
3408 q+=GetPixelChannels(image);
3417 if (quantum_info->format == FloatingPointQuantumFormat)
3422 for (x=0; x < (ssize_t) number_pixels; x++)
3424 p=PushFloatPixel(&quantum_state,p,&pixel);
3425 SetPixelRed(image,ClampToQuantum(pixel),q);
3426 p=PushFloatPixel(&quantum_state,p,&pixel);
3427 SetPixelGreen(image,ClampToQuantum(pixel),q);
3428 p=PushFloatPixel(&quantum_state,p,&pixel);
3429 SetPixelBlue(image,ClampToQuantum(pixel),q);
3430 p=PushFloatPixel(&quantum_state,p,&pixel);
3431 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3432 p+=quantum_info->pad;
3433 q+=GetPixelChannels(image);
3437 for (x=0; x < (ssize_t) number_pixels; x++)
3439 p=PushLongPixel(endian,p,&pixel);
3440 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3441 p=PushLongPixel(endian,p,&pixel);
3442 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
3443 p=PushLongPixel(endian,p,&pixel);
3444 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
3445 p=PushLongPixel(endian,p,&pixel);
3446 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
3447 p+=quantum_info->pad;
3448 q+=GetPixelChannels(image);
3454 if (quantum_info->format == FloatingPointQuantumFormat)
3459 for (x=0; x < (ssize_t) number_pixels; x++)
3461 p=PushDoublePixel(&quantum_state,p,&pixel);
3462 SetPixelRed(image,ClampToQuantum(pixel),q);
3463 p=PushDoublePixel(&quantum_state,p,&pixel);
3464 SetPixelGreen(image,ClampToQuantum(pixel),q);
3465 p=PushDoublePixel(&quantum_state,p,&pixel);
3466 SetPixelBlue(image,ClampToQuantum(pixel),q);
3467 p=PushDoublePixel(&quantum_state,p,&pixel);
3468 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3469 p+=quantum_info->pad;
3470 q+=GetPixelChannels(image);
3477 range=GetQuantumRange(image->depth);
3478 for (x=0; x < (ssize_t) number_pixels; x++)
3480 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3481 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3482 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3483 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3484 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3485 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3486 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
3487 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
3488 q+=GetPixelChannels(image);
3495 MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
3496 const QuantumInfo *quantum_info,const QuantumType quantum_type,
3497 const unsigned char *pixels,ExceptionInfo *exception)
3505 register const unsigned char
3517 assert(image != (Image *) NULL);
3518 assert(image->signature == MagickSignature);
3519 if (image->debug != MagickFalse)
3520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3521 assert(quantum_info != (QuantumInfo *) NULL);
3522 assert(quantum_info->signature == MagickSignature);
3523 if (pixels == (const unsigned char *) NULL)
3524 pixels=GetQuantumPixels(quantum_info);
3527 if (image_view == (CacheView *) NULL)
3529 number_pixels=GetImageExtent(image);
3530 q=GetAuthenticPixelQueue(image);
3534 number_pixels=GetCacheViewExtent(image_view);
3535 q=GetCacheViewAuthenticPixelQueue(image_view);
3537 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
3538 extent=GetQuantumExtent(image,quantum_info,quantum_type);
3539 switch (quantum_type)
3543 ImportAlphaQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3549 ImportBGRQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3556 ImportBGRAQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3562 ImportBlackQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3569 ImportBlueQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3575 ImportCMYKQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3582 ImportCMYKAQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3588 ImportCbYCrYQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3594 ImportGrayQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3598 case GrayAlphaQuantum:
3600 ImportGrayAlphaQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3605 case MagentaQuantum:
3607 ImportGreenQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3613 ImportIndexQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3617 case IndexAlphaQuantum:
3619 ImportIndexAlphaQuantum(image,quantum_info,quantum_state,number_pixels,p,
3623 case OpacityQuantum:
3625 ImportOpacityQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3632 ImportRedQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3639 ImportRGBQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3647 ImportRGBAQuantum(image,quantum_info,quantum_state,number_pixels,p,q,
3654 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3662 q=GetAuthenticPixelQueue(image);
3663 if (image_view != (CacheView *) NULL)
3664 q=GetCacheViewAuthenticPixelQueue(image_view);
3665 for (x=0; x < (ssize_t) number_pixels; x++)
3667 quantum=GetPixelRed(image,q);
3668 SetPixelRed(image,GetPixelGreen(image,q),q);
3669 SetPixelGreen(image,quantum,q);
3670 q+=GetPixelChannels(image);
3673 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
3678 q=GetAuthenticPixelQueue(image);
3679 if (image_view != (CacheView *) NULL)
3680 q=GetCacheViewAuthenticPixelQueue(image_view);
3681 for (x=0; x < (ssize_t) number_pixels; x++)
3683 SetPixelAlpha(image,GetPixelAlpha(image,q),q);
3684 q+=GetPixelChannels(image);
3687 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
3699 q=GetAuthenticPixelQueue(image);
3700 if (image_view != (CacheView *) NULL)
3701 q=GetCacheViewAuthenticPixelQueue(image_view);
3702 for (x=0; x < (ssize_t) number_pixels; x++)
3707 Sa=QuantumScale*GetPixelAlpha(image,q);
3708 gamma=1.0/(fabs(Sa) <= MagickEpsilon ? 1.0 : Sa);
3709 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3717 channel=GetPixelChannelMapChannel(image,i);
3718 traits=GetPixelChannelMapTraits(image,channel);
3719 if ((traits & UpdatePixelTrait) != 0)
3720 q[i]=ClampToQuantum(gamma*q[i]);
3722 q+=GetPixelChannels(image);