O2Plib.image
Class WriteGifEncoder

java.lang.Object
  extended by O2Plib.image.WriteGifEncoder

public class WriteGifEncoder
extends java.lang.Object


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 hsize
           
private static int HSIZE
           
private  int[] htab
           
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
           
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

private static final int EOF
See Also:
Constant Field Values

BITS

private static final int BITS
See Also:
Constant Field Values

HSIZE

private static final int HSIZE
See Also:
Constant Field Values

ok

private boolean ok
80% occupancy


interlace

private boolean interlace
80% occupancy


clear_flg

private boolean clear_flg
80% occupancy


htab

private int[] htab

codetab

private int[] codetab

a_count

private int a_count

hsize

private int hsize

free_ent

private int free_ent

g_init_bits

private int g_init_bits

ClearCode

private int ClearCode

EOFCode

private int EOFCode

width

private int width

height

private int height

pixelIndex

private int pixelIndex

numPixels

private int numPixels

n_bits

private int n_bits

maxbits

private int maxbits

maxcode

private int maxcode

maxmaxcode

private int maxmaxcode

cur_accum

private int cur_accum

cur_bits

private int cur_bits

masks

private int[] masks

accum

private byte[] accum

pixels

private byte[] pixels

r

private byte[] r

g

private byte[] g

b

private byte[] b
Constructor Detail

WriteGifEncoder

public WriteGifEncoder(int width,
                       int height,
                       byte[] pixels,
                       byte[] r,
                       byte[] g,
                       byte[] b)
WriteGifEncoder() - Constructs a new WriteGifEncoder. After creating the class, use writeFile() to actually write the file.

Parameters:
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]

WriteGifEncoder

public WriteGifEncoder(java.awt.Image img)
WriteGifEncoder() - Constructs using 24-bit Image. After creating the class, use writeFile() to actually write the file. The image is assumed to be fully loaded. It converts the 24-bit image into an 8-bit image with (r,g,b)LUT[] data using the MedianCut algorithm.

Parameters:
img - is the RGB image
Method Detail

writeFile

public boolean writeFile(java.lang.String oGifFileName)
writeFile() - write the Gif encoded image to output file

Parameters:
oGifFileName - is full path of file name to be written
Returns:
true if succeed

writeGif

private void writeGif(java.io.FileOutputStream out)
               throws java.io.IOException
writeGif() - Saves the image as a GIF file.

Parameters:
out - is file output stream
Throws:
java.io.IOException

writeString

private static void writeString(java.io.FileOutputStream out,
                                java.lang.String str)
                         throws java.io.IOException
writeString() - write string to the file.

Parameters:
out - is file output stream
str - is string to write
Throws:
java.io.IOException

GIFEncode

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)
                throws java.io.IOException
GIFEncode() - encode the image Adapted from ppmtogif, which is based on GIFENCOD by David Rowley . Lempel-Zim compression based on "compress".

Parameters:
outs - is file output stream
Width - of image
Height - of image
Interlace - flag
Background - value
Transparent - flag
BitsPerPixel - bits per pixel
Red - is byte array of data
Green - byte array of data
Blue - is byte array of data
Throws:
java.io.IOException

GIFNextPixel

private int GIFNextPixel()
                  throws java.io.IOException
GIFNextPixel() - Return the next pixel from the image

Throws:
java.io.IOException

Putword

private void Putword(int w,
                     java.io.FileOutputStream outs)
              throws java.io.IOException
Putword() - Write out a word to the GIF file

Throws:
java.io.IOException

Putbyte

private void Putbyte(byte b,
                     java.io.FileOutputStream outs)
              throws java.io.IOException
Putbyte() - Write out a byte to the GIF file

Throws:
java.io.IOException

MAXCODE

private final int MAXCODE(int n_bits)
MAXCODE() - return n bits


compress

private void compress(int init_bits,
                      java.io.FileOutputStream outs)
               throws java.io.IOException
compress() - GIF Image compression - modified 'compress'. Original code from GIFCOMPR.C GIF Image compression routines. * Lempel-Ziv compression based on 'compress'. GIF modifications by David Rowley (mgardi@watdcsu.waterloo.edu) This GIF Image compression - modified 'compress' was based on: compress.c - File compression ala IEEE Computer, June 1984. By Authors: Spencer W. Thomas (decvax!harpo!utah-cs!utah-gr!thomas) Jim McKie (decvax!mcvax!jim) Steve Davies (decvax!vax135!petsd!peora!srd) Ken Turkowski (decvax!decwrl!turtlevax!ken) James A. Woods (decvax!ihnp4!ames!jaw) Joe Orost (decvax!vax135!petsd!joe) Algorithm: use open addressing double hashing (no chaining) on the prefix code / next character combination. We do a variant of Knuth's algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime secondary probe. Here, the modular division first probe is gives way to a faster exclusive-or manipulation. Also do block compression with an adaptive reset, whereby the code table is cleared when the compression ratio decreases, but after the table fills. The variable-length output codes are re-sized at this point, and a special CLEAR code is generated for the decompressor. Late addition: construct the table according to file size for noticeable speed improvement on small files. Please direct questions about THE OLD implementation to ames!jaw. Block compression parameters -- after all codes are used up, and compression rate changes, start over.

Throws:
java.io.IOException

output

private void output(int code,
                    java.io.FileOutputStream outs)
             throws java.io.IOException
output() - Output the given code. Inputs: code: A n_bits-bit integer. If == -1, then EOF. This assumes that n_bits =< wordsize - 1. Outputs: Outputs code to the file. Assumptions: Chars are 8 bits long. Algorithm: Maintain a BITS character long buffer (so that 8 codes will fit in it exactly). Use the VAX insv instruction to insert each code in turn. When the buffer fills up empty it and start over.

Throws:
java.io.IOException

cl_block

private void cl_block(java.io.FileOutputStream outs)
               throws java.io.IOException
cl_block() - table clear for block compress Clear out the hash table.

Throws:
java.io.IOException

cl_hash

private void cl_hash(int hsize)
cl_hash() - reset code table


char_init

private void char_init()
char_init() - Set up the 'byte output' routine


char_out

void char_out(byte c,
              java.io.FileOutputStream outs)
        throws java.io.IOException
char_out() - add char to end of current packet, and if it is 254 characters, flush the packet to disk.

Throws:
java.io.IOException

flush_char

void flush_char(java.io.FileOutputStream outs)
          throws java.io.IOException
flush_char() - flush packet to disk, and reset the accumulator

Throws:
java.io.IOException