Class sbk.image.GifImageEncoder
All Packages Class Hierarchy This Package Previous Next Index
Class sbk.image.GifImageEncoder
java.lang.Object
|
+----sbk.image.GifImageEncoder
- public class GifImageEncoder
- extends Object
GifImageEncoder is a class which saves an image to a stream
using the GIF file format. However, it doesn't use the
patented standard LZW algorithm for compression. Instead it uses
run length compression (RLE) with an LZW like coding.
The object is constructed with either an Image
(which
must be fully loaded) or an array of int
.
The next thing to do is creating the palette and the indexes into it
with a call to indexColors
.
Given an OutputStream
the image can now be compressed
by calling encodeTo
.
Using the command line one may convert an image file readable for
javaTM (GIF, JPEG or XBM) with 256 or less colors to a
RLE compressed GIF file.
The syntax for doing this:
java sbk.image.GifImageEncoder infile outfile
(assuming java is in your search path)
Disadvantages
- The compression ratio is not as good as LZW, especially with
the given sort of coding. Usually GifImageEncoder's files are larger,
but in rare cases even smaller.
- This first release supports only noninterlaced, nontransparent
GIF87a.
Advantages
- The generated files seem to be fully compatible with todays
image processing tools.
- Compression using RLE is usually faster than using LZW.
- Overall compression (using eg. zip archives or modems) is often
better because of the repeated code sequences.
- RLE should be a free compression algorithm, at least I don't know
any case where someone pays for using it.
History
- 17 Feb 1997
- Enhanced coding => better compression ratio
- 9 Feb 1997
- Initial Release
- Version:
- 9 Feb 1997
- Author:
- Thomas Wendt @ SBK Software + Systeme GmbH
Constructor Index
- o
GifImageEncoder(Image)
- Constructs the encoder using an image.
- o
GifImageEncoder(int[], int, int)
- Constructs the encoder using an array of pixels (top-down, left-right order).
Method Index
- o
encodeTo(OutputStream)
- Writes the image out to a stream in GIF87a format (non interlaced,
no transparency).
- o
indexColors()
- Converts the RGB-values to indexes into a palette.
- o
main(String[])
- The method of the class which can be called from the command line.
Constructors
o
GifImageEncoder
public GifImageEncoder(Image i) throws Exception
- Constructs the encoder using an image.
- Parameters:
- i - The image to be encoded.
- Throws: Exception
- Will be thrown if the pixels can't be grabbed (possibly because of low memory).
o
GifImageEncoder
public GifImageEncoder(int p[],
int w,
int h)
- Constructs the encoder using an array of pixels (top-down, left-right order).
- Parameters:
- p - The pixels to be encoded.
- w - The width of the image.
- h - The height of the image.
Methods
o
indexColors
public final void indexColors() throws Exception
- Converts the RGB-values to indexes into a palette.
- Throws: Exception
- Will be thrown if there are more than 256 colors.
o
encodeTo
public final void encodeTo(OutputStream o) throws IOException
- Writes the image out to a stream in GIF87a format (non interlaced,
no transparency).
- Parameters:
- o - The stream to output to, eg. a FileOutputStream. Is buffered internally.
- Throws: IOException
- Might be thrown from write operations.
o
main
public final static void main(String args[])
- The method of the class which can be called from the command line.
Converts an image file readable for javaTM (gif, jpeg or xbm)
with 256 or less colors to rle compressed gif.
- Parameters:
- args - The inputfile as first element and the outputfile as the second one.
All Packages Class Hierarchy This Package Previous Next Index