org.apache.batik.ext.awt.image.codec.util

Class SimpleRenderedImage

public abstract class SimpleRenderedImage extends Object implements RenderedImage

A simple class implemented the RenderedImage interface. Only the getTile() method needs to be implemented by subclasses. The instance variables must also be filled in properly.

Normally in JAI PlanarImage is used for this purpose, but in the interest of modularity the use of PlanarImage has been avoided.

Field Summary
protected ColorModelcolorModel
The image's ColorModel.
protected intheight
The image's height in pixels.
protected intminX
The X coordinate of the image's upper-left pixel.
protected intminY
The Y coordinate of the image's upper-left pixel.
protected Mapproperties
A Hashtable containing the image properties.
protected SampleModelsampleModel
The image's SampleModel.
protected Listsources
The image's sources, stored in a Vector.
protected inttileGridXOffset
The X coordinate of the upper-left pixel of tile (0, 0).
protected inttileGridYOffset
The Y coordinate of the upper-left pixel of tile (0, 0).
protected inttileHeight
The height of a tile.
protected inttileWidth
The width of a tile.
protected intwidth
The image's width in pixels.
Constructor Summary
SimpleRenderedImage()
Method Summary
WritableRastercopyData(WritableRaster dest)
Copies an arbitrary rectangular region of the RenderedImage into a caller-supplied WritableRaster.
RectanglegetBounds()
Returns a Rectangle indicating the image bounds.
ColorModelgetColorModel()
Returns the ColorModel of the image.
RastergetData()
Returns the entire image in a single Raster.
RastergetData(Rectangle bounds)
Returns an arbitrary rectangular region of the RenderedImage in a Raster.
intgetHeight()
Returns the height of the image.
intgetMaxTileX()
Returns the horizontal index of the rightmost column of tiles. getMaxTileX() is implemented in terms of getMaxX() and so does not need to be implemented by subclasses.
intgetMaxTileY()
Returns the vertical index of the bottom row of tiles. getMaxTileY() is implemented in terms of getMaxY() and so does not need to be implemented by subclasses.
intgetMaxX()
Returns the X coordinate of the column immediatetely to the right of the rightmost column of the image. getMaxX() is implemented in terms of getMinX() and getWidth() and so does not need to be implemented by subclasses.
intgetMaxY()
Returns the Y coordinate of the row immediately below the bottom row of the image. getMaxY() is implemented in terms of getMinY() and getHeight() and so does not need to be implemented by subclasses.
intgetMinTileX()
Returns the horizontal index of the leftmost column of tiles. getMinTileX() is implemented in terms of getMinX() and so does not need to be implemented by subclasses.
intgetMinTileY()
Returns the vertical index of the uppermost row of tiles. getMinTileY() is implemented in terms of getMinY() and so does not need to be implemented by subclasses.
intgetMinX()
Returns the X coordinate of the leftmost column of the image.
intgetMinY()
Returns the X coordinate of the uppermost row of the image.
intgetNumXTiles()
Returns the number of tiles along the tile grid in the horizontal direction. getNumXTiles() is implemented in terms of getMinTileX() and getMaxTileX() and so does not need to be implemented by subclasses.
intgetNumYTiles()
Returns the number of tiles along the tile grid in the vertical direction. getNumYTiles() is implemented in terms of getMinTileY() and getMaxTileY() and so does not need to be implemented by subclasses.
ObjectgetProperty(String name)
Gets a property from the property set of this image.
String[]getPropertyNames()
Returns a list of the properties recognized by this image.
String[]getPropertyNames(String prefix)
Returns an array of Strings recognized as names by this property source that begin with the supplied prefix.
SampleModelgetSampleModel()
Returns the SampleModel of the image.
VectorgetSources()
intgetTileGridXOffset()
Returns the X coordinate of the upper-left pixel of tile (0, 0).
intgetTileGridYOffset()
Returns the Y coordinate of the upper-left pixel of tile (0, 0).
intgetTileHeight()
Returns the height of a tile.
intgetTileWidth()
Returns the width of a tile.
intgetWidth()
Returns the width of the image.
static inttileXToX(int tx, int tileGridXOffset, int tileWidth)
Converts a horizontal tile index into the X coordinate of its upper left pixel relative to a given tile grid layout specified by its X offset and tile width.
inttileXToX(int tx)
Converts a horizontal tile index into the X coordinate of its upper left pixel.
static inttileYToY(int ty, int tileGridYOffset, int tileHeight)
Converts a vertical tile index into the Y coordinate of its upper left pixel relative to a given tile grid layout specified by its Y offset and tile height.
inttileYToY(int ty)
Converts a vertical tile index into the Y coordinate of its upper left pixel.
static intXToTileX(int x, int tileGridXOffset, int tileWidth)
Converts a pixel's X coordinate into a horizontal tile index relative to a given tile grid layout specified by its X offset and tile width.
intXToTileX(int x)
Converts a pixel's X coordinate into a horizontal tile index.
static intYToTileY(int y, int tileGridYOffset, int tileHeight)
Converts a pixel's Y coordinate into a vertical tile index relative to a given tile grid layout specified by its Y offset and tile height.
intYToTileY(int y)
Converts a pixel's Y coordinate into a vertical tile index.

Field Detail

colorModel

protected ColorModel colorModel
The image's ColorModel.

height

protected int height
The image's height in pixels.

minX

protected int minX
The X coordinate of the image's upper-left pixel.

minY

protected int minY
The Y coordinate of the image's upper-left pixel.

properties

protected Map properties
A Hashtable containing the image properties.

sampleModel

protected SampleModel sampleModel
The image's SampleModel.

sources

protected List sources
The image's sources, stored in a Vector.

tileGridXOffset

protected int tileGridXOffset
The X coordinate of the upper-left pixel of tile (0, 0).

tileGridYOffset

protected int tileGridYOffset
The Y coordinate of the upper-left pixel of tile (0, 0).

tileHeight

protected int tileHeight
The height of a tile.

tileWidth

protected int tileWidth
The width of a tile.

width

protected int width
The image's width in pixels.

Constructor Detail

SimpleRenderedImage

public SimpleRenderedImage()

Method Detail

copyData

public WritableRaster copyData(WritableRaster dest)
Copies an arbitrary rectangular region of the RenderedImage into a caller-supplied WritableRaster. The region to be computed is determined by clipping the bounds of the supplied WritableRaster against the bounds of the image. The supplied WritableRaster must have a SampleModel that is compatible with that of the image.

If the raster argument is null, the entire image will be copied into a newly-created WritableRaster with a SampleModel that is compatible with that of the image.

Parameters: dest a WritableRaster to hold the returned portion of the image.

Returns: a reference to the supplied WritableRaster, or to a new WritableRaster if the supplied one was null.

getBounds

public Rectangle getBounds()
Returns a Rectangle indicating the image bounds.

getColorModel

public ColorModel getColorModel()
Returns the ColorModel of the image.

getData

public Raster getData()
Returns the entire image in a single Raster. For images with multiple tiles this will require making a copy.

The returned Raster is semantically a copy. This means that updates to the source image will not be reflected in the returned Raster. For non-writable (immutable) source images, the returned value may be a reference to the image's internal data. The returned Raster should be considered non-writable; any attempt to alter its pixel data (such as by casting it to WritableRaster or obtaining and modifying its DataBuffer) may result in undefined behavior. The copyData method should be used if the returned Raster is to be modified.

Returns: a Raster containing a copy of this image's data.

getData

public Raster getData(Rectangle bounds)
Returns an arbitrary rectangular region of the RenderedImage in a Raster. The rectangle of interest will be clipped against the image bounds.

The returned Raster is semantically a copy. This means that updates to the source image will not be reflected in the returned Raster. For non-writable (immutable) source images, the returned value may be a reference to the image's internal data. The returned Raster should be considered non-writable; any attempt to alter its pixel data (such as by casting it to WritableRaster or obtaining and modifying its DataBuffer) may result in undefined behavior. The copyData method should be used if the returned Raster is to be modified.

Parameters: bounds the region of the RenderedImage to be returned.

getHeight

public int getHeight()
Returns the height of the image.

getMaxTileX

public int getMaxTileX()
Returns the horizontal index of the rightmost column of tiles. getMaxTileX() is implemented in terms of getMaxX() and so does not need to be implemented by subclasses.

getMaxTileY

public int getMaxTileY()
Returns the vertical index of the bottom row of tiles. getMaxTileY() is implemented in terms of getMaxY() and so does not need to be implemented by subclasses.

getMaxX

public final int getMaxX()
Returns the X coordinate of the column immediatetely to the right of the rightmost column of the image. getMaxX() is implemented in terms of getMinX() and getWidth() and so does not need to be implemented by subclasses.

getMaxY

public final int getMaxY()
Returns the Y coordinate of the row immediately below the bottom row of the image. getMaxY() is implemented in terms of getMinY() and getHeight() and so does not need to be implemented by subclasses.

getMinTileX

public int getMinTileX()
Returns the horizontal index of the leftmost column of tiles. getMinTileX() is implemented in terms of getMinX() and so does not need to be implemented by subclasses.

getMinTileY

public int getMinTileY()
Returns the vertical index of the uppermost row of tiles. getMinTileY() is implemented in terms of getMinY() and so does not need to be implemented by subclasses.

getMinX

public int getMinX()
Returns the X coordinate of the leftmost column of the image.

getMinY

public int getMinY()
Returns the X coordinate of the uppermost row of the image.

getNumXTiles

public int getNumXTiles()
Returns the number of tiles along the tile grid in the horizontal direction. getNumXTiles() is implemented in terms of getMinTileX() and getMaxTileX() and so does not need to be implemented by subclasses.

getNumYTiles

public int getNumYTiles()
Returns the number of tiles along the tile grid in the vertical direction. getNumYTiles() is implemented in terms of getMinTileY() and getMaxTileY() and so does not need to be implemented by subclasses.

getProperty

public Object getProperty(String name)
Gets a property from the property set of this image. If the property name is not recognized, null will be returned.

Parameters: name the name of the property to get, as a String.

Returns: a reference to the property Object, or the value null

getPropertyNames

public String[] getPropertyNames()
Returns a list of the properties recognized by this image. If no properties are available, an empty String[] will be returned.

Returns: an array of Strings representing valid property names.

getPropertyNames

public String[] getPropertyNames(String prefix)
Returns an array of Strings recognized as names by this property source that begin with the supplied prefix. If no property names match, null will be returned. The comparison is done in a case-independent manner.

The default implementation calls getPropertyNames() and searches the list of names for matches.

Returns: an array of Strings giving the valid property names (can be null).

getSampleModel

public SampleModel getSampleModel()
Returns the SampleModel of the image.

getSources

public Vector getSources()

getTileGridXOffset

public int getTileGridXOffset()
Returns the X coordinate of the upper-left pixel of tile (0, 0).

getTileGridYOffset

public int getTileGridYOffset()
Returns the Y coordinate of the upper-left pixel of tile (0, 0).

getTileHeight

public int getTileHeight()
Returns the height of a tile.

getTileWidth

public int getTileWidth()
Returns the width of a tile.

getWidth

public int getWidth()
Returns the width of the image.

tileXToX

public static int tileXToX(int tx, int tileGridXOffset, int tileWidth)
Converts a horizontal tile index into the X coordinate of its upper left pixel relative to a given tile grid layout specified by its X offset and tile width.

tileXToX

public int tileXToX(int tx)
Converts a horizontal tile index into the X coordinate of its upper left pixel. This is a convenience method. No attempt is made to detect out-of-range indices.

Parameters: tx the horizontal index of a tile.

Returns: the X coordinate of the tile's upper left pixel.

tileYToY

public static int tileYToY(int ty, int tileGridYOffset, int tileHeight)
Converts a vertical tile index into the Y coordinate of its upper left pixel relative to a given tile grid layout specified by its Y offset and tile height.

tileYToY

public int tileYToY(int ty)
Converts a vertical tile index into the Y coordinate of its upper left pixel. This is a convenience method. No attempt is made to detect out-of-range indices.

Parameters: ty the vertical index of a tile.

Returns: the Y coordinate of the tile's upper left pixel.

XToTileX

public static int XToTileX(int x, int tileGridXOffset, int tileWidth)
Converts a pixel's X coordinate into a horizontal tile index relative to a given tile grid layout specified by its X offset and tile width.

XToTileX

public int XToTileX(int x)
Converts a pixel's X coordinate into a horizontal tile index. This is a convenience method. No attempt is made to detect out-of-range coordinates.

Parameters: x the X coordinate of a pixel.

Returns: the X index of the tile containing the pixel.

YToTileY

public static int YToTileY(int y, int tileGridYOffset, int tileHeight)
Converts a pixel's Y coordinate into a vertical tile index relative to a given tile grid layout specified by its Y offset and tile height.

YToTileY

public int YToTileY(int y)
Converts a pixel's Y coordinate into a vertical tile index. This is a convenience method. No attempt is made to detect out-of-range coordinates.

Parameters: y the Y coordinate of a pixel.

Returns: the Y index of the tile containing the pixel.

Copyright B) 2007 Apache Software Foundation. All Rights Reserved.