com.ngs.image.source
Class JAIImageSource

java.lang.Object
  extended by com.ngs.image.ImageSource
      extended by com.ngs.image.source.DefaultThumbnailSource
          extended by com.ngs.image.source.JAIImageSource
Direct Known Subclasses:
JAITiffImageSource

public abstract class JAIImageSource
extends DefaultThumbnailSource

An ImageSource that reads images using the JAI libraries from SeekableStream objects.

This class provides default implementations of page caching, pre-scaling of images, and converting JAI PlanarImages to BufferedImages. Classes that wish to make use of some or all of these features should extend this class, and implement the (using JAI) readStream(SeekableStream) method. In this method, RenderedOp objects should be packaged with the page number (ImageSource index) into ImagePage objects, and cached. JAI will lazily render (and cache) the Image to a BufferedImage. This class respects that.

Author:
Bryan Varner

Nested Class Summary
protected static class JAIImageSource.ImagePage
          Internal class that represents a single images in a multi-image document.
 
Constructor Summary
protected JAIImageSource()
          Creates a new JAIImageSOurce
 
Method Summary
protected  void cachePage(JAIImageSource.ImagePage ip)
          Caches the given ImagePage.
 void close()
          Clears the fileName (if one is set), and disposes and flushes any cached, rendered objects.
 void dispose()
          Implements ImageSource.
 BufferedImage getImage(int index)
          Implements ImageSource.
 int getImageCount()
          Implements ImageSource.
 String getImageName()
          Implements ImageSource.
protected  void open(com.sun.media.jai.codec.SeekableStream stream, String name)
          Opens the given Stream as the given name.
protected abstract  void readStream(com.sun.media.jai.codec.SeekableStream stream)
          This readStream should parse the current stream and populate the imageCache with new ImagePage objects..
 void setPreScale(float preScale)
          If pre-scaling (using JAI) is desired, set the preScale (both x and y axis) here.
 
Methods inherited from class com.ngs.image.source.DefaultThumbnailSource
getThumbnail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JAIImageSource

protected JAIImageSource()
Creates a new JAIImageSOurce

Method Detail

dispose

public void dispose()
Implements ImageSource. Closes the JAIImageSource.

Specified by:
dispose in class DefaultThumbnailSource

close

public void close()
Clears the fileName (if one is set), and disposes and flushes any cached, rendered objects.


setPreScale

public void setPreScale(float preScale)
If pre-scaling (using JAI) is desired, set the preScale (both x and y axis) here.

Parameters:
preScale - The multiplier to use when scaling x and y axis.

open

protected void open(com.sun.media.jai.codec.SeekableStream stream,
                    String name)
Opens the given Stream as the given name.

Parameters:
stream - The stream to open.
name - The name of the stream

readStream

protected abstract void readStream(com.sun.media.jai.codec.SeekableStream stream)
                            throws IOException
This readStream should parse the current stream and populate the imageCache with new ImagePage objects..

Throws:
IOException

cachePage

protected void cachePage(JAIImageSource.ImagePage ip)
Caches the given ImagePage.


getImage

public BufferedImage getImage(int index)
Implements ImageSource.

Specified by:
getImage in class DefaultThumbnailSource
Parameters:
index - The image to obtain from this ImageSource.
Returns:
a BufferedImage.

getImageCount

public int getImageCount()
Implements ImageSource. Gets the number of cached Images.

Specified by:
getImageCount in class DefaultThumbnailSource
Returns:
THe number of images in this ImageSource. Normally this will be 1.

getImageName

public String getImageName()
Implements ImageSource.

Specified by:
getImageName in class DefaultThumbnailSource