uk.ac.starlink.jaiutil
Class HDXImage

java.lang.Object
  extended by uk.ac.starlink.jaiutil.SimpleRenderedImage
      extended by uk.ac.starlink.jaiutil.HDXImage
All Implemented Interfaces:
RenderedImage

public class HDXImage
extends SimpleRenderedImage

This is the core class for JAI HDX/NDX support. It handles the conversion between the HDX->NDX->NDArrays and the display data. The data array is displayed by default.

This class defines a number of properties that can be accessed by applications via the getProperty method.

The value of the property "#hdx_image" returns the HDXImage object managing the image data.

The value of the property "#num_pages" returns an Integer with the number of NDXs in the HDX structure (always 1 at present).

The "#preview_image" property returns a preshrunk preview image suitable for use in a pan window. The size of the preview image may be set by calling the static method HDXImage.setPreviewSize(int).

Version:
$Id$
Author:
Allan Brighton, Peter W. Draper

Field Summary
protected  long[] axes
          The axes.
protected  int dataType
          The type of the data buffer (DataBuffer.TYPE_BYTE, ...)
protected static int defaultTileHeight
          Default tile height
protected static int defaultTileWidth
          Default tile width
protected  boolean empty
          True if the image is empty?
protected  NDArray ndArray
          Current NDArray, this is either the data, variance or quality of an NDX.
protected  NDArrayData ndArrayData
          Object used to manage data type specific operations
protected  int ndxIndex
          Index of the current NDX.
protected  List ndxs
          List of the NDXs (current one).
protected  HDXDecodeParam param
          Contains caller parameters (TODO: could specify component?).
protected static int previewSize
          Requested size of the preview image (width, height - actual size will vary)
protected  javax.media.jai.TileCache tileCache
          Object used to cache tiles
 
Fields inherited from class uk.ac.starlink.jaiutil.SimpleRenderedImage
colorModel, height, minX, minY, properties, sampleModel, sources, tileGridXOffset, tileGridYOffset, tileHeight, tileWidth, width
 
Constructor Summary
HDXImage(Document document, HDXDecodeParam param, int page)
          Create a HDXImage from a w3c Document.
HDXImage(Element element, int page)
          Create a HDXImage from a w3c Element
HDXImage(Ndx ndx)
          Construct a HDXImage from a NDX.
HDXImage(com.sun.media.jai.codec.SeekableStream input, HDXDecodeParam param, int page)
          Construct a HDXImage.
HDXImage(Source source)
          Construct a HDXImage.
HDXImage(String fileOrUrl)
          Construct a HDXImage from a file or URL.
 
Method Summary
 void clearTileCache()
          Try to save memory by clearing out the tile cache for this image.
 void close()
          Close the current "HDX".
protected  Raster fillTile(Raster tile)
          This method fills the given tile with the appropriate image data.
 double getBadValue()
          Return the Bad pixel value for the current NDArray.
 Ndx getCurrentNDX()
          Get a reference to the current NDX.
 int getCurrentNDXIndex()
          Return the index of the current NDX
static int getDefaultTileHeight()
           
static int getDefaultTileWidth()
           
 int getNumNDXs()
          Return the number of NDXs in the HDX structure.
protected  javax.media.jai.TiledImage getPreviewImage(int size)
          Return a prescaled PlanarImage that fits entirely in a window of the given size, or null if there are any errors.
static int getPreviewSize()
          Return the requested size for the preview image
 Object getProperty(String name)
          Gets a property from the property set of this HDX structure.
 String[] getPropertyNames()
          Returns a list of property names that are recognized by this image.
 int getRealHeight()
          Returns the real height of the image.
 int getRealWidth()
          Returns the real width of the image.
 float getScale()
          Return the current scale factor (zooming out is handled here for performance reasons).
protected  BufferedInputStream getStream(String fileOrUrl)
          Return a BufferedInputStream for the given file or URL.
 int getSubsample()
          Return the increment to use when accessing the image data if scale is less than 1.
 Raster getTile(int tileX, int tileY)
          Generate and return the given tile (required by the RenderedImage interface).
protected  URL getURL(String fileOrUrl)
          Return a URL for the given file or URL string.
 ColorModel initColorModel()
          Set the colormodel to use to display FITS images.
 void initData()
          Create an object to manage the data based on the type and set the value of the dataType member variable to the correct DataBuffer constant to use for the sample model.
 SampleModel initSampleModel(int tileWidth, int tileHeight)
          Return a SampleModel for this image with the given tile width and height.
static void setDefaultTileHeight(int h)
           
static void setDefaultTileWidth(int w)
           
 void setNDX(int num)
          Set the current NDX from those available.
static void setPreviewSize(int i)
          Set the requested size for the preview image
 boolean setScale(float scale)
          Set the scale (zoom factor) for the image and return true if a new image was generated.
 
Methods inherited from class uk.ac.starlink.jaiutil.SimpleRenderedImage
copyData, getBounds, getColorModel, getData, getData, getHeight, getMaxTileX, getMaxTileY, getMaxX, getMaxY, getMinTileX, getMinTileY, getMinX, getMinY, getNumXTiles, getNumYTiles, getPropertyNames, getSampleModel, getSources, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, tileXToX, tileXToX, tileYToY, tileYToY, XToTileX, XToTileX, YToTileY, YToTileY
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ndxs

protected List ndxs
List of the NDXs (current one).


ndArray

protected NDArray ndArray
Current NDArray, this is either the data, variance or quality of an NDX.


ndArrayData

protected NDArrayData ndArrayData
Object used to manage data type specific operations


axes

protected long[] axes
The axes.


ndxIndex

protected int ndxIndex
Index of the current NDX.


dataType

protected int dataType
The type of the data buffer (DataBuffer.TYPE_BYTE, ...)


defaultTileWidth

protected static int defaultTileWidth
Default tile width


defaultTileHeight

protected static int defaultTileHeight
Default tile height


tileCache

protected javax.media.jai.TileCache tileCache
Object used to cache tiles


param

protected HDXDecodeParam param
Contains caller parameters (TODO: could specify component?).


previewSize

protected static int previewSize
Requested size of the preview image (width, height - actual size will vary)


empty

protected boolean empty
True if the image is empty?

Constructor Detail

HDXImage

public HDXImage(com.sun.media.jai.codec.SeekableStream input,
                HDXDecodeParam param,
                int page)
         throws IOException
Construct a HDXImage.

Parameters:
input - the SeekableStream for the HDX XML description.
param - the parameter passed to the JAI create method
page - specifies the desired NDX, these are just discovered in their natural order starting at 0.
Throws:
IOException

HDXImage

public HDXImage(Source source)
         throws IOException
Construct a HDXImage.

Parameters:
source - a Source containing an HDX document.
Throws:
IOException

HDXImage

public HDXImage(String fileOrUrl)
         throws IOException
Construct a HDXImage from a file or URL.

Parameters:
fileOrURL - the file name or URL
Throws:
IOException

HDXImage

public HDXImage(Ndx ndx)
         throws IOException
Construct a HDXImage from a NDX.

Parameters:
ndx - the Ndx reference.
Throws:
IOException

HDXImage

public HDXImage(Document document,
                HDXDecodeParam param,
                int page)
         throws IOException
Create a HDXImage from a w3c Document.

Parameters:
Document - HDX structure
param - the parameter passed to the JAI create method
page - specifies the desired NDX (default: 0)
Throws:
IOException

HDXImage

public HDXImage(Element element,
                int page)
         throws IOException
Create a HDXImage from a w3c Element

Parameters:
Document - HDX DOM structure containing an NDX.
page - specifies the desired NDX (default: 0)
Throws:
IOException
Method Detail

getCurrentNDXIndex

public int getCurrentNDXIndex()
Return the index of the current NDX


getStream

protected BufferedInputStream getStream(String fileOrUrl)
                                 throws IOException
Return a BufferedInputStream for the given file or URL.

Throws:
IOException

getURL

protected URL getURL(String fileOrUrl)
              throws MalformedURLException
Return a URL for the given file or URL string.

Throws:
MalformedURLException

getNumNDXs

public int getNumNDXs()
Return the number of NDXs in the HDX structure.


setNDX

public void setNDX(int num)
            throws IOException
Set the current NDX from those available.

Parameters:
num - The NDX number (starts at 0).
Throws:
IOException

close

public void close()
           throws IOException
Close the current "HDX".

Throws:
IOException

getBadValue

public double getBadValue()
Return the Bad pixel value for the current NDArray. Returns Double.NaN if none is defined.


setDefaultTileWidth

public static void setDefaultTileWidth(int w)

getDefaultTileWidth

public static int getDefaultTileWidth()

setDefaultTileHeight

public static void setDefaultTileHeight(int h)

getDefaultTileHeight

public static int getDefaultTileHeight()

clearTileCache

public void clearTileCache()
Try to save memory by clearing out the tile cache for this image.


getProperty

public Object getProperty(String name)
Gets a property from the property set of this HDX structure.

Specified by:
getProperty in interface RenderedImage
Overrides:
getProperty in class SimpleRenderedImage
Parameters:
name - the name of the property to get, as a String.
Returns:
a reference to the property value or null if not found.

getPropertyNames

public String[] getPropertyNames()
Returns a list of property names that are recognized by this image.

Specified by:
getPropertyNames in interface RenderedImage
Overrides:
getPropertyNames in class SimpleRenderedImage
Returns:
an array of Strings containing valid property names.

getPreviewImage

protected javax.media.jai.TiledImage getPreviewImage(int size)
Return a prescaled PlanarImage that fits entirely in a window of the given size, or null if there are any errors.


initColorModel

public ColorModel initColorModel()
Set the colormodel to use to display FITS images.


initSampleModel

public SampleModel initSampleModel(int tileWidth,
                                   int tileHeight)
Return a SampleModel for this image with the given tile width and height.


initData

public void initData()
              throws IOException
Create an object to manage the data based on the type and set the value of the dataType member variable to the correct DataBuffer constant to use for the sample model.

Throws:
IOException

getTile

public Raster getTile(int tileX,
                      int tileY)
Generate and return the given tile (required by the RenderedImage interface). Note that tileX and tileY are indices into the tile array, not pixel locations.

Parameters:
tileX - the X index of the requested tile in the tile array.
tileY - the Y index of the requested tile in the tile array.
Returns:
the tile given by (tileX, tileY).

fillTile

protected Raster fillTile(Raster tile)
This method fills the given tile with the appropriate image data.


setPreviewSize

public static void setPreviewSize(int i)
Set the requested size for the preview image


getPreviewSize

public static int getPreviewSize()
Return the requested size for the preview image


getCurrentNDX

public Ndx getCurrentNDX()
Get a reference to the current NDX. This allows access to other goodies such as WCS information and the size of the image etc. Notes that you should use this reference and then throw it away as currently this HDXImage may change the NDX that it is using.


getRealWidth

public int getRealWidth()
Returns the real width of the image. This may be different than the value returned by getWidth() if the image is zoomed out.


getRealHeight

public int getRealHeight()
Returns the real height of the image. This may be different than the value returned by getHeight() if the image is zoomed out.


setScale

public boolean setScale(float scale)
                 throws IOException
Set the scale (zoom factor) for the image and return true if a new image was generated.

Note that zooming out is handled here for performance reasons, to avoid having to read in whole tiles, only to discard most of the data later. Zooming in should be handled in the image viewer widget at the end of the image processing chain.

Parameters:
scale - the scale factor (a value of less than 1.0 means the image is zoomed out and is handled specially here)
Returns:
true if the new scale value caused a new image to be generated, requiring an image update in the viewer widget.
Throws:
IOException

getScale

public float getScale()
Return the current scale factor (zooming out is handled here for performance reasons). Zooming in still needs to be done by the image widget.


getSubsample

public int getSubsample()
Return the increment to use when accessing the image data if scale is less than 1. A value of 1 means no scaling is done.



Copyright © 2015 Central Laboratory of the Research Councils. All Rights Reserved.