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-2013 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/pixel-private.h"
66 #include "MagickCore/quantum.h"
67 #include "MagickCore/quantum-private.h"
68 #include "MagickCore/resource_.h"
69 #include "MagickCore/semaphore.h"
70 #include "MagickCore/statistic.h"
71 #include "MagickCore/stream.h"
72 #include "MagickCore/string_.h"
73 #include "MagickCore/utility.h"
76 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 % I m p o r t Q u a n t u m P i x e l s %
84 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 % ImportQuantumPixels() transfers one or more pixel components from a user
87 % supplied buffer into the image pixel cache of an image. The pixels are
88 % expected in network byte order. It returns MagickTrue if the pixels are
89 % successfully transferred, otherwise MagickFalse.
91 % The format of the ImportQuantumPixels method is:
93 % size_t ImportQuantumPixels(const Image *image,CacheView *image_view,
94 % QuantumInfo *quantum_info,const QuantumType quantum_type,
95 % const unsigned char *pixels,ExceptionInfo *exception)
97 % A description of each parameter follows:
101 % o image_view: the image cache view.
103 % o quantum_info: the quantum info.
105 % o quantum_type: Declare which pixel components to transfer (red, green,
106 % blue, opacity, RGB, or RGBA).
108 % o pixels: The pixel components are transferred from this buffer.
110 % o exception: return any errors or warnings in this structure.
114 static inline Quantum PushColormapIndex(const Image *image,const size_t index,
115 MagickBooleanType *range_exception)
117 if (index < image->colors)
118 return((Quantum) index);
119 *range_exception=MagickTrue;
123 static inline const unsigned char *PushDoublePixel(QuantumInfo *quantum_info,
124 const unsigned char *pixels,double *pixel)
132 if (quantum_info->endian == LSBEndian)
134 quantum[0]=(*pixels++);
135 quantum[1]=(*pixels++);
136 quantum[2]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[4]=(*pixels++);
139 quantum[5]=(*pixels++);
140 quantum[6]=(*pixels++);
141 quantum[7]=(*pixels++);
142 p=(double *) quantum;
144 *pixel-=quantum_info->minimum;
145 *pixel*=quantum_info->scale;
148 quantum[7]=(*pixels++);
149 quantum[6]=(*pixels++);
150 quantum[5]=(*pixels++);
151 quantum[5]=(*pixels++);
152 quantum[3]=(*pixels++);
153 quantum[2]=(*pixels++);
154 quantum[1]=(*pixels++);
155 quantum[0]=(*pixels++);
156 p=(double *) quantum;
158 *pixel-=quantum_info->minimum;
159 *pixel*=quantum_info->scale;
163 static inline const unsigned char *PushFloatPixel(QuantumInfo *quantum_info,
164 const unsigned char *pixels,float *pixel)
172 if (quantum_info->endian == LSBEndian)
174 quantum[0]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[2]=(*pixels++);
177 quantum[3]=(*pixels++);
180 *pixel-=quantum_info->minimum;
181 *pixel*=quantum_info->scale;
184 quantum[3]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[1]=(*pixels++);
187 quantum[0]=(*pixels++);
190 *pixel-=quantum_info->minimum;
191 *pixel*=quantum_info->scale;
195 static inline const unsigned char *PushQuantumPixel(QuantumInfo *quantum_info,
196 const unsigned char *pixels,unsigned int *quantum)
204 *quantum=(QuantumAny) 0;
205 for (i=(ssize_t) quantum_info->depth; i > 0L; )
207 if (quantum_info->state.bits == 0UL)
209 quantum_info->state.pixel=(*pixels++);
210 quantum_info->state.bits=8UL;
212 quantum_bits=(size_t) i;
213 if (quantum_bits > quantum_info->state.bits)
214 quantum_bits=quantum_info->state.bits;
215 i-=(ssize_t) quantum_bits;
216 quantum_info->state.bits-=quantum_bits;
217 *quantum=(unsigned int) ((*quantum << quantum_bits) |
218 ((quantum_info->state.pixel >> quantum_info->state.bits) &~ ((~0UL) <<
224 static inline const unsigned char *PushQuantumLongPixel(
225 QuantumInfo *quantum_info,const unsigned char *pixels,unsigned int *quantum)
234 for (i=(ssize_t) quantum_info->depth; i > 0; )
236 if (quantum_info->state.bits == 0)
238 pixels=PushLongPixel(quantum_info->endian,pixels,
239 &quantum_info->state.pixel);
240 quantum_info->state.bits=32U;
242 quantum_bits=(size_t) i;
243 if (quantum_bits > quantum_info->state.bits)
244 quantum_bits=quantum_info->state.bits;
245 *quantum|=(((quantum_info->state.pixel >> (32U-quantum_info->state.bits)) &
246 quantum_info->state.mask[quantum_bits]) << (quantum_info->depth-i));
247 i-=(ssize_t) quantum_bits;
248 quantum_info->state.bits-=quantum_bits;
253 static void ImportAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
254 const MagickSizeType number_pixels,const unsigned char *restrict p,
255 Quantum *restrict q,ExceptionInfo *exception)
266 switch (quantum_info->depth)
273 for (x=0; x < (ssize_t) number_pixels; x++)
275 p=PushCharPixel(p,&pixel);
276 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
277 p+=quantum_info->pad;
278 q+=GetPixelChannels(image);
287 if (quantum_info->format == FloatingPointQuantumFormat)
289 for (x=0; x < (ssize_t) number_pixels; x++)
291 p=PushShortPixel(quantum_info->endian,p,&pixel);
292 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
293 HalfToSinglePrecision(pixel)),q);
294 p+=quantum_info->pad;
295 q+=GetPixelChannels(image);
299 for (x=0; x < (ssize_t) number_pixels; x++)
301 p=PushShortPixel(quantum_info->endian,p,&pixel);
302 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
303 p+=quantum_info->pad;
304 q+=GetPixelChannels(image);
313 if (quantum_info->format == FloatingPointQuantumFormat)
318 for (x=0; x < (ssize_t) number_pixels; x++)
320 p=PushFloatPixel(quantum_info,p,&pixel);
321 SetPixelAlpha(image,ClampToQuantum(pixel),q);
322 p+=quantum_info->pad;
323 q+=GetPixelChannels(image);
327 for (x=0; x < (ssize_t) number_pixels; x++)
329 p=PushLongPixel(quantum_info->endian,p,&pixel);
330 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
331 p+=quantum_info->pad;
332 q+=GetPixelChannels(image);
338 if (quantum_info->format == FloatingPointQuantumFormat)
343 for (x=0; x < (ssize_t) number_pixels; x++)
345 p=PushDoublePixel(quantum_info,p,&pixel);
346 SetPixelAlpha(image,ClampToQuantum(pixel),q);
347 p+=quantum_info->pad;
348 q+=GetPixelChannels(image);
355 range=GetQuantumRange(quantum_info->depth);
356 for (x=0; x < (ssize_t) number_pixels; x++)
358 p=PushQuantumPixel(quantum_info,p,&pixel);
359 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
360 p+=quantum_info->pad;
361 q+=GetPixelChannels(image);
368 static void ImportBGRQuantum(const Image *image,QuantumInfo *quantum_info,
369 const MagickSizeType number_pixels,const unsigned char *restrict p,
370 Quantum *restrict q,ExceptionInfo *exception)
384 switch (quantum_info->depth)
391 for (x=0; x < (ssize_t) number_pixels; x++)
393 p=PushCharPixel(p,&pixel);
394 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
395 p=PushCharPixel(p,&pixel);
396 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
397 p=PushCharPixel(p,&pixel);
398 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
399 SetPixelAlpha(image,OpaqueAlpha,q);
400 p+=quantum_info->pad;
401 q+=GetPixelChannels(image);
407 range=GetQuantumRange(quantum_info->depth);
408 if (quantum_info->pack == MagickFalse)
410 for (x=0; x < (ssize_t) number_pixels; x++)
412 p=PushLongPixel(quantum_info->endian,p,&pixel);
413 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
414 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
416 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
417 p+=quantum_info->pad;
418 q+=GetPixelChannels(image);
422 if (quantum_info->quantum == 32U)
424 for (x=0; x < (ssize_t) number_pixels; x++)
426 p=PushQuantumLongPixel(quantum_info,p,&pixel);
427 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
428 p=PushQuantumLongPixel(quantum_info,p,&pixel);
429 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
430 p=PushQuantumLongPixel(quantum_info,p,&pixel);
431 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
432 q+=GetPixelChannels(image);
436 for (x=0; x < (ssize_t) number_pixels; x++)
438 p=PushQuantumPixel(quantum_info,p,&pixel);
439 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
440 p=PushQuantumPixel(quantum_info,p,&pixel);
441 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
442 p=PushQuantumPixel(quantum_info,p,&pixel);
443 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
444 q+=GetPixelChannels(image);
450 range=GetQuantumRange(quantum_info->depth);
451 if (quantum_info->pack == MagickFalse)
456 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
458 p=PushShortPixel(quantum_info->endian,p,&pixel);
464 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
470 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
476 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
478 q+=GetPixelChannels(image);
482 p=PushShortPixel(quantum_info->endian,p,&pixel);
488 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
494 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
500 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
502 q+=GetPixelChannels(image);
506 p+=quantum_info->pad;
508 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
510 p=PushShortPixel(quantum_info->endian,p,&pixel);
516 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
522 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
528 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
530 q+=GetPixelChannels(image);
534 p+=quantum_info->pad;
540 if (quantum_info->quantum == 32U)
542 for (x=0; x < (ssize_t) number_pixels; x++)
544 p=PushQuantumLongPixel(quantum_info,p,&pixel);
545 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
546 p=PushQuantumLongPixel(quantum_info,p,&pixel);
547 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
548 p=PushQuantumLongPixel(quantum_info,p,&pixel);
549 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
550 q+=GetPixelChannels(image);
554 for (x=0; x < (ssize_t) number_pixels; x++)
556 p=PushQuantumPixel(quantum_info,p,&pixel);
557 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
558 p=PushQuantumPixel(quantum_info,p,&pixel);
559 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
560 p=PushQuantumPixel(quantum_info,p,&pixel);
561 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
562 q+=GetPixelChannels(image);
571 if (quantum_info->format == FloatingPointQuantumFormat)
573 for (x=0; x < (ssize_t) number_pixels; x++)
575 p=PushShortPixel(quantum_info->endian,p,&pixel);
576 SetPixelRed(image,ClampToQuantum(QuantumRange*
577 HalfToSinglePrecision(pixel)),q);
578 p=PushShortPixel(quantum_info->endian,p,&pixel);
579 SetPixelGreen(image,ClampToQuantum(QuantumRange*
580 HalfToSinglePrecision(pixel)),q);
581 p=PushShortPixel(quantum_info->endian,p,&pixel);
582 SetPixelBlue(image,ClampToQuantum(QuantumRange*
583 HalfToSinglePrecision(pixel)),q);
584 p+=quantum_info->pad;
585 q+=GetPixelChannels(image);
589 for (x=0; x < (ssize_t) number_pixels; x++)
591 p=PushShortPixel(quantum_info->endian,p,&pixel);
592 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
593 p=PushShortPixel(quantum_info->endian,p,&pixel);
594 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
595 p=PushShortPixel(quantum_info->endian,p,&pixel);
596 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
597 p+=quantum_info->pad;
598 q+=GetPixelChannels(image);
607 if (quantum_info->format == FloatingPointQuantumFormat)
612 for (x=0; x < (ssize_t) number_pixels; x++)
614 p=PushFloatPixel(quantum_info,p,&pixel);
615 SetPixelRed(image,ClampToQuantum(pixel),q);
616 p=PushFloatPixel(quantum_info,p,&pixel);
617 SetPixelGreen(image,ClampToQuantum(pixel),q);
618 p=PushFloatPixel(quantum_info,p,&pixel);
619 SetPixelBlue(image,ClampToQuantum(pixel),q);
620 p+=quantum_info->pad;
621 q+=GetPixelChannels(image);
625 for (x=0; x < (ssize_t) number_pixels; x++)
627 p=PushLongPixel(quantum_info->endian,p,&pixel);
628 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
629 p=PushLongPixel(quantum_info->endian,p,&pixel);
630 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
631 p=PushLongPixel(quantum_info->endian,p,&pixel);
632 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
633 p+=quantum_info->pad;
634 q+=GetPixelChannels(image);
640 if (quantum_info->format == FloatingPointQuantumFormat)
645 for (x=0; x < (ssize_t) number_pixels; x++)
647 p=PushDoublePixel(quantum_info,p,&pixel);
648 SetPixelRed(image,ClampToQuantum(pixel),q);
649 p=PushDoublePixel(quantum_info,p,&pixel);
650 SetPixelGreen(image,ClampToQuantum(pixel),q);
651 p=PushDoublePixel(quantum_info,p,&pixel);
652 SetPixelBlue(image,ClampToQuantum(pixel),q);
653 p+=quantum_info->pad;
654 q+=GetPixelChannels(image);
661 range=GetQuantumRange(quantum_info->depth);
662 for (x=0; x < (ssize_t) number_pixels; x++)
664 p=PushQuantumPixel(quantum_info,p,&pixel);
665 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
666 p=PushQuantumPixel(quantum_info,p,&pixel);
667 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
668 p=PushQuantumPixel(quantum_info,p,&pixel);
669 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
670 q+=GetPixelChannels(image);
677 static void ImportBGRAQuantum(const Image *image,QuantumInfo *quantum_info,
678 const MagickSizeType number_pixels,const unsigned char *restrict p,
679 Quantum *restrict q,ExceptionInfo *exception)
690 switch (quantum_info->depth)
697 for (x=0; x < (ssize_t) number_pixels; x++)
699 p=PushCharPixel(p,&pixel);
700 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
701 p=PushCharPixel(p,&pixel);
702 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
703 p=PushCharPixel(p,&pixel);
704 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
705 p=PushCharPixel(p,&pixel);
706 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
707 p+=quantum_info->pad;
708 q+=GetPixelChannels(image);
715 if (quantum_info->pack == MagickFalse)
728 for (x=0; x < (ssize_t) number_pixels; x++)
730 for (i=0; i < 4; i++)
736 p=PushLongPixel(quantum_info->endian,p,&pixel);
737 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
738 (((pixel >> 22) & 0x3ff) << 6)));
743 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
744 (((pixel >> 12) & 0x3ff) << 6)));
749 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
750 (((pixel >> 2) & 0x3ff) << 6)));
756 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
757 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
758 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
759 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
763 p+=quantum_info->pad;
764 q+=GetPixelChannels(image);
768 for (x=0; x < (ssize_t) number_pixels; x++)
770 p=PushQuantumPixel(quantum_info,p,&pixel);
771 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
772 p=PushQuantumPixel(quantum_info,p,&pixel);
773 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
775 p=PushQuantumPixel(quantum_info,p,&pixel);
776 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
778 p=PushQuantumPixel(quantum_info,p,&pixel);
779 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
781 q+=GetPixelChannels(image);
790 if (quantum_info->format == FloatingPointQuantumFormat)
792 for (x=0; x < (ssize_t) number_pixels; x++)
794 p=PushShortPixel(quantum_info->endian,p,&pixel);
795 SetPixelRed(image,ClampToQuantum(QuantumRange*
796 HalfToSinglePrecision(pixel)),q);
797 p=PushShortPixel(quantum_info->endian,p,&pixel);
798 SetPixelGreen(image,ClampToQuantum(QuantumRange*
799 HalfToSinglePrecision(pixel)),q);
800 p=PushShortPixel(quantum_info->endian,p,&pixel);
801 SetPixelBlue(image,ClampToQuantum(QuantumRange*
802 HalfToSinglePrecision(pixel)),q);
803 p=PushShortPixel(quantum_info->endian,p,&pixel);
804 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
805 HalfToSinglePrecision(pixel)),q);
806 p+=quantum_info->pad;
807 q+=GetPixelChannels(image);
811 for (x=0; x < (ssize_t) number_pixels; x++)
813 p=PushShortPixel(quantum_info->endian,p,&pixel);
814 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
815 p=PushShortPixel(quantum_info->endian,p,&pixel);
816 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
817 p=PushShortPixel(quantum_info->endian,p,&pixel);
818 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
819 p=PushShortPixel(quantum_info->endian,p,&pixel);
820 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
821 p+=quantum_info->pad;
822 q+=GetPixelChannels(image);
831 if (quantum_info->format == FloatingPointQuantumFormat)
836 for (x=0; x < (ssize_t) number_pixels; x++)
838 p=PushFloatPixel(quantum_info,p,&pixel);
839 SetPixelRed(image,ClampToQuantum(pixel),q);
840 p=PushFloatPixel(quantum_info,p,&pixel);
841 SetPixelGreen(image,ClampToQuantum(pixel),q);
842 p=PushFloatPixel(quantum_info,p,&pixel);
843 SetPixelBlue(image,ClampToQuantum(pixel),q);
844 p=PushFloatPixel(quantum_info,p,&pixel);
845 SetPixelAlpha(image,ClampToQuantum(pixel),q);
846 p+=quantum_info->pad;
847 q+=GetPixelChannels(image);
851 for (x=0; x < (ssize_t) number_pixels; x++)
853 p=PushLongPixel(quantum_info->endian,p,&pixel);
854 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
855 p=PushLongPixel(quantum_info->endian,p,&pixel);
856 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
857 p=PushLongPixel(quantum_info->endian,p,&pixel);
858 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
859 p=PushLongPixel(quantum_info->endian,p,&pixel);
860 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
861 p+=quantum_info->pad;
862 q+=GetPixelChannels(image);
868 if (quantum_info->format == FloatingPointQuantumFormat)
873 for (x=0; x < (ssize_t) number_pixels; x++)
875 p=PushDoublePixel(quantum_info,p,&pixel);
876 SetPixelRed(image,ClampToQuantum(pixel),q);
877 p=PushDoublePixel(quantum_info,p,&pixel);
878 SetPixelGreen(image,ClampToQuantum(pixel),q);
879 p=PushDoublePixel(quantum_info,p,&pixel);
880 SetPixelBlue(image,ClampToQuantum(pixel),q);
881 p=PushDoublePixel(quantum_info,p,&pixel);
882 SetPixelAlpha(image,ClampToQuantum(pixel),q);
883 p+=quantum_info->pad;
884 q+=GetPixelChannels(image);
891 range=GetQuantumRange(quantum_info->depth);
892 for (x=0; x < (ssize_t) number_pixels; x++)
894 p=PushQuantumPixel(quantum_info,p,&pixel);
895 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
896 p=PushQuantumPixel(quantum_info,p,&pixel);
897 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
898 p=PushQuantumPixel(quantum_info,p,&pixel);
899 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
900 p=PushQuantumPixel(quantum_info,p,&pixel);
901 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
902 q+=GetPixelChannels(image);
909 static void ImportBlackQuantum(const Image *image,QuantumInfo *quantum_info,
910 const MagickSizeType number_pixels,const unsigned char *restrict p,
911 Quantum *restrict q,ExceptionInfo *exception)
922 if (image->colorspace != CMYKColorspace)
924 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
925 "ColorSeparatedImageRequired","`%s'",image->filename);
928 switch (quantum_info->depth)
935 for (x=0; x < (ssize_t) number_pixels; x++)
937 p=PushCharPixel(p,&pixel);
938 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
939 p+=quantum_info->pad;
940 q+=GetPixelChannels(image);
949 if (quantum_info->format == FloatingPointQuantumFormat)
951 for (x=0; x < (ssize_t) number_pixels; x++)
953 p=PushShortPixel(quantum_info->endian,p,&pixel);
954 SetPixelBlack(image,ClampToQuantum(QuantumRange*
955 HalfToSinglePrecision(pixel)),q);
956 p+=quantum_info->pad;
957 q+=GetPixelChannels(image);
961 for (x=0; x < (ssize_t) number_pixels; x++)
963 p=PushShortPixel(quantum_info->endian,p,&pixel);
964 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
965 p+=quantum_info->pad;
966 q+=GetPixelChannels(image);
975 if (quantum_info->format == FloatingPointQuantumFormat)
980 for (x=0; x < (ssize_t) number_pixels; x++)
982 p=PushFloatPixel(quantum_info,p,&pixel);
983 SetPixelBlack(image,ClampToQuantum(pixel),q);
984 p+=quantum_info->pad;
985 q+=GetPixelChannels(image);
989 for (x=0; x < (ssize_t) number_pixels; x++)
991 p=PushLongPixel(quantum_info->endian,p,&pixel);
992 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
993 p+=quantum_info->pad;
994 q+=GetPixelChannels(image);
1000 if (quantum_info->format == FloatingPointQuantumFormat)
1005 for (x=0; x < (ssize_t) number_pixels; x++)
1007 p=PushDoublePixel(quantum_info,p,&pixel);
1008 SetPixelBlack(image,ClampToQuantum(pixel),q);
1009 p+=quantum_info->pad;
1010 q+=GetPixelChannels(image);
1017 range=GetQuantumRange(quantum_info->depth);
1018 for (x=0; x < (ssize_t) number_pixels; x++)
1020 p=PushQuantumPixel(quantum_info,p,&pixel);
1021 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1022 p+=quantum_info->pad;
1023 q+=GetPixelChannels(image);
1030 static void ImportBlueQuantum(const Image *image,QuantumInfo *quantum_info,
1031 const MagickSizeType number_pixels,const unsigned char *restrict p,
1032 Quantum *restrict q,ExceptionInfo *exception)
1043 switch (quantum_info->depth)
1050 for (x=0; x < (ssize_t) number_pixels; x++)
1052 p=PushCharPixel(p,&pixel);
1053 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1054 p+=quantum_info->pad;
1055 q+=GetPixelChannels(image);
1064 if (quantum_info->format == FloatingPointQuantumFormat)
1066 for (x=0; x < (ssize_t) number_pixels; x++)
1068 p=PushShortPixel(quantum_info->endian,p,&pixel);
1069 SetPixelBlue(image,ClampToQuantum(QuantumRange*
1070 HalfToSinglePrecision(pixel)),q);
1071 p+=quantum_info->pad;
1072 q+=GetPixelChannels(image);
1076 for (x=0; x < (ssize_t) number_pixels; x++)
1078 p=PushShortPixel(quantum_info->endian,p,&pixel);
1079 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1080 p+=quantum_info->pad;
1081 q+=GetPixelChannels(image);
1090 if (quantum_info->format == FloatingPointQuantumFormat)
1095 for (x=0; x < (ssize_t) number_pixels; x++)
1097 p=PushFloatPixel(quantum_info,p,&pixel);
1098 SetPixelBlue(image,ClampToQuantum(pixel),q);
1099 p+=quantum_info->pad;
1100 q+=GetPixelChannels(image);
1104 for (x=0; x < (ssize_t) number_pixels; x++)
1106 p=PushLongPixel(quantum_info->endian,p,&pixel);
1107 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1108 p+=quantum_info->pad;
1109 q+=GetPixelChannels(image);
1115 if (quantum_info->format == FloatingPointQuantumFormat)
1120 for (x=0; x < (ssize_t) number_pixels; x++)
1122 p=PushDoublePixel(quantum_info,p,&pixel);
1123 SetPixelBlue(image,ClampToQuantum(pixel),q);
1124 p+=quantum_info->pad;
1125 q+=GetPixelChannels(image);
1132 range=GetQuantumRange(quantum_info->depth);
1133 for (x=0; x < (ssize_t) number_pixels; x++)
1135 p=PushQuantumPixel(quantum_info,p,&pixel);
1136 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1137 p+=quantum_info->pad;
1138 q+=GetPixelChannels(image);
1145 static void ImportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info,
1146 const MagickSizeType number_pixels,const unsigned char *restrict p,
1147 Quantum *restrict q,ExceptionInfo *exception)
1158 switch (quantum_info->depth)
1166 if (quantum_info->pack == MagickFalse)
1179 for (x=0; x < (ssize_t) number_pixels; x+=2)
1181 for (i=0; i < 4; i++)
1187 p=PushLongPixel(quantum_info->endian,p,&pixel);
1188 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1189 (((pixel >> 22) & 0x3ff) << 6)));
1194 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1195 (((pixel >> 12) & 0x3ff) << 6)));
1200 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1201 (((pixel >> 2) & 0x3ff) << 6)));
1205 cbcr[i]=(Quantum) (quantum);
1208 p+=quantum_info->pad;
1209 SetPixelRed(image,cbcr[1],q);
1210 SetPixelGreen(image,cbcr[0],q);
1211 SetPixelBlue(image,cbcr[2],q);
1212 q+=GetPixelChannels(image);
1213 SetPixelRed(image,cbcr[3],q);
1214 SetPixelGreen(image,cbcr[0],q);
1215 SetPixelBlue(image,cbcr[2],q);
1216 q+=GetPixelChannels(image);
1223 range=GetQuantumRange(quantum_info->depth);
1224 for (x=0; x < (ssize_t) number_pixels; x++)
1226 p=PushQuantumPixel(quantum_info,p,&pixel);
1227 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1228 p=PushQuantumPixel(quantum_info,p,&pixel);
1229 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1230 q+=GetPixelChannels(image);
1237 static void ImportCMYKQuantum(const Image *image,QuantumInfo *quantum_info,
1238 const MagickSizeType number_pixels,const unsigned char *restrict p,
1239 Quantum *restrict q,ExceptionInfo *exception)
1250 if (image->colorspace != CMYKColorspace)
1252 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1253 "ColorSeparatedImageRequired","`%s'",image->filename);
1256 switch (quantum_info->depth)
1263 for (x=0; x < (ssize_t) number_pixels; x++)
1265 p=PushCharPixel(p,&pixel);
1266 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1267 p=PushCharPixel(p,&pixel);
1268 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1269 p=PushCharPixel(p,&pixel);
1270 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1271 p=PushCharPixel(p,&pixel);
1272 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1273 p+=quantum_info->pad;
1274 q+=GetPixelChannels(image);
1283 if (quantum_info->format == FloatingPointQuantumFormat)
1285 for (x=0; x < (ssize_t) number_pixels; x++)
1287 p=PushShortPixel(quantum_info->endian,p,&pixel);
1288 SetPixelRed(image,ClampToQuantum(QuantumRange*
1289 HalfToSinglePrecision(pixel)),q);
1290 p=PushShortPixel(quantum_info->endian,p,&pixel);
1291 SetPixelGreen(image,ClampToQuantum(QuantumRange*
1292 HalfToSinglePrecision(pixel)),q);
1293 p=PushShortPixel(quantum_info->endian,p,&pixel);
1294 SetPixelBlue(image,ClampToQuantum(QuantumRange*
1295 HalfToSinglePrecision(pixel)),q);
1296 p=PushShortPixel(quantum_info->endian,p,&pixel);
1297 SetPixelBlack(image,ClampToQuantum(QuantumRange*
1298 HalfToSinglePrecision(pixel)),q);
1299 p+=quantum_info->pad;
1300 q+=GetPixelChannels(image);
1304 for (x=0; x < (ssize_t) number_pixels; x++)
1306 p=PushShortPixel(quantum_info->endian,p,&pixel);
1307 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1308 p=PushShortPixel(quantum_info->endian,p,&pixel);
1309 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1310 p=PushShortPixel(quantum_info->endian,p,&pixel);
1311 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1312 p=PushShortPixel(quantum_info->endian,p,&pixel);
1313 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1314 p+=quantum_info->pad;
1315 q+=GetPixelChannels(image);
1324 if (quantum_info->format == FloatingPointQuantumFormat)
1329 for (x=0; x < (ssize_t) number_pixels; x++)
1331 p=PushFloatPixel(quantum_info,p,&pixel);
1332 SetPixelRed(image,ClampToQuantum(pixel),q);
1333 p=PushFloatPixel(quantum_info,p,&pixel);
1334 SetPixelGreen(image,ClampToQuantum(pixel),q);
1335 p=PushFloatPixel(quantum_info,p,&pixel);
1336 SetPixelBlue(image,ClampToQuantum(pixel),q);
1337 p=PushFloatPixel(quantum_info,p,&pixel);
1338 SetPixelBlack(image,ClampToQuantum(pixel),q);
1339 p+=quantum_info->pad;
1340 q+=GetPixelChannels(image);
1344 for (x=0; x < (ssize_t) number_pixels; x++)
1346 p=PushLongPixel(quantum_info->endian,p,&pixel);
1347 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1348 p=PushLongPixel(quantum_info->endian,p,&pixel);
1349 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1350 p=PushLongPixel(quantum_info->endian,p,&pixel);
1351 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1352 p=PushLongPixel(quantum_info->endian,p,&pixel);
1353 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1354 p+=quantum_info->pad;
1355 q+=GetPixelChannels(image);
1361 if (quantum_info->format == FloatingPointQuantumFormat)
1366 for (x=0; x < (ssize_t) number_pixels; x++)
1368 p=PushDoublePixel(quantum_info,p,&pixel);
1369 SetPixelRed(image,ClampToQuantum(pixel),q);
1370 p=PushDoublePixel(quantum_info,p,&pixel);
1371 SetPixelGreen(image,ClampToQuantum(pixel),q);
1372 p=PushDoublePixel(quantum_info,p,&pixel);
1373 SetPixelBlue(image,ClampToQuantum(pixel),q);
1374 p=PushDoublePixel(quantum_info,p,&pixel);
1375 SetPixelBlack(image,ClampToQuantum(pixel),q);
1376 p+=quantum_info->pad;
1377 q+=GetPixelChannels(image);
1384 range=GetQuantumRange(quantum_info->depth);
1385 for (x=0; x < (ssize_t) number_pixels; x++)
1387 p=PushQuantumPixel(quantum_info,p,&pixel);
1388 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1389 p=PushQuantumPixel(quantum_info,p,&pixel);
1390 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1391 p=PushQuantumPixel(quantum_info,p,&pixel);
1392 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1393 p=PushQuantumPixel(quantum_info,p,&pixel);
1394 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1395 q+=GetPixelChannels(image);
1402 static void ImportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info,
1403 const MagickSizeType number_pixels,const unsigned char *restrict p,
1404 Quantum *restrict q,ExceptionInfo *exception)
1415 if (image->colorspace != CMYKColorspace)
1417 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1418 "ColorSeparatedImageRequired","`%s'",image->filename);
1421 switch (quantum_info->depth)
1428 for (x=0; x < (ssize_t) number_pixels; x++)
1430 p=PushCharPixel(p,&pixel);
1431 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1432 p=PushCharPixel(p,&pixel);
1433 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1434 p=PushCharPixel(p,&pixel);
1435 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1436 p=PushCharPixel(p,&pixel);
1437 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1438 p=PushCharPixel(p,&pixel);
1439 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
1440 p+=quantum_info->pad;
1441 q+=GetPixelChannels(image);
1450 if (quantum_info->format == FloatingPointQuantumFormat)
1452 for (x=0; x < (ssize_t) number_pixels; x++)
1454 p=PushShortPixel(quantum_info->endian,p,&pixel);
1455 SetPixelRed(image,ClampToQuantum(QuantumRange*
1456 HalfToSinglePrecision(pixel)),q);
1457 p=PushShortPixel(quantum_info->endian,p,&pixel);
1458 SetPixelGreen(image,ClampToQuantum(QuantumRange*
1459 HalfToSinglePrecision(pixel)),q);
1460 p=PushShortPixel(quantum_info->endian,p,&pixel);
1461 SetPixelBlue(image,ClampToQuantum(QuantumRange*
1462 HalfToSinglePrecision(pixel)),q);
1463 p=PushShortPixel(quantum_info->endian,p,&pixel);
1464 SetPixelBlack(image,ClampToQuantum(QuantumRange*
1465 HalfToSinglePrecision(pixel)),q);
1466 p=PushShortPixel(quantum_info->endian,p,&pixel);
1467 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
1468 HalfToSinglePrecision(pixel)),q);
1469 p+=quantum_info->pad;
1470 q+=GetPixelChannels(image);
1474 for (x=0; x < (ssize_t) number_pixels; x++)
1476 p=PushShortPixel(quantum_info->endian,p,&pixel);
1477 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1478 p=PushShortPixel(quantum_info->endian,p,&pixel);
1479 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1480 p=PushShortPixel(quantum_info->endian,p,&pixel);
1481 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1482 p=PushShortPixel(quantum_info->endian,p,&pixel);
1483 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1484 p=PushShortPixel(quantum_info->endian,p,&pixel);
1485 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
1486 p+=quantum_info->pad;
1487 q+=GetPixelChannels(image);
1496 if (quantum_info->format == FloatingPointQuantumFormat)
1501 for (x=0; x < (ssize_t) number_pixels; x++)
1503 p=PushFloatPixel(quantum_info,p,&pixel);
1504 SetPixelRed(image,ClampToQuantum(pixel),q);
1505 p=PushFloatPixel(quantum_info,p,&pixel);
1506 SetPixelGreen(image,ClampToQuantum(pixel),q);
1507 p=PushFloatPixel(quantum_info,p,&pixel);
1508 SetPixelBlue(image,ClampToQuantum(pixel),q);
1509 p=PushFloatPixel(quantum_info,p,&pixel);
1510 SetPixelBlack(image,ClampToQuantum(pixel),q);
1511 p=PushFloatPixel(quantum_info,p,&pixel);
1512 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1513 p+=quantum_info->pad;
1514 q+=GetPixelChannels(image);
1518 for (x=0; x < (ssize_t) number_pixels; x++)
1520 p=PushLongPixel(quantum_info->endian,p,&pixel);
1521 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1522 p=PushLongPixel(quantum_info->endian,p,&pixel);
1523 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1524 p=PushLongPixel(quantum_info->endian,p,&pixel);
1525 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1526 p=PushLongPixel(quantum_info->endian,p,&pixel);
1527 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1528 p=PushLongPixel(quantum_info->endian,p,&pixel);
1529 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
1530 p+=quantum_info->pad;
1531 q+=GetPixelChannels(image);
1537 if (quantum_info->format == FloatingPointQuantumFormat)
1542 for (x=0; x < (ssize_t) number_pixels; x++)
1544 p=PushDoublePixel(quantum_info,p,&pixel);
1545 SetPixelRed(image,ClampToQuantum(pixel),q);
1546 p=PushDoublePixel(quantum_info,p,&pixel);
1547 SetPixelGreen(image,ClampToQuantum(pixel),q);
1548 p=PushDoublePixel(quantum_info,p,&pixel);
1549 SetPixelBlue(image,ClampToQuantum(pixel),q);
1550 p=PushDoublePixel(quantum_info,p,&pixel);
1551 SetPixelBlack(image,ClampToQuantum(pixel),q);
1552 p=PushDoublePixel(quantum_info,p,&pixel);
1553 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1554 p=PushDoublePixel(quantum_info,p,&pixel);
1555 p+=quantum_info->pad;
1556 q+=GetPixelChannels(image);
1563 range=GetQuantumRange(quantum_info->depth);
1564 for (x=0; x < (ssize_t) number_pixels; x++)
1566 p=PushQuantumPixel(quantum_info,p,&pixel);
1567 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1568 p=PushQuantumPixel(quantum_info,p,&pixel);
1569 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1570 p=PushQuantumPixel(quantum_info,p,&pixel);
1571 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1572 p=PushQuantumPixel(quantum_info,p,&pixel);
1573 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1574 p=PushQuantumPixel(quantum_info,p,&pixel);
1575 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1576 q+=GetPixelChannels(image);
1583 static void ImportGrayQuantum(const Image *image,QuantumInfo *quantum_info,
1584 const MagickSizeType number_pixels,const unsigned char *restrict p,
1585 Quantum *restrict q,ExceptionInfo *exception)
1599 switch (quantum_info->depth)
1609 if (quantum_info->min_is_white != MagickFalse)
1614 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
1616 for (bit=0; bit < 8; bit++)
1618 SetPixelGray(image,((*p) & (1 << (7-bit))) == 0 ? black : white,q);
1619 q+=GetPixelChannels(image);
1623 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
1625 SetPixelGray(image,((*p) & (0x01 << (7-bit))) == 0 ? black : white,q);
1626 q+=GetPixelChannels(image);
1634 register unsigned char
1637 range=GetQuantumRange(quantum_info->depth);
1638 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
1640 pixel=(unsigned char) ((*p >> 4) & 0xf);
1641 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1642 q+=GetPixelChannels(image);
1643 pixel=(unsigned char) ((*p) & 0xf);
1644 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1646 q+=GetPixelChannels(image);
1648 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1650 pixel=(unsigned char) (*p++ >> 4);
1651 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1652 q+=GetPixelChannels(image);
1661 if (quantum_info->min_is_white != MagickFalse)
1663 for (x=0; x < (ssize_t) number_pixels; x++)
1665 p=PushCharPixel(p,&pixel);
1666 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
1667 SetPixelAlpha(image,OpaqueAlpha,q);
1668 p+=quantum_info->pad;
1669 q+=GetPixelChannels(image);
1673 for (x=0; x < (ssize_t) number_pixels; x++)
1675 p=PushCharPixel(p,&pixel);
1676 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
1677 SetPixelAlpha(image,OpaqueAlpha,q);
1678 p+=quantum_info->pad;
1679 q+=GetPixelChannels(image);
1685 range=GetQuantumRange(quantum_info->depth);
1686 if (quantum_info->pack == MagickFalse)
1688 if (image->endian == LSBEndian)
1690 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1692 p=PushLongPixel(quantum_info->endian,p,&pixel);
1693 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
1695 q+=GetPixelChannels(image);
1696 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
1698 q+=GetPixelChannels(image);
1699 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
1701 p+=quantum_info->pad;
1702 q+=GetPixelChannels(image);
1704 p=PushLongPixel(quantum_info->endian,p,&pixel);
1705 if (x++ < (ssize_t) (number_pixels-1))
1707 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
1709 q+=GetPixelChannels(image);
1711 if (x++ < (ssize_t) number_pixels)
1713 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
1715 q+=GetPixelChannels(image);
1719 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
1721 p=PushLongPixel(quantum_info->endian,p,&pixel);
1722 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),
1724 q+=GetPixelChannels(image);
1725 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
1727 q+=GetPixelChannels(image);
1728 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),
1730 p+=quantum_info->pad;
1731 q+=GetPixelChannels(image);
1733 p=PushLongPixel(quantum_info->endian,p,&pixel);
1734 if (x++ < (ssize_t) (number_pixels-1))
1736 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
1738 q+=GetPixelChannels(image);
1740 if (x++ < (ssize_t) number_pixels)
1742 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
1744 q+=GetPixelChannels(image);
1748 for (x=0; x < (ssize_t) number_pixels; x++)
1750 p=PushQuantumPixel(quantum_info,p,&pixel);
1751 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1752 p+=quantum_info->pad;
1753 q+=GetPixelChannels(image);
1759 range=GetQuantumRange(quantum_info->depth);
1760 if (quantum_info->pack == MagickFalse)
1765 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
1767 p=PushShortPixel(quantum_info->endian,p,&pixel);
1768 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1770 q+=GetPixelChannels(image);
1771 p=PushShortPixel(quantum_info->endian,p,&pixel);
1772 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1774 p+=quantum_info->pad;
1775 q+=GetPixelChannels(image);
1777 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
1779 p=PushShortPixel(quantum_info->endian,p,&pixel);
1780 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
1782 p+=quantum_info->pad;
1783 q+=GetPixelChannels(image);
1789 for (x=0; x < (ssize_t) number_pixels; x++)
1791 p=PushQuantumPixel(quantum_info,p,&pixel);
1792 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1793 p+=quantum_info->pad;
1794 q+=GetPixelChannels(image);
1803 if (quantum_info->min_is_white != MagickFalse)
1805 for (x=0; x < (ssize_t) number_pixels; x++)
1807 p=PushShortPixel(quantum_info->endian,p,&pixel);
1808 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
1809 p+=quantum_info->pad;
1810 q+=GetPixelChannels(image);
1814 if (quantum_info->format == FloatingPointQuantumFormat)
1816 for (x=0; x < (ssize_t) number_pixels; x++)
1818 p=PushShortPixel(quantum_info->endian,p,&pixel);
1819 SetPixelGray(image,ClampToQuantum(QuantumRange*
1820 HalfToSinglePrecision(pixel)),q);
1821 p+=quantum_info->pad;
1822 q+=GetPixelChannels(image);
1826 for (x=0; x < (ssize_t) number_pixels; x++)
1828 p=PushShortPixel(quantum_info->endian,p,&pixel);
1829 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
1830 p+=quantum_info->pad;
1831 q+=GetPixelChannels(image);
1840 if (quantum_info->format == FloatingPointQuantumFormat)
1845 for (x=0; x < (ssize_t) number_pixels; x++)
1847 p=PushFloatPixel(quantum_info,p,&pixel);
1848 SetPixelGray(image,ClampToQuantum(pixel),q);
1849 p+=quantum_info->pad;
1850 q+=GetPixelChannels(image);
1854 for (x=0; x < (ssize_t) number_pixels; x++)
1856 p=PushLongPixel(quantum_info->endian,p,&pixel);
1857 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
1858 p+=quantum_info->pad;
1859 q+=GetPixelChannels(image);
1865 if (quantum_info->format == FloatingPointQuantumFormat)
1870 for (x=0; x < (ssize_t) number_pixels; x++)
1872 p=PushDoublePixel(quantum_info,p,&pixel);
1873 SetPixelGray(image,ClampToQuantum(pixel),q);
1874 p+=quantum_info->pad;
1875 q+=GetPixelChannels(image);
1882 range=GetQuantumRange(quantum_info->depth);
1883 for (x=0; x < (ssize_t) number_pixels; x++)
1885 p=PushQuantumPixel(quantum_info,p,&pixel);
1886 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1887 p+=quantum_info->pad;
1888 q+=GetPixelChannels(image);
1895 static void ImportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
1896 const MagickSizeType number_pixels,const unsigned char *restrict p,
1897 Quantum *restrict q,ExceptionInfo *exception)
1911 switch (quantum_info->depth)
1915 register unsigned char
1918 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
1920 for (bit=0; bit < 8; bit+=2)
1922 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1923 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
1924 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
1925 TransparentAlpha : OpaqueAlpha,q);
1926 q+=GetPixelChannels(image);
1930 if ((number_pixels % 4) != 0)
1931 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
1933 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1934 SetPixelGray(image,(Quantum) (pixel != 0 ? 0 : QuantumRange),q);
1935 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
1936 TransparentAlpha : OpaqueAlpha,q);
1937 q+=GetPixelChannels(image);
1945 register unsigned char
1948 range=GetQuantumRange(quantum_info->depth);
1949 for (x=0; x < (ssize_t) number_pixels; x++)
1951 pixel=(unsigned char) ((*p >> 4) & 0xf);
1952 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1953 pixel=(unsigned char) ((*p) & 0xf);
1954 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1956 q+=GetPixelChannels(image);
1965 for (x=0; x < (ssize_t) number_pixels; x++)
1967 p=PushCharPixel(p,&pixel);
1968 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
1969 p=PushCharPixel(p,&pixel);
1970 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
1971 p+=quantum_info->pad;
1972 q+=GetPixelChannels(image);
1978 range=GetQuantumRange(quantum_info->depth);
1979 for (x=0; x < (ssize_t) number_pixels; x++)
1981 p=PushQuantumPixel(quantum_info,p,&pixel);
1982 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1983 p=PushQuantumPixel(quantum_info,p,&pixel);
1984 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1985 p+=quantum_info->pad;
1986 q+=GetPixelChannels(image);
1992 range=GetQuantumRange(quantum_info->depth);
1993 for (x=0; x < (ssize_t) number_pixels; x++)
1995 p=PushQuantumPixel(quantum_info,p,&pixel);
1996 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
1997 p=PushQuantumPixel(quantum_info,p,&pixel);
1998 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1999 p+=quantum_info->pad;
2000 q+=GetPixelChannels(image);
2009 if (quantum_info->format == FloatingPointQuantumFormat)
2011 for (x=0; x < (ssize_t) number_pixels; x++)
2013 p=PushShortPixel(quantum_info->endian,p,&pixel);
2014 SetPixelGray(image,ClampToQuantum(QuantumRange*
2015 HalfToSinglePrecision(pixel)),q);
2016 p=PushShortPixel(quantum_info->endian,p,&pixel);
2017 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
2018 HalfToSinglePrecision(pixel)),q);
2019 p+=quantum_info->pad;
2020 q+=GetPixelChannels(image);
2024 for (x=0; x < (ssize_t) number_pixels; x++)
2026 p=PushShortPixel(quantum_info->endian,p,&pixel);
2027 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
2028 p=PushShortPixel(quantum_info->endian,p,&pixel);
2029 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
2030 p+=quantum_info->pad;
2031 q+=GetPixelChannels(image);
2040 if (quantum_info->format == FloatingPointQuantumFormat)
2045 for (x=0; x < (ssize_t) number_pixels; x++)
2047 p=PushFloatPixel(quantum_info,p,&pixel);
2048 SetPixelGray(image,ClampToQuantum(pixel),q);
2049 p=PushFloatPixel(quantum_info,p,&pixel);
2050 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2051 p+=quantum_info->pad;
2052 q+=GetPixelChannels(image);
2056 for (x=0; x < (ssize_t) number_pixels; x++)
2058 p=PushLongPixel(quantum_info->endian,p,&pixel);
2059 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
2060 p=PushLongPixel(quantum_info->endian,p,&pixel);
2061 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2062 p+=quantum_info->pad;
2063 q+=GetPixelChannels(image);
2069 if (quantum_info->format == FloatingPointQuantumFormat)
2074 for (x=0; x < (ssize_t) number_pixels; x++)
2076 p=PushDoublePixel(quantum_info,p,&pixel);
2077 SetPixelGray(image,ClampToQuantum(pixel),q);
2078 p=PushDoublePixel(quantum_info,p,&pixel);
2079 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2080 p+=quantum_info->pad;
2081 q+=GetPixelChannels(image);
2088 range=GetQuantumRange(quantum_info->depth);
2089 for (x=0; x < (ssize_t) number_pixels; x++)
2091 p=PushQuantumPixel(quantum_info,p,&pixel);
2092 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2093 p=PushQuantumPixel(quantum_info,p,&pixel);
2094 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2095 p+=quantum_info->pad;
2096 q+=GetPixelChannels(image);
2103 static void ImportGreenQuantum(const Image *image,QuantumInfo *quantum_info,
2104 const MagickSizeType number_pixels,const unsigned char *restrict p,
2105 Quantum *restrict q,ExceptionInfo *exception)
2116 switch (quantum_info->depth)
2123 for (x=0; x < (ssize_t) number_pixels; x++)
2125 p=PushCharPixel(p,&pixel);
2126 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2127 p+=quantum_info->pad;
2128 q+=GetPixelChannels(image);
2137 if (quantum_info->format == FloatingPointQuantumFormat)
2139 for (x=0; x < (ssize_t) number_pixels; x++)
2141 p=PushShortPixel(quantum_info->endian,p,&pixel);
2142 SetPixelGreen(image,ClampToQuantum(QuantumRange*
2143 HalfToSinglePrecision(pixel)),q);
2144 p+=quantum_info->pad;
2145 q+=GetPixelChannels(image);
2149 for (x=0; x < (ssize_t) number_pixels; x++)
2151 p=PushShortPixel(quantum_info->endian,p,&pixel);
2152 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
2153 p+=quantum_info->pad;
2154 q+=GetPixelChannels(image);
2163 if (quantum_info->format == FloatingPointQuantumFormat)
2168 for (x=0; x < (ssize_t) number_pixels; x++)
2170 p=PushFloatPixel(quantum_info,p,&pixel);
2171 SetPixelGreen(image,ClampToQuantum(pixel),q);
2172 p+=quantum_info->pad;
2173 q+=GetPixelChannels(image);
2177 for (x=0; x < (ssize_t) number_pixels; x++)
2179 p=PushLongPixel(quantum_info->endian,p,&pixel);
2180 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
2181 p+=quantum_info->pad;
2182 q+=GetPixelChannels(image);
2188 if (quantum_info->format == FloatingPointQuantumFormat)
2193 for (x=0; x < (ssize_t) number_pixels; x++)
2195 p=PushDoublePixel(quantum_info,p,&pixel);
2196 SetPixelGreen(image,ClampToQuantum(pixel),q);
2197 p+=quantum_info->pad;
2198 q+=GetPixelChannels(image);
2205 range=GetQuantumRange(quantum_info->depth);
2206 for (x=0; x < (ssize_t) number_pixels; x++)
2208 p=PushQuantumPixel(quantum_info,p,&pixel);
2209 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2210 p+=quantum_info->pad;
2211 q+=GetPixelChannels(image);
2218 static void ImportIndexQuantum(const Image *image,QuantumInfo *quantum_info,
2219 const MagickSizeType number_pixels,const unsigned char *restrict p,
2220 Quantum *restrict q,ExceptionInfo *exception)
2234 if (image->storage_class != PseudoClass)
2236 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2237 "ColormappedImageRequired","`%s'",image->filename);
2240 range_exception=MagickFalse;
2241 switch (quantum_info->depth)
2245 register unsigned char
2248 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
2250 for (bit=0; bit < 8; bit++)
2252 if (quantum_info->min_is_white == MagickFalse)
2253 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
2256 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
2258 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),
2260 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2261 GetPixelIndex(image,q),q);
2262 q+=GetPixelChannels(image);
2266 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
2268 if (quantum_info->min_is_white == MagickFalse)
2269 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2271 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2272 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2273 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2274 GetPixelIndex(image,q),q);
2275 q+=GetPixelChannels(image);
2281 register unsigned char
2284 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
2286 pixel=(unsigned char) ((*p >> 4) & 0xf);
2287 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2288 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2289 GetPixelIndex(image,q),q);
2290 q+=GetPixelChannels(image);
2291 pixel=(unsigned char) ((*p) & 0xf);
2292 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2293 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2294 GetPixelIndex(image,q),q);
2296 q+=GetPixelChannels(image);
2298 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
2300 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
2301 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2302 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2303 GetPixelIndex(image,q),q);
2304 q+=GetPixelChannels(image);
2313 for (x=0; x < (ssize_t) number_pixels; x++)
2315 p=PushCharPixel(p,&pixel);
2316 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2317 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2318 GetPixelIndex(image,q),q);
2319 p+=quantum_info->pad;
2320 q+=GetPixelChannels(image);
2329 if (quantum_info->format == FloatingPointQuantumFormat)
2331 for (x=0; x < (ssize_t) number_pixels; x++)
2333 p=PushShortPixel(quantum_info->endian,p,&pixel);
2334 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(
2335 (double) QuantumRange*HalfToSinglePrecision(pixel)),
2336 &range_exception),q);
2337 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2338 GetPixelIndex(image,q),q);
2339 p+=quantum_info->pad;
2340 q+=GetPixelChannels(image);
2344 for (x=0; x < (ssize_t) number_pixels; x++)
2346 p=PushShortPixel(quantum_info->endian,p,&pixel);
2347 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2348 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2349 GetPixelIndex(image,q),q);
2350 p+=quantum_info->pad;
2351 q+=GetPixelChannels(image);
2360 if (quantum_info->format == FloatingPointQuantumFormat)
2365 for (x=0; x < (ssize_t) number_pixels; x++)
2367 p=PushFloatPixel(quantum_info,p,&pixel);
2368 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2369 &range_exception),q);
2370 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2371 GetPixelIndex(image,q),q);
2372 p+=quantum_info->pad;
2373 q+=GetPixelChannels(image);
2377 for (x=0; x < (ssize_t) number_pixels; x++)
2379 p=PushLongPixel(quantum_info->endian,p,&pixel);
2380 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2381 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2382 GetPixelIndex(image,q),q);
2383 p+=quantum_info->pad;
2384 q+=GetPixelChannels(image);
2390 if (quantum_info->format == FloatingPointQuantumFormat)
2395 for (x=0; x < (ssize_t) number_pixels; x++)
2397 p=PushDoublePixel(quantum_info,p,&pixel);
2398 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2399 &range_exception),q);
2400 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2401 GetPixelIndex(image,q),q);
2402 p+=quantum_info->pad;
2403 q+=GetPixelChannels(image);
2410 for (x=0; x < (ssize_t) number_pixels; x++)
2412 p=PushQuantumPixel(quantum_info,p,&pixel);
2413 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2414 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2415 GetPixelIndex(image,q),q);
2416 p+=quantum_info->pad;
2417 q+=GetPixelChannels(image);
2422 if (range_exception != MagickFalse)
2423 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
2424 "InvalidColormapIndex","`%s'",image->filename);
2427 static void ImportIndexAlphaQuantum(const Image *image,
2428 QuantumInfo *quantum_info,const MagickSizeType number_pixels,
2429 const unsigned char *restrict p,Quantum *restrict q,ExceptionInfo *exception)
2446 if (image->storage_class != PseudoClass)
2448 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2449 "ColormappedImageRequired","`%s'",image->filename);
2452 range_exception=MagickFalse;
2453 switch (quantum_info->depth)
2457 register unsigned char
2460 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2462 for (bit=0; bit < 8; bit+=2)
2464 if (quantum_info->min_is_white == MagickFalse)
2465 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2467 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2468 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
2469 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2470 TransparentAlpha : OpaqueAlpha,q);
2471 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
2472 q+=GetPixelChannels(image);
2475 if ((number_pixels % 4) != 0)
2476 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
2478 if (quantum_info->min_is_white == MagickFalse)
2479 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
2481 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2482 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
2483 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
2484 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2485 TransparentAlpha : OpaqueAlpha,q);
2486 q+=GetPixelChannels(image);
2492 register unsigned char
2495 range=GetQuantumRange(quantum_info->depth);
2496 for (x=0; x < (ssize_t) number_pixels; x++)
2498 pixel=(unsigned char) ((*p >> 4) & 0xf);
2499 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2500 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2501 GetPixelIndex(image,q),q);
2502 pixel=(unsigned char) ((*p) & 0xf);
2503 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2505 q+=GetPixelChannels(image);
2514 for (x=0; x < (ssize_t) number_pixels; x++)
2516 p=PushCharPixel(p,&pixel);
2517 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2518 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2519 GetPixelIndex(image,q),q);
2520 p=PushCharPixel(p,&pixel);
2521 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
2522 p+=quantum_info->pad;
2523 q+=GetPixelChannels(image);
2532 if (quantum_info->format == FloatingPointQuantumFormat)
2534 for (x=0; x < (ssize_t) number_pixels; x++)
2536 p=PushShortPixel(quantum_info->endian,p,&pixel);
2537 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(
2538 (double) QuantumRange*HalfToSinglePrecision(pixel)),
2539 &range_exception),q);
2540 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2541 GetPixelIndex(image,q),q);
2542 p=PushShortPixel(quantum_info->endian,p,&pixel);
2543 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
2544 HalfToSinglePrecision(pixel)),q);
2545 p+=quantum_info->pad;
2546 q+=GetPixelChannels(image);
2550 for (x=0; x < (ssize_t) number_pixels; x++)
2552 p=PushShortPixel(quantum_info->endian,p,&pixel);
2553 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2554 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2555 GetPixelIndex(image,q),q);
2556 p=PushShortPixel(quantum_info->endian,p,&pixel);
2557 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
2558 p+=quantum_info->pad;
2559 q+=GetPixelChannels(image);
2568 if (quantum_info->format == FloatingPointQuantumFormat)
2573 for (x=0; x < (ssize_t) number_pixels; x++)
2575 p=PushFloatPixel(quantum_info,p,&pixel);
2576 SetPixelIndex(image,PushColormapIndex(image,
2577 ClampToQuantum(pixel),&range_exception),q);
2578 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2579 GetPixelIndex(image,q),q);
2580 p=PushFloatPixel(quantum_info,p,&pixel);
2581 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2582 p+=quantum_info->pad;
2583 q+=GetPixelChannels(image);
2587 for (x=0; x < (ssize_t) number_pixels; x++)
2589 p=PushLongPixel(quantum_info->endian,p,&pixel);
2590 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2591 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2592 GetPixelIndex(image,q),q);
2593 p=PushLongPixel(quantum_info->endian,p,&pixel);
2594 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2595 p+=quantum_info->pad;
2596 q+=GetPixelChannels(image);
2602 if (quantum_info->format == FloatingPointQuantumFormat)
2607 for (x=0; x < (ssize_t) number_pixels; x++)
2609 p=PushDoublePixel(quantum_info,p,&pixel);
2610 SetPixelIndex(image,PushColormapIndex(image,ClampToQuantum(pixel),
2611 &range_exception),q);
2612 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2613 GetPixelIndex(image,q),q);
2614 p=PushDoublePixel(quantum_info,p,&pixel);
2615 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2616 p+=quantum_info->pad;
2617 q+=GetPixelChannels(image);
2624 range=GetQuantumRange(quantum_info->depth);
2625 for (x=0; x < (ssize_t) number_pixels; x++)
2627 p=PushQuantumPixel(quantum_info,p,&pixel);
2628 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
2629 SetPixelInfoPixel(image,image->colormap+(ssize_t)
2630 GetPixelIndex(image,q),q);
2631 p=PushQuantumPixel(quantum_info,p,&pixel);
2632 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2633 p+=quantum_info->pad;
2634 q+=GetPixelChannels(image);
2639 if (range_exception != MagickFalse)
2640 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
2641 "InvalidColormapIndex","`%s'",image->filename);
2644 static void ImportOpacityQuantum(const Image *image,QuantumInfo *quantum_info,
2645 const MagickSizeType number_pixels,const unsigned char *restrict p,
2646 Quantum *restrict q,ExceptionInfo *exception)
2657 switch (quantum_info->depth)
2664 for (x=0; x < (ssize_t) number_pixels; x++)
2666 p=PushCharPixel(p,&pixel);
2667 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
2668 p+=quantum_info->pad;
2669 q+=GetPixelChannels(image);
2678 if (quantum_info->format == FloatingPointQuantumFormat)
2680 for (x=0; x < (ssize_t) number_pixels; x++)
2682 p=PushShortPixel(quantum_info->endian,p,&pixel);
2683 SetPixelOpacity(image,ClampToQuantum(QuantumRange*
2684 HalfToSinglePrecision(pixel)),q);
2685 p+=quantum_info->pad;
2686 q+=GetPixelChannels(image);
2690 for (x=0; x < (ssize_t) number_pixels; x++)
2692 p=PushShortPixel(quantum_info->endian,p,&pixel);
2693 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
2694 p+=quantum_info->pad;
2695 q+=GetPixelChannels(image);
2704 if (quantum_info->format == FloatingPointQuantumFormat)
2709 for (x=0; x < (ssize_t) number_pixels; x++)
2711 p=PushFloatPixel(quantum_info,p,&pixel);
2712 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2713 p+=quantum_info->pad;
2714 q+=GetPixelChannels(image);
2718 for (x=0; x < (ssize_t) number_pixels; x++)
2720 p=PushLongPixel(quantum_info->endian,p,&pixel);
2721 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
2722 p+=quantum_info->pad;
2723 q+=GetPixelChannels(image);
2729 if (quantum_info->format == FloatingPointQuantumFormat)
2734 for (x=0; x < (ssize_t) number_pixels; x++)
2736 p=PushDoublePixel(quantum_info,p,&pixel);
2737 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2738 p+=quantum_info->pad;
2739 q+=GetPixelChannels(image);
2746 range=GetQuantumRange(quantum_info->depth);
2747 for (x=0; x < (ssize_t) number_pixels; x++)
2749 p=PushQuantumPixel(quantum_info,p,&pixel);
2750 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
2751 p+=quantum_info->pad;
2752 q+=GetPixelChannels(image);
2758 static void ImportRedQuantum(const Image *image,QuantumInfo *quantum_info,
2759 const MagickSizeType number_pixels,const unsigned char *restrict p,
2760 Quantum *restrict q,ExceptionInfo *exception)
2771 switch (quantum_info->depth)
2778 for (x=0; x < (ssize_t) number_pixels; x++)
2780 p=PushCharPixel(p,&pixel);
2781 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
2782 p+=quantum_info->pad;
2783 q+=GetPixelChannels(image);
2792 if (quantum_info->format == FloatingPointQuantumFormat)
2794 for (x=0; x < (ssize_t) number_pixels; x++)
2796 p=PushShortPixel(quantum_info->endian,p,&pixel);
2797 SetPixelRed(image,ClampToQuantum(QuantumRange*
2798 HalfToSinglePrecision(pixel)),q);
2799 p+=quantum_info->pad;
2800 q+=GetPixelChannels(image);
2804 for (x=0; x < (ssize_t) number_pixels; x++)
2806 p=PushShortPixel(quantum_info->endian,p,&pixel);
2807 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
2808 p+=quantum_info->pad;
2809 q+=GetPixelChannels(image);
2818 if (quantum_info->format == FloatingPointQuantumFormat)
2823 for (x=0; x < (ssize_t) number_pixels; x++)
2825 p=PushFloatPixel(quantum_info,p,&pixel);
2826 SetPixelRed(image,ClampToQuantum(pixel),q);
2827 p+=quantum_info->pad;
2828 q+=GetPixelChannels(image);
2832 for (x=0; x < (ssize_t) number_pixels; x++)
2834 p=PushLongPixel(quantum_info->endian,p,&pixel);
2835 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
2836 p+=quantum_info->pad;
2837 q+=GetPixelChannels(image);
2843 if (quantum_info->format == FloatingPointQuantumFormat)
2848 for (x=0; x < (ssize_t) number_pixels; x++)
2850 p=PushDoublePixel(quantum_info,p,&pixel);
2851 SetPixelRed(image,ClampToQuantum(pixel),q);
2852 p+=quantum_info->pad;
2853 q+=GetPixelChannels(image);
2860 range=GetQuantumRange(quantum_info->depth);
2861 for (x=0; x < (ssize_t) number_pixels; x++)
2863 p=PushQuantumPixel(quantum_info,p,&pixel);
2864 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2865 p+=quantum_info->pad;
2866 q+=GetPixelChannels(image);
2873 static void ImportRGBQuantum(const Image *image,QuantumInfo *quantum_info,
2874 const MagickSizeType number_pixels,const unsigned char *restrict p,
2875 Quantum *restrict q,ExceptionInfo *exception)
2889 switch (quantum_info->depth)
2896 for (x=0; x < (ssize_t) number_pixels; x++)
2898 p=PushCharPixel(p,&pixel);
2899 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
2900 p=PushCharPixel(p,&pixel);
2901 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2902 p=PushCharPixel(p,&pixel);
2903 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
2904 SetPixelAlpha(image,OpaqueAlpha,q);
2905 p+=quantum_info->pad;
2906 q+=GetPixelChannels(image);
2912 range=GetQuantumRange(quantum_info->depth);
2913 if (quantum_info->pack == MagickFalse)
2915 for (x=0; x < (ssize_t) number_pixels; x++)
2917 p=PushLongPixel(quantum_info->endian,p,&pixel);
2918 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
2919 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
2921 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
2922 p+=quantum_info->pad;
2923 q+=GetPixelChannels(image);
2927 if (quantum_info->quantum == 32U)
2929 for (x=0; x < (ssize_t) number_pixels; x++)
2931 p=PushQuantumLongPixel(quantum_info,p,&pixel);
2932 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2933 p=PushQuantumLongPixel(quantum_info,p,&pixel);
2934 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2935 p=PushQuantumLongPixel(quantum_info,p,&pixel);
2936 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
2937 q+=GetPixelChannels(image);
2941 for (x=0; x < (ssize_t) number_pixels; x++)
2943 p=PushQuantumPixel(quantum_info,p,&pixel);
2944 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2945 p=PushQuantumPixel(quantum_info,p,&pixel);
2946 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2947 p=PushQuantumPixel(quantum_info,p,&pixel);
2948 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
2949 q+=GetPixelChannels(image);
2955 range=GetQuantumRange(quantum_info->depth);
2956 if (quantum_info->pack == MagickFalse)
2961 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
2963 p=PushShortPixel(quantum_info->endian,p,&pixel);
2969 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2975 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2981 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2983 q+=GetPixelChannels(image);
2987 p=PushShortPixel(quantum_info->endian,p,&pixel);
2993 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2999 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3005 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3007 q+=GetPixelChannels(image);
3011 p+=quantum_info->pad;
3013 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
3015 p=PushShortPixel(quantum_info->endian,p,&pixel);
3016 switch ((x+bit) % 3)
3021 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3027 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3033 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3035 q+=GetPixelChannels(image);
3039 p+=quantum_info->pad;
3045 if (quantum_info->quantum == 32U)
3047 for (x=0; x < (ssize_t) number_pixels; x++)
3049 p=PushQuantumLongPixel(quantum_info,p,&pixel);
3050 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3051 p=PushQuantumLongPixel(quantum_info,p,&pixel);
3052 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3053 p=PushQuantumLongPixel(quantum_info,p,&pixel);
3054 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3055 q+=GetPixelChannels(image);
3059 for (x=0; x < (ssize_t) number_pixels; x++)
3061 p=PushQuantumPixel(quantum_info,p,&pixel);
3062 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3063 p=PushQuantumPixel(quantum_info,p,&pixel);
3064 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3065 p=PushQuantumPixel(quantum_info,p,&pixel);
3066 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3067 q+=GetPixelChannels(image);
3076 if (quantum_info->format == FloatingPointQuantumFormat)
3078 for (x=0; x < (ssize_t) number_pixels; x++)
3080 p=PushShortPixel(quantum_info->endian,p,&pixel);
3081 SetPixelRed(image,ClampToQuantum(QuantumRange*
3082 HalfToSinglePrecision(pixel)),q);
3083 p=PushShortPixel(quantum_info->endian,p,&pixel);
3084 SetPixelGreen(image,ClampToQuantum(QuantumRange*
3085 HalfToSinglePrecision(pixel)),q);
3086 p=PushShortPixel(quantum_info->endian,p,&pixel);
3087 SetPixelBlue(image,ClampToQuantum(QuantumRange*
3088 HalfToSinglePrecision(pixel)),q);
3089 p+=quantum_info->pad;
3090 q+=GetPixelChannels(image);
3094 for (x=0; x < (ssize_t) number_pixels; x++)
3096 p=PushShortPixel(quantum_info->endian,p,&pixel);
3097 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3098 p=PushShortPixel(quantum_info->endian,p,&pixel);
3099 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
3100 p=PushShortPixel(quantum_info->endian,p,&pixel);
3101 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
3102 p+=quantum_info->pad;
3103 q+=GetPixelChannels(image);
3112 if (quantum_info->format == FloatingPointQuantumFormat)
3117 for (x=0; x < (ssize_t) number_pixels; x++)
3119 p=PushFloatPixel(quantum_info,p,&pixel);
3120 SetPixelRed(image,ClampToQuantum(pixel),q);
3121 p=PushFloatPixel(quantum_info,p,&pixel);
3122 SetPixelGreen(image,ClampToQuantum(pixel),q);
3123 p=PushFloatPixel(quantum_info,p,&pixel);
3124 SetPixelBlue(image,ClampToQuantum(pixel),q);
3125 p+=quantum_info->pad;
3126 q+=GetPixelChannels(image);
3130 for (x=0; x < (ssize_t) number_pixels; x++)
3132 p=PushLongPixel(quantum_info->endian,p,&pixel);
3133 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3134 p=PushLongPixel(quantum_info->endian,p,&pixel);
3135 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
3136 p=PushLongPixel(quantum_info->endian,p,&pixel);
3137 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
3138 p+=quantum_info->pad;
3139 q+=GetPixelChannels(image);
3145 if (quantum_info->format == FloatingPointQuantumFormat)
3150 for (x=0; x < (ssize_t) number_pixels; x++)
3152 p=PushDoublePixel(quantum_info,p,&pixel);
3153 SetPixelRed(image,ClampToQuantum(pixel),q);
3154 p=PushDoublePixel(quantum_info,p,&pixel);
3155 SetPixelGreen(image,ClampToQuantum(pixel),q);
3156 p=PushDoublePixel(quantum_info,p,&pixel);
3157 SetPixelBlue(image,ClampToQuantum(pixel),q);
3158 p+=quantum_info->pad;
3159 q+=GetPixelChannels(image);
3166 range=GetQuantumRange(quantum_info->depth);
3167 for (x=0; x < (ssize_t) number_pixels; x++)
3169 p=PushQuantumPixel(quantum_info,p,&pixel);
3170 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3171 p=PushQuantumPixel(quantum_info,p,&pixel);
3172 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3173 p=PushQuantumPixel(quantum_info,p,&pixel);
3174 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3175 q+=GetPixelChannels(image);
3182 static void ImportRGBAQuantum(const Image *image,QuantumInfo *quantum_info,
3183 const MagickSizeType number_pixels,const unsigned char *restrict p,
3184 Quantum *restrict q,ExceptionInfo *exception)
3195 switch (quantum_info->depth)
3202 for (x=0; x < (ssize_t) number_pixels; x++)
3204 p=PushCharPixel(p,&pixel);
3205 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3206 p=PushCharPixel(p,&pixel);
3207 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
3208 p=PushCharPixel(p,&pixel);
3209 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
3210 p=PushCharPixel(p,&pixel);
3211 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
3212 p+=quantum_info->pad;
3213 q+=GetPixelChannels(image);
3220 if (quantum_info->pack == MagickFalse)
3233 for (x=0; x < (ssize_t) number_pixels; x++)
3235 for (i=0; i < 4; i++)
3241 p=PushLongPixel(quantum_info->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)));
3261 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
3262 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
3263 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
3264 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
3268 p+=quantum_info->pad;
3269 q+=GetPixelChannels(image);
3273 for (x=0; x < (ssize_t) number_pixels; x++)
3275 p=PushQuantumPixel(quantum_info,p,&pixel);
3276 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
3277 p=PushQuantumPixel(quantum_info,p,&pixel);
3278 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3280 p=PushQuantumPixel(quantum_info,p,&pixel);
3281 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3283 p=PushQuantumPixel(quantum_info,p,&pixel);
3284 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
3286 q+=GetPixelChannels(image);
3295 if (quantum_info->format == FloatingPointQuantumFormat)
3297 for (x=0; x < (ssize_t) number_pixels; x++)
3299 p=PushShortPixel(quantum_info->endian,p,&pixel);
3300 SetPixelRed(image,ClampToQuantum(QuantumRange*
3301 HalfToSinglePrecision(pixel)),q);
3302 p=PushShortPixel(quantum_info->endian,p,&pixel);
3303 SetPixelGreen(image,ClampToQuantum(QuantumRange*
3304 HalfToSinglePrecision(pixel)),q);
3305 p=PushShortPixel(quantum_info->endian,p,&pixel);
3306 SetPixelBlue(image,ClampToQuantum(QuantumRange*
3307 HalfToSinglePrecision(pixel)),q);
3308 p=PushShortPixel(quantum_info->endian,p,&pixel);
3309 SetPixelAlpha(image,ClampToQuantum(QuantumRange*
3310 HalfToSinglePrecision(pixel)),q);
3311 p+=quantum_info->pad;
3312 q+=GetPixelChannels(image);
3316 for (x=0; x < (ssize_t) number_pixels; x++)
3318 p=PushShortPixel(quantum_info->endian,p,&pixel);
3319 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3320 p=PushShortPixel(quantum_info->endian,p,&pixel);
3321 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
3322 p=PushShortPixel(quantum_info->endian,p,&pixel);
3323 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
3324 p=PushShortPixel(quantum_info->endian,p,&pixel);
3325 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
3326 p+=quantum_info->pad;
3327 q+=GetPixelChannels(image);
3336 if (quantum_info->format == FloatingPointQuantumFormat)
3341 for (x=0; x < (ssize_t) number_pixels; x++)
3343 p=PushFloatPixel(quantum_info,p,&pixel);
3344 SetPixelRed(image,ClampToQuantum(pixel),q);
3345 p=PushFloatPixel(quantum_info,p,&pixel);
3346 SetPixelGreen(image,ClampToQuantum(pixel),q);
3347 p=PushFloatPixel(quantum_info,p,&pixel);
3348 SetPixelBlue(image,ClampToQuantum(pixel),q);
3349 p=PushFloatPixel(quantum_info,p,&pixel);
3350 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3351 p+=quantum_info->pad;
3352 q+=GetPixelChannels(image);
3356 for (x=0; x < (ssize_t) number_pixels; x++)
3358 p=PushLongPixel(quantum_info->endian,p,&pixel);
3359 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3360 p=PushLongPixel(quantum_info->endian,p,&pixel);
3361 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
3362 p=PushLongPixel(quantum_info->endian,p,&pixel);
3363 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
3364 p=PushLongPixel(quantum_info->endian,p,&pixel);
3365 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
3366 p+=quantum_info->pad;
3367 q+=GetPixelChannels(image);
3373 if (quantum_info->format == FloatingPointQuantumFormat)
3378 for (x=0; x < (ssize_t) number_pixels; x++)
3380 p=PushDoublePixel(quantum_info,p,&pixel);
3381 SetPixelRed(image,ClampToQuantum(pixel),q);
3382 p=PushDoublePixel(quantum_info,p,&pixel);
3383 SetPixelGreen(image,ClampToQuantum(pixel),q);
3384 p=PushDoublePixel(quantum_info,p,&pixel);
3385 SetPixelBlue(image,ClampToQuantum(pixel),q);
3386 p=PushDoublePixel(quantum_info,p,&pixel);
3387 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3388 p+=quantum_info->pad;
3389 q+=GetPixelChannels(image);
3396 range=GetQuantumRange(quantum_info->depth);
3397 for (x=0; x < (ssize_t) number_pixels; x++)
3399 p=PushQuantumPixel(quantum_info,p,&pixel);
3400 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3401 p=PushQuantumPixel(quantum_info,p,&pixel);
3402 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3403 p=PushQuantumPixel(quantum_info,p,&pixel);
3404 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3405 p=PushQuantumPixel(quantum_info,p,&pixel);
3406 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
3407 q+=GetPixelChannels(image);
3414 MagickExport size_t ImportQuantumPixels(const Image *image,
3415 CacheView *image_view,QuantumInfo *quantum_info,
3416 const QuantumType quantum_type,const unsigned char *pixels,
3417 ExceptionInfo *exception)
3422 register const unsigned char
3434 assert(image != (Image *) NULL);
3435 assert(image->signature == MagickSignature);
3436 if (image->debug != MagickFalse)
3437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3438 assert(quantum_info != (QuantumInfo *) NULL);
3439 assert(quantum_info->signature == MagickSignature);
3440 if (pixels == (const unsigned char *) NULL)
3441 pixels=GetQuantumPixels(quantum_info);
3444 if (image_view == (CacheView *) NULL)
3446 number_pixels=GetImageExtent(image);
3447 q=GetAuthenticPixelQueue(image);
3451 number_pixels=GetCacheViewExtent(image_view);
3452 q=GetCacheViewAuthenticPixelQueue(image_view);
3454 ResetQuantumState(quantum_info);
3455 extent=GetQuantumExtent(image,quantum_info,quantum_type);
3456 switch (quantum_type)
3460 ImportAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
3465 ImportBGRQuantum(image,quantum_info,number_pixels,p,q,exception);
3471 ImportBGRAQuantum(image,quantum_info,number_pixels,p,q,exception);
3476 ImportBlackQuantum(image,quantum_info,number_pixels,p,q,exception);
3482 ImportBlueQuantum(image,quantum_info,number_pixels,p,q,exception);
3487 ImportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception);
3493 ImportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception);
3498 ImportCbYCrYQuantum(image,quantum_info,number_pixels,p,q,exception);
3503 ImportGrayQuantum(image,quantum_info,number_pixels,p,q,exception);
3506 case GrayAlphaQuantum:
3508 ImportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
3512 case MagentaQuantum:
3514 ImportGreenQuantum(image,quantum_info,number_pixels,p,q,exception);
3519 ImportIndexQuantum(image,quantum_info,number_pixels,p,q,exception);
3522 case IndexAlphaQuantum:
3524 ImportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
3527 case OpacityQuantum:
3529 ImportOpacityQuantum(image,quantum_info,number_pixels,p,q,exception);
3535 ImportRedQuantum(image,quantum_info,number_pixels,p,q,exception);
3541 ImportRGBQuantum(image,quantum_info,number_pixels,p,q,exception);
3548 ImportRGBAQuantum(image,quantum_info,number_pixels,p,q,exception);
3554 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3562 q=GetAuthenticPixelQueue(image);
3563 if (image_view != (CacheView *) NULL)
3564 q=GetCacheViewAuthenticPixelQueue(image_view);
3565 for (x=0; x < (ssize_t) number_pixels; x++)
3567 quantum=GetPixelRed(image,q);
3568 SetPixelRed(image,GetPixelGreen(image,q),q);
3569 SetPixelGreen(image,quantum,q);
3570 q+=GetPixelChannels(image);
3573 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
3578 q=GetAuthenticPixelQueue(image);
3579 if (image_view != (CacheView *) NULL)
3580 q=GetCacheViewAuthenticPixelQueue(image_view);
3581 for (x=0; x < (ssize_t) number_pixels; x++)
3583 SetPixelAlpha(image,GetPixelAlpha(image,q),q);
3584 q+=GetPixelChannels(image);
3587 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
3599 q=GetAuthenticPixelQueue(image);
3600 if (image_view != (CacheView *) NULL)
3601 q=GetCacheViewAuthenticPixelQueue(image_view);
3602 for (x=0; x < (ssize_t) number_pixels; x++)
3607 if (GetPixelMask(image,q) != 0)
3609 q+=GetPixelChannels(image);
3612 Sa=QuantumScale*GetPixelAlpha(image,q);
3613 gamma=PerceptibleReciprocal(Sa);
3614 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3616 PixelChannel channel=GetPixelChannelChannel(image,i);
3617 PixelTrait traits=GetPixelChannelTraits(image,channel);
3618 if ((traits & UpdatePixelTrait) == 0)
3620 q[i]=ClampToQuantum(gamma*q[i]);
3622 q+=GetPixelChannels(image);