Class LZWDecoder

java.lang.Object
com.twelvemonkeys.imageio.plugins.tiff.LZWDecoder
All Implemented Interfaces:
Decoder
Direct Known Subclasses:
LZWDecoder.LZWCompatibilityDecoder, LZWDecoder.LZWSpecDecoder

abstract class LZWDecoder extends Object implements Decoder
Lempel–Ziv–Welch (LZW) decompression. LZW is a universal loss-less data compression algorithm created by Abraham Lempel, Jacob Ziv, and Terry Welch. Inspired by libTiff's LZW decompression.
Version:
$Id: LZWDecoder.java,v 1.0 08.05.12 21:11 haraldk Exp$
See Also:
  • 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:
    • table

      private final LZWDecoder.LZWString[] table
    • tableLength

      private int tableLength
    • bitsPerCode

      int bitsPerCode
    • oldCode

      private int oldCode
    • maxCode

      private int maxCode
    • bitMask

      int bitMask
    • maxString

      private int maxString
    • eofReached

      boolean eofReached
    • nextData

      int nextData
    • nextBits

      int nextBits
  • Constructor Details

    • LZWDecoder

      protected LZWDecoder(int tableSize)
  • Method Details

    • bitmaskFor

      private static int bitmaskFor(int bits)
    • init

      private void init()
    • decode

      public int decode(InputStream stream, ByteBuffer buffer) throws IOException
      Description copied from interface: Decoder
      Decodes up to buffer.length bytes from the given input stream, into the given buffer.
      Specified by:
      decode in interface Decoder
      Parameters:
      stream - the input stream to decode data from
      buffer - buffer to store the read data
      Returns:
      the total number of bytes read into the buffer, or 0 if there is no more data because the end of the stream has been reached.
      Throws:
      IOException - if an I/O error occurs.
    • addStringToTable

      private void addStringToTable(LZWDecoder.LZWString string) throws IOException
      Throws:
      IOException
    • maxCode

      protected abstract int maxCode()
    • isInTable

      private boolean isInTable(int code)
    • getNextCode

      protected abstract int getNextCode(InputStream stream) throws IOException
      Throws:
      IOException
    • isOldBitReversedStream

      static boolean isOldBitReversedStream(InputStream stream) throws IOException
      Throws:
      IOException
    • create

      public static Decoder create(boolean oldBitReversedStream)