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