Class LZWStringTable

java.lang.Object
com.itextpdf.io.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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor allocate memory for string store data
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    AddCharString(short index, byte b)
     
    void
    ClearTable(int codesize)
     
    void
    dump(PrintStream output)
     
    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
  • Constructor Details

    • LZWStringTable

      public LZWStringTable()
      Constructor allocate memory for string store data
  • Method Details

    • 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 string
      b - 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 into
      offset - offset to place expanded data
      code - the code to expand to the byte array it represents. PRECONDITION This code must already be in the LZSS
      skipHead - 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 output)