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