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 ColorModelThe 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_KEYFields inherited from class org.apache.sis.image.PlanarImage
GRID_GEOMETRY_KEY, MASK_KEY, POSITIONAL_ACCURACY_KEY, SAMPLE_RESOLUTIONS_KEY, STATISTICS_KEY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSourceAlignedImage(RenderedImage source) Creates a new image with the given source.protectedSourceAlignedImage(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 SampleModelcreateSampleModel(ColorModel colorModel, SampleModel original) Creates the sample model.booleanCompares 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 ColorModelReturns the color model associated with this image.final intfinal intReturns the minimum tile index in the x direction.final intReturns the minimum tile index in the y direction.final intgetMinX()Delegates to source image.final intgetMinY()Returns the minimum y coordinate (inclusive) of this image.final intReturns the number of tiles in the x direction.final intReturns the number of tiles in the y direction.private static SampleModelgetSampleModel(RenderedImage source) Gets the sample model, making sure it has the right size.final intReturns the x coordinate of the upper-left pixel of tile (0, 0).final intReturns the y coordinate of the upper-left pixel of tile (0, 0).final intReturns the height of tiles in this image.final intReturns the width of tiles in this image.final intgetWidth()inthashCode()Returns a hash code value for this image.protected DisposableNotifies 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, sourceTileChangedMethods 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 theinheritargument 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
nullif 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
namesargument 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, ornullif none. If non-null, this array will be modified in-place.inherit- properties to inherit from the source.append- properties to append, ornullif none.- Returns:
- properties recognized by this image, or
nullif none.
-
getMinX
public final int getMinX()Delegates to source image.- Specified by:
getMinXin interfaceRenderedImage- Overrides:
getMinXin classPlanarImage- Returns:
- the minimum x coordinate (column) of this image.
-
getMinY
public final int getMinY()Description copied from class:PlanarImageReturns 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:
getMinYin interfaceRenderedImage- Overrides:
getMinYin 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:PlanarImageReturns 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:
getMinTileXin interfaceRenderedImage- Overrides:
getMinTileXin classPlanarImage- Returns:
- the minimum tile index in the x direction.
-
getMinTileY
public final int getMinTileY()Description copied from class:PlanarImageReturns 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:
getMinTileYin interfaceRenderedImage- Overrides:
getMinTileYin classPlanarImage- Returns:
- the minimum tile index in the y direction.
-
getNumXTiles
public final int getNumXTiles()Description copied from class:PlanarImageReturns 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:
getNumXTilesin interfaceRenderedImage- Overrides:
getNumXTilesin classPlanarImage- Returns:
- returns the number of tiles in the x direction.
-
getNumYTiles
public final int getNumYTiles()Description copied from class:PlanarImageReturns 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:
getNumYTilesin interfaceRenderedImage- Overrides:
getNumYTilesin classPlanarImage- Returns:
- returns the number of tiles in the y direction.
-
getTileWidth
public final int getTileWidth()Description copied from class:ComputedImageReturns 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 thisComputedImageclass, because it would causeComputedImage.createTile(int, int)to consume more memory than necessary.- Specified by:
getTileWidthin interfaceRenderedImage- Overrides:
getTileWidthin classComputedImage- Returns:
- the width of this image in pixels.
-
getTileHeight
public final int getTileHeight()Description copied from class:ComputedImageReturns 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 thisComputedImageclass, because it would causeComputedImage.createTile(int, int)to consume more memory than necessary.- Specified by:
getTileHeightin interfaceRenderedImage- Overrides:
getTileHeightin classComputedImage- Returns:
- the height of this image in pixels.
-
getTileGridXOffset
public final int getTileGridXOffset()Description copied from class:PlanarImageReturns 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:
getTileGridXOffsetin interfaceRenderedImage- Overrides:
getTileGridXOffsetin classPlanarImage- Returns:
- the x offset of the tile grid relative to the origin.
-
getTileGridYOffset
public final int getTileGridYOffset()Description copied from class:PlanarImageReturns 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:
getTileGridYOffsetin interfaceRenderedImage- Overrides:
getTileGridYOffsetin 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:
prefetchin 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), ornullif 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.
-