|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.gifutils.GIFImage
GIFImage represents an image as stored in a gif file. It can be used to load or save images from disk without using AWT components and can thus be run from a text console.
Before using this package, it may help to become familiar with the terminology used regarding gif images. Try looking at this page for more information. Alternatively, do a web search for "gif89a specification".
GIFImage is capable of reading all extensions and images in a gif89a file, but only the graphic control extension (used for transparency and time delay) is currently supported for image creation. Multiple images are available (as in an animated .gif). The term 'primary image' is taken to mean the first image in a file.
This package was originally built around GIFEncoder, by Adam Doppelt, which was in turn based on gifsave.c, by Sverre H. Huseby. None of the current incarnation bears much resemblance to these works, however.
GIFImage is currently very alpha-ish, and you may have to do some hacking if you want to take advantage of advanced features like time delays and looping. But it's free, so don't gripe too hard:) The ZIP file contains all the classes and source code. In all seriousness, if you find a bug, please let me know.
GIFInputStream gis = new GIFInputStream( new FileInputStream(myFileName) ); GIFImage gi = new GIFImage(gis); int[] rgbPixels = gi.getRGBPixels();
int[] rgbPixels = myPixelGenerationMethod(); // get pixels somehow GIFImage gi = new GIFImage(rgbPixels, imageWidth); GIFOutputStream gos = new GIFOutputStream( new FileOutputStream(args[0]) ); gi.write(gos);
GIFImage gi = new GIFImage(rgbPixels, imageWidth); gi.setTransparentColor(Color.grey);
GIFImage gi = new GIFImage(rgbPixels1, imageWidth); // first image (0) gi.addImage(rgbPixels2, imageWidth); // second image (1) gi.addImage(rgbPixels3, imageWidth); // third image (2) gi.setDelay(50); // delay in 100th sec - defaults to first image (0) gi.setDelay(1, 50); // second image gi.setDelay(2, 50); // third image gi.setIterationCount(0); // infinite loop gi.write(myOutputStream);
Nested Class Summary | |
class |
GIFImage.NetscapeExtension
Extension block for looping animations. |
Field Summary | |
static int |
APPLICATION
|
static int |
COMMENT
|
protected jwo.utils.gifutils.GIFImage.GraphicControlExtension |
currentGraphicControlExtension
|
static int |
EXTENSION_INTRODUCER
|
static int |
GIF87a
|
static int |
GIF89a
|
static int |
GRAPHIC_CONTROL
|
protected jwo.utils.gifutils.GIFImage.Header |
header
|
static int |
IMAGE_SEPARATOR
|
static int |
LEAVE_IN_PLACE
|
protected jwo.utils.gifutils.GIFImage.LogicalScreen |
logicalScreen
|
static String |
NETSCAPE2_0
|
protected GIFImage.NetscapeExtension |
netscapeExtension
|
static int |
NONE
|
static int |
PLAIN_TEXT
|
static int |
RESTORE_TO_BACKGROUND
|
static int |
RESTORE_TO_PREVIOUS
|
protected Vector |
tableBasedImages
|
static int |
TRAILER
|
Constructor Summary | |
GIFImage(GIFInputStream input)
Create a GIFImage from .gif image data on the given stream. |
|
GIFImage(int[] pixels,
int width)
As GIFImage(int[], int, boolean), using a global color table. |
|
GIFImage(int[] pixels,
int width,
boolean localColorTable)
Create a GIFImage containing one table-based image formed from the given array of integer RGB raster data and the image width. |
Method Summary | |
void |
addImage(int[] pixels,
int width)
Adds a new table-based image to this GIFImage (at the end of the list). |
void |
addImage(int[] pixels,
int width,
boolean localColorTable)
Adds a new table-based image to this GIFImage (at the end of the list). |
protected int |
bppForNumColors(int numColors)
Calculates the minimum BPP for the given number of colors. |
int |
countImages()
Return the number of table-based images present. |
protected int |
getBppForImage(jwo.utils.gifutils.GIFImage.TableBasedImage tbi)
Return the color depth (bits/pixel) of the given table-based image. |
protected jwo.utils.gifutils.GIFImage.ColorTable |
getColorTableForImage(jwo.utils.gifutils.GIFImage.TableBasedImage tbi)
Return the color table for the given table-based image. |
int |
getDelay()
Get the time delay for the primary image in 1/100 s |
int |
getDelay(int imageIndex)
Get the time delay for the image at the given index in 1/100 s |
int |
getHeight()
Get the pixel height of the primary image. |
int |
getHeight(int imageIndex)
Get the pixel height of the image at the given index. |
int |
getIterationCount()
Return the number of times the images in this GIFImage will iterate, or 0 if they repeat indefinitely. |
int[] |
getRGBPixels()
Return the RGB pixels of the primary image. |
int[] |
getRGBPixels(int imageIndex)
Return the RGB pixels of the image at the given index. |
Color |
getTransparentColor()
Get the RGB transparent color of the primary image. |
Color |
getTransparentColor(int imageIndex)
Get the RGB transparent color of the image at the given index. |
int |
getWidth()
Get the pixel width of the primary image. |
int |
getWidth(int imageIndex)
Get the pixel width of the image at the given index. |
boolean |
isImageInterlaced()
Return whether or not the primary image is interlaced. |
boolean |
isImageInterlaced(int imageIndex)
Return whether or not the image at the given index is interlaced. |
protected jwo.utils.gifutils.GIFImage.ColorTable |
makeIndexedColor(int[] rgbPixels,
byte[] indexedPixels,
boolean localColorTable)
Extract indexed color info from the given RGB pixels. |
void |
read(GIFInputStream input)
Replace the current contents of this GIFImage with data from a .gif file present on the given input stream. |
void |
setDelay(int delay)
Set the time delay for the primary image in 1/100 s |
void |
setDelay(int imageIndex,
int delay)
Set the time delay for the image at the given index in 1/100 s |
void |
setImageInterlaced(boolean interlaced)
Set the primary image as interlaced or not. |
void |
setImageInterlaced(int imageIndex,
boolean interlaced)
Set or clear the interlaced state for the image at the given index. |
void |
setIterationCount(int iterationCount)
Make the series of images in this file iterate the given number of times, or indefinitely if 0 is given. |
void |
setTransparentColor(Color trans)
Set the RGB transparent color of the primary image. |
void |
setTransparentColor(int imageIndex,
Color trans)
Get the RGB transparent color of the image at the given index. |
String |
toString()
Print the string representation of the gif file - includes all image data including actual pixels. |
void |
write(GIFOutputStream output)
Write this GIFImage as a .gif file to the given stream. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static final int GIF87a
public static final int GIF89a
public static final int IMAGE_SEPARATOR
public static final int EXTENSION_INTRODUCER
public static final int TRAILER
public static final int PLAIN_TEXT
public static final int APPLICATION
public static final int COMMENT
public static final int GRAPHIC_CONTROL
public static final String NETSCAPE2_0
public static final int NONE
public static final int LEAVE_IN_PLACE
public static final int RESTORE_TO_BACKGROUND
public static final int RESTORE_TO_PREVIOUS
protected jwo.utils.gifutils.GIFImage.Header header
protected jwo.utils.gifutils.GIFImage.LogicalScreen logicalScreen
protected GIFImage.NetscapeExtension netscapeExtension
protected Vector tableBasedImages
protected jwo.utils.gifutils.GIFImage.GraphicControlExtension currentGraphicControlExtension
Constructor Detail |
public GIFImage(int[] pixels, int width) throws GIFFormatException
public GIFImage(int[] pixels, int width, boolean localColorTable) throws GIFFormatException
GIFFormatException
- if more than 256 colors are encounteredpublic GIFImage(GIFInputStream input) throws IOException
Method Detail |
public void addImage(int[] pixels, int width) throws GIFFormatException
GIFFormatException
- if more than 256 colors are encounteredpublic void addImage(int[] pixels, int width, boolean localColorTable) throws GIFFormatException
GIFFormatException
- if more than 256 colors are encounteredpublic int[] getRGBPixels()
public int[] getRGBPixels(int imageIndex)
public void write(GIFOutputStream output) throws IOException
IOException
public void read(GIFInputStream input) throws IOException
IOException
public String toString()
public int countImages()
public boolean isImageInterlaced()
public boolean isImageInterlaced(int imageIndex)
public void setImageInterlaced(boolean interlaced)
public void setImageInterlaced(int imageIndex, boolean interlaced)
public Color getTransparentColor()
public Color getTransparentColor(int imageIndex)
public void setTransparentColor(Color trans)
public void setTransparentColor(int imageIndex, Color trans)
public int getWidth(int imageIndex)
public int getWidth()
public int getHeight(int imageIndex)
public int getHeight()
public int getDelay()
public int getDelay(int imageIndex)
public void setDelay(int delay)
public void setDelay(int imageIndex, int delay)
public void setIterationCount(int iterationCount)
public int getIterationCount()
protected int getBppForImage(jwo.utils.gifutils.GIFImage.TableBasedImage tbi)
protected jwo.utils.gifutils.GIFImage.ColorTable getColorTableForImage(jwo.utils.gifutils.GIFImage.TableBasedImage tbi)
protected int bppForNumColors(int numColors)
protected jwo.utils.gifutils.GIFImage.ColorTable makeIndexedColor(int[] rgbPixels, byte[] indexedPixels, boolean localColorTable) throws GIFFormatException
GIFFormatException
- if more than 256 colors are found
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |