Class CCITTRLE
java.lang.Object
org.apache.sis.internal.storage.inflater.PixelChannel
org.apache.sis.internal.storage.inflater.CompressionChannel
org.apache.sis.internal.storage.inflater.CCITTRLE
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ReadableByteChannel
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:
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.
Run length | Encoding |
---|---|
0 | 0000110111 |
1 | 010 |
2 | 11 |
3 | 10 |
4 | 011 |
5 | 0011 |
- Since:
- 1.1
- Version:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate 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, orfalse
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
ConstructorsConstructorDescriptionCCITTRLE
(ChannelDataInput input, StoreListeners listeners, int sourceWidth) Creates a new channel which will decompress data from the given input. -
Method Summary
Modifier and TypeMethodDescription(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
-
Field Details
-
WHITE_RUNLENGTH_TREE
private static final short[] WHITE_RUNLENGTH_TREEModified Huffman tree for length of runs of white and black colors. This array is generated by theCCITTRLETest
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]
.
- If value at offset i is negative, then the result is
-
BLACK_RUNLENGTH_TREE
private static final short[] BLACK_RUNLENGTH_TREEModified Huffman tree for length of runs of white and black colors. This array is generated by theCCITTRLETest
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]
.
- If value at offset i is negative, then the result is
-
TERMINATING_LIMIT
static final int TERMINATING_LIMITValue 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 bitsPerRowNumber of bits in an image row, ignoring sub-regions and subsampling. -
remainingBitsInRow
private int remainingBitsInRowNumber of bits that we still have to read for current image row. -
runIsWhite
private boolean runIsWhitetrue
if reading black color, orfalse
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 runLengthNumber of black or white pixels to write in the destination buffer. -
SIZE_SHIFT
private static final int SIZE_SHIFTBit 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. ThesetInputRegion(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
Prepares this inflater for reading a new tile or a new band of a tile.- Overrides:
setInputRegion
in classCompressionChannel
- 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
Returns the number of bits of white pixels or black pixels to append.- Parameters:
tree
-WHITE_RUNLENGTH_TREE
orBLACK_RUNLENGTH_TREE
.- Throws:
IOException
-
read
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.
-