Class BMPImageReader
- java.lang.Object
-
- javax.imageio.ImageReader
-
- com.github.jaiimageio.impl.plugins.bmp.BMPImageReader
-
- All Implemented Interfaces:
BMPConstants
public class BMPImageReader extends javax.imageio.ImageReader implements BMPConstants
This class is the Java Image IO plugin reader for BMP images. It may subsample the image, clip the image, select sub-bands, and shift the decoded image origin if the proper decoding parameter are set in the providedImageReadParam
. This class supports Microsoft Windows Bitmap Version 3-5, as well as OS/2 Bitmap Version 2.x (for single-image BMP file).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
BMPImageReader.EmbeddedProgressAdapter
-
Field Summary
Fields Modifier and Type Field Description private int
alphaMask
private java.awt.image.BufferedImage
bi
The destination image.private long
bitmapFileSize
private long
bitmapOffset
private int
bitsPerPixel
private int
blueMask
private java.awt.image.ColorModel
colorModel
private long
compression
private int[]
destBands
source and destination bands.private java.awt.Rectangle
destinationRegion
The destination region.private boolean
gotHeader
Indicates whether the header is read.private int
greenMask
private int
height
The original image height.private javax.imageio.stream.ImageInputStream
iis
The input stream where reads fromprivate long
imageDataOffset
The stream position where the image data starts.private long
imageSize
private int
imageType
private boolean
isBottomUp
private BMPMetadata
metadata
The metadata from the stream.private boolean
noTransform
Indicates whether subsampled, subregion is required, and offset is definedprivate int
numBands
private java.awt.image.ColorModel
originalColorModel
private java.awt.image.SampleModel
originalSampleModel
private byte[]
palette
private int
redMask
private java.awt.image.SampleModel
sampleModel
private int
scaleX
The scaling factors.private int
scaleY
The scaling factors.private boolean
seleBand
Indicates whether subband is selected.private int[]
sourceBands
source and destination bands.private java.awt.Rectangle
sourceRegion
The source region.private static int
VERSION_2_1_BIT
private static int
VERSION_2_24_BIT
private static int
VERSION_2_4_BIT
private static int
VERSION_2_8_BIT
private static int
VERSION_3_1_BIT
private static int
VERSION_3_24_BIT
private static int
VERSION_3_4_BIT
private static int
VERSION_3_8_BIT
private static int
VERSION_3_NT_16_BIT
private static int
VERSION_3_NT_32_BIT
private static int
VERSION_3_XP_EMBEDDED
private static int
VERSION_4_1_BIT
private static int
VERSION_4_16_BIT
private static int
VERSION_4_24_BIT
private static int
VERSION_4_32_BIT
private static int
VERSION_4_4_BIT
private static int
VERSION_4_8_BIT
private static int
VERSION_4_XP_EMBEDDED
private static int
VERSION_5_XP_EMBEDDED
private int
width
The original image width.-
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
-
Fields inherited from interface com.github.jaiimageio.impl.plugins.bmp.BMPConstants
BI_BITFIELDS, BI_JPEG, BI_PNG, BI_RGB, BI_RLE4, BI_RLE8, compressionTypeNames, LCS_CALIBRATED_RGB, LCS_sRGB, LCS_WINDOWS_COLOR_SPACE, PROFILE_EMBEDDED, PROFILE_LINKED, VERSION_2, VERSION_3, VERSION_3_NT, VERSION_4, VERSION_5
-
-
Constructor Summary
Constructors Constructor Description BMPImageReader(javax.imageio.spi.ImageReaderSpi originator)
ConstructsBMPImageReader
from the providedImageReaderSpi
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canReadRaster()
private void
checkIndex(int imageIndex)
private void
decodeRLE4(int imSize, int padding, byte[] values, byte[] bdata)
private void
decodeRLE8(int imSize, int padding, byte[] values, byte[] bdata)
javax.imageio.ImageReadParam
getDefaultReadParam()
int
getHeight(int imageIndex)
javax.imageio.metadata.IIOMetadata
getImageMetadata(int imageIndex)
java.util.Iterator
getImageTypes(int imageIndex)
int
getNumImages(boolean allowSearch)
Overrides the method defined in the superclass.javax.imageio.metadata.IIOMetadata
getStreamMetadata()
int
getWidth(int imageIndex)
boolean
isRandomAccessEasy(int imageIndex)
java.awt.image.BufferedImage
read(int imageIndex, javax.imageio.ImageReadParam param)
private void
read16Bit(short[] sdata)
private void
read1Bit(byte[] bdata)
private void
read24Bit(byte[] bdata)
private void
read32Bit(int[] idata)
private void
read4Bit(byte[] bdata)
private void
read8Bit(byte[] bdata)
private java.awt.image.BufferedImage
readEmbedded(int type, java.awt.image.BufferedImage bi, javax.imageio.ImageReadParam bmpParam)
Decodes the jpeg/png image embedded in the bitmap using any jpeg ImageIO-style plugin.void
readHeader()
java.awt.image.Raster
readRaster(int imageIndex, javax.imageio.ImageReadParam param)
private void
readRLE4(byte[] bdata)
private void
readRLE8(byte[] bdata)
void
reset()
private void
resetHeaderInfo()
void
setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
Overrides the method defined in the superclass.-
Methods inherited from class javax.imageio.ImageReader
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, checkReadParamBandSettings, clearAbortRequest, computeRegions, dispose, getAspectRatio, getAvailableLocales, getDestination, getFormatName, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getRawImageType, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isSeekForwardOnly, processImageComplete, processImageProgress, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, readAll, readAll, readAsRenderedImage, readerSupportsThumbnails, readThumbnail, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
-
-
-
-
Field Detail
-
VERSION_2_1_BIT
private static final int VERSION_2_1_BIT
- See Also:
- Constant Field Values
-
VERSION_2_4_BIT
private static final int VERSION_2_4_BIT
- See Also:
- Constant Field Values
-
VERSION_2_8_BIT
private static final int VERSION_2_8_BIT
- See Also:
- Constant Field Values
-
VERSION_2_24_BIT
private static final int VERSION_2_24_BIT
- See Also:
- Constant Field Values
-
VERSION_3_1_BIT
private static final int VERSION_3_1_BIT
- See Also:
- Constant Field Values
-
VERSION_3_4_BIT
private static final int VERSION_3_4_BIT
- See Also:
- Constant Field Values
-
VERSION_3_8_BIT
private static final int VERSION_3_8_BIT
- See Also:
- Constant Field Values
-
VERSION_3_24_BIT
private static final int VERSION_3_24_BIT
- See Also:
- Constant Field Values
-
VERSION_3_NT_16_BIT
private static final int VERSION_3_NT_16_BIT
- See Also:
- Constant Field Values
-
VERSION_3_NT_32_BIT
private static final int VERSION_3_NT_32_BIT
- See Also:
- Constant Field Values
-
VERSION_4_1_BIT
private static final int VERSION_4_1_BIT
- See Also:
- Constant Field Values
-
VERSION_4_4_BIT
private static final int VERSION_4_4_BIT
- See Also:
- Constant Field Values
-
VERSION_4_8_BIT
private static final int VERSION_4_8_BIT
- See Also:
- Constant Field Values
-
VERSION_4_16_BIT
private static final int VERSION_4_16_BIT
- See Also:
- Constant Field Values
-
VERSION_4_24_BIT
private static final int VERSION_4_24_BIT
- See Also:
- Constant Field Values
-
VERSION_4_32_BIT
private static final int VERSION_4_32_BIT
- See Also:
- Constant Field Values
-
VERSION_3_XP_EMBEDDED
private static final int VERSION_3_XP_EMBEDDED
- See Also:
- Constant Field Values
-
VERSION_4_XP_EMBEDDED
private static final int VERSION_4_XP_EMBEDDED
- See Also:
- Constant Field Values
-
VERSION_5_XP_EMBEDDED
private static final int VERSION_5_XP_EMBEDDED
- See Also:
- Constant Field Values
-
bitmapFileSize
private long bitmapFileSize
-
bitmapOffset
private long bitmapOffset
-
compression
private long compression
-
imageSize
private long imageSize
-
palette
private byte[] palette
-
imageType
private int imageType
-
numBands
private int numBands
-
isBottomUp
private boolean isBottomUp
-
bitsPerPixel
private int bitsPerPixel
-
redMask
private int redMask
-
greenMask
private int greenMask
-
blueMask
private int blueMask
-
alphaMask
private int alphaMask
-
sampleModel
private java.awt.image.SampleModel sampleModel
-
originalSampleModel
private java.awt.image.SampleModel originalSampleModel
-
colorModel
private java.awt.image.ColorModel colorModel
-
originalColorModel
private java.awt.image.ColorModel originalColorModel
-
iis
private javax.imageio.stream.ImageInputStream iis
The input stream where reads from
-
gotHeader
private boolean gotHeader
Indicates whether the header is read.
-
imageDataOffset
private long imageDataOffset
The stream position where the image data starts.
-
width
private int width
The original image width.
-
height
private int height
The original image height.
-
destinationRegion
private java.awt.Rectangle destinationRegion
The destination region.
-
sourceRegion
private java.awt.Rectangle sourceRegion
The source region.
-
metadata
private BMPMetadata metadata
The metadata from the stream.
-
bi
private java.awt.image.BufferedImage bi
The destination image.
-
noTransform
private boolean noTransform
Indicates whether subsampled, subregion is required, and offset is defined
-
seleBand
private boolean seleBand
Indicates whether subband is selected.
-
scaleX
private int scaleX
The scaling factors.
-
scaleY
private int scaleY
The scaling factors.
-
sourceBands
private int[] sourceBands
source and destination bands.
-
destBands
private int[] destBands
source and destination bands.
-
-
Method Detail
-
setInput
public void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
Overrides the method defined in the superclass.- Overrides:
setInput
in classjavax.imageio.ImageReader
-
getNumImages
public int getNumImages(boolean allowSearch) throws java.io.IOException
Overrides the method defined in the superclass.- Specified by:
getNumImages
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
getWidth
public int getWidth(int imageIndex) throws java.io.IOException
- Specified by:
getWidth
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
getHeight
public int getHeight(int imageIndex) throws java.io.IOException
- Specified by:
getHeight
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
checkIndex
private void checkIndex(int imageIndex)
-
readHeader
public void readHeader() throws java.io.IOException
- Throws:
java.io.IOException
-
getImageTypes
public java.util.Iterator getImageTypes(int imageIndex) throws java.io.IOException
- Specified by:
getImageTypes
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
getDefaultReadParam
public javax.imageio.ImageReadParam getDefaultReadParam()
- Overrides:
getDefaultReadParam
in classjavax.imageio.ImageReader
-
getImageMetadata
public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex) throws java.io.IOException
- Specified by:
getImageMetadata
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
getStreamMetadata
public javax.imageio.metadata.IIOMetadata getStreamMetadata() throws java.io.IOException
- Specified by:
getStreamMetadata
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
isRandomAccessEasy
public boolean isRandomAccessEasy(int imageIndex) throws java.io.IOException
- Overrides:
isRandomAccessEasy
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
read
public java.awt.image.BufferedImage read(int imageIndex, javax.imageio.ImageReadParam param) throws java.io.IOException
- Specified by:
read
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
canReadRaster
public boolean canReadRaster()
- Overrides:
canReadRaster
in classjavax.imageio.ImageReader
-
readRaster
public java.awt.image.Raster readRaster(int imageIndex, javax.imageio.ImageReadParam param) throws java.io.IOException
- Overrides:
readRaster
in classjavax.imageio.ImageReader
- Throws:
java.io.IOException
-
resetHeaderInfo
private void resetHeaderInfo()
-
reset
public void reset()
- Overrides:
reset
in classjavax.imageio.ImageReader
-
read1Bit
private void read1Bit(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
read4Bit
private void read4Bit(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
read8Bit
private void read8Bit(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
read24Bit
private void read24Bit(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
read16Bit
private void read16Bit(short[] sdata) throws java.io.IOException
- Throws:
java.io.IOException
-
read32Bit
private void read32Bit(int[] idata) throws java.io.IOException
- Throws:
java.io.IOException
-
readRLE8
private void readRLE8(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeRLE8
private void decodeRLE8(int imSize, int padding, byte[] values, byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
readRLE4
private void readRLE4(byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
decodeRLE4
private void decodeRLE4(int imSize, int padding, byte[] values, byte[] bdata) throws java.io.IOException
- Throws:
java.io.IOException
-
readEmbedded
private java.awt.image.BufferedImage readEmbedded(int type, java.awt.image.BufferedImage bi, javax.imageio.ImageReadParam bmpParam) throws java.io.IOException
Decodes the jpeg/png image embedded in the bitmap using any jpeg ImageIO-style plugin.- Parameters:
bi
- The destinationBufferedImage
.bmpParam
- TheImageReadParam
for decoding this BMP image. The parameters for subregion, band selection and subsampling are used in decoding the jpeg image.- Throws:
java.io.IOException
-
-