Class PrefetchedImage

java.lang.Object
org.apache.sis.image.PlanarImage
org.apache.sis.image.PrefetchedImage
All Implemented Interfaces:
RenderedImage, TileErrorHandler.Executor

final class PrefetchedImage extends PlanarImage implements TileErrorHandler.Executor
An image which delegate all tile requests to another image except for some tiles that are fetched in advance. This image has the same coordinate systems than the source image.
Since:
1.1
Version:
1.3
See Also:
  • Field Details

    • source

      final RenderedImage source
      The source image from which to prefetch tiles.
    • minTileX

      private final int minTileX
      Index of the first prefetched tile. This index is determined from the area of interest (AOI) specified at construction time; it is not necessarily the index of the first tile in the image.
    • minTileY

      private final int minTileY
      Index of the first prefetched tile. This index is determined from the area of interest (AOI) specified at construction time; it is not necessarily the index of the first tile in the image.
    • numXTiles

      private final int numXTiles
      Number of prefetched tiles. This number is determined from the area of interest (AOI) specified at construction time; it is not necessarily include all tiles in the image.
    • numYTiles

      private final int numYTiles
      Number of prefetched tiles. This number is determined from the area of interest (AOI) specified at construction time; it is not necessarily include all tiles in the image.
    • tiles

      private final Raster[] tiles
      The prefetched tiles. This array contains only the tiles in the area of interest (AOI) specified at construction time; it does not necessarily contains all tiles in the image. Some element may be null if an error occurred while computing that tile, in which case a placeholder will be computed by getTile(int, int).
    • placeholderPixels

      private volatile TilePlaceholder placeholderPixels
      If error(s) occurred while computing one or more tiles, data shared by Raster placeholders. This is data for a tile showing a cross (X) in a box.
      See Also:
    • errorReport

      private ErrorHandler.Report errorReport
      Non-null if errors should be handled during getTile(int, int) execution for tiles outside the area of interest specified at construction time.
      See Also:
  • Constructor Details

    • PrefetchedImage

      PrefetchedImage(RenderedImage source, Rectangle areaOfInterest, ErrorHandler errorHandler, boolean parallel)
      Creates a new prefetched image.
      Parameters:
      source - the image to compute immediately (may be null).
      areaOfInterest - pixel coordinates of the region to prefetch, or null for the whole image.
      errorHandler - action to execute (throw an exception or log a warning) if an error occurs.
      parallel - whether to execute computation in parallel.
  • Method Details

    • isEmpty

      final boolean isEmpty()
      Returns true if this image does not prefetch any tiles.
    • getSources

      public Vector<RenderedImage> getSources()
      Returns the immediate source of image data for this image.
      Specified by:
      getSources in interface RenderedImage
      Overrides:
      getSources in class PlanarImage
      Returns:
      the immediate sources, or null if unknown.
    • getProperty

      public Object getProperty(String name)
      Gets a property from the source image. All properties are inherited from the source with no change.
      Specified by:
      getProperty in interface RenderedImage
      Overrides:
      getProperty in class PlanarImage
      Parameters:
      name - the name of the property to get.
      Returns:
      the property value, or Image.UndefinedProperty if none.
    • getPropertyNames

      public String[] getPropertyNames()
      Delegate to the source image.
      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()
      Specified by:
      getColorModel in interface RenderedImage
    • getSampleModel

      public SampleModel getSampleModel()
      Specified by:
      getSampleModel in interface RenderedImage
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface RenderedImage
    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface RenderedImage
    • getMinX

      public int getMinX()
      Description copied from class: PlanarImage
      Returns the minimum x coordinate (inclusive) of this image.

      Default implementation returns zero. Subclasses shall override this method if the image starts at another coordinate.

      Specified by:
      getMinX in interface RenderedImage
      Overrides:
      getMinX in class PlanarImage
      Returns:
      the minimum x coordinate (column) of this image.
    • getMinY

      public int getMinY()
      Description copied from class: PlanarImage
      Returns the minimum y coordinate (inclusive) of this image.

      The default implementation returns zero. Subclasses shall override this method if the image starts at another coordinate.

      Specified by:
      getMinY in interface RenderedImage
      Overrides:
      getMinY in class PlanarImage
      Returns:
      the minimum y coordinate (row) of this image.
    • getNumXTiles

      public int getNumXTiles()
      Description copied from class: PlanarImage
      Returns the number of tiles in the x direction.

      The default implementation computes this value from RenderedImage.getWidth() and RenderedImage.getTileWidth() on the assumption that PlanarImage.getMinX() is the coordinate of the leftmost pixels of tiles located at PlanarImage.getMinTileX() index. This assumption can be verified by PlanarImage.verify().

      Specified by:
      getNumXTiles in interface RenderedImage
      Overrides:
      getNumXTiles in class PlanarImage
      Returns:
      returns the number of tiles in the x direction.
    • getNumYTiles

      public int getNumYTiles()
      Description copied from class: PlanarImage
      Returns the number of tiles in the y direction.

      The default implementation computes this value from RenderedImage.getHeight() and RenderedImage.getTileHeight() on the assumption that PlanarImage.getMinY() is the coordinate of the uppermost pixels of tiles located at PlanarImage.getMinTileY() index. This assumption can be verified by PlanarImage.verify().

      Specified by:
      getNumYTiles in interface RenderedImage
      Overrides:
      getNumYTiles in class PlanarImage
      Returns:
      returns the number of tiles in the y direction.
    • getMinTileX

      public int getMinTileX()
      Description copied from class: PlanarImage
      Returns the minimum tile index in the x direction.

      The default implementation returns zero. Subclasses shall override this method if the tile grid starts at another index.

      Specified by:
      getMinTileX in interface RenderedImage
      Overrides:
      getMinTileX in class PlanarImage
      Returns:
      the minimum tile index in the x direction.
    • getMinTileY

      public int getMinTileY()
      Description copied from class: PlanarImage
      Returns the minimum tile index in the y direction.

      The default implementation returns zero. Subclasses shall override this method if the tile grid starts at another index.

      Specified by:
      getMinTileY in interface RenderedImage
      Overrides:
      getMinTileY in class PlanarImage
      Returns:
      the minimum tile index in the y direction.
    • getTileWidth

      public int getTileWidth()
      Specified by:
      getTileWidth in interface RenderedImage
    • getTileHeight

      public int getTileHeight()
      Specified by:
      getTileHeight in interface RenderedImage
    • getTileGridXOffset

      public int getTileGridXOffset()
      Description copied from class: PlanarImage
      Returns the x coordinate of the upper-left pixel of tile (0, 0). That tile (0, 0) may not actually exist.

      The default implementation computes this value from PlanarImage.getMinX(), PlanarImage.getMinTileX() and RenderedImage.getTileWidth().

      Specified by:
      getTileGridXOffset in interface RenderedImage
      Overrides:
      getTileGridXOffset in class PlanarImage
      Returns:
      the x offset of the tile grid relative to the origin.
    • getTileGridYOffset

      public int getTileGridYOffset()
      Description copied from class: PlanarImage
      Returns the y coordinate of the upper-left pixel of tile (0, 0). That tile (0, 0) may not actually exist.

      The default implementation computes this value from PlanarImage.getMinY(), PlanarImage.getMinTileY() and RenderedImage.getTileHeight().

      Specified by:
      getTileGridYOffset in interface RenderedImage
      Overrides:
      getTileGridYOffset in class PlanarImage
      Returns:
      the y offset of the tile grid relative to the origin.
    • getTile

      public Raster getTile(int tileX, int tileY)
      Returns the tile at the given location in tile coordinates. If the requested tile is in the region of prefetched tiles, that tile is returned directly. Otherwise this method delegates to the source image.
      Specified by:
      getTile in interface RenderedImage
    • execute

      public void execute(Runnable action, TileErrorHandler errorHandler)
      Executes the given action in a mode where errors occurring in RenderedImage.getTile(int, int) are reported to the given handler instead of stopping the operation. The given action is typically some operation invoking, directly or indirectly, getTile(int, int) with tile indices that may be outside the area of interest specified at construction time. Exceptions that occurred inside the area of interest were caught by the constructor and this method makes no difference for them. But exceptions occurring outside that area are interest are redirected to the source image, which may fail. This method provides a way to catch also those errors.
      Specified by:
      execute in interface TileErrorHandler.Executor
      Parameters:
      action - the action to execute (for example drawing the image).
      errorHandler - the handler to notify if errors occur.
    • createPlaceholder

      private Raster createPlaceholder(int tileX, int tileY)
      Creates a tile to use as a placeholder when a tile cannot be computed.
      Parameters:
      tileX - column index of the tile for which to create a placeholder.
      tileY - row index of the tile for which to create a placeholder.
      Returns:
      placeholder for the tile at given indices.
    • hashCode

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

      public boolean equals(Object object)
      Compares the given object with this image for equality. This is defined as a matter of principle, but is a little bit useless for PrefetchedImage because tiles have already been computed in the constructor. So it is too late for caching for example.
      Overrides:
      equals in class Object