Class LZWStringTable


  • public class LZWStringTable
    extends java.lang.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
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static short HASH_FREE  
      private static short HASHSIZE  
      private static short HASHSTEP  
      private static int MAXBITS  
      private static int MAXSTR  
      private static short NEXT_FIRST  
      (package private) short numStrings_  
      private static int RES_CODES
      codesize + Reserved Codes
      (package private) byte[] strChr_  
      (package private) short[] strHsh_  
      (package private) int[] strLen_
      each entry corresponds to a code and contains the length of data that the code expands to when decoded.
      (package private) short[] strNxt_  
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int AddCharString​(short index, byte b)  
      void ClearTable​(int codesize)  
      void dump​(java.io.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
    • Field Detail

      • RES_CODES

        private static final int RES_CODES
        codesize + Reserved Codes
        See Also:
        Constant Field Values
      • 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 Detail

      • LZWStringTable

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

      • 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​(java.io.PrintStream out)