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