91 private static final int VERSION_3_8_BIT = 6;
92 private static final int VERSION_3_24_BIT = 7;
93
94 private static final int VERSION_3_NT_16_BIT = 8;
95 private static final int VERSION_3_NT_32_BIT = 9;
96
97 private static final int VERSION_4_1_BIT = 10;
98 private static final int VERSION_4_4_BIT = 11;
99 private static final int VERSION_4_8_BIT = 12;
100 private static final int VERSION_4_16_BIT = 13;
101 private static final int VERSION_4_24_BIT = 14;
102 private static final int VERSION_4_32_BIT = 15;
103
104 private static final int VERSION_3_XP_EMBEDDED = 16;
105 private static final int VERSION_4_XP_EMBEDDED = 17;
106 private static final int VERSION_5_XP_EMBEDDED = 18;
107
108 // BMP variables
109 private long bitmapFileSize;
110 private long bitmapOffset;
111 private long compression;
112 private long imageSize;
113 private byte palette[];
114 private int imageType;
115 private int numBands;
116 private boolean isBottomUp;
117 private int bitsPerPixel;
118 private int redMask, greenMask, blueMask, alphaMask;
119
120 private SampleModel sampleModel, originalSampleModel;
121 private ColorModel colorModel, originalColorModel;
122
123 /** The input stream where reads from */
124 private ImageInputStream iis = null;
125
126 /** Indicates whether the header is read. */
127 private boolean gotHeader = false;
128
129 /** The original image width. */
130 private int width;
660 }
661
662 sampleModel =
663 new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
664 width, height,
665 numBands,
666 numBands * width,
667 bandOffsets);
668
669 colorModel =
670 ImageUtil.createColorModel(colorSpace, sampleModel);
671 }
672
673 originalSampleModel = sampleModel;
674 originalColorModel = colorModel;
675
676 // Reset to the start of bitmap; then jump to the
677 //start of image data
678 iis.reset();
679 iis.skipBytes(bitmapOffset);
680 gotHeader = true;
681 }
682
683 public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
684 throws IOException {
685 checkIndex(imageIndex);
686 try {
687 readHeader();
688 } catch (IllegalArgumentException e) {
689 throw new IIOException(I18N.getString("BMPImageReader6"), e);
690 }
691 ArrayList<ImageTypeSpecifier> list = new ArrayList<>(1);
692 list.add(new ImageTypeSpecifier(originalColorModel,
693 originalSampleModel));
694 return list.iterator();
695 }
696
697 public ImageReadParam getDefaultReadParam() {
698 return new ImageReadParam();
699 }
795 raster = bi.getWritableTile(0, 0);
796 sampleModel = bi.getSampleModel();
797 colorModel = bi.getColorModel();
798
799 noTransform &= destinationRegion.equals(raster.getBounds());
800 }
801
802 byte bdata[] = null; // buffer for byte data
803 short sdata[] = null; // buffer for short data
804 int idata[] = null; // buffer for int data
805
806 // the sampleModel can be null in case of embedded image
807 if (sampleModel != null) {
808 if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
809 bdata = ((DataBufferByte)raster.getDataBuffer()).getData();
810 else if (sampleModel.getDataType() == DataBuffer.TYPE_USHORT)
811 sdata = ((DataBufferUShort)raster.getDataBuffer()).getData();
812 else if (sampleModel.getDataType() == DataBuffer.TYPE_INT)
813 idata = ((DataBufferInt)raster.getDataBuffer()).getData();
814 }
815
816 // There should only be one tile.
817 switch(imageType) {
818
819 case VERSION_2_1_BIT:
820 // no compression
821 read1Bit(bdata);
822 break;
823
824 case VERSION_2_4_BIT:
825 // no compression
826 read4Bit(bdata);
827 break;
828
829 case VERSION_2_8_BIT:
830 // no compression
831 read8Bit(bdata);
832 break;
833
834 case VERSION_2_24_BIT:
|
91 private static final int VERSION_3_8_BIT = 6;
92 private static final int VERSION_3_24_BIT = 7;
93
94 private static final int VERSION_3_NT_16_BIT = 8;
95 private static final int VERSION_3_NT_32_BIT = 9;
96
97 private static final int VERSION_4_1_BIT = 10;
98 private static final int VERSION_4_4_BIT = 11;
99 private static final int VERSION_4_8_BIT = 12;
100 private static final int VERSION_4_16_BIT = 13;
101 private static final int VERSION_4_24_BIT = 14;
102 private static final int VERSION_4_32_BIT = 15;
103
104 private static final int VERSION_3_XP_EMBEDDED = 16;
105 private static final int VERSION_4_XP_EMBEDDED = 17;
106 private static final int VERSION_5_XP_EMBEDDED = 18;
107
108 // BMP variables
109 private long bitmapFileSize;
110 private long bitmapOffset;
111 private long bitmapStart;
112 private long compression;
113 private long imageSize;
114 private byte palette[];
115 private int imageType;
116 private int numBands;
117 private boolean isBottomUp;
118 private int bitsPerPixel;
119 private int redMask, greenMask, blueMask, alphaMask;
120
121 private SampleModel sampleModel, originalSampleModel;
122 private ColorModel colorModel, originalColorModel;
123
124 /** The input stream where reads from */
125 private ImageInputStream iis = null;
126
127 /** Indicates whether the header is read. */
128 private boolean gotHeader = false;
129
130 /** The original image width. */
131 private int width;
661 }
662
663 sampleModel =
664 new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
665 width, height,
666 numBands,
667 numBands * width,
668 bandOffsets);
669
670 colorModel =
671 ImageUtil.createColorModel(colorSpace, sampleModel);
672 }
673
674 originalSampleModel = sampleModel;
675 originalColorModel = colorModel;
676
677 // Reset to the start of bitmap; then jump to the
678 //start of image data
679 iis.reset();
680 iis.skipBytes(bitmapOffset);
681 bitmapStart = iis.getStreamPosition();
682
683 gotHeader = true;
684 }
685
686 public Iterator<ImageTypeSpecifier> getImageTypes(int imageIndex)
687 throws IOException {
688 checkIndex(imageIndex);
689 try {
690 readHeader();
691 } catch (IllegalArgumentException e) {
692 throw new IIOException(I18N.getString("BMPImageReader6"), e);
693 }
694 ArrayList<ImageTypeSpecifier> list = new ArrayList<>(1);
695 list.add(new ImageTypeSpecifier(originalColorModel,
696 originalSampleModel));
697 return list.iterator();
698 }
699
700 public ImageReadParam getDefaultReadParam() {
701 return new ImageReadParam();
702 }
798 raster = bi.getWritableTile(0, 0);
799 sampleModel = bi.getSampleModel();
800 colorModel = bi.getColorModel();
801
802 noTransform &= destinationRegion.equals(raster.getBounds());
803 }
804
805 byte bdata[] = null; // buffer for byte data
806 short sdata[] = null; // buffer for short data
807 int idata[] = null; // buffer for int data
808
809 // the sampleModel can be null in case of embedded image
810 if (sampleModel != null) {
811 if (sampleModel.getDataType() == DataBuffer.TYPE_BYTE)
812 bdata = ((DataBufferByte)raster.getDataBuffer()).getData();
813 else if (sampleModel.getDataType() == DataBuffer.TYPE_USHORT)
814 sdata = ((DataBufferUShort)raster.getDataBuffer()).getData();
815 else if (sampleModel.getDataType() == DataBuffer.TYPE_INT)
816 idata = ((DataBufferInt)raster.getDataBuffer()).getData();
817 }
818
819 iis.seek(bitmapStart);
820
821 // There should only be one tile.
822 switch(imageType) {
823
824 case VERSION_2_1_BIT:
825 // no compression
826 read1Bit(bdata);
827 break;
828
829 case VERSION_2_4_BIT:
830 // no compression
831 read4Bit(bdata);
832 break;
833
834 case VERSION_2_8_BIT:
835 // no compression
836 read8Bit(bdata);
837 break;
838
839 case VERSION_2_24_BIT:
|