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
Author:
Martin Desruisseaux (Geomatys)
See Also:
  • 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:
    • 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.