Class PrefetchedImage
- All Implemented Interfaces:
RenderedImage
,TileErrorHandler.Executor
- Since:
- 1.1
- Version:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate final class
A worker for prefetching tiles in an image. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ErrorHandler.Report
Non-null if errors should be handled duringgetTile(int, int)
execution for tiles outside the area of interest specified at construction time.private final int
Index of the first prefetched tile.private final int
Index of the first prefetched tile.private final int
Number of prefetched tiles.private final int
Number of prefetched tiles.private TilePlaceholder
If error(s) occurred while computing one or more tiles, data shared byRaster
placeholders.(package private) final RenderedImage
The 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 Raster
createPlaceholder
(int tileX, int tileY) Creates a tile to use as a placeholder when a tile cannot be computed.boolean
Compares the given object with this image for equality.void
execute
(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.int
int
Returns the minimum tile index in the x direction.int
Returns the minimum tile index in the y direction.int
getMinX()
Returns the minimum x coordinate (inclusive) of this image.int
getMinY()
Returns the minimum y coordinate (inclusive) of this image.int
Returns the number of tiles in the x direction.int
Returns 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.int
Returns the x coordinate of the upper-left pixel of tile (0, 0).int
Returns the y coordinate of the upper-left pixel of tile (0, 0).int
int
int
getWidth()
int
hashCode()
Returns a hash code value for this image.(package private) final boolean
isEmpty()
Returnstrue
if 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 benull
if 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 byRaster
placeholders. 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, ornull
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()Returnstrue
if this image does not prefetch any tiles. -
getSources
Returns the immediate source of image data for this image.- Specified by:
getSources
in interfaceRenderedImage
- Overrides:
getSources
in classPlanarImage
- Returns:
- the immediate sources, or
null
if unknown.
-
getProperty
Gets a property from the source image. All properties are inherited from the source with no change.- Specified by:
getProperty
in interfaceRenderedImage
- Overrides:
getProperty
in classPlanarImage
- Parameters:
name
- the name of the property to get.- Returns:
- the property value, or
Image.UndefinedProperty
if none.
-
getPropertyNames
Delegate to the source image.- Specified by:
getPropertyNames
in interfaceRenderedImage
- Overrides:
getPropertyNames
in classPlanarImage
- Returns:
- names of all recognized properties, or
null
if none.
-
getColorModel
- Specified by:
getColorModel
in interfaceRenderedImage
-
getSampleModel
- Specified by:
getSampleModel
in interfaceRenderedImage
-
getWidth
public int getWidth()- Specified by:
getWidth
in interfaceRenderedImage
-
getHeight
public int getHeight()- Specified by:
getHeight
in interfaceRenderedImage
-
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 interfaceRenderedImage
- Overrides:
getMinX
in classPlanarImage
- 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 interfaceRenderedImage
- Overrides:
getMinY
in classPlanarImage
- 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()
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:
getNumXTiles
in interfaceRenderedImage
- Overrides:
getNumXTiles
in classPlanarImage
- 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()
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:
getNumYTiles
in interfaceRenderedImage
- Overrides:
getNumYTiles
in classPlanarImage
- 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 interfaceRenderedImage
- Overrides:
getMinTileX
in classPlanarImage
- 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 interfaceRenderedImage
- Overrides:
getMinTileY
in classPlanarImage
- Returns:
- the minimum tile index in the y direction.
-
getTileWidth
public int getTileWidth()- Specified by:
getTileWidth
in interfaceRenderedImage
-
getTileHeight
public int getTileHeight()- Specified by:
getTileHeight
in interfaceRenderedImage
-
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()
andRenderedImage.getTileWidth()
.- Specified by:
getTileGridXOffset
in interfaceRenderedImage
- Overrides:
getTileGridXOffset
in classPlanarImage
- 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()
andRenderedImage.getTileHeight()
.- Specified by:
getTileGridYOffset
in interfaceRenderedImage
- Overrides:
getTileGridYOffset
in 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:
getTile
in 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 thesource
image, which may fail. This method provides a way to catch also those errors.- Specified by:
execute
in 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 forPrefetchedImage
because tiles have already been computed in the constructor. So it is too late for caching for example.
-