MagickCore  7.1.0
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-2021 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
27 % %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
30 % %
31 % https://imagemagick.org/script/license.php %
32 % %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
38 % %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %
41 %
42 */
43 
44 /*
45  Include declarations.
46 */
47 #include "MagickCore/studio.h"
48 #include "MagickCore/property.h"
49 #include "MagickCore/blob.h"
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  float
1689  float_pixel;
1690 
1691  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1692  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1693  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1694  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1695  float_pixel=(float) (GetPixelAlpha(image,p));
1696  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
1697  p+=GetPixelChannels(image);
1698  q+=quantum_info->pad;
1699  }
1700  break;
1701  }
1702  for (x=0; x < (ssize_t) number_pixels; x++)
1703  {
1704  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1705  q=PopLongPixel(quantum_info->endian,pixel,q);
1706  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1707  q=PopLongPixel(quantum_info->endian,pixel,q);
1708  pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1709  q=PopLongPixel(quantum_info->endian,pixel,q);
1710  pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1711  q=PopLongPixel(quantum_info->endian,pixel,q);
1712  pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
1713  q=PopLongPixel(quantum_info->endian,pixel,q);
1714  p+=GetPixelChannels(image);
1715  q+=quantum_info->pad;
1716  }
1717  break;
1718  }
1719  case 64:
1720  {
1721  if (quantum_info->format == FloatingPointQuantumFormat)
1722  {
1723  double
1724  pixel;
1725 
1726  for (x=0; x < (ssize_t) number_pixels; x++)
1727  {
1728  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1729  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1730  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1731  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1732  pixel=(double) (GetPixelAlpha(image,p));
1733  q=PopQuantumDoublePixel(quantum_info,pixel,q);
1734  p+=GetPixelChannels(image);
1735  q+=quantum_info->pad;
1736  }
1737  break;
1738  }
1739  }
1740  default:
1741  {
1742  QuantumAny
1743  range;
1744 
1745  range=GetQuantumRange(quantum_info->depth);
1746  for (x=0; x < (ssize_t) number_pixels; x++)
1747  {
1748  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1749  range),q);
1750  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1751  range),q);
1752  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1753  range),q);
1754  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1755  range),q);
1756  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
1757  range),q);
1758  p+=GetPixelChannels(image);
1759  q+=quantum_info->pad;
1760  }
1761  break;
1762  }
1763  }
1764 }
1765 
1766 static void ExportCMYKOQuantum(const Image *image,QuantumInfo *quantum_info,
1767  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
1768  unsigned char *magick_restrict q,ExceptionInfo *exception)
1769 {
1770  ssize_t
1771  x;
1772 
1773  assert(exception != (ExceptionInfo *) NULL);
1774  assert(exception->signature == MagickCoreSignature);
1775  if (image->colorspace != CMYKColorspace)
1776  {
1777  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1778  "ColorSeparatedImageRequired","`%s'",image->filename);
1779  return;
1780  }
1781  switch (quantum_info->depth)
1782  {
1783  case 8:
1784  {
1785  unsigned char
1786  pixel;
1787 
1788  for (x=0; x < (ssize_t) number_pixels; x++)
1789  {
1790  pixel=ScaleQuantumToChar(GetPixelRed(image,p));
1791  q=PopCharPixel(pixel,q);
1792  pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
1793  q=PopCharPixel(pixel,q);
1794  pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
1795  q=PopCharPixel(pixel,q);
1796  pixel=ScaleQuantumToChar(GetPixelBlack(image,p));
1797  q=PopCharPixel(pixel,q);
1798  pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
1799  q=PopCharPixel(pixel,q);
1800  p+=GetPixelChannels(image);
1801  q+=quantum_info->pad;
1802  }
1803  break;
1804  }
1805  case 16:
1806  {
1807  unsigned short
1808  pixel;
1809 
1810  if (quantum_info->format == FloatingPointQuantumFormat)
1811  {
1812  for (x=0; x < (ssize_t) number_pixels; x++)
1813  {
1815  q=PopShortPixel(quantum_info->endian,pixel,q);
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);
1824  p+=GetPixelChannels(image);
1825  q+=quantum_info->pad;
1826  }
1827  break;
1828  }
1829  for (x=0; x < (ssize_t) number_pixels; x++)
1830  {
1831  pixel=ScaleQuantumToShort(GetPixelRed(image,p));
1832  q=PopShortPixel(quantum_info->endian,pixel,q);
1833  pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
1834  q=PopShortPixel(quantum_info->endian,pixel,q);
1835  pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
1836  q=PopShortPixel(quantum_info->endian,pixel,q);
1837  pixel=ScaleQuantumToShort(GetPixelBlack(image,p));
1838  q=PopShortPixel(quantum_info->endian,pixel,q);
1839  pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
1840  q=PopShortPixel(quantum_info->endian,pixel,q);
1841  p+=GetPixelChannels(image);
1842  q+=quantum_info->pad;
1843  }
1844  break;
1845  }
1846  case 32:
1847  {
1848  unsigned int
1849  pixel;
1850 
1851  if (quantum_info->format == FloatingPointQuantumFormat)
1852  {
1853  for (x=0; x < (ssize_t) number_pixels; x++)
1854  {
1855  float
1856  float_pixel;
1857 
1858  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
1859  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
1860  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
1861  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlack(image,p),q);
1862  float_pixel=(float) (GetPixelOpacity(image,p));
1863  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
1864  p+=GetPixelChannels(image);
1865  q+=quantum_info->pad;
1866  }
1867  break;
1868  }
1869  for (x=0; x < (ssize_t) number_pixels; x++)
1870  {
1871  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
1872  q=PopLongPixel(quantum_info->endian,pixel,q);
1873  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
1874  q=PopLongPixel(quantum_info->endian,pixel,q);
1875  pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
1876  q=PopLongPixel(quantum_info->endian,pixel,q);
1877  pixel=ScaleQuantumToLong(GetPixelBlack(image,p));
1878  q=PopLongPixel(quantum_info->endian,pixel,q);
1879  pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
1880  q=PopLongPixel(quantum_info->endian,pixel,q);
1881  p+=GetPixelChannels(image);
1882  q+=quantum_info->pad;
1883  }
1884  break;
1885  }
1886  case 64:
1887  {
1888  if (quantum_info->format == FloatingPointQuantumFormat)
1889  {
1890  double
1891  pixel;
1892 
1893  for (x=0; x < (ssize_t) number_pixels; x++)
1894  {
1895  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
1896  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
1897  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
1898  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlack(image,p),q);
1899  pixel=(double) (GetPixelOpacity(image,p));
1900  q=PopQuantumDoublePixel(quantum_info,pixel,q);
1901  p+=GetPixelChannels(image);
1902  q+=quantum_info->pad;
1903  }
1904  break;
1905  }
1906  }
1907  default:
1908  {
1909  QuantumAny
1910  range;
1911 
1912  range=GetQuantumRange(quantum_info->depth);
1913  for (x=0; x < (ssize_t) number_pixels; x++)
1914  {
1915  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
1916  range),q);
1917  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
1918  range),q);
1919  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
1920  range),q);
1921  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlack(image,p),
1922  range),q);
1923  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p),
1924  range),q);
1925  p+=GetPixelChannels(image);
1926  q+=quantum_info->pad;
1927  }
1928  break;
1929  }
1930  }
1931 }
1932 
1933 static void ExportGrayQuantum(const Image *image,QuantumInfo *quantum_info,
1934  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
1935  unsigned char *magick_restrict q)
1936 {
1937  QuantumAny
1938  range;
1939 
1940  ssize_t
1941  x;
1942 
1943  switch (quantum_info->depth)
1944  {
1945  case 1:
1946  {
1947  double
1948  threshold;
1949 
1950  unsigned char
1951  black,
1952  white;
1953 
1954  ssize_t
1955  bit;
1956 
1957  black=0x00;
1958  white=0x01;
1959  if (quantum_info->min_is_white != MagickFalse)
1960  {
1961  black=0x01;
1962  white=0x00;
1963  }
1964  threshold=QuantumRange/2.0;
1965  for (x=((ssize_t) number_pixels-7); x > 0; x-=8)
1966  {
1967  *q='\0';
1968  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 7;
1969  p+=GetPixelChannels(image);
1970  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 6;
1971  p+=GetPixelChannels(image);
1972  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 5;
1973  p+=GetPixelChannels(image);
1974  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 4;
1975  p+=GetPixelChannels(image);
1976  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 3;
1977  p+=GetPixelChannels(image);
1978  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 2;
1979  p+=GetPixelChannels(image);
1980  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 1;
1981  p+=GetPixelChannels(image);
1982  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << 0;
1983  p+=GetPixelChannels(image);
1984  q++;
1985  }
1986  if ((number_pixels % 8) != 0)
1987  {
1988  *q='\0';
1989  for (bit=7; bit >= (ssize_t) (8-(number_pixels % 8)); bit--)
1990  {
1991  *q|=(GetPixelLuma(image,p) < threshold ? black : white) << bit;
1992  p+=GetPixelChannels(image);
1993  }
1994  q++;
1995  }
1996  break;
1997  }
1998  case 4:
1999  {
2000  unsigned char
2001  pixel;
2002 
2003  for (x=0; x < (ssize_t) (number_pixels-1) ; x+=2)
2004  {
2005  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2006  *q=(((pixel >> 4) & 0xf) << 4);
2007  p+=GetPixelChannels(image);
2008  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2009  *q|=pixel >> 4;
2010  p+=GetPixelChannels(image);
2011  q++;
2012  }
2013  if ((number_pixels % 2) != 0)
2014  {
2015  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2016  *q=(((pixel >> 4) & 0xf) << 4);
2017  p+=GetPixelChannels(image);
2018  q++;
2019  }
2020  break;
2021  }
2022  case 8:
2023  {
2024  unsigned char
2025  pixel;
2026 
2027  for (x=0; x < (ssize_t) number_pixels; x++)
2028  {
2029  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2030  q=PopCharPixel(pixel,q);
2031  p+=GetPixelChannels(image);
2032  q+=quantum_info->pad;
2033  }
2034  break;
2035  }
2036  case 10:
2037  {
2038  range=GetQuantumRange(quantum_info->depth);
2039  if (quantum_info->pack == MagickFalse)
2040  {
2041  unsigned int
2042  pixel;
2043 
2044  for (x=0; x < (ssize_t) (number_pixels-2); x+=3)
2045  {
2046  pixel=(unsigned int) (ScaleQuantumToAny(ClampToQuantum(
2047  GetPixelLuma(image,p+2*GetPixelChannels(image))),range) << 22 |
2049  GetPixelChannels(image))),range) << 12 | ScaleQuantumToAny(
2050  ClampToQuantum(GetPixelLuma(image,p)),range) << 2);
2051  q=PopLongPixel(quantum_info->endian,pixel,q);
2052  p+=3*GetPixelChannels(image);
2053  q+=quantum_info->pad;
2054  }
2055  if (x < (ssize_t) number_pixels)
2056  {
2057  pixel=0U;
2058  if (x++ < (ssize_t) (number_pixels-1))
2060  GetPixelChannels(image))),range) << 12;
2061  if (x++ < (ssize_t) number_pixels)
2063  range) << 2;
2064  q=PopLongPixel(quantum_info->endian,pixel,q);
2065  }
2066  break;
2067  }
2068  for (x=0; x < (ssize_t) number_pixels; x++)
2069  {
2071  GetPixelLuma(image,p)),range),q);
2072  p+=GetPixelChannels(image);
2073  q+=quantum_info->pad;
2074  }
2075  break;
2076  }
2077  case 12:
2078  {
2079  unsigned short
2080  pixel;
2081 
2082  range=GetQuantumRange(quantum_info->depth);
2083  if (quantum_info->pack == MagickFalse)
2084  {
2085  for (x=0; x < (ssize_t) number_pixels; x++)
2086  {
2087  pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2088  q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel >> 4),
2089  q);
2090  p+=GetPixelChannels(image);
2091  q+=quantum_info->pad;
2092  }
2093  break;
2094  }
2095  for (x=0; x < (ssize_t) number_pixels; x++)
2096  {
2098  GetPixelLuma(image,p)),range),q);
2099  p+=GetPixelChannels(image);
2100  q+=quantum_info->pad;
2101  }
2102  break;
2103  }
2104  case 16:
2105  {
2106  unsigned short
2107  pixel;
2108 
2109  if (quantum_info->format == FloatingPointQuantumFormat)
2110  {
2111  for (x=0; x < (ssize_t) number_pixels; x++)
2112  {
2114  q=PopShortPixel(quantum_info->endian,pixel,q);
2115  p+=GetPixelChannels(image);
2116  q+=quantum_info->pad;
2117  }
2118  break;
2119  }
2120  for (x=0; x < (ssize_t) number_pixels; x++)
2121  {
2122  pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2123  q=PopShortPixel(quantum_info->endian,pixel,q);
2124  p+=GetPixelChannels(image);
2125  q+=quantum_info->pad;
2126  }
2127  break;
2128  }
2129  case 32:
2130  {
2131  unsigned int
2132  pixel;
2133 
2134  if (quantum_info->format == FloatingPointQuantumFormat)
2135  {
2136  for (x=0; x < (ssize_t) number_pixels; x++)
2137  {
2138  float
2139  float_pixel;
2140 
2141  float_pixel=(float) GetPixelLuma(image,p);
2142  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
2143  p+=GetPixelChannels(image);
2144  q+=quantum_info->pad;
2145  }
2146  break;
2147  }
2148  for (x=0; x < (ssize_t) number_pixels; x++)
2149  {
2150  pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
2151  q=PopLongPixel(quantum_info->endian,pixel,q);
2152  p+=GetPixelChannels(image);
2153  q+=quantum_info->pad;
2154  }
2155  break;
2156  }
2157  case 64:
2158  {
2159  if (quantum_info->format == FloatingPointQuantumFormat)
2160  {
2161  for (x=0; x < (ssize_t) number_pixels; x++)
2162  {
2163  double
2164  pixel;
2165 
2166  pixel=GetPixelLuma(image,p);
2167  q=PopQuantumDoublePixel(quantum_info,pixel,q);
2168  p+=GetPixelChannels(image);
2169  q+=quantum_info->pad;
2170  }
2171  break;
2172  }
2173  }
2174  default:
2175  {
2176  range=GetQuantumRange(quantum_info->depth);
2177  for (x=0; x < (ssize_t) number_pixels; x++)
2178  {
2180  GetPixelLuma(image,p)),range),q);
2181  p+=GetPixelChannels(image);
2182  q+=quantum_info->pad;
2183  }
2184  break;
2185  }
2186  }
2187 }
2188 
2189 static void ExportGrayAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
2190  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
2191  unsigned char *magick_restrict q)
2192 {
2193  QuantumAny
2194  range;
2195 
2196  ssize_t
2197  x;
2198 
2199  switch (quantum_info->depth)
2200  {
2201  case 1:
2202  {
2203  double
2204  threshold;
2205 
2206  unsigned char
2207  black,
2208  pixel,
2209  white;
2210 
2211  ssize_t
2212  bit;
2213 
2214  black=0x00;
2215  white=0x01;
2216  if (quantum_info->min_is_white != MagickFalse)
2217  {
2218  black=0x01;
2219  white=0x00;
2220  }
2221  threshold=QuantumRange/2.0;
2222  for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2223  {
2224  *q='\0';
2225  *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 7;
2226  pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2227  0x00 : 0x01);
2228  *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 6);
2229  p+=GetPixelChannels(image);
2230  *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 5;
2231  pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2232  0x00 : 0x01);
2233  *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 4);
2234  p+=GetPixelChannels(image);
2235  *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 3;
2236  pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2237  0x00 : 0x01);
2238  *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 2);
2239  p+=GetPixelChannels(image);
2240  *q|=(GetPixelLuma(image,p) > threshold ? black : white) << 1;
2241  pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2242  0x00 : 0x01);
2243  *q|=(((int) pixel != 0 ? 0x00 : 0x01) << 0);
2244  p+=GetPixelChannels(image);
2245  q++;
2246  }
2247  if ((number_pixels % 4) != 0)
2248  {
2249  *q='\0';
2250  for (bit=0; bit <= (ssize_t) (number_pixels % 4); bit+=2)
2251  {
2252  *q|=(GetPixelLuma(image,p) > threshold ? black : white) <<
2253  (7-bit);
2254  pixel=(unsigned char) (GetPixelAlpha(image,p) == OpaqueAlpha ?
2255  0x00 : 0x01);
2256  *q|=(((int) pixel != 0 ? 0x00 : 0x01) << (unsigned char)
2257  (7-bit-1));
2258  p+=GetPixelChannels(image);
2259  }
2260  q++;
2261  }
2262  break;
2263  }
2264  case 4:
2265  {
2266  unsigned char
2267  pixel;
2268 
2269  for (x=0; x < (ssize_t) number_pixels ; x++)
2270  {
2271  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2272  *q=(((pixel >> 4) & 0xf) << 4);
2273  pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
2274  *q|=pixel & 0xf;
2275  p+=GetPixelChannels(image);
2276  q++;
2277  }
2278  break;
2279  }
2280  case 8:
2281  {
2282  unsigned char
2283  pixel;
2284 
2285  for (x=0; x < (ssize_t) number_pixels; x++)
2286  {
2287  pixel=ScaleQuantumToChar(ClampToQuantum(GetPixelLuma(image,p)));
2288  q=PopCharPixel(pixel,q);
2289  pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2290  q=PopCharPixel(pixel,q);
2291  p+=GetPixelChannels(image);
2292  q+=quantum_info->pad;
2293  }
2294  break;
2295  }
2296  case 16:
2297  {
2298  unsigned short
2299  pixel;
2300 
2301  if (quantum_info->format == FloatingPointQuantumFormat)
2302  {
2303  for (x=0; x < (ssize_t) number_pixels; x++)
2304  {
2306  q=PopShortPixel(quantum_info->endian,pixel,q);
2308  q=PopShortPixel(quantum_info->endian,pixel,q);
2309  p+=GetPixelChannels(image);
2310  q+=quantum_info->pad;
2311  }
2312  break;
2313  }
2314  for (x=0; x < (ssize_t) number_pixels; x++)
2315  {
2316  pixel=ScaleQuantumToShort(ClampToQuantum(GetPixelLuma(image,p)));
2317  q=PopShortPixel(quantum_info->endian,pixel,q);
2318  pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2319  q=PopShortPixel(quantum_info->endian,pixel,q);
2320  p+=GetPixelChannels(image);
2321  q+=quantum_info->pad;
2322  }
2323  break;
2324  }
2325  case 32:
2326  {
2327  unsigned int
2328  pixel;
2329 
2330  if (quantum_info->format == FloatingPointQuantumFormat)
2331  {
2332  for (x=0; x < (ssize_t) number_pixels; x++)
2333  {
2334  float
2335  float_pixel;
2336 
2337  float_pixel=(float) GetPixelLuma(image,p);
2338  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
2339  float_pixel=(float) (GetPixelAlpha(image,p));
2340  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
2341  p+=GetPixelChannels(image);
2342  q+=quantum_info->pad;
2343  }
2344  break;
2345  }
2346  for (x=0; x < (ssize_t) number_pixels; x++)
2347  {
2348  pixel=ScaleQuantumToLong(ClampToQuantum(GetPixelLuma(image,p)));
2349  q=PopLongPixel(quantum_info->endian,pixel,q);
2350  pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2351  q=PopLongPixel(quantum_info->endian,pixel,q);
2352  p+=GetPixelChannels(image);
2353  q+=quantum_info->pad;
2354  }
2355  break;
2356  }
2357  case 64:
2358  {
2359  if (quantum_info->format == FloatingPointQuantumFormat)
2360  {
2361  for (x=0; x < (ssize_t) number_pixels; x++)
2362  {
2363  double
2364  pixel;
2365 
2366  pixel=GetPixelLuma(image,p);
2367  q=PopQuantumDoublePixel(quantum_info,pixel,q);
2368  pixel=(double) (GetPixelAlpha(image,p));
2369  q=PopQuantumDoublePixel(quantum_info,pixel,q);
2370  p+=GetPixelChannels(image);
2371  q+=quantum_info->pad;
2372  }
2373  break;
2374  }
2375  }
2376  default:
2377  {
2378  range=GetQuantumRange(quantum_info->depth);
2379  for (x=0; x < (ssize_t) number_pixels; x++)
2380  {
2382  GetPixelLuma(image,p)),range),q);
2383  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
2384  range),q);
2385  p+=GetPixelChannels(image);
2386  q+=quantum_info->pad;
2387  }
2388  break;
2389  }
2390  }
2391 }
2392 
2393 static void ExportGreenQuantum(const Image *image,QuantumInfo *quantum_info,
2394  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
2395  unsigned char *magick_restrict q)
2396 {
2397  QuantumAny
2398  range;
2399 
2400  ssize_t
2401  x;
2402 
2403  switch (quantum_info->depth)
2404  {
2405  case 8:
2406  {
2407  unsigned char
2408  pixel;
2409 
2410  for (x=0; x < (ssize_t) number_pixels; x++)
2411  {
2412  pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
2413  q=PopCharPixel(pixel,q);
2414  p+=GetPixelChannels(image);
2415  q+=quantum_info->pad;
2416  }
2417  break;
2418  }
2419  case 16:
2420  {
2421  unsigned short
2422  pixel;
2423 
2424  if (quantum_info->format == FloatingPointQuantumFormat)
2425  {
2426  for (x=0; x < (ssize_t) number_pixels; x++)
2427  {
2429  q=PopShortPixel(quantum_info->endian,pixel,q);
2430  p+=GetPixelChannels(image);
2431  q+=quantum_info->pad;
2432  }
2433  break;
2434  }
2435  for (x=0; x < (ssize_t) number_pixels; x++)
2436  {
2437  pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
2438  q=PopShortPixel(quantum_info->endian,pixel,q);
2439  p+=GetPixelChannels(image);
2440  q+=quantum_info->pad;
2441  }
2442  break;
2443  }
2444  case 32:
2445  {
2446  unsigned int
2447  pixel;
2448 
2449  if (quantum_info->format == FloatingPointQuantumFormat)
2450  {
2451  for (x=0; x < (ssize_t) number_pixels; x++)
2452  {
2453  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
2454  p+=GetPixelChannels(image);
2455  q+=quantum_info->pad;
2456  }
2457  break;
2458  }
2459  for (x=0; x < (ssize_t) number_pixels; x++)
2460  {
2461  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
2462  q=PopLongPixel(quantum_info->endian,pixel,q);
2463  p+=GetPixelChannels(image);
2464  q+=quantum_info->pad;
2465  }
2466  break;
2467  }
2468  case 64:
2469  {
2470  if (quantum_info->format == FloatingPointQuantumFormat)
2471  {
2472  for (x=0; x < (ssize_t) number_pixels; x++)
2473  {
2474  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
2475  p+=GetPixelChannels(image);
2476  q+=quantum_info->pad;
2477  }
2478  break;
2479  }
2480  }
2481  default:
2482  {
2483  range=GetQuantumRange(quantum_info->depth);
2484  for (x=0; x < (ssize_t) number_pixels; x++)
2485  {
2486  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
2487  range),q);
2488  p+=GetPixelChannels(image);
2489  q+=quantum_info->pad;
2490  }
2491  break;
2492  }
2493  }
2494 }
2495 
2496 static void ExportIndexQuantum(const Image *image,QuantumInfo *quantum_info,
2497  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
2498  unsigned char *magick_restrict q,ExceptionInfo *exception)
2499 {
2500  ssize_t
2501  x;
2502 
2503  ssize_t
2504  bit;
2505 
2506  assert(exception != (ExceptionInfo *) NULL);
2507  assert(exception->signature == MagickCoreSignature);
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  assert(exception != (ExceptionInfo *) NULL);
2677  assert(exception->signature == MagickCoreSignature);
2678  if (image->storage_class != PseudoClass)
2679  {
2680  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2681  "ColormappedImageRequired","`%s'",image->filename);
2682  return;
2683  }
2684  switch (quantum_info->depth)
2685  {
2686  case 1:
2687  {
2688  unsigned char
2689  pixel;
2690 
2691  for (x=((ssize_t) number_pixels-3); x > 0; x-=4)
2692  {
2693  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2694  *q=((pixel & 0x01) << 7);
2695  pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2696  TransparentAlpha ? 1 : 0);
2697  *q|=((pixel & 0x01) << 6);
2698  p+=GetPixelChannels(image);
2699  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2700  *q|=((pixel & 0x01) << 5);
2701  pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2702  TransparentAlpha ? 1 : 0);
2703  *q|=((pixel & 0x01) << 4);
2704  p+=GetPixelChannels(image);
2705  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2706  *q|=((pixel & 0x01) << 3);
2707  pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2708  TransparentAlpha ? 1 : 0);
2709  *q|=((pixel & 0x01) << 2);
2710  p+=GetPixelChannels(image);
2711  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2712  *q|=((pixel & 0x01) << 1);
2713  pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2714  TransparentAlpha ? 1 : 0);
2715  *q|=((pixel & 0x01) << 0);
2716  p+=GetPixelChannels(image);
2717  q++;
2718  }
2719  if ((number_pixels % 4) != 0)
2720  {
2721  *q='\0';
2722  for (bit=3; bit >= (ssize_t) (4-(number_pixels % 4)); bit-=2)
2723  {
2724  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2725  *q|=((pixel & 0x01) << (unsigned char) (bit+4));
2726  pixel=(unsigned char) (GetPixelAlpha(image,p) == (Quantum)
2727  TransparentAlpha ? 1 : 0);
2728  *q|=((pixel & 0x01) << (unsigned char) (bit+4-1));
2729  p+=GetPixelChannels(image);
2730  }
2731  q++;
2732  }
2733  break;
2734  }
2735  case 4:
2736  {
2737  unsigned char
2738  pixel;
2739 
2740  for (x=0; x < (ssize_t) number_pixels ; x++)
2741  {
2742  pixel=(unsigned char) ((ssize_t) GetPixelIndex(image,p));
2743  *q=((pixel & 0xf) << 4);
2744  pixel=(unsigned char) (16*QuantumScale*GetPixelAlpha(image,p)+0.5);
2745  *q|=((pixel & 0xf) << 0);
2746  p+=GetPixelChannels(image);
2747  q++;
2748  }
2749  break;
2750  }
2751  case 8:
2752  {
2753  unsigned char
2754  pixel;
2755 
2756  for (x=0; x < (ssize_t) number_pixels; x++)
2757  {
2758  q=PopCharPixel((unsigned char) ((ssize_t) GetPixelIndex(image,p)),q);
2759  pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
2760  q=PopCharPixel(pixel,q);
2761  p+=GetPixelChannels(image);
2762  q+=quantum_info->pad;
2763  }
2764  break;
2765  }
2766  case 16:
2767  {
2768  unsigned short
2769  pixel;
2770 
2771  if (quantum_info->format == FloatingPointQuantumFormat)
2772  {
2773  for (x=0; x < (ssize_t) number_pixels; x++)
2774  {
2775  q=PopShortPixel(quantum_info->endian,(unsigned short)
2776  ((ssize_t) GetPixelIndex(image,p)),q);
2778  q=PopShortPixel(quantum_info->endian,pixel,q);
2779  p+=GetPixelChannels(image);
2780  q+=quantum_info->pad;
2781  }
2782  break;
2783  }
2784  for (x=0; x < (ssize_t) number_pixels; x++)
2785  {
2786  q=PopShortPixel(quantum_info->endian,(unsigned short)
2787  ((ssize_t) GetPixelIndex(image,p)),q);
2788  pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
2789  q=PopShortPixel(quantum_info->endian,pixel,q);
2790  p+=GetPixelChannels(image);
2791  q+=quantum_info->pad;
2792  }
2793  break;
2794  }
2795  case 32:
2796  {
2797  unsigned int
2798  pixel;
2799 
2800  if (quantum_info->format == FloatingPointQuantumFormat)
2801  {
2802  for (x=0; x < (ssize_t) number_pixels; x++)
2803  {
2804  float
2805  float_pixel;
2806 
2807  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelIndex(image,p),q);
2808  float_pixel=(float) GetPixelAlpha(image,p);
2809  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
2810  p+=GetPixelChannels(image);
2811  q+=quantum_info->pad;
2812  }
2813  break;
2814  }
2815  for (x=0; x < (ssize_t) number_pixels; x++)
2816  {
2817  q=PopLongPixel(quantum_info->endian,(unsigned int)
2818  GetPixelIndex(image,p),q);
2819  pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
2820  q=PopLongPixel(quantum_info->endian,pixel,q);
2821  p+=GetPixelChannels(image);
2822  q+=quantum_info->pad;
2823  }
2824  break;
2825  }
2826  case 64:
2827  {
2828  if (quantum_info->format == FloatingPointQuantumFormat)
2829  {
2830  for (x=0; x < (ssize_t) number_pixels; x++)
2831  {
2832  double
2833  pixel;
2834 
2835  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelIndex(image,p),q);
2836  pixel=(double) GetPixelAlpha(image,p);
2837  q=PopQuantumDoublePixel(quantum_info,pixel,q);
2838  p+=GetPixelChannels(image);
2839  q+=quantum_info->pad;
2840  }
2841  break;
2842  }
2843  }
2844  default:
2845  {
2846  QuantumAny
2847  range;
2848 
2849  range=GetQuantumRange(quantum_info->depth);
2850  for (x=0; x < (ssize_t) number_pixels; x++)
2851  {
2852  q=PopQuantumPixel(quantum_info,(QuantumAny) GetPixelIndex(image,p),q);
2853  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
2854  range),q);
2855  p+=GetPixelChannels(image);
2856  q+=quantum_info->pad;
2857  }
2858  break;
2859  }
2860  }
2861 }
2862 
2863 static void ExportOpacityQuantum(const Image *image,QuantumInfo *quantum_info,
2864  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
2865  unsigned char *magick_restrict q)
2866 {
2867  QuantumAny
2868  range;
2869 
2870  ssize_t
2871  x;
2872 
2873  switch (quantum_info->depth)
2874  {
2875  case 8:
2876  {
2877  unsigned char
2878  pixel;
2879 
2880  for (x=0; x < (ssize_t) number_pixels; x++)
2881  {
2882  pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
2883  q=PopCharPixel(pixel,q);
2884  p+=GetPixelChannels(image);
2885  q+=quantum_info->pad;
2886  }
2887  break;
2888  }
2889  case 16:
2890  {
2891  unsigned short
2892  pixel;
2893 
2894  if (quantum_info->format == FloatingPointQuantumFormat)
2895  {
2896  for (x=0; x < (ssize_t) number_pixels; x++)
2897  {
2899  q=PopShortPixel(quantum_info->endian,pixel,q);
2900  p+=GetPixelChannels(image);
2901  q+=quantum_info->pad;
2902  }
2903  break;
2904  }
2905  for (x=0; x < (ssize_t) number_pixels; x++)
2906  {
2907  pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
2908  q=PopShortPixel(quantum_info->endian,pixel,q);
2909  p+=GetPixelChannels(image);
2910  q+=quantum_info->pad;
2911  }
2912  break;
2913  }
2914  case 32:
2915  {
2916  unsigned int
2917  pixel;
2918 
2919  if (quantum_info->format == FloatingPointQuantumFormat)
2920  {
2921  for (x=0; x < (ssize_t) number_pixels; x++)
2922  {
2923  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelOpacity(image,p),q);
2924  p+=GetPixelChannels(image);
2925  q+=quantum_info->pad;
2926  }
2927  break;
2928  }
2929  for (x=0; x < (ssize_t) number_pixels; x++)
2930  {
2931  pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
2932  q=PopLongPixel(quantum_info->endian,pixel,q);
2933  p+=GetPixelChannels(image);
2934  q+=quantum_info->pad;
2935  }
2936  break;
2937  }
2938  case 64:
2939  {
2940  if (quantum_info->format == FloatingPointQuantumFormat)
2941  {
2942  for (x=0; x < (ssize_t) number_pixels; x++)
2943  {
2944  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelOpacity(image,p),q);
2945  p+=GetPixelChannels(image);
2946  q+=quantum_info->pad;
2947  }
2948  break;
2949  }
2950  }
2951  default:
2952  {
2953  range=GetQuantumRange(quantum_info->depth);
2954  for (x=0; x < (ssize_t) number_pixels; x++)
2955  {
2956  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(
2957  GetPixelOpacity(image,p),range),q);
2958  p+=GetPixelChannels(image);
2959  q+=quantum_info->pad;
2960  }
2961  break;
2962  }
2963  }
2964 }
2965 
2966 static void ExportRedQuantum(const Image *image,QuantumInfo *quantum_info,
2967  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
2968  unsigned char *magick_restrict q)
2969 {
2970  QuantumAny
2971  range;
2972 
2973  ssize_t
2974  x;
2975 
2976  switch (quantum_info->depth)
2977  {
2978  case 8:
2979  {
2980  unsigned char
2981  pixel;
2982 
2983  for (x=0; x < (ssize_t) number_pixels; x++)
2984  {
2985  pixel=ScaleQuantumToChar(GetPixelRed(image,p));
2986  q=PopCharPixel(pixel,q);
2987  p+=GetPixelChannels(image);
2988  q+=quantum_info->pad;
2989  }
2990  break;
2991  }
2992  case 16:
2993  {
2994  unsigned short
2995  pixel;
2996 
2997  if (quantum_info->format == FloatingPointQuantumFormat)
2998  {
2999  for (x=0; x < (ssize_t) number_pixels; x++)
3000  {
3002  q=PopShortPixel(quantum_info->endian,pixel,q);
3003  p+=GetPixelChannels(image);
3004  q+=quantum_info->pad;
3005  }
3006  break;
3007  }
3008  for (x=0; x < (ssize_t) number_pixels; x++)
3009  {
3010  pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3011  q=PopShortPixel(quantum_info->endian,pixel,q);
3012  p+=GetPixelChannels(image);
3013  q+=quantum_info->pad;
3014  }
3015  break;
3016  }
3017  case 32:
3018  {
3019  unsigned int
3020  pixel;
3021 
3022  if (quantum_info->format == FloatingPointQuantumFormat)
3023  {
3024  for (x=0; x < (ssize_t) number_pixels; x++)
3025  {
3026  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3027  p+=GetPixelChannels(image);
3028  q+=quantum_info->pad;
3029  }
3030  break;
3031  }
3032  for (x=0; x < (ssize_t) number_pixels; x++)
3033  {
3034  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3035  q=PopLongPixel(quantum_info->endian,pixel,q);
3036  p+=GetPixelChannels(image);
3037  q+=quantum_info->pad;
3038  }
3039  break;
3040  }
3041  case 64:
3042  {
3043  if (quantum_info->format == FloatingPointQuantumFormat)
3044  {
3045  for (x=0; x < (ssize_t) number_pixels; x++)
3046  {
3047  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3048  p+=GetPixelChannels(image);
3049  q+=quantum_info->pad;
3050  }
3051  break;
3052  }
3053  }
3054  default:
3055  {
3056  range=GetQuantumRange(quantum_info->depth);
3057  for (x=0; x < (ssize_t) number_pixels; x++)
3058  {
3059  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3060  range),q);
3061  p+=GetPixelChannels(image);
3062  q+=quantum_info->pad;
3063  }
3064  break;
3065  }
3066  }
3067 }
3068 
3069 static void ExportRGBQuantum(const Image *image,QuantumInfo *quantum_info,
3070  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
3071  unsigned char *magick_restrict q)
3072 {
3073  QuantumAny
3074  range;
3075 
3076  ssize_t
3077  x;
3078 
3079  ssize_t
3080  bit;
3081 
3082  switch (quantum_info->depth)
3083  {
3084  case 8:
3085  {
3086  for (x=0; x < (ssize_t) number_pixels; x++)
3087  {
3088  q=PopCharPixel(ScaleQuantumToChar(GetPixelRed(image,p)),q);
3089  q=PopCharPixel(ScaleQuantumToChar(GetPixelGreen(image,p)),q);
3090  q=PopCharPixel(ScaleQuantumToChar(GetPixelBlue(image,p)),q);
3091  p+=GetPixelChannels(image);
3092  q+=quantum_info->pad;
3093  }
3094  break;
3095  }
3096  case 10:
3097  {
3098  unsigned int
3099  pixel;
3100 
3101  range=GetQuantumRange(quantum_info->depth);
3102  if (quantum_info->pack == MagickFalse)
3103  {
3104  for (x=0; x < (ssize_t) number_pixels; x++)
3105  {
3106  pixel=(unsigned int) (
3107  ScaleQuantumToAny(GetPixelRed(image,p),range) << 22 |
3108  ScaleQuantumToAny(GetPixelGreen(image,p),range) << 12 |
3109  ScaleQuantumToAny(GetPixelBlue(image,p),range) << 2);
3110  q=PopLongPixel(quantum_info->endian,pixel,q);
3111  p+=GetPixelChannels(image);
3112  q+=quantum_info->pad;
3113  }
3114  break;
3115  }
3116  if (quantum_info->quantum == 32UL)
3117  {
3118  for (x=0; x < (ssize_t) number_pixels; x++)
3119  {
3120  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3121  q=PopQuantumLongPixel(quantum_info,pixel,q);
3122  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3123  range);
3124  q=PopQuantumLongPixel(quantum_info,pixel,q);
3125  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3126  q=PopQuantumLongPixel(quantum_info,pixel,q);
3127  p+=GetPixelChannels(image);
3128  q+=quantum_info->pad;
3129  }
3130  break;
3131  }
3132  for (x=0; x < (ssize_t) number_pixels; x++)
3133  {
3134  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3135  q=PopQuantumPixel(quantum_info,pixel,q);
3136  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3137  q=PopQuantumPixel(quantum_info,pixel,q);
3138  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3139  q=PopQuantumPixel(quantum_info,pixel,q);
3140  p+=GetPixelChannels(image);
3141  q+=quantum_info->pad;
3142  }
3143  break;
3144  }
3145  case 12:
3146  {
3147  unsigned int
3148  pixel;
3149 
3150  range=GetQuantumRange(quantum_info->depth);
3151  if (quantum_info->pack == MagickFalse)
3152  {
3153  for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
3154  {
3155  switch (x % 3)
3156  {
3157  default:
3158  case 0:
3159  {
3160  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3161  range);
3162  break;
3163  }
3164  case 1:
3165  {
3166  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3167  range);
3168  break;
3169  }
3170  case 2:
3171  {
3172  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3173  range);
3174  p+=GetPixelChannels(image);
3175  break;
3176  }
3177  }
3178  q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3179  q);
3180  switch ((x+1) % 3)
3181  {
3182  default:
3183  case 0:
3184  {
3185  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3186  range);
3187  break;
3188  }
3189  case 1:
3190  {
3191  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3192  range);
3193  break;
3194  }
3195  case 2:
3196  {
3197  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3198  range);
3199  p+=GetPixelChannels(image);
3200  break;
3201  }
3202  }
3203  q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3204  q);
3205  q+=quantum_info->pad;
3206  }
3207  for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
3208  {
3209  switch ((x+bit) % 3)
3210  {
3211  default:
3212  case 0:
3213  {
3214  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),
3215  range);
3216  break;
3217  }
3218  case 1:
3219  {
3220  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3221  range);
3222  break;
3223  }
3224  case 2:
3225  {
3226  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),
3227  range);
3228  p+=GetPixelChannels(image);
3229  break;
3230  }
3231  }
3232  q=PopShortPixel(quantum_info->endian,(unsigned short) (pixel << 4),
3233  q);
3234  q+=quantum_info->pad;
3235  }
3236  if (bit != 0)
3237  p+=GetPixelChannels(image);
3238  break;
3239  }
3240  if (quantum_info->quantum == 32UL)
3241  {
3242  for (x=0; x < (ssize_t) number_pixels; x++)
3243  {
3244  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3245  q=PopQuantumLongPixel(quantum_info,pixel,q);
3246  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3247  range);
3248  q=PopQuantumLongPixel(quantum_info,pixel,q);
3249  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3250  q=PopQuantumLongPixel(quantum_info,pixel,q);
3251  p+=GetPixelChannels(image);
3252  q+=quantum_info->pad;
3253  }
3254  break;
3255  }
3256  for (x=0; x < (ssize_t) number_pixels; x++)
3257  {
3258  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3259  q=PopQuantumPixel(quantum_info,pixel,q);
3260  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3261  q=PopQuantumPixel(quantum_info,pixel,q);
3262  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3263  q=PopQuantumPixel(quantum_info,pixel,q);
3264  p+=GetPixelChannels(image);
3265  q+=quantum_info->pad;
3266  }
3267  break;
3268  }
3269  case 16:
3270  {
3271  unsigned short
3272  pixel;
3273 
3274  if (quantum_info->format == FloatingPointQuantumFormat)
3275  {
3276  for (x=0; x < (ssize_t) number_pixels; x++)
3277  {
3279  q=PopShortPixel(quantum_info->endian,pixel,q);
3281  q=PopShortPixel(quantum_info->endian,pixel,q);
3283  q=PopShortPixel(quantum_info->endian,pixel,q);
3284  p+=GetPixelChannels(image);
3285  q+=quantum_info->pad;
3286  }
3287  break;
3288  }
3289  for (x=0; x < (ssize_t) number_pixels; x++)
3290  {
3291  pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3292  q=PopShortPixel(quantum_info->endian,pixel,q);
3293  pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3294  q=PopShortPixel(quantum_info->endian,pixel,q);
3295  pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3296  q=PopShortPixel(quantum_info->endian,pixel,q);
3297  p+=GetPixelChannels(image);
3298  q+=quantum_info->pad;
3299  }
3300  break;
3301  }
3302  case 32:
3303  {
3304  unsigned int
3305  pixel;
3306 
3307  if (quantum_info->format == FloatingPointQuantumFormat)
3308  {
3309  for (x=0; x < (ssize_t) number_pixels; x++)
3310  {
3311  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),
3312  q);
3313  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),
3314  q);
3315  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),
3316  q);
3317  p+=GetPixelChannels(image);
3318  q+=quantum_info->pad;
3319  }
3320  break;
3321  }
3322  for (x=0; x < (ssize_t) number_pixels; x++)
3323  {
3324  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3325  q=PopLongPixel(quantum_info->endian,pixel,q);
3326  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3327  q=PopLongPixel(quantum_info->endian,pixel,q);
3328  pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3329  q=PopLongPixel(quantum_info->endian,pixel,q);
3330  p+=GetPixelChannels(image);
3331  q+=quantum_info->pad;
3332  }
3333  break;
3334  }
3335  case 64:
3336  {
3337  if (quantum_info->format == FloatingPointQuantumFormat)
3338  {
3339  for (x=0; x < (ssize_t) number_pixels; x++)
3340  {
3341  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3342  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
3343  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
3344  p+=GetPixelChannels(image);
3345  q+=quantum_info->pad;
3346  }
3347  break;
3348  }
3349  }
3350  default:
3351  {
3352  range=GetQuantumRange(quantum_info->depth);
3353  for (x=0; x < (ssize_t) number_pixels; x++)
3354  {
3355  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3356  range),q);
3357  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3358  range),q);
3359  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3360  range),q);
3361  p+=GetPixelChannels(image);
3362  q+=quantum_info->pad;
3363  }
3364  break;
3365  }
3366  }
3367 }
3368 
3369 static void ExportRGBAQuantum(const Image *image,QuantumInfo *quantum_info,
3370  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
3371  unsigned char *magick_restrict q)
3372 {
3373  QuantumAny
3374  range;
3375 
3376  ssize_t
3377  x;
3378 
3379  switch (quantum_info->depth)
3380  {
3381  case 8:
3382  {
3383  unsigned char
3384  pixel;
3385 
3386  for (x=0; x < (ssize_t) number_pixels; x++)
3387  {
3388  pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3389  q=PopCharPixel(pixel,q);
3390  pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3391  q=PopCharPixel(pixel,q);
3392  pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3393  q=PopCharPixel(pixel,q);
3394  pixel=ScaleQuantumToChar(GetPixelAlpha(image,p));
3395  q=PopCharPixel(pixel,q);
3396  p+=GetPixelChannels(image);
3397  q+=quantum_info->pad;
3398  }
3399  break;
3400  }
3401  case 10:
3402  {
3403  unsigned int
3404  pixel;
3405 
3406  range=GetQuantumRange(quantum_info->depth);
3407  if (quantum_info->pack == MagickFalse)
3408  {
3409  ssize_t
3410  i;
3411 
3412  size_t
3413  quantum;
3414 
3415  ssize_t
3416  n;
3417 
3418  n=0;
3419  quantum=0;
3420  pixel=0;
3421  for (x=0; x < (ssize_t) number_pixels; x++)
3422  {
3423  for (i=0; i < 4; i++)
3424  {
3425  switch (i)
3426  {
3427  case 0: quantum=(size_t) GetPixelRed(image,p); break;
3428  case 1: quantum=(size_t) GetPixelGreen(image,p); break;
3429  case 2: quantum=(size_t) GetPixelBlue(image,p); break;
3430  case 3: quantum=(size_t) GetPixelAlpha(image,p); break;
3431  }
3432  switch (n % 3)
3433  {
3434  case 0:
3435  {
3436  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3437  range) << 22);
3438  break;
3439  }
3440  case 1:
3441  {
3442  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3443  range) << 12);
3444  break;
3445  }
3446  case 2:
3447  {
3448  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3449  range) << 2);
3450  q=PopLongPixel(quantum_info->endian,pixel,q);
3451  pixel=0;
3452  break;
3453  }
3454  }
3455  n++;
3456  }
3457  p+=GetPixelChannels(image);
3458  q+=quantum_info->pad;
3459  }
3460  break;
3461  }
3462  if (quantum_info->quantum == 32UL)
3463  {
3464  for (x=0; x < (ssize_t) number_pixels; x++)
3465  {
3466  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3467  q=PopQuantumLongPixel(quantum_info,pixel,q);
3468  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3469  range);
3470  q=PopQuantumLongPixel(quantum_info,pixel,q);
3471  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3472  q=PopQuantumLongPixel(quantum_info,pixel,q);
3473  pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),
3474  range);
3475  q=PopQuantumLongPixel(quantum_info,pixel,q);
3476  p+=GetPixelChannels(image);
3477  q+=quantum_info->pad;
3478  }
3479  break;
3480  }
3481  for (x=0; x < (ssize_t) number_pixels; x++)
3482  {
3483  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3484  q=PopQuantumPixel(quantum_info,pixel,q);
3485  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3486  q=PopQuantumPixel(quantum_info,pixel,q);
3487  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3488  q=PopQuantumPixel(quantum_info,pixel,q);
3489  pixel=(unsigned int) ScaleQuantumToAny(GetPixelAlpha(image,p),range);
3490  q=PopQuantumPixel(quantum_info,pixel,q);
3491  p+=GetPixelChannels(image);
3492  q+=quantum_info->pad;
3493  }
3494  break;
3495  }
3496  case 16:
3497  {
3498  unsigned short
3499  pixel;
3500 
3501  if (quantum_info->format == FloatingPointQuantumFormat)
3502  {
3503  for (x=0; x < (ssize_t) number_pixels; x++)
3504  {
3506  q=PopShortPixel(quantum_info->endian,pixel,q);
3508  q=PopShortPixel(quantum_info->endian,pixel,q);
3510  q=PopShortPixel(quantum_info->endian,pixel,q);
3512  q=PopShortPixel(quantum_info->endian,pixel,q);
3513  p+=GetPixelChannels(image);
3514  q+=quantum_info->pad;
3515  }
3516  break;
3517  }
3518  for (x=0; x < (ssize_t) number_pixels; x++)
3519  {
3520  pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3521  q=PopShortPixel(quantum_info->endian,pixel,q);
3522  pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3523  q=PopShortPixel(quantum_info->endian,pixel,q);
3524  pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3525  q=PopShortPixel(quantum_info->endian,pixel,q);
3526  pixel=ScaleQuantumToShort(GetPixelAlpha(image,p));
3527  q=PopShortPixel(quantum_info->endian,pixel,q);
3528  p+=GetPixelChannels(image);
3529  q+=quantum_info->pad;
3530  }
3531  break;
3532  }
3533  case 32:
3534  {
3535  unsigned int
3536  pixel;
3537 
3538  if (quantum_info->format == FloatingPointQuantumFormat)
3539  {
3540  for (x=0; x < (ssize_t) number_pixels; x++)
3541  {
3542  float
3543  float_pixel;
3544 
3545  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),q);
3546  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),q);
3547  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),q);
3548  float_pixel=(float) GetPixelAlpha(image,p);
3549  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
3550  p+=GetPixelChannels(image);
3551  q+=quantum_info->pad;
3552  }
3553  break;
3554  }
3555  for (x=0; x < (ssize_t) number_pixels; x++)
3556  {
3557  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3558  q=PopLongPixel(quantum_info->endian,pixel,q);
3559  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3560  q=PopLongPixel(quantum_info->endian,pixel,q);
3561  pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3562  q=PopLongPixel(quantum_info->endian,pixel,q);
3563  pixel=ScaleQuantumToLong(GetPixelAlpha(image,p));
3564  q=PopLongPixel(quantum_info->endian,pixel,q);
3565  p+=GetPixelChannels(image);
3566  q+=quantum_info->pad;
3567  }
3568  break;
3569  }
3570  case 64:
3571  {
3572  if (quantum_info->format == FloatingPointQuantumFormat)
3573  {
3574  double
3575  pixel;
3576 
3577  for (x=0; x < (ssize_t) number_pixels; x++)
3578  {
3579  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelRed(image,p),q);
3580  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelGreen(image,p),q);
3581  q=PopQuantumDoublePixel(quantum_info,(double) GetPixelBlue(image,p),q);
3582  pixel=(double) GetPixelAlpha(image,p);
3583  q=PopQuantumDoublePixel(quantum_info,pixel,q);
3584  p+=GetPixelChannels(image);
3585  q+=quantum_info->pad;
3586  }
3587  break;
3588  }
3589  }
3590  default:
3591  {
3592  range=GetQuantumRange(quantum_info->depth);
3593  for (x=0; x < (ssize_t) number_pixels; x++)
3594  {
3595  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3596  range),q);
3597  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3598  range),q);
3599  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3600  range),q);
3601  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelAlpha(image,p),
3602  range),q);
3603  p+=GetPixelChannels(image);
3604  q+=quantum_info->pad;
3605  }
3606  break;
3607  }
3608  }
3609 }
3610 
3611 static void ExportRGBOQuantum(const Image *image,QuantumInfo *quantum_info,
3612  const MagickSizeType number_pixels,const Quantum *magick_restrict p,
3613  unsigned char *magick_restrict q)
3614 {
3615  QuantumAny
3616  range;
3617 
3618  ssize_t
3619  x;
3620 
3621  switch (quantum_info->depth)
3622  {
3623  case 8:
3624  {
3625  unsigned char
3626  pixel;
3627 
3628  for (x=0; x < (ssize_t) number_pixels; x++)
3629  {
3630  pixel=ScaleQuantumToChar(GetPixelRed(image,p));
3631  q=PopCharPixel(pixel,q);
3632  pixel=ScaleQuantumToChar(GetPixelGreen(image,p));
3633  q=PopCharPixel(pixel,q);
3634  pixel=ScaleQuantumToChar(GetPixelBlue(image,p));
3635  q=PopCharPixel(pixel,q);
3636  pixel=ScaleQuantumToChar(GetPixelOpacity(image,p));
3637  q=PopCharPixel(pixel,q);
3638  p+=GetPixelChannels(image);
3639  q+=quantum_info->pad;
3640  }
3641  break;
3642  }
3643  case 10:
3644  {
3645  unsigned int
3646  pixel;
3647 
3648  range=GetQuantumRange(quantum_info->depth);
3649  if (quantum_info->pack == MagickFalse)
3650  {
3651  ssize_t
3652  i;
3653 
3654  size_t
3655  quantum;
3656 
3657  ssize_t
3658  n;
3659 
3660  n=0;
3661  quantum=0;
3662  pixel=0;
3663  for (x=0; x < (ssize_t) number_pixels; x++)
3664  {
3665  for (i=0; i < 4; i++)
3666  {
3667  switch (i)
3668  {
3669  case 0: quantum=(size_t) GetPixelRed(image,p); break;
3670  case 1: quantum=(size_t) GetPixelGreen(image,p); break;
3671  case 2: quantum=(size_t) GetPixelBlue(image,p); break;
3672  case 3: quantum=(size_t) GetPixelOpacity(image,p); break;
3673  }
3674  switch (n % 3)
3675  {
3676  case 0:
3677  {
3678  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3679  range) << 22);
3680  break;
3681  }
3682  case 1:
3683  {
3684  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3685  range) << 12);
3686  break;
3687  }
3688  case 2:
3689  {
3690  pixel|=(size_t) (ScaleQuantumToAny((Quantum) quantum,
3691  range) << 2);
3692  q=PopLongPixel(quantum_info->endian,pixel,q);
3693  pixel=0;
3694  break;
3695  }
3696  }
3697  n++;
3698  }
3699  p+=GetPixelChannels(image);
3700  q+=quantum_info->pad;
3701  }
3702  break;
3703  }
3704  if (quantum_info->quantum == 32UL)
3705  {
3706  for (x=0; x < (ssize_t) number_pixels; x++)
3707  {
3708  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3709  q=PopQuantumLongPixel(quantum_info,pixel,q);
3710  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),
3711  range);
3712  q=PopQuantumLongPixel(quantum_info,pixel,q);
3713  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3714  q=PopQuantumLongPixel(quantum_info,pixel,q);
3715  pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),
3716  range);
3717  q=PopQuantumLongPixel(quantum_info,pixel,q);
3718  p+=GetPixelChannels(image);
3719  q+=quantum_info->pad;
3720  }
3721  break;
3722  }
3723  for (x=0; x < (ssize_t) number_pixels; x++)
3724  {
3725  pixel=(unsigned int) ScaleQuantumToAny(GetPixelRed(image,p),range);
3726  q=PopQuantumPixel(quantum_info,pixel,q);
3727  pixel=(unsigned int) ScaleQuantumToAny(GetPixelGreen(image,p),range);
3728  q=PopQuantumPixel(quantum_info,pixel,q);
3729  pixel=(unsigned int) ScaleQuantumToAny(GetPixelBlue(image,p),range);
3730  q=PopQuantumPixel(quantum_info,pixel,q);
3731  pixel=(unsigned int) ScaleQuantumToAny(GetPixelOpacity(image,p),range);
3732  q=PopQuantumPixel(quantum_info,pixel,q);
3733  p+=GetPixelChannels(image);
3734  q+=quantum_info->pad;
3735  }
3736  break;
3737  }
3738  case 16:
3739  {
3740  unsigned short
3741  pixel;
3742 
3743  if (quantum_info->format == FloatingPointQuantumFormat)
3744  {
3745  for (x=0; x < (ssize_t) number_pixels; x++)
3746  {
3748  q=PopShortPixel(quantum_info->endian,pixel,q);
3750  q=PopShortPixel(quantum_info->endian,pixel,q);
3752  q=PopShortPixel(quantum_info->endian,pixel,q);
3754  q=PopShortPixel(quantum_info->endian,pixel,q);
3755  p+=GetPixelChannels(image);
3756  q+=quantum_info->pad;
3757  }
3758  break;
3759  }
3760  for (x=0; x < (ssize_t) number_pixels; x++)
3761  {
3762  pixel=ScaleQuantumToShort(GetPixelRed(image,p));
3763  q=PopShortPixel(quantum_info->endian,pixel,q);
3764  pixel=ScaleQuantumToShort(GetPixelGreen(image,p));
3765  q=PopShortPixel(quantum_info->endian,pixel,q);
3766  pixel=ScaleQuantumToShort(GetPixelBlue(image,p));
3767  q=PopShortPixel(quantum_info->endian,pixel,q);
3768  pixel=ScaleQuantumToShort(GetPixelOpacity(image,p));
3769  q=PopShortPixel(quantum_info->endian,pixel,q);
3770  p+=GetPixelChannels(image);
3771  q+=quantum_info->pad;
3772  }
3773  break;
3774  }
3775  case 32:
3776  {
3777  unsigned int
3778  pixel;
3779 
3780  if (quantum_info->format == FloatingPointQuantumFormat)
3781  {
3782  for (x=0; x < (ssize_t) number_pixels; x++)
3783  {
3784  float
3785  float_pixel;
3786 
3787  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelRed(image,p),
3788  q);
3789  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelGreen(image,p),
3790  q);
3791  q=PopQuantumFloatPixel(quantum_info,(float) GetPixelBlue(image,p),
3792  q);
3793  float_pixel=(float) GetPixelOpacity(image,p);
3794  q=PopQuantumFloatPixel(quantum_info,float_pixel,q);
3795  p+=GetPixelChannels(image);
3796  q+=quantum_info->pad;
3797  }
3798  break;
3799  }
3800  for (x=0; x < (ssize_t) number_pixels; x++)
3801  {
3802  pixel=ScaleQuantumToLong(GetPixelRed(image,p));
3803  q=PopLongPixel(quantum_info->endian,pixel,q);
3804  pixel=ScaleQuantumToLong(GetPixelGreen(image,p));
3805  q=PopLongPixel(quantum_info->endian,pixel,q);
3806  pixel=ScaleQuantumToLong(GetPixelBlue(image,p));
3807  q=PopLongPixel(quantum_info->endian,pixel,q);
3808  pixel=ScaleQuantumToLong(GetPixelOpacity(image,p));
3809  q=PopLongPixel(quantum_info->endian,pixel,q);
3810  p+=GetPixelChannels(image);
3811  q+=quantum_info->pad;
3812  }
3813  break;
3814  }
3815  case 64:
3816  {
3817  if (quantum_info->format == FloatingPointQuantumFormat)
3818  {
3819  double
3820  pixel;
3821 
3822  for (x=0; x < (ssize_t) number_pixels; x++)
3823  {
3824  q=PopQuantumDoublePixel(quantum_info,(double)
3825  GetPixelRed(image,p),q);
3826  q=PopQuantumDoublePixel(quantum_info,(double)
3827  GetPixelGreen(image,p),q);
3828  q=PopQuantumDoublePixel(quantum_info,(double)
3829  GetPixelBlue(image,p),q);
3830  pixel=(double) GetPixelOpacity(image,p);
3831  q=PopQuantumDoublePixel(quantum_info,pixel,q);
3832  p+=GetPixelChannels(image);
3833  q+=quantum_info->pad;
3834  }
3835  break;
3836  }
3837  }
3838  default:
3839  {
3840  range=GetQuantumRange(quantum_info->depth);
3841  for (x=0; x < (ssize_t) number_pixels; x++)
3842  {
3843  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelRed(image,p),
3844  range),q);
3845  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelGreen(image,p),
3846  range),q);
3847  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelBlue(image,p),
3848  range),q);
3849  q=PopQuantumPixel(quantum_info,ScaleQuantumToAny(GetPixelOpacity(image,p),
3850  range),q);
3851  p+=GetPixelChannels(image);
3852  q+=quantum_info->pad;
3853  }
3854  break;
3855  }
3856  }
3857 }
3858 
3860  CacheView *image_view,QuantumInfo *quantum_info,
3861  const QuantumType quantum_type,unsigned char *magick_restrict pixels,
3862  ExceptionInfo *exception)
3863 {
3865  number_pixels;
3866 
3867  const Quantum
3868  *magick_restrict p;
3869 
3870  size_t
3871  extent;
3872 
3873  ssize_t
3874  x;
3875 
3876  unsigned char
3877  *magick_restrict q;
3878 
3879  assert(image != (Image *) NULL);
3880  assert(image->signature == MagickCoreSignature);
3881  if (image->debug != MagickFalse)
3882  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
3883  assert(quantum_info != (QuantumInfo *) NULL);
3884  assert(quantum_info->signature == MagickCoreSignature);
3885  if (pixels == (unsigned char *) NULL)
3886  pixels=(unsigned char *) GetQuantumPixels(quantum_info);
3887  if (image_view == (CacheView *) NULL)
3888  {
3889  number_pixels=GetImageExtent(image);
3890  p=GetVirtualPixelQueue(image);
3891  }
3892  else
3893  {
3894  number_pixels=GetCacheViewExtent(image_view);
3895  p=GetCacheViewVirtualPixelQueue(image_view);
3896  }
3897  if (quantum_info->alpha_type == AssociatedQuantumAlpha)
3898  {
3899  double
3900  Sa;
3901 
3902  Quantum
3903  *magick_restrict r;
3904 
3905  /*
3906  Associate alpha.
3907  */
3908  if (image_view != (CacheView *) NULL)
3909  r=GetCacheViewAuthenticPixelQueue(image_view);
3910  else
3911  r=GetAuthenticPixelQueue(image);
3912  for (x=0; x < (ssize_t) image->columns; x++)
3913  {
3914  ssize_t
3915  i;
3916 
3917  Sa=QuantumScale*GetPixelAlpha(image,r);
3918  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
3919  {
3920  PixelChannel channel = GetPixelChannelChannel(image,i);
3921  PixelTrait traits = GetPixelChannelTraits(image,channel);
3922  if ((traits & UpdatePixelTrait) == 0)
3923  continue;
3924  r[i]=ClampToQuantum(Sa*r[i]);
3925  }
3926  r+=GetPixelChannels(image);
3927  }
3928  }
3929  if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
3930  {
3931  Quantum
3932  quantum;
3933 
3934  Quantum
3935  *magick_restrict r;
3936 
3937  if (image_view != (CacheView *) NULL)
3938  r=GetAuthenticPixelQueue(image);
3939  else
3940  r=GetAuthenticPixelQueue(image);
3941  for (x=0; x < (ssize_t) number_pixels; x++)
3942  {
3943  quantum=GetPixelRed(image,r);
3944  SetPixelRed(image,GetPixelGreen(image,r),r);
3945  SetPixelGreen(image,quantum,r);
3946  r+=GetPixelChannels(image);
3947  }
3948  }
3949  q=pixels;
3950  ResetQuantumState(quantum_info);
3951  extent=GetQuantumExtent(image,quantum_info,quantum_type);
3952  switch (quantum_type)
3953  {
3954  case AlphaQuantum:
3955  {
3956  ExportAlphaQuantum(image,quantum_info,number_pixels,p,q);
3957  break;
3958  }
3959  case BGRQuantum:
3960  {
3961  ExportBGRQuantum(image,quantum_info,number_pixels,p,q);
3962  break;
3963  }
3964  case BGRAQuantum:
3965  {
3966  ExportBGRAQuantum(image,quantum_info,number_pixels,p,q);
3967  break;
3968  }
3969  case BGROQuantum:
3970  {
3971  ExportBGROQuantum(image,quantum_info,number_pixels,p,q);
3972  break;
3973  }
3974  case BlackQuantum:
3975  {
3976  ExportBlackQuantum(image,quantum_info,number_pixels,p,q,exception);
3977  break;
3978  }
3979  case BlueQuantum:
3980  case YellowQuantum:
3981  {
3982  ExportBlueQuantum(image,quantum_info,number_pixels,p,q);
3983  break;
3984  }
3985  case CMYKQuantum:
3986  {
3987  ExportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception);
3988  break;
3989  }
3990  case CMYKAQuantum:
3991  {
3992  ExportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception);
3993  break;
3994  }
3995  case CMYKOQuantum:
3996  {
3997  ExportCMYKOQuantum(image,quantum_info,number_pixels,p,q,exception);
3998  break;
3999  }
4000  case CbYCrYQuantum:
4001  {
4002  ExportCbYCrYQuantum(image,quantum_info,number_pixels,p,q);
4003  break;
4004  }
4005  case GrayQuantum:
4006  {
4007  ExportGrayQuantum(image,quantum_info,number_pixels,p,q);
4008  break;
4009  }
4010  case GrayAlphaQuantum:
4011  {
4012  ExportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q);
4013  break;
4014  }
4015  case GreenQuantum:
4016  case MagentaQuantum:
4017  {
4018  ExportGreenQuantum(image,quantum_info,number_pixels,p,q);
4019  break;
4020  }
4021  case IndexQuantum:
4022  {
4023  ExportIndexQuantum(image,quantum_info,number_pixels,p,q,exception);
4024  break;
4025  }
4026  case IndexAlphaQuantum:
4027  {
4028  ExportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
4029  break;
4030  }
4031  case RedQuantum:
4032  case CyanQuantum:
4033  {
4034  ExportRedQuantum(image,quantum_info,number_pixels,p,q);
4035  break;
4036  }
4037  case OpacityQuantum:
4038  {
4039  ExportOpacityQuantum(image,quantum_info,number_pixels,p,q);
4040  break;
4041  }
4042  case RGBQuantum:
4043  case CbYCrQuantum:
4044  {
4045  ExportRGBQuantum(image,quantum_info,number_pixels,p,q);
4046  break;
4047  }
4048  case RGBAQuantum:
4049  case CbYCrAQuantum:
4050  {
4051  ExportRGBAQuantum(image,quantum_info,number_pixels,p,q);
4052  break;
4053  }
4054  case RGBOQuantum:
4055  {
4056  ExportRGBOQuantum(image,quantum_info,number_pixels,p,q);
4057  break;
4058  }
4059  default:
4060  break;
4061  }
4062  if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
4063  {
4064  Quantum
4065  quantum;
4066 
4067  Quantum
4068  *magick_restrict r;
4069 
4070  if (image_view != (CacheView *) NULL)
4071  r=GetCacheViewAuthenticPixelQueue(image_view);
4072  else
4073  r=GetAuthenticPixelQueue(image);
4074  for (x=0; x < (ssize_t) number_pixels; x++)
4075  {
4076  quantum=GetPixelRed(image,r);
4077  SetPixelRed(image,GetPixelGreen(image,r),r);
4078  SetPixelGreen(image,quantum,r);
4079  r+=GetPixelChannels(image);
4080  }
4081  }
4082  return(extent);
4083 }
MagickExport Quantum * GetAuthenticPixelQueue(const Image *image)
Definition: cache.c:1424
#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:448
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:601
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:579
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:85
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)
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)
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)
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:1662
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:489
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:1600
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:3184
unsigned short Quantum
Definition: magick-type.h:86
MagickExport Quantum * GetCacheViewAuthenticPixelQueue(CacheView *cache_view)
Definition: cache-view.c:379
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 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:137
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
MagickBooleanType debug
Definition: image.h:334
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