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