blob: 24663c66e84710e34bc60b67092021ff0abfddf6 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
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% John Cristy %
22% October 1998 %
23% %
24% %
25% Copyright 1999-2008 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% http://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 "magick/studio.h"
48#include "magick/property.h"
49#include "magick/blob.h"
50#include "magick/blob-private.h"
51#include "magick/color-private.h"
52#include "magick/exception.h"
53#include "magick/exception-private.h"
54#include "magick/cache.h"
55#include "magick/constitute.h"
56#include "magick/delegate.h"
57#include "magick/geometry.h"
58#include "magick/list.h"
59#include "magick/magick.h"
60#include "magick/memory_.h"
61#include "magick/monitor.h"
62#include "magick/option.h"
63#include "magick/pixel.h"
64#include "magick/pixel-private.h"
65#include "magick/quantum.h"
66#include "magick/quantum-private.h"
67#include "magick/resource_.h"
68#include "magick/semaphore.h"
69#include "magick/statistic.h"
70#include "magick/stream.h"
71#include "magick/string_.h"
72#include "magick/utility.h"
73
74/*
75%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76% %
77% %
78% %
79% I m p o r t Q u a n t u m P i x e l s %
80% %
81% %
82% %
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84%
85% ImportQuantumPixels() transfers one or more pixel components from a user
86% supplied buffer into the image pixel cache of an image. The pixels are
87% expected in network byte order. It returns MagickTrue if the pixels are
88% successfully transferred, otherwise MagickFalse.
89%
90% The format of the ImportQuantumPixels method is:
91%
92% size_t ImportQuantumPixels(Image *image,CacheView *image_view,
93% const QuantumInfo *quantum_info,const QuantumType quantum_type,
94% const unsigned char *pixels,ExceptionInfo *exception)
95%
96% A description of each parameter follows:
97%
98% o image: the image.
99%
100% o image_view: the image cache view.
101%
102% o quantum_info: the quantum info.
103%
104% o quantum_type: Declare which pixel components to transfer (red, green,
105% blue, opacity, RGB, or RGBA).
106%
107% o pixels: The pixel components are transferred from this buffer.
108%
109% o exception: return any errors or warnings in this structure.
110%
111*/
112
113static inline IndexPacket PushColormapIndex(Image *image,
114 const unsigned long index,MagickBooleanType *range_exception)
115{
116 if (index < image->colors)
117 return((IndexPacket) index);
118 *range_exception=MagickTrue;
119 return((IndexPacket) 0);
120}
121
122static inline const unsigned char *PushDoublePixel(
123 const QuantumState *quantum_state,const unsigned char *pixels,double *pixel)
124{
125 double
126 *p;
127
128 unsigned char
129 quantum[8];
130
131 if (quantum_state->endian != LSBEndian)
132 {
133 quantum[7]=(*pixels++);
134 quantum[6]=(*pixels++);
135 quantum[5]=(*pixels++);
136 quantum[5]=(*pixels++);
137 quantum[3]=(*pixels++);
138 quantum[2]=(*pixels++);
139 quantum[1]=(*pixels++);
140 quantum[0]=(*pixels++);
141 p=(double *) quantum;
142 *pixel=(*p);
143 *pixel-=quantum_state->minimum;
144 *pixel*=quantum_state->scale;
145 return(pixels);
146 }
147 quantum[0]=(*pixels++);
148 quantum[1]=(*pixels++);
149 quantum[2]=(*pixels++);
150 quantum[3]=(*pixels++);
151 quantum[4]=(*pixels++);
152 quantum[5]=(*pixels++);
153 quantum[6]=(*pixels++);
154 quantum[7]=(*pixels++);
155 p=(double *) quantum;
156 *pixel=(*p);
157 *pixel-=quantum_state->minimum;
158 *pixel*=quantum_state->scale;
159 return(pixels);
160}
161
162static inline const unsigned char *PushFloatPixel(
163 const QuantumState *quantum_state,const unsigned char *pixels,float *pixel)
164{
165 float
166 *p;
167
168 unsigned char
169 quantum[4];
170
171 if (quantum_state->endian != LSBEndian)
172 {
173 quantum[3]=(*pixels++);
174 quantum[2]=(*pixels++);
175 quantum[1]=(*pixels++);
176 quantum[0]=(*pixels++);
177 p=(float *) quantum;
178 *pixel=(*p);
179 *pixel-=quantum_state->minimum;
180 *pixel*=quantum_state->scale;
181 return(pixels);
182 }
183 quantum[0]=(*pixels++);
184 quantum[1]=(*pixels++);
185 quantum[2]=(*pixels++);
186 quantum[3]=(*pixels++);
187 p=(float *) quantum;
188 *pixel=(*p);
189 *pixel-=quantum_state->minimum;
190 *pixel*=quantum_state->scale;
191 return(pixels);
192}
193
194static inline const unsigned char *PushQuantumPixel(
195 QuantumState *quantum_state,const unsigned long depth,
196 const unsigned char *pixels,unsigned long *quantum)
197{
198 register long
199 i;
200
201 register unsigned long
202 quantum_bits;
203
204 *quantum=(QuantumAny) 0;
205 for (i=(long) depth; i > 0L; )
206 {
207 if (quantum_state->bits == 0UL)
208 {
209 quantum_state->pixel=(*pixels++);
210 quantum_state->bits=8UL;
211 }
212 quantum_bits=(unsigned long) i;
213 if (quantum_bits > quantum_state->bits)
214 quantum_bits=quantum_state->bits;
215 i-=quantum_bits;
216 quantum_state->bits-=quantum_bits;
217 *quantum=(*quantum << quantum_bits) | ((quantum_state->pixel >>
218 quantum_state->bits) &~ ((~0UL) << quantum_bits));
219 }
220 return(pixels);
221}
222
223static inline const unsigned char *PushQuantumLongPixel(
224 QuantumState *quantum_state,const unsigned long depth,
225 const unsigned char *pixels,unsigned long *quantum)
226{
227 register long
228 i;
229
230 register unsigned long
231 quantum_bits;
232
233 *quantum=0UL;
234 for (i=(long) depth; i > 0; )
235 {
236 if (quantum_state->bits == 0)
237 {
238 pixels=PushLongPixel(quantum_state->endian,pixels,
239 &quantum_state->pixel);
240 quantum_state->bits=32UL;
241 }
242 quantum_bits=(unsigned long) i;
243 if (quantum_bits > quantum_state->bits)
244 quantum_bits=quantum_state->bits;
245 *quantum|=(((quantum_state->pixel >> (32UL-quantum_state->bits)) &
246 quantum_state->mask[quantum_bits]) << (depth-i));
247 i-=quantum_bits;
248 quantum_state->bits-=quantum_bits;
249 }
250 return(pixels);
251}
252
253MagickExport size_t ImportQuantumPixels(Image *image,CacheView *image_view,
254 const QuantumInfo *quantum_info,const QuantumType quantum_type,
255 const unsigned char *pixels,ExceptionInfo *exception)
256{
257 EndianType
258 endian;
259
260 long
261 bit;
262
263 MagickSizeType
264 number_pixels;
265
266 QuantumAny
267 range;
268
269 QuantumState
270 quantum_state;
271
272 register const unsigned char
cristyaebafa22009-11-26 01:48:56 +0000273 *restrict p;
cristy3ed852e2009-09-05 21:47:34 +0000274
275 register IndexPacket
cristyc47d1f82009-11-26 01:44:43 +0000276 *restrict indexes;
cristy3ed852e2009-09-05 21:47:34 +0000277
278 register long
279 x;
280
281 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +0000282 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +0000283
284 size_t
285 extent;
286
287 unsigned long
288 pixel;
289
290 assert(image != (Image *) NULL);
291 assert(image->signature == MagickSignature);
292 if (image->debug != MagickFalse)
293 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
294 assert(quantum_info != (QuantumInfo *) NULL);
295 assert(quantum_info->signature == MagickSignature);
296 if (pixels == (const unsigned char *) NULL)
297 pixels=GetQuantumPixels(quantum_info);
298 x=0;
299 p=pixels;
300 number_pixels=GetImageExtent(image);
301 q=GetAuthenticPixelQueue(image);
302 indexes=GetAuthenticIndexQueue(image);
303 if (image_view != (CacheView *) NULL)
304 {
305 number_pixels=GetCacheViewExtent(image_view);
306 q=GetCacheViewAuthenticPixelQueue(image_view);
307 indexes=GetCacheViewAuthenticIndexQueue(image_view);
308 }
309 InitializeQuantumState(quantum_info,image->endian,&quantum_state);
310 extent=GetQuantumExtent(image,quantum_info,quantum_type);
311 endian=quantum_state.endian;
312 switch (quantum_type)
313 {
314 case IndexQuantum:
315 {
316 MagickBooleanType
317 range_exception;
318
319 if (image->storage_class != PseudoClass)
320 {
321 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
322 "ColormappedImageRequired","`%s'",image->filename);
323 return(extent);
324 }
325 range_exception=MagickFalse;
326 switch (quantum_info->depth)
327 {
328 case 1:
329 {
330 register unsigned char
331 pixel;
332
333 for (x=0; x < ((long) number_pixels-7); x+=8)
334 {
335 for (bit=0; bit < 8; bit++)
336 {
337 if (quantum_info->min_is_white == MagickFalse)
338 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
339 0x00 : 0x01);
340 else
341 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
342 0x00 : 0x01);
343 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
344 *q=image->colormap[(long) indexes[x+bit]];
345 q++;
346 }
347 p++;
348 }
349 for (bit=0; bit < (long) (number_pixels % 8); bit++)
350 {
351 if (quantum_info->min_is_white == MagickFalse)
352 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
353 0x00 : 0x01);
354 else
355 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
356 0x00 : 0x01);
357 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
358 *q=image->colormap[(long) indexes[x+bit]];
359 q++;
360 }
361 break;
362 }
363 case 4:
364 {
365 register unsigned char
366 pixel;
367
368 for (x=0; x < ((long) number_pixels-1); x+=2)
369 {
370 pixel=(unsigned char) ((*p >> 4) & 0xf);
371 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
372 *q=image->colormap[(long) indexes[x]];
373 q++;
374 pixel=(unsigned char) ((*p) & 0xf);
375 indexes[x+1]=PushColormapIndex(image,pixel,&range_exception);
376 *q=image->colormap[(long) indexes[x+1]];
377 p++;
378 q++;
379 }
380 for (bit=0; bit < (long) (number_pixels % 2); bit++)
381 {
382 pixel=(unsigned char) ((*p++ >> 4) & 0xf);
383 indexes[x+bit]=PushColormapIndex(image,pixel,&range_exception);
384 *q=image->colormap[(long) indexes[x+bit]];
385 q++;
386 }
387 break;
388 }
389 case 8:
390 {
391 unsigned char
392 pixel;
393
394 for (x=0; x < (long) number_pixels; x++)
395 {
396 p=PushCharPixel(p,&pixel);
397 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
398 *q=image->colormap[(long) indexes[x]];
399 p+=quantum_info->pad;
400 q++;
401 }
402 break;
403 }
404 case 16:
405 {
406 unsigned short
407 pixel;
408
cristyc9672a92010-01-06 00:57:45 +0000409 if (quantum_info->format == FloatingPointQuantumFormat)
410 {
411 for (x=0; x < (long) number_pixels; x++)
412 {
413 p=PushShortPixel(endian,p,&pixel);
414 indexes[x]=PushColormapIndex(image,RoundToQuantum(
415 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)),
416 &range_exception);
417 *q=image->colormap[(long) indexes[x]];
418 p+=quantum_info->pad;
419 q++;
420 }
421 break;
422 }
cristy3ed852e2009-09-05 21:47:34 +0000423 for (x=0; x < (long) number_pixels; x++)
424 {
425 p=PushShortPixel(endian,p,&pixel);
426 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
427 *q=image->colormap[(long) indexes[x]];
428 p+=quantum_info->pad;
429 q++;
430 }
431 break;
432 }
433 case 32:
434 {
435 unsigned long
436 pixel;
437
438 if (quantum_info->format == FloatingPointQuantumFormat)
439 {
440 float
441 pixel;
442
443 for (x=0; x < (long) number_pixels; x++)
444 {
445 p=PushFloatPixel(&quantum_state,p,&pixel);
446 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
447 &range_exception);
448 *q=image->colormap[(long) indexes[x]];
449 p+=quantum_info->pad;
450 q++;
451 }
452 break;
453 }
454 for (x=0; x < (long) number_pixels; x++)
455 {
456 p=PushLongPixel(endian,p,&pixel);
457 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
458 *q=image->colormap[(long) indexes[x]];
459 p+=quantum_info->pad;
460 q++;
461 }
462 break;
463 }
464 case 64:
465 {
466 if (quantum_info->format == FloatingPointQuantumFormat)
467 {
468 double
469 pixel;
470
471 for (x=0; x < (long) number_pixels; x++)
472 {
473 p=PushDoublePixel(&quantum_state,p,&pixel);
474 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
475 &range_exception);
476 *q=image->colormap[(long) indexes[x]];
477 p+=quantum_info->pad;
478 q++;
479 }
480 break;
481 }
482 }
483 default:
484 {
485 for (x=0; x < (long) number_pixels; x++)
486 {
487 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
488 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
489 *q=image->colormap[(long) indexes[x]];
490 p+=quantum_info->pad;
491 q++;
492 }
493 break;
494 }
495 }
496 if (range_exception != MagickFalse)
497 (void) ThrowMagickException(exception,GetMagickModule(),
498 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
499 break;
500 }
501 case IndexAlphaQuantum:
502 {
503 MagickBooleanType
504 range_exception;
505
506 if (image->storage_class != PseudoClass)
507 {
508 (void) ThrowMagickException(exception,GetMagickModule(),
509 ImageError,"ColormappedImageRequired","`%s'",image->filename);
510 return(extent);
511 }
512 range_exception=MagickFalse;
513 switch (quantum_info->depth)
514 {
515 case 1:
516 {
517 register unsigned char
518 pixel;
519
520 for (x=0; x < ((long) number_pixels-3); x+=4)
521 {
522 for (bit=0; bit < 8; bit+=2)
523 {
524 if (quantum_info->min_is_white == MagickFalse)
525 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
526 0x00 : 0x01);
527 else
528 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
529 0x00 : 0x01);
530 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
531 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
532 q->green=q->red;
533 q->blue=q->red;
534 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
535 == 0 ? TransparentOpacity : OpaqueOpacity);
536 q++;
537 }
538 }
539 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
540 {
541 if (quantum_info->min_is_white == MagickFalse)
542 pixel=(unsigned char) (((*p) & (1 << (7-bit))) == 0 ?
543 0x00 : 0x01);
544 else
545 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ?
546 0x00 : 0x01);
547 indexes[x+bit/2]=(IndexPacket) (pixel == 0 ? 0 : 1);
548 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
549 q->green=q->red;
550 q->blue=q->red;
551 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) ==
552 0 ? TransparentOpacity : OpaqueOpacity);
553 q++;
554 }
555 break;
556 }
557 case 4:
558 {
559 register unsigned char
560 pixel;
561
562 range=GetQuantumRange(image->depth);
563 for (x=0; x < (long) number_pixels; x++)
564 {
565 pixel=(unsigned char) ((*p >> 4) & 0xf);
566 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
567 *q=image->colormap[(long) indexes[x]];
568 pixel=(unsigned char) ((*p) & 0xf);
569 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
570 p++;
571 q++;
572 }
573 break;
574 }
575 case 8:
576 {
577 unsigned char
578 pixel;
579
580 for (x=0; x < (long) number_pixels; x++)
581 {
582 p=PushCharPixel(p,&pixel);
583 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
584 *q=image->colormap[(long) indexes[x]];
585 p=PushCharPixel(p,&pixel);
586 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
587 p+=quantum_info->pad;
588 q++;
589 }
590 break;
591 }
592 case 16:
593 {
594 unsigned short
595 pixel;
596
cristyc9672a92010-01-06 00:57:45 +0000597 if (quantum_info->format == FloatingPointQuantumFormat)
598 {
599 for (x=0; x < (long) number_pixels; x++)
600 {
601 p=PushShortPixel(endian,p,&pixel);
602 indexes[x]=PushColormapIndex(image,RoundToQuantum(
603 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)),
604 &range_exception);
605 *q=image->colormap[(long) indexes[x]];
606 p=PushShortPixel(endian,p,&pixel);
607 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(
608 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)));
609 p+=quantum_info->pad;
610 q++;
611 }
612 break;
613 }
cristy3ed852e2009-09-05 21:47:34 +0000614 for (x=0; x < (long) number_pixels; x++)
615 {
616 p=PushShortPixel(endian,p,&pixel);
617 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
618 *q=image->colormap[(long) indexes[x]];
619 p=PushShortPixel(endian,p,&pixel);
620 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
621 p+=quantum_info->pad;
622 q++;
623 }
624 break;
625 }
626 case 32:
627 {
628 unsigned long
629 pixel;
630
631 if (quantum_info->format == FloatingPointQuantumFormat)
632 {
633 float
634 pixel;
635
636 for (x=0; x < (long) number_pixels; x++)
637 {
638 p=PushFloatPixel(&quantum_state,p,&pixel);
639 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
640 &range_exception);
641 *q=image->colormap[(long) indexes[x]];
642 p=PushFloatPixel(&quantum_state,p,&pixel);
643 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
644 p+=quantum_info->pad;
645 q++;
646 }
647 break;
648 }
649 for (x=0; x < (long) number_pixels; x++)
650 {
651 p=PushLongPixel(endian,p,&pixel);
652 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
653 *q=image->colormap[(long) indexes[x]];
654 p=PushLongPixel(endian,p,&pixel);
655 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
656 p+=quantum_info->pad;
657 q++;
658 }
659 break;
660 }
661 case 64:
662 {
663 if (quantum_info->format == FloatingPointQuantumFormat)
664 {
665 double
666 pixel;
667
668 for (x=0; x < (long) number_pixels; x++)
669 {
670 p=PushDoublePixel(&quantum_state,p,&pixel);
671 indexes[x]=PushColormapIndex(image,RoundToQuantum(pixel),
672 &range_exception);
673 *q=image->colormap[(long) indexes[x]];
674 p=PushDoublePixel(&quantum_state,p,&pixel);
675 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
676 p+=quantum_info->pad;
677 q++;
678 }
679 break;
680 }
681 }
682 default:
683 {
684 range=GetQuantumRange(image->depth);
685 for (x=0; x < (long) number_pixels; x++)
686 {
687 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
688 indexes[x]=PushColormapIndex(image,pixel,&range_exception);
689 *q=image->colormap[(long) indexes[x]];
690 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
691 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
692 p+=quantum_info->pad;
693 q++;
694 }
695 break;
696 }
697 }
698 if (range_exception != MagickFalse)
699 (void) ThrowMagickException(exception,GetMagickModule(),
700 CorruptImageError,"InvalidColormapIndex","`%s'",image->filename);
701 break;
702 }
703 case GrayQuantum:
704 {
705 switch (quantum_info->depth)
706 {
707 case 1:
708 {
709 register Quantum
710 black,
711 white;
712
713 black=0;
714 white=(Quantum) QuantumRange;
715 if (quantum_info->min_is_white != MagickFalse)
716 {
717 black=(Quantum) QuantumRange;
718 white=0;
719 }
720 for (x=0; x < ((long) number_pixels-7); x+=8)
721 {
722 for (bit=0; bit < 8; bit++)
723 {
724 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
725 q->green=q->red;
726 q->blue=q->red;
727 q++;
728 }
729 p++;
730 }
731 for (bit=0; bit < (long) (number_pixels % 8); bit++)
732 {
733 q->red=(((*p) & (1 << (7-bit))) == 0 ? black : white);
734 q->green=q->red;
735 q->blue=q->red;
736 q++;
737 }
738 if (bit != 0)
739 p++;
740 break;
741 }
742 case 4:
743 {
744 register unsigned char
745 pixel;
746
747 range=GetQuantumRange(image->depth);
748 for (x=0; x < ((long) number_pixels-1); x+=2)
749 {
750 pixel=(unsigned char) ((*p >> 4) & 0xf);
751 q->red=ScaleAnyToQuantum(pixel,range);
752 q->green=q->red;
753 q->blue=q->red;
754 q++;
755 pixel=(unsigned char) ((*p) & 0xf);
756 q->red=ScaleAnyToQuantum(pixel,range);
757 q->green=q->red;
758 q->blue=q->red;
759 p++;
760 q++;
761 }
762 for (bit=0; bit < (long) (number_pixels % 2); bit++)
763 {
764 pixel=(unsigned char) (*p++ >> 4);
765 q->red=ScaleAnyToQuantum(pixel,range);
766 q->green=q->red;
767 q->blue=q->red;
768 q++;
769 }
770 break;
771 }
772 case 8:
773 {
774 unsigned char
775 pixel;
776
777 if (quantum_info->min_is_white != MagickFalse)
778 {
779 for (x=0; x < (long) number_pixels; x++)
780 {
781 p=PushCharPixel(p,&pixel);
782 q->red=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
783 q->green=q->red;
784 q->blue=q->red;
785 q->opacity=OpaqueOpacity;
786 p+=quantum_info->pad;
787 q++;
788 }
789 break;
790 }
791 for (x=0; x < (long) number_pixels; x++)
792 {
793 p=PushCharPixel(p,&pixel);
794 q->red=ScaleCharToQuantum(pixel);
795 q->green=q->red;
796 q->blue=q->red;
797 q->opacity=OpaqueOpacity;
798 p+=quantum_info->pad;
799 q++;
800 }
801 break;
802 }
803 case 10:
804 {
805 range=GetQuantumRange(image->depth);
806 if (quantum_info->pack == MagickFalse)
807 {
808 if (image->endian != LSBEndian)
809 {
810 for (x=0; x < (long) number_pixels/3; x++)
811 {
812 p=PushLongPixel(endian,p,&pixel);
813 q->red=ScaleAnyToQuantum((pixel >> 0) & 0x3ff,range);
814 q->green=q->red;
815 q->blue=q->red;
816 q++;
817 q->red=ScaleAnyToQuantum((pixel >> 10) & 0x3ff,range);
818 q->green=q->red;
819 q->blue=q->red;
820 q++;
821 q->red=ScaleAnyToQuantum((pixel >> 20) & 0x3ff,range);
822 q->green=q->red;
823 q->blue=q->red;
824 p+=quantum_info->pad;
825 q++;
826 }
827 break;
828 }
829 for (x=0; x < (long) number_pixels/3; x++)
830 {
831 p=PushLongPixel(endian,p,&pixel);
832 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
833 q->green=q->red;
834 q->blue=q->red;
835 q++;
836 q->red=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
837 q->green=q->red;
838 q->blue=q->red;
839 q++;
840 q->red=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
841 q->green=q->red;
842 q->blue=q->red;
843 p+=quantum_info->pad;
844 q++;
845 }
846 break;
847 }
848 for (x=0; x < (long) number_pixels; x++)
849 {
850 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
851 q->red=ScaleAnyToQuantum(pixel,range);
852 q->green=q->red;
853 q->blue=q->red;
854 p+=quantum_info->pad;
855 q++;
856 }
857 break;
858 }
859 case 12:
860 {
861 range=GetQuantumRange(image->depth);
862 if (quantum_info->pack == MagickFalse)
863 {
864 unsigned short
865 pixel;
866
867 for (x=0; x < (long) (number_pixels-1); x+=2)
868 {
869 p=PushShortPixel(endian,p,&pixel);
870 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
871 q->green=q->red;
872 q->blue=q->red;
873 q++;
874 p=PushShortPixel(endian,p,&pixel);
875 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
876 q->green=q->red;
877 q->blue=q->red;
878 p+=quantum_info->pad;
879 q++;
880 }
881 for (bit=0; bit < (long) (number_pixels % 2); bit++)
882 {
883 p=PushShortPixel(endian,p,&pixel);
884 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
885 q->green=q->red;
886 q->blue=q->red;
887 p+=quantum_info->pad;
888 q++;
889 }
890 if (bit != 0)
891 p++;
892 break;
893 }
894 for (x=0; x < (long) number_pixels; x++)
895 {
896 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
897 q->red=ScaleAnyToQuantum(pixel,range);
898 q->green=q->red;
899 q->blue=q->red;
900 p+=quantum_info->pad;
901 q++;
902 }
903 break;
904 }
905 case 16:
906 {
907 unsigned short
908 pixel;
909
910 if (quantum_info->min_is_white != MagickFalse)
911 {
912 for (x=0; x < (long) number_pixels; x++)
913 {
914 p=PushShortPixel(endian,p,&pixel);
915 q->red=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
916 q->green=q->red;
917 q->blue=q->red;
918 p+=quantum_info->pad;
919 q++;
920 }
921 break;
922 }
cristyc9672a92010-01-06 00:57:45 +0000923 if (quantum_info->format == FloatingPointQuantumFormat)
924 {
925 for (x=0; x < (long) number_pixels; x++)
926 {
927 p=PushShortPixel(endian,p,&pixel);
928 q->red=RoundToQuantum((MagickRealType) QuantumRange*
929 ScaleHalfToFloat(pixel));
930 q->green=q->red;
931 q->blue=q->red;
932 p+=quantum_info->pad;
933 q++;
934 }
935 break;
936 }
cristy3ed852e2009-09-05 21:47:34 +0000937 for (x=0; x < (long) number_pixels; x++)
938 {
939 p=PushShortPixel(endian,p,&pixel);
940 q->red=ScaleShortToQuantum(pixel);
941 q->green=q->red;
942 q->blue=q->red;
943 p+=quantum_info->pad;
944 q++;
945 }
946 break;
947 }
948 case 32:
949 {
950 unsigned long
951 pixel;
952
953 if (quantum_info->format == FloatingPointQuantumFormat)
954 {
955 float
956 pixel;
957
958 for (x=0; x < (long) number_pixels; x++)
959 {
960 p=PushFloatPixel(&quantum_state,p,&pixel);
961 q->red=RoundToQuantum(pixel);
962 q->green=q->red;
963 q->blue=q->red;
964 p+=quantum_info->pad;
965 q++;
966 }
967 break;
968 }
969 for (x=0; x < (long) number_pixels; x++)
970 {
971 p=PushLongPixel(endian,p,&pixel);
972 q->red=ScaleLongToQuantum(pixel);
973 q->green=q->red;
974 q->blue=q->red;
975 p+=quantum_info->pad;
976 q++;
977 }
978 break;
979 }
980 case 64:
981 {
982 if (quantum_info->format == FloatingPointQuantumFormat)
983 {
984 double
985 pixel;
986
987 for (x=0; x < (long) number_pixels; x++)
988 {
989 p=PushDoublePixel(&quantum_state,p,&pixel);
990 q->red=RoundToQuantum(pixel);
991 q->green=q->red;
992 q->blue=q->red;
993 p+=quantum_info->pad;
994 q++;
995 }
996 break;
997 }
998 }
999 default:
1000 {
1001 range=GetQuantumRange(image->depth);
1002 for (x=0; x < (long) number_pixels; x++)
1003 {
1004 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1005 q->red=ScaleAnyToQuantum(pixel,range);
1006 q->green=q->red;
1007 q->blue=q->red;
1008 p+=quantum_info->pad;
1009 q++;
1010 }
1011 break;
1012 }
1013 }
1014 break;
1015 }
1016 case GrayAlphaQuantum:
1017 {
1018 switch (quantum_info->depth)
1019 {
1020 case 1:
1021 {
1022 register unsigned char
1023 pixel;
1024
1025 for (x=0; x < ((long) number_pixels-3); x+=4)
1026 {
1027 for (bit=0; bit < 8; bit+=2)
1028 {
1029 pixel=(unsigned char)
1030 (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1031 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1032 q->green=q->red;
1033 q->blue=q->red;
1034 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit)))
1035 == 0 ? TransparentOpacity : OpaqueOpacity);
1036 q++;
1037 }
1038 p++;
1039 }
1040 for (bit=0; bit < (long) (number_pixels % 4); bit+=2)
1041 {
1042 pixel=(unsigned char) (((*p) & (1 << (7-bit))) != 0 ? 0x00 : 0x01);
1043 q->red=(Quantum) (pixel == 0 ? 0 : QuantumRange);
1044 q->green=q->red;
1045 q->blue=q->red;
1046 q->opacity=(Quantum) (((*p) & (1UL << (unsigned char) (6-bit))) == 0
1047 ? TransparentOpacity : OpaqueOpacity);
1048 q++;
1049 }
1050 if (bit != 0)
1051 p++;
1052 break;
1053 }
1054 case 4:
1055 {
1056 register unsigned char
1057 pixel;
1058
1059 range=GetQuantumRange(image->depth);
1060 for (x=0; x < (long) number_pixels; x++)
1061 {
1062 pixel=(unsigned char) ((*p >> 4) & 0xf);
1063 q->red=ScaleAnyToQuantum(pixel,range);
1064 q->green=q->red;
1065 q->blue=q->red;
1066 pixel=(unsigned char) ((*p) & 0xf);
1067 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1068 p++;
1069 q++;
1070 }
1071 break;
1072 }
1073 case 8:
1074 {
1075 unsigned char
1076 pixel;
1077
1078 for (x=0; x < (long) number_pixels; x++)
1079 {
1080 p=PushCharPixel(p,&pixel);
1081 q->red=ScaleCharToQuantum(pixel);
1082 q->green=q->red;
1083 q->blue=q->red;
1084 p=PushCharPixel(p,&pixel);
1085 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1086 p+=quantum_info->pad;
1087 q++;
1088 }
1089 break;
1090 }
1091 case 10:
1092 {
1093 range=GetQuantumRange(image->depth);
1094 for (x=0; x < (long) number_pixels; x++)
1095 {
1096 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1097 q->red=ScaleAnyToQuantum(pixel,range);
1098 q->green=q->red;
1099 q->blue=q->red;
1100 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1101 q->opacity=ScaleAnyToQuantum(pixel,range);
1102 p+=quantum_info->pad;
1103 q++;
1104 }
1105 break;
1106 }
1107 case 12:
1108 {
1109 range=GetQuantumRange(image->depth);
1110 for (x=0; x < (long) number_pixels; x++)
1111 {
1112 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1113 q->red=ScaleAnyToQuantum(pixel,range);
1114 q->green=q->red;
1115 q->blue=q->red;
1116 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1117 q->opacity=ScaleAnyToQuantum(pixel,range);
1118 p+=quantum_info->pad;
1119 q++;
1120 }
1121 break;
1122 }
1123 case 16:
1124 {
1125 unsigned short
1126 pixel;
1127
cristyc9672a92010-01-06 00:57:45 +00001128 if (quantum_info->format == FloatingPointQuantumFormat)
1129 {
1130 for (x=0; x < (long) number_pixels; x++)
1131 {
1132 p=PushShortPixel(endian,p,&pixel);
1133 q->red=RoundToQuantum((MagickRealType) QuantumRange*
1134 ScaleHalfToFloat(pixel));
1135 q->green=q->red;
1136 q->blue=q->red;
1137 p=PushShortPixel(endian,p,&pixel);
1138 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(
1139 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)));
1140 p+=quantum_info->pad;
1141 q++;
1142 }
1143 break;
1144 }
cristy3ed852e2009-09-05 21:47:34 +00001145 for (x=0; x < (long) number_pixels; x++)
1146 {
1147 p=PushShortPixel(endian,p,&pixel);
1148 q->red=ScaleShortToQuantum(pixel);
1149 q->green=q->red;
1150 q->blue=q->red;
1151 p=PushShortPixel(endian,p,&pixel);
1152 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1153 p+=quantum_info->pad;
1154 q++;
1155 }
1156 break;
1157 }
1158 case 32:
1159 {
1160 unsigned long
1161 pixel;
1162
1163 if (quantum_info->format == FloatingPointQuantumFormat)
1164 {
1165 float
1166 pixel;
1167
1168 for (x=0; x < (long) number_pixels; x++)
1169 {
1170 p=PushFloatPixel(&quantum_state,p,&pixel);
1171 q->red=RoundToQuantum(pixel);
1172 q->green=q->red;
1173 q->blue=q->red;
1174 p=PushFloatPixel(&quantum_state,p,&pixel);
1175 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1176 p+=quantum_info->pad;
1177 q++;
1178 }
1179 break;
1180 }
1181 for (x=0; x < (long) number_pixels; x++)
1182 {
1183 p=PushLongPixel(endian,p,&pixel);
1184 q->red=ScaleLongToQuantum(pixel);
1185 q->green=q->red;
1186 q->blue=q->red;
1187 p=PushLongPixel(endian,p,&pixel);
1188 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1189 p+=quantum_info->pad;
1190 q++;
1191 }
1192 break;
1193 }
1194 case 64:
1195 {
1196 if (quantum_info->format == FloatingPointQuantumFormat)
1197 {
1198 double
1199 pixel;
1200
1201 for (x=0; x < (long) number_pixels; x++)
1202 {
1203 p=PushDoublePixel(&quantum_state,p,&pixel);
1204 q->red=RoundToQuantum(pixel);
1205 q->green=q->red;
1206 q->blue=q->red;
1207 p=PushDoublePixel(&quantum_state,p,&pixel);
1208 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1209 p+=quantum_info->pad;
1210 q++;
1211 }
1212 break;
1213 }
1214 }
1215 default:
1216 {
1217 range=GetQuantumRange(image->depth);
1218 for (x=0; x < (long) number_pixels; x++)
1219 {
1220 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1221 q->red=ScaleAnyToQuantum(pixel,range);
1222 q->green=q->red;
1223 q->blue=q->red;
1224 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1225 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1226 p+=quantum_info->pad;
1227 q++;
1228 }
1229 break;
1230 }
1231 }
1232 break;
1233 }
1234 case RedQuantum:
1235 case CyanQuantum:
1236 {
1237 switch (quantum_info->depth)
1238 {
1239 case 8:
1240 {
1241 unsigned char
1242 pixel;
1243
1244 for (x=0; x < (long) number_pixels; x++)
1245 {
1246 p=PushCharPixel(p,&pixel);
1247 q->red=ScaleCharToQuantum(pixel);
1248 p+=quantum_info->pad;
1249 q++;
1250 }
1251 break;
1252 }
1253 case 16:
1254 {
1255 unsigned short
1256 pixel;
1257
cristyc9672a92010-01-06 00:57:45 +00001258 if (quantum_info->format == FloatingPointQuantumFormat)
1259 {
1260 for (x=0; x < (long) number_pixels; x++)
1261 {
1262 p=PushShortPixel(endian,p,&pixel);
1263 q->red=RoundToQuantum((MagickRealType) QuantumRange*
1264 ScaleHalfToFloat(pixel));
1265 p+=quantum_info->pad;
1266 q++;
1267 }
1268 break;
1269 }
cristy3ed852e2009-09-05 21:47:34 +00001270 for (x=0; x < (long) number_pixels; x++)
1271 {
1272 p=PushShortPixel(endian,p,&pixel);
1273 q->red=ScaleShortToQuantum(pixel);
1274 p+=quantum_info->pad;
1275 q++;
1276 }
1277 break;
1278 }
1279 case 32:
1280 {
1281 unsigned long
1282 pixel;
1283
1284 if (quantum_info->format == FloatingPointQuantumFormat)
1285 {
1286 float
1287 pixel;
1288
1289 for (x=0; x < (long) number_pixels; x++)
1290 {
1291 p=PushFloatPixel(&quantum_state,p,&pixel);
1292 q->red=RoundToQuantum(pixel);
1293 p+=quantum_info->pad;
1294 q++;
1295 }
1296 break;
1297 }
1298 for (x=0; x < (long) number_pixels; x++)
1299 {
1300 p=PushLongPixel(endian,p,&pixel);
1301 q->red=ScaleLongToQuantum(pixel);
1302 p+=quantum_info->pad;
1303 q++;
1304 }
1305 break;
1306 }
1307 case 64:
1308 {
1309 if (quantum_info->format == FloatingPointQuantumFormat)
1310 {
1311 double
1312 pixel;
1313
1314 for (x=0; x < (long) number_pixels; x++)
1315 {
1316 p=PushDoublePixel(&quantum_state,p,&pixel);
1317 q->red=RoundToQuantum(pixel);
1318 p+=quantum_info->pad;
1319 q++;
1320 }
1321 break;
1322 }
1323 }
1324 default:
1325 {
1326 range=GetQuantumRange(image->depth);
1327 for (x=0; x < (long) number_pixels; x++)
1328 {
1329 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1330 q->red=ScaleAnyToQuantum(pixel,range);
1331 p+=quantum_info->pad;
1332 q++;
1333 }
1334 break;
1335 }
1336 }
1337 break;
1338 }
1339 case GreenQuantum:
1340 case MagentaQuantum:
1341 {
1342 switch (quantum_info->depth)
1343 {
1344 case 8:
1345 {
1346 unsigned char
1347 pixel;
1348
1349 for (x=0; x < (long) number_pixels; x++)
1350 {
1351 p=PushCharPixel(p,&pixel);
1352 q->green=ScaleCharToQuantum(pixel);
1353 p+=quantum_info->pad;
1354 q++;
1355 }
1356 break;
1357 }
1358 case 16:
1359 {
1360 unsigned short
1361 pixel;
1362
cristyc9672a92010-01-06 00:57:45 +00001363 if (quantum_info->format == FloatingPointQuantumFormat)
1364 {
1365 for (x=0; x < (long) number_pixels; x++)
1366 {
1367 p=PushShortPixel(endian,p,&pixel);
1368 q->green=RoundToQuantum((MagickRealType) QuantumRange*
1369 ScaleHalfToFloat(pixel));
1370 p+=quantum_info->pad;
1371 q++;
1372 }
1373 break;
1374 }
cristy3ed852e2009-09-05 21:47:34 +00001375 for (x=0; x < (long) number_pixels; x++)
1376 {
1377 p=PushShortPixel(endian,p,&pixel);
1378 q->green=ScaleShortToQuantum(pixel);
1379 p+=quantum_info->pad;
1380 q++;
1381 }
1382 break;
1383 }
1384 case 32:
1385 {
1386 unsigned long
1387 pixel;
1388
1389 if (quantum_info->format == FloatingPointQuantumFormat)
1390 {
1391 float
1392 pixel;
1393
1394 for (x=0; x < (long) number_pixels; x++)
1395 {
1396 p=PushFloatPixel(&quantum_state,p,&pixel);
1397 q->green=RoundToQuantum(pixel);
1398 p+=quantum_info->pad;
1399 q++;
1400 }
1401 break;
1402 }
1403 for (x=0; x < (long) number_pixels; x++)
1404 {
1405 p=PushLongPixel(endian,p,&pixel);
1406 q->green=ScaleLongToQuantum(pixel);
1407 p+=quantum_info->pad;
1408 q++;
1409 }
1410 break;
1411 }
1412 case 64:
1413 {
1414 if (quantum_info->format == FloatingPointQuantumFormat)
1415 {
1416 double
1417 pixel;
1418
1419 for (x=0; x < (long) number_pixels; x++)
1420 {
1421 p=PushDoublePixel(&quantum_state,p,&pixel);
1422 q->green=RoundToQuantum(pixel);
1423 p+=quantum_info->pad;
1424 q++;
1425 }
1426 break;
1427 }
1428 }
1429 default:
1430 {
1431 range=GetQuantumRange(image->depth);
1432 for (x=0; x < (long) number_pixels; x++)
1433 {
1434 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1435 q->green=ScaleAnyToQuantum(pixel,range);
1436 p+=quantum_info->pad;
1437 q++;
1438 }
1439 break;
1440 }
1441 }
1442 break;
1443 }
1444 case BlueQuantum:
1445 case YellowQuantum:
1446 {
1447 switch (quantum_info->depth)
1448 {
1449 case 8:
1450 {
1451 unsigned char
1452 pixel;
1453
1454 for (x=0; x < (long) number_pixels; x++)
1455 {
1456 p=PushCharPixel(p,&pixel);
1457 q->blue=ScaleCharToQuantum(pixel);
1458 p+=quantum_info->pad;
1459 q++;
1460 }
1461 break;
1462 }
1463 case 16:
1464 {
1465 unsigned short
1466 pixel;
1467
cristyc9672a92010-01-06 00:57:45 +00001468 if (quantum_info->format == FloatingPointQuantumFormat)
1469 {
1470 for (x=0; x < (long) number_pixels; x++)
1471 {
1472 p=PushShortPixel(endian,p,&pixel);
1473 q->blue=RoundToQuantum((MagickRealType) QuantumRange*
1474 ScaleHalfToFloat(pixel));
1475 p+=quantum_info->pad;
1476 q++;
1477 }
1478 break;
1479 }
cristy3ed852e2009-09-05 21:47:34 +00001480 for (x=0; x < (long) number_pixels; x++)
1481 {
1482 p=PushShortPixel(endian,p,&pixel);
1483 q->blue=ScaleShortToQuantum(pixel);
1484 p+=quantum_info->pad;
1485 q++;
1486 }
1487 break;
1488 }
1489 case 32:
1490 {
1491 unsigned long
1492 pixel;
1493
1494 if (quantum_info->format == FloatingPointQuantumFormat)
1495 {
1496 float
1497 pixel;
1498
1499 for (x=0; x < (long) number_pixels; x++)
1500 {
1501 p=PushFloatPixel(&quantum_state,p,&pixel);
1502 q->blue=RoundToQuantum(pixel);
1503 p+=quantum_info->pad;
1504 q++;
1505 }
1506 break;
1507 }
1508 for (x=0; x < (long) number_pixels; x++)
1509 {
1510 p=PushLongPixel(endian,p,&pixel);
1511 q->blue=ScaleLongToQuantum(pixel);
1512 p+=quantum_info->pad;
1513 q++;
1514 }
1515 break;
1516 }
1517 case 64:
1518 {
1519 if (quantum_info->format == FloatingPointQuantumFormat)
1520 {
1521 double
1522 pixel;
1523
1524 for (x=0; x < (long) number_pixels; x++)
1525 {
1526 p=PushDoublePixel(&quantum_state,p,&pixel);
1527 q->blue=RoundToQuantum(pixel);
1528 p+=quantum_info->pad;
1529 q++;
1530 }
1531 break;
1532 }
1533 }
1534 default:
1535 {
1536 range=GetQuantumRange(image->depth);
1537 for (x=0; x < (long) number_pixels; x++)
1538 {
1539 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1540 q->blue=ScaleAnyToQuantum(pixel,range);
1541 p+=quantum_info->pad;
1542 q++;
1543 }
1544 break;
1545 }
1546 }
1547 break;
1548 }
1549 case AlphaQuantum:
1550 {
1551 switch (quantum_info->depth)
1552 {
1553 case 8:
1554 {
1555 unsigned char
1556 pixel;
1557
1558 for (x=0; x < (long) number_pixels; x++)
1559 {
1560 p=PushCharPixel(p,&pixel);
1561 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
1562 p+=quantum_info->pad;
1563 q++;
1564 }
1565 break;
1566 }
1567 case 16:
1568 {
1569 unsigned short
1570 pixel;
1571
cristyc9672a92010-01-06 00:57:45 +00001572 if (quantum_info->format == FloatingPointQuantumFormat)
1573 {
1574 for (x=0; x < (long) number_pixels; x++)
1575 {
1576 p=PushShortPixel(endian,p,&pixel);
1577 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(
1578 (MagickRealType) QuantumRange*
1579 ScaleHalfToFloat(pixel)));
1580 p+=quantum_info->pad;
1581 q++;
1582 }
1583 break;
1584 }
cristy3ed852e2009-09-05 21:47:34 +00001585 for (x=0; x < (long) number_pixels; x++)
1586 {
1587 p=PushShortPixel(endian,p,&pixel);
1588 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
1589 p+=quantum_info->pad;
1590 q++;
1591 }
1592 break;
1593 }
1594 case 32:
1595 {
1596 unsigned long
1597 pixel;
1598
1599 if (quantum_info->format == FloatingPointQuantumFormat)
1600 {
1601 float
1602 pixel;
1603
1604 for (x=0; x < (long) number_pixels; x++)
1605 {
1606 p=PushFloatPixel(&quantum_state,p,&pixel);
1607 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1608 p+=quantum_info->pad;
1609 q++;
1610 }
1611 break;
1612 }
1613 for (x=0; x < (long) number_pixels; x++)
1614 {
1615 p=PushLongPixel(endian,p,&pixel);
1616 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
1617 p+=quantum_info->pad;
1618 q++;
1619 }
1620 break;
1621 }
1622 case 64:
1623 {
1624 if (quantum_info->format == FloatingPointQuantumFormat)
1625 {
1626 double
1627 pixel;
1628
1629 for (x=0; x < (long) number_pixels; x++)
1630 {
1631 p=PushDoublePixel(&quantum_state,p,&pixel);
1632 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
1633 p+=quantum_info->pad;
1634 q++;
1635 }
1636 break;
1637 }
1638 }
1639 default:
1640 {
1641 range=GetQuantumRange(image->depth);
1642 for (x=0; x < (long) number_pixels; x++)
1643 {
1644 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1645 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
1646 p+=quantum_info->pad;
1647 q++;
1648 }
1649 break;
1650 }
1651 }
1652 break;
1653 }
1654 case BlackQuantum:
1655 {
1656 if (image->colorspace != CMYKColorspace)
1657 {
1658 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
1659 "ColorSeparatedImageRequired","`%s'",image->filename);
1660 return(extent);
1661 }
1662 switch (quantum_info->depth)
1663 {
1664 case 8:
1665 {
1666 unsigned char
1667 pixel;
1668
1669 for (x=0; x < (long) number_pixels; x++)
1670 {
1671 p=PushCharPixel(p,&pixel);
1672 indexes[x]=ScaleCharToQuantum(pixel);
1673 p+=quantum_info->pad;
1674 }
1675 break;
1676 }
1677 case 16:
1678 {
1679 unsigned short
1680 pixel;
1681
cristyc9672a92010-01-06 00:57:45 +00001682 if (quantum_info->format == FloatingPointQuantumFormat)
1683 {
1684 for (x=0; x < (long) number_pixels; x++)
1685 {
1686 p=PushShortPixel(endian,p,&pixel);
1687 indexes[x]=RoundToQuantum((MagickRealType) QuantumRange*
1688 ScaleHalfToFloat(pixel));
1689 p+=quantum_info->pad;
1690 }
1691 break;
1692 }
cristy3ed852e2009-09-05 21:47:34 +00001693 for (x=0; x < (long) number_pixels; x++)
1694 {
1695 p=PushShortPixel(endian,p,&pixel);
1696 indexes[x]=ScaleShortToQuantum(pixel);
1697 p+=quantum_info->pad;
1698 }
1699 break;
1700 }
1701 case 32:
1702 {
1703 unsigned long
1704 pixel;
1705
1706 if (quantum_info->format == FloatingPointQuantumFormat)
1707 {
1708 float
1709 pixel;
1710
1711 for (x=0; x < (long) number_pixels; x++)
1712 {
1713 p=PushFloatPixel(&quantum_state,p,&pixel);
1714 indexes[x]=RoundToQuantum(pixel);
1715 p+=quantum_info->pad;
1716 q++;
1717 }
1718 break;
1719 }
1720 for (x=0; x < (long) number_pixels; x++)
1721 {
1722 p=PushLongPixel(endian,p,&pixel);
1723 indexes[x]=ScaleLongToQuantum(pixel);
1724 p+=quantum_info->pad;
1725 q++;
1726 }
1727 break;
1728 }
1729 case 64:
1730 {
1731 if (quantum_info->format == FloatingPointQuantumFormat)
1732 {
1733 double
1734 pixel;
1735
1736 for (x=0; x < (long) number_pixels; x++)
1737 {
1738 p=PushDoublePixel(&quantum_state,p,&pixel);
1739 indexes[x]=RoundToQuantum(pixel);
1740 p+=quantum_info->pad;
1741 q++;
1742 }
1743 break;
1744 }
1745 }
1746 default:
1747 {
1748 range=GetQuantumRange(image->depth);
1749 for (x=0; x < (long) number_pixels; x++)
1750 {
1751 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1752 indexes[x]=ScaleAnyToQuantum(pixel,range);
1753 p+=quantum_info->pad;
1754 q++;
1755 }
1756 break;
1757 }
1758 }
1759 break;
1760 }
1761 case RGBQuantum:
1762 case CbYCrQuantum:
1763 {
1764 switch (quantum_info->depth)
1765 {
1766 case 8:
1767 {
1768 unsigned char
1769 pixel;
1770
1771 for (x=0; x < (long) number_pixels; x++)
1772 {
1773 p=PushCharPixel(p,&pixel);
1774 q->red=ScaleCharToQuantum(pixel);
1775 p=PushCharPixel(p,&pixel);
1776 q->green=ScaleCharToQuantum(pixel);
1777 p=PushCharPixel(p,&pixel);
1778 q->blue=ScaleCharToQuantum(pixel);
1779 q->opacity=OpaqueOpacity;
1780 p+=quantum_info->pad;
1781 q++;
1782 }
1783 break;
1784 }
1785 case 10:
1786 {
1787 range=GetQuantumRange(image->depth);
1788 if (quantum_info->pack == MagickFalse)
1789 {
1790 for (x=0; x < (long) number_pixels; x++)
1791 {
1792 p=PushLongPixel(endian,p,&pixel);
1793 q->red=ScaleAnyToQuantum((pixel >> 22) & 0x3ff,range);
1794 q->green=ScaleAnyToQuantum((pixel >> 12) & 0x3ff,range);
1795 q->blue=ScaleAnyToQuantum((pixel >> 2) & 0x3ff,range);
1796 p+=quantum_info->pad;
1797 q++;
1798 }
1799 break;
1800 }
1801 if (quantum_info->quantum == 32UL)
1802 {
1803 for (x=0; x < (long) number_pixels; x++)
1804 {
1805 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1806 q->red=ScaleAnyToQuantum(pixel,range);
1807 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1808 q->green=ScaleAnyToQuantum(pixel,range);
1809 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1810 q->blue=ScaleAnyToQuantum(pixel,range);
1811 q++;
1812 }
1813 break;
1814 }
1815 for (x=0; x < (long) number_pixels; x++)
1816 {
1817 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1818 q->red=ScaleAnyToQuantum(pixel,range);
1819 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1820 q->green=ScaleAnyToQuantum(pixel,range);
1821 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1822 q->blue=ScaleAnyToQuantum(pixel,range);
1823 q++;
1824 }
1825 break;
1826 }
1827 case 12:
1828 {
1829 range=GetQuantumRange(image->depth);
1830 if (quantum_info->pack == MagickFalse)
1831 {
1832 unsigned short
1833 pixel;
1834
1835 for (x=0; x < (long) (3*number_pixels-1); x+=2)
1836 {
1837 p=PushShortPixel(endian,p,&pixel);
1838 switch (x % 3)
1839 {
1840 default:
1841 case 0:
1842 {
1843 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1844 break;
1845 }
1846 case 1:
1847 {
1848 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1849 break;
1850 }
1851 case 2:
1852 {
1853 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1854 q++;
1855 break;
1856 }
1857 }
1858 p=PushShortPixel(endian,p,&pixel);
1859 switch ((x+1) % 3)
1860 {
1861 default:
1862 case 0:
1863 {
1864 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1865 break;
1866 }
1867 case 1:
1868 {
1869 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1870 break;
1871 }
1872 case 2:
1873 {
1874 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1875 q++;
1876 break;
1877 }
1878 }
1879 p+=quantum_info->pad;
1880 }
1881 for (bit=0; bit < (long) (3*number_pixels % 2); bit++)
1882 {
1883 p=PushShortPixel(endian,p,&pixel);
1884 switch ((x+bit) % 3)
1885 {
1886 default:
1887 case 0:
1888 {
1889 q->red=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1890 break;
1891 }
1892 case 1:
1893 {
1894 q->green=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1895 break;
1896 }
1897 case 2:
1898 {
1899 q->blue=ScaleAnyToQuantum((QuantumAny) (pixel >> 4),range);
1900 q++;
1901 break;
1902 }
1903 }
1904 p+=quantum_info->pad;
1905 }
1906 if (bit != 0)
1907 p++;
1908 break;
1909 }
1910 if (quantum_info->quantum == 32UL)
1911 {
1912 for (x=0; x < (long) number_pixels; x++)
1913 {
1914 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1915 q->red=ScaleAnyToQuantum(pixel,range);
1916 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1917 q->green=ScaleAnyToQuantum(pixel,range);
1918 p=PushQuantumLongPixel(&quantum_state,image->depth,p,&pixel);
1919 q->blue=ScaleAnyToQuantum(pixel,range);
1920 q++;
1921 }
1922 break;
1923 }
1924 for (x=0; x < (long) number_pixels; x++)
1925 {
1926 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1927 q->red=ScaleAnyToQuantum(pixel,range);
1928 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1929 q->green=ScaleAnyToQuantum(pixel,range);
1930 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
1931 q->blue=ScaleAnyToQuantum(pixel,range);
1932 q++;
1933 }
1934 break;
1935 }
1936 case 16:
1937 {
1938 unsigned short
1939 pixel;
1940
cristyc9672a92010-01-06 00:57:45 +00001941 if (quantum_info->format == FloatingPointQuantumFormat)
1942 {
1943 for (x=0; x < (long) number_pixels; x++)
1944 {
1945 p=PushShortPixel(endian,p,&pixel);
1946 q->red=RoundToQuantum((MagickRealType) QuantumRange*
1947 ScaleHalfToFloat(pixel));
1948 p=PushShortPixel(endian,p,&pixel);
1949 q->green=RoundToQuantum((MagickRealType) QuantumRange*
1950 ScaleHalfToFloat(pixel));
1951 p=PushShortPixel(endian,p,&pixel);
1952 q->blue=RoundToQuantum((MagickRealType) QuantumRange*
1953 ScaleHalfToFloat(pixel));
1954 p+=quantum_info->pad;
1955 q++;
1956 }
1957 break;
1958 }
cristy3ed852e2009-09-05 21:47:34 +00001959 for (x=0; x < (long) number_pixels; x++)
1960 {
1961 p=PushShortPixel(endian,p,&pixel);
1962 q->red=ScaleShortToQuantum(pixel);
1963 p=PushShortPixel(endian,p,&pixel);
1964 q->green=ScaleShortToQuantum(pixel);
1965 p=PushShortPixel(endian,p,&pixel);
1966 q->blue=ScaleShortToQuantum(pixel);
1967 p+=quantum_info->pad;
1968 q++;
1969 }
1970 break;
1971 }
1972 case 32:
1973 {
1974 unsigned long
1975 pixel;
1976
1977 if (quantum_info->format == FloatingPointQuantumFormat)
1978 {
1979 float
1980 pixel;
1981
1982 for (x=0; x < (long) number_pixels; x++)
1983 {
1984 p=PushFloatPixel(&quantum_state,p,&pixel);
1985 q->red=RoundToQuantum(pixel);
1986 p=PushFloatPixel(&quantum_state,p,&pixel);
1987 q->green=RoundToQuantum(pixel);
1988 p=PushFloatPixel(&quantum_state,p,&pixel);
1989 q->blue=RoundToQuantum(pixel);
1990 p+=quantum_info->pad;
1991 q++;
1992 }
1993 break;
1994 }
1995 for (x=0; x < (long) number_pixels; x++)
1996 {
1997 p=PushLongPixel(endian,p,&pixel);
1998 q->red=ScaleLongToQuantum(pixel);
1999 p=PushLongPixel(endian,p,&pixel);
2000 q->green=ScaleLongToQuantum(pixel);
2001 p=PushLongPixel(endian,p,&pixel);
2002 q->blue=ScaleLongToQuantum(pixel);
2003 p+=quantum_info->pad;
2004 q++;
2005 }
2006 break;
2007 }
2008 case 64:
2009 {
2010 if (quantum_info->format == FloatingPointQuantumFormat)
2011 {
2012 double
2013 pixel;
2014
2015 for (x=0; x < (long) number_pixels; x++)
2016 {
2017 p=PushDoublePixel(&quantum_state,p,&pixel);
2018 q->red=RoundToQuantum(pixel);
2019 p=PushDoublePixel(&quantum_state,p,&pixel);
2020 q->green=RoundToQuantum(pixel);
2021 p=PushDoublePixel(&quantum_state,p,&pixel);
2022 q->blue=RoundToQuantum(pixel);
2023 p+=quantum_info->pad;
2024 q++;
2025 }
2026 break;
2027 }
2028 }
2029 default:
2030 {
2031 range=GetQuantumRange(image->depth);
2032 for (x=0; x < (long) number_pixels; x++)
2033 {
2034 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2035 q->red=ScaleAnyToQuantum(pixel,range);
2036 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2037 q->green=ScaleAnyToQuantum(pixel,range);
2038 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2039 q->blue=ScaleAnyToQuantum(pixel,range);
2040 q++;
2041 }
2042 break;
2043 }
2044 }
2045 break;
2046 }
2047 case RGBAQuantum:
2048 case RGBOQuantum:
2049 case CbYCrAQuantum:
2050 {
2051 switch (quantum_info->depth)
2052 {
2053 case 8:
2054 {
2055 unsigned char
2056 pixel;
2057
2058 for (x=0; x < (long) number_pixels; x++)
2059 {
2060 p=PushCharPixel(p,&pixel);
2061 q->red=ScaleCharToQuantum(pixel);
2062 p=PushCharPixel(p,&pixel);
2063 q->green=ScaleCharToQuantum(pixel);
2064 p=PushCharPixel(p,&pixel);
2065 q->blue=ScaleCharToQuantum(pixel);
2066 p=PushCharPixel(p,&pixel);
2067 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2068 p+=quantum_info->pad;
2069 q++;
2070 }
2071 break;
2072 }
2073 case 10:
2074 {
2075 pixel=0;
2076 if (quantum_info->pack == MagickFalse)
2077 {
2078 long
2079 n;
2080
2081 register long
2082 i;
2083
2084 unsigned long
2085 quantum;
2086
2087 n=0;
2088 quantum=0;
2089 for (x=0; x < (long) number_pixels; x++)
2090 {
2091 for (i=0; i < 4; i++)
2092 {
2093 switch (n % 3)
2094 {
2095 case 0:
2096 {
2097 p=PushLongPixel(endian,p,&pixel);
2098 quantum=(unsigned long) (ScaleShortToQuantum(
2099 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2100 break;
2101 }
2102 case 1:
2103 {
2104 quantum=(unsigned long) (ScaleShortToQuantum(
2105 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2106 break;
2107 }
2108 case 2:
2109 {
2110 quantum=(unsigned long) (ScaleShortToQuantum(
2111 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2112 break;
2113 }
2114 }
2115 switch (i)
2116 {
2117 case 0: q->red=(Quantum) (quantum); break;
2118 case 1: q->green=(Quantum) (quantum); break;
2119 case 2: q->blue=(Quantum) (quantum); break;
2120 case 3: q->opacity=(Quantum) (QuantumRange-quantum); break;
2121 }
2122 n++;
2123 }
2124 p+=quantum_info->pad;
2125 q++;
2126 }
2127 break;
2128 }
2129 for (x=0; x < (long) number_pixels; x++)
2130 {
2131 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2132 q->red=ScaleShortToQuantum((unsigned short) (pixel << 6));
2133 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2134 q->green=ScaleShortToQuantum((unsigned short) (pixel << 6));
2135 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2136 q->blue=ScaleShortToQuantum((unsigned short) (pixel << 6));
2137 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2138 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(
2139 (unsigned short) (pixel << 6)));
2140 q++;
2141 }
2142 break;
2143 }
2144 case 16:
2145 {
2146 unsigned short
2147 pixel;
2148
cristyc9672a92010-01-06 00:57:45 +00002149 if (quantum_info->format == FloatingPointQuantumFormat)
2150 {
2151 for (x=0; x < (long) number_pixels; x++)
2152 {
2153 p=PushShortPixel(endian,p,&pixel);
2154 q->red=RoundToQuantum((MagickRealType) QuantumRange*
2155 ScaleHalfToFloat(pixel));
2156 p=PushShortPixel(endian,p,&pixel);
2157 q->green=RoundToQuantum((MagickRealType) QuantumRange*
2158 ScaleHalfToFloat(pixel));
2159 p=PushShortPixel(endian,p,&pixel);
2160 q->blue=RoundToQuantum((MagickRealType) QuantumRange*
2161 ScaleHalfToFloat(pixel));
2162 p=PushShortPixel(endian,p,&pixel);
2163 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(
2164 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)));
2165 p+=quantum_info->pad;
2166 q++;
2167 }
2168 break;
2169 }
cristy3ed852e2009-09-05 21:47:34 +00002170 for (x=0; x < (long) number_pixels; x++)
2171 {
2172 p=PushShortPixel(endian,p,&pixel);
2173 q->red=ScaleShortToQuantum(pixel);
2174 p=PushShortPixel(endian,p,&pixel);
2175 q->green=ScaleShortToQuantum(pixel);
2176 p=PushShortPixel(endian,p,&pixel);
2177 q->blue=ScaleShortToQuantum(pixel);
2178 p=PushShortPixel(endian,p,&pixel);
2179 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2180 p+=quantum_info->pad;
2181 q++;
2182 }
2183 break;
2184 }
2185 case 32:
2186 {
2187 unsigned long
2188 pixel;
2189
2190 if (quantum_info->format == FloatingPointQuantumFormat)
2191 {
2192 float
2193 pixel;
2194
2195 for (x=0; x < (long) number_pixels; x++)
2196 {
2197 p=PushFloatPixel(&quantum_state,p,&pixel);
2198 q->red=RoundToQuantum(pixel);
2199 p=PushFloatPixel(&quantum_state,p,&pixel);
2200 q->green=RoundToQuantum(pixel);
2201 p=PushFloatPixel(&quantum_state,p,&pixel);
2202 q->blue=RoundToQuantum(pixel);
2203 p=PushFloatPixel(&quantum_state,p,&pixel);
2204 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2205 p+=quantum_info->pad;
2206 q++;
2207 }
2208 break;
2209 }
2210 for (x=0; x < (long) number_pixels; x++)
2211 {
2212 p=PushLongPixel(endian,p,&pixel);
2213 q->red=ScaleLongToQuantum(pixel);
2214 p=PushLongPixel(endian,p,&pixel);
2215 q->green=ScaleLongToQuantum(pixel);
2216 p=PushLongPixel(endian,p,&pixel);
2217 q->blue=ScaleLongToQuantum(pixel);
2218 p=PushLongPixel(endian,p,&pixel);
2219 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2220 p+=quantum_info->pad;
2221 q++;
2222 }
2223 break;
2224 }
2225 case 64:
2226 {
2227 if (quantum_info->format == FloatingPointQuantumFormat)
2228 {
2229 double
2230 pixel;
2231
2232 for (x=0; x < (long) number_pixels; x++)
2233 {
2234 p=PushDoublePixel(&quantum_state,p,&pixel);
2235 q->red=RoundToQuantum(pixel);
2236 p=PushDoublePixel(&quantum_state,p,&pixel);
2237 q->green=RoundToQuantum(pixel);
2238 p=PushDoublePixel(&quantum_state,p,&pixel);
2239 q->blue=RoundToQuantum(pixel);
2240 p=PushDoublePixel(&quantum_state,p,&pixel);
2241 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2242 p+=quantum_info->pad;
2243 q++;
2244 }
2245 break;
2246 }
2247 }
2248 default:
2249 {
2250 range=GetQuantumRange(image->depth);
2251 for (x=0; x < (long) number_pixels; x++)
2252 {
2253 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2254 q->red=ScaleAnyToQuantum(pixel,range);
2255 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2256 q->green=ScaleAnyToQuantum(pixel,range);
2257 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2258 q->blue=ScaleAnyToQuantum(pixel,range);
2259 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2260 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2261 q++;
2262 }
2263 break;
2264 }
2265 }
2266 break;
2267 }
2268 case CMYKQuantum:
2269 {
2270 if (image->colorspace != CMYKColorspace)
2271 {
2272 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2273 "ColorSeparatedImageRequired","`%s'",image->filename);
2274 return(extent);
2275 }
2276 switch (quantum_info->depth)
2277 {
2278 case 8:
2279 {
2280 unsigned char
2281 pixel;
2282
2283 for (x=0; x < (long) number_pixels; x++)
2284 {
2285 p=PushCharPixel(p,&pixel);
2286 q->red=ScaleCharToQuantum(pixel);
2287 p=PushCharPixel(p,&pixel);
2288 q->green=ScaleCharToQuantum(pixel);
2289 p=PushCharPixel(p,&pixel);
2290 q->blue=ScaleCharToQuantum(pixel);
2291 p=PushCharPixel(p,&pixel);
2292 indexes[x]=ScaleCharToQuantum(pixel);
2293 p+=quantum_info->pad;
2294 q++;
2295 }
2296 break;
2297 }
2298 case 16:
2299 {
2300 unsigned short
2301 pixel;
2302
cristyc9672a92010-01-06 00:57:45 +00002303 if (quantum_info->format == FloatingPointQuantumFormat)
2304 {
2305 for (x=0; x < (long) number_pixels; x++)
2306 {
2307 p=PushShortPixel(endian,p,&pixel);
2308 q->red=RoundToQuantum((MagickRealType) QuantumRange*
2309 ScaleHalfToFloat(pixel));
2310 p=PushShortPixel(endian,p,&pixel);
2311 q->green=RoundToQuantum((MagickRealType) QuantumRange*
2312 ScaleHalfToFloat(pixel));
2313 p=PushShortPixel(endian,p,&pixel);
2314 q->blue=RoundToQuantum((MagickRealType) QuantumRange*
2315 ScaleHalfToFloat(pixel));
2316 p=PushShortPixel(endian,p,&pixel);
2317 indexes[x]=RoundToQuantum((MagickRealType) QuantumRange*
2318 ScaleHalfToFloat(pixel));
2319 p+=quantum_info->pad;
2320 q++;
2321 }
2322 break;
2323 }
cristy3ed852e2009-09-05 21:47:34 +00002324 for (x=0; x < (long) number_pixels; x++)
2325 {
2326 p=PushShortPixel(endian,p,&pixel);
2327 q->red=ScaleShortToQuantum(pixel);
2328 p=PushShortPixel(endian,p,&pixel);
2329 q->green=ScaleShortToQuantum(pixel);
2330 p=PushShortPixel(endian,p,&pixel);
2331 q->blue=ScaleShortToQuantum(pixel);
2332 p=PushShortPixel(endian,p,&pixel);
2333 indexes[x]=ScaleShortToQuantum(pixel);
2334 p+=quantum_info->pad;
2335 q++;
2336 }
2337 break;
2338 }
2339 case 32:
2340 {
2341 unsigned long
2342 pixel;
2343
2344 if (quantum_info->format == FloatingPointQuantumFormat)
2345 {
2346 float
2347 pixel;
2348
2349 for (x=0; x < (long) number_pixels; x++)
2350 {
2351 p=PushFloatPixel(&quantum_state,p,&pixel);
2352 q->red=RoundToQuantum(pixel);
2353 p=PushFloatPixel(&quantum_state,p,&pixel);
2354 q->green=RoundToQuantum(pixel);
2355 p=PushFloatPixel(&quantum_state,p,&pixel);
2356 q->blue=RoundToQuantum(pixel);
2357 p=PushFloatPixel(&quantum_state,p,&pixel);
2358 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2359 p+=quantum_info->pad;
2360 q++;
2361 }
2362 break;
2363 }
2364 for (x=0; x < (long) number_pixels; x++)
2365 {
2366 p=PushLongPixel(endian,p,&pixel);
2367 q->red=ScaleLongToQuantum(pixel);
2368 p=PushLongPixel(endian,p,&pixel);
2369 q->green=ScaleLongToQuantum(pixel);
2370 p=PushLongPixel(endian,p,&pixel);
2371 q->blue=ScaleLongToQuantum(pixel);
2372 p=PushLongPixel(endian,p,&pixel);
2373 indexes[x]=ScaleLongToQuantum(pixel);
2374 p+=quantum_info->pad;
2375 q++;
2376 }
2377 break;
2378 }
2379 case 64:
2380 {
2381 if (quantum_info->format == FloatingPointQuantumFormat)
2382 {
2383 double
2384 pixel;
2385
2386 for (x=0; x < (long) number_pixels; x++)
2387 {
2388 p=PushDoublePixel(&quantum_state,p,&pixel);
2389 q->red=RoundToQuantum(pixel);
2390 p=PushDoublePixel(&quantum_state,p,&pixel);
2391 q->green=RoundToQuantum(pixel);
2392 p=PushDoublePixel(&quantum_state,p,&pixel);
2393 q->blue=RoundToQuantum(pixel);
2394 p=PushDoublePixel(&quantum_state,p,&pixel);
2395 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2396 p+=quantum_info->pad;
2397 q++;
2398 }
2399 break;
2400 }
2401 }
2402 default:
2403 {
2404 range=GetQuantumRange(image->depth);
2405 for (x=0; x < (long) number_pixels; x++)
2406 {
2407 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2408 q->red=ScaleAnyToQuantum(pixel,range);
2409 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2410 q->green=ScaleAnyToQuantum(pixel,range);
2411 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2412 q->blue=ScaleAnyToQuantum(pixel,range);
2413 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2414 indexes[x]=ScaleAnyToQuantum(pixel,range);
2415 q++;
2416 }
2417 break;
2418 }
2419 }
2420 break;
2421 }
2422 case CMYKAQuantum:
2423 case CMYKOQuantum:
2424 {
2425 if (image->colorspace != CMYKColorspace)
2426 {
2427 (void) ThrowMagickException(exception,GetMagickModule(),ImageError,
2428 "ColorSeparatedImageRequired","`%s'",image->filename);
2429 return(extent);
2430 }
2431 switch (quantum_info->depth)
2432 {
2433 case 8:
2434 {
2435 unsigned char
2436 pixel;
2437
2438 for (x=0; x < (long) number_pixels; x++)
2439 {
2440 p=PushCharPixel(p,&pixel);
2441 q->red=ScaleCharToQuantum(pixel);
2442 p=PushCharPixel(p,&pixel);
2443 q->green=ScaleCharToQuantum(pixel);
2444 p=PushCharPixel(p,&pixel);
2445 q->blue=ScaleCharToQuantum(pixel);
2446 p=PushCharPixel(p,&pixel);
2447 indexes[x]=ScaleCharToQuantum(pixel);
2448 p=PushCharPixel(p,&pixel);
2449 q->opacity=(Quantum) (QuantumRange-ScaleCharToQuantum(pixel));
2450 p+=quantum_info->pad;
2451 q++;
2452 }
2453 break;
2454 }
2455 case 16:
2456 {
2457 unsigned short
2458 pixel;
2459
cristyc9672a92010-01-06 00:57:45 +00002460 if (quantum_info->format == FloatingPointQuantumFormat)
2461 {
2462 for (x=0; x < (long) number_pixels; x++)
2463 {
2464 p=PushShortPixel(endian,p,&pixel);
2465 q->red=RoundToQuantum((MagickRealType) QuantumRange*
2466 ScaleHalfToFloat(pixel));
2467 p=PushShortPixel(endian,p,&pixel);
2468 q->green=RoundToQuantum((MagickRealType) QuantumRange*
2469 ScaleHalfToFloat(pixel));
2470 p=PushShortPixel(endian,p,&pixel);
2471 q->blue=RoundToQuantum((MagickRealType) QuantumRange*
2472 ScaleHalfToFloat(pixel));
2473 p=PushShortPixel(endian,p,&pixel);
2474 indexes[x]=RoundToQuantum((MagickRealType) QuantumRange*
2475 ScaleHalfToFloat(pixel));
2476 p=PushShortPixel(endian,p,&pixel);
2477 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(
2478 (MagickRealType) QuantumRange*ScaleHalfToFloat(pixel)));
2479 p+=quantum_info->pad;
2480 q++;
2481 }
2482 break;
2483 }
cristy3ed852e2009-09-05 21:47:34 +00002484 for (x=0; x < (long) number_pixels; x++)
2485 {
2486 p=PushShortPixel(endian,p,&pixel);
2487 q->red=ScaleShortToQuantum(pixel);
2488 p=PushShortPixel(endian,p,&pixel);
2489 q->green=ScaleShortToQuantum(pixel);
2490 p=PushShortPixel(endian,p,&pixel);
2491 q->blue=ScaleShortToQuantum(pixel);
2492 p=PushShortPixel(endian,p,&pixel);
2493 indexes[x]=ScaleShortToQuantum(pixel);
2494 p=PushShortPixel(endian,p,&pixel);
2495 q->opacity=(Quantum) (QuantumRange-ScaleShortToQuantum(pixel));
2496 p+=quantum_info->pad;
2497 q++;
2498 }
2499 break;
2500 }
2501 case 32:
2502 {
2503 unsigned long
2504 pixel;
2505
2506 if (quantum_info->format == FloatingPointQuantumFormat)
2507 {
2508 float
2509 pixel;
2510
2511 for (x=0; x < (long) number_pixels; x++)
2512 {
2513 p=PushFloatPixel(&quantum_state,p,&pixel);
2514 q->red=RoundToQuantum(pixel);
2515 p=PushFloatPixel(&quantum_state,p,&pixel);
2516 q->green=RoundToQuantum(pixel);
2517 p=PushFloatPixel(&quantum_state,p,&pixel);
2518 q->blue=RoundToQuantum(pixel);
2519 p=PushFloatPixel(&quantum_state,p,&pixel);
2520 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2521 p=PushFloatPixel(&quantum_state,p,&pixel);
2522 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2523 p+=quantum_info->pad;
2524 q++;
2525 }
2526 break;
2527 }
2528 for (x=0; x < (long) number_pixels; x++)
2529 {
2530 p=PushLongPixel(endian,p,&pixel);
2531 q->red=ScaleLongToQuantum(pixel);
2532 p=PushLongPixel(endian,p,&pixel);
2533 q->green=ScaleLongToQuantum(pixel);
2534 p=PushLongPixel(endian,p,&pixel);
2535 q->blue=ScaleLongToQuantum(pixel);
2536 p=PushLongPixel(endian,p,&pixel);
2537 indexes[x]=ScaleLongToQuantum(pixel);
2538 p=PushLongPixel(endian,p,&pixel);
2539 q->opacity=(Quantum) (QuantumRange-ScaleLongToQuantum(pixel));
2540 p+=quantum_info->pad;
2541 q++;
2542 }
2543 break;
2544 }
2545 case 64:
2546 {
2547 if (quantum_info->format == FloatingPointQuantumFormat)
2548 {
2549 double
2550 pixel;
2551
2552 for (x=0; x < (long) number_pixels; x++)
2553 {
2554 p=PushDoublePixel(&quantum_state,p,&pixel);
2555 q->red=RoundToQuantum(pixel);
2556 p=PushDoublePixel(&quantum_state,p,&pixel);
2557 q->green=RoundToQuantum(pixel);
2558 p=PushDoublePixel(&quantum_state,p,&pixel);
2559 q->blue=RoundToQuantum(pixel);
2560 p=PushDoublePixel(&quantum_state,p,&pixel);
2561 indexes[x]=(IndexPacket) RoundToQuantum(pixel);
2562 p=PushDoublePixel(&quantum_state,p,&pixel);
2563 q->opacity=(Quantum) (QuantumRange-RoundToQuantum(pixel));
2564 p=PushDoublePixel(&quantum_state,p,&pixel);
2565 p+=quantum_info->pad;
2566 q++;
2567 }
2568 break;
2569 }
2570 }
2571 default:
2572 {
2573 range=GetQuantumRange(image->depth);
2574 for (x=0; x < (long) number_pixels; x++)
2575 {
2576 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2577 q->red=ScaleAnyToQuantum(pixel,range);
2578 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2579 q->green=ScaleAnyToQuantum(pixel,range);
2580 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2581 q->blue=ScaleAnyToQuantum(pixel,range);
2582 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2583 indexes[x]=ScaleAnyToQuantum(pixel,range);
2584 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2585 q->opacity=(Quantum) (QuantumRange-ScaleAnyToQuantum(pixel,range));
2586 q++;
2587 }
2588 break;
2589 }
2590 }
2591 break;
2592 }
2593 case CbYCrYQuantum:
2594 {
2595 switch (quantum_info->depth)
2596 {
2597 case 10:
2598 {
2599 Quantum
2600 cbcr[4];
2601
2602 pixel=0;
2603 if (quantum_info->pack == MagickFalse)
2604 {
2605 long
2606 n;
2607
2608 register long
2609 i;
2610
2611 unsigned long
2612 quantum;
2613
2614 n=0;
2615 quantum=0;
2616 for (x=0; x < (long) number_pixels; x+=2)
2617 {
2618 for (i=0; i < 4; i++)
2619 {
2620 switch (n % 3)
2621 {
2622 case 0:
2623 {
2624 p=PushLongPixel(endian,p,&pixel);
2625 quantum=(unsigned long) (ScaleShortToQuantum(
2626 (unsigned short) (((pixel >> 22) & 0x3ff) << 6)));
2627 break;
2628 }
2629 case 1:
2630 {
2631 quantum=(unsigned long) (ScaleShortToQuantum(
2632 (unsigned short) (((pixel >> 12) & 0x3ff) << 6)));
2633 break;
2634 }
2635 case 2:
2636 {
2637 quantum=(unsigned long) (ScaleShortToQuantum(
2638 (unsigned short) (((pixel >> 2) & 0x3ff) << 6)));
2639 break;
2640 }
2641 }
2642 cbcr[i]=(Quantum) (quantum);
2643 n++;
2644 }
2645 p+=quantum_info->pad;
2646 q->red=cbcr[1];
2647 q->green=cbcr[0];
2648 q->blue=cbcr[2];
2649 q++;
2650 q->red=cbcr[3];
2651 q->green=cbcr[0];
2652 q->blue=cbcr[2];
2653 q++;
2654 }
2655 break;
2656 }
2657 }
2658 default:
2659 {
2660 range=GetQuantumRange(image->depth);
2661 for (x=0; x < (long) number_pixels; x++)
2662 {
2663 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2664 q->red=ScaleAnyToQuantum(pixel,range);
2665 p=PushQuantumPixel(&quantum_state,image->depth,p,&pixel);
2666 q->green=ScaleAnyToQuantum(pixel,range);
2667 q++;
2668 }
2669 break;
2670 }
2671 }
2672 break;
2673 }
2674 default:
2675 break;
2676 }
2677 if ((quantum_type == CbYCrQuantum) || (quantum_type == CbYCrAQuantum))
2678 {
2679 Quantum
2680 quantum;
2681
2682 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002683 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002684
2685 q=GetAuthenticPixelQueue(image);
2686 if (image_view != (CacheView *) NULL)
2687 q=GetCacheViewAuthenticPixelQueue(image_view);
2688 for (x=0; x < (long) number_pixels; x++)
2689 {
2690 quantum=q->red;
2691 q->red=q->green;
2692 q->green=quantum;
2693 q++;
2694 }
2695 }
2696 if ((quantum_type == RGBOQuantum) || (quantum_type == CMYKOQuantum))
2697 {
2698 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002699 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002700
2701 q=GetAuthenticPixelQueue(image);
2702 if (image_view != (CacheView *) NULL)
2703 q=GetCacheViewAuthenticPixelQueue(image_view);
2704 for (x=0; x < (long) number_pixels; x++)
2705 {
2706 q->opacity=(Quantum) (QuantumRange-q->opacity);
2707 q++;
2708 }
2709 }
2710 if (quantum_info->alpha_type == DisassociatedQuantumAlpha)
2711 {
2712 MagickRealType
2713 alpha;
2714
2715 register PixelPacket
cristyc47d1f82009-11-26 01:44:43 +00002716 *restrict q;
cristy3ed852e2009-09-05 21:47:34 +00002717
2718 /*
2719 Disassociate alpha.
2720 */
2721 q=GetAuthenticPixelQueue(image);
2722 if (image_view != (CacheView *) NULL)
2723 q=GetCacheViewAuthenticPixelQueue(image_view);
2724 for (x=0; x < (long) number_pixels; x++)
2725 {
2726 alpha=QuantumScale*((MagickRealType) QuantumRange-q->opacity);
2727 alpha=1.0/(fabs(alpha) <= MagickEpsilon ? 1.0 : alpha);
2728 q->red=RoundToQuantum(alpha*q->red);
2729 q->green=RoundToQuantum(alpha*q->green);
2730 q->blue=RoundToQuantum(alpha*q->blue);
2731 q++;
2732 }
2733 }
2734 return(extent);
2735}