Class SourceAlignedImage
- All Implemented Interfaces:
RenderedImage
,Disposable
- Direct Known Subclasses:
BandSelectImage
,MaskedImage
,MaskImage
,PositionalConsistencyImage
ComputedImage
javadoc for more information about tile computation.
This class is similar to
ImageAdapter
except that it extends ComputedImage
and does not forward ComputedImage.getTile(int, int)
, PlanarImage.getData()
and other data methods
to the source image.Sub-classing
Subclasses need to implement at least theComputedImage.computeTile(int, int, WritableRaster)
method.
That method is invoked when a requested tile is not in the cache or needs to be updated.
All methods related to pixel and tile coordinates (getMinX()
, getMinTileX()
,
etc.) are final and delegate to the source image.
The equals(Object)
and hashCode()
methods should also be overridden.- Since:
- 1.1
- Version:
- 1.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ColorModel
The color model for this image.Convenience collection for subclasses that inherit all properties related to positioning.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
ConstructorsModifierConstructorDescriptionprotected
SourceAlignedImage
(RenderedImage source) Creates a new image with the given source.protected
SourceAlignedImage
(RenderedImage source, ColorModel colorModel) Creates a new image with the given source and a sample model derived from the given color model.(package private)
SourceAlignedImage
(RenderedImage source, ColorModel colorModel, SampleModel sampleModel) Creates a new image with the given source, color model and sample model. -
Method Summary
Modifier and TypeMethodDescriptionprivate static SampleModel
createSampleModel
(ColorModel colorModel, SampleModel original) Creates the sample model.boolean
Compares the given object with this image for equality.(package private) static String[]
filterPropertyNames
(String[] names, Set<String> inherit, String[] append) Returns the names of properties as a merge between source properties (after filtering) and properties added by the subclass.final ColorModel
Returns the color model associated with this image.final int
final int
Returns the minimum tile index in the x direction.final int
Returns the minimum tile index in the y direction.final int
getMinX()
Delegates to source image.final int
getMinY()
Returns the minimum y coordinate (inclusive) of this image.final int
Returns the number of tiles in the x direction.final int
Returns the number of tiles in the y direction.private static SampleModel
getSampleModel
(RenderedImage source) Gets the sample model, making sure it has the right size.final int
Returns the x coordinate of the upper-left pixel of tile (0, 0).final int
Returns the y coordinate of the upper-left pixel of tile (0, 0).final int
Returns the height of tiles in this image.final int
Returns the width of tiles in this image.final int
getWidth()
int
hashCode()
Returns a hash code value for this image.protected Disposable
Notifies the source image that tiles will be computed soon in the given region.Methods inherited from class org.apache.sis.image.ComputedImage
clearErrorFlags, computeTile, createTile, dispose, equalsBase, getDestination, getSampleModel, getSource, getSource, getSources, getTile, getWritableTileIndices, hashCodeBase, hasTileWriters, isTileWritable, markDirtyTiles, markTileWritable, reference, setDestination, sourceTileChanged
Methods inherited from class org.apache.sis.image.PlanarImage
copyData, getBounds, getData, getData, getProperty, getPropertyNames, toString, verify
-
Field Details
-
POSITIONAL_PROPERTIES
Convenience collection for subclasses that inherit all properties related to positioning. May be used as theinherit
argument infilterPropertyNames(String[], Set, String[])
. Inheriting those properties make sense for operations that do not change pixel coordinates. -
colorModel
The color model for this image. May benull
.
-
-
Constructor Details
-
SourceAlignedImage
Creates a new image with the given source. This image inherit the color model and sample model of source image.- Parameters:
source
- the image to use as a background for this image.
-
SourceAlignedImage
SourceAlignedImage(RenderedImage source, ColorModel colorModel, SampleModel sampleModel) Creates a new image with the given source, color model and sample model. This constructor is not public because user could specify a sample model with mismatched tile size.- Parameters:
source
- source of this image. Shall not be null.colorModel
- the color model of the new image.sampleModel
- the sample model of the new image.
-
SourceAlignedImage
Creates a new image with the given source and a sample model derived from the given color model. The new image will have the same tile size than the given image.- Parameters:
source
- source of this image. Shall not be null.colorModel
- the color model of the new image.
-
-
Method Details
-
getSampleModel
@Workaround(library="JDK", version="1.8") private static SampleModel getSampleModel(RenderedImage source) Gets the sample model, making sure it has the right size. This is a workaround for RFE #4093999 ("Relax constraint on placement of this()/super() call in constructors"). -
createSampleModel
@Workaround(library="JDK", version="1.8") private static SampleModel createSampleModel(ColorModel colorModel, SampleModel original) Creates the sample model. This is a workaround for RFE #4093999 ("Relax constraint on placement of this()/super() call in constructors"). -
getColorModel
Returns the color model associated with this image.- Returns:
- the color model, or
null
if none.
-
filterPropertyNames
Returns the names of properties as a merge between source properties (after filtering) and properties added by the subclass. This is a helper method forPlanarImage.getPropertyNames()
implementations in subclasses.The
names
argument should be the result of invokingRenderedImage.getPropertyNames()
on the source image. This method modifies directly that array returned bygetPropertyNames()
on the assumption that the array is already a copy. This assumption is okay when the source is known to be an Apache SIS implementation.- Parameters:
names
- names of properties to filter, ornull
if none. If non-null, this array will be modified in-place.inherit
- properties to inherit from the source.append
- properties to append, ornull
if none.- Returns:
- properties recognized by this image, or
null
if none.
-
getMinX
public final int getMinX()Delegates to source image.- Specified by:
getMinX
in interfaceRenderedImage
- Overrides:
getMinX
in classPlanarImage
- Returns:
- the minimum x coordinate (column) of this image.
-
getMinY
public final 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.
-
getWidth
public final int getWidth() -
getHeight
public final int getHeight() -
getMinTileX
public final 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 final 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.
-
getNumXTiles
public final 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 final 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.
-
getTileWidth
public final int getTileWidth()Description copied from class:ComputedImage
Returns the width of tiles in this image. The default implementation returnsSampleModel.getWidth()
.Note: a raster can have a smaller width than its sample model, for example when a raster is a view over a subregion of another raster. But this is not recommended in the particular case of thisComputedImage
class, because it would causeComputedImage.createTile(int, int)
to consume more memory than necessary.- Specified by:
getTileWidth
in interfaceRenderedImage
- Overrides:
getTileWidth
in classComputedImage
- Returns:
- the width of this image in pixels.
-
getTileHeight
public final int getTileHeight()Description copied from class:ComputedImage
Returns the height of tiles in this image. The default implementation returnsSampleModel.getHeight()
.Note: a raster can have a smaller height than its sample model, for example when a raster is a view over a subregion of another raster. But this is not recommended in the particular case of thisComputedImage
class, because it would causeComputedImage.createTile(int, int)
to consume more memory than necessary.- Specified by:
getTileHeight
in interfaceRenderedImage
- Overrides:
getTileHeight
in classComputedImage
- Returns:
- the height of this image in pixels.
-
getTileGridXOffset
public final 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 final 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.
-
prefetch
Notifies the source image that tiles will be computed soon in the given region. If the source image is an instance ofPlanarImage
, then this method forwards the notification to it. Otherwise default implementation does nothing.- Overrides:
prefetch
in classComputedImage
- Parameters:
tiles
- indices of the tiles which will be prefetched.- Returns:
- handler on which to invoke
dispose()
after the prefetch operation completed (successfully or not), ornull
if none.
-
hashCode
public int hashCode()Returns a hash code value for this image. Subclasses should override this method. -
equals
Compares the given object with this image for equality. Subclasses should override this method.
-