Class LZWStringTable

java.lang.Object
com.github.jaiimageio.impl.common.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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final short
     
    private static final short
     
    private static final short
     
    private static final int
     
    private static final int
     
    private static final short
     
    (package private) short
     
    private static final int
    codesize + Reserved Codes
    (package private) byte[]
     
    (package private) short[]
     
    (package private) int[]
    each entry corresponds to a code and contains the length of data that the code expands to when decoded.
    (package private) short[]
     
  • 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
     
    int
    expandCode(byte[] buf, int offset, short code, int skipHead)
    If expanded data doesnt 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
  • Field Details

    • RES_CODES

      private static final int RES_CODES
      codesize + Reserved Codes
      See Also:
    • HASH_FREE

      private static final short HASH_FREE
      See Also:
    • NEXT_FIRST

      private static final short NEXT_FIRST
      See Also:
    • MAXBITS

      private static final int MAXBITS
      See Also:
    • MAXSTR

      private static final int MAXSTR
      See Also:
    • HASHSIZE

      private static final short HASHSIZE
      See Also:
    • HASHSTEP

      private static final short HASHSTEP
      See Also:
    • strChr_

      byte[] strChr_
    • strNxt_

      short[] strNxt_
    • strHsh_

      short[] strHsh_
    • numStrings_

      short numStrings_
    • strLen_

      int[] strLen_
      each entry corresponds to a code and contains the length of data that the code expands to when decoded.
  • 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 initialisation]
      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 predecesor 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 doesnt 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. Succesive 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 allready 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 out)