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

abstract class CopyFromBytes extends Inflater
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
  • Field Details

    • streamPosition

      private long streamPosition
      Stream position where to perform the next reading.
    • positionNeedsRefresh

      private boolean positionNeedsRefresh
      Whether streamPosition needs to be refreshed by a call to ChannelData.getStreamPosition().
    • bytesPerElement

      private final int bytesPerElement
      Number of bytes in a bank element. A bank element is usually a sample value.
    • pixelsPerElement

      private final int pixelsPerElement
      Number 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 the SinglePixelPackedSampleModel 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

      public void setInputOutput(long start, long byteCount, Buffer bank) throws IOException
      Sets the input and output and prepares this inflater for reading a new tile or band of a tile.
      Overrides:
      setInputOutput in class Inflater
      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

      public void uncompressRow() throws IOException
      Reads a row of sample values and stores them in the target buffer. Subclasses must override this method and invoke super.uncompress() before to do the actual reading.
      Specified by:
      uncompressRow in class Inflater
      Throws:
      IOException - if an error occurred while reading the input channel.
    • skip

      public final void skip(long n) throws IOException
      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 of pixelsPerElement if this method is not invoked for skipping all remaining values until end of row. See Inflater.skip(long) for more information.
      Specified by:
      skip in class Inflater
      Parameters:
      n - number of uncompressed sample values to ignore.
      Throws:
      IOException - if an error occurred while reading the input channel.
    • skipAfterChunk

      final int skipAfterChunk(int skipIndex) throws IOException
      Skips the number of chunks specified by the Inflater.skipAfterChunks array at the given index. This method tries to move by incrementing the buffer position.
      Design note: we do not use ChannelDataInput.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 in skipAfterChunks array.
      Returns:
      new skipIndex value.
      Throws:
      IOException