Class PrefetchedImage
- All Implemented Interfaces:
RenderedImage,TileErrorHandler.Executor
- Since:
- 1.1
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final classA worker for prefetching tiles in an image. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ErrorHandler.ReportNon-null if errors should be handled duringgetTile(int, int)execution for tiles outside the area of interest specified at construction time.private final intIndex of the first prefetched tile.private final intIndex of the first prefetched tile.private final intNumber of prefetched tiles.private final intNumber of prefetched tiles.private TilePlaceholderIf error(s) occurred while computing one or more tiles, data shared byRasterplaceholders.(package private) final RenderedImageThe source image from which to prefetch tiles.private final Raster[]The prefetched tiles.Fields inherited from class org.apache.sis.image.PlanarImage
GRID_GEOMETRY_KEY, MASK_KEY, POSITIONAL_ACCURACY_KEY, SAMPLE_RESOLUTIONS_KEY, STATISTICS_KEY -
Constructor Summary
ConstructorsConstructorDescriptionPrefetchedImage(RenderedImage source, Rectangle areaOfInterest, ErrorHandler errorHandler, boolean parallel) Creates a new prefetched image. -
Method Summary
Modifier and TypeMethodDescriptionprivate RastercreatePlaceholder(int tileX, int tileY) Creates a tile to use as a placeholder when a tile cannot be computed.booleanCompares the given object with this image for equality.voidexecute(Runnable action, TileErrorHandler errorHandler) Executes the given action in a mode where errors occurring inRenderedImage.getTile(int, int)are reported to the given handler instead of stopping the operation.intintReturns the minimum tile index in the x direction.intReturns the minimum tile index in the y direction.intgetMinX()Returns the minimum x coordinate (inclusive) of this image.intgetMinY()Returns the minimum y coordinate (inclusive) of this image.intReturns the number of tiles in the x direction.intReturns the number of tiles in the y direction.getProperty(String name) Gets a property from the source image.String[]Delegate to the source image.Returns the immediate source of image data for this image.getTile(int tileX, int tileY) Returns the tile at the given location in tile coordinates.intReturns the x coordinate of the upper-left pixel of tile (0, 0).intReturns the y coordinate of the upper-left pixel of tile (0, 0).intintintgetWidth()inthashCode()Returns a hash code value for this image.(package private) final booleanisEmpty()Returnstrueif this image does not prefetch any tiles.
-
Field Details
-
source
The source image from which to prefetch tiles. -
minTileX
private final int minTileXIndex 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 minTileYIndex 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 numXTilesNumber 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 numYTilesNumber 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
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 benullif an error occurred while computing that tile, in which case a placeholder will be computed bygetTile(int, int). -
placeholderPixels
If error(s) occurred while computing one or more tiles, data shared byRasterplaceholders. This is data for a tile showing a cross (X) in a box.- See Also:
-
errorReport
Non-null if errors should be handled duringgetTile(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 benull).areaOfInterest- pixel coordinates of the region to prefetch, ornullfor 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()Returnstrueif this image does not prefetch any tiles. -
getSources
Returns the immediate source of image data for this image.- Specified by:
getSourcesin interfaceRenderedImage- Overrides:
getSourcesin classPlanarImage- Returns:
- the immediate sources, or
nullif unknown.
-
getProperty
Gets a property from the source image. All properties are inherited from the source with no change.- Specified by:
getPropertyin interfaceRenderedImage- Overrides:
getPropertyin classPlanarImage- Parameters:
name- the name of the property to get.- Returns:
- the property value, or
Image.UndefinedPropertyif none.
-
getPropertyNames
Delegate to the source image.- Specified by:
getPropertyNamesin interfaceRenderedImage- Overrides:
getPropertyNamesin classPlanarImage- Returns:
- names of all recognized properties, or
nullif none.
-
getColorModel
- Specified by:
getColorModelin interfaceRenderedImage
-
getSampleModel
- Specified by:
getSampleModelin interfaceRenderedImage
-
getWidth
public int getWidth()- Specified by:
getWidthin interfaceRenderedImage
-
getHeight
public int getHeight()- Specified by:
getHeightin interfaceRenderedImage
-
getMinX
public int getMinX()Description copied from class:PlanarImageReturns 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:
getMinXin interfaceRenderedImage- Overrides:
getMinXin classPlanarImage- Returns:
- the minimum x coordinate (column) of this image.
-
getMinY
public int getMinY()Description copied from class:PlanarImageReturns 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:
getMinYin interfaceRenderedImage- Overrides:
getMinYin classPlanarImage- Returns:
- the minimum y coordinate (row) of this image.
-
getNumXTiles
public int getNumXTiles()Description copied from class:PlanarImageReturns the number of tiles in the x direction.The default implementation computes this value from
RenderedImage.getWidth()andRenderedImage.getTileWidth()on the assumption thatPlanarImage.getMinX()is the coordinate of the leftmost pixels of tiles located atPlanarImage.getMinTileX()index. This assumption can be verified byPlanarImage.verify().- Specified by:
getNumXTilesin interfaceRenderedImage- Overrides:
getNumXTilesin classPlanarImage- Returns:
- returns the number of tiles in the x direction.
-
getNumYTiles
public int getNumYTiles()Description copied from class:PlanarImageReturns the number of tiles in the y direction.The default implementation computes this value from
RenderedImage.getHeight()andRenderedImage.getTileHeight()on the assumption thatPlanarImage.getMinY()is the coordinate of the uppermost pixels of tiles located atPlanarImage.getMinTileY()index. This assumption can be verified byPlanarImage.verify().- Specified by:
getNumYTilesin interfaceRenderedImage- Overrides:
getNumYTilesin classPlanarImage- Returns:
- returns the number of tiles in the y direction.
-
getMinTileX
public int getMinTileX()Description copied from class:PlanarImageReturns 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:
getMinTileXin interfaceRenderedImage- Overrides:
getMinTileXin classPlanarImage- Returns:
- the minimum tile index in the x direction.
-
getMinTileY
public int getMinTileY()Description copied from class:PlanarImageReturns 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:
getMinTileYin interfaceRenderedImage- Overrides:
getMinTileYin classPlanarImage- Returns:
- the minimum tile index in the y direction.
-
getTileWidth
public int getTileWidth()- Specified by:
getTileWidthin interfaceRenderedImage
-
getTileHeight
public int getTileHeight()- Specified by:
getTileHeightin interfaceRenderedImage
-
getTileGridXOffset
public int getTileGridXOffset()Description copied from class:PlanarImageReturns 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()andRenderedImage.getTileWidth().- Specified by:
getTileGridXOffsetin interfaceRenderedImage- Overrides:
getTileGridXOffsetin classPlanarImage- Returns:
- the x offset of the tile grid relative to the origin.
-
getTileGridYOffset
public int getTileGridYOffset()Description copied from class:PlanarImageReturns 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()andRenderedImage.getTileHeight().- Specified by:
getTileGridYOffsetin interfaceRenderedImage- Overrides:
getTileGridYOffsetin classPlanarImage- Returns:
- the y offset of the tile grid relative to the origin.
-
getTile
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:
getTilein interfaceRenderedImage
-
execute
Executes the given action in a mode where errors occurring inRenderedImage.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 thesourceimage, which may fail. This method provides a way to catch also those errors.- Specified by:
executein interfaceTileErrorHandler.Executor- Parameters:
action- the action to execute (for example drawing the image).errorHandler- the handler to notify if errors occur.
-
createPlaceholder
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 withequals(Object). -
equals
Compares the given object with this image for equality. This is defined as a matter of principle, but is a little bit useless forPrefetchedImagebecause tiles have already been computed in the constructor. So it is too late for caching for example.
-