Class HorizontalPredictor

All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ReadableByteChannel
Direct Known Subclasses:
HorizontalPredictor.Bytes, HorizontalPredictor.Doubles, HorizontalPredictor.Floats, HorizontalPredictor.Integers, HorizontalPredictor.Shorts

abstract class HorizontalPredictor extends PredictorChannel
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 Classes
    Modifier and Type
    Class
    Description
    private 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

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Constructor
    Description
    HorizontalPredictor(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 Type
    Method
    Description
    protected 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 using savedValues 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)
    Saves pixelStride 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • sampleSizeM1

      private final int sampleSizeM1
      Number of bytes minus one in a sample value.
    • pixelStride

      protected final int pixelStride
      Number 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 to ByteBuffer no matter the data type.
    • scanlineStride

      private final int scanlineStride
      Number 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 to ByteBuffer 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).
    • column

      private int column
      Column 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 to scanlineStride.
    • truncationMask

      private final int truncationMask
      The 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. The setInputRegion(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. The setInputRegion(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

      public final void setInputRegion(long start, long byteCount) throws IOException
      Prepares this predictor for reading a new tile or a new band of a tile.
      Overrides:
      setInputRegion in class PredictorChannel
      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

      protected 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.
      Specified by:
      apply in class PredictorChannel
      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

      abstract int applyOnFirst(ByteBuffer buffer, int position, int end, int offset)
      Applies the predictor on the specified region of the given buffer, but using savedValues array as the source of previous values. This is used only for the first pixel in a new invocation of apply(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 this apply(…) 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

      abstract int applyOnRow(ByteBuffer buffer, int position, int end)
      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 this apply(…) call.
      Returns:
      value of position after the last sample values processed by this method.
    • saveLastPixel

      abstract void saveLastPixel(ByteBuffer buffer, int keep, int position)
      Saves pixelStride bytes making the sample values of the last pixel. The first sample value to read from the buffer is given by position. 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.