Class BatchComputedImage

java.lang.Object
org.apache.sis.image.PlanarImage
org.apache.sis.image.ComputedImage
org.apache.sis.internal.coverage.j2d.BatchComputedImage
All Implemented Interfaces:
RenderedImage, Disposable
Direct Known Subclasses:
TiledDeferredImage

public abstract class BatchComputedImage extends ComputedImage
A computed image for which it is more efficient to compute tiles in batch instead of one-by-one. This class is useful only when users may prefetch in advance groups of tiles by calls to the ImageProcessor.prefetch(RenderedImage, Rectangle) method.

Caching

Implementations should manage their own cache for avoiding to compute the same tiles many times. The caching mechanism inherited from ComputedImage is less useful here.
Since:
1.2
Version:
1.2
  • Field Details

  • Constructor Details

    • BatchComputedImage

      protected BatchComputedImage(SampleModel sampleModel, Map<String,Object> properties, RenderedImage... sources)
      Creates an initially empty image with the given sample model.
      Parameters:
      sampleModel - the sample model shared by all tiles in this image.
      properties - image properties (DeferredProperty supported), or null if none.
      sources - sources of this image (may be an empty array), or a null array if unknown.
  • Method Details

    • getProperty

      public Object getProperty(String key)
      Gets a property from this image.
      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.
    • computeTiles

      protected abstract Raster[] computeTiles(Rectangle tiles) throws Exception
      Computes immediately and returns all tiles in the given ranges of tile indices. Tiles shall be returned in row-major order. It is implementer responsibility to ensure that all rasters have consistent Raster.getMinX()/getMinY() values.
      Parameters:
      tiles - range of tile indices for which to precompute tiles.
      Returns:
      precomputed tiles for the given indices, in row-major fashion.
      Throws:
      Exception - if an error occurred when computing tiles.
    • computeTile

      protected final Raster computeTile(int tileX, int tileY, WritableRaster previous) throws Exception
      Invoked when a single tile need to be computed. This method first searches for the tile in the regions prepared by calls to prefetch(Rectangle). If the requested tile is not already fetched, then this method delegates to computeTiles(Rectangle).
      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.
      previous - ignored (this method creates a new raster on each invocation).
      Returns:
      computed tile for the given indices.
      Throws:
      Exception - if an error occurred while computing the tile.
    • prefetch

      protected Disposable prefetch(Rectangle region)
      Notifies this image that tiles will be computed soon in the given region.
      Overrides:
      prefetch in class ComputedImage
      Parameters:
      region - indices of the tiles which will be prefetched.
      Returns:
      handler on which to invoke dispose() after the prefetch operation.
    • remove

      private void remove(BatchComputedImage.Rasters tiles)
      Discards the given set of tiles. This method is invoked when the fetched tiles are no longer needed.
      Parameters:
      tiles - fetched tiles to removed from the prefetched linked list.