j2d.io.gif.stills
Class GifDecoder

java.lang.Object
  extended by j2d.io.gif.stills.GifDecoder

public class GifDecoder
extends java.lang.Object

Class GifDecoder - Decodes a GIF file into one or more frames.

 Example:
    GifDecoder d = new GifDecoder();
    d.read("sample.gif");
    int n = d.getFrameCount();
    for (int i = 0; i < n; i++) {
       BufferedImage frame = d.getFrame(i);  // frame i
       int t = d.getDelay(i);  // display duration of frame in milliseconds
       // do something with frame
    }
 
No copyright asserted on the source code of this class. May be used for any purpose, however, refer to the Unisys LZW patent for any additional restrictions. Please forward any corrections to kweiner@fmsware.com.

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
 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.
static void main(java.lang.String[] args)
           
 int read(java.io.BufferedInputStream is)
           
 int read(java.lang.String name)
          Reads GIF file from specified source (file or URL string)
 
Methods inherited from class java.lang.Object
equals, 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

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.

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)

main

public static void main(java.lang.String[] args)