|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--WriteGifEncoder
The WriteGifEncoder class writes out an Image object as a named GIF file. After creating the class, use writeFile() to actually write the file.
This module was taken from NIH ImageJ and was in turn derived from GifEncoder.java and MedianCut.java. It writes out an Image as a GIF file after convering 24-bit RGB to an 8-bit IndexColorModel. It was taken from a public domain version of Wayne Rasband's ImageJ source code available at http://rsb.info.nih.gov/nih-image/
Transparency handling and variable bit size courtesy of Jack Palevich. Copyright (C) 1996 by Jef PoskanzerThis code was then modified by P. Lemkin, G. Thornwall, NCI/FCRDC.. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Visit the ACME Labs Java page for up-to-date versions of this and other fine Java utilities at http://www.acme.com/java/
This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The MAExplorer Mozilla and Legal files are available on http://maexplorer.sourceforge.net/.
Field Summary | |
private int |
a_count
|
private byte[] |
accum
|
private byte[] |
b
|
private static int |
BITS
|
private boolean |
clear_flg
80% occupancy |
private int |
ClearCode
|
private int[] |
codetab
|
private int |
cur_accum
|
private int |
cur_bits
|
private static int |
EOF
|
private int |
EOFCode
|
private int |
free_ent
|
private byte[] |
g
|
private int |
g_init_bits
|
private int |
height
|
private int |
Height
|
private int |
hsize
|
private static int |
HSIZE
|
private int[] |
htab
|
private java.awt.Image |
img
Image if specified |
private boolean |
interlace
80% occupancy |
private boolean |
Interlace
80% occupancy |
private int[] |
masks
|
private int |
maxbits
|
private int |
maxcode
|
private int |
maxmaxcode
|
private int |
n_bits
|
private int |
numPixels
|
private boolean |
ok
80% occupancy |
private int |
pixelIndex
|
private byte[] |
pixels
|
private byte[] |
r
|
private int |
width
|
private int |
Width
|
Constructor Summary | |
WriteGifEncoder(java.awt.Image img)
WriteGifEncoder() - Constructs using 24-bit Image. |
|
WriteGifEncoder(int width,
int height,
byte[] pixels,
byte[] r,
byte[] g,
byte[] b)
WriteGifEncoder() - Constructs a new WriteGifEncoder. |
Method Summary | |
private void |
char_init()
char_init() - Set up the 'byte output' routine |
(package private) void |
char_out(byte c,
java.io.FileOutputStream outs)
char_out() - add char to end of current packet, and if it is 254 characters, flush the packet to disk. |
private void |
cl_block(java.io.FileOutputStream outs)
cl_block() - table clear for block compress Clear out the hash table. |
private void |
cl_hash(int hsize)
cl_hash() - reset code table |
private void |
compress(int init_bits,
java.io.FileOutputStream outs)
compress() - GIF Image compression - modified 'compress'. |
(package private) void |
flush_char(java.io.FileOutputStream outs)
flush_char() - flush packet to disk, and reset the accumulator |
private void |
GIFEncode(java.io.FileOutputStream outs,
int Width,
int Height,
boolean Interlace,
byte Background,
int Transparent,
int BitsPerPixel,
byte[] Red,
byte[] Green,
byte[] Blue)
GIFEncode() - encode the image Adapted from ppmtogif, which is based on GIFENCOD by David Rowley |
private int |
GIFNextPixel()
GIFNextPixel() - Return the next pixel from the image |
private int |
MAXCODE(int n_bits)
MAXCODE() - return n bits |
private void |
output(int code,
java.io.FileOutputStream outs)
output() - Output the given code. |
private void |
Putbyte(byte b,
java.io.FileOutputStream outs)
Putbyte() - Write out a byte to the GIF file |
private void |
Putword(int w,
java.io.FileOutputStream outs)
Putword() - Write out a word to the GIF file |
boolean |
writeFile(java.lang.String oGifFileName)
writeFile() - write the Gif encoded image to output file |
private void |
writeGif(java.io.FileOutputStream out)
writeGif() - Saves the image as a GIF file. |
private static void |
writeString(java.io.FileOutputStream out,
java.lang.String str)
writeString() - write string to the file. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static final int EOF
private static final int BITS
private static final int HSIZE
private boolean ok
private boolean interlace
private boolean Interlace
private boolean clear_flg
private int[] htab
private int[] codetab
private int a_count
private int hsize
private int free_ent
private int g_init_bits
private int ClearCode
private int EOFCode
private int width
private int height
private int Width
private int Height
private int pixelIndex
private int numPixels
private int n_bits
private int maxbits
private int maxcode
private int maxmaxcode
private int cur_accum
private int cur_bits
private java.awt.Image img
private int[] masks
private byte[] accum
private byte[] pixels
private byte[] r
private byte[] g
private byte[] b
Constructor Detail |
public WriteGifEncoder(int width, int height, byte[] pixels, byte[] r, byte[] g, byte[] b)
width
- The image width.height
- The image height.pixels
- The pixel data.r
- The red look-up table.g
- The green look-up table.b
- The blue look-up table.
[Not used in MAExplorer]public WriteGifEncoder(java.awt.Image img)
img
- is the RGB imageMethod Detail |
public boolean writeFile(java.lang.String oGifFileName)
oGifFileName
- is full path of file name to be writtenprivate void writeGif(java.io.FileOutputStream out) throws java.io.IOException
out
- is file output streamprivate static void writeString(java.io.FileOutputStream out, java.lang.String str) throws java.io.IOException
out
- is file output streamstr
- is string to writeprivate void GIFEncode(java.io.FileOutputStream outs, int Width, int Height, boolean Interlace, byte Background, int Transparent, int BitsPerPixel, byte[] Red, byte[] Green, byte[] Blue) throws java.io.IOException
outs
- is file output streamWidth
- of imageHeight
- of imageInterlace
- flagBackground
- valueTransparent
- flagBitsPerPixel
- bits per pixelRed
- is byte array of dataGreen
- byte array of dataBlue
- is byte array of dataprivate int GIFNextPixel() throws java.io.IOException
private void Putword(int w, java.io.FileOutputStream outs) throws java.io.IOException
private void Putbyte(byte b, java.io.FileOutputStream outs) throws java.io.IOException
private final int MAXCODE(int n_bits)
private void compress(int init_bits, java.io.FileOutputStream outs) throws java.io.IOException
private void output(int code, java.io.FileOutputStream outs) throws java.io.IOException
private void cl_block(java.io.FileOutputStream outs) throws java.io.IOException
private void cl_hash(int hsize)
private void char_init()
void char_out(byte c, java.io.FileOutputStream outs) throws java.io.IOException
void flush_char(java.io.FileOutputStream outs) throws java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |