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