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 ShapeThe clip in pixel coordinates.private TilePlaceholderA provider of empty tiles.private final FillValuesValues to assign to the pixels to mask.private RectangleBounds of the clip in pixels coordinates and in tile coordinates.private final booleantruefor masking pixels inside the shape, orfalsefor masking pixels outside the shape.private SoftReference<ByteBuffer>The clip after rasterization.private intNumber of pixels (bits) to skip for reaching the same column of next line (scanline stride).private RectangleBounds of the clip in pixels coordinates and in tile coordinates.Fields inherited from class org.apache.sis.image.SourceAlignedImage
POSITIONAL_PROPERTIESFields inherited from class org.apache.sis.image.ComputedImage
sampleModel, SOURCE_PADDING_KEYFields 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 RastercomputeTile(int tileX, int tileY, WritableRaster tile) Invoked when a tile need to be computed or updated.private RastercreateEmptyTile(int xmin, int ymin) Returns an empty tile starting at the given pixel coordinates.booleanCompares the given object with this image for equality.private ByteBuffergetMask()Returns pixel values of the mask in a multi pixel packed array.private RectangleReturns 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.inthashCode()Returns a hash code value for this image.private booleanneedCreate(WritableRaster tile, Raster source) Returnstrueif 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, prefetchMethods 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 maskInsidetruefor masking pixels inside the shape, orfalsefor 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-truefor masking pixels inside the shape, orfalsefor masking outside.fillValues- values to assign to pixels outside clip area, ornullfor default values.
-
-
Method Details
-
getProperty
Gets a property from this image.- Specified by:
getPropertyin interfaceRenderedImage- Overrides:
getPropertyin classPlanarImage- Parameters:
key- the name of the property to get.- Returns:
- the property value, or
Image.UndefinedPropertyif none.
-
getPropertyNames
Returns the names of all recognized properties.- Specified by:
getPropertyNamesin interfaceRenderedImage- Overrides:
getPropertyNamesin classPlanarImage- Returns:
- names of all recognized properties, or
nullif 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:
computeTilein 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
Returnstrueif 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:
trueif given tile is null or should not be modified.
-
equals
Compares the given object with this image for equality. This method returnstrueif 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:
equalsin classSourceAlignedImage- Parameters:
object- the object to compare with this image.- Returns:
trueif 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:
hashCodein classSourceAlignedImage- Returns:
- a hash code value based on a description of the operation performed by this image.
-