jwo.utils.gifutils
Class GIFInputStream

java.lang.Object
  extended byjava.io.InputStream
      extended byjava.io.FilterInputStream
          extended byjwo.utils.gifutils.BitInputStream
              extended byjwo.utils.gifutils.GIFInputStream

public class GIFInputStream
extends BitInputStream

GIFInputStream provides readXXX() methods useful for reading in the contents of a GIF file. Included are methods which handle LZW decompression of the image data.

Author:
Benjamin E. Norman. Very minor modifications, Jo Wood.

Field Summary
static int MAXIMUM_CODE_LENGTH
          the maximum code size in bits for GIF LZW decompression
protected  jwo.utils.gifutils.LZWStringTable stringTable
          the string table for LZW decompression
 
Fields inherited from class jwo.utils.gifutils.BitInputStream
cachedBits, numCachedBits
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
GIFInputStream(InputStream is)
           
 
Method Summary
 byte readByte()
          Read an 8 bit byte at the current bit boundary.
protected  short readCode(BitInputStream bis)
          Read a code from the given BitInputStream using the code size from the instance LZW string table.
 Color readColor()
          Reads 3 bytes and intereprets them as an RRGGBB hex color.
 byte[] readDataBlock()
          Read data sub-blocks from the underlying input stream until a block terminator (a single zero byte) is encountered.
 byte[] readDataSubBlock()
          Read a data sub-block from the underlying stream.
 byte[] readImageData(int length)
          Read the compressed data for a table-based image and return the decompressed raster data.
 int readWord()
          Reads an unsigned LSB-first 16 byte word from the underlying stream.
 
Methods inherited from class jwo.utils.gifutils.BitInputStream
read, readBit, readBits
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXIMUM_CODE_LENGTH

public static final int MAXIMUM_CODE_LENGTH
the maximum code size in bits for GIF LZW decompression

See Also:
Constant Field Values

stringTable

protected jwo.utils.gifutils.LZWStringTable stringTable
the string table for LZW decompression

Constructor Detail

GIFInputStream

public GIFInputStream(InputStream is)
Method Detail

readByte

public byte readByte()
              throws IOException
Read an 8 bit byte at the current bit boundary.

Throws:
EOFException - if 8 bits are not available.
IOException

readWord

public int readWord()
             throws IOException
Reads an unsigned LSB-first 16 byte word from the underlying stream.

Throws:
EOFException - if EOF is reached before 2 bytes are read
IOException

readColor

public Color readColor()
                throws IOException
Reads 3 bytes and intereprets them as an RRGGBB hex color.

Throws:
EOFException - if EOF is reached before 3 bytes are read
IOException

readDataSubBlock

public byte[] readDataSubBlock()
                        throws IOException
Read a data sub-block from the underlying stream. The first byte read is taken to be the sub-block's length and is not returned in the array.

Throws:
EOFException - if a complete block is not read before EOF
IOException

readDataBlock

public byte[] readDataBlock()
                     throws IOException
Read data sub-blocks from the underlying input stream until a block terminator (a single zero byte) is encountered. All bytes read except for the first byte of each sub-block are returned.

Throws:
IOException

readCode

protected short readCode(BitInputStream bis)
                  throws IOException
Read a code from the given BitInputStream using the code size from the instance LZW string table. Therefore, this should only be called after (usually by) readImageData(), which instantiates the string table.

Throws:
IOException

readImageData

public byte[] readImageData(int length)
                     throws IOException
Read the compressed data for a table-based image and return the decompressed raster data. Each byte in the return array will correspond to one pixel, regardless of image bit depth. The root code size is read as a single byte before the image data sub-blocks. The length of the uncompressed data is required so that the array may be created; this should be simply the image width times the image height.

Throws:
GIFFormatException - if EOF is reached prematurely or the LZW decoding fails
IOException


Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005