Class GifSequenceReader
- java.lang.Object
-
- com.sksamuel.scrimage.nio.internal.GifSequenceReader
-
public class GifSequenceReader 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 }
-
-
Field Summary
Fields Modifier and Type Field Description protected int[]
act
protected int
bgColor
protected int
bgIndex
protected byte[]
block
protected int
blockSize
protected int
delay
protected int
dispose
protected int
frameCount
protected int
frameIndexWithLastDoNotDispose
protected java.util.List<com.sksamuel.scrimage.nio.internal.GifSequenceReader.GifFrame>
frames
protected int[]
gct
protected boolean
gctFlag
protected int
gctSize
protected int
height
protected int
ih
protected java.awt.image.BufferedImage
image
protected java.io.BufferedInputStream
in
protected boolean
interlace
protected int
iw
protected int
ix
protected int
iy
protected int
lastBgColor
protected java.awt.image.BufferedImage
lastImage
protected java.awt.Rectangle
lastRect
protected int[]
lct
protected boolean
lctFlag
protected int
lctSize
protected int
loopCount
protected static int
MaxStackSize
protected int
pixelAspect
protected byte[]
pixels
protected byte[]
pixelStack
protected short[]
prefix
protected int
status
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.protected byte[]
suffix
protected int
transIndex
protected boolean
transparency
protected int
width
-
Constructor Summary
Constructors Constructor Description GifSequenceReader()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]
bytes()
Gets gif image bytes.protected void
decodeImageData()
Decodes LZW image data into pixel array.protected boolean
err()
Returns true if an error was encountered during reading/decodingint
getDelay(int n)
Gets display duration for specified frame.DisposeMethod
getDisposeMethod(int n)
Gets dispose method 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.java.awt.Dimension
getFrameSize()
Gets image size.java.awt.image.BufferedImage
getImage()
Gets the first (or only) image read.int
getLoopCount()
Gets the "Netscape" iteration count, if any.protected void
init()
Initializes or re-initializes readerprotected int
read()
Reads a single byte from the input stream.int
read(java.io.BufferedInputStream is)
Reads GIF image from streamint
read(java.io.InputStream is)
Reads GIF image from streamint
read(java.lang.String name)
Reads GIF file from specified file/URL source (URL assumed if name contains ":/" or "file:")protected int
readBlock()
Reads next variable length block from input.protected int[]
readColorTable(int ncolors)
Reads color table as 256 RGB integer valuesprotected void
readContents()
Main file parser.protected void
readGraphicControlExt()
Reads Graphics Control Extension valuesprotected void
readHeader()
Reads GIF file header information.protected void
readImage()
Reads next frame imageprotected void
readLSD()
Reads Logical Screen Descriptorprotected void
readNetscapeExt()
Reads Netscape extenstion to obtain iteration countprotected int
readShort()
Reads next 16-bit value, LSB firstprotected 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.
-
-
-
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
-
in
protected java.io.BufferedInputStream in
-
status
protected int status
-
width
protected int width
-
height
protected int height
-
gctFlag
protected boolean gctFlag
-
gctSize
protected int gctSize
-
loopCount
protected int loopCount
-
gct
protected int[] gct
-
lct
protected int[] lct
-
act
protected int[] act
-
bgIndex
protected int bgIndex
-
bgColor
protected int bgColor
-
lastBgColor
protected int lastBgColor
-
pixelAspect
protected int pixelAspect
-
lctFlag
protected boolean lctFlag
-
interlace
protected boolean interlace
-
lctSize
protected int lctSize
-
ix
protected int ix
-
iy
protected int iy
-
iw
protected int iw
-
ih
protected int ih
-
lastRect
protected java.awt.Rectangle lastRect
-
image
protected java.awt.image.BufferedImage image
-
lastImage
protected java.awt.image.BufferedImage lastImage
-
block
protected byte[] block
-
blockSize
protected int blockSize
-
frameIndexWithLastDoNotDispose
protected int frameIndexWithLastDoNotDispose
-
dispose
protected int dispose
-
transparency
protected boolean transparency
-
delay
protected int delay
-
transIndex
protected int transIndex
-
MaxStackSize
protected static final int MaxStackSize
- See Also:
- Constant Field Values
-
prefix
protected short[] prefix
-
suffix
protected byte[] suffix
-
pixelStack
protected byte[] pixelStack
-
pixels
protected byte[] pixels
-
frames
protected java.util.List<com.sksamuel.scrimage.nio.internal.GifSequenceReader.GifFrame> frames
-
frameCount
protected int frameCount
-
-
Method Detail
-
getDelay
public int getDelay(int n)
Gets display duration for specified frame.- Parameters:
n
- int index of frame- Returns:
- delay in milliseconds
-
getDisposeMethod
public DisposeMethod getDisposeMethod(int n)
Gets dispose method for specified frame.- Parameters:
n
- int index of frame- Returns:
- DisposeMethod enum for given frame
-
getFrameCount
public int getFrameCount()
Gets the number of frames read from file.- Returns:
- frame count
-
getImage
public java.awt.image.BufferedImage getImage()
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.
-
setPixels
protected void setPixels()
Creates new frame image from current data (and previous frames as specified by their disposition codes).
-
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.
-
getFrameSize
public java.awt.Dimension getFrameSize()
Gets image size.- Returns:
- GIF image dimensions
-
bytes
public byte[] bytes() throws java.io.IOException
Gets gif image bytes.- Returns:
- GIF InputStream bytes
- Throws:
java.io.IOException
-
read
public int read(java.io.BufferedInputStream is)
Reads GIF image from stream- Parameters:
is
- BufferedInputStream containing GIF file.- Returns:
- read status code (0 = no errors)
-
read
public int read(java.io.InputStream is)
Reads GIF image from stream- Parameters:
is
- InputStream containing GIF file.- Returns:
- read status code (0 = no errors)
-
read
public int read(java.lang.String name)
Reads GIF file from specified file/URL source (URL assumed if name contains ":/" or "file:")- 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.
-
skip
protected void skip()
Skips variable length blocks up to and including next zero length block.
-
-