Class PackBitsDecoder
- All Implemented Interfaces:
Decoder
From Wikipedia, the free encyclopedia
PackBits is a fast, simple compression scheme for run-length encoding of
data.
Apple introduced the PackBits format with the release of MacPaint on the Macintosh computer. This compression scheme is one of the types of compression that can be used in TIFF-files.
A PackBits data stream consists of packets of one byte of header followed by data. The header is a signed byte; the data can be signed, unsigned, or packed (such as MacPaint pixels).
Header byte | Data |
---|---|
0 to 127 | 1 + n literal bytes of data |
0 to -127 | One byte of data, repeated 1 - n times in the decompressed output |
-128 | No operation |
Note that interpreting 0 as positive or negative makes no difference in the output. Runs of two bytes adjacent to non-runs are typically written as literal data.
- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/PackBitsDecoder.java#1 $
- Author:
- Harald Kuhr
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates aPackBitsDecoder
.PackBitsDecoder
(boolean disableNoOp) Creates aPackBitsDecoder
, with optional compatibility mode.PackBitsDecoder
(int sampleSize, boolean disableNoOp) Creates aPackBitsDecoder
, with optional compatibility mode. -
Method Summary
Modifier and TypeMethodDescriptionint
decode
(InputStream stream, ByteBuffer buffer) Decodes bytes from the given input stream, to the given buffer.
-
Constructor Details
-
PackBitsDecoder
public PackBitsDecoder()Creates aPackBitsDecoder
. -
PackBitsDecoder
public PackBitsDecoder(boolean disableNoOp) Creates aPackBitsDecoder
, with optional compatibility mode.As some implementations of PackBits-like encoders treat
-128
as length of a compressed run, instead of a no-op, it's possible to disable no-ops for compatibility. Should be used with caution, even though, most known encoders never write no-ops in the compressed streams.- Parameters:
disableNoOp
-true
if-128
should be treated as a compressed run, and not a no-op
-
PackBitsDecoder
public PackBitsDecoder(int sampleSize, boolean disableNoOp) Creates aPackBitsDecoder
, with optional compatibility mode.As some implementations of PackBits-like encoders treat
-128
as length of a compressed run, instead of a no-op, it's possible to disable no-ops for compatibility. Should be used with caution, even though, most known encoders never write no-ops in the compressed streams.- Parameters:
disableNoOp
-true
if-128
should be treated as a compressed run, and not a no-op
-
-
Method Details
-
decode
Decodes bytes from the given input stream, to the given buffer.- Specified by:
decode
in interfaceDecoder
- Parameters:
stream
- the stream to decode frombuffer
- a byte array, minimum 128 (or 129 if no-op is disabled) bytes long- Returns:
- The number of bytes decoded
- Throws:
IOException
- if a problem occurs during decoding.
-