Class BandedSampleConverter

All Implemented Interfaces:
RenderedImage, Disposable
Direct Known Subclasses:
BandedSampleConverter.Writable

class BandedSampleConverter extends ComputedImage
An image where each sample value is computed independently of other sample values and independently of neighbor points. Values are computed by a separated MathTransform1D for each band (by contrast, an InterleavedSampleConverter would handle all sample values as a coordinate tuple). Current implementation makes the following simplifications:
  • The image has exactly one source.
  • Image layout (minimum coordinates, image size, tile grid) is the same than source image layout, unless the source has too large tiles in which case ImageLayout automatically subdivides the tile grid in smaller tiles.
  • Image is computed and stored on a band-by-band basis using a BandedSampleModel.
  • Calculation is performed on float or double numbers.
If the given source is writable and the transform are invertible, then the BandedSampleConverter returned by the create(…) method will implement WritableRenderedImage interface. In such case, writing converted values will cause the corresponding source values to be updated too.
Since:
1.1
Version:
1.3
  • Field Details

    • ADDED_PROPERTIES

      private static final String[] ADDED_PROPERTIES
      Properties potentially added by this image, no matter if present in source image or not. Must be consistent with the switch case statement doing its own calculation in getProperty(String).
      See Also:
    • converters

      private final org.opengis.referencing.operation.MathTransform1D[] converters
      The transfer functions to apply on each band of the source image.
    • colorModel

      private final ColorModel colorModel
      The color model for the expected range of values. May be null.
    • sampleResolutions

      private final double[] sampleResolutions
      The sample resolutions, or null if unknown.
  • Constructor Details

    • BandedSampleConverter

      private BandedSampleConverter(RenderedImage source, BandedSampleModel sampleModel, ColorModel colorModel, NumberRange<?>[] ranges, org.opengis.referencing.operation.MathTransform1D[] converters)
      Creates a new image which will compute values using the given converters.
      Parameters:
      source - the image for which to convert sample values.
      sampleModel - the sample model shared by all tiles in this image.
      colorModel - the color model for the expected range of values, or null.
      ranges - the expected range of values for each band, or null if unknown.
      converters - the transfer functions to apply on each band of the source image. If this array was a user-provided parameter, should be cloned by caller.
  • Method Details

    • create

      static BandedSampleConverter create(RenderedImage source, ImageLayout layout, NumberRange<?>[] sourceRanges, org.opengis.referencing.operation.MathTransform1D[] converters, int targetType, ColorModel colorModel)
      Creates a new image of the given data type which will compute values using the given converters. The number of bands is the length of the converters array, which must be greater than 0 and not greater than the number of bands in the source image.
      Parameters:
      source - the image for which to convert sample values.
      layout - object to use for computing tile size.
      sourceRanges - the expected range of values for each band in source image, or null if unknown.
      converters - the transfer functions to apply on each band of the source image.
      targetType - the type of this image resulting from conversion of given image. Shall be one of DataBuffer constants.
      colorModel - the color model for the expected range of values, or null.
      Returns:
      the image which compute converted values from the given source.
      See Also:
    • getProperty

      public Object getProperty(String key)
      Gets a property from this image. Current implementation recognizes: "org.apache.sis.SampleResolution".
      Specified by:
      getProperty in interface RenderedImage
      Overrides:
      getProperty in class PlanarImage
      Parameters:
      key - the name of the property to get.
      Returns:
      the property value, or Image.UndefinedProperty if none.
    • getPropertyNames

      public String[] getPropertyNames()
      Returns the names of all recognized properties, or null if this image has no properties.
      Specified by:
      getPropertyNames in interface RenderedImage
      Overrides:
      getPropertyNames in class PlanarImage
      Returns:
      names of all recognized properties, or null if none.
    • getColorModel

      public ColorModel getColorModel()
      Returns the color model associated with all rasters of this image. If the sample values of this image are floating point numbers, then a gray scale color model is computed from the expected range of values.
      Returns:
      the color model of this image, or null if none.
    • getWidth

      public int getWidth()
      Returns the width (in pixels) of this image. This is the the same value than the source image (not necessarily zero).
      Returns:
      the width (number of columns) of this image.
    • getHeight

      public int getHeight()
      Returns the height (in pixels) of this image. This is the the same value than the source image (not necessarily zero).
      Returns:
      the height (number of rows) of this image.
    • getMinX

      public int getMinX()
      Returns the minimum x coordinate (inclusive) of this image. This is the the same value than the source image (not necessarily zero).
      Specified by:
      getMinX in interface RenderedImage
      Overrides:
      getMinX in class PlanarImage
      Returns:
      the minimum x coordinate (column) of this image.
    • getMinY

      public int getMinY()
      Returns the minimum y coordinate (inclusive) of this image. This is the the same value than the source image (not necessarily zero).
      Specified by:
      getMinY in interface RenderedImage
      Overrides:
      getMinY in class PlanarImage
      Returns:
      the minimum y coordinate (row) of this image.
    • getMinTileX

      public int getMinTileX()
      Returns the minimum tile index in the x direction. This is the the same value than the source image (not necessarily zero).
      Specified by:
      getMinTileX in interface RenderedImage
      Overrides:
      getMinTileX in class PlanarImage
      Returns:
      the minimum tile index in the x direction.
    • getMinTileY

      public int getMinTileY()
      Returns the minimum tile index in the y direction. This is the the same value than the source image (not necessarily zero).
      Specified by:
      getMinTileY in interface RenderedImage
      Overrides:
      getMinTileY in class PlanarImage
      Returns:
      the minimum tile index in the y direction.
    • computeTile

      protected Raster computeTile(int tileX, int tileY, WritableRaster target) throws org.opengis.referencing.operation.TransformException
      Computes the tile at specified indices.
      Specified by:
      computeTile in class ComputedImage
      Parameters:
      tileX - the column index of the tile to compute.
      tileY - the row index of the tile to compute.
      target - if the tile already exists but needs to be updated, the tile to update. Otherwise null.
      Returns:
      computed tile for the given indices (cannot be null).
      Throws:
      org.opengis.referencing.operation.TransformException - if an error occurred while converting a sample value.
    • prefetch

      protected Disposable prefetch(Rectangle tiles)
      Notifies the source image that tiles will be computed soon in the given region. If the source image is an instance of PlanarImage, then this method forwards the notification to it. Otherwise default implementation does nothing.
      Overrides:
      prefetch in class ComputedImage
      Parameters:
      tiles - indices of the tiles which will be prefetched.
      Returns:
      handler on which to invoke dispose() after the prefetch operation completed (successfully or not), or null if none.
    • hashCode

      public int hashCode()
      Returns a hash code value for this image.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Compares the given object with this image for equality.
      Overrides:
      equals in class Object