Class LZWEncoder

java.lang.Object
com.twelvemonkeys.imageio.plugins.tiff.LZWEncoder
All Implemented Interfaces:
Encoder

final class LZWEncoder extends Object implements Encoder
LZWEncoder

Inspired by LZWTreeEncoder by Wen Yu and the algorithm described by Bob Montgomery which "[...] uses a tree method to search if a new string is already in the table, which is much simpler, faster, and easier to understand than hashing."

Version:
$Id: LZWEncoder.java,v 1.0 02.12.13 14:13 haraldk Exp$
  • Field Details

    • CLEAR_CODE

      static final int CLEAR_CODE
      Clear: Re-initialize tables.
      See Also:
    • EOI_CODE

      static final int EOI_CODE
      End of Information.
      See Also:
    • MIN_BITS

      private static final int MIN_BITS
      See Also:
    • MAX_BITS

      private static final int MAX_BITS
      See Also:
    • TABLE_SIZE

      private static final int TABLE_SIZE
      See Also:
    • CHILDREN

      private final short[] CHILDREN
    • SIBLINGS

      private final short[] SIBLINGS
    • SUFFIXES

      private final short[] SUFFIXES
    • parent

      private int parent
    • bitsPerCode

      private int bitsPerCode
    • nextValidCode

      private int nextValidCode
    • maxCode

      private int maxCode
    • bits

      private int bits
    • bitPos

      private int bitPos
    • remaining

      private long remaining
  • Constructor Details

    • LZWEncoder

      LZWEncoder(long length)
  • Method Details

    • encode

      public void encode(OutputStream stream, ByteBuffer buffer) throws IOException
      Description copied from interface: Encoder
      Encodes up to buffer.remaining() bytes into the given input stream, from the given buffer.
      Specified by:
      encode in interface Encoder
      Parameters:
      stream - the output stream to encode data to
      buffer - buffer to read data from
      Throws:
      IOException - if an I/O error occurs
    • encodeBytes

      void encodeBytes(OutputStream stream, ByteBuffer buffer) throws IOException
      Throws:
      IOException
    • increaseCodeSizeOrResetIfNeeded

      private void increaseCodeSizeOrResetIfNeeded(OutputStream stream) throws IOException
      Throws:
      IOException
    • resetTables

      private void resetTables()
    • writeCode

      private void writeCode(OutputStream stream, int code) throws IOException
      Throws:
      IOException
    • maxValue

      private static int maxValue(int codeLen)
    • bitmaskFor

      private static int bitmaskFor(int bits)