Interface ImageOp
- All Superinterfaces:
Op<BufferedImage>
- All Known Subinterfaces:
CropOp
,GamePieceOp
,RotateOp
,RotateScaleOp
,ScaleOp
,SourceOp
,SVGOp
- All Known Implementing Classes:
AbstractOpImpl
,AbstractTiledOpImpl
,AbstractTileOpImpl
,CropOpBitmapImpl
,FixedScaleOpBitmapImpl
,FixedScaleOpTiledBitmapImpl
,GamePieceOpImpl
,GridOp
,ImageItem.BaseOp
,ImageSourceOpBitmapImpl
,Labeler.HTMLLabelOp
,Labeler.LabelOp
,OrthoRotateOpBitmapImpl
,RotateScaleOpBitmapImpl
,RotateScaleOpSVGImpl
,ScaleOpBitmapImpl
,ScaleOpTiledBitmapImpl
,SolidColorOp
,SourceOpBitmapImpl
,SourceOpDiskCacheBitmapImpl
,SourceOpSVGImpl
,SourceOpTiledBitmapImpl
,SourceTileOpBitmapImpl
,SourceTileOpSVGImpl
ImageOp
is the interface for all such
operations. The results of all operations are memoized (using a
memory-sensitive cache), so retrieving results is both fast and
memory-efficient.
Warning: For efficiency reasons, no images retrieved from
an ImageOp
are returned defensively. That is, the
Image
returned is possibly the one retained internally by
the ImageOp
. Therefore, Image
s obtained from
an ImageOp
must not be altered, as this might
interfere with image caching. If an Image
obtained this way
needs to be modified, copy the Image
first and alter the
copy.
- Since:
- 3.1.0
- Author:
- Joel Uckelman
-
Method Summary
Modifier and TypeMethodDescriptioneval()
The image computation itself happens in this method.Submits a request for theBufferedImage
produced by this operation, and returns a reference to that request.getFutureTile
(int tileX, int tileY, ImageOpObserver obs) Submits a request for tile(tileX,tileY)
, and returns a reference to that request.getFutureTile
(Point p, ImageOpObserver obs) Submits a request for tile(tileX,tileY)
, and returns a reference to that request.int
Returns the height of theBufferedImage
which would be returned bygetImage()
.getImage()
Calculates theBufferedImage
produced by this operation.getImage
(ImageOpObserver obs) Calculates theBufferedImage
produced by this operation, and reports completion or failure to the specifiedImageOpObserver
.int
Returns the number of tiles along the x-axis.int
Returns the number of tiles along the y-axis.getSize()
Returns the size of theBufferedImage
which would be returned bygetImage()
.getTile
(int tileX, int tileY, ImageOpObserver obs) Calculates tile(tileX,tileY)
, and reports completion or failure to the specifiedImageOpObserver
.getTile
(Point p, ImageOpObserver obs) Calculates tile(p.x,p.y)
, and reports completion or failure to the specifiedImageOpObserver
.int
Returns the standard height of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
.Point[]
getTileIndices
(Rectangle rect) Returns an array ofPoint
s representing the tiles intersecting the givenRectangle
.getTileOp
(int tileX, int tileY) Returns anImageOp
which can produce the requested tile.Returns anImageOp
which can produce the requested tile.Returns the standard size of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
.int
Returns the standard width of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
.int
getWidth()
Returns the width of theBufferedImage
which would be returned bygetImage()
.Methods inherited from interface VASSAL.tools.opcache.Op
getSources, newKey, update
-
Method Details
-
eval
The image computation itself happens in this method.Warning: This method is not intended to be called from anywhere except
getImage()
.- Specified by:
eval
in interfaceOp<BufferedImage>
- Returns:
- the result of running this
Op
- Throws:
Exception
- The operation represented by thisImageOp
could be anything, so any exception may be thrown.
-
getImage
BufferedImage getImage()Calculates theBufferedImage
produced by this operation. Calls to this method are memoized to prevent redundant computations.Warning:
BufferedImage
s returned by this method must not be modified.- Returns:
- the resulting
BufferedImage
-
getImage
BufferedImage getImage(ImageOpObserver obs) throws CancellationException, InterruptedException, ExecutionException Calculates theBufferedImage
produced by this operation, and reports completion or failure to the specifiedImageOpObserver
. Calls to this method are memoized to prevent redundant computations. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation.When a non-blocking call is made (i.e., when
obs != null
), the cache is checked and if the image is found, it is returned immediately. If the image is already being calculated,obs
is notified when the pre-existing request completes. Otherwise, a new request is queued andobs
is notified when that completes.When a blocking call is made (i.e., when
obs == null
), the cache is checked and if the image is found, it is returned immediately. If the image is already being calculated, this method blocks on the completion of the existing calculation. Otherwise, a new calculation is started and this method blocks on it. In all cases, when a calculation is completed, the result is cached.Warning:
BufferedImage
s returned by this method must not be modified.- Parameters:
obs
- the observer to be notified on completion- Returns:
- the resulting
BufferedImage
- Throws:
CancellationException
- if the operation was cancelledInterruptedException
- if the operation was interruptedExecutionException
- if the operation failed- See Also:
-
getFutureImage
Submits a request for theBufferedImage
produced by this operation, and returns a reference to that request. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation.This implementation uses a memory-sensitive cache to memoize calls to
getFutureImage
. It returns aFuture<BufferedImage>
so that the request may be cancelled if no longer needed.Future
s are returned immediately, except in the case where the is no observer and no pre-existingFuture
for thisImageOp
'sBufferedImage
, in which case this method blocks on completion of the computation.Warning:
BufferedImage
s obtained from theFuture
s returned by this method must not be modified.- Parameters:
obs
- the observer to be notified on completion- Returns:
- a
Future
for the resultingBufferedImage
- Throws:
ExecutionException
- if the operation failed- See Also:
-
getSize
Dimension getSize()Returns the size of theBufferedImage
which would be returned bygetImage()
. The size is cached so that it need not be recalculated on each call.- Returns:
- the size of the resulting
BufferedImage
in pixels - See Also:
-
getWidth
int getWidth()Returns the width of theBufferedImage
which would be returned bygetImage()
. The width is cached so that it need not be recalculated on each call.- Returns:
- the width of the resulting
BufferedImage
in pixels - See Also:
-
getHeight
int getHeight()Returns the height of theBufferedImage
which would be returned bygetImage()
. The height is cached so that it need not be recalculated on each call.- Returns:
- the height of the resulting
BufferedImage
in pixels - See Also:
-
getTileSize
Dimension getTileSize()Returns the standard size of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
. Tiles which are in the extreme right column will not have full width if theBufferedImage
width is not an integral multiple of the tile width. Similarly, tiles in the bottom row will not have full height if theBufferedImage
height is not an integral multiple of the tile height.- Returns:
- the size of
BufferedImage
tiles in pixels - See Also:
-
getTileHeight
int getTileHeight()Returns the standard height of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
.- Returns:
- the height of
BufferedImage
tiles in pixels - See Also:
-
getTileWidth
int getTileWidth()Returns the standard width of theBufferedImage
tiles which are returned bygetTile(java.awt.Point, VASSAL.tools.imageop.ImageOpObserver)
.- Returns:
- the width of
BufferedImage
tiles in pixels - See Also:
-
getNumXTiles
int getNumXTiles()Returns the number of tiles along the x-axis. There will always be at least one column of tiles. The number of columns should equal(int) Math.ceil((double) getWidth() / getTileWidth())
.- Returns:
- the number of tiles along the x-axis
-
getNumYTiles
int getNumYTiles()Returns the number of tiles along the y-axis. There will always be at least one row of tiles. The number of rows should equal(int) Math.ceil((double) getHeight() / getTileHeight())
.- Returns:
- the number of tiles along the y-axis
-
getTile
BufferedImage getTile(Point p, ImageOpObserver obs) throws CancellationException, InterruptedException, ExecutionException Calculates tile(p.x,p.y)
, and reports completion or failure to the specifiedImageOpObserver
. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the mainBufferedImage
is(0,0)
. Note thatp.x
andp.y
are indices into the tile array, not pixel locations.This convenience method is equivalent to
getTile(p.x, p.y, obs)
.Warning:
BufferedImage
s returned by this method must not be modified.- Parameters:
p
- the position of the requested tileobs
- the observer- Returns:
- the resulting
BufferedImage
- Throws:
CancellationException
- if the operation was cancelledInterruptedException
- if the operation was interruptedExecutionException
- if the operation failed
-
getTile
BufferedImage getTile(int tileX, int tileY, ImageOpObserver obs) throws CancellationException, InterruptedException, ExecutionException Calculates tile(tileX,tileY)
, and reports completion or failure to the specifiedImageOpObserver
. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the mainBufferedImage
is(0,0)
. Note thattileX
andtileY
are indices into the tile array, not pixel locations.Warning:
BufferedImage
s returned by this method must not be modified.- Parameters:
tileX
- the x position of the requested tiletileY
- the y position of the requested tileobs
- the observer to be notified on completion- Returns:
- the resulting
BufferedImage
- Throws:
CancellationException
- if the operation was cancelledInterruptedException
- if the operation was interruptedExecutionException
- if the operation failed
-
getFutureTile
Submits a request for tile(tileX,tileY)
, and returns a reference to that request. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the mainBufferedImage
is(0,0)
. Note thattileX
andtileY
are indices into the tile array, not pixel locations.This convenience method is equivalent to
getFutureTile(p.x, p.y, obs)
.Warning:
BufferedImage
s obtained from theFuture
s returned by this method must not be modified.- Parameters:
p
- the position of the requested tileobs
- the observer to be notified on completion- Returns:
- a
Future
for the resultingBufferedImage
- Throws:
ExecutionException
- if the operation failed
-
getFutureTile
Future<BufferedImage> getFutureTile(int tileX, int tileY, ImageOpObserver obs) throws ExecutionException Submits a request for tile(tileX,tileY)
, and returns a reference to that request. If a non-null
observer is given, then the operation may be done asynchronously. If the observer isnull
, then this method will block on completion of the operation. Tiles are numbered from zero, so the tile in the upper-left corner of the mainBufferedImage
is(0,0)
. Note thattileX
andtileY
are indices into the tile array, not pixel locations.Warning:
BufferedImage
s obtained from theFuture
s returned by this method must not be modified.- Parameters:
tileX
- the x position of the requested tiletileY
- the y position of the requested tileobs
- the observer to be notified on completion- Returns:
- a
Future
for the resultingBufferedImage
- Throws:
ExecutionException
- if the operation failed
-
getTileOp
-
getTileOp
Returns anImageOp
which can produce the requested tile.- Parameters:
tileX
- the x position of the requested tiletileY
- the y position of the requested tile- Returns:
- the
ImageOp
which produces the requested tile
-
getTileIndices
Returns an array ofPoint
s representing the tiles intersecting the givenRectangle
.- Parameters:
rect
- the rectangle- Returns:
- the positions of the tiles hit by the rectangle
- Throws:
IllegalArgumentException
- ifrect == null
.
-