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