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