Class LSBBitReader

java.lang.Object
com.twelvemonkeys.imageio.plugins.webp.LSBBitReader

public final class LSBBitReader extends Object
LSBBitReader
  • Field Details

    • imageInput

      private final ImageInputStream imageInput
    • bitOffset

      private int bitOffset
    • streamPosition

      private long streamPosition
    • buffer

      private long buffer
      Pre-buffers up to the next 8 Bytes in input. Contains valid bits in bits 63 to bitOffset (inclusive).
  • Constructor Details

  • Method Details

    • readBits

      public long readBits(int bits) throws IOException
      Reads the specified number of bits from the stream in an LSB-first way and advances the bitOffset. The underlying ImageInputStream will be advanced to the first not (completely) read byte. Requesting more than 64 bits will advance the reader by the correct amount and return the lowest 64 bits of the read number
      Parameters:
      bits - the number of bits to read
      Returns:
      a signed long built from the requested bits (truncated to the low 64 bits)
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • peekBits

      public long peekBits(int bits) throws IOException
      Reads the specified number of bits from the buffer in an LSB-first way. Does not advance the bitOffset or the underlying input stream. As only 56 bits are buffered (in the worst case) peeking more is not possible without advancing the reader and as such disallowed.
      Parameters:
      bits - the number of bits to peek (max 56)
      Returns:
      a signed long built from the requested bits
      Throws:
      IOException - if an I/O error occurs
      See Also:
    • readBits

      private long readBits(int bits, boolean peek) throws IOException
      Throws:
      IOException
    • refillBuffer

      private void refillBuffer() throws IOException
      Throws:
      IOException
    • resetBuffer

      private void resetBuffer() throws IOException
      Throws:
      IOException
    • readBit

      public int readBit() throws IOException
      Throws:
      IOException