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