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