Class SampleModelFactory

java.lang.Object
org.apache.sis.internal.coverage.j2d.SampleModelFactory

public final class SampleModelFactory extends Object
A factory for SampleModel instances. This class provides a convenient way to get the properties of an existing sample model, modify them, then create a new sample model with the modified properties.
Since:
1.1
Version:
1.1
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private int[]
    Offsets for all bands in data array elements, or null if not applicable.
    private int[]
    Index for each bank storing a band of image data, or null if not applicable.
    private int[]
    The bit masks for all bands, or null if not applicable.
    private int
    The bit offset into the data array where the first pixel begins.
    private int
    Type of sample values as one of the DataBuffer constants.
    private final int
    Width and height in pixels of tiles using the sample model.
    private int
    Number of bands of the image data.
    private int
    Number of bits per pixel, or 0 if not applicable.
    private int
    Number of sample values to advance for moving to next pixel.
    private int
    Number of sample values to advance for moving to next line.
    private final int
    Width and height in pixels of tiles using the sample model.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new factory initialized to the value of given sample model.
    SampleModelFactory(DataType type, int width, int height, int numBands, int bitsPerSample, boolean isBanded)
    Creates a factory initialized to the given values.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static int
    bitCount(int mask)
    Returns the number of bits in the given mask.
    Builds a sample model based on current factory configuration.
    private static int[]
    subset(int[] data, int[] bands, boolean compress)
    Creates a subset of the data arrays for the specified bands.
    void
    subsetAndCompress(int[] bands)
    Requests a sample model with only a subset of the bands of the original sample model.

    Methods inherited from class java.lang.Object

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

    • dataType

      private int dataType
      Type of sample values as one of the DataBuffer constants.
    • width

      private final int width
      Width and height in pixels of tiles using the sample model.

      Warning: changing sample model size has non-obvious implications in BandedSampleModel case when all data are in a single bank. The SampleModel.createCompatibleSampleModel(int, int) method should be preferred instead.

      See Also:
    • height

      private final int height
      Width and height in pixels of tiles using the sample model.

      Warning: changing sample model size has non-obvious implications in BandedSampleModel case when all data are in a single bank. The SampleModel.createCompatibleSampleModel(int, int) method should be preferred instead.

      See Also:
    • numBands

      private int numBands
      Number of bands of the image data. Note: do not confuse bands and banks.
    • bankIndices

      private int[] bankIndices
      Index for each bank storing a band of image data, or null if not applicable.
    • bandOffsets

      private int[] bandOffsets
      Offsets for all bands in data array elements, or null if not applicable.
    • bitMasks

      private int[] bitMasks
      The bit masks for all bands, or null if not applicable.
    • dataBitOffset

      private int dataBitOffset
      The bit offset into the data array where the first pixel begins.
    • numberOfBits

      private int numberOfBits
      Number of bits per pixel, or 0 if not applicable. Also known as "pixel bit stride".
    • pixelStride

      private int pixelStride
      Number of sample values to advance for moving to next pixel. This is 0 when numberOfBits should be used instead.
    • scanlineStride

      private int scanlineStride
      Number of sample values to advance for moving to next line.
  • Constructor Details

    • SampleModelFactory

      public SampleModelFactory(DataType type, int width, int height, int numBands, int bitsPerSample, boolean isBanded)
      Creates a factory initialized to the given values.
      Parameters:
      type - type of sample values.
      width - tile width in pixels.
      height - tile height in pixels.
      numBands - number of bands.
      bitsPerSample - number of bits per sample values.
      isBanded - true if each band is stored in a separated bank.
      Throws:
      RasterFormatException - if the arguments imply a sample model of unsupported type.
    • SampleModelFactory

      public SampleModelFactory(SampleModel model)
      Creates a new factory initialized to the value of given sample model.
      Parameters:
      model - the sample model from which to copy values.
      Throws:
      RasterFormatException - if the type of the given sample model is not supported.
  • Method Details

    • subsetAndCompress

      public void subsetAndCompress(int[] bands)
      Requests a sample model with only a subset of the bands of the original sample model. Special cases:
      • For SinglePixelPackedSampleModel, this method may change the data type if decreasing the number of bands make possible to store pixels in smaller integers.

      Comparison with standard method

      The standard SampleModel.createSubsetSampleModel(int[]) method also selects a subset of the bands. However, that standard method creates a sample model accepting the same DataBuffer than the original SampleModel, which is useful for creating a view of image data that are already in memory. By contrast, this BandSelector compresses bank indices or pixel masks for leaving no empty space between them. This is useful when done before loading data from a file in order to avoid consuming space for bands that were not requested.
      Parameters:
      bands - bands to keep.
      See Also:
    • bitCount

      private static int bitCount(int mask)
      Returns the number of bits in the given mask. All bits between the first and last bits are considered set to 1. This is intentional, because masks shall not overlap.
      See Also:
    • subset

      private static int[] subset(int[] data, int[] bands, boolean compress)
      Creates a subset of the data arrays for the specified bands. If compress is true, then sequences such as {1, 3, 4, 6, …} are replaced by {0, 1, 2, 3, …} (not necessarily in increasing order).
    • build

      public SampleModel build()
      Builds a sample model based on current factory configuration. The factory is still valid after this method call.
      Returns:
      the sample model built from current factory configuration.
      Throws:
      IllegalArgumentException - if an error occurred while building a sample model.