All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel

final class CCITTRLE extends CompressionChannel
Inflater for values encoded with the CCITT Group 3, 1-Dimensional Modified Huffman run length encoding. This compression is described in section 10 of TIFF 6 specification. "Run length" (consecutive black or white pixels) are encoded with "words" having a variable number of bits. Example:
Run length encoding examples
Run length Encoding
0 0000110111
1 010
2 11
3 10
4 011
5 0011
Because the number of bits varies, leading zeros are significant. For example, "11" is not equivalent to "011", which is not equivalent to "0011" neither. Consequently, we cannot parse directly the bits as integer values.
Since:
1.1
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
    Number of bits in an image row, ignoring sub-regions and subsampling.
    private static final short[]
    Modified Huffman tree for length of runs of white and black colors.
    private int
    Number of bits that we still have to read for current image row.
    private boolean
    true if reading black color, or false if reading white color.
    private int
    Number of black or white pixels to write in the destination buffer.
    private static final int
    Bit shift to apply on 1 for obtaining 8 (2³ = 8).
    (package private) static final int
    Value after the last terminating run length.
    private static final short[]
    Modified Huffman tree for length of runs of white and black colors.

    Fields inherited from class org.apache.sis.internal.storage.inflater.CompressionChannel

    input, listeners
  • Constructor Summary

    Constructors
    Constructor
    Description
    CCITTRLE(ChannelDataInput input, StoreListeners listeners, int sourceWidth)
    Creates a new channel which will decompress data from the given input.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final int
    getRunLength(short[] tree)
    Returns the number of bits of white pixels or black pixels to append.
    int
    read(ByteBuffer target)
    Decompresses some bytes from the input into the given destination buffer.
    void
    setInputRegion(long start, long byteCount)
    Prepares this inflater for reading a new tile or a new band of a tile.

    Methods inherited from class org.apache.sis.internal.storage.inflater.CompressionChannel

    close, createDataInput, finished, isOpen, repeat, resources

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • WHITE_RUNLENGTH_TREE

      private static final short[] WHITE_RUNLENGTH_TREE
      Modified Huffman tree for length of runs of white and black colors. This array is generated by the CCITTRLETest class, which will also verifies that those values are still corrects. This array is used for finding the "run length" associated to a sequence of bits like below:
      • If value at offset i is negative, then the result is ~RUNLENGTH_TREE[i].
      • Otherwise read a bit and choose a branch according the bit value:
        • If the bit is 0, continue tree traversal at i+1.
        • If the bit is 1, continue tree traversal at RUNLENGTH_TREE[i].
    • BLACK_RUNLENGTH_TREE

      private static final short[] BLACK_RUNLENGTH_TREE
      Modified Huffman tree for length of runs of white and black colors. This array is generated by the CCITTRLETest class, which will also verifies that those values are still corrects. This array is used for finding the "run length" associated to a sequence of bits like below:
      • If value at offset i is negative, then the result is ~RUNLENGTH_TREE[i].
      • Otherwise read a bit and choose a branch according the bit value:
        • If the bit is 0, continue tree traversal at i+1.
        • If the bit is 1, continue tree traversal at RUNLENGTH_TREE[i].
    • TERMINATING_LIMIT

      static final int TERMINATING_LIMIT
      Value after the last terminating run length. Run lengths equal or greater to this value must be added to the next value until a terminating value is found.
      See Also:
    • bitsPerRow

      private final int bitsPerRow
      Number of bits in an image row, ignoring sub-regions and subsampling.
    • remainingBitsInRow

      private int remainingBitsInRow
      Number of bits that we still have to read for current image row.
    • runIsWhite

      private boolean runIsWhite
      true if reading black color, or false if reading white color. The photometric interpretation ("White is zero" versus "Black is zero") does not need to be handled here; it is handled by the color model instead.
    • runLength

      private int runLength
      Number of black or white pixels to write in the destination buffer.
    • SIZE_SHIFT

      private static final int SIZE_SHIFT
      Bit shift to apply on 1 for obtaining 8 (2³ = 8).
      See Also:
  • Constructor Details

    • CCITTRLE

      CCITTRLE(ChannelDataInput input, StoreListeners listeners, int sourceWidth)
      Creates a new channel which will decompress data from the given input. The setInputRegion(long, long) method must be invoked after construction before a reading process can start.
      Parameters:
      input - the source of data to decompress.
      listeners - object where to report warnings.
      sourceWidth - number of pixels in a row of the source image.
  • Method Details

    • setInputRegion

      public void setInputRegion(long start, long byteCount) throws IOException
      Prepares this inflater for reading a new tile or a new band of a tile.
      Overrides:
      setInputRegion in class CompressionChannel
      Parameters:
      start - stream position where to start reading.
      byteCount - number of bytes to read from the input.
      Throws:
      IOException - if the stream cannot be seek to the given start position.
    • getRunLength

      final int getRunLength(short[] tree) throws IOException
      Returns the number of bits of white pixels or black pixels to append.
      Parameters:
      tree - WHITE_RUNLENGTH_TREE or BLACK_RUNLENGTH_TREE.
      Throws:
      IOException
    • read

      public int read(ByteBuffer target) throws IOException
      Decompresses some bytes from the input into the given destination buffer.
      Parameters:
      target - the buffer into which bytes are to be transferred.
      Returns:
      the number of bytes read, or -1 if end-of-stream.
      Throws:
      IOException - if some other I/O error occurs.