org.geotools.image.io.mosaic
Class MosaicImageWriter

java.lang.Object
  extended by javax.imageio.ImageWriter
      extended by org.geotools.image.io.mosaic.MosaicImageWriter
All Implemented Interfaces:
javax.imageio.ImageTranscoder

public class MosaicImageWriter
extends javax.imageio.ImageWriter

An image writer that delegates to a mosaic of other image writers. The mosaic is specified as a collection of Tile objects given to setOutput(Object) method. While this class can write a RenderedImage, the preferred approach is to invoke writeFromInput(java.lang.Object, int, javax.imageio.ImageWriteParam) with a File input in argument. This approach is non-standard but often required since images to mosaic are typically bigger than RenderedImage capacity.

Since:
2.5
Version:
$Id: MosaicImageWriter.java 31445 2008-09-07 18:14:23Z desruisseaux $
Author:
Cédric Briançon, Martin Desruisseaux

Nested Class Summary
static class MosaicImageWriter.Spi
          Service provider for MosaicImageWriter.
 
Field Summary
 
Fields inherited from class javax.imageio.ImageWriter
availableLocales, locale, originatingProvider, output, progressListeners, warningListeners, warningLocales
 
Constructor Summary
MosaicImageWriter()
          Constructs an image writer with the default provider.
MosaicImageWriter(javax.imageio.spi.ImageWriterSpi spi)
          Constructs an image writer with the specified provider.
 
Method Summary
 javax.imageio.metadata.IIOMetadata convertImageMetadata(javax.imageio.metadata.IIOMetadata inData, javax.imageio.ImageTypeSpecifier imageType, javax.imageio.ImageWriteParam param)
          Returns image metadata initialized to the specified state, or null.
 javax.imageio.metadata.IIOMetadata convertStreamMetadata(javax.imageio.metadata.IIOMetadata inData, javax.imageio.ImageWriteParam param)
          Returns stream metadata initialized to the specified state, or null.
 void dispose()
          Disposes resources held by this writter.
protected  boolean filter(javax.imageio.ImageReader reader)
          Invoked after MosaicImageWriter has created a reader and set the input.
protected  boolean filter(javax.imageio.ImageWriter writer)
          Invoked after MosaicImageWriter has created a writer and set the output.
 javax.imageio.metadata.IIOMetadata getDefaultImageMetadata(javax.imageio.ImageTypeSpecifier imageType, javax.imageio.ImageWriteParam param)
          Returns the default image metadata, or null if none.
 javax.imageio.metadata.IIOMetadata getDefaultStreamMetadata(javax.imageio.ImageWriteParam param)
          Returns the default stream metadata, or null if none.
 MosaicImageWriteParam getDefaultWriteParam()
          Returns default parameters appropriate for this format.
 java.util.logging.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  void onTileWrite(Tile tile, javax.imageio.ImageWriteParam parameters)
          Invoked automatically when a tile is about to be written.
 void setLogLevel(java.util.logging.Level level)
          Sets the logging level for tile information during read and write operations.
 void setOutput(java.lang.Object output)
          Sets the output, which is expected to be an array of tile managers.
 void write(javax.imageio.metadata.IIOMetadata metadata, javax.imageio.IIOImage image, javax.imageio.ImageWriteParam param)
          Writes the specified image as a set of tiles.
 boolean writeFromInput(java.lang.Object input, int inputIndex, javax.imageio.ImageWriteParam param)
          Reads the image from the given input and writes it as a set of tiles.
 
Methods inherited from class javax.imageio.ImageWriter
abort, abortRequested, addIIOWriteProgressListener, addIIOWriteWarningListener, canInsertEmpty, canInsertImage, canRemoveImage, canReplaceImageMetadata, canReplacePixels, canReplaceStreamMetadata, canWriteEmpty, canWriteRasters, canWriteSequence, clearAbortRequest, endInsertEmpty, endReplacePixels, endWriteEmpty, endWriteSequence, getAvailableLocales, getLocale, getNumThumbnailsSupported, getOriginatingProvider, getPreferredThumbnailSizes, prepareInsertEmpty, prepareReplacePixels, prepareWriteEmpty, prepareWriteSequence, processImageComplete, processImageProgress, processImageStarted, processThumbnailComplete, processThumbnailProgress, processThumbnailStarted, processWarningOccurred, processWarningOccurred, processWriteAborted, removeAllIIOWriteProgressListeners, removeAllIIOWriteWarningListeners, removeIIOWriteProgressListener, removeIIOWriteWarningListener, removeImage, replaceImageMetadata, replacePixels, replacePixels, replaceStreamMetadata, reset, setLocale, write, write, writeInsert, writeToSequence
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MosaicImageWriter

public MosaicImageWriter()
Constructs an image writer with the default provider.


MosaicImageWriter

public MosaicImageWriter(javax.imageio.spi.ImageWriterSpi spi)
Constructs an image writer with the specified provider.

Parameters:
spi - The service provider, or null for the default one.
Method Detail

getLogLevel

public java.util.logging.Level getLogLevel()
Returns the logging level for tile information during read and write operations.

Returns:
The current logging level.

setLogLevel

public void setLogLevel(java.util.logging.Level level)
Sets the logging level for tile information during read and write operations. The default value is Level.FINE. A null value restore the default.

Parameters:
level - The new logging level, or null for the default.

getOutput

public TileManager[] getOutput()
Returns the output, which is a an array of tile managers. The array length is the maximum number of images that can be inserted. The element at index i is the tile manager to use when writing at image index i.

Overrides:
getOutput in class javax.imageio.ImageWriter

setOutput

public void setOutput(java.lang.Object output)
               throws java.lang.IllegalArgumentException
Sets the output, which is expected to be an array of tile managers. If the given input is a singleton, an array or a collection of Tile objects, then it will be wrapped in an array of TileManagers.

Overrides:
setOutput in class javax.imageio.ImageWriter
Parameters:
output - The output.
Throws:
java.lang.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).

getDefaultWriteParam

public MosaicImageWriteParam getDefaultWriteParam()
Returns default parameters appropriate for this format.

Overrides:
getDefaultWriteParam in class javax.imageio.ImageWriter

write

public void write(javax.imageio.metadata.IIOMetadata metadata,
                  javax.imageio.IIOImage image,
                  javax.imageio.ImageWriteParam param)
           throws java.io.IOException
Writes the specified image as a set of tiles. The default implementation copies the image in a temporary file, then invokes writeFromInput(java.lang.Object, int, javax.imageio.ImageWriteParam). This somewhat inefficient approach may be changed in a future version.

Specified by:
write in class javax.imageio.ImageWriter
Parameters:
metadata - The stream metadata.
image - The image to write.
param - The parameter for the image to write.
Throws:
java.io.IOException - if an error occured while writing the image.

writeFromInput

public boolean writeFromInput(java.lang.Object input,
                              int inputIndex,
                              javax.imageio.ImageWriteParam param)
                       throws java.io.IOException
Reads the image from the given input and writes it as a set of tiles. The input is typically a 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.

Parameters:
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.
Returns:
true on success, or false if the process has been aborted.
Throws:
java.io.IOException - If an error occured while reading or writing.

getMaximumMemoryAllocation

public long getMaximumMemoryAllocation()
Returns the maximal amount of memory that 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 garantee that no more memory than the returned value will be used.

Returns:
An estimation of the maximum amount of memory allowed for allocation, in bytes.

filter

protected boolean filter(javax.imageio.ImageReader reader)
                  throws java.io.IOException
Invoked after 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.

Parameters:
reader - The image reader created and configured by MosaicImageWriter.
Returns:
true If the given reader is ready for use, or false if an other reader should be fetched.
Throws:
java.io.IOException - if an error occured while inspecting or configuring the reader.

filter

protected boolean filter(javax.imageio.ImageWriter writer)
                  throws java.io.IOException
Invoked after 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.

Parameters:
writer - The image writer created and configured by MosaicImageWriter.
Returns:
true If the given writer is ready for use, or false if an other writer should be fetched.
Throws:
java.io.IOException - if an error occured while inspecting or configuring the writer.

onTileWrite

protected void onTileWrite(Tile tile,
                           javax.imageio.ImageWriteParam parameters)
                    throws java.io.IOException
Invoked automatically when a tile is about to be written. The default implementation does nothing. Subclasses can override this method in order to set custom write parameters.

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 choosen by MosaicImageWriter for reading images, which itself depends on the amount of available memory.

Parameters:
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.
Throws:
java.io.IOException - if an I/O operation was required and failed.

getDefaultStreamMetadata

public javax.imageio.metadata.IIOMetadata getDefaultStreamMetadata(javax.imageio.ImageWriteParam param)
Returns the default stream metadata, or null if none. The default implementation returns null in all cases.

Specified by:
getDefaultStreamMetadata in class javax.imageio.ImageWriter

getDefaultImageMetadata

public javax.imageio.metadata.IIOMetadata getDefaultImageMetadata(javax.imageio.ImageTypeSpecifier imageType,
                                                                  javax.imageio.ImageWriteParam param)
Returns the default image metadata, or null if none. The default implementation returns null in all cases.

Specified by:
getDefaultImageMetadata in class javax.imageio.ImageWriter

convertStreamMetadata

public javax.imageio.metadata.IIOMetadata convertStreamMetadata(javax.imageio.metadata.IIOMetadata inData,
                                                                javax.imageio.ImageWriteParam param)
Returns stream metadata initialized to the specified state, or null. The default implementation returns null in all cases since this plugin doesn't provide metadata encoding capabilities.

Specified by:
convertStreamMetadata in interface javax.imageio.ImageTranscoder
Specified by:
convertStreamMetadata in class javax.imageio.ImageWriter

convertImageMetadata

public javax.imageio.metadata.IIOMetadata convertImageMetadata(javax.imageio.metadata.IIOMetadata inData,
                                                               javax.imageio.ImageTypeSpecifier imageType,
                                                               javax.imageio.ImageWriteParam param)
Returns image metadata initialized to the specified state, or null. The default implementation returns null in all cases since this plugin doesn't provide metadata encoding capabilities.

Specified by:
convertImageMetadata in interface javax.imageio.ImageTranscoder
Specified by:
convertImageMetadata in class javax.imageio.ImageWriter

dispose

public void dispose()
Disposes resources held by this writter. This method should be invoked when this writer is no longer in use, in order to release some threads created by the writer.

Overrides:
dispose in class javax.imageio.ImageWriter


Copyright © 1996-2010 Geotools. All Rights Reserved.