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