Class 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 provided ImageReadParam. This class supports Microsoft Windows Bitmap Version 3-5, as well as OS/2 Bitmap Version 2.x (for single-image BMP file).
    • Constructor Summary

      Constructors 
      Constructor Description
      BMPImageReader​(javax.imageio.spi.ImageReaderSpi originator)
      Constructs BMPImageReader from the provided ImageReaderSpi.
    • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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.
    • Constructor Detail

      • BMPImageReader

        public BMPImageReader​(javax.imageio.spi.ImageReaderSpi originator)
        Constructs BMPImageReader from the provided ImageReaderSpi.
    • Method Detail

      • setInput

        public void setInput​(java.lang.Object input,
                             boolean seekForwardOnly,
                             boolean ignoreMetadata)
        Overrides the method defined in the superclass.
        Overrides:
        setInput in class javax.imageio.ImageReader
      • getNumImages

        public int getNumImages​(boolean allowSearch)
                         throws java.io.IOException
        Overrides the method defined in the superclass.
        Specified by:
        getNumImages in class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • getWidth

        public int getWidth​(int imageIndex)
                     throws java.io.IOException
        Specified by:
        getWidth in class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • getHeight

        public int getHeight​(int imageIndex)
                      throws java.io.IOException
        Specified by:
        getHeight in class javax.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 class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • getDefaultReadParam

        public javax.imageio.ImageReadParam getDefaultReadParam()
        Overrides:
        getDefaultReadParam in class javax.imageio.ImageReader
      • getImageMetadata

        public javax.imageio.metadata.IIOMetadata getImageMetadata​(int imageIndex)
                                                            throws java.io.IOException
        Specified by:
        getImageMetadata in class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • getStreamMetadata

        public javax.imageio.metadata.IIOMetadata getStreamMetadata()
                                                             throws java.io.IOException
        Specified by:
        getStreamMetadata in class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • isRandomAccessEasy

        public boolean isRandomAccessEasy​(int imageIndex)
                                   throws java.io.IOException
        Overrides:
        isRandomAccessEasy in class javax.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 class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • canReadRaster

        public boolean canReadRaster()
        Overrides:
        canReadRaster in class javax.imageio.ImageReader
      • readRaster

        public java.awt.image.Raster readRaster​(int imageIndex,
                                                javax.imageio.ImageReadParam param)
                                         throws java.io.IOException
        Overrides:
        readRaster in class javax.imageio.ImageReader
        Throws:
        java.io.IOException
      • resetHeaderInfo

        private void resetHeaderInfo()
      • reset

        public void reset()
        Overrides:
        reset in class javax.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 destination BufferedImage.
        bmpParam - The ImageReadParam for decoding this BMP image. The parameters for subregion, band selection and subsampling are used in decoding the jpeg image.
        Throws:
        java.io.IOException