Class CopyFromBytes
java.lang.Object
org.apache.sis.internal.storage.inflater.Inflater
org.apache.sis.internal.storage.inflater.CopyFromBytes
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Direct Known Subclasses:
CopyFromBytes.Bytes
,CopyFromBytes.Doubles
,CopyFromBytes.Floats
,CopyFromBytes.Ints
,CopyFromBytes.Shorts
A pseudo-inflater which copies values from a buffer of bytes to the destination image buffer.
When reading uncompressed TIFF images, the source buffer is the direct buffer used for I/O operations.
When reading compressed TIFF images, the source buffer is a temporary buffer where data segments are
uncompressed before to be copied to the destination image. This is useful when handling subsampling
on-the-fly at decompression time would be too difficult: implementers can decompress everything in
a temporary buffer and let this
CopyFromBytes
class do the subsampling.- Since:
- 1.1
- Version:
- 1.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Inflater for sample values stored as bytes.private static final class
Inflater for sample values stored as double-precision floating point numbers.private static final class
Inflater for sample values stored as single-precision floating point numbers.private static final class
Inflater for sample values stored as 32 bits integers.private static final class
Inflater for sample values stored as short integers. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
Number of bytes in a bank element.private final int
Number of pixels per primitive element.private boolean
WhetherstreamPosition
needs to be refreshed by a call toChannelData.getStreamPosition()
.private long
Stream position where to perform the next reading.Fields inherited from class org.apache.sis.internal.storage.inflater.Inflater
chunksPerRow, elementsPerChunk, input, skipAfterChunks
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CopyFromBytes
(ChannelDataInput input, int chunksPerRow, int samplesPerChunk, int[] skipAfterChunks, int pixelsPerElement, int bytesPerElement) For constructors in inner classes. -
Method Summary
Modifier and TypeMethodDescription(package private) static CopyFromBytes
create
(ChannelDataInput input, DataType dataType, int chunksPerRow, int samplesPerChunk, int[] skipAfterChunks, int pixelsPerElement) Creates a new instance.void
setInputOutput
(long start, long byteCount, Buffer bank) Sets the input and output and prepares this inflater for reading a new tile or band of a tile.final void
skip
(long n) Skips the given amount of sample values without storing them.(package private) final int
skipAfterChunk
(int skipIndex) Skips the number of chunks specified by theInflater.skipAfterChunks
array at the given index.void
Reads a row of sample values and stores them in the target buffer.
-
Field Details
-
streamPosition
private long streamPositionStream position where to perform the next reading. -
positionNeedsRefresh
private boolean positionNeedsRefreshWhetherstreamPosition
needs to be refreshed by a call toChannelData.getStreamPosition()
. -
bytesPerElement
private final int bytesPerElementNumber of bytes in a bank element. A bank element is usually a sample value. -
pixelsPerElement
private final int pixelsPerElementNumber of pixels per primitive element. Always 1 except for multi-pixels packed images.Note: this is "pixels per element", not "samples per element", because the value of this field shall be 1 in theSinglePixelPackedSampleModel
case (by contrast a "samples per element" would have a value greater than 1). But this field can nevertheless be understood as a "samples per element" value where only one band is considered at a time.
-
-
Constructor Details
-
CopyFromBytes
private CopyFromBytes(ChannelDataInput input, int chunksPerRow, int samplesPerChunk, int[] skipAfterChunks, int pixelsPerElement, int bytesPerElement) For constructors in inner classes.- Parameters:
input
- the source of data to decompress.chunksPerRow
- number of chunks (usually pixels) per row in target image. Must be strictly positive.samplesPerChunk
- number of sample values per chunk (sample, pixel or row). Must be strictly positive.skipAfterChunks
- number of sample values to skip between chunks. May be empty or null.pixelsPerElement
- number of pixels per primitive element. Always 1 except for multi-pixels packed images.bytesPerElement
- number of bytes in a bank element (a bank element is usually a sample value).
-
-
Method Details
-
create
static CopyFromBytes create(ChannelDataInput input, DataType dataType, int chunksPerRow, int samplesPerChunk, int[] skipAfterChunks, int pixelsPerElement) throws UnsupportedEncodingException Creates a new instance.- Parameters:
input
- the source of data to decompress.chunksPerRow
- number of chunks (usually pixels) per row. Must be strictly positive.samplesPerChunk
- number of sample values per chunk (sample, pixel or row). Must be strictly positive.skipAfterChunks
- number of sample values to skip between chunks. May be empty or null.pixelsPerElement
- number of pixels per primitive element. Always 1 except for multi-pixels packed images.- Returns:
- the inflater for the given targe type.
- Throws:
UnsupportedEncodingException
- if the buffer type is not recognized.
-
setInputOutput
Sets the input and output and prepares this inflater for reading a new tile or band of a tile.- Overrides:
setInputOutput
in classInflater
- Parameters:
start
- input stream position where to start reading.byteCount
- number of bytes to read before decompression.bank
- where to store sample values.- Throws:
IOException
- if an I/O operation was required and failed.
-
uncompressRow
Reads a row of sample values and stores them in the target buffer. Subclasses must override this method and invokesuper.uncompress()
before to do the actual reading.- Specified by:
uncompressRow
in classInflater
- Throws:
IOException
- if an error occurred while reading the input channel.
-
skip
Skips the given amount of sample values without storing them. The given value is in units of sample values, not in bytes.Case of multi-pixels packed image
It is caller's responsibility to ensure that n is a multiple ofpixelsPerElement
if this method is not invoked for skipping all remaining values until end of row. SeeInflater.skip(long)
for more information.- Specified by:
skip
in classInflater
- Parameters:
n
- number of uncompressed sample values to ignore.- Throws:
IOException
- if an error occurred while reading the input channel.
-
skipAfterChunk
Skips the number of chunks specified by theInflater.skipAfterChunks
array at the given index. This method tries to move by incrementing the buffer position.Design note: we do not useChannelDataInput.seek(long)
because the displacement is usually small. Changing the buffer position is sufficient in the majority of cases. If not, then it should be okay to fill the buffer with next data (instead of doing a seek operation) because there is usually few remaining values to skip. Performance of this method is important, so we try to avoid overhead.- Parameters:
skipIndex
- index inskipAfterChunks
array.- Returns:
- new
skipIndex
value. - Throws:
IOException
-