Class SourceAlignedImage

All Implemented Interfaces:
RenderedImage, Disposable
Direct Known Subclasses:
BandSelectImage, MaskedImage, MaskImage, PositionalConsistencyImage

abstract class SourceAlignedImage extends ComputedImage
An image computed from a single source and sharing the same coordinate system. In addition of pixel coordinate system, images share also the same tile indices. Tiles in this image have the same size than tiles in the source image. See ComputedImage javadoc for more information about tile computation.
Relationship with other classes
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 the ComputedImage.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 Details

    • POSITIONAL_PROPERTIES

      static final Set<String> POSITIONAL_PROPERTIES
      Convenience collection for subclasses that inherit all properties related to positioning. May be used as the inherit argument in filterPropertyNames(String[], Set, String[]). Inheriting those properties make sense for operations that do not change pixel coordinates.
    • colorModel

      private final ColorModel colorModel
      The color model for this image. May be null.
  • Constructor Details

    • SourceAlignedImage

      protected SourceAlignedImage(RenderedImage source)
      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

      protected SourceAlignedImage(RenderedImage source, ColorModel colorModel)
      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

      public final ColorModel getColorModel()
      Returns the color model associated with this image.
      Returns:
      the color model, or null if none.
    • filterPropertyNames

      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. This is a helper method for PlanarImage.getPropertyNames() implementations in subclasses.

      The names argument should be the result of invoking RenderedImage.getPropertyNames() on the source image. This method modifies directly that array returned by getPropertyNames() 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, or null if none. If non-null, this array will be modified in-place.
      inherit - properties to inherit from the source.
      append - properties to append, or null 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 interface RenderedImage
      Overrides:
      getMinX in class PlanarImage
      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 interface RenderedImage
      Overrides:
      getMinY in class PlanarImage
      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 interface RenderedImage
      Overrides:
      getMinTileX in class PlanarImage
      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 interface RenderedImage
      Overrides:
      getMinTileY in class PlanarImage
      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() and RenderedImage.getTileWidth() on the assumption that PlanarImage.getMinX() is the coordinate of the leftmost pixels of tiles located at PlanarImage.getMinTileX() index. This assumption can be verified by PlanarImage.verify().

      Specified by:
      getNumXTiles in interface RenderedImage
      Overrides:
      getNumXTiles in class PlanarImage
      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() and RenderedImage.getTileHeight() on the assumption that PlanarImage.getMinY() is the coordinate of the uppermost pixels of tiles located at PlanarImage.getMinTileY() index. This assumption can be verified by PlanarImage.verify().

      Specified by:
      getNumYTiles in interface RenderedImage
      Overrides:
      getNumYTiles in class PlanarImage
      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 returns SampleModel.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 this ComputedImage class, because it would cause ComputedImage.createTile(int, int) to consume more memory than necessary.
      Specified by:
      getTileWidth in interface RenderedImage
      Overrides:
      getTileWidth in class ComputedImage
      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 returns SampleModel.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 this ComputedImage class, because it would cause ComputedImage.createTile(int, int) to consume more memory than necessary.
      Specified by:
      getTileHeight in interface RenderedImage
      Overrides:
      getTileHeight in class ComputedImage
      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() and RenderedImage.getTileWidth().

      Specified by:
      getTileGridXOffset in interface RenderedImage
      Overrides:
      getTileGridXOffset in class PlanarImage
      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() and RenderedImage.getTileHeight().

      Specified by:
      getTileGridYOffset in interface RenderedImage
      Overrides:
      getTileGridYOffset in class PlanarImage
      Returns:
      the y offset of the tile grid relative to the origin.
    • prefetch

      protected Disposable prefetch(Rectangle tiles)
      Notifies the source image that tiles will be computed soon in the given region. If the source image is an instance of PlanarImage, then this method forwards the notification to it. Otherwise default implementation does nothing.
      Overrides:
      prefetch in class ComputedImage
      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), or null if none.
    • hashCode

      public int hashCode()
      Returns a hash code value for this image. Subclasses should override this method.
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object object)
      Compares the given object with this image for equality. Subclasses should override this method.
      Overrides:
      equals in class Object