it.tidalwave.imageio.raw
Class RAWImageReaderSupport

java.lang.Object
  extended by javax.imageio.ImageReader
      extended by it.tidalwave.imageio.raw.RAWImageReaderSupport
Direct Known Subclasses:
CRWImageReader, TIFFImageReaderSupport

public abstract class RAWImageReaderSupport
extends javax.imageio.ImageReader

This class provides support for all RAW image readers.

Version:
CVS $Id: RAWImageReaderSupport.java,v 1.8 2006/02/15 13:53:51 fabriziogiudici Exp $
Author:
Fabrizio Giudici

Field Summary
protected  HeaderProcessor headerProcessor
           
protected  RAWImageInputStream iis
          The input object cast as a RAWImageInputStream.
protected  Directory makerNote
          The Maker Note.
protected  RAWMetadataSupport metadata
          The image metadata.
protected  boolean metadataLoaded
          True if metadata has been loaded.
protected  Directory primaryDirectory
          The primary directory.
 
Fields inherited from class javax.imageio.ImageReader
availableLocales, ignoreMetadata, input, locale, minIndex, originatingProvider, progressListeners, seekForwardOnly, updateListeners, warningListeners, warningLocales
 
Constructor Summary
protected RAWImageReaderSupport(javax.imageio.spi.ImageReaderSpi originatingProvider)
           
 
Method Summary
protected  void checkImageIndex(int imageIndex)
          Checks the validity of an image index.
protected  void checkMetadataIsLoaded()
          Checks that metadata has been loaded.
protected  java.awt.image.BufferedImage createImage(int transferType, int colorSpaceType, java.awt.image.WritableRaster raster)
          Create a BufferedImage given a raster.
protected abstract  RAWMetadataSupport createMetadata(Directory primaryDirectory, Directory imageDirectory)
          This method must be implemented by concrete subclasses to create an instance of RAWMetadataSupport.
 void dispose()
           
protected  void disposeAll()
          Releases all the allocated resources.
protected  void ensureMetadataIsLoaded(int imageIndex)
          Ensures that metadata has been loaded; loads it now otherwise.
protected  void failure(java.lang.String message)
          This method is provided for subclasses that want to abort the loading process.
 javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
           
 java.util.Iterator getImageTypes(int imageIndex)
          
 int getNumImages(boolean allowSearch)
          Returns the number of images managed by this ImageReader.
 javax.imageio.metadata.IIOMetadata getStreamMetadata()
          
protected static java.awt.image.BufferedImage loadEmbeddedImage(javax.imageio.stream.ImageInputStream iis, int offset, int length)
          Loads an embedded image.
protected  java.awt.image.BufferedImage loadImage(int imageIndex)
          This default implementation just ensures that metadata is loaded and then calls #loadRAWImage(RAWImageInputStream).
protected  RAWMetadataSupport loadMetadata(int imageIndex)
          Concrete implementation of the metadata loader.
protected abstract  Directory loadPrimaryDirectory()
          Loads the primary directory.
protected  java.awt.image.BufferedImage loadRAWImage()
          Creates a Raster, an image and then invokes loadRAWRaster() to read the actual image data.
protected abstract  java.awt.image.WritableRaster loadRAWRaster()
          This method must be implemented by concrete subclasses to load an image raster.
protected abstract  java.awt.image.BufferedImage loadThumbnail(int imageIndex, int thumbnailIndex)
          This method must be implemented by concrete subclasses to load a thumbnail.
 void processImageProgress(float progress)
          Never use this method.
protected abstract  void processMetadata()
          Analyzes and sets various variables to point at different pieces of metadata.
 java.awt.image.BufferedImage read(int imageIndex, javax.imageio.ImageReadParam param)
          
 boolean readerSupportsThumbnails()
           
 java.awt.image.BufferedImage readThumbnail(int imageIndex, int thumbnailIndex)
          
 void reset()
           
 void setInput(java.lang.Object input, boolean seekForwardOnly, boolean ignoreMetadata)
          Overrides original implementation by calling wrapInput(Object) to give a chance to use a decorator for the input.
protected  java.lang.Object wrapInput(java.lang.Object input)
          Gives a chance to use a decorator for the input object.
 
Methods inherited from class javax.imageio.ImageReader
abort, abortRequested, addIIOReadProgressListener, addIIOReadUpdateListener, addIIOReadWarningListener, canReadRaster, checkReadParamBandSettings, clearAbortRequest, computeRegions, getAspectRatio, getAvailableLocales, getDefaultReadParam, getDestination, getFormatName, getHeight, getImageMetadata, getInput, getLocale, getMinIndex, getNumThumbnails, getOriginatingProvider, getRawImageType, getSourceRegion, getStreamMetadata, getThumbnailHeight, getThumbnailWidth, getTileGridXOffset, getTileGridYOffset, getTileHeight, getTileWidth, getWidth, hasThumbnails, isIgnoringMetadata, isImageTiled, isRandomAccessEasy, isSeekForwardOnly, processImageComplete, processImageStarted, processImageUpdate, processPassComplete, processPassStarted, processReadAborted, processSequenceComplete, processSequenceStarted, processThumbnailComplete, processThumbnailPassComplete, processThumbnailPassStarted, processThumbnailProgress, processThumbnailStarted, processThumbnailUpdate, processWarningOccurred, processWarningOccurred, read, readAll, readAll, readAsRenderedImage, readRaster, readTile, readTileRaster, removeAllIIOReadProgressListeners, removeAllIIOReadUpdateListeners, removeAllIIOReadWarningListeners, removeIIOReadProgressListener, removeIIOReadUpdateListener, removeIIOReadWarningListener, setInput, setInput, setLocale
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

iis

protected RAWImageInputStream iis
The input object cast as a RAWImageInputStream.


metadataLoaded

protected boolean metadataLoaded
True if metadata has been loaded.


metadata

protected RAWMetadataSupport metadata
The image metadata.


primaryDirectory

protected Directory primaryDirectory
The primary directory.


makerNote

protected Directory makerNote
The Maker Note.


headerProcessor

protected HeaderProcessor headerProcessor
Constructor Detail

RAWImageReaderSupport

protected RAWImageReaderSupport(javax.imageio.spi.ImageReaderSpi originatingProvider)
Parameters:
originatingProvider -
Method Detail

read

public final java.awt.image.BufferedImage read(int imageIndex,
                                               javax.imageio.ImageReadParam param)
                                        throws java.io.IOException

Specified by:
read in class javax.imageio.ImageReader
Throws:
java.io.IOException

readThumbnail

public final java.awt.image.BufferedImage readThumbnail(int imageIndex,
                                                        int thumbnailIndex)
                                                 throws java.io.IOException

Overrides:
readThumbnail in class javax.imageio.ImageReader
Throws:
java.io.IOException

getImageMetadata

public javax.imageio.metadata.IIOMetadata getImageMetadata(int imageIndex)
                                                    throws java.io.IOException
Specified by:
getImageMetadata in class javax.imageio.ImageReader
Throws:
java.io.IOException

setInput

public void setInput(java.lang.Object input,
                     boolean seekForwardOnly,
                     boolean ignoreMetadata)
Overrides original implementation by calling wrapInput(Object) to give a chance to use a decorator for the input.

Overrides:
setInput in class javax.imageio.ImageReader

reset

public final void reset()
Overrides:
reset in class javax.imageio.ImageReader

dispose

public final void dispose()
Overrides:
dispose in class javax.imageio.ImageReader

processImageProgress

public void processImageProgress(float progress)
Never use this method. This is to make it public and available to the RasterReader. FIXME: this is not elegant.

Overrides:
processImageProgress in class javax.imageio.ImageReader

readerSupportsThumbnails

public boolean readerSupportsThumbnails()
Overrides:
readerSupportsThumbnails in class javax.imageio.ImageReader

getNumImages

public int getNumImages(boolean allowSearch)
Returns the number of images managed by this ImageReader. There's only ONE image in a RAW file (thumbnails are not counted here).

Specified by:
getNumImages in class javax.imageio.ImageReader
Parameters:
allowSearch - unused
Returns:
the number of managed images

getImageTypes

public java.util.Iterator getImageTypes(int imageIndex)

Specified by:
getImageTypes in class javax.imageio.ImageReader

getStreamMetadata

public javax.imageio.metadata.IIOMetadata getStreamMetadata()

Specified by:
getStreamMetadata in class javax.imageio.ImageReader

loadImage

protected java.awt.image.BufferedImage loadImage(int imageIndex)
                                          throws java.io.IOException
This default implementation just ensures that metadata is loaded and then calls #loadRAWImage(RAWImageInputStream).

Parameters:
imageIndex - the index of the image to load
Returns:
the loaded image
Throws:
java.io.IOException

loadThumbnail

protected abstract java.awt.image.BufferedImage loadThumbnail(int imageIndex,
                                                              int thumbnailIndex)
                                                       throws java.io.IOException
This method must be implemented by concrete subclasses to load a thumbnail.

Parameters:
imageIndex - the index of the image
thumbnailIndex - the index of the thumbnail to load
Returns:
the loaded thumbnail
Throws:
java.io.IOException - if an I/O error occurs

loadRAWRaster

protected abstract java.awt.image.WritableRaster loadRAWRaster()
                                                        throws java.io.IOException
This method must be implemented by concrete subclasses to load an image raster.

Returns:
the loaded raster
Throws:
java.io.IOException - if an I/O error occurs

createMetadata

protected abstract RAWMetadataSupport createMetadata(Directory primaryDirectory,
                                                     Directory imageDirectory)
This method must be implemented by concrete subclasses to create an instance of RAWMetadataSupport. Each SPI should use its own subclass.

Parameters:
primaryDirectory - the primary directory
imageDirectory - the image directory
Returns:
the raw metadata

loadPrimaryDirectory

protected abstract Directory loadPrimaryDirectory()
                                           throws java.io.IOException
Loads the primary directory.

Returns:
the primary directory
Throws:
java.io.IOException - if an I/O error occurs

processMetadata

protected abstract void processMetadata()
                                 throws java.io.IOException
Analyzes and sets various variables to point at different pieces of metadata.

Throws:
java.io.IOException - if an I/O error occurs

wrapInput

protected java.lang.Object wrapInput(java.lang.Object input)
Gives a chance to use a decorator for the input object. By default a RAWImageInputStream is wrapped. Subclasses may change this behaviour by overriding this method.

Parameters:
input - the input object
Returns:
the decorated object

failure

protected void failure(java.lang.String message)
This method is provided for subclasses that want to abort the loading process. This calls the abortRequested() method of the ImageInputStream and then throws a RuntimeException.

Parameters:
message - the message relative to the failure
Throws:
java.lang.RuntimeException - always

createImage

protected java.awt.image.BufferedImage createImage(int transferType,
                                                   int colorSpaceType,
                                                   java.awt.image.WritableRaster raster)
Create a BufferedImage given a raster.

Parameters:
transferType - the transfer type (one of the DataBuffer .TYPE values).
colorSpaceType - the color space type
raster - the raster
Returns:
the new BufferedImage

disposeAll

protected void disposeAll()
Releases all the allocated resources.


checkImageIndex

protected void checkImageIndex(int imageIndex)
Checks the validity of an image index.

Parameters:
imageIndex - the imageindex
Throws:
java.lang.IndexOutOfBoundsException - if the index is invalid

ensureMetadataIsLoaded

protected void ensureMetadataIsLoaded(int imageIndex)
                               throws java.io.IOException
Ensures that metadata has been loaded; loads it now otherwise.

Parameters:
imageIndex -
Throws:
java.lang.IllegalStateException - if metadata can't be loaded
java.io.IOException

checkMetadataIsLoaded

protected void checkMetadataIsLoaded()
Checks that metadata has been loaded.

Throws:
java.lang.IllegalStateException - if metadata is not loaded

loadRAWImage

protected final java.awt.image.BufferedImage loadRAWImage()
                                                   throws java.io.IOException
Creates a Raster, an image and then invokes loadRAWRaster() to read the actual image data.

Returns:
the image
Throws:
java.io.IOException - if an I/O error occurs

loadMetadata

protected RAWMetadataSupport loadMetadata(int imageIndex)
                                   throws java.io.IOException
Concrete implementation of the metadata loader.

Parameters:
imageIndex - the imageIndex of the metadata to load
Returns:
the metadata
Throws:
java.io.IOException - if an I/O error occurs

loadEmbeddedImage

protected static java.awt.image.BufferedImage loadEmbeddedImage(javax.imageio.stream.ImageInputStream iis,
                                                                int offset,
                                                                int length)
                                                         throws java.io.IOException
Loads an embedded image. This method is usually used to laod thumbnails, which are coded as embedded JPEGs. Anyway this method is able to deal with any image format for which a SPI driver is available.

Parameters:
iis - the image input stream
offset - the offset of the image data
length - the length of the image data
Returns:
the image
Throws:
java.io.IOException - if an I/O error occurs