public class LZWTreeEncoder extends java.lang.Object implements ImageEncoder
Constructor and Description |
---|
LZWTreeEncoder(java.io.OutputStream os,
int codesize,
int buf_length) |
LZWTreeEncoder(java.io.OutputStream os,
int codesize,
int buf_length,
Updatable<java.lang.Integer> writer)
There are some subtle differences between the LZW algorithm used by TIFF and GIF images.
|
Modifier and Type | Method and Description |
---|---|
void |
encode(byte[] pixels,
int start,
int len)
LZW encode the pixel byte array.
|
void |
finish()
Finish up the compression.
|
int |
getCompressedDataLen()
This method is only intended to be called after calling finish()
|
void |
initialize() |
public LZWTreeEncoder(java.io.OutputStream os, int codesize, int buf_length)
public LZWTreeEncoder(java.io.OutputStream os, int codesize, int buf_length, Updatable<java.lang.Integer> writer)
TIFF and GIF each switch to the next code size using slightly different algorithms. GIF increments the code size as soon as the LZW string table's length is equal to 2**code_size, while TIFF increments the code size when the table's length is equal to 2**code_size - 1.
Packing Bits into Bytes TIFF and GIF LZW algorithms differ in how they pack the code bits into the byte stream. The least significant bit in a TIFF code is stored in the most significant bit of the byte stream, while the least significant bit in a GIF code is stored in the least significant bit of the byte stream.
Special Codes TIFF and GIF both add the concept of a 'Clear Code' and a 'End of Information Code' to the LZW algorithm. In both cases, the 'Clear Code' is equal to 2**(code_size - 1) and the 'End of Information Code' is equal to the Clear Code + 1. These 2 codes are reserved in the string table. So in both cases, the LZW string table is initialized to have a length equal to the End of Information Code + 1.
public void encode(byte[] pixels, int start, int len) throws java.lang.Exception
encode
in interface ImageEncoder
pixels
- pixel array to be encodedstart
- offset to the pixel array to start encodinglen
- number of bytes to be encodedjava.lang.Exception
public void finish() throws java.lang.Exception
finish
in interface ImageEncoder
java.lang.Exception
public int getCompressedDataLen()
getCompressedDataLen
in interface ImageEncoder
public void initialize() throws java.lang.Exception
initialize
in interface ImageEncoder
java.lang.Exception