com.itextpdf.text.pdf.codec
Class LZWStringTable
java.lang.Object
com.itextpdf.text.pdf.codec.LZWStringTable
public class LZWStringTable
- extends Object
General purpose LZW String Table.
Extracted from GIFEncoder by Adam Doppelt
Comments added by Robin Luiten
expandCode
added by Robin Luiten
The strLen_ table to give quick access to the lenght of an expanded
code for use by the expandCode
method added by Robin.
- Since:
- 5.0.2
Constructor Summary |
LZWStringTable()
Constructor allocate memory for string store data |
Method Summary |
int |
AddCharString(short index,
byte b)
|
void |
ClearTable(int codesize)
|
void |
dump(PrintStream out)
|
int |
expandCode(byte[] buf,
int offset,
short code,
int skipHead)
If expanded data doesn't fit into array only what will fit is written
to buf and the return value indicates how much of the expanded code has
been written to the buf. |
short |
FindCharString(short index,
byte b)
|
static int |
Hash(short index,
byte lastbyte)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LZWStringTable
public LZWStringTable()
- Constructor allocate memory for string store data
AddCharString
public int AddCharString(short index,
byte b)
- Parameters:
index
- value of -1 indicates no predecessor [used in initialization]b
- the byte [character] to add to the string store which follows
the predecessor string specified the index.
- Returns:
- 0xFFFF if no space in table left for addition of predecessor
index and byte b. Else return the code allocated for combination index + b.
FindCharString
public short FindCharString(short index,
byte b)
- Parameters:
index
- index to prefix stringb
- the character that follws the index prefix
- Returns:
- b if param index is HASH_FREE. Else return the code
for this prefix and byte successor
ClearTable
public void ClearTable(int codesize)
- Parameters:
codesize
- the size of code to be preallocated for the
string store.
Hash
public static int Hash(short index,
byte lastbyte)
expandCode
public int expandCode(byte[] buf,
int offset,
short code,
int skipHead)
- If expanded data doesn't fit into array only what will fit is written
to buf and the return value indicates how much of the expanded code has
been written to the buf. The next call to expandCode() should be with
the same code and have the skip parameter set the negated value of the
previous return. Successive negative return values should be negated and
added together for next skip parameter value with same code.
- Parameters:
buf
- buffer to place expanded data intooffset
- offset to place expanded datacode
- the code to expand to the byte array it represents.
PRECONDITION This code must already be in the LZSSskipHead
- is the number of bytes at the start of the expanded code to
be skipped before data is written to buf. It is possible that skipHead is
equal to codeLen.
- Returns:
- the length of data expanded into buf. If the expanded code is longer
than space left in buf then the value returned is a negative number which when
negated is equal to the number of bytes that were used of the code being expanded.
This negative value also indicates the buffer is full.
dump
public void dump(PrintStream out)
Copyright © 2011. All Rights Reserved.