MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
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-2018 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://www.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  p=(double *) quantum;
143  *pixel=(*p);
144  *pixel-=quantum_info->minimum;
145  *pixel*=quantum_info->scale;
146  return(pixels);
147  }
148  quantum[7]=(*pixels++);
149  quantum[6]=(*pixels++);
150  quantum[5]=(*pixels++);
151  quantum[4]=(*pixels++);
152  quantum[3]=(*pixels++);
153  quantum[2]=(*pixels++);
154  quantum[1]=(*pixels++);
155  quantum[0]=(*pixels++);
156  p=(double *) quantum;
157  *pixel=(*p);
158  *pixel-=quantum_info->minimum;
159  *pixel*=quantum_info->scale;
160  return(pixels);
161 }
162 
163 static inline const unsigned char *PushQuantumFloatPixel(QuantumInfo *quantum_info,
164  const unsigned char *magick_restrict pixels,float *pixel)
165 {
166  float
167  *p;
168 
169  unsigned char
170  quantum[4];
171 
172  if (quantum_info->endian == LSBEndian)
173  {
174  quantum[0]=(*pixels++);
175  quantum[1]=(*pixels++);
176  quantum[2]=(*pixels++);
177  quantum[3]=(*pixels++);
178  p=(float *) quantum;
179  *pixel=(*p);
180  *pixel-=quantum_info->minimum;
181  *pixel*=quantum_info->scale;
182  return(pixels);
183  }
184  quantum[3]=(*pixels++);
185  quantum[2]=(*pixels++);
186  quantum[1]=(*pixels++);
187  quantum[0]=(*pixels++);
188  p=(float *) quantum;
189  *pixel=(*p);
190  *pixel-=quantum_info->minimum;
191  *pixel*=quantum_info->scale;
192  return(pixels);
193 }
194 
195 static inline const unsigned char *PushQuantumPixel(QuantumInfo *quantum_info,
196  const unsigned char *magick_restrict pixels,unsigned int *quantum)
197 {
198  register ssize_t
199  i;
200 
201  register size_t
202  quantum_bits;
203 
204  *quantum=(QuantumAny) 0;
205  for (i=(ssize_t) quantum_info->depth; i > 0L; )
206  {
207  if (quantum_info->state.bits == 0UL)
208  {
209  quantum_info->state.pixel=(*pixels++);
210  quantum_info->state.bits=8UL;
211  }
212  quantum_bits=(size_t) i;
213  if (quantum_bits > quantum_info->state.bits)
214  quantum_bits=quantum_info->state.bits;
215  i-=(ssize_t) quantum_bits;
216  quantum_info->state.bits-=quantum_bits;
217  *quantum=(unsigned int) ((*quantum << quantum_bits) |
218  ((quantum_info->state.pixel >> quantum_info->state.bits) &~ ((~0UL) <<
219  quantum_bits)));
220  }
221  return(pixels);
222 }
223 
224 static inline const unsigned char *PushQuantumLongPixel(
225  QuantumInfo *quantum_info,const unsigned char *magick_restrict pixels,
226  unsigned int *quantum)
227 {
228  register ssize_t
229  i;
230 
231  register size_t
232  quantum_bits;
233 
234  *quantum=0UL;
235  for (i=(ssize_t) quantum_info->depth; i > 0; )
236  {
237  if (quantum_info->state.bits == 0)
238  {
239  pixels=PushLongPixel(quantum_info->endian,pixels,
240  &quantum_info->state.pixel);
241  quantum_info->state.bits=32U;
242  }
243  quantum_bits=(size_t) i;
244  if (quantum_bits > quantum_info->state.bits)
245  quantum_bits=quantum_info->state.bits;
246  *quantum|=(((quantum_info->state.pixel >> (32U-quantum_info->state.bits)) &
247  quantum_info->state.mask[quantum_bits]) << (quantum_info->depth-i));
248  i-=(ssize_t) quantum_bits;
249  quantum_info->state.bits-=quantum_bits;
250  }
251  return(pixels);
252 }
253 
254 static void ImportAlphaQuantum(const Image *image,QuantumInfo *quantum_info,
255  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
257 {
258  QuantumAny
259  range;
260 
261  register ssize_t
262  x;
263 
264  unsigned int
265  pixel;
266 
267  assert(image != (Image *) NULL);
268  assert(image->signature == MagickCoreSignature);
269  switch (quantum_info->depth)
270  {
271  case 8:
272  {
273  unsigned char
274  pixel;
275 
276  for (x=0; x < (ssize_t) number_pixels; x++)
277  {
278  p=PushCharPixel(p,&pixel);
279  SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
280  p+=quantum_info->pad;
281  q+=GetPixelChannels(image);
282  }
283  break;
284  }
285  case 16:
286  {
287  unsigned short
288  pixel;
289 
290  if (quantum_info->format == FloatingPointQuantumFormat)
291  {
292  for (x=0; x < (ssize_t) number_pixels; x++)
293  {
294  p=PushShortPixel(quantum_info->endian,p,&pixel);
296  HalfToSinglePrecision(pixel)),q);
297  p+=quantum_info->pad;
298  q+=GetPixelChannels(image);
299  }
300  break;
301  }
302  for (x=0; x < (ssize_t) number_pixels; x++)
303  {
304  p=PushShortPixel(quantum_info->endian,p,&pixel);
305  SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
306  p+=quantum_info->pad;
307  q+=GetPixelChannels(image);
308  }
309  break;
310  }
311  case 32:
312  {
313  unsigned int
314  pixel;
315 
316  if (quantum_info->format == FloatingPointQuantumFormat)
317  {
318  float
319  pixel;
320 
321  for (x=0; x < (ssize_t) number_pixels; x++)
322  {
323  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
324  SetPixelAlpha(image,ClampToQuantum(pixel),q);
325  p+=quantum_info->pad;
326  q+=GetPixelChannels(image);
327  }
328  break;
329  }
330  for (x=0; x < (ssize_t) number_pixels; x++)
331  {
332  p=PushLongPixel(quantum_info->endian,p,&pixel);
333  SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
334  p+=quantum_info->pad;
335  q+=GetPixelChannels(image);
336  }
337  break;
338  }
339  case 64:
340  {
341  if (quantum_info->format == FloatingPointQuantumFormat)
342  {
343  double
344  pixel;
345 
346  for (x=0; x < (ssize_t) number_pixels; x++)
347  {
348  p=PushDoublePixel(quantum_info,p,&pixel);
349  SetPixelAlpha(image,ClampToQuantum(pixel),q);
350  p+=quantum_info->pad;
351  q+=GetPixelChannels(image);
352  }
353  break;
354  }
355  }
356  default:
357  {
358  range=GetQuantumRange(quantum_info->depth);
359  for (x=0; x < (ssize_t) number_pixels; x++)
360  {
361  p=PushQuantumPixel(quantum_info,p,&pixel);
362  SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
363  p+=quantum_info->pad;
364  q+=GetPixelChannels(image);
365  }
366  break;
367  }
368  }
369 }
370 
371 static void ImportBGRQuantum(const Image *image,QuantumInfo *quantum_info,
372  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
374 {
375  QuantumAny
376  range;
377 
378  register ssize_t
379  x;
380 
381  ssize_t
382  bit;
383 
384  unsigned int
385  pixel;
386 
387  assert(image != (Image *) NULL);
388  assert(image->signature == MagickCoreSignature);
389  switch (quantum_info->depth)
390  {
391  case 8:
392  {
393  unsigned char
394  pixel;
395 
396  for (x=0; x < (ssize_t) number_pixels; x++)
397  {
398  p=PushCharPixel(p,&pixel);
399  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
400  p=PushCharPixel(p,&pixel);
401  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
402  p=PushCharPixel(p,&pixel);
403  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
404  SetPixelAlpha(image,OpaqueAlpha,q);
405  p+=quantum_info->pad;
406  q+=GetPixelChannels(image);
407  }
408  break;
409  }
410  case 10:
411  {
412  range=GetQuantumRange(quantum_info->depth);
413  if (quantum_info->pack == MagickFalse)
414  {
415  for (x=0; x < (ssize_t) number_pixels; x++)
416  {
417  p=PushLongPixel(quantum_info->endian,p,&pixel);
418  SetPixelRed(image,ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range),q);
419  SetPixelGreen(image,ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range),
420  q);
421  SetPixelBlue(image,ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range),q);
422  p+=quantum_info->pad;
423  q+=GetPixelChannels(image);
424  }
425  break;
426  }
427  if (quantum_info->quantum == 32U)
428  {
429  for (x=0; x < (ssize_t) number_pixels; x++)
430  {
431  p=PushQuantumLongPixel(quantum_info,p,&pixel);
432  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
433  p=PushQuantumLongPixel(quantum_info,p,&pixel);
434  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
435  p=PushQuantumLongPixel(quantum_info,p,&pixel);
436  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
437  q+=GetPixelChannels(image);
438  }
439  break;
440  }
441  for (x=0; x < (ssize_t) number_pixels; x++)
442  {
443  p=PushQuantumPixel(quantum_info,p,&pixel);
444  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
445  p=PushQuantumPixel(quantum_info,p,&pixel);
446  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
447  p=PushQuantumPixel(quantum_info,p,&pixel);
448  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
449  q+=GetPixelChannels(image);
450  }
451  break;
452  }
453  case 12:
454  {
455  range=GetQuantumRange(quantum_info->depth);
456  if (quantum_info->pack == MagickFalse)
457  {
458  unsigned short
459  pixel;
460 
461  for (x=0; x < (ssize_t) (3*number_pixels-1); x+=2)
462  {
463  p=PushShortPixel(quantum_info->endian,p,&pixel);
464  switch (x % 3)
465  {
466  default:
467  case 0:
468  {
469  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
470  range),q);
471  break;
472  }
473  case 1:
474  {
475  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
476  range),q);
477  break;
478  }
479  case 2:
480  {
481  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
482  range),q);
483  q+=GetPixelChannels(image);
484  break;
485  }
486  }
487  p=PushShortPixel(quantum_info->endian,p,&pixel);
488  switch ((x+1) % 3)
489  {
490  default:
491  case 0:
492  {
493  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
494  range),q);
495  break;
496  }
497  case 1:
498  {
499  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
500  range),q);
501  break;
502  }
503  case 2:
504  {
505  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
506  range),q);
507  q+=GetPixelChannels(image);
508  break;
509  }
510  }
511  p+=quantum_info->pad;
512  }
513  for (bit=0; bit < (ssize_t) (3*number_pixels % 2); bit++)
514  {
515  p=PushShortPixel(quantum_info->endian,p,&pixel);
516  switch ((x+bit) % 3)
517  {
518  default:
519  case 0:
520  {
521  SetPixelRed(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
522  range),q);
523  break;
524  }
525  case 1:
526  {
527  SetPixelGreen(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
528  range),q);
529  break;
530  }
531  case 2:
532  {
533  SetPixelBlue(image,ScaleAnyToQuantum((QuantumAny) (pixel >> 4),
534  range),q);
535  q+=GetPixelChannels(image);
536  break;
537  }
538  }
539  p+=quantum_info->pad;
540  }
541  if (bit != 0)
542  p++;
543  break;
544  }
545  if (quantum_info->quantum == 32U)
546  {
547  for (x=0; x < (ssize_t) number_pixels; x++)
548  {
549  p=PushQuantumLongPixel(quantum_info,p,&pixel);
550  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
551  p=PushQuantumLongPixel(quantum_info,p,&pixel);
552  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
553  p=PushQuantumLongPixel(quantum_info,p,&pixel);
554  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
555  q+=GetPixelChannels(image);
556  }
557  break;
558  }
559  for (x=0; x < (ssize_t) number_pixels; x++)
560  {
561  p=PushQuantumPixel(quantum_info,p,&pixel);
562  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
563  p=PushQuantumPixel(quantum_info,p,&pixel);
564  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
565  p=PushQuantumPixel(quantum_info,p,&pixel);
566  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
567  q+=GetPixelChannels(image);
568  }
569  break;
570  }
571  case 16:
572  {
573  unsigned short
574  pixel;
575 
576  if (quantum_info->format == FloatingPointQuantumFormat)
577  {
578  for (x=0; x < (ssize_t) number_pixels; x++)
579  {
580  p=PushShortPixel(quantum_info->endian,p,&pixel);
582  HalfToSinglePrecision(pixel)),q);
583  p=PushShortPixel(quantum_info->endian,p,&pixel);
585  HalfToSinglePrecision(pixel)),q);
586  p=PushShortPixel(quantum_info->endian,p,&pixel);
588  HalfToSinglePrecision(pixel)),q);
589  p+=quantum_info->pad;
590  q+=GetPixelChannels(image);
591  }
592  break;
593  }
594  for (x=0; x < (ssize_t) number_pixels; x++)
595  {
596  p=PushShortPixel(quantum_info->endian,p,&pixel);
597  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
598  p=PushShortPixel(quantum_info->endian,p,&pixel);
599  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
600  p=PushShortPixel(quantum_info->endian,p,&pixel);
601  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
602  p+=quantum_info->pad;
603  q+=GetPixelChannels(image);
604  }
605  break;
606  }
607  case 32:
608  {
609  unsigned int
610  pixel;
611 
612  if (quantum_info->format == FloatingPointQuantumFormat)
613  {
614  float
615  pixel;
616 
617  for (x=0; x < (ssize_t) number_pixels; x++)
618  {
619  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
620  SetPixelRed(image,ClampToQuantum(pixel),q);
621  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
622  SetPixelGreen(image,ClampToQuantum(pixel),q);
623  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
624  SetPixelBlue(image,ClampToQuantum(pixel),q);
625  p+=quantum_info->pad;
626  q+=GetPixelChannels(image);
627  }
628  break;
629  }
630  for (x=0; x < (ssize_t) number_pixels; x++)
631  {
632  p=PushLongPixel(quantum_info->endian,p,&pixel);
633  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
634  p=PushLongPixel(quantum_info->endian,p,&pixel);
635  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
636  p=PushLongPixel(quantum_info->endian,p,&pixel);
637  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
638  p+=quantum_info->pad;
639  q+=GetPixelChannels(image);
640  }
641  break;
642  }
643  case 64:
644  {
645  if (quantum_info->format == FloatingPointQuantumFormat)
646  {
647  double
648  pixel;
649 
650  for (x=0; x < (ssize_t) number_pixels; x++)
651  {
652  p=PushDoublePixel(quantum_info,p,&pixel);
653  SetPixelRed(image,ClampToQuantum(pixel),q);
654  p=PushDoublePixel(quantum_info,p,&pixel);
655  SetPixelGreen(image,ClampToQuantum(pixel),q);
656  p=PushDoublePixel(quantum_info,p,&pixel);
657  SetPixelBlue(image,ClampToQuantum(pixel),q);
658  p+=quantum_info->pad;
659  q+=GetPixelChannels(image);
660  }
661  break;
662  }
663  }
664  default:
665  {
666  range=GetQuantumRange(quantum_info->depth);
667  for (x=0; x < (ssize_t) number_pixels; x++)
668  {
669  p=PushQuantumPixel(quantum_info,p,&pixel);
670  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
671  p=PushQuantumPixel(quantum_info,p,&pixel);
672  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
673  p=PushQuantumPixel(quantum_info,p,&pixel);
674  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
675  q+=GetPixelChannels(image);
676  }
677  break;
678  }
679  }
680 }
681 
682 static void ImportBGRAQuantum(const Image *image,QuantumInfo *quantum_info,
683  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
685 {
686  QuantumAny
687  range;
688 
689  register ssize_t
690  x;
691 
692  unsigned int
693  pixel;
694 
695  assert(image != (Image *) NULL);
696  assert(image->signature == MagickCoreSignature);
697  switch (quantum_info->depth)
698  {
699  case 8:
700  {
701  unsigned char
702  pixel;
703 
704  for (x=0; x < (ssize_t) number_pixels; x++)
705  {
706  p=PushCharPixel(p,&pixel);
707  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
708  p=PushCharPixel(p,&pixel);
709  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
710  p=PushCharPixel(p,&pixel);
711  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
712  p=PushCharPixel(p,&pixel);
713  SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
714  p+=quantum_info->pad;
715  q+=GetPixelChannels(image);
716  }
717  break;
718  }
719  case 10:
720  {
721  pixel=0;
722  if (quantum_info->pack == MagickFalse)
723  {
724  register ssize_t
725  i;
726 
727  size_t
728  quantum;
729 
730  ssize_t
731  n;
732 
733  n=0;
734  quantum=0;
735  for (x=0; x < (ssize_t) number_pixels; x++)
736  {
737  for (i=0; i < 4; i++)
738  {
739  switch (n % 3)
740  {
741  case 0:
742  {
743  p=PushLongPixel(quantum_info->endian,p,&pixel);
744  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
745  (((pixel >> 22) & 0x3ff) << 6)));
746  break;
747  }
748  case 1:
749  {
750  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
751  (((pixel >> 12) & 0x3ff) << 6)));
752  break;
753  }
754  case 2:
755  {
756  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
757  (((pixel >> 2) & 0x3ff) << 6)));
758  break;
759  }
760  }
761  switch (i)
762  {
763  case 0: SetPixelRed(image,(Quantum) quantum,q); break;
764  case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
765  case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
766  case 3: SetPixelAlpha(image,(Quantum) quantum,q); break;
767  }
768  n++;
769  }
770  p+=quantum_info->pad;
771  q+=GetPixelChannels(image);
772  }
773  break;
774  }
775  for (x=0; x < (ssize_t) number_pixels; x++)
776  {
777  p=PushQuantumPixel(quantum_info,p,&pixel);
778  SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
779  p=PushQuantumPixel(quantum_info,p,&pixel);
780  SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
781  q);
782  p=PushQuantumPixel(quantum_info,p,&pixel);
783  SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
784  q);
785  p=PushQuantumPixel(quantum_info,p,&pixel);
786  SetPixelAlpha(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
787  q);
788  q+=GetPixelChannels(image);
789  }
790  break;
791  }
792  case 16:
793  {
794  unsigned short
795  pixel;
796 
797  if (quantum_info->format == FloatingPointQuantumFormat)
798  {
799  for (x=0; x < (ssize_t) number_pixels; x++)
800  {
801  p=PushShortPixel(quantum_info->endian,p,&pixel);
803  HalfToSinglePrecision(pixel)),q);
804  p=PushShortPixel(quantum_info->endian,p,&pixel);
806  HalfToSinglePrecision(pixel)),q);
807  p=PushShortPixel(quantum_info->endian,p,&pixel);
809  HalfToSinglePrecision(pixel)),q);
810  p=PushShortPixel(quantum_info->endian,p,&pixel);
812  HalfToSinglePrecision(pixel)),q);
813  p+=quantum_info->pad;
814  q+=GetPixelChannels(image);
815  }
816  break;
817  }
818  for (x=0; x < (ssize_t) number_pixels; x++)
819  {
820  p=PushShortPixel(quantum_info->endian,p,&pixel);
821  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
822  p=PushShortPixel(quantum_info->endian,p,&pixel);
823  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
824  p=PushShortPixel(quantum_info->endian,p,&pixel);
825  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
826  p=PushShortPixel(quantum_info->endian,p,&pixel);
827  SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
828  p+=quantum_info->pad;
829  q+=GetPixelChannels(image);
830  }
831  break;
832  }
833  case 32:
834  {
835  unsigned int
836  pixel;
837 
838  if (quantum_info->format == FloatingPointQuantumFormat)
839  {
840  float
841  pixel;
842 
843  for (x=0; x < (ssize_t) number_pixels; x++)
844  {
845  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
846  SetPixelRed(image,ClampToQuantum(pixel),q);
847  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
848  SetPixelGreen(image,ClampToQuantum(pixel),q);
849  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
850  SetPixelBlue(image,ClampToQuantum(pixel),q);
851  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
852  SetPixelAlpha(image,ClampToQuantum(pixel),q);
853  p+=quantum_info->pad;
854  q+=GetPixelChannels(image);
855  }
856  break;
857  }
858  for (x=0; x < (ssize_t) number_pixels; x++)
859  {
860  p=PushLongPixel(quantum_info->endian,p,&pixel);
861  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
862  p=PushLongPixel(quantum_info->endian,p,&pixel);
863  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
864  p=PushLongPixel(quantum_info->endian,p,&pixel);
865  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
866  p=PushLongPixel(quantum_info->endian,p,&pixel);
867  SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
868  p+=quantum_info->pad;
869  q+=GetPixelChannels(image);
870  }
871  break;
872  }
873  case 64:
874  {
875  if (quantum_info->format == FloatingPointQuantumFormat)
876  {
877  double
878  pixel;
879 
880  for (x=0; x < (ssize_t) number_pixels; x++)
881  {
882  p=PushDoublePixel(quantum_info,p,&pixel);
883  SetPixelRed(image,ClampToQuantum(pixel),q);
884  p=PushDoublePixel(quantum_info,p,&pixel);
885  SetPixelGreen(image,ClampToQuantum(pixel),q);
886  p=PushDoublePixel(quantum_info,p,&pixel);
887  SetPixelBlue(image,ClampToQuantum(pixel),q);
888  p=PushDoublePixel(quantum_info,p,&pixel);
889  SetPixelAlpha(image,ClampToQuantum(pixel),q);
890  p+=quantum_info->pad;
891  q+=GetPixelChannels(image);
892  }
893  break;
894  }
895  }
896  default:
897  {
898  range=GetQuantumRange(quantum_info->depth);
899  for (x=0; x < (ssize_t) number_pixels; x++)
900  {
901  p=PushQuantumPixel(quantum_info,p,&pixel);
902  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
903  p=PushQuantumPixel(quantum_info,p,&pixel);
904  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
905  p=PushQuantumPixel(quantum_info,p,&pixel);
906  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
907  p=PushQuantumPixel(quantum_info,p,&pixel);
908  SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
909  q+=GetPixelChannels(image);
910  }
911  break;
912  }
913  }
914 }
915 
916 static void ImportBGROQuantum(const Image *image,QuantumInfo *quantum_info,
917  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
919 {
920  QuantumAny
921  range;
922 
923  register ssize_t
924  x;
925 
926  unsigned int
927  pixel;
928 
929  assert(image != (Image *) NULL);
930  assert(image->signature == MagickCoreSignature);
931  switch (quantum_info->depth)
932  {
933  case 8:
934  {
935  unsigned char
936  pixel;
937 
938  for (x=0; x < (ssize_t) number_pixels; x++)
939  {
940  p=PushCharPixel(p,&pixel);
941  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
942  p=PushCharPixel(p,&pixel);
943  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
944  p=PushCharPixel(p,&pixel);
945  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
946  p=PushCharPixel(p,&pixel);
947  SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
948  p+=quantum_info->pad;
949  q+=GetPixelChannels(image);
950  }
951  break;
952  }
953  case 10:
954  {
955  pixel=0;
956  if (quantum_info->pack == MagickFalse)
957  {
958  register ssize_t
959  i;
960 
961  size_t
962  quantum;
963 
964  ssize_t
965  n;
966 
967  n=0;
968  quantum=0;
969  for (x=0; x < (ssize_t) number_pixels; x++)
970  {
971  for (i=0; i < 4; i++)
972  {
973  switch (n % 3)
974  {
975  case 0:
976  {
977  p=PushLongPixel(quantum_info->endian,p,&pixel);
978  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
979  (((pixel >> 22) & 0x3ff) << 6)));
980  break;
981  }
982  case 1:
983  {
984  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
985  (((pixel >> 12) & 0x3ff) << 6)));
986  break;
987  }
988  case 2:
989  {
990  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
991  (((pixel >> 2) & 0x3ff) << 6)));
992  break;
993  }
994  }
995  switch (i)
996  {
997  case 0: SetPixelRed(image,(Quantum) quantum,q); break;
998  case 1: SetPixelGreen(image,(Quantum) quantum,q); break;
999  case 2: SetPixelBlue(image,(Quantum) quantum,q); break;
1000  case 3: SetPixelOpacity(image,(Quantum) quantum,q); break;
1001  }
1002  n++;
1003  }
1004  p+=quantum_info->pad;
1005  q+=GetPixelChannels(image);
1006  }
1007  break;
1008  }
1009  for (x=0; x < (ssize_t) number_pixels; x++)
1010  {
1011  p=PushQuantumPixel(quantum_info,p,&pixel);
1012  SetPixelRed(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),q);
1013  p=PushQuantumPixel(quantum_info,p,&pixel);
1014  SetPixelGreen(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1015  q);
1016  p=PushQuantumPixel(quantum_info,p,&pixel);
1017  SetPixelBlue(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1018  q);
1019  p=PushQuantumPixel(quantum_info,p,&pixel);
1020  SetPixelOpacity(image,ScaleShortToQuantum((unsigned short) (pixel << 6)),
1021  q);
1022  q+=GetPixelChannels(image);
1023  }
1024  break;
1025  }
1026  case 16:
1027  {
1028  unsigned short
1029  pixel;
1030 
1031  if (quantum_info->format == FloatingPointQuantumFormat)
1032  {
1033  for (x=0; x < (ssize_t) number_pixels; x++)
1034  {
1035  p=PushShortPixel(quantum_info->endian,p,&pixel);
1037  HalfToSinglePrecision(pixel)),q);
1038  p=PushShortPixel(quantum_info->endian,p,&pixel);
1040  HalfToSinglePrecision(pixel)),q);
1041  p=PushShortPixel(quantum_info->endian,p,&pixel);
1043  HalfToSinglePrecision(pixel)),q);
1044  p=PushShortPixel(quantum_info->endian,p,&pixel);
1046  HalfToSinglePrecision(pixel)),q);
1047  p+=quantum_info->pad;
1048  q+=GetPixelChannels(image);
1049  }
1050  break;
1051  }
1052  for (x=0; x < (ssize_t) number_pixels; x++)
1053  {
1054  p=PushShortPixel(quantum_info->endian,p,&pixel);
1055  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1056  p=PushShortPixel(quantum_info->endian,p,&pixel);
1057  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1058  p=PushShortPixel(quantum_info->endian,p,&pixel);
1059  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1060  p=PushShortPixel(quantum_info->endian,p,&pixel);
1061  SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
1062  p+=quantum_info->pad;
1063  q+=GetPixelChannels(image);
1064  }
1065  break;
1066  }
1067  case 32:
1068  {
1069  unsigned int
1070  pixel;
1071 
1072  if (quantum_info->format == FloatingPointQuantumFormat)
1073  {
1074  float
1075  pixel;
1076 
1077  for (x=0; x < (ssize_t) number_pixels; x++)
1078  {
1079  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1080  SetPixelRed(image,ClampToQuantum(pixel),q);
1081  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1082  SetPixelGreen(image,ClampToQuantum(pixel),q);
1083  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1084  SetPixelBlue(image,ClampToQuantum(pixel),q);
1085  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1086  SetPixelOpacity(image,ClampToQuantum(pixel),q);
1087  p+=quantum_info->pad;
1088  q+=GetPixelChannels(image);
1089  }
1090  break;
1091  }
1092  for (x=0; x < (ssize_t) number_pixels; x++)
1093  {
1094  p=PushLongPixel(quantum_info->endian,p,&pixel);
1095  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1096  p=PushLongPixel(quantum_info->endian,p,&pixel);
1097  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1098  p=PushLongPixel(quantum_info->endian,p,&pixel);
1099  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1100  p=PushLongPixel(quantum_info->endian,p,&pixel);
1101  SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
1102  p+=quantum_info->pad;
1103  q+=GetPixelChannels(image);
1104  }
1105  break;
1106  }
1107  case 64:
1108  {
1109  if (quantum_info->format == FloatingPointQuantumFormat)
1110  {
1111  double
1112  pixel;
1113 
1114  for (x=0; x < (ssize_t) number_pixels; x++)
1115  {
1116  p=PushDoublePixel(quantum_info,p,&pixel);
1117  SetPixelRed(image,ClampToQuantum(pixel),q);
1118  p=PushDoublePixel(quantum_info,p,&pixel);
1119  SetPixelGreen(image,ClampToQuantum(pixel),q);
1120  p=PushDoublePixel(quantum_info,p,&pixel);
1121  SetPixelBlue(image,ClampToQuantum(pixel),q);
1122  p=PushDoublePixel(quantum_info,p,&pixel);
1123  SetPixelOpacity(image,ClampToQuantum(pixel),q);
1124  p+=quantum_info->pad;
1125  q+=GetPixelChannels(image);
1126  }
1127  break;
1128  }
1129  }
1130  default:
1131  {
1132  range=GetQuantumRange(quantum_info->depth);
1133  for (x=0; x < (ssize_t) number_pixels; x++)
1134  {
1135  p=PushQuantumPixel(quantum_info,p,&pixel);
1136  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1137  p=PushQuantumPixel(quantum_info,p,&pixel);
1138  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1139  p=PushQuantumPixel(quantum_info,p,&pixel);
1140  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1141  p=PushQuantumPixel(quantum_info,p,&pixel);
1142  SetPixelOpacity(image,ScaleAnyToQuantum(pixel,range),q);
1143  q+=GetPixelChannels(image);
1144  }
1145  break;
1146  }
1147  }
1148 }
1149 
1150 static void ImportBlackQuantum(const Image *image,QuantumInfo *quantum_info,
1151  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1152  Quantum *magick_restrict q,ExceptionInfo *exception)
1153 {
1154  QuantumAny
1155  range;
1156 
1157  register ssize_t
1158  x;
1159 
1160  unsigned int
1161  pixel;
1162 
1163  if (image->colorspace != CMYKColorspace)
1164  {
1165  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1166  "ColorSeparatedImageRequired","`%s'",image->filename);
1167  return;
1168  }
1169  switch (quantum_info->depth)
1170  {
1171  case 8:
1172  {
1173  unsigned char
1174  pixel;
1175 
1176  for (x=0; x < (ssize_t) number_pixels; x++)
1177  {
1178  p=PushCharPixel(p,&pixel);
1179  SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1180  p+=quantum_info->pad;
1181  q+=GetPixelChannels(image);
1182  }
1183  break;
1184  }
1185  case 16:
1186  {
1187  unsigned short
1188  pixel;
1189 
1190  if (quantum_info->format == FloatingPointQuantumFormat)
1191  {
1192  for (x=0; x < (ssize_t) number_pixels; x++)
1193  {
1194  p=PushShortPixel(quantum_info->endian,p,&pixel);
1196  HalfToSinglePrecision(pixel)),q);
1197  p+=quantum_info->pad;
1198  q+=GetPixelChannels(image);
1199  }
1200  break;
1201  }
1202  for (x=0; x < (ssize_t) number_pixels; x++)
1203  {
1204  p=PushShortPixel(quantum_info->endian,p,&pixel);
1205  SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1206  p+=quantum_info->pad;
1207  q+=GetPixelChannels(image);
1208  }
1209  break;
1210  }
1211  case 32:
1212  {
1213  unsigned int
1214  pixel;
1215 
1216  if (quantum_info->format == FloatingPointQuantumFormat)
1217  {
1218  float
1219  pixel;
1220 
1221  for (x=0; x < (ssize_t) number_pixels; x++)
1222  {
1223  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1224  SetPixelBlack(image,ClampToQuantum(pixel),q);
1225  p+=quantum_info->pad;
1226  q+=GetPixelChannels(image);
1227  }
1228  break;
1229  }
1230  for (x=0; x < (ssize_t) number_pixels; x++)
1231  {
1232  p=PushLongPixel(quantum_info->endian,p,&pixel);
1233  SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1234  p+=quantum_info->pad;
1235  q+=GetPixelChannels(image);
1236  }
1237  break;
1238  }
1239  case 64:
1240  {
1241  if (quantum_info->format == FloatingPointQuantumFormat)
1242  {
1243  double
1244  pixel;
1245 
1246  for (x=0; x < (ssize_t) number_pixels; x++)
1247  {
1248  p=PushDoublePixel(quantum_info,p,&pixel);
1249  SetPixelBlack(image,ClampToQuantum(pixel),q);
1250  p+=quantum_info->pad;
1251  q+=GetPixelChannels(image);
1252  }
1253  break;
1254  }
1255  }
1256  default:
1257  {
1258  range=GetQuantumRange(quantum_info->depth);
1259  for (x=0; x < (ssize_t) number_pixels; x++)
1260  {
1261  p=PushQuantumPixel(quantum_info,p,&pixel);
1262  SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1263  p+=quantum_info->pad;
1264  q+=GetPixelChannels(image);
1265  }
1266  break;
1267  }
1268  }
1269 }
1270 
1271 static void ImportBlueQuantum(const Image *image,QuantumInfo *quantum_info,
1272  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1274 {
1275  QuantumAny
1276  range;
1277 
1278  register ssize_t
1279  x;
1280 
1281  unsigned int
1282  pixel;
1283 
1284  assert(image != (Image *) NULL);
1285  assert(image->signature == MagickCoreSignature);
1286  switch (quantum_info->depth)
1287  {
1288  case 8:
1289  {
1290  unsigned char
1291  pixel;
1292 
1293  for (x=0; x < (ssize_t) number_pixels; x++)
1294  {
1295  p=PushCharPixel(p,&pixel);
1296  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1297  p+=quantum_info->pad;
1298  q+=GetPixelChannels(image);
1299  }
1300  break;
1301  }
1302  case 16:
1303  {
1304  unsigned short
1305  pixel;
1306 
1307  if (quantum_info->format == FloatingPointQuantumFormat)
1308  {
1309  for (x=0; x < (ssize_t) number_pixels; x++)
1310  {
1311  p=PushShortPixel(quantum_info->endian,p,&pixel);
1313  HalfToSinglePrecision(pixel)),q);
1314  p+=quantum_info->pad;
1315  q+=GetPixelChannels(image);
1316  }
1317  break;
1318  }
1319  for (x=0; x < (ssize_t) number_pixels; x++)
1320  {
1321  p=PushShortPixel(quantum_info->endian,p,&pixel);
1322  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1323  p+=quantum_info->pad;
1324  q+=GetPixelChannels(image);
1325  }
1326  break;
1327  }
1328  case 32:
1329  {
1330  unsigned int
1331  pixel;
1332 
1333  if (quantum_info->format == FloatingPointQuantumFormat)
1334  {
1335  float
1336  pixel;
1337 
1338  for (x=0; x < (ssize_t) number_pixels; x++)
1339  {
1340  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1341  SetPixelBlue(image,ClampToQuantum(pixel),q);
1342  p+=quantum_info->pad;
1343  q+=GetPixelChannels(image);
1344  }
1345  break;
1346  }
1347  for (x=0; x < (ssize_t) number_pixels; x++)
1348  {
1349  p=PushLongPixel(quantum_info->endian,p,&pixel);
1350  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1351  p+=quantum_info->pad;
1352  q+=GetPixelChannels(image);
1353  }
1354  break;
1355  }
1356  case 64:
1357  {
1358  if (quantum_info->format == FloatingPointQuantumFormat)
1359  {
1360  double
1361  pixel;
1362 
1363  for (x=0; x < (ssize_t) number_pixels; x++)
1364  {
1365  p=PushDoublePixel(quantum_info,p,&pixel);
1366  SetPixelBlue(image,ClampToQuantum(pixel),q);
1367  p+=quantum_info->pad;
1368  q+=GetPixelChannels(image);
1369  }
1370  break;
1371  }
1372  }
1373  default:
1374  {
1375  range=GetQuantumRange(quantum_info->depth);
1376  for (x=0; x < (ssize_t) number_pixels; x++)
1377  {
1378  p=PushQuantumPixel(quantum_info,p,&pixel);
1379  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1380  p+=quantum_info->pad;
1381  q+=GetPixelChannels(image);
1382  }
1383  break;
1384  }
1385  }
1386 }
1387 
1388 static void ImportCbYCrYQuantum(const Image *image,QuantumInfo *quantum_info,
1389  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1391 {
1392  QuantumAny
1393  range;
1394 
1395  register ssize_t
1396  x;
1397 
1398  unsigned int
1399  pixel;
1400 
1401  assert(image != (Image *) NULL);
1402  assert(image->signature == MagickCoreSignature);
1403  switch (quantum_info->depth)
1404  {
1405  case 10:
1406  {
1407  Quantum
1408  cbcr[4];
1409 
1410  pixel=0;
1411  if (quantum_info->pack == MagickFalse)
1412  {
1413  register ssize_t
1414  i;
1415 
1416  size_t
1417  quantum;
1418 
1419  ssize_t
1420  n;
1421 
1422  n=0;
1423  quantum=0;
1424  for (x=0; x < (ssize_t) number_pixels; x+=4)
1425  {
1426  for (i=0; i < 4; i++)
1427  {
1428  switch (n % 3)
1429  {
1430  case 0:
1431  {
1432  p=PushLongPixel(quantum_info->endian,p,&pixel);
1433  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1434  (((pixel >> 22) & 0x3ff) << 6)));
1435  break;
1436  }
1437  case 1:
1438  {
1439  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1440  (((pixel >> 12) & 0x3ff) << 6)));
1441  break;
1442  }
1443  case 2:
1444  {
1445  quantum=(size_t) (ScaleShortToQuantum((unsigned short)
1446  (((pixel >> 2) & 0x3ff) << 6)));
1447  break;
1448  }
1449  }
1450  cbcr[i]=(Quantum) (quantum);
1451  n++;
1452  }
1453  p+=quantum_info->pad;
1454  SetPixelRed(image,cbcr[1],q);
1455  SetPixelGreen(image,cbcr[0],q);
1456  SetPixelBlue(image,cbcr[2],q);
1457  q+=GetPixelChannels(image);
1458  SetPixelRed(image,cbcr[3],q);
1459  SetPixelGreen(image,cbcr[0],q);
1460  SetPixelBlue(image,cbcr[2],q);
1461  q+=GetPixelChannels(image);
1462  }
1463  break;
1464  }
1465  }
1466  default:
1467  {
1468  range=GetQuantumRange(quantum_info->depth);
1469  for (x=0; x < (ssize_t) number_pixels; x++)
1470  {
1471  p=PushQuantumPixel(quantum_info,p,&pixel);
1472  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1473  p=PushQuantumPixel(quantum_info,p,&pixel);
1474  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1475  q+=GetPixelChannels(image);
1476  }
1477  break;
1478  }
1479  }
1480 }
1481 
1482 static void ImportCMYKQuantum(const Image *image,QuantumInfo *quantum_info,
1483  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1484  Quantum *magick_restrict q,ExceptionInfo *exception)
1485 {
1486  QuantumAny
1487  range;
1488 
1489  register ssize_t
1490  x;
1491 
1492  unsigned int
1493  pixel;
1494 
1495  if (image->colorspace != CMYKColorspace)
1496  {
1497  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1498  "ColorSeparatedImageRequired","`%s'",image->filename);
1499  return;
1500  }
1501  switch (quantum_info->depth)
1502  {
1503  case 8:
1504  {
1505  unsigned char
1506  pixel;
1507 
1508  for (x=0; x < (ssize_t) number_pixels; x++)
1509  {
1510  p=PushCharPixel(p,&pixel);
1511  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1512  p=PushCharPixel(p,&pixel);
1513  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1514  p=PushCharPixel(p,&pixel);
1515  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1516  p=PushCharPixel(p,&pixel);
1517  SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1518  p+=quantum_info->pad;
1519  q+=GetPixelChannels(image);
1520  }
1521  break;
1522  }
1523  case 16:
1524  {
1525  unsigned short
1526  pixel;
1527 
1528  if (quantum_info->format == FloatingPointQuantumFormat)
1529  {
1530  for (x=0; x < (ssize_t) number_pixels; x++)
1531  {
1532  p=PushShortPixel(quantum_info->endian,p,&pixel);
1534  HalfToSinglePrecision(pixel)),q);
1535  p=PushShortPixel(quantum_info->endian,p,&pixel);
1537  HalfToSinglePrecision(pixel)),q);
1538  p=PushShortPixel(quantum_info->endian,p,&pixel);
1540  HalfToSinglePrecision(pixel)),q);
1541  p=PushShortPixel(quantum_info->endian,p,&pixel);
1543  HalfToSinglePrecision(pixel)),q);
1544  p+=quantum_info->pad;
1545  q+=GetPixelChannels(image);
1546  }
1547  break;
1548  }
1549  for (x=0; x < (ssize_t) number_pixels; x++)
1550  {
1551  p=PushShortPixel(quantum_info->endian,p,&pixel);
1552  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1553  p=PushShortPixel(quantum_info->endian,p,&pixel);
1554  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1555  p=PushShortPixel(quantum_info->endian,p,&pixel);
1556  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1557  p=PushShortPixel(quantum_info->endian,p,&pixel);
1558  SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1559  p+=quantum_info->pad;
1560  q+=GetPixelChannels(image);
1561  }
1562  break;
1563  }
1564  case 32:
1565  {
1566  unsigned int
1567  pixel;
1568 
1569  if (quantum_info->format == FloatingPointQuantumFormat)
1570  {
1571  float
1572  pixel;
1573 
1574  for (x=0; x < (ssize_t) number_pixels; x++)
1575  {
1576  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1577  SetPixelRed(image,ClampToQuantum(pixel),q);
1578  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1579  SetPixelGreen(image,ClampToQuantum(pixel),q);
1580  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1581  SetPixelBlue(image,ClampToQuantum(pixel),q);
1582  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1583  SetPixelBlack(image,ClampToQuantum(pixel),q);
1584  p+=quantum_info->pad;
1585  q+=GetPixelChannels(image);
1586  }
1587  break;
1588  }
1589  for (x=0; x < (ssize_t) number_pixels; x++)
1590  {
1591  p=PushLongPixel(quantum_info->endian,p,&pixel);
1592  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1593  p=PushLongPixel(quantum_info->endian,p,&pixel);
1594  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1595  p=PushLongPixel(quantum_info->endian,p,&pixel);
1596  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1597  p=PushLongPixel(quantum_info->endian,p,&pixel);
1598  SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1599  p+=quantum_info->pad;
1600  q+=GetPixelChannels(image);
1601  }
1602  break;
1603  }
1604  case 64:
1605  {
1606  if (quantum_info->format == FloatingPointQuantumFormat)
1607  {
1608  double
1609  pixel;
1610 
1611  for (x=0; x < (ssize_t) number_pixels; x++)
1612  {
1613  p=PushDoublePixel(quantum_info,p,&pixel);
1614  SetPixelRed(image,ClampToQuantum(pixel),q);
1615  p=PushDoublePixel(quantum_info,p,&pixel);
1616  SetPixelGreen(image,ClampToQuantum(pixel),q);
1617  p=PushDoublePixel(quantum_info,p,&pixel);
1618  SetPixelBlue(image,ClampToQuantum(pixel),q);
1619  p=PushDoublePixel(quantum_info,p,&pixel);
1620  SetPixelBlack(image,ClampToQuantum(pixel),q);
1621  p+=quantum_info->pad;
1622  q+=GetPixelChannels(image);
1623  }
1624  break;
1625  }
1626  }
1627  default:
1628  {
1629  range=GetQuantumRange(quantum_info->depth);
1630  for (x=0; x < (ssize_t) number_pixels; x++)
1631  {
1632  p=PushQuantumPixel(quantum_info,p,&pixel);
1633  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1634  p=PushQuantumPixel(quantum_info,p,&pixel);
1635  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1636  p=PushQuantumPixel(quantum_info,p,&pixel);
1637  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1638  p=PushQuantumPixel(quantum_info,p,&pixel);
1639  SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1640  q+=GetPixelChannels(image);
1641  }
1642  break;
1643  }
1644  }
1645 }
1646 
1647 static void ImportCMYKAQuantum(const Image *image,QuantumInfo *quantum_info,
1648  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1649  Quantum *magick_restrict q,ExceptionInfo *exception)
1650 {
1651  QuantumAny
1652  range;
1653 
1654  register ssize_t
1655  x;
1656 
1657  unsigned int
1658  pixel;
1659 
1660  if (image->colorspace != CMYKColorspace)
1661  {
1662  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1663  "ColorSeparatedImageRequired","`%s'",image->filename);
1664  return;
1665  }
1666  switch (quantum_info->depth)
1667  {
1668  case 8:
1669  {
1670  unsigned char
1671  pixel;
1672 
1673  for (x=0; x < (ssize_t) number_pixels; x++)
1674  {
1675  p=PushCharPixel(p,&pixel);
1676  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1677  p=PushCharPixel(p,&pixel);
1678  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1679  p=PushCharPixel(p,&pixel);
1680  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1681  p=PushCharPixel(p,&pixel);
1682  SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1683  p=PushCharPixel(p,&pixel);
1684  SetPixelAlpha(image,ScaleCharToQuantum(pixel),q);
1685  p+=quantum_info->pad;
1686  q+=GetPixelChannels(image);
1687  }
1688  break;
1689  }
1690  case 16:
1691  {
1692  unsigned short
1693  pixel;
1694 
1695  if (quantum_info->format == FloatingPointQuantumFormat)
1696  {
1697  for (x=0; x < (ssize_t) number_pixels; x++)
1698  {
1699  p=PushShortPixel(quantum_info->endian,p,&pixel);
1701  HalfToSinglePrecision(pixel)),q);
1702  p=PushShortPixel(quantum_info->endian,p,&pixel);
1704  HalfToSinglePrecision(pixel)),q);
1705  p=PushShortPixel(quantum_info->endian,p,&pixel);
1707  HalfToSinglePrecision(pixel)),q);
1708  p=PushShortPixel(quantum_info->endian,p,&pixel);
1710  HalfToSinglePrecision(pixel)),q);
1711  p=PushShortPixel(quantum_info->endian,p,&pixel);
1713  HalfToSinglePrecision(pixel)),q);
1714  p+=quantum_info->pad;
1715  q+=GetPixelChannels(image);
1716  }
1717  break;
1718  }
1719  for (x=0; x < (ssize_t) number_pixels; x++)
1720  {
1721  p=PushShortPixel(quantum_info->endian,p,&pixel);
1722  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1723  p=PushShortPixel(quantum_info->endian,p,&pixel);
1724  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1725  p=PushShortPixel(quantum_info->endian,p,&pixel);
1726  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1727  p=PushShortPixel(quantum_info->endian,p,&pixel);
1728  SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1729  p=PushShortPixel(quantum_info->endian,p,&pixel);
1730  SetPixelAlpha(image,ScaleShortToQuantum(pixel),q);
1731  p+=quantum_info->pad;
1732  q+=GetPixelChannels(image);
1733  }
1734  break;
1735  }
1736  case 32:
1737  {
1738  unsigned int
1739  pixel;
1740 
1741  if (quantum_info->format == FloatingPointQuantumFormat)
1742  {
1743  float
1744  pixel;
1745 
1746  for (x=0; x < (ssize_t) number_pixels; x++)
1747  {
1748  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1749  SetPixelRed(image,ClampToQuantum(pixel),q);
1750  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1751  SetPixelGreen(image,ClampToQuantum(pixel),q);
1752  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1753  SetPixelBlue(image,ClampToQuantum(pixel),q);
1754  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1755  SetPixelBlack(image,ClampToQuantum(pixel),q);
1756  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1757  SetPixelAlpha(image,ClampToQuantum(pixel),q);
1758  p+=quantum_info->pad;
1759  q+=GetPixelChannels(image);
1760  }
1761  break;
1762  }
1763  for (x=0; x < (ssize_t) number_pixels; x++)
1764  {
1765  p=PushLongPixel(quantum_info->endian,p,&pixel);
1766  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1767  p=PushLongPixel(quantum_info->endian,p,&pixel);
1768  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1769  p=PushLongPixel(quantum_info->endian,p,&pixel);
1770  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1771  p=PushLongPixel(quantum_info->endian,p,&pixel);
1772  SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1773  p=PushLongPixel(quantum_info->endian,p,&pixel);
1774  SetPixelAlpha(image,ScaleLongToQuantum(pixel),q);
1775  p+=quantum_info->pad;
1776  q+=GetPixelChannels(image);
1777  }
1778  break;
1779  }
1780  case 64:
1781  {
1782  if (quantum_info->format == FloatingPointQuantumFormat)
1783  {
1784  double
1785  pixel;
1786 
1787  for (x=0; x < (ssize_t) number_pixels; x++)
1788  {
1789  p=PushDoublePixel(quantum_info,p,&pixel);
1790  SetPixelRed(image,ClampToQuantum(pixel),q);
1791  p=PushDoublePixel(quantum_info,p,&pixel);
1792  SetPixelGreen(image,ClampToQuantum(pixel),q);
1793  p=PushDoublePixel(quantum_info,p,&pixel);
1794  SetPixelBlue(image,ClampToQuantum(pixel),q);
1795  p=PushDoublePixel(quantum_info,p,&pixel);
1796  SetPixelBlack(image,ClampToQuantum(pixel),q);
1797  p=PushDoublePixel(quantum_info,p,&pixel);
1798  SetPixelAlpha(image,ClampToQuantum(pixel),q);
1799  p=PushDoublePixel(quantum_info,p,&pixel);
1800  p+=quantum_info->pad;
1801  q+=GetPixelChannels(image);
1802  }
1803  break;
1804  }
1805  }
1806  default:
1807  {
1808  range=GetQuantumRange(quantum_info->depth);
1809  for (x=0; x < (ssize_t) number_pixels; x++)
1810  {
1811  p=PushQuantumPixel(quantum_info,p,&pixel);
1812  SetPixelRed(image,ScaleAnyToQuantum(pixel,range),q);
1813  p=PushQuantumPixel(quantum_info,p,&pixel);
1814  SetPixelGreen(image,ScaleAnyToQuantum(pixel,range),q);
1815  p=PushQuantumPixel(quantum_info,p,&pixel);
1816  SetPixelBlue(image,ScaleAnyToQuantum(pixel,range),q);
1817  p=PushQuantumPixel(quantum_info,p,&pixel);
1818  SetPixelBlack(image,ScaleAnyToQuantum(pixel,range),q);
1819  p=PushQuantumPixel(quantum_info,p,&pixel);
1820  SetPixelAlpha(image,ScaleAnyToQuantum(pixel,range),q);
1821  q+=GetPixelChannels(image);
1822  }
1823  break;
1824  }
1825  }
1826 }
1827 
1828 static void ImportCMYKOQuantum(const Image *image,QuantumInfo *quantum_info,
1829  const MagickSizeType number_pixels,const unsigned char *magick_restrict p,
1830  Quantum *magick_restrict q,ExceptionInfo *exception)
1831 {
1832  QuantumAny
1833  range;
1834 
1835  register ssize_t
1836  x;
1837 
1838  unsigned int
1839  pixel;
1840 
1841  if (image->colorspace != CMYKColorspace)
1842  {
1843  (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1844  "ColorSeparatedImageRequired","`%s'",image->filename);
1845  return;
1846  }
1847  switch (quantum_info->depth)
1848  {
1849  case 8:
1850  {
1851  unsigned char
1852  pixel;
1853 
1854  for (x=0; x < (ssize_t) number_pixels; x++)
1855  {
1856  p=PushCharPixel(p,&pixel);
1857  SetPixelRed(image,ScaleCharToQuantum(pixel),q);
1858  p=PushCharPixel(p,&pixel);
1859  SetPixelGreen(image,ScaleCharToQuantum(pixel),q);
1860  p=PushCharPixel(p,&pixel);
1861  SetPixelBlue(image,ScaleCharToQuantum(pixel),q);
1862  p=PushCharPixel(p,&pixel);
1863  SetPixelBlack(image,ScaleCharToQuantum(pixel),q);
1864  p=PushCharPixel(p,&pixel);
1865  SetPixelOpacity(image,ScaleCharToQuantum(pixel),q);
1866  p+=quantum_info->pad;
1867  q+=GetPixelChannels(image);
1868  }
1869  break;
1870  }
1871  case 16:
1872  {
1873  unsigned short
1874  pixel;
1875 
1876  if (quantum_info->format == FloatingPointQuantumFormat)
1877  {
1878  for (x=0; x < (ssize_t) number_pixels; x++)
1879  {
1880  p=PushShortPixel(quantum_info->endian,p,&pixel);
1882  HalfToSinglePrecision(pixel)),q);
1883  p=PushShortPixel(quantum_info->endian,p,&pixel);
1885  HalfToSinglePrecision(pixel)),q);
1886  p=PushShortPixel(quantum_info->endian,p,&pixel);
1888  HalfToSinglePrecision(pixel)),q);
1889  p=PushShortPixel(quantum_info->endian,p,&pixel);
1891  HalfToSinglePrecision(pixel)),q);
1892  p=PushShortPixel(quantum_info->endian,p,&pixel);
1894  HalfToSinglePrecision(pixel)),q);
1895  p+=quantum_info->pad;
1896  q+=GetPixelChannels(image);
1897  }
1898  break;
1899  }
1900  for (x=0; x < (ssize_t) number_pixels; x++)
1901  {
1902  p=PushShortPixel(quantum_info->endian,p,&pixel);
1903  SetPixelRed(image,ScaleShortToQuantum(pixel),q);
1904  p=PushShortPixel(quantum_info->endian,p,&pixel);
1905  SetPixelGreen(image,ScaleShortToQuantum(pixel),q);
1906  p=PushShortPixel(quantum_info->endian,p,&pixel);
1907  SetPixelBlue(image,ScaleShortToQuantum(pixel),q);
1908  p=PushShortPixel(quantum_info->endian,p,&pixel);
1909  SetPixelBlack(image,ScaleShortToQuantum(pixel),q);
1910  p=PushShortPixel(quantum_info->endian,p,&pixel);
1911  SetPixelOpacity(image,ScaleShortToQuantum(pixel),q);
1912  p+=quantum_info->pad;
1913  q+=GetPixelChannels(image);
1914  }
1915  break;
1916  }
1917  case 32:
1918  {
1919  unsigned int
1920  pixel;
1921 
1922  if (quantum_info->format == FloatingPointQuantumFormat)
1923  {
1924  float
1925  pixel;
1926 
1927  for (x=0; x < (ssize_t) number_pixels; x++)
1928  {
1929  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1930  SetPixelRed(image,ClampToQuantum(pixel),q);
1931  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1932  SetPixelGreen(image,ClampToQuantum(pixel),q);
1933  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1934  SetPixelBlue(image,ClampToQuantum(pixel),q);
1935  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1936  SetPixelBlack(image,ClampToQuantum(pixel),q);
1937  p=PushQuantumFloatPixel(quantum_info,p,&pixel);
1938  SetPixelOpacity(image,ClampToQuantum(pixel),q);
1939  p+=quantum_info->pad;
1940  q+=GetPixelChannels(image);
1941  }
1942  break;
1943  }
1944  for (x=0; x < (ssize_t) number_pixels; x++)
1945  {
1946  p=PushLongPixel(quantum_info->endian,p,&pixel);
1947  SetPixelRed(image,ScaleLongToQuantum(pixel),q);
1948  p=PushLongPixel(quantum_info->endian,p,&pixel);
1949  SetPixelGreen(image,ScaleLongToQuantum(pixel),q);
1950  p=PushLongPixel(quantum_info->endian,p,&pixel);
1951  SetPixelBlue(image,ScaleLongToQuantum(pixel),q);
1952  p=PushLongPixel(quantum_info->endian,p,&pixel);
1953  SetPixelBlack(image,ScaleLongToQuantum(pixel),q);
1954  p=PushLongPixel(quantum_info->endian,p,&pixel);
1955  SetPixelOpacity(image,ScaleLongToQuantum(pixel),q);
1956  p+=quantum_info->pad;
1957  q+=GetPixelChannels(image);
1958  }
1959  break;
1960  }
1961  case 64:
1962  {
1963  if (quantum_info->format == FloatingPointQuantumFormat)
1964  {
1965  double
1966  pixel;
1967 
1968  for (x=0; x < (ssize_t) number_pixels; x++)
1969  {
1970  p=PushDoublePixel(quantum_info,p,&pixel);
1971  SetPixelRed(image,ClampToQuantum(pixel),q);
1972  p=PushDoublePixel(quantum_info,p,&pixel);
1973  SetPixelGreen(image,ClampToQuantum(pixel),q);
1974  p=PushDoublePixel(quantum_info,p,&pixel);
1975  SetPixelBlue(image,ClampToQuantum(pixel),q);
1976  p=PushDoublePixel(quantum_info,p,&pixel);
1977  SetPixelBlack(image,ClampToQuantum(pixel),q);
1978  p=PushDoublePixel(quantum_info,p,&pixel);
1979  SetPixelOpacity(image,ClampToQuantum(pixel),q);
1980  p=PushDoublePixel(quantum_info,p,&pixel);
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  p=PushLongPixel(quantum_info->endian,p,&pixel);
2134  if (x++ < (ssize_t) (number_pixels-1))
2135  {
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  p=PushLongPixel(quantum_info->endian,p,&pixel);
2163  if (x++ < (ssize_t) (number_pixels-1))
2164  {
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 == DisassociatedQuantumAlpha)
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  if (GetPixelWriteMask(image,q) <= (QuantumRange/2))
4284  {
4285  q+=GetPixelChannels(image);
4286  continue;
4287  }
4288  Sa=QuantumScale*GetPixelAlpha(image,q);
4289  gamma=PerceptibleReciprocal(Sa);
4290  for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
4291  {
4292  PixelChannel channel = GetPixelChannelChannel(image,i);
4293  PixelTrait traits = GetPixelChannelTraits(image,channel);
4294  if ((channel == AlphaPixelChannel) ||
4295  ((traits & UpdatePixelTrait) == 0))
4296  continue;
4297  q[i]=ClampToQuantum(gamma*q[i]);
4298  }
4299  q+=GetPixelChannels(image);
4300  }
4301  }
4302  return(extent);
4303 }
MagickExport Quantum * GetAuthenticPixelQueue(const Image *image)
Definition: cache.c:1316
#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:575
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)
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)
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
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)
static const unsigned char * PushShortPixel(const EndianType endian, const unsigned char *pixels, unsigned short *pixel)
#define MagickCoreSignature
MagickBooleanType pack
static const unsigned char * PushCharPixel(const unsigned char *pixels, unsigned char *pixel)
MagickBooleanType
Definition: magick-type.h:156
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 Quantum GetPixelWriteMask(const Image *magick_restrict image, const Quantum *magick_restrict pixel)
static void ImportBlueQuantum(const Image *image, QuantumInfo *quantum_info, const MagickSizeType number_pixels, const unsigned char *magick_restrict p, Quantum *magick_restrict q)
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:128
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:1058
static const unsigned char * PushLongPixel(const EndianType endian, const unsigned char *pixels, unsigned int *pixel)
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
size_t signature
Definition: image.h:354
#define QuantumScale
Definition: magick-type.h:113
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:485
static void SetPixelBlue(const Image *magick_restrict image, const Quantum blue, Quantum *magick_restrict pixel)
PixelChannel
Definition: pixel.h:66
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:1492
static float HalfToSinglePrecision(const unsigned short half)
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
static Quantum ClampToQuantum(const MagickRealType value)
Definition: quantum.h:84
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:82
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:50
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:132
MagickBooleanType min_is_white
MagickSizeType QuantumAny
Definition: magick-type.h:142
ColorspaceType colorspace
Definition: image.h:157
#define QuantumRange
Definition: magick-type.h:83
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:302