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