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