Class TLcdJAIRasterModelDecoder
- All Implemented Interfaces:
ILcdModelDecoder
jai
files. A
jai
file is a java properties file that describes the spatial
reference of an image. The actual image is decoded by the Java Advanced
Imaging library.
Input files
File | Required | Entry point | Description |
---|---|---|---|
*.jai | x | x | File containing the raster metadata: image file name, a model reference, and raster bounds |
*.* | x | Image file containing the actual raster data |
The decoder looks for the following properties when decoding an
rst
file. Each of the keys must be preceded by
"TLcdJAIRasterModelDecoder.
". If a property is not specified,
the corresponding property of the decoder is used as default.
The name of the single image file that contains the raster data:
directoryPath
(optional): the location of the image data. This string is prefixed to the file name, so it typically should contain a trailing slash or backslash. The path can be a file path or a URL. The default is the location of thejai
file itself.fileName
: the relative file name of the image.
General information that may be useful for applications:
displayName
: a convenient name for the data, stored in theILcdModelDescriptor
of the decoded model.typeName
: the type of the data, stored in theILcdModelDescriptor
of the decoded model. For instance CADRG, jog, GeoTIFF,...
Information about the position and size of the raster in model coordinates:
ulx
: the abscissa of the upper-left corner of the raster, expressed in model coordinates.uly
: the ordinate of the upper-left corner of the raster, expressed in model coordinates.rasterWidth
: the width of the raster, expressed in model coordinates.rasterHeight
: the height of the raster, expressed in model coordinates.
Information about the tile/level structure of each raster.
noTileRows
(default = 1): the number of tile rows per raster.noTileColumns
(default = 1): the number of tile columns per raster.tileWidth
: the width of one tile, expressed in model coordinates. The default is the raster width divided by the number of tile columns.tileHeight
: the height of one tile, expressed in model coordinates. The default is the raster height divided by the number of tile rows.pixelDensity
: the estimated number of pixels per unit area in this raster. Alternatively, the decoder can compute the pixel density itself, based on the image file and its bounds in model coordinates or the pixel size metadata documented below. The pixel density is typically used to determine the right level of detail during display, without having to read the all the tiles.
Information about the size in pixels of the raster and tiles. These properties are optional and are only used for pixel density calculation.
tilePixelWidth
: the width of a single tile in pixels.tilePixelHeight
: the height of a single tile in pixels.rasterPixelWidth
: the width of the raster in pixels.rasterPixelHeight
: the height of the raster in pixels.
Information about the size in pixels of the raster and tiles. These properties are optional and are only used for pixel density calculation.
tilePixelWidth
: the width of a single tile in pixels.tilePixelHeight
: the height of a single tile in pixels.rasterPixelWidth
: the width of the raster in pixels.rasterPixelHeight
: the height of the raster in pixels.
Information for creating multiple raster levels on the fly:
noLevels
(default = 1): the number of raster levels with varying levels of detail that should be constructed on the fly, and cached, for more efficient access by the application. If 1, a single level raster is constructed. If larger than 1, a multi-level raster is constructed.levelScaleFactor
(default = 0.5): the scale factor between subsequent levels.
Information needed to create an appropriate ColorModel
:
ILcdColorModelFactory.class
(default = none): the name of the class that implements an optionalILcdColorModelFactory
. This factory must produce aColorModel
that is compatible with the given data. It is only required if the image files themselves don't provide the right color model.defaultPixel
(default = 0): the default color value or index that is assigned to pixels that don't have a value, e.g. pixels outside the raster bounds. This should typically be the transparent color or color index, so that missing pixels inside the raster and pixels outside the raster are transparent. The value may be prefixed by0x
to indicate a hexadecimal value.forcedTransparentColorIndex
(default = -1): the index of a color that should be made transparent in the models that will be decoded next. This can be useful if the image has an IndexColorModel that doesn't contain a transparent color of its own.
Model reference
Finally, an important set of properties specifies the appropriateILcdModelReference
. The creation as such of an
ILcdModelReference
is delegated to the
TLcdModelReferenceFactory
. The starting point is a property
that specifies the class:
ILcdModelReference.class
: the fully qualified class name of the model reference.
ILcdModelReference
determines which properties are
required. For more information on what properties are needed, see the various
implementations of ILcdModelReference
.
The above properties can also be set on this class directly. The method
decodeJAI
will then decode the given image file with these
settings.
The following excerpt of an jai
file illustrates the creation of a
TLcdGridReference
based on a Transverse Mercator projection and the
WGS84 geodetic datum.
TLcdRasterModelDecoder.ILcdModelReference.class = com.luciad.reference.TLcdGridReference
TLcdJAIRasterModelDecoder.TLcdGridReference.projection.ILcdProjection.class = com.luciad.projection.TLcdTransverseMercator
TLcdJAIRasterModelDecoder.TLcdGridReference.projection.TLcdTransverseMercator.centralMeridian =-75.0
TLcdJAIRasterModelDecoder.TLcdGridReference.falseEasting = 500000
TLcdJAIRasterModelDecoder.TLcdGridReference.falseNorthing = 0.0
TLcdJAIRasterModelDecoder.TLcdGridReference.scale = 0.9996
TLcdJAIRasterModelDecoder.TLcdGridReference.unitOfMeasure = 1
TLcdJAIRasterModelDecoder.TLcdGridReference.geodeticDatum.ILcdGeodeticDatumFactory.class = com.luciad.geodesy.TLcdJPLGeodeticDatumFactory
TLcdJAIRasterModelDecoder.TLcdGridReference.geodeticDatum.TLcdJPLGeodeticDatumFactory = WGS\ 84
Note that the TLcdModelReferenceFactory
may call on other
factories to which it will pass on the properties, so that those factories
may look for the information that they require. The class
ILcdGeodeticDatumFactory
, in previous illustration, is such a
factory.
Supported file transfer protocols
- This model decoder supports all transfer protocols that are supported by
the
imageInputStreamFactory
of this decoder. TheimageInputStreamFactory
must produce aSeekableStream
.
Model structure
- This model decoder creates a model per
jai
file. - All models returned by this model decoder implement
ILcd2DBoundsIndexedModel
.
Model descriptor
- All models returned by this model decoder have a
TLcdJAIModelDescriptor
or aTLcdMultilevelJAIModelDescriptor
. - The type name of the model descriptor is the display name of this decoder.
Model elements
- Each decoded model contains a single element that implements
ALcdImage
(and eitherILcdRaster
orILcdMultilevelRaster)
).
Useful settings
- The property
sourceName
(default = fileName) allows to specify the full name of the image, in case only aRenderedImage
is provided to the decoder. - The property
JAIOperator
(default = "stream
") specifies the JAI operator that is used to load the image. - The property
imageInputStreamFactory
specifies the factory that will be used to create the input streams from which images can be decoded. It is only used if the JAI operator is "stream
" (the default). It must createSeekableInputStream
instances, in order for JAI to be able to use them. - The property
levelInterpolation
specifies the interpolation that is used to derive lower-resolution levels (default =null
, for nearest neighbor interpolation). - The properties
colorModel
,defaultValue
,forcedTransparentColorIndex
, andexpandColorMap
provide some control over the color models that are attached to the decoded rasters, if the color models of the images aren't quite suitable.
Sample code
ILcdModelDecoder decoder = new TLcdJAIRasterModelDecoder();
ILcdModel model = decoder.decode("raster.jai");
Performance tips
- The decoder makes use of the Java Advanced Imaging library for decoding
and caching images. It may therefore be helpful to tune the cache
size of Java Advanced Imaging:
JAI.getDefaultInstance().getTileCache().setMemoryCapacity(size);
- The decoder supports tiled images. Tiled images can greatly improve access times and reduce memory usage, since only the required parts of the images are decoded and cached.
- It is possible to compute and cache lower resolution images on the
fly, by means of the properties
levelCount
,levelScaleFactor
, andlevelInterpolation
. Although there is an obvious overhead compared to the precomputed levels of detail, this technique still provides better raster painting performance when zoomed out.
Thread safety
- The decoding of models is thread-safe, as long as no properties are changed during the decoding.
- The decoded models are thread-safe for read access.
Known limitations
- The
jai
format is closely tied to the LuciadLightspeed library. - The current implementation of Java Advanced Imaging does not support TIFF RGB rasters with a planar configuration.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionCreates a new TLcdJAIRasterModelDecoder that creates single level raster models by default.TLcdJAIRasterModelDecoder
(int aLevelCount, double aLevelScaleFactor, javax.media.jai.Interpolation aLevelInterpolation) Creates a new TLcdJAIRasterModelDecoder that creates multi-level raster models by default. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canDecodeSource
(String aSourceName) Checks whether this class can decode the given data.Creates a new model from the given data source.decodeProperties
(String aDirectoryPath, Properties aProperties) Decodes a model containing a raster, based on a given set of properties.decodeRenderedImage
(RenderedImage aRenderedImage) Decodes a given rendered image with the current settings of this model decoder.Returns the color model that is assigned to decoded rasters.int
Returns the default color or color index that is assigned to decoded rasters.Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.int
Returns the index of the color that is made transparent.Returns the factory that creates the input streams for decoding images.Returns the JAI operator that is used to load raster images.int
Returns the number of raster levels that is constructed on the fly.javax.media.jai.Interpolation
Returns the Interpolation that is applied between subsequent levels.double
Returns the scale factor between subsequent levels.Returns the model bounds that are assigned to decoded rasters.Returns the model reference that is assigned to decoded models.double
Returns the pixel density that is assigned to decoded rasters.Returns the default source name for decoded raster models.Returns the default type name for decoded raster models.boolean
Deprecated.This method has been deprecated.static void
setClassTraceOn
(boolean aClassTraceOn) Deprecated.This method has been deprecated.void
setColorModel
(ColorModel aColorModel) Sets the color model to be assigned to decoded rasters.void
setDefaultValue
(int aDefaultValue) Sets the default color or color index to be assigned to decoded rasters.void
setDisplayName
(String aDisplayName) Sets the default display name for decoded raster models, in case the properties file doesn't provide one.void
setForcedTransparentColorIndex
(int aForcedTransparentColorIndex) Sets the index of the color that should be made transparent in the rasters that will be decoded next.void
setImageInputStreamFactory
(ILcdInputStreamFactory aImageInputStreamFactory) Sets the factory that will create the input streams from which images can be decoded.void
setJAIOperator
(String aJAIOperator) Sets the JAI operator to be used to load raster images.void
setLevelCount
(int aLevelCount) Sets the default number of raster levels with varying levels of detail that should be constructed on the fly, in case the properties file doesn't provide one.void
setLevelInterpolation
(javax.media.jai.Interpolation aLevelInterpolation) Sets the Interpolation to be applied between subsequent levels.void
setLevelScaleFactor
(double aLevelScaleFactor) Sets the default scale factor between subsequent levels, in case the properties file doesn't provide one.void
setModelBounds
(ILcdBounds aModelBounds) Sets the model bounds to be assigned to decoded rasters.void
setModelReference
(ILcdModelReference aModelReference) Sets the model reference to be assigned to decoded models.void
setPixelDensity
(double aPixelDensity) Sets the pixel density to be assigned to decoded rasters.void
setSourceName
(String aSourceName) Sets the default source name for decoded raster models, in case the properties file doesn't provide one.void
setTraceOn
(boolean aTraceOn) Deprecated.This method has been deprecated.void
setTypeName
(String aTypeName) Sets the default type name for decoded raster models, in case the properties file doesn't provide one.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.luciad.model.ILcdModelDecoder
canDecodeSource, decodeModelMetadata, decodeModelMetadata, decodeSource, discoverDataSources
-
Field Details
-
DEFAULT_DISPLAY_NAME
- See Also:
-
DEFAULT_EXTENSION
- See Also:
-
DEFAULT_JAI_OPERATOR
- See Also:
-
-
Constructor Details
-
TLcdJAIRasterModelDecoder
public TLcdJAIRasterModelDecoder()Creates a new TLcdJAIRasterModelDecoder that creates single level raster models by default. -
TLcdJAIRasterModelDecoder
public TLcdJAIRasterModelDecoder(int aLevelCount, double aLevelScaleFactor, javax.media.jai.Interpolation aLevelInterpolation) Creates a new TLcdJAIRasterModelDecoder that creates multi-level raster models by default.- Parameters:
aLevelCount
- the number of rasters levels.aLevelScaleFactor
- the scale factor between subsequent levels, in both raster dimensions.aLevelInterpolation
- the type of interpolation between subsequent levels.
-
-
Method Details
-
setClassTraceOn
public static void setClassTraceOn(boolean aClassTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for all instances of this class. If the argument istrue
then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.- Parameters:
aClassTraceOn
- if true then all log messages are recorded, otherwise only the informative, warning and error messages are recorded.
-
setTraceOn
public void setTraceOn(boolean aTraceOn) Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Enables tracing for this class instance. Calling this method with eithertrue
orfalse
as argument automatically turns off tracing for all other class instances for whichsetTraceOn
has not been called. If the argument isfalse
then only the informative, warning and error log messages are recorded.- Parameters:
aTraceOn
- if true then all log messages are recorded for this instance. If false, then only the informative, warning and error log messages are recorded.
-
isTraceOn
public boolean isTraceOn()Deprecated.This method has been deprecated. It is recommended to use the standard Java logging framework directly.Returnstrue
if tracing is enabled for this class.- Returns:
- true if tracing is enabled for this class, false otherwise.
-
setSourceName
Sets the default source name for decoded raster models, in case the properties file doesn't provide one. -
getSourceName
Returns the default source name for decoded raster models. -
setDisplayName
Sets the default display name for decoded raster models, in case the properties file doesn't provide one. -
getDisplayName
Description copied from interface:ILcdModelDecoder
Returns a short, displayable name for the format that is decoded by thisILcdModelDecoder
.- Specified by:
getDisplayName
in interfaceILcdModelDecoder
- Returns:
- the displayable name of this
ILcdModelDecoder
.
-
setTypeName
Sets the default type name for decoded raster models, in case the properties file doesn't provide one. -
getTypeName
Returns the default type name for decoded raster models. -
setJAIOperator
Sets the JAI operator to be used to load raster images. -
getJAIOperator
Returns the JAI operator that is used to load raster images. -
setImageInputStreamFactory
Sets the factory that will create the input streams from which images can be decoded. It will only be used if the JAI operator is "stream
" (the default). It must createjavax.media.jai.codec.SeekableStream
instances, in order for JAI to be able to use them. -
getImageInputStreamFactory
Returns the factory that creates the input streams for decoding images. -
setLevelCount
public void setLevelCount(int aLevelCount) Sets the default number of raster levels with varying levels of detail that should be constructed on the fly, in case the properties file doesn't provide one. If 1, a single level raster is constructed. If larger than 1, a multi-level raster is constructed. -
getLevelCount
public int getLevelCount()Returns the number of raster levels that is constructed on the fly. -
setLevelScaleFactor
public void setLevelScaleFactor(double aLevelScaleFactor) Sets the default scale factor between subsequent levels, in case the properties file doesn't provide one.- See Also:
-
getLevelScaleFactor
public double getLevelScaleFactor()Returns the scale factor between subsequent levels. -
setLevelInterpolation
public void setLevelInterpolation(javax.media.jai.Interpolation aLevelInterpolation) Sets the Interpolation to be applied between subsequent levels.- See Also:
-
getLevelInterpolation
public javax.media.jai.Interpolation getLevelInterpolation()Returns the Interpolation that is applied between subsequent levels. -
setModelReference
Sets the model reference to be assigned to decoded models. -
getModelReference
Returns the model reference that is assigned to decoded models. -
setModelBounds
Sets the model bounds to be assigned to decoded rasters. -
getModelBounds
Returns the model bounds that are assigned to decoded rasters. -
setPixelDensity
public void setPixelDensity(double aPixelDensity) Sets the pixel density to be assigned to decoded rasters. -
getPixelDensity
public double getPixelDensity()Returns the pixel density that is assigned to decoded rasters. -
setColorModel
Sets the color model to be assigned to decoded rasters. -
getColorModel
Returns the color model that is assigned to decoded rasters. -
setDefaultValue
public void setDefaultValue(int aDefaultValue) Sets the default color or color index to be assigned to decoded rasters. -
getDefaultValue
public int getDefaultValue()Returns the default color or color index that is assigned to decoded rasters. -
setForcedTransparentColorIndex
public void setForcedTransparentColorIndex(int aForcedTransparentColorIndex) Sets the index of the color that should be made transparent in the rasters that will be decoded next. This can be useful if the image has an IndexColorModel that doesn't contain a transparent color of its own. -
getForcedTransparentColorIndex
public int getForcedTransparentColorIndex()Returns the index of the color that is made transparent. -
canDecodeSource
Checks whether this class can decode the given data. The extension of the file name should be "jai".- Specified by:
canDecodeSource
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the name of the file or URL that is to be decoded.- Returns:
true
if the data specified by the source name can be decoded,false
otherwise.- See Also:
-
decode
Description copied from interface:ILcdModelDecoder
Creates a new model from the given data source.- Specified by:
decode
in interfaceILcdModelDecoder
- Parameters:
aSourceName
- the data source to be decoded; typically a file name or a URL.- Returns:
- A model containing the decoded data. While
null
is allowed, implementors are advised to throw an error instead. - Throws:
IOException
- for any exceptions caused by IO problems or invalid data. Since decoding invalid data almost always results in RunTimeExceptions (NullPointerException, IndexOutOfBoundsException, IllegalArgumentException, ...) on unexpected places, implementations are advised to catch RuntimeExceptions in their decode() method, and wrap them into an IOException, as illustrated in the code snippet below.public ILcdModel decode( String aSourceName ) throws IOException { try (InputStream input = fInputStreamFactory.createInputStream(aSourceName)) { // Perform decoding ... } catch (RuntimeException e) { throw new IOException(e); } }
- See Also:
-
decodeProperties
Decodes a model containing a raster, based on a given set of properties.- Parameters:
aDirectoryPath
- the directory containing the image file.aProperties
- the properties describing the image file and the way it should be decoded.- Throws:
IOException
-
decodeRenderedImage
Decodes a given rendered image with the current settings of this model decoder.- Throws:
IOException
-