|
|
Definition at line 474 of file bmp.c.
References AbsoluteIntent, AbsoluteValue, AcquireMagickMemory(), AllocateImage(), AllocateImageColormap(), AllocateNextImage(), assert, BI_BITFIELDS, BI_JPEG, BI_PNG, BI_RGB, BI_RLE4, BI_RLE8, _PixelPacket::blue, _ChromaticityInfo::blue_primary, _Image::chromaticity, _Image::client_data, CloseBlob(), CoderError, CoderEvent, _Image::colormap, _Image::colors, _Image::columns, _Image::compression, ConstrainColormapIndex(), CorruptImageError, _Image::debug, _ImageInfo::debug, DecodeImage(), _Image::depth, DestroyImage(), DestroyImageList(), DirectClass, EOFBlob(), _Image::filename, _ImageInfo::filename, FlipImage(), _Image::gamma, GetBlobSize(), GetFirstImageInList(), GetIndexes(), GetMagickModule, _PixelPacket::green, _ChromaticityInfo::green_primary, IndexPacket, IsBMP(), LCS_GM_ABS_COLORIMETRIC, LCS_GM_BUSINESS, LCS_GM_GRAPHICS, LCS_GM_IMAGES, LoadImagesTag, LoadImageTag, LocaleNCompare(), LogMagickEvent(), MagickBooleanType, MagickFalse, MagickOffsetType, MagickProgressMonitor, MagickSignature, MagickSizeType, _Image::matte, Max, _Image::next, _ImageInfo::number_scenes, _PixelPacket::opacity, OpenBlob(), PerceptualIntent, _ImageInfo::ping, _Image::previous, _Image::progress_monitor, PseudoClass, Quantum, QuantumTick, ReadBinaryBlobMode, ReadBlob(), ReadBlobLSBLong(), ReadBlobLSBShort(), _PixelPacket::red, _ChromaticityInfo::red_primary, RelativeIntent, RelinquishMagickMemory(), _Image::rendering_intent, ResetMagickMemory(), ResourceLimitError, _Image::rows, SaturationIntent, ScaleCharToQuantum, ScaleShortToQuantum, _ImageInfo::scene, _Image::scene, SeekBlob(), SetImagePixels(), _ExceptionInfo::signature, _ImageInfo::signature, ssize_t, _Image::storage_class, SyncImagePixels(), SyncNextImageInList(), TellBlob(), ThrowFileException, ThrowMagickException(), ThrowReaderException, TraceEvent, _PrimaryInfo::x, _Image::x_resolution, _PrimaryInfo::y, and _Image::y_resolution.
Referenced by RegisterBMPImage().
00475 {
00476 BMPInfo
00477 bmp_info;
00478
00479 Image
00480 *image;
00481
00482 IndexPacket
00483 index;
00484
00485 long
00486 y;
00487
00488 MagickBooleanType
00489 status;
00490
00491 MagickOffsetType
00492 start_position;
00493
00494 register IndexPacket
00495 *indexes;
00496
00497 register long
00498 x;
00499
00500 register PixelPacket
00501 *q;
00502
00503 register long
00504 i;
00505
00506 register unsigned char
00507 *p;
00508
00509 ssize_t
00510 count;
00511
00512 size_t
00513 length;
00514
00515 unsigned char
00516 magick[12],
00517 *pixels;
00518
00519 unsigned long
00520 bit,
00521 blue,
00522 bytes_per_line,
00523 green,
00524 opacity,
00525 red;
00526
00527
00528
00529
00530 assert(image_info != ( const ImageInfo *) NULL);
00531 assert(image_info-> signature == MagickSignature);
00532 if (image_info-> debug != MagickFalse)
00533 ( void) LogMagickEvent(TraceEvent, GetMagickModule(),image_info-> filename);
00534 assert(exception != ( ExceptionInfo *) NULL);
00535 assert(exception-> signature == MagickSignature);
00536 image= AllocateImage(image_info);
00537 status= OpenBlob(image_info,image,ReadBinaryBlobMode,exception);
00538 if (status == MagickFalse)
00539 {
00540 DestroyImageList(image);
00541 return(( Image *) NULL);
00542 }
00543
00544
00545
00546 ( void) ResetMagickMemory(&bmp_info,0, sizeof(bmp_info));
00547 bmp_info. ba_offset=0;
00548 start_position=0;
00549 count= ReadBlob(image,2,magick);
00550 do
00551 {
00552 PixelPacket
00553 quantum_bits,
00554 shift;
00555
00556 unsigned long
00557 profile_data,
00558 profile_size;
00559
00560
00561
00562
00563 if (bmp_info. ba_offset == 0)
00564 start_position= TellBlob(image)-2;
00565 bmp_info. ba_offset=0;
00566 while ( LocaleNCompare(( char *) magick, "BA",2) == 0)
00567 {
00568 bmp_info. file_size= ReadBlobLSBLong(image);
00569 bmp_info. ba_offset= ReadBlobLSBLong(image);
00570 bmp_info. offset_bits= ReadBlobLSBLong(image);
00571 count= ReadBlob(image,2,magick);
00572 if (count == 0)
00573 break;
00574 }
00575 if (image-> debug != MagickFalse)
00576 ( void) LogMagickEvent(CoderEvent, GetMagickModule(), " Magick: %c%c",
00577 magick[0],magick[1]);
00578 if ((count == 0) || (( LocaleNCompare(( char *) magick, "BM",2) != 0) &&
00579 ( LocaleNCompare(( char *) magick, "CI",2) != 0)))
00580 ThrowReaderException(CorruptImageError, "ImproperImageHeader");
00581 bmp_info. file_size= ReadBlobLSBLong(image);
00582 ( void) ReadBlobLSBLong(image);
00583 bmp_info. offset_bits= ReadBlobLSBLong(image);
00584 bmp_info. size= ReadBlobLSBLong(image);
00585 if (image-> debug != MagickFalse)
00586 ( void) LogMagickEvent(CoderEvent, GetMagickModule(), " BMP size: %lu",
00587 bmp_info. size);
00588 if (bmp_info. size == 12)
00589 {
00590
00591
00592
00593 bmp_info. width=( short) ReadBlobLSBShort(image);
00594 bmp_info. height=( short) ReadBlobLSBShort(image);
00595 bmp_info. planes= ReadBlobLSBShort(image);
00596 bmp_info. bits_per_pixel= ReadBlobLSBShort(image);
00597 bmp_info. x_pixels=0;
00598 bmp_info. y_pixels=0;
00599 bmp_info. number_colors=0;
00600 bmp_info. compression= BI_RGB;
00601 bmp_info. image_size=0;
00602 bmp_info. alpha_mask=0;
00603 if (image-> debug != MagickFalse)
00604 {
00605 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00606 " Format: OS/2 Bitmap");
00607 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00608 " Geometry: %ldx%ld",bmp_info. width,bmp_info. height);
00609 }
00610 }
00611 else
00612 {
00613
00614
00615
00616 if (bmp_info. size < 40)
00617 ThrowReaderException(CorruptImageError, "NonOS2HeaderSizeError");
00618 bmp_info. width=( short) ReadBlobLSBLong(image);
00619 bmp_info. height=( short) ReadBlobLSBLong(image);
00620 bmp_info. planes= ReadBlobLSBShort(image);
00621 bmp_info. bits_per_pixel= ReadBlobLSBShort(image);
00622 bmp_info. compression= ReadBlobLSBLong(image);
00623 bmp_info. image_size= ReadBlobLSBLong(image);
00624 bmp_info. x_pixels= ReadBlobLSBLong(image);
00625 bmp_info. y_pixels= ReadBlobLSBLong(image);
00626 bmp_info. number_colors= ReadBlobLSBLong(image);
00627 bmp_info. colors_important= ReadBlobLSBLong(image);
00628 profile_data=0;
00629 profile_size=0;
00630 if (image-> debug != MagickFalse)
00631 {
00632 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00633 " Format: MS Windows bitmap");
00634 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00635 " Geometry: %ldx%ld",bmp_info. width,bmp_info. height);
00636 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00637 " Bits per pixel: %d",bmp_info. bits_per_pixel);
00638 switch (( int) bmp_info. compression)
00639 {
00640 case BI_RGB:
00641 {
00642 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00643 " Compression: BI_RGB");
00644 break;
00645 }
00646 case BI_RLE4:
00647 {
00648 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00649 " Compression: BI_RLE4");
00650 break;
00651 }
00652 case BI_RLE8:
00653 {
00654 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00655 " Compression: BI_RLE8");
00656 break;
00657 }
00658 case BI_BITFIELDS:
00659 {
00660 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00661 " Compression: BI_BITFIELDS");
00662 break;
00663 }
00664 case BI_PNG:
00665 {
00666 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00667 " Compression: BI_PNG");
00668 break;
00669 }
00670 case BI_JPEG:
00671 {
00672 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00673 " Compression: BI_JPEG");
00674 break;
00675 }
00676 default:
00677 {
00678 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00679 " Compression: UNKNOWN (%lu)",bmp_info. compression);
00680 }
00681 }
00682 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00683 " Number of colors: %lu",bmp_info. number_colors);
00684 }
00685 bmp_info. red_mask= ReadBlobLSBLong(image);
00686 bmp_info. green_mask= ReadBlobLSBLong(image);
00687 bmp_info. blue_mask= ReadBlobLSBLong(image);
00688 if (bmp_info. size > 40)
00689 {
00690 double
00691 sum;
00692
00693
00694
00695
00696 bmp_info. alpha_mask= ReadBlobLSBLong(image);
00697 bmp_info. colorspace=( long) ReadBlobLSBLong(image);
00698
00699
00700
00701 bmp_info. red_primary. x=( double)
00702 ReadBlobLSBLong(image)/0x3ffffff;
00703 bmp_info. red_primary. y=( double)
00704 ReadBlobLSBLong(image)/0x3ffffff;
00705 bmp_info. red_primary. z=( double)
00706 ReadBlobLSBLong(image)/0x3ffffff;
00707 bmp_info. green_primary. x=( double)
00708 ReadBlobLSBLong(image)/0x3ffffff;
00709 bmp_info. green_primary. y=( double)
00710 ReadBlobLSBLong(image)/0x3ffffff;
00711 bmp_info. green_primary. z=( double)
00712 ReadBlobLSBLong(image)/0x3ffffff;
00713 bmp_info. blue_primary. x=( double)
00714 ReadBlobLSBLong(image)/0x3ffffff;
00715 bmp_info. blue_primary. y=( double)
00716 ReadBlobLSBLong(image)/0x3ffffff;
00717 bmp_info. blue_primary. z=( double)
00718 ReadBlobLSBLong(image)/0x3ffffff;
00719 sum=bmp_info. red_primary. x+bmp_info. red_primary. x+
00720 bmp_info. red_primary. z;
00721 image-> chromaticity. red_primary. x/=sum;
00722 image-> chromaticity. red_primary. y/=sum;
00723 sum=bmp_info. green_primary. x+bmp_info. green_primary. x+
00724 bmp_info. green_primary. z;
00725 image-> chromaticity. green_primary. x/=sum;
00726 image-> chromaticity. green_primary. y/=sum;
00727 sum=bmp_info. blue_primary. x+bmp_info. blue_primary. x+
00728 bmp_info. blue_primary. z;
00729 image-> chromaticity. blue_primary. x/=sum;
00730 image-> chromaticity. blue_primary. y/=sum;
00731
00732
00733
00734 bmp_info. gamma_scale. x=( double) ReadBlobLSBLong(image)/0xffff;
00735 bmp_info. gamma_scale. y=( double) ReadBlobLSBLong(image)/0xffff;
00736 bmp_info. gamma_scale. z=( double) ReadBlobLSBLong(image)/0xffff;
00737
00738
00739
00740 image-> gamma=(bmp_info. gamma_scale. x+bmp_info. gamma_scale. y+
00741 bmp_info. gamma_scale. z)/3.0;
00742 }
00743 if (bmp_info. size > 108)
00744 {
00745 unsigned long
00746 intent;
00747
00748
00749
00750
00751 intent= ReadBlobLSBLong(image);
00752 switch (( int) intent)
00753 {
00754 case LCS_GM_BUSINESS:
00755 {
00756 image-> rendering_intent= SaturationIntent;
00757 break;
00758 }
00759 case LCS_GM_GRAPHICS:
00760 {
00761 image-> rendering_intent= RelativeIntent;
00762 break;
00763 }
00764 case LCS_GM_IMAGES:
00765 {
00766 image-> rendering_intent= PerceptualIntent;
00767 break;
00768 }
00769 case LCS_GM_ABS_COLORIMETRIC:
00770 {
00771 image-> rendering_intent= AbsoluteIntent;
00772 break;
00773 }
00774 }
00775 profile_data= ReadBlobLSBLong(image);
00776 profile_size= ReadBlobLSBLong(image);
00777 ( void) ReadBlobLSBLong(image);
00778 }
00779 }
00780 if ((bmp_info. compression != BI_RGB) &&
00781 (( MagickSizeType) bmp_info. file_size != GetBlobSize(image)))
00782 ( void) ThrowMagickException(exception, GetMagickModule(),CorruptImageError,
00783 "LengthAndFilesizeDoNotMatch",image-> filename);
00784 if (bmp_info. width <= 0)
00785 ThrowReaderException(CorruptImageError, "NegativeOrZeroImageSize");
00786 if (bmp_info. height == 0)
00787 ThrowReaderException(CorruptImageError, "NegativeOrZeroImageSize");
00788 if ((bmp_info. height < 0) && (bmp_info. compression !=0))
00789 ThrowReaderException(CorruptImageError, "CompressionNotValid");
00790 if (bmp_info. planes != 1)
00791 ThrowReaderException(CorruptImageError, "StaticPlanesValueNotEqualToOne");
00792 if ((bmp_info. bits_per_pixel != 1) && (bmp_info. bits_per_pixel != 4) &&
00793 (bmp_info. bits_per_pixel != 8) && (bmp_info. bits_per_pixel != 16) &&
00794 (bmp_info. bits_per_pixel != 24) && (bmp_info. bits_per_pixel != 32))
00795 ThrowReaderException(CorruptImageError, "UnrecognizedBitsPerPixel");
00796 if (bmp_info. number_colors > (1UL << bmp_info. bits_per_pixel))
00797 ThrowReaderException(CorruptImageError, "UnrecognizedNumberOfColors");
00798 if (bmp_info. compression > 3)
00799 ThrowReaderException(CorruptImageError, "UnrecognizedImageCompression");
00800 if ((bmp_info. compression == 1) && (bmp_info. bits_per_pixel != 8))
00801 ThrowReaderException(CorruptImageError, "UnrecognizedBitsPerPixel");
00802 if ((bmp_info. compression == 2) && (bmp_info. bits_per_pixel != 4))
00803 ThrowReaderException(CorruptImageError, "UnrecognizedBitsPerPixel");
00804 if ((bmp_info. compression == 3) && (bmp_info. bits_per_pixel < 16))
00805 ThrowReaderException(CorruptImageError, "UnrecognizedBitsPerPixel");
00806 switch (bmp_info. compression)
00807 {
00808 case BI_RGB:
00809 case BI_RLE8:
00810 case BI_RLE4:
00811 case BI_BITFIELDS:
00812 break;
00813 case BI_JPEG:
00814 ThrowReaderException(CoderError, "JPEGCompressionNotSupported");
00815 case BI_PNG:
00816 ThrowReaderException(CoderError, "PNGCompressionNotSupported");
00817 default:
00818 ThrowReaderException(CorruptImageError, "UnrecognizedImageCompression");
00819 }
00820 image-> columns=( unsigned long) bmp_info. width;
00821 image-> rows=( unsigned long) AbsoluteValue(bmp_info. height);
00822 image-> depth=8;
00823 image-> matte=( MagickBooleanType) (bmp_info. alpha_mask != 0);
00824 if ((bmp_info. number_colors != 0) || (bmp_info. bits_per_pixel < 16))
00825 {
00826 image-> storage_class= PseudoClass;
00827 image-> colors=bmp_info. number_colors;
00828 if (image-> colors == 0)
00829 image-> colors=1L << bmp_info. bits_per_pixel;
00830 }
00831 if (image-> storage_class == PseudoClass)
00832 {
00833 unsigned char
00834 *bmp_colormap;
00835
00836 size_t
00837 packet_size;
00838
00839
00840
00841
00842 if (image-> debug != MagickFalse)
00843 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00844 " Reading colormap of %ld colors",image-> colors);
00845 if ( AllocateImageColormap(image,image-> colors) == MagickFalse)
00846 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00847 bmp_colormap=( unsigned char *)
00848 AcquireMagickMemory((size_t) (4*image-> colors));
00849 if (bmp_colormap == ( unsigned char *) NULL)
00850 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00851 if ((bmp_info. size == 12) || (bmp_info. size == 64))
00852 packet_size=3;
00853 else
00854 packet_size=4;
00855 ( void) SeekBlob(image,start_position+14+bmp_info. size,SEEK_SET);
00856 ( void) ReadBlob(image,packet_size*image-> colors,bmp_colormap);
00857 p=bmp_colormap;
00858 for (i=0; i < ( long) image-> colors; i++)
00859 {
00860 image-> colormap[i]. blue= ScaleCharToQuantum(*p++);
00861 image-> colormap[i]. green= ScaleCharToQuantum(*p++);
00862 image-> colormap[i]. red= ScaleCharToQuantum(*p++);
00863 if (packet_size == 4)
00864 p++;
00865 }
00866 bmp_colormap=( unsigned char *) RelinquishMagickMemory(bmp_colormap);
00867 }
00868 if ((image_info-> ping != MagickFalse) && (image_info-> number_scenes != 0))
00869 if (image-> scene >= (image_info-> scene+image_info-> number_scenes-1))
00870 break;
00871
00872
00873
00874 ( void) SeekBlob(image,start_position+bmp_info. offset_bits,SEEK_SET);
00875 if (bmp_info. compression == BI_RLE4)
00876 bmp_info. bits_per_pixel<<=1;
00877 bytes_per_line=4*((image-> columns*bmp_info. bits_per_pixel+31)/32);
00878 length=(size_t) bytes_per_line*image-> rows;
00879 pixels=( unsigned char *) AcquireMagickMemory((size_t)
00880 Max(bytes_per_line,image-> columns+256)*image-> rows* sizeof(*pixels));
00881 if (pixels == ( unsigned char *) NULL)
00882 ThrowReaderException(ResourceLimitError, "MemoryAllocationFailed");
00883 if ((bmp_info. compression == BI_RGB) ||
00884 (bmp_info. compression == BI_BITFIELDS))
00885 {
00886 if (image-> debug != MagickFalse)
00887 ( void) LogMagickEvent(CoderEvent, GetMagickModule(),
00888 " Reading pixels (%ld bytes)",( long) length);
00889 ( void) ReadBlob(image,length,pixels);
00890 }
00891 else
00892 {
00893
00894
00895
00896 status= DecodeImage(image,bmp_info. compression,pixels);
00897 if (status == MagickFalse)
00898 ThrowReaderException(CorruptImageError,
00899 "UnableToRunlengthDecodeImage");
00900 }
00901
00902
00903
00904 image-> x_resolution=( double) bmp_info. x_pixels/100.0;
00905 image-> y_resolution=( double) bmp_info. y_pixels/100.0;
00906
00907
00908
00909 if (bmp_info. compression == BI_RGB)
00910 {
00911 bmp_info. alpha_mask=0;
00912 bmp_info. red_mask=0x00ff0000UL;
00913 bmp_info. green_mask=0x0000ff00UL;
00914 bmp_info. blue_mask=0x000000ffUL;
00915 if (bmp_info. bits_per_pixel == 16)
00916 {
00917
00918
00919
00920 bmp_info. red_mask=0x00007c00UL;
00921 bmp_info. green_mask=0x000003e0UL;
00922 bmp_info. blue_mask=0x0000001fUL;
00923 }
00924 }
00925 if ((bmp_info. bits_per_pixel == 16) || (bmp_info. bits_per_pixel == 32))
00926 {
00927 register unsigned long
00928 sample;
00929
00930
00931
00932
00933 ( void) ResetMagickMemory(&shift,0, sizeof(shift));
00934 ( void) ResetMagickMemory(&quantum_bits,0, sizeof(quantum_bits));
00935 if (bmp_info. red_mask != 0)
00936 while (((bmp_info. red_mask << shift. red) & 0x80000000UL) == 0)
00937 shift. red++;
00938 if (bmp_info. green_mask != 0)
00939 while (((bmp_info. green_mask << shift. green) & 0x80000000UL) == 0)
00940 shift. green++;
00941 if (bmp_info. blue_mask != 0)
00942 while (((bmp_info. blue_mask << shift. blue) & 0x80000000UL) == 0)
00943 shift. blue++;
00944 if (bmp_info. alpha_mask != 0)
00945 while (((bmp_info. alpha_mask << shift. opacity) & 0x80000000UL) == 0)
00946 shift. opacity++;
00947 sample=shift. red;
00948 while (((bmp_info. red_mask << sample) & 0x80000000UL) != 0)
00949 sample++;
00950 quantum_bits. red=( Quantum) (sample-shift. red);
00951 sample=shift. green;
00952 while (((bmp_info. green_mask << sample) & 0x80000000UL) != 0)
00953 sample++;
00954 quantum_bits. green=( Quantum) (sample-shift. green);
00955 sample=shift. blue;
00956 while (((bmp_info. blue_mask << sample) & 0x80000000UL) != 0)
00957 sample++;
00958 quantum_bits. blue=( Quantum) (sample-shift. blue);
00959 sample=shift. opacity;
00960 while (((bmp_info. alpha_mask << sample) & 0x80000000UL) != 0)
00961 sample++;
00962 quantum_bits. opacity=( Quantum) (sample-shift. opacity);
00963 }
00964 switch (bmp_info. bits_per_pixel)
00965 {
00966 case 1:
00967 {
00968
00969
00970
00971 for (y=( long) image-> rows-1; y >= 0; y--)
00972 {
00973 p=pixels+(image-> rows-y-1)*bytes_per_line;
00974 q= SetImagePixels(image,0,y,image-> columns,1);
00975 if (q == ( PixelPacket *) NULL)
00976 break;
00977 indexes= GetIndexes(image);
00978 for (x=0; x < (( long) image-> columns-7); x+=8)
00979 {
00980 for (bit=0; bit < 8; bit++)
00981 {
00982 index=( IndexPacket) (((*p) & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
00983 indexes[x+bit]=index;
00984 *q++=image-> colormap[index];
00985 }
00986 p++;
00987 }
00988 if ((image-> columns % 8) != 0)
00989 {
00990 for (bit=0; bit < (image-> columns % 8); bit++)
00991 {
00992 index=( IndexPacket) (((*p) & (0x80 >> bit)) != 0 ? 0x01 : 0x00);
00993 indexes[x+bit]=index;
00994 *q++=image-> colormap[index];
00995 }
00996 p++;
00997 }
00998 if ( SyncImagePixels(image) == MagickFalse)
00999 break;
01000 if (image-> previous == ( Image *) NULL)
01001 if ((image-> progress_monitor != ( MagickProgressMonitor) NULL) &&
01002 ( QuantumTick(y,image-> rows) != MagickFalse))
01003 {
01004 status=image-> progress_monitor(LoadImageTag,y,image-> rows,
01005 image-> client_data);
01006 if (status == MagickFalse)
01007 break;
01008 }
01009 }
01010 break;
01011 }
01012 case 4:
01013 {
01014
01015
01016
01017 for (y=( long) image-> rows-1; y >= 0; y--)
01018 {
01019 p=pixels+(image-> rows-y-1)*bytes_per_line;
01020 q= SetImagePixels(image,0,y,image-> columns,1);
01021 if (q == ( PixelPacket *) NULL)
01022 break;
01023 indexes= GetIndexes(image);
01024 for (x=0; x < (( long) image-> columns-1); x+=2)
01025 {
01026 index= ConstrainColormapIndex(image,(*p >> 4) & 0x0f);
01027 indexes[x]=index;
01028 *q++=image-> colormap[index];
01029 index= ConstrainColormapIndex(image,*p & 0x0f);
01030 indexes[x+1]=index;
01031 *q++=image-> colormap[index];
01032 p++;
01033 }
01034 if ((image-> columns % 2) != 0)
01035 {
01036 index= ConstrainColormapIndex(image,(*p >> 4) & 0xf);
01037 indexes[x]=index;
01038 *q++=image-> colormap[index];
01039 p++;
01040 }
01041 if ( SyncImagePixels(image) == MagickFalse)
01042 break;
01043 if (image-> previous == ( Image *) NULL)
01044 if ((image-> progress_monitor != ( MagickProgressMonitor) NULL) &&
01045 ( QuantumTick(y,image-> rows) != MagickFalse))
01046 {
01047 status=image-> progress_monitor(LoadImageTag,y,image-> rows,
01048 image-> client_data);
01049 if (status == MagickFalse)
01050 break;
01051 }
01052 }
01053 break;
01054 }
01055 case 8:
01056 {
01057
01058
01059
01060 if ((bmp_info. compression == BI_RLE8) ||
01061 (bmp_info. compression == BI_RLE4))
01062 bytes_per_line=image-> columns;
01063 for (y=( long) image-> rows-1; y >= 0; y--)
01064 {
01065 p=pixels+(image-> rows-y-1)*bytes_per_line;
01066 q= SetImagePixels(image,0,y,image-> columns,1);
01067 if (q == ( PixelPacket *) NULL)
01068 break;
01069 indexes= GetIndexes(image);
01070 for (x = ( long)image-> columns; x != 0; --x)
01071 {
01072 index= ConstrainColormapIndex(image,*p);
01073 *indexes++=index;
01074 *q=image-> colormap[index];
01075 p++;
01076 q++;
01077 }
01078 if ( SyncImagePixels(image) == MagickFalse)
01079 break;
01080 if (image-> previous == ( Image *) NULL)
01081 if ((image-> progress_monitor != ( MagickProgressMonitor) NULL) &&
01082 ( QuantumTick(image-> rows-y-1,image-> rows) != MagickFalse))
01083 {
01084 status=image-> progress_monitor(LoadImageTag,(MagickOffsetType)
01085 image-> rows-y-1,image-> rows,image-> client_data);
01086 if (status == MagickFalse)
01087 break;
01088 }
01089 }
01090 break;
01091 }
01092 case 16:
01093 {
01094 unsigned long
01095 pixel;
01096
01097
01098
01099
01100 if (bmp_info. compression != BI_RGB &&
01101 bmp_info. compression != BI_BITFIELDS)
01102 ThrowReaderException(CorruptImageError,
01103 "UnrecognizedImageCompression");
01104 bytes_per_line=2*(image-> columns+image-> columns%2);
01105 image-> storage_class= DirectClass;
01106 for (y=( long) image-> rows-1; y >= 0; y--)
01107 {
01108 p=pixels+(image-> rows-y-1)*bytes_per_line;
01109 q= SetImagePixels(image,0,y,image-> columns,1);
01110 if (q == ( PixelPacket *) NULL)
01111 break;
01112 for (x=0; x < ( long) image-> columns; x++)
01113 {
01114 pixel=( unsigned long) (*p++);
01115 pixel|=(*p++) << 8;
01116 red=((pixel & bmp_info. red_mask) << shift. red) >> 16;
01117 if (quantum_bits. red == 5)
01118 red|=((red & 0xe000) >> 5);
01119 if (quantum_bits. red <= 8)
01120 red|=((red & 0xff00) >> 8);
01121 green=((pixel & bmp_info. green_mask) << shift. green) >> 16;
01122 if (quantum_bits. green == 5)
01123 green|=((green & 0xe000) >> 5);
01124 if (quantum_bits. green == 6)
01125 green|=((green & 0xc000) >> 6);
01126 if (quantum_bits. green <= 8)
01127 green|=((green & 0xff00) >> 8);
01128 blue=((pixel & bmp_info. blue_mask) << shift. blue) >> 16;
01129 if (quantum_bits. blue == 5)
01130 blue|=((blue & 0xe000) >> 5);
01131 if (quantum_bits. blue <= 8)
01132 blue|=((blue & 0xff00) >> 8);
01133 q-> red= ScaleShortToQuantum(red);
01134 q-> green= ScaleShortToQuantum(green);
01135 q-> blue= ScaleShortToQuantum(b
|