Class ImageAdapter

java.lang.Object
org.apache.sis.image.PlanarImage
org.apache.sis.image.ImageAdapter
All Implemented Interfaces:
RenderedImage
Direct Known Subclasses:
AnnotatedImage, RecoloredImage

abstract class ImageAdapter extends PlanarImage
An image which wraps an existing image unchanged, except for properties and/or color model. All RenderedImage methods related to coordinate systems (pixel coordinates or tile indices), and all methods fetching tiles, delegate to the wrapped image.

Design note

most non-abstract methods are final because PixelIterator (among others) relies on the fact that it can unwrap this image and still get the same pixel values.

Relationship with other classes

This class is similar to SourceAlignedImage except that it does not extend ComputedImage and forward getTile(int, int), getData() and other data methods to the source image.

Requirements for subclasses

All subclasses shall override equals(Object) and hashCode().
Since:
1.1
Version:
1.2
  • Field Details

    • source

      protected final RenderedImage source
      The source image wrapped by this adapter.
  • Constructor Details

    • ImageAdapter

      protected ImageAdapter(RenderedImage source)
      Creates a new wrapper for the given image.
      Parameters:
      source - the image to wrap.
  • Method Details

    • getSources

      public final Vector<RenderedImage> getSources()
      Returns the source of this image in an vector of length 1.
      Specified by:
      getSources in interface RenderedImage
      Overrides:
      getSources in class PlanarImage
      Returns:
      the unique source of this image.
    • getPropertyNames

      public String[] getPropertyNames()
      Returns the names of properties of wrapped image.
      Specified by:
      getPropertyNames in interface RenderedImage
      Overrides:
      getPropertyNames in class PlanarImage
      Returns:
      all recognized property names.
    • getProperty

      public Object getProperty(String name)
      Gets a property from this image or from its source.
      Specified by:
      getProperty in interface RenderedImage
      Overrides:
      getProperty in class PlanarImage
      Parameters:
      name - name of the property to get.
      Returns:
      the property for the given name (null is a valid result), or Image.UndefinedProperty if the given name is not a recognized property name.
    • getColorModel

      public ColorModel getColorModel()
      Returns the color model of this image.
    • getSampleModel

      public final SampleModel getSampleModel()
      Delegates to the wrapped image.
    • getWidth

      public final int getWidth()
    • getHeight

      public final int getHeight()
    • getMinX

      public final int getMinX()
      Description copied from class: PlanarImage
      Returns the minimum x coordinate (inclusive) of this image.

      Default implementation returns zero. Subclasses shall override this method if the image starts at another coordinate.

      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.
    • 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.
    • 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.
    • getTileWidth

      public final int getTileWidth()
    • getTileHeight

      public final int getTileHeight()
    • 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.
    • getTile

      public final Raster getTile(int tx, int ty)
    • getData

      public final Raster getData()
      Description copied from class: PlanarImage
      Returns a copy of this image as one large tile. The returned raster will not be updated if this image is changed.
      Specified by:
      getData in interface RenderedImage
      Overrides:
      getData in class PlanarImage
      Returns:
      a copy of this image as one large tile.
    • getData

      public final Raster getData(Rectangle region)
      Description copied from class: PlanarImage
      Returns a copy of an arbitrary region of this image. The returned raster will not be updated if this image is changed.
      Specified by:
      getData in interface RenderedImage
      Overrides:
      getData in class PlanarImage
      Parameters:
      region - the region of this image to copy.
      Returns:
      a copy of this image in the given area of interest.
    • copyData

      public final WritableRaster copyData(WritableRaster r)
      Description copied from class: PlanarImage
      Copies an arbitrary rectangular region of this image to the supplied writable raster. The region to be copied is determined from the bounds of the supplied raster. The supplied raster must have a SampleModel that is compatible with this image. If the raster is null, an raster is created by this method.
      Specified by:
      copyData in interface RenderedImage
      Overrides:
      copyData in class PlanarImage
      Parameters:
      r - the raster to hold a copy of this image, or null.
      Returns:
      the given raster if it was not-null, or a new raster otherwise.
    • 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 PlanarImage
      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.
    • equals

      public boolean equals(Object object)
      Compares the given object with this image for equality. This method should be quick and compare how images compute their values from their sources; it should not compare the actual pixel values.

      The default implementation returns true if the given object is non-null, is an instance of the exact same class than this image and the source of both images are equal. Subclasses should override this method if more properties need to be compared.

      Overrides:
      equals in class Object
      Parameters:
      object - the object to compare with this image.
      Returns:
      true if the given object is an image performing the same calculation than this image.
    • hashCode

      public int hashCode()
      Returns a hash code value for this image. This method should be quick, for example using only a description of the operation to be done (e.g. implementation class, parameters). This method should not compute the hash code from sample values.

      The default implementation computes a hash code based on the source hash code and this image class. Subclasses should override this method if more properties need to be hashed.

      Overrides:
      hashCode in class Object
      Returns:
      a hash code value based on a description of the operation performed by this image.
    • toString

      public String toString()
      Returns a string representation of this image for debugging purpose.
      Overrides:
      toString in class PlanarImage
      Returns:
      a string representation of this image for debugging purpose only.
    • appendStringContent

      abstract Class<? extends ImageAdapter> appendStringContent(StringBuilder buffer)
      Appends a content to show in the toString() representation, after the class name and before the string representation of the wrapped image.
      Parameters:
      buffer - where to start writing content of toString() representation.
      Returns:
      name of the class to show in the toString() representation.