- All Implemented Interfaces:
RenderedImage
- Direct Known Subclasses:
ComputedImage
RenderedImage
implementations in Apache SIS.
The "Planar" part in the class name emphasizes that this image is a representation
of two-dimensional data and should not contain an image with three-dimensional effects.
Planar images can be used as data storage for GridCoverage2D
.
javax.media.jai.PlanarImage
class defined in the Java Advanced Imaging (JAI) library.
That excellent library was 20 years in advance on thematic like defining a chain of image operations,
multi-threaded execution, distribution over a computer network, etc.
But unfortunately the JAI library does not seems to be maintained anymore.
We do not try to reproduce the full set of JAI functionalities here, but we progressively
reproduce some little bits of functionalities as they are needed by Apache SIS.This base class does not store any state, but assumes that numbering of pixel coordinates and tile indices start at zero. Subclasses need to implement at least the following methods:
RenderedImage.getWidth()
— the image width in pixels.RenderedImage.getHeight()
— the image height in pixels.RenderedImage.getTileWidth()
— the tile width in pixels.RenderedImage.getTileHeight()
— the tile height in pixels.RenderedImage.getTile(int,int)
— the tile at given tile indices.
If pixel coordinates or tile indices do not start at zero, then subclasses shall also override the following methods:
getMinX()
— the minimum x coordinate (inclusive) of the image.getMinY()
— the minimum y coordinate (inclusive) of the image.getMinTileX()
— the minimum tile index in the x direction.getMinTileY()
— the minimum tile index in the y direction.
getNumXTiles()
, getNumYTiles()
,
getTileGridXOffset()
, getTileGridYOffset()
, getData()
,
getData(Rectangle)
and copyData(WritableRaster)
in terms of above methods.
Writable images
Some subclasses may implement theWritableRenderedImage
interface. If this image is writable,
then the WritableRenderedImage.getWritableTile(…)
and
releaseWritableTile(…)
methods should be invoked in
try ... finally
blocks like below:
WritableRenderedImage image = ...;
WritableRaster tile = image.getWritableTile(tileX, tileY);
try {
// Do some process on the tile.
} finally {
image.releaseWritableTile(tileX, tileY);
}
TileObserver
s. Some implementations may also acquire and release
synchronization locks in the getWritableTile(…)
and releaseWritableTile(…)
methods.
Apache SIS does not yet define a synchronization policy
for WritableRenderedImage
, but such policy may be defined in a future version.- Since:
- 1.1
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Key for a property defining a conversion from pixel coordinates to "real world" coordinates.static final String
Key of property providing a mask for missing values.static final String
Estimation of positional accuracy, typically in metres or pixel units.static final String
Key for a property defining a conversion from pixel values to the units of measurement.static final String
Key of a property defining the resolutions of sample values in each band.static final String
Key of property providing statistics on sample values in each band. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncopyData
(WritableRaster raster) Copies an arbitrary rectangular region of this image to the supplied writable raster.Returns the image location (x, y) and image size (width, height).getData()
Returns a copy of this image as one large tile.Returns a copy of an arbitrary region of this image.int
Returns the minimum tile index in the x direction.int
Returns the minimum tile index in the y direction.int
Returns the minimum x coordinate (inclusive) of this image.int
Returns the minimum y coordinate (inclusive) of this image.int
Returns the number of tiles in the x direction.int
Returns the number of tiles in the y direction.getProperty
(String key) Gets a property from this image.String[]
Returns the names of all recognized properties, ornull
if this image has no properties.Returns the immediate sources of image data for this image.int
Returns the x coordinate of the upper-left pixel of tile (0, 0).int
Returns the y coordinate of the upper-left pixel of tile (0, 0).Returns a string representation of this image for debugging purpose.verify()
Verifies whether image layout information are consistent.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface RenderedImage
getColorModel, getHeight, getSampleModel, getTile, getTileHeight, getTileWidth, getWidth
-
Field Details
-
GRID_GEOMETRY_KEY
Key for a property defining a conversion from pixel coordinates to "real world" coordinates. Other information include an envelope in "real world" coordinates and an estimation of pixel resolution. The value is aGridGeometry
instance with following properties:- The number of grid dimensions is always 2.
- The number of CRS dimensions is always 2.
- The grid extent is the image bounds.
- The grid to CRS map pixel coordinates "real world" coordinates (always two-dimensional).
- See Also:
-
POSITIONAL_ACCURACY_KEY
Estimation of positional accuracy, typically in metres or pixel units. Pixel positions may have limited accuracy in they are computed by coordinate transformations. The position may also be inaccurate because of approximation applied for faster rendering.Values should be instances of
. The array length is typically 1 or 2. If accuracy is limited by a coordinate transformation, then the array should contain an accuracy expressed in a linear unit such as meter. If accuracy is limited by an approximation applied during resampling operation, then the array should contain an accuracy expressed in pixel units.Quantity
- See Also:
-
SAMPLE_DIMENSIONS_KEY
Key for a property defining a conversion from pixel values to the units of measurement. The value should be an array ofSampleDimension
instances. The array length should be the number of bands.- Since:
- 1.4
- See Also:
-
SAMPLE_RESOLUTIONS_KEY
Key of a property defining the resolutions of sample values in each band. This property is recommended for images having sample values as floating point numbers. For example if sample values were computed by value = integer × scale factor, then the resolution is the scale factor. This information can be used for choosing the number of fraction digits to show when writing sample values in text format.Values should be instances of
double[]
. The array length should be the number of bands. This property may be computed automatically during conversions from integer values to floating point values.- See Also:
-
STATISTICS_KEY
Key of property providing statistics on sample values in each band. Providing a value for this key is recommended when those statistics are known in advance (for example if they are provided in some metadata of a raster format). Statistics are useful for stretching a color palette over the values actually used in an image.Values should be instances of
Statistics[]
. The array length should be the number of bands. If this property is not provided, Apache SIS may have to compute statistics itself (by iterating over pixel values) when needed.Statistics are only indicative. They may be computed on an image sub-region.
- See Also:
-
MASK_KEY
Key of property providing a mask for missing values. Values should be instances ofRenderedImage
with a single band, binary sample values and a color model ofTransparency.BITMASK
type. The binary values 0 and 1 are alpha values: 0 for fully transparent pixels and 1 for fully opaque pixels. For every pixel (x,y) in this image, the pixel at the same coordinates in the mask is either fully transparent (sample value 0) if the sample value in this image is valid, or fully opaque (sample value 1) if the sample value in this image is invalid (Float.NaN
).If this
PlanarImage
has more than one band, then the value for this property is the overlay of masks of each band: pixels are 0 when sample values are valid in all bands, and 1 when sample value is invalid in at least one band.Note that it is usually not necessary to use masks explicitly in Apache SIS because missing values are represented by
Float.NaN
. This property is provided for algorithms that cannot work with NaN values.- See Also:
-
-
Constructor Details
-
PlanarImage
protected PlanarImage()Creates a new rendered image.
-
-
Method Details
-
getSources
Returns the immediate sources of image data for this image. This method returnsnull
if the image has no information about its immediate sources. It returns an empty vector if the image object has no immediate sources.The default implementation returns
null
. Note that this is not equivalent to an empty vector.- Specified by:
getSources
in interfaceRenderedImage
- Returns:
- the immediate sources, or
null
if unknown.
-
getProperty
Gets a property from this image. The property to get is identified by the specified key. The set of available keys is given bygetPropertyNames()
and depends on the image instance. The following table gives examples of keys recognized by some Apache SISRenderedImage
instances:Examples of property keys Keys Values "org.apache.sis.GridGeometry" Conversion from pixel coordinates to "real world" coordinates. "org.apache.sis.PositionalAccuracy" Estimation of positional accuracy, typically in metres or pixel units. "org.apache.sis.SampleDimensions" Conversions from pixel values to the units of measurement for each band. "org.apache.sis.SampleResolutions" Resolutions of sample values in each band. "org.apache.sis.Statistics" Minimum, maximum and mean values for each band. "org.apache.sis.Mask" Image with transparent pixels at locations of valid values and opaque pixels elsewhere. "org.apache.sis.PositionalConsistency" Estimation of positional error for each pixel as a consistency check. "org.apache.sis.SourcePadding" Amount of additional source pixels needed on each side of a destination pixel for computing its value. Image.UndefinedProperty
if the specified property is not defined. The default implementation returnsImage.UndefinedProperty
in all cases.- Specified by:
getProperty
in interfaceRenderedImage
- Parameters:
key
- the name of the property to get.- Returns:
- the property value, or
Image.UndefinedProperty
if none.
-
getPropertyNames
Returns the names of all recognized properties, ornull
if this image has no properties.The default implementation returns
null
.- Specified by:
getPropertyNames
in interfaceRenderedImage
- Returns:
- names of all recognized properties, or
null
if none.
-
getBounds
Returns the image location (x, y) and image size (width, height). This is a convenience method encapsulating the results of 4 method calls in a single object.- Returns:
- the image location and image size as a new rectangle.
- See Also:
-
getMinX
public int getMinX()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 interfaceRenderedImage
- Returns:
- the minimum x coordinate (column) of this image.
-
getMinY
public int getMinY()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
- Returns:
- the minimum y coordinate (row) of this image.
-
getMinTileX
public int getMinTileX()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
- Returns:
- the minimum tile index in the x direction.
-
getMinTileY
public int getMinTileY()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
- Returns:
- the minimum tile index in the y direction.
-
getNumXTiles
public int getNumXTiles()Returns the number of tiles in the x direction.The default implementation computes this value from
RenderedImage.getWidth()
andRenderedImage.getTileWidth()
on the assumption thatgetMinX()
is the coordinate of the leftmost pixels of tiles located atgetMinTileX()
index. This assumption can be verified byverify()
.- Specified by:
getNumXTiles
in interfaceRenderedImage
- Returns:
- returns the number of tiles in the x direction.
-
getNumYTiles
public int getNumYTiles()Returns the number of tiles in the y direction.The default implementation computes this value from
RenderedImage.getHeight()
andRenderedImage.getTileHeight()
on the assumption thatgetMinY()
is the coordinate of the uppermost pixels of tiles located atgetMinTileY()
index. This assumption can be verified byverify()
.- Specified by:
getNumYTiles
in interfaceRenderedImage
- Returns:
- returns the number of tiles in the y direction.
-
getTileGridXOffset
public int getTileGridXOffset()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
getMinX()
,getMinTileX()
andRenderedImage.getTileWidth()
.- Specified by:
getTileGridXOffset
in interfaceRenderedImage
- Returns:
- the x offset of the tile grid relative to the origin.
-
getTileGridYOffset
public int getTileGridYOffset()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
getMinY()
,getMinTileY()
andRenderedImage.getTileHeight()
.- Specified by:
getTileGridYOffset
in interfaceRenderedImage
- Returns:
- the y offset of the tile grid relative to the origin.
-
getData
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 interfaceRenderedImage
- Returns:
- a copy of this image as one large tile.
-
getData
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 interfaceRenderedImage
- Parameters:
aoi
- the region of this image to copy.- Returns:
- a copy of this image in the given area of interest.
- Throws:
IllegalArgumentException
- if the given rectangle is not contained in this image bounds.
-
copyData
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 aSampleModel
that is compatible with this image. If the raster isnull
, an raster is created by this method.- Specified by:
copyData
in interfaceRenderedImage
- Parameters:
raster
- the raster to hold a copy of this image, ornull
.- Returns:
- the given raster if it was not-null, or a new raster otherwise.
-
verify
Verifies whether image layout information are consistent. This method verifies that the coordinates of image upper-left corner are equal to the coordinates of the upper-left corner of the tile in the upper-left corner, and that image size is equal to the sum of the sizes of all tiles. Compatibility of sample model and color model is also verified.The default implementation may return the following identifiers, in that order (i.e. this method returns the identifier of the first test that fail):
Identifiers of inconsistent values Identifier Meaning "colorModel"
Color model is incompatible with sample model. "tileWidth"
Tile width is greater than sample model width. "tileHeight"
Tile height is greater than sample model height. "numXTiles"
Number of tiles on the X axis is inconsistent with image width. "numYTiles"
Number of tiles on the Y axis is inconsistent with image height. "tileX"
minTileX
and/ortileGridXOffset
is inconsistent."tileY"
minTileY
and/ortileGridYOffset
is inconsistent."width"
image width is not an integer multiple of tile width. "height"
Image height is not an integer multiple of tile height. "minX"
,"minY"
,"tileGridXOffset"
and"tileGridYOffset"
values before to fallback on the more generic"tileX"
and"tileY"
above checks. The returned identifiers may also have subcategories. For example"colorModel"
may be subdivided with"colorModel.numBands"
and"colorModel.transferType"
.Ignorable inconsistency
Inconsistency in"width"
and"height"
values may be acceptable if all other verifications pass (in particular the"numXTiles"
and"numYTiles"
checks). It happens when tiles in the last row or last column have some unused space compared to the image size. This is legal in TIFF format for example. For this reason, the"width"
and"height"
values should be checked last, after all other values have been verified consistent.- Returns:
null
if image layout information are consistent, or the name of inconsistent attribute if a problem is found.
-
toString
Returns a string representation of this image for debugging purpose. This string representation may change in any future SIS version.
-