com.lowagie.text.pdf.codec
Class BmpImage

java.lang.Object
  extended by com.lowagie.text.pdf.codec.BmpImage

public class BmpImage
extends Object

Reads a BMP image. All types of BMP can be read.

It is based in the JAI codec.

Author:
Paulo Soares (psoares@consiste.pt)

Field Summary
private  int alphaMask
           
private static int BI_BITFIELDS
           
private static int BI_RGB
           
private static int BI_RLE4
           
private static int BI_RLE8
           
private  long bitmapFileSize
           
private  long bitmapOffset
           
private  int bitsPerPixel
           
private  int blueMask
           
private  long compression
           
private  int greenMask
           
(package private)  int height
           
private  long imageSize
           
private  int imageType
           
private  InputStream inputStream
           
private  boolean isBottomUp
           
private static int LCS_CALIBRATED_RGB
           
private static int LCS_CMYK
           
private static int LCS_sRGB
           
private  int numBands
           
private  byte[] palette
           
 HashMap properties
           
private  int redMask
           
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_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
           
(package private)  int width
           
private  long xPelsPerMeter
           
private  long yPelsPerMeter
           
 
Constructor Summary
BmpImage(InputStream is, boolean noHeader, int size)
           
 
Method Summary
private  byte[] decodeRLE(boolean is8, byte[] values)
           
private  int findMask(int mask)
           
private  int findShift(int mask)
           
private  Image getImage()
           
static Image getImage(byte[] data)
          Reads a BMP from a byte array.
static Image getImage(InputStream is)
          Reads a BMP from a stream.
static Image getImage(InputStream is, boolean noHeader, int size)
          Reads a BMP from a stream.
static Image getImage(String file)
          Reads a BMP from a file.
static Image getImage(URL url)
          Reads a BMP from an url.
private  byte[] getPalette(int group)
           
private  Image indexedModel(byte[] bdata, int bpc, int paletteEntries)
           
protected  void process(InputStream stream, boolean noHeader)
           
private  Image read1632Bit(boolean is32)
           
private  Image read1Bit(int paletteEntries)
           
private  void read24Bit(byte[] bdata)
           
private  Image read4Bit(int paletteEntries)
           
private  Image read8Bit(int paletteEntries)
           
private  long readDWord(InputStream stream)
           
private  int readInt(InputStream stream)
           
private  int readLong(InputStream stream)
           
private  void readPalette(int sizeOfPalette)
           
private  Image readRLE4()
           
private  Image readRLE8()
           
private  int readShort(InputStream stream)
           
private  int readUnsignedByte(InputStream stream)
           
private  long readUnsignedInt(InputStream stream)
           
private  int readUnsignedShort(InputStream stream)
           
private  int readWord(InputStream stream)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

inputStream

private InputStream inputStream

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

properties

public HashMap properties

xPelsPerMeter

private long xPelsPerMeter

yPelsPerMeter

private long yPelsPerMeter

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

LCS_CALIBRATED_RGB

private static final int LCS_CALIBRATED_RGB
See Also:
Constant Field Values

LCS_sRGB

private static final int LCS_sRGB
See Also:
Constant Field Values

LCS_CMYK

private static final int LCS_CMYK
See Also:
Constant Field Values

BI_RGB

private static final int BI_RGB
See Also:
Constant Field Values

BI_RLE8

private static final int BI_RLE8
See Also:
Constant Field Values

BI_RLE4

private static final int BI_RLE4
See Also:
Constant Field Values

BI_BITFIELDS

private static final int BI_BITFIELDS
See Also:
Constant Field Values

width

int width

height

int height
Constructor Detail

BmpImage

BmpImage(InputStream is,
         boolean noHeader,
         int size)
   throws IOException
Throws:
IOException
Method Detail

getImage

public static Image getImage(URL url)
                      throws IOException
Reads a BMP from an url.

Parameters:
url - the url
Returns:
the image
Throws:
IOException - on error

getImage

public static Image getImage(InputStream is)
                      throws IOException
Reads a BMP from a stream. The stream is not closed.

Parameters:
is - the stream
Returns:
the image
Throws:
IOException - on error

getImage

public static Image getImage(InputStream is,
                             boolean noHeader,
                             int size)
                      throws IOException
Reads a BMP from a stream. The stream is not closed. The BMP may not have a header and be considered as a plain DIB.

Parameters:
is - the stream
noHeader - true to process a plain DIB
size - the size of the DIB. Not used for a BMP
Returns:
the image
Throws:
IOException - on error

getImage

public static Image getImage(String file)
                      throws IOException
Reads a BMP from a file.

Parameters:
file - the file
Returns:
the image
Throws:
IOException - on error

getImage

public static Image getImage(byte[] data)
                      throws IOException
Reads a BMP from a byte array.

Parameters:
data - the byte array
Returns:
the image
Throws:
IOException - on error

process

protected void process(InputStream stream,
                       boolean noHeader)
                throws IOException
Throws:
IOException

getPalette

private byte[] getPalette(int group)

getImage

private Image getImage()
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

indexedModel

private Image indexedModel(byte[] bdata,
                           int bpc,
                           int paletteEntries)
                    throws BadElementException
Throws:
BadElementException

readPalette

private void readPalette(int sizeOfPalette)
                  throws IOException
Throws:
IOException

read1Bit

private Image read1Bit(int paletteEntries)
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

read4Bit

private Image read4Bit(int paletteEntries)
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

read8Bit

private Image read8Bit(int paletteEntries)
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

read24Bit

private void read24Bit(byte[] bdata)

findMask

private int findMask(int mask)

findShift

private int findShift(int mask)

read1632Bit

private Image read1632Bit(boolean is32)
                   throws IOException,
                          BadElementException
Throws:
IOException
BadElementException

readRLE8

private Image readRLE8()
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

readRLE4

private Image readRLE4()
                throws IOException,
                       BadElementException
Throws:
IOException
BadElementException

decodeRLE

private byte[] decodeRLE(boolean is8,
                         byte[] values)

readUnsignedByte

private int readUnsignedByte(InputStream stream)
                      throws IOException
Throws:
IOException

readUnsignedShort

private int readUnsignedShort(InputStream stream)
                       throws IOException
Throws:
IOException

readShort

private int readShort(InputStream stream)
               throws IOException
Throws:
IOException

readWord

private int readWord(InputStream stream)
              throws IOException
Throws:
IOException

readUnsignedInt

private long readUnsignedInt(InputStream stream)
                      throws IOException
Throws:
IOException

readInt

private int readInt(InputStream stream)
             throws IOException
Throws:
IOException

readDWord

private long readDWord(InputStream stream)
                throws IOException
Throws:
IOException

readLong

private int readLong(InputStream stream)
              throws IOException
Throws:
IOException

Hosted by Hostbasket