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