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