Package org.apache.sis.image
Class MaskedImage
java.lang.Object
org.apache.sis.image.PlanarImage
org.apache.sis.image.ComputedImage
org.apache.sis.image.SourceAlignedImage
org.apache.sis.image.MaskedImage
- All Implemented Interfaces:
RenderedImage
,Disposable
An image which is the result of clearing all pixels inside or outside a geometry.
The geometry shall be expressed in pixel coordinates.
- Since:
- 1.2
- Version:
- 1.2
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Shape
The clip in pixel coordinates.private TilePlaceholder
A provider of empty tiles.private final FillValues
Values to assign to the pixels to mask.private Rectangle
Bounds of the clip in pixels coordinates and in tile coordinates.private final boolean
true
for masking pixels inside the shape, orfalse
for masking pixels outside the shape.private SoftReference
<ByteBuffer> The clip after rasterization.private int
Number of pixels (bits) to skip for reaching the same column of next line (scanline stride).private Rectangle
Bounds of the clip in pixels coordinates and in tile coordinates.Fields inherited from class org.apache.sis.image.SourceAlignedImage
POSITIONAL_PROPERTIES
Fields inherited from class org.apache.sis.image.ComputedImage
sampleModel, SOURCE_PADDING_KEY
Fields inherited from class org.apache.sis.image.PlanarImage
GRID_GEOMETRY_KEY, MASK_KEY, POSITIONAL_ACCURACY_KEY, SAMPLE_RESOLUTIONS_KEY, STATISTICS_KEY
-
Constructor Summary
ConstructorsConstructorDescriptionMaskedImage
(RenderedImage source, Shape clip, boolean maskInside, Number[] fillValues) Creates a new image with the given source image and clip. -
Method Summary
Modifier and TypeMethodDescriptionprotected Raster
computeTile
(int tileX, int tileY, WritableRaster tile) Invoked when a tile need to be computed or updated.private Raster
createEmptyTile
(int xmin, int ymin) Returns an empty tile starting at the given pixel coordinates.boolean
Compares the given object with this image for equality.private ByteBuffer
getMask()
Returns pixel values of the mask in a multi pixel packed array.private Rectangle
Returns the bounds of the clip in tile coordinates.getProperty
(String key) Gets a property from this image.String[]
Returns the names of all recognized properties.int
hashCode()
Returns a hash code value for this image.private boolean
needCreate
(WritableRaster tile, Raster source) Returnstrue
if the given tile should be discarded and a new tile created before to write pixel values.Methods inherited from class org.apache.sis.image.SourceAlignedImage
filterPropertyNames, getColorModel, getHeight, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, prefetch
Methods inherited from class org.apache.sis.image.ComputedImage
clearErrorFlags, createTile, dispose, equalsBase, getDestination, getSampleModel, getSource, getSource, getSources, getTile, getWritableTileIndices, hashCodeBase, hasTileWriters, isTileWritable, markDirtyTiles, markTileWritable, reference, setDestination, sourceTileChanged
-
Field Details
-
clip
The clip in pixel coordinates. -
maskInside
private final boolean maskInsidetrue
for masking pixels inside the shape, orfalse
for masking pixels outside the shape. -
maskBounds
Bounds of the clip in pixels coordinates and in tile coordinates. The latter provides a fast way to determine if a tile intersects the mask. The bounds are computed together when first needed.- See Also:
-
maskTiles
Bounds of the clip in pixels coordinates and in tile coordinates. The latter provides a fast way to determine if a tile intersects the mask. The bounds are computed together when first needed.- See Also:
-
maskRef
The clip after rasterization. Each element contains 8 pixel values. Index of pixel value at coordinate (x,y) can be obtained as below:- See Also:
-
maskScanlineStride
private transient int maskScanlineStrideNumber of pixels (bits) to skip for reaching the same column of next line (scanline stride). This is the image width rounded to the next multiple of 8 (integer amount of bytes). -
fillValues
Values to assign to the pixels to mask. -
emptyTiles
A provider of empty tiles. All empty tiles will share the same data buffer for saving memory.
-
-
Constructor Details
-
MaskedImage
MaskedImage(RenderedImage source, Shape clip, boolean maskInside, Number[] fillValues) Creates a new image with the given source image and clip.- Parameters:
source
- the image from which to copy pixel values.clip
- the clip or mask in pixel coordinates.maskInside
-true
for masking pixels inside the shape, orfalse
for masking outside.fillValues
- values to assign to pixels outside clip area, ornull
for default values.
-
-
Method Details
-
getProperty
Gets a property from this image.- Specified by:
getProperty
in interfaceRenderedImage
- Overrides:
getProperty
in classPlanarImage
- Parameters:
key
- the name of the property to get.- Returns:
- the property value, or
Image.UndefinedProperty
if none.
-
getPropertyNames
Returns the names of all recognized properties.- Specified by:
getPropertyNames
in interfaceRenderedImage
- Overrides:
getPropertyNames
in classPlanarImage
- Returns:
- names of all recognized properties, or
null
if none.
-
getMaskTiles
Returns the bounds of the clip in tile coordinates. It provides a fast way to determine if a tile intersects the mask. -
getMask
Returns pixel values of the mask in a multi pixel packed array. After conversion toLongBuffer
, index of pixel value at coordinate (x,y) can be obtained as below:Pre-conditions
ThegetMaskTiles()
method must have been invoked at least once before this method. -
computeTile
Invoked when a tile need to be computed or updated. May be invoked concurrently in different threads.- Specified by:
computeTile
in classComputedImage
- Parameters:
tileX
- the column index of the tile to compute.tileY
- the row index of the tile to compute.tile
- if the tile already exists but needs to be updated, the tile to update. Otherwisenull
.- Returns:
- computed tile for the given indices.
-
createEmptyTile
Returns an empty tile starting at the given pixel coordinates. Each empty tile will share its data buffer with other empty tiles, including from other images using the same sample model. -
needCreate
Returnstrue
if the given tile should be discarded and a new tile created before to write pixel values.- Parameters:
tile
- the tile to potentially reuse. Can benull
.source
- the corresponding tile from source image.- Returns:
true
if given tile is null or should not be modified.
-
equals
Compares the given object with this image for equality. This method returnstrue
if the given object is non-null, is an instance of the exact same class than this image, has equal sources, clip and fill values.- Overrides:
equals
in classSourceAlignedImage
- Parameters:
object
- the object to compare with this image.- Returns:
true
if the given object is an image performing the same clipping than this image.
-
hashCode
public int hashCode()Returns a hash code value for this image.- Overrides:
hashCode
in classSourceAlignedImage
- Returns:
- a hash code value based on a description of the operation performed by this image.
-