jwo.utils.gifutils
Class GIFOutputStream

java.lang.Object
  extended byjava.io.OutputStream
      extended byjava.io.FilterOutputStream
          extended byjwo.utils.gifutils.BitOutputStream
              extended byjwo.utils.gifutils.GIFOutputStream

public class GIFOutputStream
extends BitOutputStream

GIFOutputStream provides writeXXX() methods useful for writing out a bitmap image to a GIF file. Included are methods which handle LZW compression 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 compression
protected  jwo.utils.gifutils.LZWStringTable stringTable
          the string table for LZW compression
 
Fields inherited from class jwo.utils.gifutils.BitOutputStream
cachedBits, numCachedBits
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
GIFOutputStream(OutputStream os)
           
 
Method Summary
protected  void writeCode(short code, BitOutputStream bos)
          Write a code to the given BitOutputStream using the current bit length from the string table.
 void writeColor(Color color)
          Writes a color as 3 bytes in RRGGBB hex format.
 void writeDataBlock(byte[] block)
          Write the given bytes to the underlying output stream as a series of data sub-blocks.
 void writeDataSubBlock(byte[] subBlock)
          Write a data sub-block from the underlying stream.
 void writeImageData(byte[] pixels, int bpp)
          LZW compresses the given pixel data and writes it to the underlying output stream as a data block.
 void writeWord(int word)
          Writes an unsigned LSB-first 16 byte word to the underlying stream.
 
Methods inherited from class jwo.utils.gifutils.BitOutputStream
flush, write, writeBit, writeBits
 
Methods inherited from class java.io.FilterOutputStream
close, write, write
 
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 compression

See Also:
Constant Field Values

stringTable

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

Constructor Detail

GIFOutputStream

public GIFOutputStream(OutputStream os)
Method Detail

writeWord

public void writeWord(int word)
               throws IOException
Writes an unsigned LSB-first 16 byte word to the underlying stream.

Throws:
IOException

writeColor

public void writeColor(Color color)
                throws IOException
Writes a color as 3 bytes in RRGGBB hex format.

Throws:
IOException

writeDataSubBlock

public void writeDataSubBlock(byte[] subBlock)
                       throws IOException
Write a data sub-block from the underlying stream. Before the given bytes, the length of the block (0-255) is written.

Throws:
IOException

writeDataBlock

public void writeDataBlock(byte[] block)
                    throws IOException
Write the given bytes to the underlying output stream as a series of data sub-blocks. As many sub-blocks of size 255 as possible will be written, then one smaller block as necessary. A final sub-block of a single zero byte is written to terminate the block.

Throws:
IOException

writeCode

protected void writeCode(short code,
                         BitOutputStream bos)
                  throws IOException
Write a code to the given BitOutputStream using the current bit length from the string table. (The string table is instantiated by the writeImageData() method, so this should not be called directly.)

Throws:
IOException

writeImageData

public void writeImageData(byte[] pixels,
                           int bpp)
                    throws IOException
LZW compresses the given pixel data and writes it to the underlying output stream as a data block. Before the data is written, the root code size is output. This code size is just the given color depth of the image, or 2 if the depth is one.

Throws:
IOException


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