MagickCore 7.1.1
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
quantum-import.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
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 %
11% %
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 %
15% I M M P O O R R T %
16% IIIII M M P OOO R R T %
17% %
18% MagickCore Methods to Import Quantum Pixels %
19% %
20% Software Design %
21% Cristy %
22% October 1998 %
23% %
24% %
25% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
26% dedicated to making software imaging solutions freely available. %
27% %
28% You may not use this file except in compliance with the License. You may %
29% obtain a copy of the License at %
30% %
31% https://imagemagick.org/script/license.php %
32% %
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. %
38% %
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40%
41%
42*/
43
44/*
45 Include declarations.
46*/
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"
73
74/*
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76% %
77% %
78% %
79% I m p o r t Q u a n t u m P i x e l s %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
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 the number of imported pixels.
88%
89% The format of the ImportQuantumPixels method is:
90%
91% size_t ImportQuantumPixels(const Image *image,CacheView *image_view,
92% QuantumInfo *quantum_info,const QuantumType quantum_type,
93% const unsigned char *magick_restrict pixels,ExceptionInfo *exception)
94%
95% A description of each parameter follows:
96%
97% o image: the image.
98%
99% o image_view: the image cache view.
100%
101% o quantum_info: the quantum info.
102%
103% o quantum_type: Declare which pixel components to transfer (red, green,
104% blue, opacity, RGB, or RGBA).
105%
106% o pixels: The pixel components are transferred from this buffer.
107%
108% o exception: return any errors or warnings in this structure.
109%
110*/
111
112static inline Quantum PushColormapIndex(const Image *image,const size_t index,
113 MagickBooleanType *range_exception)
114{
115 if (index < image->colors)
116 return((Quantum) index);
117 *range_exception=MagickTrue;
118 return((Quantum) 0);
119}
120
121static inline const unsigned char *PushDoublePixel(QuantumInfo *quantum_info,
122 const unsigned char *magick_restrict pixels,double *pixel)
123{
124 double
125 *p;
126
127 unsigned char
128 quantum[8];
129
130 if (quantum_info->endian == LSBEndian)
131 {
132 quantum[0]=(*pixels++);
133 quantum[1]=(*pixels++);
134 quantum[2]=(*pixels++);
135 quantum[3]=(*pixels++);
136 quantum[4]=(*pixels++);
137 quantum[5]=(*pixels++);
138 quantum[6]=(*pixels++);
139 quantum[7]=(*pixels++);
140 }
141 else
142 {
143 quantum[7]=(*pixels++);
144 quantum[6]=(*pixels++);
145 quantum[5]=(*pixels++);
146 quantum[4]=(*pixels++);
147 quantum[3]=(*pixels++);
148 quantum[2]=(*pixels++);
149 quantum[1]=(*pixels++);
150 quantum[0]=(*pixels++);
151 }
152 p=(double *) quantum;
153 *pixel=(*p);
154 *pixel-=quantum_info->minimum;
155 *pixel*=quantum_info->scale;
156 return(pixels);
157}
158
159static inline float ScaleFloatPixel(const QuantumInfo *quantum_info,
160 const unsigned char *quantum)
161{
162 double
163 pixel;
164
165 pixel=(double) (*((float *) quantum));
166 pixel-=quantum_info->minimum;
167 pixel*=quantum_info->scale;
168 if (pixel < (double) -FLT_MAX)
169 return(-FLT_MAX);
170 if (pixel > (double) FLT_MAX)
171 return(FLT_MAX);
172 return(pixel);
173}
174
175static inline const unsigned char *PushQuantumFloatPixel(
176 const QuantumInfo *quantum_info,const unsigned char *magick_restrict pixels,
177 float *pixel)
178{
179 unsigned char
180 quantum[4];
181
182 if (quantum_info->endian == LSBEndian)
183 {
184 quantum[0]=(*pixels++);
185 quantum[1]=(*pixels++);
186 quantum[2]=(*pixels++);
187 quantum[3]=(*pixels++);
188 }
189 else
190 {
191 quantum[3]=(*pixels++);
192 quantum[2]=(*pixels++);
193 quantum[1]=(*pixels++);
194 quantum[0]=(*pixels++);
195 }
196 *pixel=ScaleFloatPixel(quantum_info,quantum);
197 return(pixels);
198}
199
200static inline const unsigned char *PushQuantumFloat24Pixel(
201 const QuantumInfo *quantum_info,const unsigned char *magick_restrict pixels,
202 float *pixel)
203{
204 unsigned char
205 quantum[4];
206
207 if (quantum_info->endian == LSBEndian)
208 {
209 quantum[0]=(*pixels++);
210 quantum[1]=(*pixels++);
211 quantum[2]=(*pixels++);
212 }
213 else
214 {
215 quantum[2]=(*pixels++);
216 quantum[1]=(*pixels++);
217 quantum[0]=(*pixels++);
218 }
219 if ((quantum[0] | quantum[1] | quantum[2]) == 0U)
220 quantum[3]=0;
221 else
222 {
223 unsigned char
224 exponent,
225 sign_bit;
226
227 sign_bit=(quantum[2] & 0x80);
228 exponent=(quantum[2] & 0x7F);
229 if (exponent != 0)
230 exponent=exponent-63+127;
231 quantum[3]=sign_bit | (exponent >> 1);
232 quantum[2]=((exponent & 1) << 7) | ((quantum[1] & 0xFE) >> 1);
233 quantum[1]=((quantum[1] & 0x01) << 7) | ((quantum[0] & 0xFE) >> 1);
234 quantum[0]=(quantum[0] & 0x01) << 7;
235 }
236 *pixel=ScaleFloatPixel(quantum_info,quantum);
237 return(pixels);
238}
239
240static inline const unsigned char *PushQuantumPixel(QuantumInfo *quantum_info,
241 const unsigned char *magick_restrict pixels,unsigned int *quantum)
242{
243 ssize_t
244 i;
245
246 size_t
247 quantum_bits;
248
249 *quantum=(QuantumAny) 0;
250 for (i=(ssize_t) quantum_info->depth; i > 0L; )
251 {
252 if (quantum_info->state.bits == 0UL)
253 {
254 quantum_info->state.pixel=(*pixels++);
255 quantum_info->state.bits=8UL;
256 }
257 quantum_bits=(size_t) i;
258 if (quantum_bits > quantum_info->state.bits)
259 quantum_bits=quantum_info->state.bits;
260 i-=(ssize_t) quantum_bits;
261 quantum_info->state.bits-=quantum_bits;
262 if (quantum_bits < 64)
263 *quantum=(unsigned int) (((MagickSizeType) *quantum << quantum_bits) |
264 ((quantum_info->state.pixel >> quantum_info->state.bits) &~
265 ((~0UL) << quantum_bits)));
266 }
267 return(pixels);
268}
269
270static inline const unsigned char *PushQuantumLongPixel(
271 QuantumInfo *quantum_info,const unsigned char *magick_restrict pixels,
272 unsigned int *quantum)
273{
274 ssize_t
275 i;
276
277 size_t
278 quantum_bits;
279
280 *quantum=0UL;
281 for (i=(ssize_t) quantum_info->depth; i > 0; )
282 {
283 if (quantum_info->state.bits == 0)
284 {
285 pixels=PushLongPixel(quantum_info->endian,pixels,
286 &quantum_info->state.pixel);
287 quantum_info->state.bits=32U;
288 }
289 quantum_bits=(size_t) i;
290 if (quantum_bits > quantum_info->state.bits)
291 quantum_bits=quantum_info->state.bits;
292 *quantum|=(((quantum_info->state.pixel >> (32U-quantum_info->state.bits)) &
293 quantum_info->state.mask[quantum_bits]) << ((ssize_t)
294 quantum_info->depth-i));
295 i-=(ssize_t) quantum_bits;
296 quantum_info->state.bits-=quantum_bits;
297 }
298 return(pixels);
299}
300
301static void ImportAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
302 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
303 Quantum *magick_restrict q)
304{
305 QuantumAny
306 range;
307
308 ssize_t
309 x;
310
311 assert(image != (Image *) NULL);
312 assert(image->signature == MagickCoreSignature);
313 switch (quantum_info->depth)
314 {
315 case 8:
316 {
317 unsigned char
318 pixel;
319
320 for (x=0; x < (ssize_t) number_pixels; x++)
321 {
322 p=PushCharPixel(p,&pixel);
323 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
324 p+=quantum_info->pad;
325 q+=GetPixelChannels(image);
326 }
327 break;
328 }
329 case 16:
330 {
331 unsigned short
332 pixel;
333
334 if (quantum_info->format == FloatingPointQuantumFormat)
335 {
336 for (x=0; x < (ssize_t) number_pixels; x++)
337 {
338 p=PushShortPixel(quantum_info->endian,p,&pixel);
339 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
340 HalfToSinglePrecision(pixel)),q);
341 p+=quantum_info->pad;
342 q+=GetPixelChannels(image);
343 }
344 break;
345 }
346 for (x=0; x < (ssize_t) number_pixels; x++)
347 {
348 p=PushShortPixel(quantum_info->endian,p,&pixel);
349 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
350 p+=quantum_info->pad;
351 q+=GetPixelChannels(image);
352 }
353 break;
354 }
355 case 32:
356 {
357 if (quantum_info->format == FloatingPointQuantumFormat)
358 {
359 float
360 pixel;
361
362 for (x=0; x < (ssize_t) number_pixels; x++)
363 {
364 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
365 SetPixelAlpha(image,ClampToQuantum(pixel),q);
366 p+=quantum_info->pad;
367 q+=GetPixelChannels(image);
368 }
369 break;
370 }
371 else
372 {
373 unsigned int
374 pixel;
375
376 for (x=0; x < (ssize_t) number_pixels; x++)
377 {
378 p=PushLongPixel(quantum_info->endian,p,&pixel);
379 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
380 p+=quantum_info->pad;
381 q+=GetPixelChannels(image);
382 }
383 break;
384 }
385 }
386 case 24:
387 {
388 if (quantum_info->format == FloatingPointQuantumFormat)
389 {
390 float
391 pixel;
392
393 for (x=0; x < (ssize_t) number_pixels; x++)
394 {
395 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
396 SetPixelAlpha(image,ClampToQuantum(pixel),q);
397 p+=quantum_info->pad;
398 q+=GetPixelChannels(image);
399 }
400 break;
401 }
402 magick_fallthrough;
403 }
404 case 64:
405 {
406 if (quantum_info->format == FloatingPointQuantumFormat)
407 {
408 double
409 pixel;
410
411 for (x=0; x < (ssize_t) number_pixels; x++)
412 {
413 p=PushDoublePixel(quantum_info,p,&pixel);
414 SetPixelAlpha(image,ClampToQuantum(pixel),q);
415 p+=quantum_info->pad;
416 q+=GetPixelChannels(image);
417 }
418 break;
419 }
420 magick_fallthrough;
421 }
422 default:
423 {
424 unsigned int
425 pixel;
426
427 range=GetQuantumRange(quantum_info->depth);
428 for (x=0; x < (ssize_t) number_pixels; x++)
429 {
430 p=PushQuantumPixel(quantum_info,p,&pixel);
431 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
432 p+=quantum_info->pad;
433 q+=GetPixelChannels(image);
434 }
435 break;
436 }
437 }
438}
439
440static void ImportBGRQuantum(const Image *image,QuantumInfo *quantum_info,
441 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
442 Quantum *magick_restrict q)
443{
444 QuantumAny
445 range;
446
447 ssize_t
448 x;
449
450 ssize_t
451 bit;
452
453 assert(image != (Image *) NULL);
454 assert(image->signature == MagickCoreSignature);
455 switch (quantum_info->depth)
456 {
457 case 8:
458 {
459 unsigned char
460 pixel;
461
462 for (x=0; x < (ssize_t) number_pixels; x++)
463 {
464 p=PushCharPixel(p,&pixel);
465 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
466 p=PushCharPixel(p,&pixel);
467 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
468 p=PushCharPixel(p,&pixel);
469 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
470 SetPixelAlpha(image,OpaqueAlpha,q);
471 p+=quantum_info->pad;
472 q+=GetPixelChannels(image);
473 }
474 break;
475 }
476 case 10:
477 {
478 unsigned int
479 pixel;
480
481 range=GetQuantumRange(quantum_info->depth);
482 if (quantum_info->pack == MagickFalse)
483 {
484 for (x=0; x < (ssize_t) number_pixels; x++)
485 {
486 p=PushLongPixel(quantum_info->endian,p,&pixel);
487 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
488 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
489 q);
490 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
491 p+=quantum_info->pad;
492 q+=GetPixelChannels(image);
493 }
494 break;
495 }
496 if (quantum_info->quantum == 32U)
497 {
498 for (x=0; x < (ssize_t) number_pixels; x++)
499 {
500 p=PushQuantumLongPixel(quantum_info,p,&pixel);
501 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
502 p=PushQuantumLongPixel(quantum_info,p,&pixel);
503 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
504 p=PushQuantumLongPixel(quantum_info,p,&pixel);
505 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
506 q+=GetPixelChannels(image);
507 }
508 break;
509 }
510 for (x=0; x < (ssize_t) number_pixels; x++)
511 {
512 p=PushQuantumPixel(quantum_info,p,&pixel);
513 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
514 p=PushQuantumPixel(quantum_info,p,&pixel);
515 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
516 p=PushQuantumPixel(quantum_info,p,&pixel);
517 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
518 q+=GetPixelChannels(image);
519 }
520 break;
521 }
522 case 12:
523 {
524 range=GetQuantumRange(quantum_info->depth);
525 if (quantum_info->pack == MagickFalse)
526 {
527 unsigned short
528 pixel;
529
530 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
531 {
532 p=PushShortPixel(quantum_info->endian,p,&pixel);
533 switch (x % 3)
534 {
535 default:
536 case 0:
537 {
538 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
539 range),q);
540 break;
541 }
542 case 1:
543 {
544 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
545 range),q);
546 break;
547 }
548 case 2:
549 {
550 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
551 range),q);
552 q+=GetPixelChannels(image);
553 break;
554 }
555 }
556 p=PushShortPixel(quantum_info->endian,p,&pixel);
557 switch ((x+1) % 3)
558 {
559 default:
560 case 0:
561 {
562 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
563 range),q);
564 break;
565 }
566 case 1:
567 {
568 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
569 range),q);
570 break;
571 }
572 case 2:
573 {
574 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
575 range),q);
576 q+=GetPixelChannels(image);
577 break;
578 }
579 }
580 p+=quantum_info->pad;
581 }
582 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
583 {
584 p=PushShortPixel(quantum_info->endian,p,&pixel);
585 switch ((x+bit) % 3)
586 {
587 default:
588 case 0:
589 {
590 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
591 range),q);
592 break;
593 }
594 case 1:
595 {
596 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
597 range),q);
598 break;
599 }
600 case 2:
601 {
602 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
603 range),q);
604 q+=GetPixelChannels(image);
605 break;
606 }
607 }
608 p+=quantum_info->pad;
609 }
610 if (bit != 0)
611 p++;
612 break;
613 }
614 else
615 {
616 unsigned int
617 pixel;
618
619 if (quantum_info->quantum == 32U)
620 {
621 for (x=0; x < (ssize_t) number_pixels; x++)
622 {
623 p=PushQuantumLongPixel(quantum_info,p,&pixel);
624 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
625 p=PushQuantumLongPixel(quantum_info,p,&pixel);
626 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
627 p=PushQuantumLongPixel(quantum_info,p,&pixel);
628 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
629 q+=GetPixelChannels(image);
630 }
631 break;
632 }
633 for (x=0; x < (ssize_t) number_pixels; x++)
634 {
635 p=PushQuantumPixel(quantum_info,p,&pixel);
636 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
637 p=PushQuantumPixel(quantum_info,p,&pixel);
638 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
639 p=PushQuantumPixel(quantum_info,p,&pixel);
640 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
641 q+=GetPixelChannels(image);
642 }
643 break;
644 }
645 }
646 case 16:
647 {
648 unsigned short
649 pixel;
650
651 if (quantum_info->format == FloatingPointQuantumFormat)
652 {
653 for (x=0; x < (ssize_t) number_pixels; x++)
654 {
655 p=PushShortPixel(quantum_info->endian,p,&pixel);
656 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
657 HalfToSinglePrecision(pixel)),q);
658 p=PushShortPixel(quantum_info->endian,p,&pixel);
659 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
660 HalfToSinglePrecision(pixel)),q);
661 p=PushShortPixel(quantum_info->endian,p,&pixel);
662 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
663 HalfToSinglePrecision(pixel)),q);
664 p+=quantum_info->pad;
665 q+=GetPixelChannels(image);
666 }
667 break;
668 }
669 for (x=0; x < (ssize_t) number_pixels; x++)
670 {
671 p=PushShortPixel(quantum_info->endian,p,&pixel);
672 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
673 p=PushShortPixel(quantum_info->endian,p,&pixel);
674 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
675 p=PushShortPixel(quantum_info->endian,p,&pixel);
676 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
677 p+=quantum_info->pad;
678 q+=GetPixelChannels(image);
679 }
680 break;
681 }
682 case 32:
683 {
684 if (quantum_info->format == FloatingPointQuantumFormat)
685 {
686 float
687 pixel;
688
689 for (x=0; x < (ssize_t) number_pixels; x++)
690 {
691 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
692 SetPixelRed(image,ClampToQuantum(pixel),q);
693 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
694 SetPixelGreen(image,ClampToQuantum(pixel),q);
695 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
696 SetPixelBlue(image,ClampToQuantum(pixel),q);
697 p+=quantum_info->pad;
698 q+=GetPixelChannels(image);
699 }
700 break;
701 }
702 else
703 {
704 unsigned int
705 pixel;
706
707 for (x=0; x < (ssize_t) number_pixels; x++)
708 {
709 p=PushLongPixel(quantum_info->endian,p,&pixel);
710 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
711 p=PushLongPixel(quantum_info->endian,p,&pixel);
712 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
713 p=PushLongPixel(quantum_info->endian,p,&pixel);
714 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
715 p+=quantum_info->pad;
716 q+=GetPixelChannels(image);
717 }
718 break;
719 }
720 }
721 case 24:
722 {
723 if (quantum_info->format == FloatingPointQuantumFormat)
724 {
725 float
726 pixel;
727
728 for (x=0; x < (ssize_t) number_pixels; x++)
729 {
730 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
731 SetPixelRed(image,ClampToQuantum(pixel),q);
732 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
733 SetPixelGreen(image,ClampToQuantum(pixel),q);
734 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
735 SetPixelBlue(image,ClampToQuantum(pixel),q);
736 p+=quantum_info->pad;
737 q+=GetPixelChannels(image);
738 }
739 break;
740 }
741 magick_fallthrough;
742 }
743 case 64:
744 {
745 if (quantum_info->format == FloatingPointQuantumFormat)
746 {
747 double
748 pixel;
749
750 for (x=0; x < (ssize_t) number_pixels; x++)
751 {
752 p=PushDoublePixel(quantum_info,p,&pixel);
753 SetPixelRed(image,ClampToQuantum(pixel),q);
754 p=PushDoublePixel(quantum_info,p,&pixel);
755 SetPixelGreen(image,ClampToQuantum(pixel),q);
756 p=PushDoublePixel(quantum_info,p,&pixel);
757 SetPixelBlue(image,ClampToQuantum(pixel),q);
758 p+=quantum_info->pad;
759 q+=GetPixelChannels(image);
760 }
761 break;
762 }
763 magick_fallthrough;
764 }
765 default:
766 {
767 unsigned int
768 pixel;
769
770 range=GetQuantumRange(quantum_info->depth);
771 for (x=0; x < (ssize_t) number_pixels; x++)
772 {
773 p=PushQuantumPixel(quantum_info,p,&pixel);
774 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
775 p=PushQuantumPixel(quantum_info,p,&pixel);
776 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
777 p=PushQuantumPixel(quantum_info,p,&pixel);
778 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
779 q+=GetPixelChannels(image);
780 }
781 break;
782 }
783 }
784}
785
786static void ImportBGRAQuantum(const Image *image,QuantumInfo *quantum_info,
787 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
788 Quantum *magick_restrict q)
789{
790 QuantumAny
791 range;
792
793 ssize_t
794 x;
795
796 assert(image != (Image *) NULL);
797 assert(image->signature == MagickCoreSignature);
798 switch (quantum_info->depth)
799 {
800 case 8:
801 {
802 unsigned char
803 pixel;
804
805 for (x=0; x < (ssize_t) number_pixels; x++)
806 {
807 p=PushCharPixel(p,&pixel);
808 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
809 p=PushCharPixel(p,&pixel);
810 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
811 p=PushCharPixel(p,&pixel);
812 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
813 p=PushCharPixel(p,&pixel);
814 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
815 p+=quantum_info->pad;
816 q+=GetPixelChannels(image);
817 }
818 break;
819 }
820 case 10:
821 {
822 unsigned int
823 pixel;
824
825 pixel=0;
826 if (quantum_info->pack == MagickFalse)
827 {
828 ssize_t
829 i;
830
831 size_t
832 quantum;
833
834 ssize_t
835 n;
836
837 n=0;
838 quantum=0;
839 for (x=0; x < (ssize_t) number_pixels; x++)
840 {
841 for (i=0; i < 4; i++)
842 {
843 switch (n % 3)
844 {
845 case 0:
846 {
847 p=PushLongPixel(quantum_info->endian,p,&pixel);
848 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
849 (((pixel >> 22) & 0x3ff) << 6)));
850 break;
851 }
852 case 1:
853 {
854 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
855 (((pixel >> 12) & 0x3ff) << 6)));
856 break;
857 }
858 case 2:
859 {
860 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
861 (((pixel >> 2) & 0x3ff) << 6)));
862 break;
863 }
864 }
865 switch (i)
866 {
867 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
868 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
869 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
870 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
871 }
872 n++;
873 }
874 p+=quantum_info->pad;
875 q+=GetPixelChannels(image);
876 }
877 break;
878 }
879 for (x=0; x < (ssize_t) number_pixels; x++)
880 {
881 p=PushQuantumPixel(quantum_info,p,&pixel);
882 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
883 p=PushQuantumPixel(quantum_info,p,&pixel);
884 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
885 q);
886 p=PushQuantumPixel(quantum_info,p,&pixel);
887 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
888 q);
889 p=PushQuantumPixel(quantum_info,p,&pixel);
890 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
891 q);
892 q+=GetPixelChannels(image);
893 }
894 break;
895 }
896 case 16:
897 {
898 unsigned short
899 pixel;
900
901 if (quantum_info->format == FloatingPointQuantumFormat)
902 {
903 for (x=0; x < (ssize_t) number_pixels; x++)
904 {
905 p=PushShortPixel(quantum_info->endian,p,&pixel);
906 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
907 HalfToSinglePrecision(pixel)),q);
908 p=PushShortPixel(quantum_info->endian,p,&pixel);
909 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
910 HalfToSinglePrecision(pixel)),q);
911 p=PushShortPixel(quantum_info->endian,p,&pixel);
912 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
913 HalfToSinglePrecision(pixel)),q);
914 p=PushShortPixel(quantum_info->endian,p,&pixel);
915 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
916 HalfToSinglePrecision(pixel)),q);
917 p+=quantum_info->pad;
918 q+=GetPixelChannels(image);
919 }
920 break;
921 }
922 for (x=0; x < (ssize_t) number_pixels; x++)
923 {
924 p=PushShortPixel(quantum_info->endian,p,&pixel);
925 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
926 p=PushShortPixel(quantum_info->endian,p,&pixel);
927 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
928 p=PushShortPixel(quantum_info->endian,p,&pixel);
929 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
930 p=PushShortPixel(quantum_info->endian,p,&pixel);
931 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
932 p+=quantum_info->pad;
933 q+=GetPixelChannels(image);
934 }
935 break;
936 }
937 case 32:
938 {
939 if (quantum_info->format == FloatingPointQuantumFormat)
940 {
941 float
942 pixel;
943
944 for (x=0; x < (ssize_t) number_pixels; x++)
945 {
946 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
947 SetPixelRed(image,ClampToQuantum(pixel),q);
948 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
949 SetPixelGreen(image,ClampToQuantum(pixel),q);
950 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
951 SetPixelBlue(image,ClampToQuantum(pixel),q);
952 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
953 SetPixelAlpha(image,ClampToQuantum(pixel),q);
954 p+=quantum_info->pad;
955 q+=GetPixelChannels(image);
956 }
957 break;
958 }
959 else
960 {
961 unsigned int
962 pixel;
963
964 for (x=0; x < (ssize_t) number_pixels; x++)
965 {
966 p=PushLongPixel(quantum_info->endian,p,&pixel);
967 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
968 p=PushLongPixel(quantum_info->endian,p,&pixel);
969 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
970 p=PushLongPixel(quantum_info->endian,p,&pixel);
971 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
972 p=PushLongPixel(quantum_info->endian,p,&pixel);
973 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
974 p+=quantum_info->pad;
975 q+=GetPixelChannels(image);
976 }
977 break;
978 }
979 }
980 case 24:
981 {
982 if (quantum_info->format == FloatingPointQuantumFormat)
983 {
984 float
985 pixel;
986
987 for (x=0; x < (ssize_t) number_pixels; x++)
988 {
989 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
990 SetPixelRed(image,ClampToQuantum(pixel),q);
991 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
992 SetPixelGreen(image,ClampToQuantum(pixel),q);
993 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
994 SetPixelBlue(image,ClampToQuantum(pixel),q);
995 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
996 SetPixelAlpha(image,ClampToQuantum(pixel),q);
997 p+=quantum_info->pad;
998 q+=GetPixelChannels(image);
999 }
1000 break;
1001 }
1002 magick_fallthrough;
1003 }
1004 case 64:
1005 {
1006 if (quantum_info->format == FloatingPointQuantumFormat)
1007 {
1008 double
1009 pixel;
1010
1011 for (x=0; x < (ssize_t) number_pixels; x++)
1012 {
1013 p=PushDoublePixel(quantum_info,p,&pixel);
1014 SetPixelRed(image,ClampToQuantum(pixel),q);
1015 p=PushDoublePixel(quantum_info,p,&pixel);
1016 SetPixelGreen(image,ClampToQuantum(pixel),q);
1017 p=PushDoublePixel(quantum_info,p,&pixel);
1018 SetPixelBlue(image,ClampToQuantum(pixel),q);
1019 p=PushDoublePixel(quantum_info,p,&pixel);
1020 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1021 p+=quantum_info->pad;
1022 q+=GetPixelChannels(image);
1023 }
1024 break;
1025 }
1026 magick_fallthrough;
1027 }
1028 default:
1029 {
1030 unsigned int
1031 pixel;
1032
1033 range=GetQuantumRange(quantum_info->depth);
1034 for (x=0; x < (ssize_t) number_pixels; x++)
1035 {
1036 p=PushQuantumPixel(quantum_info,p,&pixel);
1037 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1038 p=PushQuantumPixel(quantum_info,p,&pixel);
1039 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1040 p=PushQuantumPixel(quantum_info,p,&pixel);
1041 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1042 p=PushQuantumPixel(quantum_info,p,&pixel);
1043 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1044 q+=GetPixelChannels(image);
1045 }
1046 break;
1047 }
1048 }
1049}
1050
1051static void ImportBGROQuantum(const Image *image,QuantumInfo *quantum_info,
1052 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1053 Quantum *magick_restrict q)
1054{
1055 QuantumAny
1056 range;
1057
1058 ssize_t
1059 x;
1060
1061 assert(image != (Image *) NULL);
1062 assert(image->signature == MagickCoreSignature);
1063 switch (quantum_info->depth)
1064 {
1065 case 8:
1066 {
1067 unsigned char
1068 pixel;
1069
1070 for (x=0; x < (ssize_t) number_pixels; x++)
1071 {
1072 p=PushCharPixel(p,&pixel);
1073 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1074 p=PushCharPixel(p,&pixel);
1075 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1076 p=PushCharPixel(p,&pixel);
1077 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1078 p=PushCharPixel(p,&pixel);
1079 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
1080 p+=quantum_info->pad;
1081 q+=GetPixelChannels(image);
1082 }
1083 break;
1084 }
1085 case 10:
1086 {
1087 unsigned int
1088 pixel;
1089
1090 pixel=0;
1091 if (quantum_info->pack == MagickFalse)
1092 {
1093 ssize_t
1094 i;
1095
1096 size_t
1097 quantum;
1098
1099 ssize_t
1100 n;
1101
1102 n=0;
1103 quantum=0;
1104 for (x=0; x < (ssize_t) number_pixels; x++)
1105 {
1106 for (i=0; i < 4; i++)
1107 {
1108 switch (n % 3)
1109 {
1110 case 0:
1111 {
1112 p=PushLongPixel(quantum_info->endian,p,&pixel);
1113 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1114 (((pixel >> 22) & 0x3ff) << 6)));
1115 break;
1116 }
1117 case 1:
1118 {
1119 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1120 (((pixel >> 12) & 0x3ff) << 6)));
1121 break;
1122 }
1123 case 2:
1124 {
1125 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1126 (((pixel >> 2) & 0x3ff) << 6)));
1127 break;
1128 }
1129 }
1130 switch (i)
1131 {
1132 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
1133 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
1134 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
1135 case 3: SetPixelOpacity(image,(Quantum) quantum,q); break;
1136 }
1137 n++;
1138 }
1139 p+=quantum_info->pad;
1140 q+=GetPixelChannels(image);
1141 }
1142 break;
1143 }
1144 for (x=0; x < (ssize_t) number_pixels; x++)
1145 {
1146 p=PushQuantumPixel(quantum_info,p,&pixel);
1147 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
1148 p=PushQuantumPixel(quantum_info,p,&pixel);
1149 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1150 q);
1151 p=PushQuantumPixel(quantum_info,p,&pixel);
1152 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1153 q);
1154 p=PushQuantumPixel(quantum_info,p,&pixel);
1155 SetPixelOpacity(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1156 q);
1157 q+=GetPixelChannels(image);
1158 }
1159 break;
1160 }
1161 case 16:
1162 {
1163 unsigned short
1164 pixel;
1165
1166 if (quantum_info->format == FloatingPointQuantumFormat)
1167 {
1168 for (x=0; x < (ssize_t) number_pixels; x++)
1169 {
1170 p=PushShortPixel(quantum_info->endian,p,&pixel);
1171 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
1172 HalfToSinglePrecision(pixel)),q);
1173 p=PushShortPixel(quantum_info->endian,p,&pixel);
1174 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
1175 HalfToSinglePrecision(pixel)),q);
1176 p=PushShortPixel(quantum_info->endian,p,&pixel);
1177 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
1178 HalfToSinglePrecision(pixel)),q);
1179 p=PushShortPixel(quantum_info->endian,p,&pixel);
1180 SetPixelOpacity(image,ClampToQuantum((double) QuantumRange*(double)
1181 HalfToSinglePrecision(pixel)),q);
1182 p+=quantum_info->pad;
1183 q+=GetPixelChannels(image);
1184 }
1185 break;
1186 }
1187 for (x=0; x < (ssize_t) number_pixels; x++)
1188 {
1189 p=PushShortPixel(quantum_info->endian,p,&pixel);
1190 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1191 p=PushShortPixel(quantum_info->endian,p,&pixel);
1192 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1193 p=PushShortPixel(quantum_info->endian,p,&pixel);
1194 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1195 p=PushShortPixel(quantum_info->endian,p,&pixel);
1196 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
1197 p+=quantum_info->pad;
1198 q+=GetPixelChannels(image);
1199 }
1200 break;
1201 }
1202 case 32:
1203 {
1204 if (quantum_info->format == FloatingPointQuantumFormat)
1205 {
1206 float
1207 pixel;
1208
1209 for (x=0; x < (ssize_t) number_pixels; x++)
1210 {
1211 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1212 SetPixelRed(image,ClampToQuantum(pixel),q);
1213 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1214 SetPixelGreen(image,ClampToQuantum(pixel),q);
1215 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1216 SetPixelBlue(image,ClampToQuantum(pixel),q);
1217 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1218 SetPixelOpacity(image,ClampToQuantum(pixel),q);
1219 p+=quantum_info->pad;
1220 q+=GetPixelChannels(image);
1221 }
1222 break;
1223 }
1224 else
1225 {
1226 unsigned int
1227 pixel;
1228
1229 for (x=0; x < (ssize_t) number_pixels; x++)
1230 {
1231 p=PushLongPixel(quantum_info->endian,p,&pixel);
1232 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1233 p=PushLongPixel(quantum_info->endian,p,&pixel);
1234 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1235 p=PushLongPixel(quantum_info->endian,p,&pixel);
1236 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1237 p=PushLongPixel(quantum_info->endian,p,&pixel);
1238 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
1239 p+=quantum_info->pad;
1240 q+=GetPixelChannels(image);
1241 }
1242 }
1243 break;
1244 }
1245 case 24:
1246 {
1247 if (quantum_info->format == FloatingPointQuantumFormat)
1248 {
1249 float
1250 pixel;
1251
1252 for (x=0; x < (ssize_t) number_pixels; x++)
1253 {
1254 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1255 SetPixelRed(image,ClampToQuantum(pixel),q);
1256 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1257 SetPixelGreen(image,ClampToQuantum(pixel),q);
1258 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1259 SetPixelBlue(image,ClampToQuantum(pixel),q);
1260 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1261 SetPixelOpacity(image,ClampToQuantum(pixel),q);
1262 p+=quantum_info->pad;
1263 q+=GetPixelChannels(image);
1264 }
1265 break;
1266 }
1267 magick_fallthrough;
1268 }
1269 case 64:
1270 {
1271 if (quantum_info->format == FloatingPointQuantumFormat)
1272 {
1273 double
1274 pixel;
1275
1276 for (x=0; x < (ssize_t) number_pixels; x++)
1277 {
1278 p=PushDoublePixel(quantum_info,p,&pixel);
1279 SetPixelRed(image,ClampToQuantum(pixel),q);
1280 p=PushDoublePixel(quantum_info,p,&pixel);
1281 SetPixelGreen(image,ClampToQuantum(pixel),q);
1282 p=PushDoublePixel(quantum_info,p,&pixel);
1283 SetPixelBlue(image,ClampToQuantum(pixel),q);
1284 p=PushDoublePixel(quantum_info,p,&pixel);
1285 SetPixelOpacity(image,ClampToQuantum(pixel),q);
1286 p+=quantum_info->pad;
1287 q+=GetPixelChannels(image);
1288 }
1289 break;
1290 }
1291 magick_fallthrough;
1292 }
1293 default:
1294 {
1295 unsigned int
1296 pixel;
1297
1298 range=GetQuantumRange(quantum_info->depth);
1299 for (x=0; x < (ssize_t) number_pixels; x++)
1300 {
1301 p=PushQuantumPixel(quantum_info,p,&pixel);
1302 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1303 p=PushQuantumPixel(quantum_info,p,&pixel);
1304 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1305 p=PushQuantumPixel(quantum_info,p,&pixel);
1306 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1307 p=PushQuantumPixel(quantum_info,p,&pixel);
1308 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
1309 q+=GetPixelChannels(image);
1310 }
1311 break;
1312 }
1313 }
1314}
1315
1316static void ImportBlackQuantum(const Image *image,QuantumInfo *quantum_info,
1317 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1318 Quantum *magick_restrict q,ExceptionInfo *exception)
1319{
1320 QuantumAny
1321 range;
1322
1323 ssize_t
1324 x;
1325
1326 if (image->colorspace != CMYKColorspace)
1327 {
1328 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1329 "ColorSeparatedImageRequired","`%s'",image->filename);
1330 return;
1331 }
1332 switch (quantum_info->depth)
1333 {
1334 case 8:
1335 {
1336 unsigned char
1337 pixel;
1338
1339 for (x=0; x < (ssize_t) number_pixels; x++)
1340 {
1341 p=PushCharPixel(p,&pixel);
1342 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1343 p+=quantum_info->pad;
1344 q+=GetPixelChannels(image);
1345 }
1346 break;
1347 }
1348 case 16:
1349 {
1350 unsigned short
1351 pixel;
1352
1353 if (quantum_info->format == FloatingPointQuantumFormat)
1354 {
1355 for (x=0; x < (ssize_t) number_pixels; x++)
1356 {
1357 p=PushShortPixel(quantum_info->endian,p,&pixel);
1358 SetPixelBlack(image,ClampToQuantum((double) QuantumRange*(double)
1359 HalfToSinglePrecision(pixel)),q);
1360 p+=quantum_info->pad;
1361 q+=GetPixelChannels(image);
1362 }
1363 break;
1364 }
1365 for (x=0; x < (ssize_t) number_pixels; x++)
1366 {
1367 p=PushShortPixel(quantum_info->endian,p,&pixel);
1368 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1369 p+=quantum_info->pad;
1370 q+=GetPixelChannels(image);
1371 }
1372 break;
1373 }
1374 case 32:
1375 {
1376 if (quantum_info->format == FloatingPointQuantumFormat)
1377 {
1378 float
1379 pixel;
1380
1381 for (x=0; x < (ssize_t) number_pixels; x++)
1382 {
1383 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1384 SetPixelBlack(image,ClampToQuantum(pixel),q);
1385 p+=quantum_info->pad;
1386 q+=GetPixelChannels(image);
1387 }
1388 break;
1389 }
1390 else
1391 {
1392 unsigned int
1393 pixel;
1394
1395 for (x=0; x < (ssize_t) number_pixels; x++)
1396 {
1397 p=PushLongPixel(quantum_info->endian,p,&pixel);
1398 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1399 p+=quantum_info->pad;
1400 q+=GetPixelChannels(image);
1401 }
1402 break;
1403 }
1404 }
1405 case 24:
1406 {
1407 if (quantum_info->format == FloatingPointQuantumFormat)
1408 {
1409 float
1410 pixel;
1411
1412 for (x=0; x < (ssize_t) number_pixels; x++)
1413 {
1414 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1415 SetPixelBlack(image,ClampToQuantum(pixel),q);
1416 p+=quantum_info->pad;
1417 q+=GetPixelChannels(image);
1418 }
1419 break;
1420 }
1421 magick_fallthrough;
1422 }
1423 case 64:
1424 {
1425 if (quantum_info->format == FloatingPointQuantumFormat)
1426 {
1427 double
1428 pixel;
1429
1430 for (x=0; x < (ssize_t) number_pixels; x++)
1431 {
1432 p=PushDoublePixel(quantum_info,p,&pixel);
1433 SetPixelBlack(image,ClampToQuantum(pixel),q);
1434 p+=quantum_info->pad;
1435 q+=GetPixelChannels(image);
1436 }
1437 break;
1438 }
1439 magick_fallthrough;
1440 }
1441 default:
1442 {
1443 unsigned int
1444 pixel;
1445
1446 range=GetQuantumRange(quantum_info->depth);
1447 for (x=0; x < (ssize_t) number_pixels; x++)
1448 {
1449 p=PushQuantumPixel(quantum_info,p,&pixel);
1450 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1451 p+=quantum_info->pad;
1452 q+=GetPixelChannels(image);
1453 }
1454 break;
1455 }
1456 }
1457}
1458
1459static void ImportBlueQuantum(const Image *image,QuantumInfo *quantum_info,
1460 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1461 Quantum *magick_restrict q)
1462{
1463 QuantumAny
1464 range;
1465
1466 ssize_t
1467 x;
1468
1469 assert(image != (Image *) NULL);
1470 assert(image->signature == MagickCoreSignature);
1471 switch (quantum_info->depth)
1472 {
1473 case 8:
1474 {
1475 unsigned char
1476 pixel;
1477
1478 for (x=0; x < (ssize_t) number_pixels; x++)
1479 {
1480 p=PushCharPixel(p,&pixel);
1481 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1482 p+=quantum_info->pad;
1483 q+=GetPixelChannels(image);
1484 }
1485 break;
1486 }
1487 case 16:
1488 {
1489 unsigned short
1490 pixel;
1491
1492 if (quantum_info->format == FloatingPointQuantumFormat)
1493 {
1494 for (x=0; x < (ssize_t) number_pixels; x++)
1495 {
1496 p=PushShortPixel(quantum_info->endian,p,&pixel);
1497 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
1498 HalfToSinglePrecision(pixel)),q);
1499 p+=quantum_info->pad;
1500 q+=GetPixelChannels(image);
1501 }
1502 break;
1503 }
1504 for (x=0; x < (ssize_t) number_pixels; x++)
1505 {
1506 p=PushShortPixel(quantum_info->endian,p,&pixel);
1507 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1508 p+=quantum_info->pad;
1509 q+=GetPixelChannels(image);
1510 }
1511 break;
1512 }
1513 case 32:
1514 {
1515 if (quantum_info->format == FloatingPointQuantumFormat)
1516 {
1517 float
1518 pixel;
1519
1520 for (x=0; x < (ssize_t) number_pixels; x++)
1521 {
1522 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1523 SetPixelBlue(image,ClampToQuantum(pixel),q);
1524 p+=quantum_info->pad;
1525 q+=GetPixelChannels(image);
1526 }
1527 break;
1528 }
1529 else
1530 {
1531 unsigned int
1532 pixel;
1533
1534 for (x=0; x < (ssize_t) number_pixels; x++)
1535 {
1536 p=PushLongPixel(quantum_info->endian,p,&pixel);
1537 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1538 p+=quantum_info->pad;
1539 q+=GetPixelChannels(image);
1540 }
1541 break;
1542 }
1543 }
1544 case 24:
1545 {
1546 if (quantum_info->format == FloatingPointQuantumFormat)
1547 {
1548 float
1549 pixel;
1550
1551 for (x=0; x < (ssize_t) number_pixels; x++)
1552 {
1553 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1554 SetPixelBlue(image,ClampToQuantum(pixel),q);
1555 p+=quantum_info->pad;
1556 q+=GetPixelChannels(image);
1557 }
1558 break;
1559 }
1560 magick_fallthrough;
1561 }
1562 case 64:
1563 {
1564 if (quantum_info->format == FloatingPointQuantumFormat)
1565 {
1566 double
1567 pixel;
1568
1569 for (x=0; x < (ssize_t) number_pixels; x++)
1570 {
1571 p=PushDoublePixel(quantum_info,p,&pixel);
1572 SetPixelBlue(image,ClampToQuantum(pixel),q);
1573 p+=quantum_info->pad;
1574 q+=GetPixelChannels(image);
1575 }
1576 break;
1577 }
1578 magick_fallthrough;
1579 }
1580 default:
1581 {
1582 unsigned int
1583 pixel;
1584
1585 range=GetQuantumRange(quantum_info->depth);
1586 for (x=0; x < (ssize_t) number_pixels; x++)
1587 {
1588 p=PushQuantumPixel(quantum_info,p,&pixel);
1589 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1590 p+=quantum_info->pad;
1591 q+=GetPixelChannels(image);
1592 }
1593 break;
1594 }
1595 }
1596}
1597
1598static void ImportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info,
1599 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1600 Quantum *magick_restrict q)
1601{
1602 QuantumAny
1603 range;
1604
1605 ssize_t
1606 x;
1607
1608 unsigned int
1609 pixel;
1610
1611 assert(image != (Image *) NULL);
1612 assert(image->signature == MagickCoreSignature);
1613 switch (quantum_info->depth)
1614 {
1615 case 10:
1616 {
1617 Quantum
1618 cbcr[4];
1619
1620 pixel=0;
1621 if (quantum_info->pack == MagickFalse)
1622 {
1623 ssize_t
1624 i;
1625
1626 size_t
1627 quantum;
1628
1629 ssize_t
1630 n;
1631
1632 n=0;
1633 quantum=0;
1634 for (x=0; x < (ssize_t) (number_pixels-3); x+=4)
1635 {
1636 for (i=0; i < 4; i++)
1637 {
1638 switch (n % 3)
1639 {
1640 case 0:
1641 {
1642 p=PushLongPixel(quantum_info->endian,p,&pixel);
1643 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1644 (((pixel >> 22) & 0x3ff) << 6)));
1645 break;
1646 }
1647 case 1:
1648 {
1649 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1650 (((pixel >> 12) & 0x3ff) << 6)));
1651 break;
1652 }
1653 case 2:
1654 {
1655 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1656 (((pixel >> 2) & 0x3ff) << 6)));
1657 break;
1658 }
1659 }
1660 cbcr[i]=(Quantum) (quantum);
1661 n++;
1662 }
1663 p+=quantum_info->pad;
1664 SetPixelRed(image,cbcr[1],q);
1665 SetPixelGreen(image,cbcr[0],q);
1666 SetPixelBlue(image,cbcr[2],q);
1667 q+=GetPixelChannels(image);
1668 SetPixelRed(image,cbcr[3],q);
1669 SetPixelGreen(image,cbcr[0],q);
1670 SetPixelBlue(image,cbcr[2],q);
1671 q+=GetPixelChannels(image);
1672 }
1673 break;
1674 }
1675 magick_fallthrough;
1676 }
1677 default:
1678 {
1679 range=GetQuantumRange(quantum_info->depth);
1680 for (x=0; x < (ssize_t) number_pixels; x++)
1681 {
1682 p=PushQuantumPixel(quantum_info,p,&pixel);
1683 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1684 p=PushQuantumPixel(quantum_info,p,&pixel);
1685 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1686 q+=GetPixelChannels(image);
1687 }
1688 break;
1689 }
1690 }
1691}
1692
1693static void ImportCMYKQuantum(const Image *image,QuantumInfo *quantum_info,
1694 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1695 Quantum *magick_restrict q,ExceptionInfo *exception)
1696{
1697 QuantumAny
1698 range;
1699
1700 ssize_t
1701 x;
1702
1703 if (image->colorspace != CMYKColorspace)
1704 {
1705 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1706 "ColorSeparatedImageRequired","`%s'",image->filename);
1707 return;
1708 }
1709 switch (quantum_info->depth)
1710 {
1711 case 8:
1712 {
1713 unsigned char
1714 pixel;
1715
1716 for (x=0; x < (ssize_t) number_pixels; x++)
1717 {
1718 p=PushCharPixel(p,&pixel);
1719 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1720 p=PushCharPixel(p,&pixel);
1721 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1722 p=PushCharPixel(p,&pixel);
1723 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1724 p=PushCharPixel(p,&pixel);
1725 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1726 p+=quantum_info->pad;
1727 q+=GetPixelChannels(image);
1728 }
1729 break;
1730 }
1731 case 16:
1732 {
1733 unsigned short
1734 pixel;
1735
1736 if (quantum_info->format == FloatingPointQuantumFormat)
1737 {
1738 for (x=0; x < (ssize_t) number_pixels; x++)
1739 {
1740 p=PushShortPixel(quantum_info->endian,p,&pixel);
1741 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
1742 HalfToSinglePrecision(pixel)),q);
1743 p=PushShortPixel(quantum_info->endian,p,&pixel);
1744 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
1745 HalfToSinglePrecision(pixel)),q);
1746 p=PushShortPixel(quantum_info->endian,p,&pixel);
1747 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
1748 HalfToSinglePrecision(pixel)),q);
1749 p=PushShortPixel(quantum_info->endian,p,&pixel);
1750 SetPixelBlack(image,ClampToQuantum((double) QuantumRange*(double)
1751 HalfToSinglePrecision(pixel)),q);
1752 p+=quantum_info->pad;
1753 q+=GetPixelChannels(image);
1754 }
1755 break;
1756 }
1757 for (x=0; x < (ssize_t) number_pixels; x++)
1758 {
1759 p=PushShortPixel(quantum_info->endian,p,&pixel);
1760 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1761 p=PushShortPixel(quantum_info->endian,p,&pixel);
1762 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1763 p=PushShortPixel(quantum_info->endian,p,&pixel);
1764 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1765 p=PushShortPixel(quantum_info->endian,p,&pixel);
1766 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1767 p+=quantum_info->pad;
1768 q+=GetPixelChannels(image);
1769 }
1770 break;
1771 }
1772 case 32:
1773 {
1774 if (quantum_info->format == FloatingPointQuantumFormat)
1775 {
1776 float
1777 pixel;
1778
1779 for (x=0; x < (ssize_t) number_pixels; x++)
1780 {
1781 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1782 SetPixelRed(image,ClampToQuantum(pixel),q);
1783 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1784 SetPixelGreen(image,ClampToQuantum(pixel),q);
1785 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1786 SetPixelBlue(image,ClampToQuantum(pixel),q);
1787 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1788 SetPixelBlack(image,ClampToQuantum(pixel),q);
1789 p+=quantum_info->pad;
1790 q+=GetPixelChannels(image);
1791 }
1792 break;
1793 }
1794 else
1795 {
1796 unsigned int
1797 pixel;
1798
1799 for (x=0; x < (ssize_t) number_pixels; x++)
1800 {
1801 p=PushLongPixel(quantum_info->endian,p,&pixel);
1802 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1803 p=PushLongPixel(quantum_info->endian,p,&pixel);
1804 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1805 p=PushLongPixel(quantum_info->endian,p,&pixel);
1806 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1807 p=PushLongPixel(quantum_info->endian,p,&pixel);
1808 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1809 p+=quantum_info->pad;
1810 q+=GetPixelChannels(image);
1811 }
1812 break;
1813 }
1814 }
1815 case 24:
1816 {
1817 if (quantum_info->format == FloatingPointQuantumFormat)
1818 {
1819 float
1820 pixel;
1821
1822 for (x=0; x < (ssize_t) number_pixels; x++)
1823 {
1824 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1825 SetPixelRed(image,ClampToQuantum(pixel),q);
1826 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1827 SetPixelGreen(image,ClampToQuantum(pixel),q);
1828 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1829 SetPixelBlue(image,ClampToQuantum(pixel),q);
1830 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
1831 SetPixelBlack(image,ClampToQuantum(pixel),q);
1832 p+=quantum_info->pad;
1833 q+=GetPixelChannels(image);
1834 }
1835 break;
1836 }
1837 magick_fallthrough;
1838 }
1839 case 64:
1840 {
1841 if (quantum_info->format == FloatingPointQuantumFormat)
1842 {
1843 double
1844 pixel;
1845
1846 for (x=0; x < (ssize_t) number_pixels; x++)
1847 {
1848 p=PushDoublePixel(quantum_info,p,&pixel);
1849 SetPixelRed(image,ClampToQuantum(pixel),q);
1850 p=PushDoublePixel(quantum_info,p,&pixel);
1851 SetPixelGreen(image,ClampToQuantum(pixel),q);
1852 p=PushDoublePixel(quantum_info,p,&pixel);
1853 SetPixelBlue(image,ClampToQuantum(pixel),q);
1854 p=PushDoublePixel(quantum_info,p,&pixel);
1855 SetPixelBlack(image,ClampToQuantum(pixel),q);
1856 p+=quantum_info->pad;
1857 q+=GetPixelChannels(image);
1858 }
1859 break;
1860 }
1861 magick_fallthrough;
1862 }
1863 default:
1864 {
1865 unsigned int
1866 pixel;
1867
1868 range=GetQuantumRange(quantum_info->depth);
1869 for (x=0; x < (ssize_t) number_pixels; x++)
1870 {
1871 p=PushQuantumPixel(quantum_info,p,&pixel);
1872 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1873 p=PushQuantumPixel(quantum_info,p,&pixel);
1874 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1875 p=PushQuantumPixel(quantum_info,p,&pixel);
1876 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1877 p=PushQuantumPixel(quantum_info,p,&pixel);
1878 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1879 q+=GetPixelChannels(image);
1880 }
1881 break;
1882 }
1883 }
1884}
1885
1886static void ImportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info,
1887 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1888 Quantum *magick_restrict q,ExceptionInfo *exception)
1889{
1890 QuantumAny
1891 range;
1892
1893 ssize_t
1894 x;
1895
1896 if (image->colorspace != CMYKColorspace)
1897 {
1898 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1899 "ColorSeparatedImageRequired","`%s'",image->filename);
1900 return;
1901 }
1902 switch (quantum_info->depth)
1903 {
1904 case 8:
1905 {
1906 unsigned char
1907 pixel;
1908
1909 for (x=0; x < (ssize_t) number_pixels; x++)
1910 {
1911 p=PushCharPixel(p,&pixel);
1912 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1913 p=PushCharPixel(p,&pixel);
1914 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1915 p=PushCharPixel(p,&pixel);
1916 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1917 p=PushCharPixel(p,&pixel);
1918 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1919 p=PushCharPixel(p,&pixel);
1920 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
1921 p+=quantum_info->pad;
1922 q+=GetPixelChannels(image);
1923 }
1924 break;
1925 }
1926 case 16:
1927 {
1928 unsigned short
1929 pixel;
1930
1931 if (quantum_info->format == FloatingPointQuantumFormat)
1932 {
1933 for (x=0; x < (ssize_t) number_pixels; x++)
1934 {
1935 p=PushShortPixel(quantum_info->endian,p,&pixel);
1936 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
1937 HalfToSinglePrecision(pixel)),q);
1938 p=PushShortPixel(quantum_info->endian,p,&pixel);
1939 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
1940 HalfToSinglePrecision(pixel)),q);
1941 p=PushShortPixel(quantum_info->endian,p,&pixel);
1942 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
1943 HalfToSinglePrecision(pixel)),q);
1944 p=PushShortPixel(quantum_info->endian,p,&pixel);
1945 SetPixelBlack(image,ClampToQuantum((double) QuantumRange*(double)
1946 HalfToSinglePrecision(pixel)),q);
1947 p=PushShortPixel(quantum_info->endian,p,&pixel);
1948 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
1949 HalfToSinglePrecision(pixel)),q);
1950 p+=quantum_info->pad;
1951 q+=GetPixelChannels(image);
1952 }
1953 break;
1954 }
1955 for (x=0; x < (ssize_t) number_pixels; x++)
1956 {
1957 p=PushShortPixel(quantum_info->endian,p,&pixel);
1958 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1959 p=PushShortPixel(quantum_info->endian,p,&pixel);
1960 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1961 p=PushShortPixel(quantum_info->endian,p,&pixel);
1962 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1963 p=PushShortPixel(quantum_info->endian,p,&pixel);
1964 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1965 p=PushShortPixel(quantum_info->endian,p,&pixel);
1966 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
1967 p+=quantum_info->pad;
1968 q+=GetPixelChannels(image);
1969 }
1970 break;
1971 }
1972 case 32:
1973 {
1974 if (quantum_info->format == FloatingPointQuantumFormat)
1975 {
1976 float
1977 pixel;
1978
1979 for (x=0; x < (ssize_t) number_pixels; x++)
1980 {
1981 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1982 SetPixelRed(image,ClampToQuantum(pixel),q);
1983 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1984 SetPixelGreen(image,ClampToQuantum(pixel),q);
1985 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1986 SetPixelBlue(image,ClampToQuantum(pixel),q);
1987 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1988 SetPixelBlack(image,ClampToQuantum(pixel),q);
1989 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1990 SetPixelAlpha(image,ClampToQuantum(pixel),q);
1991 p+=quantum_info->pad;
1992 q+=GetPixelChannels(image);
1993 }
1994 break;
1995 }
1996 else
1997 {
1998 unsigned int
1999 pixel;
2000
2001 for (x=0; x < (ssize_t) number_pixels; x++)
2002 {
2003 p=PushLongPixel(quantum_info->endian,p,&pixel);
2004 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
2005 p=PushLongPixel(quantum_info->endian,p,&pixel);
2006 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
2007 p=PushLongPixel(quantum_info->endian,p,&pixel);
2008 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
2009 p=PushLongPixel(quantum_info->endian,p,&pixel);
2010 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
2011 p=PushLongPixel(quantum_info->endian,p,&pixel);
2012 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2013 p+=quantum_info->pad;
2014 q+=GetPixelChannels(image);
2015 }
2016 break;
2017 }
2018 }
2019 case 24:
2020 {
2021 if (quantum_info->format == FloatingPointQuantumFormat)
2022 {
2023 float
2024 pixel;
2025
2026 for (x=0; x < (ssize_t) number_pixels; x++)
2027 {
2028 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2029 SetPixelRed(image,ClampToQuantum(pixel),q);
2030 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2031 SetPixelGreen(image,ClampToQuantum(pixel),q);
2032 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2033 SetPixelBlue(image,ClampToQuantum(pixel),q);
2034 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2035 SetPixelBlack(image,ClampToQuantum(pixel),q);
2036 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2037 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2038 p+=quantum_info->pad;
2039 q+=GetPixelChannels(image);
2040 }
2041 break;
2042 }
2043 magick_fallthrough;
2044 }
2045 case 64:
2046 {
2047 if (quantum_info->format == FloatingPointQuantumFormat)
2048 {
2049 double
2050 pixel;
2051
2052 for (x=0; x < (ssize_t) number_pixels; x++)
2053 {
2054 p=PushDoublePixel(quantum_info,p,&pixel);
2055 SetPixelRed(image,ClampToQuantum(pixel),q);
2056 p=PushDoublePixel(quantum_info,p,&pixel);
2057 SetPixelGreen(image,ClampToQuantum(pixel),q);
2058 p=PushDoublePixel(quantum_info,p,&pixel);
2059 SetPixelBlue(image,ClampToQuantum(pixel),q);
2060 p=PushDoublePixel(quantum_info,p,&pixel);
2061 SetPixelBlack(image,ClampToQuantum(pixel),q);
2062 p=PushDoublePixel(quantum_info,p,&pixel);
2063 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2064 p+=quantum_info->pad;
2065 q+=GetPixelChannels(image);
2066 }
2067 break;
2068 }
2069 magick_fallthrough;
2070 }
2071 default:
2072 {
2073 unsigned int
2074 pixel;
2075
2076 range=GetQuantumRange(quantum_info->depth);
2077 for (x=0; x < (ssize_t) number_pixels; x++)
2078 {
2079 p=PushQuantumPixel(quantum_info,p,&pixel);
2080 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2081 p=PushQuantumPixel(quantum_info,p,&pixel);
2082 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2083 p=PushQuantumPixel(quantum_info,p,&pixel);
2084 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
2085 p=PushQuantumPixel(quantum_info,p,&pixel);
2086 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
2087 p=PushQuantumPixel(quantum_info,p,&pixel);
2088 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2089 q+=GetPixelChannels(image);
2090 }
2091 break;
2092 }
2093 }
2094}
2095
2096static void ImportCMYKOQuantum(const Image *image,QuantumInfo *quantum_info,
2097 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
2098 Quantum *magick_restrict q,ExceptionInfo *exception)
2099{
2100 QuantumAny
2101 range;
2102
2103 ssize_t
2104 x;
2105
2106 if (image->colorspace != CMYKColorspace)
2107 {
2108 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2109 "ColorSeparatedImageRequired","`%s'",image->filename);
2110 return;
2111 }
2112 switch (quantum_info->depth)
2113 {
2114 case 8:
2115 {
2116 unsigned char
2117 pixel;
2118
2119 for (x=0; x < (ssize_t) number_pixels; x++)
2120 {
2121 p=PushCharPixel(p,&pixel);
2122 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
2123 p=PushCharPixel(p,&pixel);
2124 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2125 p=PushCharPixel(p,&pixel);
2126 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
2127 p=PushCharPixel(p,&pixel);
2128 SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
2129 p=PushCharPixel(p,&pixel);
2130 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
2131 p+=quantum_info->pad;
2132 q+=GetPixelChannels(image);
2133 }
2134 break;
2135 }
2136 case 16:
2137 {
2138 unsigned short
2139 pixel;
2140
2141 if (quantum_info->format == FloatingPointQuantumFormat)
2142 {
2143 for (x=0; x < (ssize_t) number_pixels; x++)
2144 {
2145 p=PushShortPixel(quantum_info->endian,p,&pixel);
2146 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
2147 HalfToSinglePrecision(pixel)),q);
2148 p=PushShortPixel(quantum_info->endian,p,&pixel);
2149 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
2150 HalfToSinglePrecision(pixel)),q);
2151 p=PushShortPixel(quantum_info->endian,p,&pixel);
2152 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
2153 HalfToSinglePrecision(pixel)),q);
2154 p=PushShortPixel(quantum_info->endian,p,&pixel);
2155 SetPixelBlack(image,ClampToQuantum((double) QuantumRange*(double)
2156 HalfToSinglePrecision(pixel)),q);
2157 p=PushShortPixel(quantum_info->endian,p,&pixel);
2158 SetPixelOpacity(image,ClampToQuantum((double) QuantumRange*(double)
2159 HalfToSinglePrecision(pixel)),q);
2160 p+=quantum_info->pad;
2161 q+=GetPixelChannels(image);
2162 }
2163 break;
2164 }
2165 for (x=0; x < (ssize_t) number_pixels; x++)
2166 {
2167 p=PushShortPixel(quantum_info->endian,p,&pixel);
2168 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
2169 p=PushShortPixel(quantum_info->endian,p,&pixel);
2170 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
2171 p=PushShortPixel(quantum_info->endian,p,&pixel);
2172 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
2173 p=PushShortPixel(quantum_info->endian,p,&pixel);
2174 SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
2175 p=PushShortPixel(quantum_info->endian,p,&pixel);
2176 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
2177 p+=quantum_info->pad;
2178 q+=GetPixelChannels(image);
2179 }
2180 break;
2181 }
2182 case 32:
2183 {
2184 if (quantum_info->format == FloatingPointQuantumFormat)
2185 {
2186 float
2187 pixel;
2188
2189 for (x=0; x < (ssize_t) number_pixels; x++)
2190 {
2191 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2192 SetPixelRed(image,ClampToQuantum(pixel),q);
2193 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2194 SetPixelGreen(image,ClampToQuantum(pixel),q);
2195 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2196 SetPixelBlue(image,ClampToQuantum(pixel),q);
2197 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2198 SetPixelBlack(image,ClampToQuantum(pixel),q);
2199 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2200 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2201 p+=quantum_info->pad;
2202 q+=GetPixelChannels(image);
2203 }
2204 break;
2205 }
2206 else
2207 {
2208 unsigned int
2209 pixel;
2210
2211 for (x=0; x < (ssize_t) number_pixels; x++)
2212 {
2213 p=PushLongPixel(quantum_info->endian,p,&pixel);
2214 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
2215 p=PushLongPixel(quantum_info->endian,p,&pixel);
2216 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
2217 p=PushLongPixel(quantum_info->endian,p,&pixel);
2218 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
2219 p=PushLongPixel(quantum_info->endian,p,&pixel);
2220 SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
2221 p=PushLongPixel(quantum_info->endian,p,&pixel);
2222 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
2223 p+=quantum_info->pad;
2224 q+=GetPixelChannels(image);
2225 }
2226 break;
2227 }
2228 }
2229 case 24:
2230 {
2231 if (quantum_info->format == FloatingPointQuantumFormat)
2232 {
2233 float
2234 pixel;
2235
2236 for (x=0; x < (ssize_t) number_pixels; x++)
2237 {
2238 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2239 SetPixelRed(image,ClampToQuantum(pixel),q);
2240 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2241 SetPixelGreen(image,ClampToQuantum(pixel),q);
2242 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2243 SetPixelBlue(image,ClampToQuantum(pixel),q);
2244 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2245 SetPixelBlack(image,ClampToQuantum(pixel),q);
2246 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2247 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2248 p+=quantum_info->pad;
2249 q+=GetPixelChannels(image);
2250 }
2251 break;
2252 }
2253 magick_fallthrough;
2254 }
2255 case 64:
2256 {
2257 if (quantum_info->format == FloatingPointQuantumFormat)
2258 {
2259 double
2260 pixel;
2261
2262 for (x=0; x < (ssize_t) number_pixels; x++)
2263 {
2264 p=PushDoublePixel(quantum_info,p,&pixel);
2265 SetPixelRed(image,ClampToQuantum(pixel),q);
2266 p=PushDoublePixel(quantum_info,p,&pixel);
2267 SetPixelGreen(image,ClampToQuantum(pixel),q);
2268 p=PushDoublePixel(quantum_info,p,&pixel);
2269 SetPixelBlue(image,ClampToQuantum(pixel),q);
2270 p=PushDoublePixel(quantum_info,p,&pixel);
2271 SetPixelBlack(image,ClampToQuantum(pixel),q);
2272 p=PushDoublePixel(quantum_info,p,&pixel);
2273 SetPixelOpacity(image,ClampToQuantum(pixel),q);
2274 p+=quantum_info->pad;
2275 q+=GetPixelChannels(image);
2276 }
2277 break;
2278 }
2279 magick_fallthrough;
2280 }
2281 default:
2282 {
2283 unsigned int
2284 pixel;
2285
2286 range=GetQuantumRange(quantum_info->depth);
2287 for (x=0; x < (ssize_t) number_pixels; x++)
2288 {
2289 p=PushQuantumPixel(quantum_info,p,&pixel);
2290 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
2291 p=PushQuantumPixel(quantum_info,p,&pixel);
2292 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
2293 p=PushQuantumPixel(quantum_info,p,&pixel);
2294 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
2295 p=PushQuantumPixel(quantum_info,p,&pixel);
2296 SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
2297 p=PushQuantumPixel(quantum_info,p,&pixel);
2298 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
2299 q+=GetPixelChannels(image);
2300 }
2301 break;
2302 }
2303 }
2304}
2305
2306static void ImportGrayQuantum(const Image *image,QuantumInfo *quantum_info,
2307 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
2308 Quantum *magick_restrict q)
2309{
2310 QuantumAny
2311 range;
2312
2313 ssize_t
2314 x;
2315
2316 ssize_t
2317 bit;
2318
2319 assert(image != (Image *) NULL);
2320 assert(image->signature == MagickCoreSignature);
2321 switch (quantum_info->depth)
2322 {
2323 case 1:
2324 {
2325 Quantum
2326 black,
2327 white;
2328
2329 black=(Quantum) 0;
2330 white=QuantumRange;
2331 if (quantum_info->min_is_white != MagickFalse)
2332 {
2333 black=QuantumRange;
2334 white=(Quantum) 0;
2335 }
2336 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
2337 {
2338 for (bit=0; bit < 8; bit++)
2339 {
2340 SetPixelGray(image,((*p) & (1 << (7-bit))) == 0 ? black : white,q);
2341 q+=GetPixelChannels(image);
2342 }
2343 p++;
2344 }
2345 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
2346 {
2347 SetPixelGray(image,((*p) & (0x01 << (7-bit))) == 0 ? black : white,q);
2348 q+=GetPixelChannels(image);
2349 }
2350 if (bit != 0)
2351 p++;
2352 break;
2353 }
2354 case 4:
2355 {
2356 unsigned char
2357 pixel;
2358
2359 range=GetQuantumRange(quantum_info->depth);
2360 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
2361 {
2362 pixel=(unsigned char) ((*p >> 4) & 0xf);
2363 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2364 q+=GetPixelChannels(image);
2365 pixel=(unsigned char) ((*p) & 0xf);
2366 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2367 p++;
2368 q+=GetPixelChannels(image);
2369 }
2370 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
2371 {
2372 pixel=(unsigned char) (*p++ >> 4);
2373 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2374 q+=GetPixelChannels(image);
2375 }
2376 break;
2377 }
2378 case 8:
2379 {
2380 unsigned char
2381 pixel;
2382
2383 if (quantum_info->min_is_white != MagickFalse)
2384 {
2385 for (x=0; x < (ssize_t) number_pixels; x++)
2386 {
2387 p=PushCharPixel(p,&pixel);
2388 SetPixelGray(image,QuantumRange-ScaleCharToQuantum(pixel),q);
2389 SetPixelAlpha(image,OpaqueAlpha,q);
2390 p+=quantum_info->pad;
2391 q+=GetPixelChannels(image);
2392 }
2393 break;
2394 }
2395 for (x=0; x < (ssize_t) number_pixels; x++)
2396 {
2397 p=PushCharPixel(p,&pixel);
2398 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
2399 SetPixelAlpha(image,OpaqueAlpha,q);
2400 p+=quantum_info->pad;
2401 q+=GetPixelChannels(image);
2402 }
2403 break;
2404 }
2405 case 10:
2406 {
2407 unsigned int
2408 pixel;
2409
2410 pixel=0;
2411 range=GetQuantumRange(quantum_info->depth);
2412 if (quantum_info->pack == MagickFalse)
2413 {
2414 if (image->endian == LSBEndian)
2415 {
2416 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
2417 {
2418 p=PushLongPixel(quantum_info->endian,p,&pixel);
2419 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
2420 range),q);
2421 q+=GetPixelChannels(image);
2422 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
2423 range),q);
2424 q+=GetPixelChannels(image);
2425 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
2426 range),q);
2427 p+=quantum_info->pad;
2428 q+=GetPixelChannels(image);
2429 }
2430 if (x++ < (ssize_t) (number_pixels-1))
2431 {
2432 p=PushLongPixel(quantum_info->endian,p,&pixel);
2433 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,
2434 range),q);
2435 q+=GetPixelChannels(image);
2436 }
2437 if (x++ < (ssize_t) number_pixels)
2438 {
2439 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
2440 range),q);
2441 q+=GetPixelChannels(image);
2442 }
2443 break;
2444 }
2445 for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
2446 {
2447 p=PushLongPixel(quantum_info->endian,p,&pixel);
2448 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),
2449 q);
2450 q+=GetPixelChannels(image);
2451 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
2452 q);
2453 q+=GetPixelChannels(image);
2454 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),
2455 q);
2456 p+=quantum_info->pad;
2457 q+=GetPixelChannels(image);
2458 }
2459 if (x++ < (ssize_t) (number_pixels-1))
2460 {
2461 p=PushLongPixel(quantum_info->endian,p,&pixel);
2462 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,
2463 range),q);
2464 q+=GetPixelChannels(image);
2465 }
2466 if (x++ < (ssize_t) number_pixels)
2467 {
2468 SetPixelGray(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,
2469 range),q);
2470 q+=GetPixelChannels(image);
2471 }
2472 break;
2473 }
2474 for (x=0; x < (ssize_t) number_pixels; x++)
2475 {
2476 p=PushQuantumPixel(quantum_info,p,&pixel);
2477 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2478 p+=quantum_info->pad;
2479 q+=GetPixelChannels(image);
2480 }
2481 break;
2482 }
2483 case 12:
2484 {
2485 range=GetQuantumRange(quantum_info->depth);
2486 if (quantum_info->pack == MagickFalse)
2487 {
2488 unsigned short
2489 pixel;
2490
2491 for (x=0; x < (ssize_t) (number_pixels-1); x+=2)
2492 {
2493 p=PushShortPixel(quantum_info->endian,p,&pixel);
2494 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2495 range),q);
2496 q+=GetPixelChannels(image);
2497 p=PushShortPixel(quantum_info->endian,p,&pixel);
2498 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2499 range),q);
2500 p+=quantum_info->pad;
2501 q+=GetPixelChannels(image);
2502 }
2503 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
2504 {
2505 p=PushShortPixel(quantum_info->endian,p,&pixel);
2506 SetPixelGray(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
2507 range),q);
2508 p+=quantum_info->pad;
2509 q+=GetPixelChannels(image);
2510 }
2511 if (bit != 0)
2512 p++;
2513 break;
2514 }
2515 else
2516 {
2517 unsigned int
2518 pixel;
2519
2520 for (x=0; x < (ssize_t) number_pixels; x++)
2521 {
2522 p=PushQuantumPixel(quantum_info,p,&pixel);
2523 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2524 p+=quantum_info->pad;
2525 q+=GetPixelChannels(image);
2526 }
2527 break;
2528 }
2529 }
2530 case 16:
2531 {
2532 unsigned short
2533 pixel;
2534
2535 if (quantum_info->min_is_white != MagickFalse)
2536 {
2537 for (x=0; x < (ssize_t) number_pixels; x++)
2538 {
2539 p=PushShortPixel(quantum_info->endian,p,&pixel);
2540 SetPixelGray(image,QuantumRange-ScaleShortToQuantum(pixel),q);
2541 p+=quantum_info->pad;
2542 q+=GetPixelChannels(image);
2543 }
2544 break;
2545 }
2546 if (quantum_info->format == FloatingPointQuantumFormat)
2547 {
2548 for (x=0; x < (ssize_t) number_pixels; x++)
2549 {
2550 p=PushShortPixel(quantum_info->endian,p,&pixel);
2551 SetPixelGray(image,ClampToQuantum((double) QuantumRange*(double)
2552 HalfToSinglePrecision(pixel)),q);
2553 p+=quantum_info->pad;
2554 q+=GetPixelChannels(image);
2555 }
2556 break;
2557 }
2558 if (quantum_info->format == SignedQuantumFormat)
2559 {
2560 for (x=0; x < (ssize_t) number_pixels; x++)
2561 {
2562 p=PushShortPixel(quantum_info->endian,p,&pixel);
2563 pixel=(unsigned short) (((unsigned int) pixel+32768) % 65536);
2564 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
2565 p+=quantum_info->pad;
2566 q+=GetPixelChannels(image);
2567 }
2568 break;
2569 }
2570 for (x=0; x < (ssize_t) number_pixels; x++)
2571 {
2572 p=PushShortPixel(quantum_info->endian,p,&pixel);
2573 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
2574 p+=quantum_info->pad;
2575 q+=GetPixelChannels(image);
2576 }
2577 break;
2578 }
2579 case 32:
2580 {
2581 if (quantum_info->format == FloatingPointQuantumFormat)
2582 {
2583 float
2584 pixel;
2585
2586 for (x=0; x < (ssize_t) number_pixels; x++)
2587 {
2588 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2589 SetPixelGray(image,ClampToQuantum(pixel),q);
2590 p+=quantum_info->pad;
2591 q+=GetPixelChannels(image);
2592 }
2593 break;
2594 }
2595 else
2596 {
2597 unsigned int
2598 pixel;
2599
2600 for (x=0; x < (ssize_t) number_pixels; x++)
2601 {
2602 p=PushLongPixel(quantum_info->endian,p,&pixel);
2603 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
2604 p+=quantum_info->pad;
2605 q+=GetPixelChannels(image);
2606 }
2607 break;
2608 }
2609 }
2610 case 24:
2611 {
2612 if (quantum_info->format == FloatingPointQuantumFormat)
2613 {
2614 float
2615 pixel;
2616
2617 for (x=0; x < (ssize_t) number_pixels; x++)
2618 {
2619 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2620 SetPixelGray(image,ClampToQuantum(pixel),q);
2621 p+=quantum_info->pad;
2622 q+=GetPixelChannels(image);
2623 }
2624 break;
2625 }
2626 magick_fallthrough;
2627 }
2628 case 64:
2629 {
2630 if (quantum_info->format == FloatingPointQuantumFormat)
2631 {
2632 double
2633 pixel;
2634
2635 for (x=0; x < (ssize_t) number_pixels; x++)
2636 {
2637 p=PushDoublePixel(quantum_info,p,&pixel);
2638 SetPixelGray(image,ClampToQuantum(pixel),q);
2639 p+=quantum_info->pad;
2640 q+=GetPixelChannels(image);
2641 }
2642 break;
2643 }
2644 magick_fallthrough;
2645 }
2646 default:
2647 {
2648 unsigned int
2649 pixel;
2650
2651 range=GetQuantumRange(quantum_info->depth);
2652 for (x=0; x < (ssize_t) number_pixels; x++)
2653 {
2654 p=PushQuantumPixel(quantum_info,p,&pixel);
2655 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2656 p+=quantum_info->pad;
2657 q+=GetPixelChannels(image);
2658 }
2659 break;
2660 }
2661 }
2662}
2663
2664static void ImportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
2665 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
2666 Quantum *magick_restrict q)
2667{
2668 QuantumAny
2669 range;
2670
2671 ssize_t
2672 x;
2673
2674 ssize_t
2675 bit;
2676
2677 assert(image != (Image *) NULL);
2678 assert(image->signature == MagickCoreSignature);
2679 switch (quantum_info->depth)
2680 {
2681 case 1:
2682 {
2683 unsigned char
2684 pixel;
2685
2686 bit=0;
2687 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2688 {
2689 for (bit=0; bit < 8; bit+=2)
2690 {
2691 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2692 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
2693 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2694 TransparentAlpha : OpaqueAlpha,q);
2695 q+=GetPixelChannels(image);
2696 }
2697 p++;
2698 }
2699 if ((number_pixels % 4) != 0)
2700 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
2701 {
2702 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
2703 SetPixelGray(image,(Quantum) (pixel != 0 ? 0 : QuantumRange),q);
2704 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
2705 TransparentAlpha : OpaqueAlpha,q);
2706 q+=GetPixelChannels(image);
2707 }
2708 if (bit != 0)
2709 p++;
2710 break;
2711 }
2712 case 4:
2713 {
2714 unsigned char
2715 pixel;
2716
2717 range=GetQuantumRange(quantum_info->depth);
2718 for (x=0; x < (ssize_t) number_pixels; x++)
2719 {
2720 pixel=(unsigned char) ((*p >> 4) & 0xf);
2721 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2722 pixel=(unsigned char) ((*p) & 0xf);
2723 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2724 p++;
2725 q+=GetPixelChannels(image);
2726 }
2727 break;
2728 }
2729 case 8:
2730 {
2731 unsigned char
2732 pixel;
2733
2734 for (x=0; x < (ssize_t) number_pixels; x++)
2735 {
2736 p=PushCharPixel(p,&pixel);
2737 SetPixelGray(image,ScaleCharToQuantum(pixel),q);
2738 p=PushCharPixel(p,&pixel);
2739 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
2740 p+=quantum_info->pad;
2741 q+=GetPixelChannels(image);
2742 }
2743 break;
2744 }
2745 case 10:
2746 {
2747 unsigned int
2748 pixel;
2749
2750 range=GetQuantumRange(quantum_info->depth);
2751 for (x=0; x < (ssize_t) number_pixels; x++)
2752 {
2753 p=PushQuantumPixel(quantum_info,p,&pixel);
2754 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2755 p=PushQuantumPixel(quantum_info,p,&pixel);
2756 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2757 p+=quantum_info->pad;
2758 q+=GetPixelChannels(image);
2759 }
2760 break;
2761 }
2762 case 12:
2763 {
2764 unsigned int
2765 pixel;
2766
2767 range=GetQuantumRange(quantum_info->depth);
2768 for (x=0; x < (ssize_t) number_pixels; x++)
2769 {
2770 p=PushQuantumPixel(quantum_info,p,&pixel);
2771 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2772 p=PushQuantumPixel(quantum_info,p,&pixel);
2773 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2774 p+=quantum_info->pad;
2775 q+=GetPixelChannels(image);
2776 }
2777 break;
2778 }
2779 case 16:
2780 {
2781 unsigned short
2782 pixel;
2783
2784 if (quantum_info->format == FloatingPointQuantumFormat)
2785 {
2786 for (x=0; x < (ssize_t) number_pixels; x++)
2787 {
2788 p=PushShortPixel(quantum_info->endian,p,&pixel);
2789 SetPixelGray(image,ClampToQuantum((double) QuantumRange*(double)
2790 HalfToSinglePrecision(pixel)),q);
2791 p=PushShortPixel(quantum_info->endian,p,&pixel);
2792 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
2793 HalfToSinglePrecision(pixel)),q);
2794 p+=quantum_info->pad;
2795 q+=GetPixelChannels(image);
2796 }
2797 break;
2798 }
2799 for (x=0; x < (ssize_t) number_pixels; x++)
2800 {
2801 p=PushShortPixel(quantum_info->endian,p,&pixel);
2802 SetPixelGray(image,ScaleShortToQuantum(pixel),q);
2803 p=PushShortPixel(quantum_info->endian,p,&pixel);
2804 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
2805 p+=quantum_info->pad;
2806 q+=GetPixelChannels(image);
2807 }
2808 break;
2809 }
2810 case 32:
2811 {
2812 if (quantum_info->format == FloatingPointQuantumFormat)
2813 {
2814 float
2815 pixel;
2816
2817 for (x=0; x < (ssize_t) number_pixels; x++)
2818 {
2819 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2820 SetPixelGray(image,ClampToQuantum(pixel),q);
2821 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2822 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2823 p+=quantum_info->pad;
2824 q+=GetPixelChannels(image);
2825 }
2826 break;
2827 }
2828 else
2829 {
2830 unsigned int
2831 pixel;
2832
2833 for (x=0; x < (ssize_t) number_pixels; x++)
2834 {
2835 p=PushLongPixel(quantum_info->endian,p,&pixel);
2836 SetPixelGray(image,ScaleLongToQuantum(pixel),q);
2837 p=PushLongPixel(quantum_info->endian,p,&pixel);
2838 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
2839 p+=quantum_info->pad;
2840 q+=GetPixelChannels(image);
2841 }
2842 break;
2843 }
2844 }
2845 case 24:
2846 {
2847 if (quantum_info->format == FloatingPointQuantumFormat)
2848 {
2849 float
2850 pixel;
2851
2852 for (x=0; x < (ssize_t) number_pixels; x++)
2853 {
2854 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2855 SetPixelGray(image,ClampToQuantum(pixel),q);
2856 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
2857 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2858 p+=quantum_info->pad;
2859 q+=GetPixelChannels(image);
2860 }
2861 break;
2862 }
2863 magick_fallthrough;
2864 }
2865 case 64:
2866 {
2867 if (quantum_info->format == FloatingPointQuantumFormat)
2868 {
2869 double
2870 pixel;
2871
2872 for (x=0; x < (ssize_t) number_pixels; x++)
2873 {
2874 p=PushDoublePixel(quantum_info,p,&pixel);
2875 SetPixelGray(image,ClampToQuantum(pixel),q);
2876 p=PushDoublePixel(quantum_info,p,&pixel);
2877 SetPixelAlpha(image,ClampToQuantum(pixel),q);
2878 p+=quantum_info->pad;
2879 q+=GetPixelChannels(image);
2880 }
2881 break;
2882 }
2883 magick_fallthrough;
2884 }
2885 default:
2886 {
2887 unsigned int
2888 pixel;
2889
2890 range=GetQuantumRange(quantum_info->depth);
2891 for (x=0; x < (ssize_t) number_pixels; x++)
2892 {
2893 p=PushQuantumPixel(quantum_info,p,&pixel);
2894 SetPixelGray(image,ScaleAnyToQuantum(pixel,range),q);
2895 p=PushQuantumPixel(quantum_info,p,&pixel);
2896 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
2897 p+=quantum_info->pad;
2898 q+=GetPixelChannels(image);
2899 }
2900 break;
2901 }
2902 }
2903}
2904
2905static void ImportGreenQuantum(const Image *image,QuantumInfo *quantum_info,
2906 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
2907 Quantum *magick_restrict q)
2908{
2909 QuantumAny
2910 range;
2911
2912 ssize_t
2913 x;
2914
2915 assert(image != (Image *) NULL);
2916 assert(image->signature == MagickCoreSignature);
2917 switch (quantum_info->depth)
2918 {
2919 case 8:
2920 {
2921 unsigned char
2922 pixel;
2923
2924 for (x=0; x < (ssize_t) number_pixels; x++)
2925 {
2926 p=PushCharPixel(p,&pixel);
2927 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
2928 p+=quantum_info->pad;
2929 q+=GetPixelChannels(image);
2930 }
2931 break;
2932 }
2933 case 16:
2934 {
2935 unsigned short
2936 pixel;
2937
2938 if (quantum_info->format == FloatingPointQuantumFormat)
2939 {
2940 for (x=0; x < (ssize_t) number_pixels; x++)
2941 {
2942 p=PushShortPixel(quantum_info->endian,p,&pixel);
2943 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
2944 HalfToSinglePrecision(pixel)),q);
2945 p+=quantum_info->pad;
2946 q+=GetPixelChannels(image);
2947 }
2948 break;
2949 }
2950 for (x=0; x < (ssize_t) number_pixels; x++)
2951 {
2952 p=PushShortPixel(quantum_info->endian,p,&pixel);
2953 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
2954 p+=quantum_info->pad;
2955 q+=GetPixelChannels(image);
2956 }
2957 break;
2958 }
2959 case 32:
2960 {
2961 if (quantum_info->format == FloatingPointQuantumFormat)
2962 {
2963 float
2964 pixel;
2965
2966 for (x=0; x < (ssize_t) number_pixels; x++)
2967 {
2968 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
2969 SetPixelGreen(image,ClampToQuantum(pixel),q);
2970 p+=quantum_info->pad;
2971 q+=GetPixelChannels(image);
2972 }
2973 break;
2974 }
2975 else
2976 {
2977 unsigned int
2978 pixel;
2979
2980 for (x=0; x < (ssize_t) number_pixels; x++)
2981 {
2982 p=PushLongPixel(quantum_info->endian,p,&pixel);
2983 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
2984 p+=quantum_info->pad;
2985 q+=GetPixelChannels(image);
2986 }
2987 break;
2988 }
2989 }
2990 case 24:
2991 {
2992 if (quantum_info->format == FloatingPointQuantumFormat)
2993 {
2994 float
2995 pixel;
2996
2997 for (x=0; x < (ssize_t) number_pixels; x++)
2998 {
2999 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3000 SetPixelGreen(image,ClampToQuantum(pixel),q);
3001 p+=quantum_info->pad;
3002 q+=GetPixelChannels(image);
3003 }
3004 break;
3005 }
3006 magick_fallthrough;
3007 }
3008 case 64:
3009 {
3010 if (quantum_info->format == FloatingPointQuantumFormat)
3011 {
3012 double
3013 pixel;
3014
3015 for (x=0; x < (ssize_t) number_pixels; x++)
3016 {
3017 p=PushDoublePixel(quantum_info,p,&pixel);
3018 SetPixelGreen(image,ClampToQuantum(pixel),q);
3019 p+=quantum_info->pad;
3020 q+=GetPixelChannels(image);
3021 }
3022 break;
3023 }
3024 magick_fallthrough;
3025 }
3026 default:
3027 {
3028 unsigned int
3029 pixel;
3030
3031 range=GetQuantumRange(quantum_info->depth);
3032 for (x=0; x < (ssize_t) number_pixels; x++)
3033 {
3034 p=PushQuantumPixel(quantum_info,p,&pixel);
3035 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3036 p+=quantum_info->pad;
3037 q+=GetPixelChannels(image);
3038 }
3039 break;
3040 }
3041 }
3042}
3043
3044static void ImportIndexQuantum(const Image *image,QuantumInfo *quantum_info,
3045 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3046 Quantum *magick_restrict q,ExceptionInfo *exception)
3047{
3048 MagickBooleanType
3049 range_exception;
3050
3051 ssize_t
3052 x;
3053
3054 ssize_t
3055 bit;
3056
3057 if (image->storage_class != PseudoClass)
3058 {
3059 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3060 "ColormappedImageRequired","`%s'",image->filename);
3061 return;
3062 }
3063 range_exception=MagickFalse;
3064 switch (quantum_info->depth)
3065 {
3066 case 1:
3067 {
3068 unsigned char
3069 pixel;
3070
3071 for (x=0; x < ((ssize_t) number_pixels-7); x+=8)
3072 {
3073 for (bit=0; bit < 8; bit++)
3074 {
3075 if (quantum_info->min_is_white == MagickFalse)
3076 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
3077 0x00 : 0x01);
3078 else
3079 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
3080 0x00 : 0x01);
3081 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),
3082 q);
3083 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3084 GetPixelIndex(image,q),q);
3085 q+=GetPixelChannels(image);
3086 }
3087 p++;
3088 }
3089 for (bit=0; bit < (ssize_t) (number_pixels % 8); bit++)
3090 {
3091 if (quantum_info->min_is_white == MagickFalse)
3092 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
3093 else
3094 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
3095 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3096 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3097 GetPixelIndex(image,q),q);
3098 q+=GetPixelChannels(image);
3099 }
3100 break;
3101 }
3102 case 4:
3103 {
3104 unsigned char
3105 pixel;
3106
3107 for (x=0; x < ((ssize_t) number_pixels-1); x+=2)
3108 {
3109 pixel=(unsigned char) ((*p >> 4) & 0xf);
3110 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3111 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3112 GetPixelIndex(image,q),q);
3113 q+=GetPixelChannels(image);
3114 pixel=(unsigned char) ((*p) & 0xf);
3115 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3116 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3117 GetPixelIndex(image,q),q);
3118 p++;
3119 q+=GetPixelChannels(image);
3120 }
3121 for (bit=0; bit < (ssize_t) (number_pixels % 2); bit++)
3122 {
3123 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
3124 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3125 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3126 GetPixelIndex(image,q),q);
3127 q+=GetPixelChannels(image);
3128 }
3129 break;
3130 }
3131 case 8:
3132 {
3133 unsigned char
3134 pixel;
3135
3136 for (x=0; x < (ssize_t) number_pixels; x++)
3137 {
3138 p=PushCharPixel(p,&pixel);
3139 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3140 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3141 GetPixelIndex(image,q),q);
3142 p+=quantum_info->pad;
3143 q+=GetPixelChannels(image);
3144 }
3145 break;
3146 }
3147 case 16:
3148 {
3149 unsigned short
3150 pixel;
3151
3152 if (quantum_info->format == FloatingPointQuantumFormat)
3153 {
3154 for (x=0; x < (ssize_t) number_pixels; x++)
3155 {
3156 p=PushShortPixel(quantum_info->endian,p,&pixel);
3157 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3158 ClampToQuantum((double) QuantumRange*(double)
3159 HalfToSinglePrecision(pixel)),&range_exception),q);
3160 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3161 GetPixelIndex(image,q),q);
3162 p+=quantum_info->pad;
3163 q+=GetPixelChannels(image);
3164 }
3165 break;
3166 }
3167 for (x=0; x < (ssize_t) number_pixels; x++)
3168 {
3169 p=PushShortPixel(quantum_info->endian,p,&pixel);
3170 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3171 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3172 GetPixelIndex(image,q),q);
3173 p+=quantum_info->pad;
3174 q+=GetPixelChannels(image);
3175 }
3176 break;
3177 }
3178 case 32:
3179 {
3180 if (quantum_info->format == FloatingPointQuantumFormat)
3181 {
3182 float
3183 pixel;
3184
3185 for (x=0; x < (ssize_t) number_pixels; x++)
3186 {
3187 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3188 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3189 ClampToQuantum(pixel),&range_exception),q);
3190 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3191 GetPixelIndex(image,q),q);
3192 p+=quantum_info->pad;
3193 q+=GetPixelChannels(image);
3194 }
3195 break;
3196 }
3197 else
3198 {
3199 unsigned int
3200 pixel;
3201
3202 for (x=0; x < (ssize_t) number_pixels; x++)
3203 {
3204 p=PushLongPixel(quantum_info->endian,p,&pixel);
3205 SetPixelIndex(image,PushColormapIndex(image,pixel,
3206 &range_exception),q);
3207 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3208 GetPixelIndex(image,q),q);
3209 p+=quantum_info->pad;
3210 q+=GetPixelChannels(image);
3211 }
3212 break;
3213 }
3214 }
3215 case 24:
3216 {
3217 if (quantum_info->format == FloatingPointQuantumFormat)
3218 {
3219 float
3220 pixel;
3221
3222 for (x=0; x < (ssize_t) number_pixels; x++)
3223 {
3224 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3225 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3226 ClampToQuantum(pixel),&range_exception),q);
3227 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3228 GetPixelIndex(image,q),q);
3229 p+=quantum_info->pad;
3230 q+=GetPixelChannels(image);
3231 }
3232 break;
3233 }
3234 magick_fallthrough;
3235 }
3236 case 64:
3237 {
3238 if (quantum_info->format == FloatingPointQuantumFormat)
3239 {
3240 double
3241 pixel;
3242
3243 for (x=0; x < (ssize_t) number_pixels; x++)
3244 {
3245 p=PushDoublePixel(quantum_info,p,&pixel);
3246 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3247 ClampToQuantum(pixel),&range_exception),q);
3248 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3249 GetPixelIndex(image,q),q);
3250 p+=quantum_info->pad;
3251 q+=GetPixelChannels(image);
3252 }
3253 break;
3254 }
3255 magick_fallthrough;
3256 }
3257 default:
3258 {
3259 unsigned int
3260 pixel;
3261
3262 for (x=0; x < (ssize_t) number_pixels; x++)
3263 {
3264 p=PushQuantumPixel(quantum_info,p,&pixel);
3265 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3266 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3267 GetPixelIndex(image,q),q);
3268 p+=quantum_info->pad;
3269 q+=GetPixelChannels(image);
3270 }
3271 break;
3272 }
3273 }
3274 if (range_exception != MagickFalse)
3275 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3276 "InvalidColormapIndex","`%s'",image->filename);
3277}
3278
3279static void ImportIndexAlphaQuantum(const Image *image,
3280 QuantumInfo *quantum_info,const MagickSizeType number_pixels,
3281 const unsigned char *magick_restrict p,Quantum *magick_restrict q,
3282 ExceptionInfo *exception)
3283{
3284 MagickBooleanType
3285 range_exception;
3286
3287 QuantumAny
3288 range;
3289
3290 ssize_t
3291 x;
3292
3293 ssize_t
3294 bit;
3295
3296 if (image->storage_class != PseudoClass)
3297 {
3298 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3299 "ColormappedImageRequired","`%s'",image->filename);
3300 return;
3301 }
3302 range_exception=MagickFalse;
3303 switch (quantum_info->depth)
3304 {
3305 case 1:
3306 {
3307 unsigned char
3308 pixel;
3309
3310 for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
3311 {
3312 for (bit=0; bit < 8; bit+=2)
3313 {
3314 if (quantum_info->min_is_white == MagickFalse)
3315 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
3316 else
3317 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
3318 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
3319 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
3320 TransparentAlpha : OpaqueAlpha,q);
3321 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
3322 q+=GetPixelChannels(image);
3323 }
3324 }
3325 if ((number_pixels % 4) != 0)
3326 for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
3327 {
3328 if (quantum_info->min_is_white == MagickFalse)
3329 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ? 0x00 : 0x01);
3330 else
3331 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
3332 SetPixelIndex(image,(Quantum) (pixel == 0 ? 0 : 1),q);
3333 SetPixelGray(image,(Quantum) (pixel == 0 ? 0 : QuantumRange),q);
3334 SetPixelAlpha(image,((*p) & (1UL << (unsigned char) (6-bit))) == 0 ?
3335 TransparentAlpha : OpaqueAlpha,q);
3336 q+=GetPixelChannels(image);
3337 }
3338 break;
3339 }
3340 case 4:
3341 {
3342 unsigned char
3343 pixel;
3344
3345 range=GetQuantumRange(quantum_info->depth);
3346 for (x=0; x < (ssize_t) number_pixels; x++)
3347 {
3348 pixel=(unsigned char) ((*p >> 4) & 0xf);
3349 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3350 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3351 GetPixelIndex(image,q),q);
3352 pixel=(unsigned char) ((*p) & 0xf);
3353 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
3354 p++;
3355 q+=GetPixelChannels(image);
3356 }
3357 break;
3358 }
3359 case 8:
3360 {
3361 unsigned char
3362 pixel;
3363
3364 for (x=0; x < (ssize_t) number_pixels; x++)
3365 {
3366 p=PushCharPixel(p,&pixel);
3367 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3368 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3369 GetPixelIndex(image,q),q);
3370 p=PushCharPixel(p,&pixel);
3371 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
3372 p+=quantum_info->pad;
3373 q+=GetPixelChannels(image);
3374 }
3375 break;
3376 }
3377 case 16:
3378 {
3379 unsigned short
3380 pixel;
3381
3382 if (quantum_info->format == FloatingPointQuantumFormat)
3383 {
3384 for (x=0; x < (ssize_t) number_pixels; x++)
3385 {
3386 p=PushShortPixel(quantum_info->endian,p,&pixel);
3387 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3388 ClampToQuantum((double) QuantumRange*(double)
3389 HalfToSinglePrecision(pixel)),&range_exception),q);
3390 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3391 GetPixelIndex(image,q),q);
3392 p=PushShortPixel(quantum_info->endian,p,&pixel);
3393 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
3394 HalfToSinglePrecision(pixel)),q);
3395 p+=quantum_info->pad;
3396 q+=GetPixelChannels(image);
3397 }
3398 break;
3399 }
3400 for (x=0; x < (ssize_t) number_pixels; x++)
3401 {
3402 p=PushShortPixel(quantum_info->endian,p,&pixel);
3403 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3404 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3405 GetPixelIndex(image,q),q);
3406 p=PushShortPixel(quantum_info->endian,p,&pixel);
3407 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
3408 p+=quantum_info->pad;
3409 q+=GetPixelChannels(image);
3410 }
3411 break;
3412 }
3413 case 32:
3414 {
3415 if (quantum_info->format == FloatingPointQuantumFormat)
3416 {
3417 float
3418 pixel;
3419
3420 for (x=0; x < (ssize_t) number_pixels; x++)
3421 {
3422 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3423 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3424 ClampToQuantum(pixel),&range_exception),q);
3425 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3426 GetPixelIndex(image,q),q);
3427 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3428 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3429 p+=quantum_info->pad;
3430 q+=GetPixelChannels(image);
3431 }
3432 break;
3433 }
3434 else
3435 {
3436 unsigned int
3437 pixel;
3438
3439 for (x=0; x < (ssize_t) number_pixels; x++)
3440 {
3441 p=PushLongPixel(quantum_info->endian,p,&pixel);
3442 SetPixelIndex(image,PushColormapIndex(image,pixel,
3443 &range_exception),q);
3444 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3445 GetPixelIndex(image,q),q);
3446 p=PushLongPixel(quantum_info->endian,p,&pixel);
3447 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
3448 p+=quantum_info->pad;
3449 q+=GetPixelChannels(image);
3450 }
3451 break;
3452 }
3453 }
3454 case 24:
3455 {
3456 if (quantum_info->format == FloatingPointQuantumFormat)
3457 {
3458 float
3459 pixel;
3460
3461 for (x=0; x < (ssize_t) number_pixels; x++)
3462 {
3463 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3464 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3465 ClampToQuantum(pixel),&range_exception),q);
3466 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3467 GetPixelIndex(image,q),q);
3468 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3469 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3470 p+=quantum_info->pad;
3471 q+=GetPixelChannels(image);
3472 }
3473 break;
3474 }
3475 magick_fallthrough;
3476 }
3477 case 64:
3478 {
3479 if (quantum_info->format == FloatingPointQuantumFormat)
3480 {
3481 double
3482 pixel;
3483
3484 for (x=0; x < (ssize_t) number_pixels; x++)
3485 {
3486 p=PushDoublePixel(quantum_info,p,&pixel);
3487 SetPixelIndex(image,PushColormapIndex(image,(size_t)
3488 ClampToQuantum(pixel),&range_exception),q);
3489 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3490 GetPixelIndex(image,q),q);
3491 p=PushDoublePixel(quantum_info,p,&pixel);
3492 SetPixelAlpha(image,ClampToQuantum(pixel),q);
3493 p+=quantum_info->pad;
3494 q+=GetPixelChannels(image);
3495 }
3496 break;
3497 }
3498 magick_fallthrough;
3499 }
3500 default:
3501 {
3502 unsigned int
3503 pixel;
3504
3505 range=GetQuantumRange(quantum_info->depth);
3506 for (x=0; x < (ssize_t) number_pixels; x++)
3507 {
3508 p=PushQuantumPixel(quantum_info,p,&pixel);
3509 SetPixelIndex(image,PushColormapIndex(image,pixel,&range_exception),q);
3510 SetPixelViaPixelInfo(image,image->colormap+(ssize_t)
3511 GetPixelIndex(image,q),q);
3512 p=PushQuantumPixel(quantum_info,p,&pixel);
3513 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
3514 p+=quantum_info->pad;
3515 q+=GetPixelChannels(image);
3516 }
3517 break;
3518 }
3519 }
3520 if (range_exception != MagickFalse)
3521 (void) ThrowMagickException(exception,GetMagickModule(),CorruptImageError,
3522 "InvalidColormapIndex","`%s'",image->filename);
3523}
3524
3525static void ImportMultispectralQuantum(const Image *image,
3526 QuantumInfo *quantum_info,const MagickSizeType number_pixels,
3527 const unsigned char *magick_restrict p,Quantum *magick_restrict q,
3528 ExceptionInfo *exception)
3529{
3530 QuantumAny
3531 range;
3532
3533 ssize_t
3534 i,
3535 x;
3536
3537 if (image->number_meta_channels == 0)
3538 {
3539 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
3540 "MultispectralImageRequired","`%s'",image->filename);
3541 return;
3542 }
3543 switch (quantum_info->depth)
3544 {
3545 case 8:
3546 {
3547 unsigned char
3548 pixel;
3549
3550 for (x=0; x < (ssize_t) number_pixels; x++)
3551 {
3552 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3553 {
3554 p=PushCharPixel(p,&pixel);
3555 q[i]=ScaleCharToQuantum(pixel);
3556 }
3557 p+=quantum_info->pad;
3558 q+=GetPixelChannels(image);
3559 }
3560 break;
3561 }
3562 case 16:
3563 {
3564 unsigned short
3565 pixel;
3566
3567 if (quantum_info->format == FloatingPointQuantumFormat)
3568 {
3569 for (x=0; x < (ssize_t) number_pixels; x++)
3570 {
3571 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3572 {
3573 p=PushShortPixel(quantum_info->endian,p,&pixel);
3574 q[i]=ClampToQuantum((double) QuantumRange*(double)HalfToSinglePrecision(pixel));
3575 }
3576 p+=quantum_info->pad;
3577 q+=GetPixelChannels(image);
3578 }
3579 break;
3580 }
3581 for (x=0; x < (ssize_t) number_pixels; x++)
3582 {
3583 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3584 {
3585 p=PushShortPixel(quantum_info->endian,p,&pixel);
3586 q[i]=ScaleShortToQuantum(pixel);
3587 }
3588 p+=quantum_info->pad;
3589 q+=GetPixelChannels(image);
3590 }
3591 break;
3592 }
3593 case 32:
3594 {
3595 if (quantum_info->format == FloatingPointQuantumFormat)
3596 {
3597 float
3598 pixel;
3599
3600 for (x=0; x < (ssize_t) number_pixels; x++)
3601 {
3602 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3603 {
3604 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3605 q[i]=ClampToQuantum(pixel);
3606 }
3607 p+=quantum_info->pad;
3608 q+=GetPixelChannels(image);
3609 }
3610 break;
3611 }
3612 else
3613 {
3614 unsigned int
3615 pixel;
3616
3617 for (x=0; x < (ssize_t) number_pixels; x++)
3618 {
3619 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3620 {
3621 p=PushLongPixel(quantum_info->endian,p,&pixel);
3622 q[i]=ScaleLongToQuantum(pixel);
3623 }
3624 p+=quantum_info->pad;
3625 q+=GetPixelChannels(image);
3626 }
3627 break;
3628 }
3629 }
3630 case 24:
3631 {
3632 if (quantum_info->format == FloatingPointQuantumFormat)
3633 {
3634 float
3635 pixel;
3636
3637 for (x=0; x < (ssize_t) number_pixels; x++)
3638 {
3639 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3640 {
3641 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3642 q[i]=ClampToQuantum(pixel);
3643 }
3644 p+=quantum_info->pad;
3645 q+=GetPixelChannels(image);
3646 }
3647 break;
3648 }
3649 magick_fallthrough;
3650 }
3651 case 64:
3652 {
3653 if (quantum_info->format == FloatingPointQuantumFormat)
3654 {
3655 double
3656 pixel;
3657
3658 for (x=0; x < (ssize_t) number_pixels; x++)
3659 {
3660 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3661 {
3662 p=PushDoublePixel(quantum_info,p,&pixel);
3663 q[i]=ClampToQuantum(pixel);
3664 }
3665 p+=quantum_info->pad;
3666 q+=GetPixelChannels(image);
3667 }
3668 break;
3669 }
3670 magick_fallthrough;
3671 }
3672 default:
3673 {
3674 unsigned int
3675 pixel = 0;
3676
3677 range=GetQuantumRange(quantum_info->depth);
3678 for (x=0; x < (ssize_t) number_pixels; x++)
3679 {
3680 for (i=0; i < (ssize_t) GetImageChannels(image); i++)
3681 {
3682 p=PushQuantumPixel(quantum_info,p,&pixel);
3683 q[i]=ScaleAnyToQuantum(pixel,range);
3684 }
3685 q+=GetPixelChannels(image);
3686 }
3687 break;
3688 }
3689 }
3690}
3691
3692static void ImportOpacityQuantum(const Image *image,QuantumInfo *quantum_info,
3693 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3694 Quantum *magick_restrict q)
3695{
3696 QuantumAny
3697 range;
3698
3699 ssize_t
3700 x;
3701
3702 assert(image != (Image *) NULL);
3703 assert(image->signature == MagickCoreSignature);
3704 switch (quantum_info->depth)
3705 {
3706 case 8:
3707 {
3708 unsigned char
3709 pixel;
3710
3711 for (x=0; x < (ssize_t) number_pixels; x++)
3712 {
3713 p=PushCharPixel(p,&pixel);
3714 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
3715 p+=quantum_info->pad;
3716 q+=GetPixelChannels(image);
3717 }
3718 break;
3719 }
3720 case 16:
3721 {
3722 unsigned short
3723 pixel;
3724
3725 if (quantum_info->format == FloatingPointQuantumFormat)
3726 {
3727 for (x=0; x < (ssize_t) number_pixels; x++)
3728 {
3729 p=PushShortPixel(quantum_info->endian,p,&pixel);
3730 SetPixelOpacity(image,ClampToQuantum((double) QuantumRange*(double)
3731 HalfToSinglePrecision(pixel)),q);
3732 p+=quantum_info->pad;
3733 q+=GetPixelChannels(image);
3734 }
3735 break;
3736 }
3737 for (x=0; x < (ssize_t) number_pixels; x++)
3738 {
3739 p=PushShortPixel(quantum_info->endian,p,&pixel);
3740 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
3741 p+=quantum_info->pad;
3742 q+=GetPixelChannels(image);
3743 }
3744 break;
3745 }
3746 case 32:
3747 {
3748 if (quantum_info->format == FloatingPointQuantumFormat)
3749 {
3750 float
3751 pixel;
3752
3753 for (x=0; x < (ssize_t) number_pixels; x++)
3754 {
3755 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3756 SetPixelOpacity(image,ClampToQuantum(pixel),q);
3757 p+=quantum_info->pad;
3758 q+=GetPixelChannels(image);
3759 }
3760 break;
3761 }
3762 else
3763 {
3764 unsigned int
3765 pixel;
3766
3767 for (x=0; x < (ssize_t) number_pixels; x++)
3768 {
3769 p=PushLongPixel(quantum_info->endian,p,&pixel);
3770 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
3771 p+=quantum_info->pad;
3772 q+=GetPixelChannels(image);
3773 }
3774 break;
3775 }
3776 }
3777 case 24:
3778 {
3779 if (quantum_info->format == FloatingPointQuantumFormat)
3780 {
3781 float
3782 pixel;
3783
3784 for (x=0; x < (ssize_t) number_pixels; x++)
3785 {
3786 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3787 SetPixelOpacity(image,ClampToQuantum(pixel),q);
3788 p+=quantum_info->pad;
3789 q+=GetPixelChannels(image);
3790 }
3791 break;
3792 }
3793 magick_fallthrough;
3794 }
3795 case 64:
3796 {
3797 if (quantum_info->format == FloatingPointQuantumFormat)
3798 {
3799 double
3800 pixel;
3801
3802 for (x=0; x < (ssize_t) number_pixels; x++)
3803 {
3804 p=PushDoublePixel(quantum_info,p,&pixel);
3805 SetPixelOpacity(image,ClampToQuantum(pixel),q);
3806 p+=quantum_info->pad;
3807 q+=GetPixelChannels(image);
3808 }
3809 break;
3810 }
3811 magick_fallthrough;
3812 }
3813 default:
3814 {
3815 unsigned int
3816 pixel;
3817
3818 range=GetQuantumRange(quantum_info->depth);
3819 for (x=0; x < (ssize_t) number_pixels; x++)
3820 {
3821 p=PushQuantumPixel(quantum_info,p,&pixel);
3822 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
3823 p+=quantum_info->pad;
3824 q+=GetPixelChannels(image);
3825 }
3826 break;
3827 }
3828 }
3829}
3830
3831static void ImportRedQuantum(const Image *image,QuantumInfo *quantum_info,
3832 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3833 Quantum *magick_restrict q)
3834{
3835 QuantumAny
3836 range;
3837
3838 ssize_t
3839 x;
3840
3841 assert(image != (Image *) NULL);
3842 assert(image->signature == MagickCoreSignature);
3843 switch (quantum_info->depth)
3844 {
3845 case 8:
3846 {
3847 unsigned char
3848 pixel;
3849
3850 for (x=0; x < (ssize_t) number_pixels; x++)
3851 {
3852 p=PushCharPixel(p,&pixel);
3853 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3854 p+=quantum_info->pad;
3855 q+=GetPixelChannels(image);
3856 }
3857 break;
3858 }
3859 case 16:
3860 {
3861 unsigned short
3862 pixel;
3863
3864 if (quantum_info->format == FloatingPointQuantumFormat)
3865 {
3866 for (x=0; x < (ssize_t) number_pixels; x++)
3867 {
3868 p=PushShortPixel(quantum_info->endian,p,&pixel);
3869 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
3870 HalfToSinglePrecision(pixel)),q);
3871 p+=quantum_info->pad;
3872 q+=GetPixelChannels(image);
3873 }
3874 break;
3875 }
3876 for (x=0; x < (ssize_t) number_pixels; x++)
3877 {
3878 p=PushShortPixel(quantum_info->endian,p,&pixel);
3879 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3880 p+=quantum_info->pad;
3881 q+=GetPixelChannels(image);
3882 }
3883 break;
3884 }
3885 case 32:
3886 {
3887 if (quantum_info->format == FloatingPointQuantumFormat)
3888 {
3889 float
3890 pixel;
3891
3892 for (x=0; x < (ssize_t) number_pixels; x++)
3893 {
3894 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3895 SetPixelRed(image,ClampToQuantum(pixel),q);
3896 p+=quantum_info->pad;
3897 q+=GetPixelChannels(image);
3898 }
3899 break;
3900 }
3901 else
3902 {
3903 unsigned int
3904 pixel;
3905
3906 for (x=0; x < (ssize_t) number_pixels; x++)
3907 {
3908 p=PushLongPixel(quantum_info->endian,p,&pixel);
3909 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3910 p+=quantum_info->pad;
3911 q+=GetPixelChannels(image);
3912 }
3913 break;
3914 }
3915 }
3916 case 24:
3917 {
3918 if (quantum_info->format == FloatingPointQuantumFormat)
3919 {
3920 float
3921 pixel;
3922
3923 for (x=0; x < (ssize_t) number_pixels; x++)
3924 {
3925 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3926 SetPixelRed(image,ClampToQuantum(pixel),q);
3927 p+=quantum_info->pad;
3928 q+=GetPixelChannels(image);
3929 }
3930 break;
3931 }
3932 magick_fallthrough;
3933 }
3934 case 64:
3935 {
3936 if (quantum_info->format == FloatingPointQuantumFormat)
3937 {
3938 double
3939 pixel;
3940
3941 for (x=0; x < (ssize_t) number_pixels; x++)
3942 {
3943 p=PushDoublePixel(quantum_info,p,&pixel);
3944 SetPixelRed(image,ClampToQuantum(pixel),q);
3945 p+=quantum_info->pad;
3946 q+=GetPixelChannels(image);
3947 }
3948 break;
3949 }
3950 magick_fallthrough;
3951 }
3952 default:
3953 {
3954 unsigned int
3955 pixel;
3956
3957 range=GetQuantumRange(quantum_info->depth);
3958 for (x=0; x < (ssize_t) number_pixels; x++)
3959 {
3960 p=PushQuantumPixel(quantum_info,p,&pixel);
3961 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3962 p+=quantum_info->pad;
3963 q+=GetPixelChannels(image);
3964 }
3965 break;
3966 }
3967 }
3968}
3969
3970static void ImportRGBQuantum(const Image *image,QuantumInfo *quantum_info,
3971 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3972 Quantum *magick_restrict q)
3973{
3974 QuantumAny
3975 range;
3976
3977 ssize_t
3978 x;
3979
3980 ssize_t
3981 bit;
3982
3983 assert(image != (Image *) NULL);
3984 assert(image->signature == MagickCoreSignature);
3985 switch (quantum_info->depth)
3986 {
3987 case 8:
3988 {
3989 unsigned char
3990 pixel;
3991
3992 for (x=0; x < (ssize_t) number_pixels; x++)
3993 {
3994 p=PushCharPixel(p,&pixel);
3995 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3996 p=PushCharPixel(p,&pixel);
3997 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
3998 p=PushCharPixel(p,&pixel);
3999 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
4000 SetPixelAlpha(image,OpaqueAlpha,q);
4001 p+=quantum_info->pad;
4002 q+=GetPixelChannels(image);
4003 }
4004 break;
4005 }
4006 case 10:
4007 {
4008 unsigned int
4009 pixel;
4010
4011 range=GetQuantumRange(quantum_info->depth);
4012 if (quantum_info->pack == MagickFalse)
4013 {
4014 for (x=0; x < (ssize_t) number_pixels; x++)
4015 {
4016 p=PushLongPixel(quantum_info->endian,p,&pixel);
4017 SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
4018 SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
4019 q);
4020 SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
4021 p+=quantum_info->pad;
4022 q+=GetPixelChannels(image);
4023 }
4024 break;
4025 }
4026 if (quantum_info->quantum == 32U)
4027 {
4028 for (x=0; x < (ssize_t) number_pixels; x++)
4029 {
4030 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4031 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4032 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4033 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4034 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4035 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4036 q+=GetPixelChannels(image);
4037 }
4038 break;
4039 }
4040 for (x=0; x < (ssize_t) number_pixels; x++)
4041 {
4042 p=PushQuantumPixel(quantum_info,p,&pixel);
4043 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4044 p=PushQuantumPixel(quantum_info,p,&pixel);
4045 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4046 p=PushQuantumPixel(quantum_info,p,&pixel);
4047 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4048 q+=GetPixelChannels(image);
4049 }
4050 break;
4051 }
4052 case 12:
4053 {
4054 range=GetQuantumRange(quantum_info->depth);
4055 if (quantum_info->pack == MagickFalse)
4056 {
4057 unsigned short
4058 pixel;
4059
4060 for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
4061 {
4062 p=PushShortPixel(quantum_info->endian,p,&pixel);
4063 switch (x % 3)
4064 {
4065 default:
4066 case 0:
4067 {
4068 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4069 range),q);
4070 break;
4071 }
4072 case 1:
4073 {
4074 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4075 range),q);
4076 break;
4077 }
4078 case 2:
4079 {
4080 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4081 range),q);
4082 q+=GetPixelChannels(image);
4083 break;
4084 }
4085 }
4086 p=PushShortPixel(quantum_info->endian,p,&pixel);
4087 switch ((x+1) % 3)
4088 {
4089 default:
4090 case 0:
4091 {
4092 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4093 range),q);
4094 break;
4095 }
4096 case 1:
4097 {
4098 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4099 range),q);
4100 break;
4101 }
4102 case 2:
4103 {
4104 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4105 range),q);
4106 q+=GetPixelChannels(image);
4107 break;
4108 }
4109 }
4110 p+=quantum_info->pad;
4111 }
4112 for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
4113 {
4114 p=PushShortPixel(quantum_info->endian,p,&pixel);
4115 switch ((x+bit) % 3)
4116 {
4117 default:
4118 case 0:
4119 {
4120 SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4121 range),q);
4122 break;
4123 }
4124 case 1:
4125 {
4126 SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4127 range),q);
4128 break;
4129 }
4130 case 2:
4131 {
4132 SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
4133 range),q);
4134 q+=GetPixelChannels(image);
4135 break;
4136 }
4137 }
4138 p+=quantum_info->pad;
4139 }
4140 if (bit != 0)
4141 p++;
4142 break;
4143 }
4144 else
4145 {
4146 unsigned int
4147 pixel;
4148
4149 if (quantum_info->quantum == 32U)
4150 {
4151 for (x=0; x < (ssize_t) number_pixels; x++)
4152 {
4153 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4154 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4155 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4156 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4157 p=PushQuantumLongPixel(quantum_info,p,&pixel);
4158 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4159 q+=GetPixelChannels(image);
4160 }
4161 break;
4162 }
4163 for (x=0; x < (ssize_t) number_pixels; x++)
4164 {
4165 p=PushQuantumPixel(quantum_info,p,&pixel);
4166 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4167 p=PushQuantumPixel(quantum_info,p,&pixel);
4168 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4169 p=PushQuantumPixel(quantum_info,p,&pixel);
4170 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4171 q+=GetPixelChannels(image);
4172 }
4173 break;
4174 }
4175 }
4176 case 16:
4177 {
4178 unsigned short
4179 pixel;
4180
4181 if (quantum_info->format == FloatingPointQuantumFormat)
4182 {
4183 for (x=0; x < (ssize_t) number_pixels; x++)
4184 {
4185 p=PushShortPixel(quantum_info->endian,p,&pixel);
4186 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
4187 HalfToSinglePrecision(pixel)),q);
4188 p=PushShortPixel(quantum_info->endian,p,&pixel);
4189 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
4190 HalfToSinglePrecision(pixel)),q);
4191 p=PushShortPixel(quantum_info->endian,p,&pixel);
4192 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
4193 HalfToSinglePrecision(pixel)),q);
4194 p+=quantum_info->pad;
4195 q+=GetPixelChannels(image);
4196 }
4197 break;
4198 }
4199 for (x=0; x < (ssize_t) number_pixels; x++)
4200 {
4201 p=PushShortPixel(quantum_info->endian,p,&pixel);
4202 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4203 p=PushShortPixel(quantum_info->endian,p,&pixel);
4204 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4205 p=PushShortPixel(quantum_info->endian,p,&pixel);
4206 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4207 p+=quantum_info->pad;
4208 q+=GetPixelChannels(image);
4209 }
4210 break;
4211 }
4212 case 32:
4213 {
4214 if (quantum_info->format == FloatingPointQuantumFormat)
4215 {
4216 float
4217 pixel;
4218
4219 for (x=0; x < (ssize_t) number_pixels; x++)
4220 {
4221 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4222 SetPixelRed(image,ClampToQuantum(pixel),q);
4223 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4224 SetPixelGreen(image,ClampToQuantum(pixel),q);
4225 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4226 SetPixelBlue(image,ClampToQuantum(pixel),q);
4227 p+=quantum_info->pad;
4228 q+=GetPixelChannels(image);
4229 }
4230 break;
4231 }
4232 else
4233 {
4234 unsigned int
4235 pixel;
4236
4237 for (x=0; x < (ssize_t) number_pixels; x++)
4238 {
4239 p=PushLongPixel(quantum_info->endian,p,&pixel);
4240 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4241 p=PushLongPixel(quantum_info->endian,p,&pixel);
4242 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4243 p=PushLongPixel(quantum_info->endian,p,&pixel);
4244 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4245 p+=quantum_info->pad;
4246 q+=GetPixelChannels(image);
4247 }
4248 break;
4249 }
4250 }
4251 case 24:
4252 {
4253 if (quantum_info->format == FloatingPointQuantumFormat)
4254 {
4255 float
4256 pixel;
4257
4258 for (x=0; x < (ssize_t) number_pixels; x++)
4259 {
4260 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4261 SetPixelRed(image,ClampToQuantum(pixel),q);
4262 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4263 SetPixelGreen(image,ClampToQuantum(pixel),q);
4264 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4265 SetPixelBlue(image,ClampToQuantum(pixel),q);
4266 p+=quantum_info->pad;
4267 q+=GetPixelChannels(image);
4268 }
4269 break;
4270 }
4271 magick_fallthrough;
4272 }
4273 case 64:
4274 {
4275 if (quantum_info->format == FloatingPointQuantumFormat)
4276 {
4277 double
4278 pixel;
4279
4280 for (x=0; x < (ssize_t) number_pixels; x++)
4281 {
4282 p=PushDoublePixel(quantum_info,p,&pixel);
4283 SetPixelRed(image,ClampToQuantum(pixel),q);
4284 p=PushDoublePixel(quantum_info,p,&pixel);
4285 SetPixelGreen(image,ClampToQuantum(pixel),q);
4286 p=PushDoublePixel(quantum_info,p,&pixel);
4287 SetPixelBlue(image,ClampToQuantum(pixel),q);
4288 p+=quantum_info->pad;
4289 q+=GetPixelChannels(image);
4290 }
4291 break;
4292 }
4293 magick_fallthrough;
4294 }
4295 default:
4296 {
4297 unsigned int
4298 pixel;
4299
4300 range=GetQuantumRange(quantum_info->depth);
4301 for (x=0; x < (ssize_t) number_pixels; x++)
4302 {
4303 p=PushQuantumPixel(quantum_info,p,&pixel);
4304 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4305 p=PushQuantumPixel(quantum_info,p,&pixel);
4306 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4307 p=PushQuantumPixel(quantum_info,p,&pixel);
4308 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4309 q+=GetPixelChannels(image);
4310 }
4311 break;
4312 }
4313 }
4314}
4315
4316static void ImportRGBAQuantum(const Image *image,QuantumInfo *quantum_info,
4317 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
4318 Quantum *magick_restrict q)
4319{
4320 QuantumAny
4321 range;
4322
4323 ssize_t
4324 x;
4325
4326 assert(image != (Image *) NULL);
4327 assert(image->signature == MagickCoreSignature);
4328 switch (quantum_info->depth)
4329 {
4330 case 8:
4331 {
4332 unsigned char
4333 pixel;
4334
4335 for (x=0; x < (ssize_t) number_pixels; x++)
4336 {
4337 p=PushCharPixel(p,&pixel);
4338 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
4339 p=PushCharPixel(p,&pixel);
4340 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
4341 p=PushCharPixel(p,&pixel);
4342 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
4343 p=PushCharPixel(p,&pixel);
4344 SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
4345 p+=quantum_info->pad;
4346 q+=GetPixelChannels(image);
4347 }
4348 break;
4349 }
4350 case 10:
4351 {
4352 unsigned int
4353 pixel;
4354
4355 pixel=0;
4356 if (quantum_info->pack == MagickFalse)
4357 {
4358 ssize_t
4359 i;
4360
4361 size_t
4362 quantum;
4363
4364 ssize_t
4365 n;
4366
4367 n=0;
4368 quantum=0;
4369 for (x=0; x < (ssize_t) number_pixels; x++)
4370 {
4371 for (i=0; i < 4; i++)
4372 {
4373 switch (n % 3)
4374 {
4375 case 0:
4376 {
4377 p=PushLongPixel(quantum_info->endian,p,&pixel);
4378 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4379 (((pixel >> 22) & 0x3ff) << 6)));
4380 break;
4381 }
4382 case 1:
4383 {
4384 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4385 (((pixel >> 12) & 0x3ff) << 6)));
4386 break;
4387 }
4388 case 2:
4389 {
4390 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4391 (((pixel >> 2) & 0x3ff) << 6)));
4392 break;
4393 }
4394 }
4395 switch (i)
4396 {
4397 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
4398 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
4399 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
4400 case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
4401 }
4402 n++;
4403 }
4404 p+=quantum_info->pad;
4405 q+=GetPixelChannels(image);
4406 }
4407 break;
4408 }
4409 for (x=0; x < (ssize_t) number_pixels; x++)
4410 {
4411 p=PushQuantumPixel(quantum_info,p,&pixel);
4412 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
4413 p=PushQuantumPixel(quantum_info,p,&pixel);
4414 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4415 q);
4416 p=PushQuantumPixel(quantum_info,p,&pixel);
4417 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4418 q);
4419 p=PushQuantumPixel(quantum_info,p,&pixel);
4420 SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4421 q);
4422 q+=GetPixelChannels(image);
4423 }
4424 break;
4425 }
4426 case 16:
4427 {
4428 unsigned short
4429 pixel;
4430
4431 if (quantum_info->format == FloatingPointQuantumFormat)
4432 {
4433 for (x=0; x < (ssize_t) number_pixels; x++)
4434 {
4435 p=PushShortPixel(quantum_info->endian,p,&pixel);
4436 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
4437 HalfToSinglePrecision(pixel)),q);
4438 p=PushShortPixel(quantum_info->endian,p,&pixel);
4439 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
4440 HalfToSinglePrecision(pixel)),q);
4441 p=PushShortPixel(quantum_info->endian,p,&pixel);
4442 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
4443 HalfToSinglePrecision(pixel)),q);
4444 p=PushShortPixel(quantum_info->endian,p,&pixel);
4445 SetPixelAlpha(image,ClampToQuantum((double) QuantumRange*(double)
4446 HalfToSinglePrecision(pixel)),q);
4447 p+=quantum_info->pad;
4448 q+=GetPixelChannels(image);
4449 }
4450 break;
4451 }
4452 for (x=0; x < (ssize_t) number_pixels; x++)
4453 {
4454 p=PushShortPixel(quantum_info->endian,p,&pixel);
4455 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4456 p=PushShortPixel(quantum_info->endian,p,&pixel);
4457 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4458 p=PushShortPixel(quantum_info->endian,p,&pixel);
4459 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4460 p=PushShortPixel(quantum_info->endian,p,&pixel);
4461 SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
4462 p+=quantum_info->pad;
4463 q+=GetPixelChannels(image);
4464 }
4465 break;
4466 }
4467 case 32:
4468 {
4469 if (quantum_info->format == FloatingPointQuantumFormat)
4470 {
4471 float
4472 pixel;
4473
4474 for (x=0; x < (ssize_t) number_pixels; x++)
4475 {
4476 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4477 SetPixelRed(image,ClampToQuantum(pixel),q);
4478 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4479 SetPixelGreen(image,ClampToQuantum(pixel),q);
4480 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4481 SetPixelBlue(image,ClampToQuantum(pixel),q);
4482 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4483 SetPixelAlpha(image,ClampToQuantum(pixel),q);
4484 p+=quantum_info->pad;
4485 q+=GetPixelChannels(image);
4486 }
4487 break;
4488 }
4489 else
4490 {
4491 unsigned int
4492 pixel;
4493
4494 for (x=0; x < (ssize_t) number_pixels; x++)
4495 {
4496 p=PushLongPixel(quantum_info->endian,p,&pixel);
4497 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4498 p=PushLongPixel(quantum_info->endian,p,&pixel);
4499 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4500 p=PushLongPixel(quantum_info->endian,p,&pixel);
4501 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4502 p=PushLongPixel(quantum_info->endian,p,&pixel);
4503 SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
4504 p+=quantum_info->pad;
4505 q+=GetPixelChannels(image);
4506 }
4507 break;
4508 }
4509 }
4510 case 24:
4511 {
4512 if (quantum_info->format == FloatingPointQuantumFormat)
4513 {
4514 float
4515 pixel;
4516
4517 for (x=0; x < (ssize_t) number_pixels; x++)
4518 {
4519 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4520 SetPixelRed(image,ClampToQuantum(pixel),q);
4521 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4522 SetPixelGreen(image,ClampToQuantum(pixel),q);
4523 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4524 SetPixelBlue(image,ClampToQuantum(pixel),q);
4525 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4526 SetPixelAlpha(image,ClampToQuantum(pixel),q);
4527 p+=quantum_info->pad;
4528 q+=GetPixelChannels(image);
4529 }
4530 break;
4531 }
4532 magick_fallthrough;
4533 }
4534 case 64:
4535 {
4536 if (quantum_info->format == FloatingPointQuantumFormat)
4537 {
4538 double
4539 pixel;
4540
4541 for (x=0; x < (ssize_t) number_pixels; x++)
4542 {
4543 p=PushDoublePixel(quantum_info,p,&pixel);
4544 SetPixelRed(image,ClampToQuantum(pixel),q);
4545 p=PushDoublePixel(quantum_info,p,&pixel);
4546 SetPixelGreen(image,ClampToQuantum(pixel),q);
4547 p=PushDoublePixel(quantum_info,p,&pixel);
4548 SetPixelBlue(image,ClampToQuantum(pixel),q);
4549 p=PushDoublePixel(quantum_info,p,&pixel);
4550 SetPixelAlpha(image,ClampToQuantum(pixel),q);
4551 p+=quantum_info->pad;
4552 q+=GetPixelChannels(image);
4553 }
4554 break;
4555 }
4556 magick_fallthrough;
4557 }
4558 default:
4559 {
4560 unsigned int
4561 pixel;
4562
4563 range=GetQuantumRange(quantum_info->depth);
4564 for (x=0; x < (ssize_t) number_pixels; x++)
4565 {
4566 p=PushQuantumPixel(quantum_info,p,&pixel);
4567 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4568 p=PushQuantumPixel(quantum_info,p,&pixel);
4569 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4570 p=PushQuantumPixel(quantum_info,p,&pixel);
4571 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4572 p=PushQuantumPixel(quantum_info,p,&pixel);
4573 SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
4574 q+=GetPixelChannels(image);
4575 }
4576 break;
4577 }
4578 }
4579}
4580
4581static void ImportRGBOQuantum(const Image *image,QuantumInfo *quantum_info,
4582 const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
4583 Quantum *magick_restrict q)
4584{
4585 QuantumAny
4586 range;
4587
4588 ssize_t
4589 x;
4590
4591 assert(image != (Image *) NULL);
4592 assert(image->signature == MagickCoreSignature);
4593 switch (quantum_info->depth)
4594 {
4595 case 8:
4596 {
4597 unsigned char
4598 pixel;
4599
4600 for (x=0; x < (ssize_t) number_pixels; x++)
4601 {
4602 p=PushCharPixel(p,&pixel);
4603 SetPixelRed(image,ScaleCharToQuantum(pixel),q);
4604 p=PushCharPixel(p,&pixel);
4605 SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
4606 p=PushCharPixel(p,&pixel);
4607 SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
4608 p=PushCharPixel(p,&pixel);
4609 SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
4610 p+=quantum_info->pad;
4611 q+=GetPixelChannels(image);
4612 }
4613 break;
4614 }
4615 case 10:
4616 {
4617 unsigned int
4618 pixel;
4619
4620 pixel=0;
4621 if (quantum_info->pack == MagickFalse)
4622 {
4623 ssize_t
4624 i;
4625
4626 size_t
4627 quantum;
4628
4629 ssize_t
4630 n;
4631
4632 n=0;
4633 quantum=0;
4634 for (x=0; x < (ssize_t) number_pixels; x++)
4635 {
4636 for (i=0; i < 4; i++)
4637 {
4638 switch (n % 3)
4639 {
4640 case 0:
4641 {
4642 p=PushLongPixel(quantum_info->endian,p,&pixel);
4643 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4644 (((pixel >> 22) & 0x3ff) << 6)));
4645 break;
4646 }
4647 case 1:
4648 {
4649 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4650 (((pixel >> 12) & 0x3ff) << 6)));
4651 break;
4652 }
4653 case 2:
4654 {
4655 quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4656 (((pixel >> 2) & 0x3ff) << 6)));
4657 break;
4658 }
4659 }
4660 switch (i)
4661 {
4662 case 0: SetPixelRed(image,(Quantum) quantum,q); break;
4663 case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
4664 case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
4665 case 3: SetPixelOpacity(image,(Quantum) quantum,q); break;
4666 }
4667 n++;
4668 }
4669 p+=quantum_info->pad;
4670 q+=GetPixelChannels(image);
4671 }
4672 break;
4673 }
4674 for (x=0; x < (ssize_t) number_pixels; x++)
4675 {
4676 p=PushQuantumPixel(quantum_info,p,&pixel);
4677 SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
4678 p=PushQuantumPixel(quantum_info,p,&pixel);
4679 SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4680 q);
4681 p=PushQuantumPixel(quantum_info,p,&pixel);
4682 SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4683 q);
4684 p=PushQuantumPixel(quantum_info,p,&pixel);
4685 SetPixelOpacity(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4686 q);
4687 q+=GetPixelChannels(image);
4688 }
4689 break;
4690 }
4691 case 16:
4692 {
4693 unsigned short
4694 pixel;
4695
4696 if (quantum_info->format == FloatingPointQuantumFormat)
4697 {
4698 for (x=0; x < (ssize_t) number_pixels; x++)
4699 {
4700 p=PushShortPixel(quantum_info->endian,p,&pixel);
4701 SetPixelRed(image,ClampToQuantum((double) QuantumRange*(double)
4702 HalfToSinglePrecision(pixel)),q);
4703 p=PushShortPixel(quantum_info->endian,p,&pixel);
4704 SetPixelGreen(image,ClampToQuantum((double) QuantumRange*(double)
4705 HalfToSinglePrecision(pixel)),q);
4706 p=PushShortPixel(quantum_info->endian,p,&pixel);
4707 SetPixelBlue(image,ClampToQuantum((double) QuantumRange*(double)
4708 HalfToSinglePrecision(pixel)),q);
4709 p=PushShortPixel(quantum_info->endian,p,&pixel);
4710 SetPixelOpacity(image,ClampToQuantum((double) QuantumRange*(double)
4711 HalfToSinglePrecision(pixel)),q);
4712 p+=quantum_info->pad;
4713 q+=GetPixelChannels(image);
4714 }
4715 break;
4716 }
4717 for (x=0; x < (ssize_t) number_pixels; x++)
4718 {
4719 p=PushShortPixel(quantum_info->endian,p,&pixel);
4720 SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4721 p=PushShortPixel(quantum_info->endian,p,&pixel);
4722 SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4723 p=PushShortPixel(quantum_info->endian,p,&pixel);
4724 SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4725 p=PushShortPixel(quantum_info->endian,p,&pixel);
4726 SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
4727 p+=quantum_info->pad;
4728 q+=GetPixelChannels(image);
4729 }
4730 break;
4731 }
4732 case 32:
4733 {
4734 if (quantum_info->format == FloatingPointQuantumFormat)
4735 {
4736 float
4737 pixel;
4738
4739 for (x=0; x < (ssize_t) number_pixels; x++)
4740 {
4741 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4742 SetPixelRed(image,ClampToQuantum(pixel),q);
4743 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4744 SetPixelGreen(image,ClampToQuantum(pixel),q);
4745 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4746 SetPixelBlue(image,ClampToQuantum(pixel),q);
4747 p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4748 SetPixelOpacity(image,ClampToQuantum(pixel),q);
4749 p+=quantum_info->pad;
4750 q+=GetPixelChannels(image);
4751 }
4752 break;
4753 }
4754 else
4755 {
4756 unsigned int
4757 pixel;
4758
4759 for (x=0; x < (ssize_t) number_pixels; x++)
4760 {
4761 p=PushLongPixel(quantum_info->endian,p,&pixel);
4762 SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4763 p=PushLongPixel(quantum_info->endian,p,&pixel);
4764 SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4765 p=PushLongPixel(quantum_info->endian,p,&pixel);
4766 SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4767 p=PushLongPixel(quantum_info->endian,p,&pixel);
4768 SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
4769 p+=quantum_info->pad;
4770 q+=GetPixelChannels(image);
4771 }
4772 break;
4773 }
4774 }
4775 case 24:
4776 {
4777 if (quantum_info->format == FloatingPointQuantumFormat)
4778 {
4779 float
4780 pixel;
4781
4782 for (x=0; x < (ssize_t) number_pixels; x++)
4783 {
4784 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4785 SetPixelRed(image,ClampToQuantum(pixel),q);
4786 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4787 SetPixelGreen(image,ClampToQuantum(pixel),q);
4788 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4789 SetPixelBlue(image,ClampToQuantum(pixel),q);
4790 p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4791 SetPixelOpacity(image,ClampToQuantum(pixel),q);
4792 p+=quantum_info->pad;
4793 q+=GetPixelChannels(image);
4794 }
4795 break;
4796 }
4797 magick_fallthrough;
4798 }
4799 case 64:
4800 {
4801 if (quantum_info->format == FloatingPointQuantumFormat)
4802 {
4803 double
4804 pixel;
4805
4806 for (x=0; x < (ssize_t) number_pixels; x++)
4807 {
4808 p=PushDoublePixel(quantum_info,p,&pixel);
4809 SetPixelRed(image,ClampToQuantum(pixel),q);
4810 p=PushDoublePixel(quantum_info,p,&pixel);
4811 SetPixelGreen(image,ClampToQuantum(pixel),q);
4812 p=PushDoublePixel(quantum_info,p,&pixel);
4813 SetPixelBlue(image,ClampToQuantum(pixel),q);
4814 p=PushDoublePixel(quantum_info,p,&pixel);
4815 SetPixelOpacity(image,ClampToQuantum(pixel),q);
4816 p+=quantum_info->pad;
4817 q+=GetPixelChannels(image);
4818 }
4819 break;
4820 }
4821 magick_fallthrough;
4822 }
4823 default:
4824 {
4825 unsigned int
4826 pixel;
4827
4828 range=GetQuantumRange(quantum_info->depth);
4829 for (x=0; x < (ssize_t) number_pixels; x++)
4830 {
4831 p=PushQuantumPixel(quantum_info,p,&pixel);
4832 SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4833 p=PushQuantumPixel(quantum_info,p,&pixel);
4834 SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4835 p=PushQuantumPixel(quantum_info,p,&pixel);
4836 SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4837 p=PushQuantumPixel(quantum_info,p,&pixel);
4838 SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
4839 q+=GetPixelChannels(image);
4840 }
4841 break;
4842 }
4843 }
4844}
4845
4846MagickExport size_t ImportQuantumPixels(const Image *image,
4847 CacheView *image_view,QuantumInfo *quantum_info,
4848 const QuantumType quantum_type,const unsigned char *magick_restrict pixels,
4849 ExceptionInfo *exception)
4850{
4851 MagickSizeType
4852 number_pixels;
4853
4854 const unsigned char
4855 *magick_restrict p;
4856
4857 ssize_t
4858 x;
4859
4860 Quantum
4861 *magick_restrict q;
4862
4863 size_t
4864 extent;
4865
4866 assert(image != (Image *) NULL);
4867 assert(image->signature == MagickCoreSignature);
4868 assert(quantum_info != (QuantumInfo *) NULL);
4869 assert(quantum_info->signature == MagickCoreSignature);
4870 if (IsEventLogging() != MagickFalse)
4871 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4872 if (pixels == (const unsigned char *) NULL)
4873 pixels=(const unsigned char *) GetQuantumPixels(quantum_info);
4874 x=0;
4875 p=pixels;
4876 if (image_view == (CacheView *) NULL)
4877 {
4878 number_pixels=GetImageExtent(image);
4879 q=GetAuthenticPixelQueue(image);
4880 }
4881 else
4882 {
4883 number_pixels=GetCacheViewExtent(image_view);
4884 q=GetCacheViewAuthenticPixelQueue(image_view);
4885 }
4886 ResetQuantumState(quantum_info);
4887 extent=GetQuantumExtent(image,quantum_info,quantum_type);
4888 switch (quantum_type)
4889 {
4890 case AlphaQuantum:
4891 {
4892 ImportAlphaQuantum(image,quantum_info,number_pixels,p,q);
4893 break;
4894 }
4895 case BGRQuantum:
4896 {
4897 ImportBGRQuantum(image,quantum_info,number_pixels,p,q);
4898 break;
4899 }
4900 case BGRAQuantum:
4901 {
4902 ImportBGRAQuantum(image,quantum_info,number_pixels,p,q);
4903 break;
4904 }
4905 case BGROQuantum:
4906 {
4907 ImportBGROQuantum(image,quantum_info,number_pixels,p,q);
4908 break;
4909 }
4910 case BlackQuantum:
4911 {
4912 ImportBlackQuantum(image,quantum_info,number_pixels,p,q,exception);
4913 break;
4914 }
4915 case BlueQuantum:
4916 case YellowQuantum:
4917 {
4918 ImportBlueQuantum(image,quantum_info,number_pixels,p,q);
4919 break;
4920 }
4921 case CMYKQuantum:
4922 {
4923 ImportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception);
4924 break;
4925 }
4926 case CMYKAQuantum:
4927 {
4928 ImportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception);
4929 break;
4930 }
4931 case MultispectralQuantum:
4932 {
4933 ImportMultispectralQuantum(image,quantum_info,number_pixels,p,q,exception);
4934 break;
4935 }
4936 case CMYKOQuantum:
4937 {
4938 ImportCMYKOQuantum(image,quantum_info,number_pixels,p,q,exception);
4939 break;
4940 }
4941 case CbYCrYQuantum:
4942 {
4943 ImportCbYCrYQuantum(image,quantum_info,number_pixels,p,q);
4944 break;
4945 }
4946 case GrayQuantum:
4947 {
4948 ImportGrayQuantum(image,quantum_info,number_pixels,p,q);
4949 break;
4950 }
4951 case GrayAlphaQuantum:
4952 {
4953 ImportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q);
4954 break;
4955 }
4956 case GreenQuantum:
4957 case MagentaQuantum:
4958 {
4959 ImportGreenQuantum(image,quantum_info,number_pixels,p,q);
4960 break;
4961 }
4962 case IndexQuantum:
4963 {
4964 ImportIndexQuantum(image,quantum_info,number_pixels,p,q,exception);
4965 break;
4966 }
4967 case IndexAlphaQuantum:
4968 {
4969 ImportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
4970 break;
4971 }
4972 case OpacityQuantum:
4973 {
4974 ImportOpacityQuantum(image,quantum_info,number_pixels,p,q);
4975 break;
4976 }
4977 case RedQuantum:
4978 case CyanQuantum:
4979 {
4980 ImportRedQuantum(image,quantum_info,number_pixels,p,q);
4981 break;
4982 }
4983 case RGBQuantum:
4984 case CbYCrQuantum:
4985 {
4986 ImportRGBQuantum(image,quantum_info,number_pixels,p,q);
4987 break;
4988 }
4989 case RGBAQuantum:
4990 case CbYCrAQuantum:
4991 {
4992 ImportRGBAQuantum(image,quantum_info,number_pixels,p,q);
4993 break;
4994 }
4995 case RGBOQuantum:
4996 {
4997 ImportRGBOQuantum(image,quantum_info,number_pixels,p,q);
4998 break;
4999 }
5000 default:
5001 break;
5002 }
5003 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
5004 {
5005 Quantum
5006 quantum;
5007
5008 q=GetAuthenticPixelQueue(image);
5009 if (image_view != (CacheView *) NULL)
5010 q=GetCacheViewAuthenticPixelQueue(image_view);
5011 for (x=0; x < (ssize_t) number_pixels; x++)
5012 {
5013 quantum=GetPixelRed(image,q);
5014 SetPixelRed(image,GetPixelGreen(image,q),q);
5015 SetPixelGreen(image,quantum,q);
5016 q+=GetPixelChannels(image);
5017 }
5018 }
5019 if (quantum_info->alpha_type == AssociatedQuantumAlpha)
5020 {
5021 double
5022 gamma,
5023 Sa;
5024
5025 /*
5026 Disassociate alpha.
5027 */
5028 q=GetAuthenticPixelQueue(image);
5029 if (image_view != (CacheView *) NULL)
5030 q=GetCacheViewAuthenticPixelQueue(image_view);
5031 for (x=0; x < (ssize_t) number_pixels; x++)
5032 {
5033 ssize_t
5034 i;
5035
5036 Sa=QuantumScale*(double) GetPixelAlpha(image,q);
5037 gamma=PerceptibleReciprocal(Sa);
5038 for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
5039 {
5040 PixelChannel channel = GetPixelChannelChannel(image,i);
5041 PixelTrait traits = GetPixelChannelTraits(image,channel);
5042 if ((channel == AlphaPixelChannel) ||
5043 ((traits & UpdatePixelTrait) == 0))
5044 continue;
5045 q[i]=ClampToQuantum(gamma*(double) q[i]);
5046 }
5047 q+=GetPixelChannels(image);
5048 }
5049 }
5050 return(extent);
5051}