|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
ObjectImageWriter
MosaicImageWriter
public class MosaicImageWriter
An image writer which takes a large image (potentially tiled) in input and write tiles as
output. The mosaic to write is specified as a collection of Tile objects given to
the setOutput(Object) method. The pixel values to write can be specified either
as a RenderedImage (this is the standard API), or as a single
File or a collection of source tiles given to the writeFromInput(Object,
ImageWriteParam) method. The later alternative is non-standard but often required since
the image to mosaic is typically bigger than the capacity of a single RenderedImage.
Caching of source tiles
This class may be slow when reading source images encoded in a compressed format like PNG,
because multiple passes over the same image may be necessary for writing different tiles
and compression makes the seeks harder. This problem can be mitigated by copying the source
images to temporary files in an uncompressed RAW format. The inconvenient is that a large
amount of disk space will be temporarily required until the write operation is completed.
Caching are enabled by default. If the environment is constrained by disk space or if the
source tiles are known to be already uncompressed, then caching can be disabled by overriding
the isCachingEnabled(ImageReader,int) method.
Filtering source images
It is possible to apply an operation on source images before to create the target tiles. The
operation can be specified by the MosaicImageWriteParam.setSourceTileFilter(BufferedImageOp)
method, for example in order to add transparency to fully opaque images. Note that if an operation
is applied, then the source tiles will be cached in temporary RAW files as described in the above
section even if isCachingEnabled(ImageReader,int) returns false.
| coverage/geotk-coverageio (download) | View source code for this class |
| Nested Class Summary | |
|---|---|
static class |
MosaicImageWriter.Spi
Service provider for MosaicImageWriter. |
| Field Summary |
|---|
| Fields inherited from class ImageWriter |
|---|
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales |
| Constructor Summary | |
|---|---|
MosaicImageWriter()
Constructs an image writer with the default provider. |
|
MosaicImageWriter(ImageWriterSpi spi)
Constructs an image writer with the specified provider. |
|
| Method Summary | |
|---|---|
IIOMetadata |
convertImageMetadata(IIOMetadata inData,
ImageTypeSpecifier imageType,
ImageWriteParam param)
Returns image metadata initialized to the specified state, or null. |
IIOMetadata |
convertStreamMetadata(IIOMetadata inData,
ImageWriteParam param)
Returns stream metadata initialized to the specified state, or null. |
void |
dispose()
Disposes resources held by this writer. |
protected boolean |
filter(ImageReader reader)
Invoked after MosaicImageWriter has created a reader and
set the input. |
protected boolean |
filter(ImageWriter writer)
Invoked after MosaicImageWriter has created a writer and
set the output. |
IIOMetadata |
getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param)
Returns the default image metadata, or null if none. |
IIOMetadata |
getDefaultStreamMetadata(ImageWriteParam param)
Returns the default stream metadata, or null if none. |
MosaicImageWriteParam |
getDefaultWriteParam()
Returns default parameters appropriate for this format. |
Level |
getLogLevel()
Returns the logging level for tile information during read and write operations. |
long |
getMaximumMemoryAllocation()
Returns the maximal amount of memory that writeFromInput is allowed
to use. |
TileManager[] |
getOutput()
Returns the output, which is a an array of tile managers. |
protected boolean |
isCachingEnabled(ImageReader input,
int inputIndex)
Returns true if this writer is allowed to copy source images to temporary
uncompressed RAW files. |
protected void |
onTileWrite(Tile tile,
ImageWriteParam parameters)
Invoked automatically when a tile is about to be written. |
void |
reset()
Resets this writer to its initial state. |
void |
setLogLevel(Level level)
Sets the logging level for tile information during read and write operations. |
void |
setOutput(Object output)
Sets the output, which is expected to be an array of tile managers. |
void |
write(IIOMetadata metadata,
IIOImage image,
ImageWriteParam param)
Writes the specified image as a set of tiles. |
boolean |
writeFromInput(Object input,
ImageWriteParam param)
Reads the image from the given input and writes it as a set of tiles. |
boolean |
writeFromInput(Object input,
int inputIndex,
ImageWriteParam param)
Reads the image from the given input and writes it as a set of tiles. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MosaicImageWriter()
public MosaicImageWriter(ImageWriterSpi spi)
spi - The service provider, or null for the default one.| Method Detail |
|---|
public Level getLogLevel()
PerformanceLevel constants, determined
according the duration of the operation.
getLogLevel in interface LogProducerpublic void setLogLevel(Level level)
null value restores the default level documented in the getLogLevel()
method.
setLogLevel in interface LogProducerlevel - The new logging level, or null for the default.public TileManager[] getOutput()
getOutput in class ImageWriter
public void setOutput(Object output)
throws IllegalArgumentException
Tile objects, then it will be wrapped in an array of TileManagers.
setOutput in class ImageWriteroutput - The output.
IllegalArgumentException - if output is not an instance of one of the
expected classes, or if the output can not be used because of an I/O error
(in which case the exception has a IOException as its
cause).public MosaicImageWriteParam getDefaultWriteParam()
getDefaultWriteParam in class ImageWriter
public void write(IIOMetadata metadata,
IIOImage image,
ImageWriteParam param)
throws IOException
writeFromInput(java.lang.Object, javax.imageio.ImageWriteParam). This very inefficient approach
may be changed in a future version.
write in class ImageWritermetadata - The stream metadata.image - The image to write.param - The parameter for the image to write.
IOException - if an error occurred while writing the image.
public boolean writeFromInput(Object input,
ImageWriteParam param)
throws IOException
writeFromInput(input,
0, param) except that this method ensures that the input contains only one
image. If more than one image is found, then an exception is throw. This is often desirable
when the input is a collection of Tiles, since having more than one "image" (where
"image" in this context means an input mosaic as a whole) means that we failed to create a
single mosaic from a set of source tiles.
input - The image input, typically as a File.param - The write parameters, or null for the default.
true on success, or false if the process has been aborted.
IOException - If an error occurred while reading or writing.
public boolean writeFromInput(Object input,
int inputIndex,
ImageWriteParam param)
throws IOException
File object, but other kind of inputs may be accepted depending on available image
readers. The output files and tiling layout can be specified as a collection of Tile
objects given to setOutput(Object) method.
input - The image input, typically as a File.inputIndex - The image index to read from the given input file.param - The write parameters, or null for the default.
true on success, or false if the process has been aborted.
IOException - If an error occurred while reading or writing.public long getMaximumMemoryAllocation()
writeFromInput is allowed
to use. The default implementation computes a value from the amount of memory available in
the current JVM. Subclasses can override this method for returning a different value.
The returned value will be considered on a best effort basis. There is no guarantee that no more memory than the returned value will be used.
protected boolean isCachingEnabled(ImageReader input,
int inputIndex)
throws IOException
true if this writer is allowed to copy source images to temporary
uncompressed RAW files. Doing so can speed up considerably the creation of large
mosaics, at the expense of temporary disk space.
The default implementation returns true if the following conditions are meet:
false.Subclasses should override this method if they can provide a better answer, or if they known that their source tiles are already uncompressed.
Note: This method is invoked only in the context ofwriteFromInput(Object, …)methods, which get the image to write from anImageReader. This method is not invoked in the context of thewrite(RenderedImage)method because an image available in memory (ignoring JAI tiling) is assumed to not need disk cache. For this reason there is noisCachingEnabled(RenderedImage)method.
input - The input image or mosaic, an an ImageReader with its
input set.inputIndex - The image index to read from the given input file.
true if this writer can cache the source tiles.
IOException - If this method required an I/O operation and that operation failed.
protected boolean filter(ImageReader reader)
throws IOException
MosaicImageWriter has created a reader and
set the input. Users can override this method
for performing additional configuration and may returns false if the given reader
is not suitable. The default implementation returns true in all case.
reader - The image reader created and configured by MosaicImageWriter.
true If the given reader is ready for use, or false if an other
reader should be fetched.
IOException - if an error occurred while inspecting or configuring the reader.
protected boolean filter(ImageWriter writer)
throws IOException
MosaicImageWriter has created a writer and
set the output. Users can override this method
for performing additional configuration and may returns false if the given writer
is not suitable. The default implementation returns true in all case.
writer - The image writer created and configured by MosaicImageWriter.
true If the given writer is ready for use, or false if an other
writer should be fetched.
IOException - if an error occurred while inspecting or configuring the writer.
protected void onTileWrite(Tile tile,
ImageWriteParam parameters)
throws IOException
The source region and
source subsampling parameters can not be
set through this method. Their setting will be overwritten by the caller because their
values depend on the strategy chosen by MosaicImageWriter for reading images,
which itself depends on the amount of available memory.
tile - The tile to be written.parameters - The parameters to be given to the image writer.
This method is allowed to change the parameter values.
IOException - if an I/O operation was required and failed.public IIOMetadata getDefaultStreamMetadata(ImageWriteParam param)
null if none.
The default implementation returns null in all cases.
getDefaultStreamMetadata in class ImageWriter
public IIOMetadata getDefaultImageMetadata(ImageTypeSpecifier imageType,
ImageWriteParam param)
null if none.
The default implementation returns null in all cases.
getDefaultImageMetadata in class ImageWriter
public IIOMetadata convertStreamMetadata(IIOMetadata inData,
ImageWriteParam param)
null.
The default implementation returns null in all cases since this plugin
doesn't provide metadata encoding capabilities.
convertStreamMetadata in interface ImageTranscoderconvertStreamMetadata in class ImageWriter
public IIOMetadata convertImageMetadata(IIOMetadata inData,
ImageTypeSpecifier imageType,
ImageWriteParam param)
null.
The default implementation returns null in all cases since this plugin
doesn't provide metadata encoding capabilities.
convertImageMetadata in interface ImageTranscoderconvertImageMetadata in class ImageWriterpublic void reset()
reset in class ImageWriterpublic void dispose()
dispose in interface Disposabledispose in class ImageWriter
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||