Class LZWEncoder

java.lang.Object
  extended by LZWEncoder

public class LZWEncoder
extends java.lang.Object

Adapted from Jef Poskanzer's Java port by way of J. M. G. Elliott.


Field Summary
(package private)  int a_count
          Number of characters so far in this 'packet'.
(package private)  byte[] accum
          Define the storage for the packet accumulator.
(package private) static int BITS
          DEFINE BITS AS 12.
(package private)  boolean clear_flg
          block compression parameters -- after all codes are used up, and compression rate changes, start over.
(package private)  int ClearCode
          Integer representing the clear code.
(package private)  int[] codetab
          Integer Array of size HSIZE.
(package private)  int cur_accum
          Integer representing the Current Accumulation.
(package private)  int cur_bits
          Integer representing the Current Bits.
 int curPixel
          Integer representing current pixel.
static int EOF
          Integer representing End Of File value.
(package private)  int EOFCode
          Integer representing the EOF code.
(package private)  int free_ent
          first unused entry.
(package private)  int g_init_bits
          Integer.
(package private)  int hsize
          for dynamic table sizing.
(package private) static int HSIZE
          DEFINE HSIZE AS 5003.
(package private)  int[] htab
          Integer Array of size HSIZE.
 int imgH
          Integer representing image Height.
 int imgW
          Integer representing image Width.
private  int initCodeSize
          Integer representing initial Code Size.
(package private)  int[] masks
          An array of hex masks.
(package private)  int maxbits
          user settable max # bits/code.
(package private)  int maxcode
          maximum code, given n_bits.
(package private)  int maxmaxcode
          should NEVER generate this code.
(package private)  int n_bits
          number of bits/code.
private  byte[] pixAry
          Byte array representing the pixel color values.
 int remaining
          Integer representing remaining pixels.
 
Constructor Summary
LZWEncoder(int width, int height, byte[] pixels, int color_depth)
          This is the constructor for the LZWEncoder class.
 
Method Summary
(package private)  void char_out(byte c, java.io.OutputStream outs)
          Add a character to the end of the current packet, and if it is 254 characters, flush the packet to disk.
(package private)  void cl_block(java.io.OutputStream outs)
          Clear out the hash table table clear for block compress.
(package private)  void cl_hash(int hsize)
          Reset code table.
(package private)  void compress(int init_bits, java.io.OutputStream outs)
          Compress code table.
(package private)  void encode(java.io.OutputStream os)
          This method does the encoding and sends to an output stream.
(package private)  void flush_char(java.io.OutputStream outs)
          Flush the packet to disk, and reset the accumulator.
(package private)  int MAXCODE(int n_bits)
          This method returns the Max Code given the number of bits.
 int nextPixel()
          Return the next pixel from the image.
(package private)  void output(int code, java.io.OutputStream outs)
          This method produces the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOF

public static final int EOF
Integer representing End Of File value.

See Also:
Constant Field Values

imgW

public int imgW
Integer representing image Width.


imgH

public int imgH
Integer representing image Height.


pixAry

private byte[] pixAry
Byte array representing the pixel color values.


initCodeSize

private int initCodeSize
Integer representing initial Code Size.


remaining

public int remaining
Integer representing remaining pixels.


curPixel

public int curPixel
Integer representing current pixel.


BITS

static final int BITS
DEFINE BITS AS 12.

See Also:
Constant Field Values

HSIZE

static final int HSIZE
DEFINE HSIZE AS 5003.

See Also:
Constant Field Values

n_bits

int n_bits
number of bits/code.


maxbits

int maxbits
user settable max # bits/code.


maxcode

int maxcode
maximum code, given n_bits.


maxmaxcode

int maxmaxcode
should NEVER generate this code.


htab

int[] htab
Integer Array of size HSIZE.


codetab

int[] codetab
Integer Array of size HSIZE.


hsize

int hsize
for dynamic table sizing.


free_ent

int free_ent
first unused entry.


clear_flg

boolean clear_flg
block compression parameters -- after all codes are used up, and compression rate changes, start over.


g_init_bits

int g_init_bits
Integer.


ClearCode

int ClearCode
Integer representing the clear code.


EOFCode

int EOFCode
Integer representing the EOF code.


cur_accum

int cur_accum
Integer representing the Current Accumulation.


cur_bits

int cur_bits
Integer representing the Current Bits.


masks

int[] masks
An array of hex masks.


a_count

int a_count
Number of characters so far in this 'packet'.


accum

byte[] accum
Define the storage for the packet accumulator.

Constructor Detail

LZWEncoder

LZWEncoder(int width,
           int height,
           byte[] pixels,
           int color_depth)
This is the constructor for the LZWEncoder class.

Parameters:
width - int representing width
height - int representing height
pixels - byte array representing the picture color codes
color_depth - int representing color depth
Method Detail

char_out

void char_out(byte c,
              java.io.OutputStream outs)
        throws java.io.IOException
Add a character to the end of the current packet, and if it is 254 characters, flush the packet to disk.

Parameters:
c - a single byte
outs - output stream
Throws:
java.io.IOException

cl_block

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

Parameters:
outs - OutputStream object
Throws:
java.io.IOException

cl_hash

void cl_hash(int hsize)
Reset code table.

Parameters:
hsize - an int representing the hash table size

compress

void compress(int init_bits,
              java.io.OutputStream outs)
        throws java.io.IOException
Compress code table.

Parameters:
outs - OutputStream object
init_bits - int representing the init bits
Throws:
java.io.IOException

encode

void encode(java.io.OutputStream os)
      throws java.io.IOException
This method does the encoding and sends to an output stream.

Parameters:
os - OutputStream object
Throws:
java.io.IOException

flush_char

void flush_char(java.io.OutputStream outs)
          throws java.io.IOException
Flush the packet to disk, and reset the accumulator.

Parameters:
outs - OutputStream object
Throws:
java.io.IOException

MAXCODE

final int MAXCODE(int n_bits)
This method returns the Max Code given the number of bits.

Parameters:
n_bits - integer representing the number of bits
Returns:
the maxcode as an integer

nextPixel

public int nextPixel()
Return the next pixel from the image.

Returns:
the next pixel from the image

output

void output(int code,
            java.io.OutputStream outs)
      throws java.io.IOException
This method produces the output.

Parameters:
code - an integer representing the code
outs - OutputStream object
Throws:
java.io.IOException