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