MagickCore  7.1.0
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-2021 ImageMagick Studio LLC, a non-profit organization %
26 % dedicated to making software imaging solutions freely available. %
27 % %
28 % You may not use this file except in compliance with the License. You may %
29 % obtain a copy of the License at %
30 % %
31 % https://imagemagick.org/script/license.php %
32 % %
33 % Unless required by applicable law or agreed to in writing, software %
34 % distributed under the License is distributed on an "AS IS" BASIS, %
35 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
36 % See the License for the specific language governing permissions and %
37 % limitations under the License. %
38 % %
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 %
41 %
42 */
43 
44 /*
45  Include declarations.
46 */
47 #include "MagickCore/studio.h"
48 #include "MagickCore/property.h"
49 #include "MagickCore/blob.h"
52 #include "MagickCore/exception.h"
54 #include "MagickCore/cache.h"
55 #include "MagickCore/constitute.h"
56 #include "MagickCore/delegate.h"
57 #include "MagickCore/geometry.h"
58 #include "MagickCore/list.h"
59 #include "MagickCore/magick.h"
60 #include "MagickCore/memory_.h"
61 #include "MagickCore/monitor.h"
62 #include "MagickCore/option.h"
63 #include "MagickCore/pixel.h"
65 #include "MagickCore/quantum.h"
67 #include "MagickCore/resource_.h"
68 #include "MagickCore/semaphore.h"
69 #include "MagickCore/statistic.h"
70 #include "MagickCore/stream.h"
71 #include "MagickCore/string_.h"
72 #include "MagickCore/utility.h"
73 
74 /*
75 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % %
77 % %
78 % %
79 % 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 ImportOpacityQuantum(const Image *image,QuantumInfo *quantum_info,
3496  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3498 {
3499  QuantumAny
3500  range;
3501 
3502  ssize_t
3503  x;
3504 
3505  assert(image != (Image *) NULL);
3506  assert(image->signature == MagickCoreSignature);
3507  switch (quantum_info->depth)
3508  {
3509  case 8:
3510  {
3511  unsigned char
3512  pixel;
3513 
3514  for (x=0; x < (ssize_t) number_pixels; x++)
3515  {
3516  p=PushCharPixel(p,&pixel);
3517  SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
3518  p+=quantum_info->pad;
3519  q+=GetPixelChannels(image);
3520  }
3521  break;
3522  }
3523  case 16:
3524  {
3525  unsigned short
3526  pixel;
3527 
3528  if (quantum_info->format == FloatingPointQuantumFormat)
3529  {
3530  for (x=0; x < (ssize_t) number_pixels; x++)
3531  {
3532  p=PushShortPixel(quantum_info->endian,p,&pixel);
3534  HalfToSinglePrecision(pixel)),q);
3535  p+=quantum_info->pad;
3536  q+=GetPixelChannels(image);
3537  }
3538  break;
3539  }
3540  for (x=0; x < (ssize_t) number_pixels; x++)
3541  {
3542  p=PushShortPixel(quantum_info->endian,p,&pixel);
3543  SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
3544  p+=quantum_info->pad;
3545  q+=GetPixelChannels(image);
3546  }
3547  break;
3548  }
3549  case 24:
3550  {
3551  if (quantum_info->format == FloatingPointQuantumFormat)
3552  {
3553  float
3554  pixel;
3555 
3556  for (x=0; x < (ssize_t) number_pixels; x++)
3557  {
3558  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3559  SetPixelOpacity(image,ClampToQuantum(pixel),q);
3560  p+=quantum_info->pad;
3561  q+=GetPixelChannels(image);
3562  }
3563  break;
3564  }
3565  }
3566  case 32:
3567  {
3568  if (quantum_info->format == FloatingPointQuantumFormat)
3569  {
3570  float
3571  pixel;
3572 
3573  for (x=0; x < (ssize_t) number_pixels; x++)
3574  {
3575  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3576  SetPixelOpacity(image,ClampToQuantum(pixel),q);
3577  p+=quantum_info->pad;
3578  q+=GetPixelChannels(image);
3579  }
3580  break;
3581  }
3582  else
3583  {
3584  unsigned int
3585  pixel;
3586 
3587  for (x=0; x < (ssize_t) number_pixels; x++)
3588  {
3589  p=PushLongPixel(quantum_info->endian,p,&pixel);
3590  SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
3591  p+=quantum_info->pad;
3592  q+=GetPixelChannels(image);
3593  }
3594  break;
3595  }
3596  }
3597  case 64:
3598  {
3599  if (quantum_info->format == FloatingPointQuantumFormat)
3600  {
3601  double
3602  pixel;
3603 
3604  for (x=0; x < (ssize_t) number_pixels; x++)
3605  {
3606  p=PushDoublePixel(quantum_info,p,&pixel);
3607  SetPixelOpacity(image,ClampToQuantum(pixel),q);
3608  p+=quantum_info->pad;
3609  q+=GetPixelChannels(image);
3610  }
3611  break;
3612  }
3613  }
3614  default:
3615  {
3616  unsigned int
3617  pixel;
3618 
3619  range=GetQuantumRange(quantum_info->depth);
3620  for (x=0; x < (ssize_t) number_pixels; x++)
3621  {
3622  p=PushQuantumPixel(quantum_info,p,&pixel);
3623  SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
3624  p+=quantum_info->pad;
3625  q+=GetPixelChannels(image);
3626  }
3627  break;
3628  }
3629  }
3630 }
3631 
3632 static void ImportRedQuantum(const Image *image,QuantumInfo *quantum_info,
3633  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3635 {
3636  QuantumAny
3637  range;
3638 
3639  ssize_t
3640  x;
3641 
3642  assert(image != (Image *) NULL);
3643  assert(image->signature == MagickCoreSignature);
3644  switch (quantum_info->depth)
3645  {
3646  case 8:
3647  {
3648  unsigned char
3649  pixel;
3650 
3651  for (x=0; x < (ssize_t) number_pixels; x++)
3652  {
3653  p=PushCharPixel(p,&pixel);
3654  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3655  p+=quantum_info->pad;
3656  q+=GetPixelChannels(image);
3657  }
3658  break;
3659  }
3660  case 16:
3661  {
3662  unsigned short
3663  pixel;
3664 
3665  if (quantum_info->format == FloatingPointQuantumFormat)
3666  {
3667  for (x=0; x < (ssize_t) number_pixels; x++)
3668  {
3669  p=PushShortPixel(quantum_info->endian,p,&pixel);
3671  HalfToSinglePrecision(pixel)),q);
3672  p+=quantum_info->pad;
3673  q+=GetPixelChannels(image);
3674  }
3675  break;
3676  }
3677  for (x=0; x < (ssize_t) number_pixels; x++)
3678  {
3679  p=PushShortPixel(quantum_info->endian,p,&pixel);
3680  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
3681  p+=quantum_info->pad;
3682  q+=GetPixelChannels(image);
3683  }
3684  break;
3685  }
3686  case 24:
3687  {
3688  if (quantum_info->format == FloatingPointQuantumFormat)
3689  {
3690  float
3691  pixel;
3692 
3693  for (x=0; x < (ssize_t) number_pixels; x++)
3694  {
3695  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
3696  SetPixelRed(image,ClampToQuantum(pixel),q);
3697  p+=quantum_info->pad;
3698  q+=GetPixelChannels(image);
3699  }
3700  break;
3701  }
3702  }
3703  case 32:
3704  {
3705  if (quantum_info->format == FloatingPointQuantumFormat)
3706  {
3707  float
3708  pixel;
3709 
3710  for (x=0; x < (ssize_t) number_pixels; x++)
3711  {
3712  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
3713  SetPixelRed(image,ClampToQuantum(pixel),q);
3714  p+=quantum_info->pad;
3715  q+=GetPixelChannels(image);
3716  }
3717  break;
3718  }
3719  else
3720  {
3721  unsigned int
3722  pixel;
3723 
3724  for (x=0; x < (ssize_t) number_pixels; x++)
3725  {
3726  p=PushLongPixel(quantum_info->endian,p,&pixel);
3727  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
3728  p+=quantum_info->pad;
3729  q+=GetPixelChannels(image);
3730  }
3731  break;
3732  }
3733  }
3734  case 64:
3735  {
3736  if (quantum_info->format == FloatingPointQuantumFormat)
3737  {
3738  double
3739  pixel;
3740 
3741  for (x=0; x < (ssize_t) number_pixels; x++)
3742  {
3743  p=PushDoublePixel(quantum_info,p,&pixel);
3744  SetPixelRed(image,ClampToQuantum(pixel),q);
3745  p+=quantum_info->pad;
3746  q+=GetPixelChannels(image);
3747  }
3748  break;
3749  }
3750  }
3751  default:
3752  {
3753  unsigned int
3754  pixel;
3755 
3756  range=GetQuantumRange(quantum_info->depth);
3757  for (x=0; x < (ssize_t) number_pixels; x++)
3758  {
3759  p=PushQuantumPixel(quantum_info,p,&pixel);
3760  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3761  p+=quantum_info->pad;
3762  q+=GetPixelChannels(image);
3763  }
3764  break;
3765  }
3766  }
3767 }
3768 
3769 static void ImportRGBQuantum(const Image *image,QuantumInfo *quantum_info,
3770  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
3772 {
3773  QuantumAny
3774  range;
3775 
3776  ssize_t
3777  x;
3778 
3779  ssize_t
3780  bit;
3781 
3782  assert(image != (Image *) NULL);
3783  assert(image->signature == MagickCoreSignature);
3784  switch (quantum_info->depth)
3785  {
3786  case 8:
3787  {
3788  unsigned char
3789  pixel;
3790 
3791  for (x=0; x < (ssize_t) number_pixels; x++)
3792  {
3793  p=PushCharPixel(p,&pixel);
3794  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
3795  p=PushCharPixel(p,&pixel);
3796  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
3797  p=PushCharPixel(p,&pixel);
3798  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
3799  SetPixelAlpha(image,OpaqueAlpha,q);
3800  p+=quantum_info->pad;
3801  q+=GetPixelChannels(image);
3802  }
3803  break;
3804  }
3805  case 10:
3806  {
3807  unsigned int
3808  pixel;
3809 
3810  range=GetQuantumRange(quantum_info->depth);
3811  if (quantum_info->pack == MagickFalse)
3812  {
3813  for (x=0; x < (ssize_t) number_pixels; x++)
3814  {
3815  p=PushLongPixel(quantum_info->endian,p,&pixel);
3816  SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
3817  SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
3818  q);
3819  SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
3820  p+=quantum_info->pad;
3821  q+=GetPixelChannels(image);
3822  }
3823  break;
3824  }
3825  if (quantum_info->quantum == 32U)
3826  {
3827  for (x=0; x < (ssize_t) number_pixels; x++)
3828  {
3829  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3830  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3831  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3832  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3833  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3834  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3835  q+=GetPixelChannels(image);
3836  }
3837  break;
3838  }
3839  for (x=0; x < (ssize_t) number_pixels; x++)
3840  {
3841  p=PushQuantumPixel(quantum_info,p,&pixel);
3842  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3843  p=PushQuantumPixel(quantum_info,p,&pixel);
3844  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3845  p=PushQuantumPixel(quantum_info,p,&pixel);
3846  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3847  q+=GetPixelChannels(image);
3848  }
3849  break;
3850  }
3851  case 12:
3852  {
3853  range=GetQuantumRange(quantum_info->depth);
3854  if (quantum_info->pack == MagickFalse)
3855  {
3856  unsigned short
3857  pixel;
3858 
3859  for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
3860  {
3861  p=PushShortPixel(quantum_info->endian,p,&pixel);
3862  switch (x % 3)
3863  {
3864  default:
3865  case 0:
3866  {
3867  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3868  range),q);
3869  break;
3870  }
3871  case 1:
3872  {
3873  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3874  range),q);
3875  break;
3876  }
3877  case 2:
3878  {
3879  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3880  range),q);
3881  q+=GetPixelChannels(image);
3882  break;
3883  }
3884  }
3885  p=PushShortPixel(quantum_info->endian,p,&pixel);
3886  switch ((x+1) % 3)
3887  {
3888  default:
3889  case 0:
3890  {
3891  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3892  range),q);
3893  break;
3894  }
3895  case 1:
3896  {
3897  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3898  range),q);
3899  break;
3900  }
3901  case 2:
3902  {
3903  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3904  range),q);
3905  q+=GetPixelChannels(image);
3906  break;
3907  }
3908  }
3909  p+=quantum_info->pad;
3910  }
3911  for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
3912  {
3913  p=PushShortPixel(quantum_info->endian,p,&pixel);
3914  switch ((x+bit) % 3)
3915  {
3916  default:
3917  case 0:
3918  {
3919  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3920  range),q);
3921  break;
3922  }
3923  case 1:
3924  {
3925  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3926  range),q);
3927  break;
3928  }
3929  case 2:
3930  {
3931  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
3932  range),q);
3933  q+=GetPixelChannels(image);
3934  break;
3935  }
3936  }
3937  p+=quantum_info->pad;
3938  }
3939  if (bit != 0)
3940  p++;
3941  break;
3942  }
3943  else
3944  {
3945  unsigned int
3946  pixel;
3947 
3948  if (quantum_info->quantum == 32U)
3949  {
3950  for (x=0; x < (ssize_t) number_pixels; x++)
3951  {
3952  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3953  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3954  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3955  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3956  p=PushQuantumLongPixel(quantum_info,p,&pixel);
3957  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3958  q+=GetPixelChannels(image);
3959  }
3960  break;
3961  }
3962  for (x=0; x < (ssize_t) number_pixels; x++)
3963  {
3964  p=PushQuantumPixel(quantum_info,p,&pixel);
3965  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
3966  p=PushQuantumPixel(quantum_info,p,&pixel);
3967  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
3968  p=PushQuantumPixel(quantum_info,p,&pixel);
3969  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
3970  q+=GetPixelChannels(image);
3971  }
3972  break;
3973  }
3974  }
3975  case 16:
3976  {
3977  unsigned short
3978  pixel;
3979 
3980  if (quantum_info->format == FloatingPointQuantumFormat)
3981  {
3982  for (x=0; x < (ssize_t) number_pixels; x++)
3983  {
3984  p=PushShortPixel(quantum_info->endian,p,&pixel);
3986  HalfToSinglePrecision(pixel)),q);
3987  p=PushShortPixel(quantum_info->endian,p,&pixel);
3989  HalfToSinglePrecision(pixel)),q);
3990  p=PushShortPixel(quantum_info->endian,p,&pixel);
3992  HalfToSinglePrecision(pixel)),q);
3993  p+=quantum_info->pad;
3994  q+=GetPixelChannels(image);
3995  }
3996  break;
3997  }
3998  for (x=0; x < (ssize_t) number_pixels; x++)
3999  {
4000  p=PushShortPixel(quantum_info->endian,p,&pixel);
4001  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4002  p=PushShortPixel(quantum_info->endian,p,&pixel);
4003  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4004  p=PushShortPixel(quantum_info->endian,p,&pixel);
4005  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4006  p+=quantum_info->pad;
4007  q+=GetPixelChannels(image);
4008  }
4009  break;
4010  }
4011  case 24:
4012  {
4013  if (quantum_info->format == FloatingPointQuantumFormat)
4014  {
4015  float
4016  pixel;
4017 
4018  for (x=0; x < (ssize_t) number_pixels; x++)
4019  {
4020  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4021  SetPixelRed(image,ClampToQuantum(pixel),q);
4022  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4023  SetPixelGreen(image,ClampToQuantum(pixel),q);
4024  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4025  SetPixelBlue(image,ClampToQuantum(pixel),q);
4026  p+=quantum_info->pad;
4027  q+=GetPixelChannels(image);
4028  }
4029  break;
4030  }
4031  }
4032  case 32:
4033  {
4034  if (quantum_info->format == FloatingPointQuantumFormat)
4035  {
4036  float
4037  pixel;
4038 
4039  for (x=0; x < (ssize_t) number_pixels; x++)
4040  {
4041  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4042  SetPixelRed(image,ClampToQuantum(pixel),q);
4043  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4044  SetPixelGreen(image,ClampToQuantum(pixel),q);
4045  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4046  SetPixelBlue(image,ClampToQuantum(pixel),q);
4047  p+=quantum_info->pad;
4048  q+=GetPixelChannels(image);
4049  }
4050  break;
4051  }
4052  else
4053  {
4054  unsigned int
4055  pixel;
4056 
4057  for (x=0; x < (ssize_t) number_pixels; x++)
4058  {
4059  p=PushLongPixel(quantum_info->endian,p,&pixel);
4060  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4061  p=PushLongPixel(quantum_info->endian,p,&pixel);
4062  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4063  p=PushLongPixel(quantum_info->endian,p,&pixel);
4064  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4065  p+=quantum_info->pad;
4066  q+=GetPixelChannels(image);
4067  }
4068  break;
4069  }
4070  }
4071  case 64:
4072  {
4073  if (quantum_info->format == FloatingPointQuantumFormat)
4074  {
4075  double
4076  pixel;
4077 
4078  for (x=0; x < (ssize_t) number_pixels; x++)
4079  {
4080  p=PushDoublePixel(quantum_info,p,&pixel);
4081  SetPixelRed(image,ClampToQuantum(pixel),q);
4082  p=PushDoublePixel(quantum_info,p,&pixel);
4083  SetPixelGreen(image,ClampToQuantum(pixel),q);
4084  p=PushDoublePixel(quantum_info,p,&pixel);
4085  SetPixelBlue(image,ClampToQuantum(pixel),q);
4086  p+=quantum_info->pad;
4087  q+=GetPixelChannels(image);
4088  }
4089  break;
4090  }
4091  }
4092  default:
4093  {
4094  unsigned int
4095  pixel;
4096 
4097  range=GetQuantumRange(quantum_info->depth);
4098  for (x=0; x < (ssize_t) number_pixels; x++)
4099  {
4100  p=PushQuantumPixel(quantum_info,p,&pixel);
4101  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4102  p=PushQuantumPixel(quantum_info,p,&pixel);
4103  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4104  p=PushQuantumPixel(quantum_info,p,&pixel);
4105  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4106  q+=GetPixelChannels(image);
4107  }
4108  break;
4109  }
4110  }
4111 }
4112 
4113 static void ImportRGBAQuantum(const Image *image,QuantumInfo *quantum_info,
4114  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
4116 {
4117  QuantumAny
4118  range;
4119 
4120  ssize_t
4121  x;
4122 
4123  assert(image != (Image *) NULL);
4124  assert(image->signature == MagickCoreSignature);
4125  switch (quantum_info->depth)
4126  {
4127  case 8:
4128  {
4129  unsigned char
4130  pixel;
4131 
4132  for (x=0; x < (ssize_t) number_pixels; x++)
4133  {
4134  p=PushCharPixel(p,&pixel);
4135  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
4136  p=PushCharPixel(p,&pixel);
4137  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
4138  p=PushCharPixel(p,&pixel);
4139  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
4140  p=PushCharPixel(p,&pixel);
4141  SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
4142  p+=quantum_info->pad;
4143  q+=GetPixelChannels(image);
4144  }
4145  break;
4146  }
4147  case 10:
4148  {
4149  unsigned int
4150  pixel;
4151 
4152  pixel=0;
4153  if (quantum_info->pack == MagickFalse)
4154  {
4155  ssize_t
4156  i;
4157 
4158  size_t
4159  quantum;
4160 
4161  ssize_t
4162  n;
4163 
4164  n=0;
4165  quantum=0;
4166  for (x=0; x < (ssize_t) number_pixels; x++)
4167  {
4168  for (i=0; i < 4; i++)
4169  {
4170  switch (n % 3)
4171  {
4172  case 0:
4173  {
4174  p=PushLongPixel(quantum_info->endian,p,&pixel);
4175  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4176  (((pixel >> 22) & 0x3ff) << 6)));
4177  break;
4178  }
4179  case 1:
4180  {
4181  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4182  (((pixel >> 12) & 0x3ff) << 6)));
4183  break;
4184  }
4185  case 2:
4186  {
4187  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4188  (((pixel >> 2) & 0x3ff) << 6)));
4189  break;
4190  }
4191  }
4192  switch (i)
4193  {
4194  case 0: SetPixelRed(image,(Quantum) quantum,q); break;
4195  case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
4196  case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
4197  case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
4198  }
4199  n++;
4200  }
4201  p+=quantum_info->pad;
4202  q+=GetPixelChannels(image);
4203  }
4204  break;
4205  }
4206  for (x=0; x < (ssize_t) number_pixels; x++)
4207  {
4208  p=PushQuantumPixel(quantum_info,p,&pixel);
4209  SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
4210  p=PushQuantumPixel(quantum_info,p,&pixel);
4211  SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4212  q);
4213  p=PushQuantumPixel(quantum_info,p,&pixel);
4214  SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4215  q);
4216  p=PushQuantumPixel(quantum_info,p,&pixel);
4217  SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4218  q);
4219  q+=GetPixelChannels(image);
4220  }
4221  break;
4222  }
4223  case 16:
4224  {
4225  unsigned short
4226  pixel;
4227 
4228  if (quantum_info->format == FloatingPointQuantumFormat)
4229  {
4230  for (x=0; x < (ssize_t) number_pixels; x++)
4231  {
4232  p=PushShortPixel(quantum_info->endian,p,&pixel);
4234  HalfToSinglePrecision(pixel)),q);
4235  p=PushShortPixel(quantum_info->endian,p,&pixel);
4237  HalfToSinglePrecision(pixel)),q);
4238  p=PushShortPixel(quantum_info->endian,p,&pixel);
4240  HalfToSinglePrecision(pixel)),q);
4241  p=PushShortPixel(quantum_info->endian,p,&pixel);
4243  HalfToSinglePrecision(pixel)),q);
4244  p+=quantum_info->pad;
4245  q+=GetPixelChannels(image);
4246  }
4247  break;
4248  }
4249  for (x=0; x < (ssize_t) number_pixels; x++)
4250  {
4251  p=PushShortPixel(quantum_info->endian,p,&pixel);
4252  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4253  p=PushShortPixel(quantum_info->endian,p,&pixel);
4254  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4255  p=PushShortPixel(quantum_info->endian,p,&pixel);
4256  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4257  p=PushShortPixel(quantum_info->endian,p,&pixel);
4258  SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
4259  p+=quantum_info->pad;
4260  q+=GetPixelChannels(image);
4261  }
4262  break;
4263  }
4264  case 24:
4265  {
4266  if (quantum_info->format == FloatingPointQuantumFormat)
4267  {
4268  float
4269  pixel;
4270 
4271  for (x=0; x < (ssize_t) number_pixels; x++)
4272  {
4273  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4274  SetPixelRed(image,ClampToQuantum(pixel),q);
4275  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4276  SetPixelGreen(image,ClampToQuantum(pixel),q);
4277  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4278  SetPixelBlue(image,ClampToQuantum(pixel),q);
4279  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4280  SetPixelAlpha(image,ClampToQuantum(pixel),q);
4281  p+=quantum_info->pad;
4282  q+=GetPixelChannels(image);
4283  }
4284  break;
4285  }
4286  }
4287  case 32:
4288  {
4289  if (quantum_info->format == FloatingPointQuantumFormat)
4290  {
4291  float
4292  pixel;
4293 
4294  for (x=0; x < (ssize_t) number_pixels; x++)
4295  {
4296  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4297  SetPixelRed(image,ClampToQuantum(pixel),q);
4298  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4299  SetPixelGreen(image,ClampToQuantum(pixel),q);
4300  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4301  SetPixelBlue(image,ClampToQuantum(pixel),q);
4302  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4303  SetPixelAlpha(image,ClampToQuantum(pixel),q);
4304  p+=quantum_info->pad;
4305  q+=GetPixelChannels(image);
4306  }
4307  break;
4308  }
4309  else
4310  {
4311  unsigned int
4312  pixel;
4313 
4314  for (x=0; x < (ssize_t) number_pixels; x++)
4315  {
4316  p=PushLongPixel(quantum_info->endian,p,&pixel);
4317  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4318  p=PushLongPixel(quantum_info->endian,p,&pixel);
4319  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4320  p=PushLongPixel(quantum_info->endian,p,&pixel);
4321  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4322  p=PushLongPixel(quantum_info->endian,p,&pixel);
4323  SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
4324  p+=quantum_info->pad;
4325  q+=GetPixelChannels(image);
4326  }
4327  break;
4328  }
4329  }
4330  case 64:
4331  {
4332  if (quantum_info->format == FloatingPointQuantumFormat)
4333  {
4334  double
4335  pixel;
4336 
4337  for (x=0; x < (ssize_t) number_pixels; x++)
4338  {
4339  p=PushDoublePixel(quantum_info,p,&pixel);
4340  SetPixelRed(image,ClampToQuantum(pixel),q);
4341  p=PushDoublePixel(quantum_info,p,&pixel);
4342  SetPixelGreen(image,ClampToQuantum(pixel),q);
4343  p=PushDoublePixel(quantum_info,p,&pixel);
4344  SetPixelBlue(image,ClampToQuantum(pixel),q);
4345  p=PushDoublePixel(quantum_info,p,&pixel);
4346  SetPixelAlpha(image,ClampToQuantum(pixel),q);
4347  p+=quantum_info->pad;
4348  q+=GetPixelChannels(image);
4349  }
4350  break;
4351  }
4352  }
4353  default:
4354  {
4355  unsigned int
4356  pixel;
4357 
4358  range=GetQuantumRange(quantum_info->depth);
4359  for (x=0; x < (ssize_t) number_pixels; x++)
4360  {
4361  p=PushQuantumPixel(quantum_info,p,&pixel);
4362  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4363  p=PushQuantumPixel(quantum_info,p,&pixel);
4364  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4365  p=PushQuantumPixel(quantum_info,p,&pixel);
4366  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4367  p=PushQuantumPixel(quantum_info,p,&pixel);
4368  SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
4369  q+=GetPixelChannels(image);
4370  }
4371  break;
4372  }
4373  }
4374 }
4375 
4376 static void ImportRGBOQuantum(const Image *image,QuantumInfo *quantum_info,
4377  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
4379 {
4380  QuantumAny
4381  range;
4382 
4383  ssize_t
4384  x;
4385 
4386  assert(image != (Image *) NULL);
4387  assert(image->signature == MagickCoreSignature);
4388  switch (quantum_info->depth)
4389  {
4390  case 8:
4391  {
4392  unsigned char
4393  pixel;
4394 
4395  for (x=0; x < (ssize_t) number_pixels; x++)
4396  {
4397  p=PushCharPixel(p,&pixel);
4398  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
4399  p=PushCharPixel(p,&pixel);
4400  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
4401  p=PushCharPixel(p,&pixel);
4402  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
4403  p=PushCharPixel(p,&pixel);
4404  SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
4405  p+=quantum_info->pad;
4406  q+=GetPixelChannels(image);
4407  }
4408  break;
4409  }
4410  case 10:
4411  {
4412  unsigned int
4413  pixel;
4414 
4415  pixel=0;
4416  if (quantum_info->pack == MagickFalse)
4417  {
4418  ssize_t
4419  i;
4420 
4421  size_t
4422  quantum;
4423 
4424  ssize_t
4425  n;
4426 
4427  n=0;
4428  quantum=0;
4429  for (x=0; x < (ssize_t) number_pixels; x++)
4430  {
4431  for (i=0; i < 4; i++)
4432  {
4433  switch (n % 3)
4434  {
4435  case 0:
4436  {
4437  p=PushLongPixel(quantum_info->endian,p,&pixel);
4438  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4439  (((pixel >> 22) & 0x3ff) << 6)));
4440  break;
4441  }
4442  case 1:
4443  {
4444  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4445  (((pixel >> 12) & 0x3ff) << 6)));
4446  break;
4447  }
4448  case 2:
4449  {
4450  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
4451  (((pixel >> 2) & 0x3ff) << 6)));
4452  break;
4453  }
4454  }
4455  switch (i)
4456  {
4457  case 0: SetPixelRed(image,(Quantum) quantum,q); break;
4458  case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
4459  case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
4460  case 3: SetPixelOpacity(image,(Quantum) quantum,q); break;
4461  }
4462  n++;
4463  }
4464  p+=quantum_info->pad;
4465  q+=GetPixelChannels(image);
4466  }
4467  break;
4468  }
4469  for (x=0; x < (ssize_t) number_pixels; x++)
4470  {
4471  p=PushQuantumPixel(quantum_info,p,&pixel);
4472  SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
4473  p=PushQuantumPixel(quantum_info,p,&pixel);
4474  SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4475  q);
4476  p=PushQuantumPixel(quantum_info,p,&pixel);
4477  SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4478  q);
4479  p=PushQuantumPixel(quantum_info,p,&pixel);
4480  SetPixelOpacity(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
4481  q);
4482  q+=GetPixelChannels(image);
4483  }
4484  break;
4485  }
4486  case 16:
4487  {
4488  unsigned short
4489  pixel;
4490 
4491  if (quantum_info->format == FloatingPointQuantumFormat)
4492  {
4493  for (x=0; x < (ssize_t) number_pixels; x++)
4494  {
4495  p=PushShortPixel(quantum_info->endian,p,&pixel);
4497  HalfToSinglePrecision(pixel)),q);
4498  p=PushShortPixel(quantum_info->endian,p,&pixel);
4500  HalfToSinglePrecision(pixel)),q);
4501  p=PushShortPixel(quantum_info->endian,p,&pixel);
4503  HalfToSinglePrecision(pixel)),q);
4504  p=PushShortPixel(quantum_info->endian,p,&pixel);
4506  HalfToSinglePrecision(pixel)),q);
4507  p+=quantum_info->pad;
4508  q+=GetPixelChannels(image);
4509  }
4510  break;
4511  }
4512  for (x=0; x < (ssize_t) number_pixels; x++)
4513  {
4514  p=PushShortPixel(quantum_info->endian,p,&pixel);
4515  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
4516  p=PushShortPixel(quantum_info->endian,p,&pixel);
4517  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
4518  p=PushShortPixel(quantum_info->endian,p,&pixel);
4519  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
4520  p=PushShortPixel(quantum_info->endian,p,&pixel);
4521  SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
4522  p+=quantum_info->pad;
4523  q+=GetPixelChannels(image);
4524  }
4525  break;
4526  }
4527  case 24:
4528  {
4529  if (quantum_info->format == FloatingPointQuantumFormat)
4530  {
4531  float
4532  pixel;
4533 
4534  for (x=0; x < (ssize_t) number_pixels; x++)
4535  {
4536  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4537  SetPixelRed(image,ClampToQuantum(pixel),q);
4538  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4539  SetPixelGreen(image,ClampToQuantum(pixel),q);
4540  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4541  SetPixelBlue(image,ClampToQuantum(pixel),q);
4542  p=PushQuantumFloat24Pixel(quantum_info,p,&pixel);
4543  SetPixelOpacity(image,ClampToQuantum(pixel),q);
4544  p+=quantum_info->pad;
4545  q+=GetPixelChannels(image);
4546  }
4547  break;
4548  }
4549  }
4550  case 32:
4551  {
4552  if (quantum_info->format == FloatingPointQuantumFormat)
4553  {
4554  float
4555  pixel;
4556 
4557  for (x=0; x < (ssize_t) number_pixels; x++)
4558  {
4559  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4560  SetPixelRed(image,ClampToQuantum(pixel),q);
4561  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4562  SetPixelGreen(image,ClampToQuantum(pixel),q);
4563  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4564  SetPixelBlue(image,ClampToQuantum(pixel),q);
4565  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
4566  SetPixelOpacity(image,ClampToQuantum(pixel),q);
4567  p+=quantum_info->pad;
4568  q+=GetPixelChannels(image);
4569  }
4570  break;
4571  }
4572  else
4573  {
4574  unsigned int
4575  pixel;
4576 
4577  for (x=0; x < (ssize_t) number_pixels; x++)
4578  {
4579  p=PushLongPixel(quantum_info->endian,p,&pixel);
4580  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
4581  p=PushLongPixel(quantum_info->endian,p,&pixel);
4582  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
4583  p=PushLongPixel(quantum_info->endian,p,&pixel);
4584  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
4585  p=PushLongPixel(quantum_info->endian,p,&pixel);
4586  SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
4587  p+=quantum_info->pad;
4588  q+=GetPixelChannels(image);
4589  }
4590  break;
4591  }
4592  }
4593  case 64:
4594  {
4595  if (quantum_info->format == FloatingPointQuantumFormat)
4596  {
4597  double
4598  pixel;
4599 
4600  for (x=0; x < (ssize_t) number_pixels; x++)
4601  {
4602  p=PushDoublePixel(quantum_info,p,&pixel);
4603  SetPixelRed(image,ClampToQuantum(pixel),q);
4604  p=PushDoublePixel(quantum_info,p,&pixel);
4605  SetPixelGreen(image,ClampToQuantum(pixel),q);
4606  p=PushDoublePixel(quantum_info,p,&pixel);
4607  SetPixelBlue(image,ClampToQuantum(pixel),q);
4608  p=PushDoublePixel(quantum_info,p,&pixel);
4609  SetPixelOpacity(image,ClampToQuantum(pixel),q);
4610  p+=quantum_info->pad;
4611  q+=GetPixelChannels(image);
4612  }
4613  break;
4614  }
4615  }
4616  default:
4617  {
4618  unsigned int
4619  pixel;
4620 
4621  range=GetQuantumRange(quantum_info->depth);
4622  for (x=0; x < (ssize_t) number_pixels; x++)
4623  {
4624  p=PushQuantumPixel(quantum_info,p,&pixel);
4625  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
4626  p=PushQuantumPixel(quantum_info,p,&pixel);
4627  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
4628  p=PushQuantumPixel(quantum_info,p,&pixel);
4629  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
4630  p=PushQuantumPixel(quantum_info,p,&pixel);
4631  SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
4632  q+=GetPixelChannels(image);
4633  }
4634  break;
4635  }
4636  }
4637 }
4638 
4640  CacheView *image_view,QuantumInfo *quantum_info,
4641  const QuantumType quantum_type,const unsigned char *magick_restrict pixels,
4642  ExceptionInfo *exception)
4643 {
4645  number_pixels;
4646 
4647  const unsigned char
4648  *magick_restrict p;
4649 
4650  ssize_t
4651  x;
4652 
4653  Quantum
4654  *magick_restrict q;
4655 
4656  size_t
4657  extent;
4658 
4659  assert(image != (Image *) NULL);
4660  assert(image->signature == MagickCoreSignature);
4661  if (image->debug != MagickFalse)
4662  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
4663  assert(quantum_info != (QuantumInfo *) NULL);
4664  assert(quantum_info->signature == MagickCoreSignature);
4665  if (pixels == (const unsigned char *) NULL)
4666  pixels=(const unsigned char *) GetQuantumPixels(quantum_info);
4667  x=0;
4668  p=pixels;
4669  if (image_view == (CacheView *) NULL)
4670  {
4671  number_pixels=GetImageExtent(image);
4672  q=GetAuthenticPixelQueue(image);
4673  }
4674  else
4675  {
4676  number_pixels=GetCacheViewExtent(image_view);
4677  q=GetCacheViewAuthenticPixelQueue(image_view);
4678  }
4679  ResetQuantumState(quantum_info);
4680  extent=GetQuantumExtent(image,quantum_info,quantum_type);
4681  switch (quantum_type)
4682  {
4683  case AlphaQuantum:
4684  {
4685  ImportAlphaQuantum(image,quantum_info,number_pixels,p,q);
4686  break;
4687  }
4688  case BGRQuantum:
4689  {
4690  ImportBGRQuantum(image,quantum_info,number_pixels,p,q);
4691  break;
4692  }
4693  case BGRAQuantum:
4694  {
4695  ImportBGRAQuantum(image,quantum_info,number_pixels,p,q);
4696  break;
4697  }
4698  case BGROQuantum:
4699  {
4700  ImportBGROQuantum(image,quantum_info,number_pixels,p,q);
4701  break;
4702  }
4703  case BlackQuantum:
4704  {
4705  ImportBlackQuantum(image,quantum_info,number_pixels,p,q,exception);
4706  break;
4707  }
4708  case BlueQuantum:
4709  case YellowQuantum:
4710  {
4711  ImportBlueQuantum(image,quantum_info,number_pixels,p,q);
4712  break;
4713  }
4714  case CMYKQuantum:
4715  {
4716  ImportCMYKQuantum(image,quantum_info,number_pixels,p,q,exception);
4717  break;
4718  }
4719  case CMYKAQuantum:
4720  {
4721  ImportCMYKAQuantum(image,quantum_info,number_pixels,p,q,exception);
4722  break;
4723  }
4724  case CMYKOQuantum:
4725  {
4726  ImportCMYKOQuantum(image,quantum_info,number_pixels,p,q,exception);
4727  break;
4728  }
4729  case CbYCrYQuantum:
4730  {
4731  ImportCbYCrYQuantum(image,quantum_info,number_pixels,p,q);
4732  break;
4733  }
4734  case GrayQuantum:
4735  {
4736  ImportGrayQuantum(image,quantum_info,number_pixels,p,q);
4737  break;
4738  }
4739  case GrayAlphaQuantum:
4740  {
4741  ImportGrayAlphaQuantum(image,quantum_info,number_pixels,p,q);
4742  break;
4743  }
4744  case GreenQuantum:
4745  case MagentaQuantum:
4746  {
4747  ImportGreenQuantum(image,quantum_info,number_pixels,p,q);
4748  break;
4749  }
4750  case IndexQuantum:
4751  {
4752  ImportIndexQuantum(image,quantum_info,number_pixels,p,q,exception);
4753  break;
4754  }
4755  case IndexAlphaQuantum:
4756  {
4757  ImportIndexAlphaQuantum(image,quantum_info,number_pixels,p,q,exception);
4758  break;
4759  }
4760  case OpacityQuantum:
4761  {
4762  ImportOpacityQuantum(image,quantum_info,number_pixels,p,q);
4763  break;
4764  }
4765  case RedQuantum:
4766  case CyanQuantum:
4767  {
4768  ImportRedQuantum(image,quantum_info,number_pixels,p,q);
4769  break;
4770  }
4771  case RGBQuantum:
4772  case CbYCrQuantum:
4773  {
4774  ImportRGBQuantum(image,quantum_info,number_pixels,p,q);
4775  break;
4776  }
4777  case RGBAQuantum:
4778  case CbYCrAQuantum:
4779  {
4780  ImportRGBAQuantum(image,quantum_info,number_pixels,p,q);
4781  break;
4782  }
4783  case RGBOQuantum:
4784  {
4785  ImportRGBOQuantum(image,quantum_info,number_pixels,p,q);
4786  break;
4787  }
4788  default:
4789  break;
4790  }
4791  if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
4792  {
4793  Quantum
4794  quantum;
4795 
4796  q=GetAuthenticPixelQueue(image);
4797  if (image_view != (CacheView *) NULL)
4798  q=GetCacheViewAuthenticPixelQueue(image_view);
4799  for (x=0; x < (ssize_t) number_pixels; x++)
4800  {
4801  quantum=GetPixelRed(image,q);
4802  SetPixelRed(image,GetPixelGreen(image,q),q);
4803  SetPixelGreen(image,quantum,q);
4804  q+=GetPixelChannels(image);
4805  }
4806  }
4807  if (quantum_info->alpha_type == AssociatedQuantumAlpha)
4808  {
4809  double
4810  gamma,
4811  Sa;
4812 
4813  /*
4814  Disassociate alpha.
4815  */
4816  q=GetAuthenticPixelQueue(image);
4817  if (image_view != (CacheView *) NULL)
4818  q=GetCacheViewAuthenticPixelQueue(image_view);
4819  for (x=0; x < (ssize_t) number_pixels; x++)
4820  {
4821  ssize_t
4822  i;
4823 
4824  Sa=QuantumScale*GetPixelAlpha(image,q);
4825  gamma=PerceptibleReciprocal(Sa);
4826  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4827  {
4828  PixelChannel channel = GetPixelChannelChannel(image,i);
4829  PixelTrait traits = GetPixelChannelTraits(image,channel);
4830  if ((channel == AlphaPixelChannel) ||
4831  ((traits & UpdatePixelTrait) == 0))
4832  continue;
4833  q[i]=ClampToQuantum(gamma*q[i]);
4834  }
4835  q+=GetPixelChannels(image);
4836  }
4837  }
4838  return(extent);
4839 }
MagickExport Quantum * GetAuthenticPixelQueue(const Image *image)
Definition: cache.c:1425
#define magick_restrict
Definition: MagickCore.h:41
static float ScaleFloatPixel(const QuantumInfo *quantum_info, const unsigned char *quantum)
#define TransparentAlpha
Definition: image.h:26
QuantumFormatType format
MagickExport MagickSizeType GetCacheViewExtent(const CacheView *cache_view)
Definition: cache-view.c:448
PixelInfo * colormap
Definition: image.h:179
static MagickSizeType GetQuantumRange(const size_t depth)
QuantumAlphaType alpha_type
static Quantum GetPixelAlpha(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void SetPixelOpacity(const Image *magick_restrict image, const Quantum alpha, Quantum *magick_restrict pixel)
static Quantum GetPixelRed(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void ImportBGRQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q)
static void ImportIndexAlphaQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q, ExceptionInfo *exception)
EndianType endian
Definition: image.h:228
static void SetPixelGray(const Image *magick_restrict image, const Quantum gray, Quantum *magick_restrict pixel)
#define OpaqueAlpha
Definition: image.h:25
static void ImportGrayQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q)
MagickPrivate void ResetQuantumState(QuantumInfo *)
Definition: quantum.c:579
static PixelTrait GetPixelChannelTraits(const Image *magick_restrict image, const PixelChannel channel)
static void SetPixelViaPixelInfo(const Image *magick_restrict image, const PixelInfo *magick_restrict pixel_info, Quantum *magick_restrict pixel)
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:85
Definition: image.h:151
static void ImportGreenQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q)
EndianType endian
static const unsigned char * PushQuantumLongPixel(QuantumInfo *quantum_info, const unsigned char *magick_restrict pixels, unsigned int *quantum)
#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)
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:1662
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:489
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:1601
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:379
static void SetPixelIndex(const Image *magick_restrict image, const Quantum index, Quantum *magick_restrict pixel)
static void ImportRGBQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q)
static void SetPixelAlpha(const Image *magick_restrict image, const Quantum alpha, Quantum *magick_restrict pixel)
static void ImportIndexQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q, ExceptionInfo *exception)
QuantumType
Definition: quantum.h:51
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:137
MagickBooleanType min_is_white
MagickSizeType QuantumAny
Definition: magick-type.h:152
ColorspaceType colorspace
Definition: image.h:157
#define QuantumRange
Definition: magick-type.h:87
MagickBooleanType debug
Definition: image.h:334
static void 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