Class HorizontalPredictor
java.lang.Object
org.apache.sis.internal.storage.inflater.PixelChannel
org.apache.sis.internal.storage.inflater.PredictorChannel
org.apache.sis.internal.storage.inflater.HorizontalPredictor
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ReadableByteChannel
- Direct Known Subclasses:
HorizontalPredictor.Bytes
,HorizontalPredictor.Doubles
,HorizontalPredictor.Floats
,HorizontalPredictor.Integers
,HorizontalPredictor.Shorts
Implementation of
Predictor.HORIZONTAL
.
Current implementation works only on 8, 16, 32 or 64-bits samples.
Values packed on 4, 2 or 1 bits are not yet supported.- Since:
- 1.1
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
A horizontal predictor working on byte values.private static final class
A horizontal predictor working on double-precision floating point values.private static final class
A horizontal predictor working on single-precision floating point values.private static final class
A horizontal predictor working on 32 bits integer values.private static final class
A horizontal predictor working on short integer values. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate int
Column index (as a count of bytes, not a count of sample values or pixels).protected final int
Number of bytes between a sample value of a pixel and the same sample value of the next pixel.private final int
Number of bytes minus one in a sample value.private final int
Number of bytes between a column in a row and the same column in the next row.private final int
The mask to apply for truncating a position to a multiple of data type size. -
Constructor Summary
ConstructorsConstructorDescriptionHorizontalPredictor
(CompressionChannel input, int samplesPerPixel, int width, int sampleSize) Creates a new predictor which will read uncompressed data from the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected final int
apply
(ByteBuffer buffer, int start) Applies the predictor on data in the given buffer, from the given start position until current buffer position.(package private) abstract int
applyOnFirst
(ByteBuffer buffer, int position, int end, int offset) Applies the predictor on the specified region of the given buffer, but usingsavedValues
array as the source of previous values.(package private) abstract int
applyOnRow
(ByteBuffer buffer, int position, int end) Applies the predictor on the specified region of the given buffer.(package private) static HorizontalPredictor
create
(CompressionChannel input, DataType dataType, int pixelStride, int width) Creates a new predictor.(package private) abstract void
saveLastPixel
(ByteBuffer buffer, int keep, int position) SavespixelStride
bytes making the sample values of the last pixel.final void
setInputRegion
(long start, long byteCount) Prepares this predictor for reading a new tile or a new band of a tile.Methods inherited from class org.apache.sis.internal.storage.inflater.PredictorChannel
close, isOpen, read
-
Field Details
-
sampleSizeM1
private final int sampleSizeM1Number of bytes minus one in a sample value. -
pixelStride
protected final int pixelStrideNumber of bytes between a sample value of a pixel and the same sample value of the next pixel. Contrarily to similar fields in other classes, the value in this class is expressed in bytes rather than a count of sample values because this stride will be applied toByteBuffer
no matter the data type. -
scanlineStride
private final int scanlineStrideNumber of bytes between a column in a row and the same column in the next row. Contrarily to similar fields in other classes, the value in this class is expressed in bytes rather than a count of sample values because this stride will be applied toByteBuffer
no matter the data type.Invariants:
- This is a multiple of
pixelStride
. - Must be strictly greater than
pixelStride
(i.e. image width must be at least 2 pixels).
- This is a multiple of
-
column
private int columnColumn index (as a count of bytes, not a count of sample values or pixels). Used for detecting when the decoding process starts a new row. It shall always be a multiple of the data size (in bytes) and between 0 toscanlineStride
. -
truncationMask
private final int truncationMaskThe mask to apply for truncating a position to a multiple of data type size. For example if the data type is unsigned short, then the mask shall truncate positions to a multiple of 2.
-
-
Constructor Details
-
HorizontalPredictor
HorizontalPredictor(CompressionChannel input, int samplesPerPixel, int width, int sampleSize) Creates a new predictor which will read uncompressed data from the given channel. ThesetInputRegion(long, long)
method must be invoked after construction before a reading process can start.- Parameters:
input
- the channel that decompress data.samplesPerPixel
- number of sample values per pixel in the source image.width
- number of pixels in the source image.sampleSize
- number of bytes in a sample value.
-
-
Method Details
-
create
static HorizontalPredictor create(CompressionChannel input, DataType dataType, int pixelStride, int width) Creates a new predictor. ThesetInputRegion(long, long)
method must be invoked after construction before a reading process can start.- Parameters:
input
- the channel that decompress data.dataType
- primitive type used for storing data elements in the bank.pixelStride
- number of sample values per pixel in the source image.width
- number of pixels in the source image.sampleSize
- number of bytes in a sample value.- Returns:
- the predictor, or
null
if the given type is unsupported.
-
setInputRegion
Prepares this predictor for reading a new tile or a new band of a tile.- Overrides:
setInputRegion
in classPredictorChannel
- 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.
-
apply
Applies the predictor on data in the given buffer, from the given start position until current buffer position.- Specified by:
apply
in classPredictorChannel
- Parameters:
buffer
- the buffer on which to apply the predictor.start
- position of first byte to process.- Returns:
- position after the last sample value processed. Should be
limit
, unless the predictor needs more data for processing the last bytes.
-
applyOnFirst
Applies the predictor on the specified region of the given buffer, but usingsavedValues
array as the source of previous values. This is used only for the first pixel in a new invocation ofapply(ByteBuffer, int)
.- Parameters:
buffer
- the buffer on which to apply the predictor.position
- position of the first value to modify in the given buffer.end
- position after the last value to process in thisapply(…)
call.offset
- offset (in bytes) of the first saved value to use.- Returns:
- value of
position
after the last sample values processed by this method.
-
applyOnRow
Applies the predictor on the specified region of the given buffer. All integer arguments given to this method are in bytes, with increasing values from left to right. This method shall increment the position by a multiple of data type size (e.g. 2 for short integers).- Parameters:
buffer
- the buffer on which to apply the predictor.position
- position of the first value to modify in the given buffer.end
- position after the last value to process in thisapply(…)
call.- Returns:
- value of
position
after the last sample values processed by this method.
-
saveLastPixel
SavespixelStride
bytes making the sample values of the last pixel. The first sample value to read from the buffer is given byposition
. In rare occasions, some previously saved values may need to be reused.- Parameters:
buffer
- buffer from which to save sample values.keep
- number of bytes to keep in the currently saved values.position
- position in the buffer of the first byte to save, after the values to keep.
-