com.alee.graphics.image.gif
Class GifDecoder

java.lang.Object
  extended by com.alee.graphics.image.gif.GifDecoder

public class GifDecoder
extends java.lang.Object

Version:
1.01 July 2001
Author:
Kevin Weiner, FM Software; LZW decoder adapted from John Cristy's ImageMagick.

Nested Class Summary
static class GifDecoder.GifFrame
           
 
Field Summary
static int STATUS_FORMAT_ERROR
          File read status: Error decoding file (may be partially decoded)
static int STATUS_OK
          File read status: No errors.
static int STATUS_OPEN_ERROR
          File read status: Unable to open source.
 
Constructor Summary
GifDecoder()
           
 
Method Summary
protected  void decodeImageData()
          Decodes LZW image data into pixel array.
protected  boolean err()
          Returns true if an error was encountered during reading/decoding
 java.awt.image.BufferedImage getCurrentBufImg()
          Gets the first (or only) image read.
 int getDelay(int n)
          Gets display duration for specified frame.
 java.awt.image.BufferedImage getFrame(int n)
          Gets the image contents of frame n.
 int getFrameCount()
          Gets the number of frames read from file.
 int getLoopCount()
          Gets the "Netscape" iteration count, if any.
 int getPixelAspect()
           
 int getStatus()
          Additional getters
protected  void init()
          Initializes or re-initializes reader
protected  int read()
          Reads a single byte from the input stream.
 int read(java.io.BufferedInputStream is)
           
 int read(java.lang.String name)
          Reads GIF file from specified source (file or URL string)
protected  int readBlock()
          Reads next variable length block from input.
protected  int[] readColorTable(int ncolors)
          Reads color table as 256 RGB integer values
protected  void readContents()
          Main file parser.
protected  void readGraphicControlExt()
          Reads Graphics Control Extension values
protected  void readHeader()
          Reads GIF file header information.
protected  void readImage()
          Reads next frame image
protected  void readLSD()
          Reads Logical Screen Descriptor
protected  void readNetscapeExt()
          Reads Netscape extenstion to obtain iteration count
protected  int readShort()
          Reads next 16-bit value, LSB first
protected  void resetFrame()
          Resets frame state for reading next image.
protected  void setPixels()
          Creates new frame image from current data (and previous frames as specified by their disposition codes).
protected  void skip()
          Skips variable length blocks up to and including next zero length block.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_OK

public static final int STATUS_OK
File read status: No errors.

See Also:
Constant Field Values

STATUS_FORMAT_ERROR

public static final int STATUS_FORMAT_ERROR
File read status: Error decoding file (may be partially decoded)

See Also:
Constant Field Values

STATUS_OPEN_ERROR

public static final int STATUS_OPEN_ERROR
File read status: Unable to open source.

See Also:
Constant Field Values
Constructor Detail

GifDecoder

public GifDecoder()
Method Detail

getPixelAspect

public int getPixelAspect()

getDelay

public int getDelay(int n)
Gets display duration for specified frame.

Parameters:
n - int index of frame
Returns:
delay in milliseconds

getFrame

public java.awt.image.BufferedImage getFrame(int n)
Gets the image contents of frame n. f

Returns:
BufferedImage representation of frame, or null if n is invalid.

getFrameCount

public int getFrameCount()
Gets the number of frames read from file.

Returns:
frame count

getCurrentBufImg

public java.awt.image.BufferedImage getCurrentBufImg()
Gets the first (or only) image read.

Returns:
BufferedImage containing first frame, or null if none.

getLoopCount

public int getLoopCount()
Gets the "Netscape" iteration count, if any. A count of 0 means repeat indefinitiely.

Returns:
iteration count if one was specified, else 1.

read

public int read(java.io.BufferedInputStream is)
Parameters:
is - An inputStream with gif animation
Returns:
status code (0=no error)

read

public int read(java.lang.String name)
Reads GIF file from specified source (file or URL string)

Parameters:
name - String containing source
Returns:
read status code (0 = no errors)

decodeImageData

protected void decodeImageData()
Decodes LZW image data into pixel array. Adapted from John Cristy's ImageMagick.


err

protected boolean err()
Returns true if an error was encountered during reading/decoding


init

protected void init()
Initializes or re-initializes reader


read

protected int read()
Reads a single byte from the input stream.


readBlock

protected int readBlock()
Reads next variable length block from input.

Returns:
number of bytes stored in "buffer"

readColorTable

protected int[] readColorTable(int ncolors)
Reads color table as 256 RGB integer values

Parameters:
ncolors - int number of colors to read
Returns:
int array containing 256 colors (packed ARGB with full alpha)

readContents

protected void readContents()
Main file parser. Reads GIF content blocks.


readGraphicControlExt

protected void readGraphicControlExt()
Reads Graphics Control Extension values


readHeader

protected void readHeader()
Reads GIF file header information.


readImage

protected void readImage()
Reads next frame image


readLSD

protected void readLSD()
Reads Logical Screen Descriptor


readNetscapeExt

protected void readNetscapeExt()
Reads Netscape extenstion to obtain iteration count


readShort

protected int readShort()
Reads next 16-bit value, LSB first


resetFrame

protected void resetFrame()
Resets frame state for reading next image.


setPixels

protected void setPixels()
Creates new frame image from current data (and previous frames as specified by their disposition codes).


skip

protected void skip()
Skips variable length blocks up to and including next zero length block.


getStatus

public int getStatus()
Additional getters