com.lizardtech.djvubean
Class DjVuFilter

java.lang.Object
  extended by java.awt.image.ImageFilter
      extended by com.lizardtech.djvubean.DjVuFilter
All Implemented Interfaces:
java.awt.image.ImageConsumer, java.lang.Cloneable, java.lang.Runnable

public final class DjVuFilter
extends java.awt.image.ImageFilter
implements java.lang.Runnable

DjVuFilter objects are used to present a segment of a DjVu image at an arbitrary resolution. In order to keep the code simple, this filter is used on a 1 pixel memory source to wrap into an ImageProducer. This avoids the need to implement low level methods to deal directly with ImageConsumer objects. The animated flag may be used for progressive rendering and scrolling. When animated, up to two additional threads may be used to offload work. The first thread updates the buffered pixels after each progressive update and after move() method calls. The second thread passes the pixels to the ImageConsumer.

Author:
Bill C. Riemers, Foxtrot Technologies Inc.

Field Summary
 boolean animated
          True if separate threads may be used.
protected  int fullHeight
          The full height of the subsampled segment.
protected  int fullWidth
          The full width of the subsampled segment.
static java.awt.image.ColorModel GRAY_MODEL
          Gray Color model.
 DjVuInfo info
          The DjVuInfo Codec
 DjVuPage page
          The DjVuPage being displayed.
protected  java.awt.Point position
          The new position of the upper left corner.
static java.awt.image.ColorModel RGB_MODEL
          RGB Color model.
protected  int subsample
          The current subsample rate.
protected  double sx
          Horizontal scale factor.
protected  double sy
          Vertical scale factor.
 
Fields inherited from class java.awt.image.ImageFilter
consumer
 
Fields inherited from interface java.awt.image.ImageConsumer
COMPLETESCANLINES, IMAGEABORTED, IMAGEERROR, RANDOMPIXELORDER, SINGLEFRAME, SINGLEFRAMEDONE, SINGLEPASS, STATICIMAGEDONE, TOPDOWNLEFTRIGHT
 
Constructor Summary
DjVuFilter(java.awt.Rectangle bounds, java.awt.Dimension pageSize, DjVuPage page, boolean animated)
          Creates a new instance of DjVuFilter
 
Method Summary
 java.awt.Rectangle getBounds()
          Return the bounding rectangle of the segment.
 java.awt.Image getImage(java.awt.Component parent)
          Call to lookup, or create an image with the specified parent.
 java.awt.image.ImageProducer getImageProducer()
          Called to create an ImageProducer which uses this filter.
 java.awt.Dimension getSize()
          Return the scaled page size.
 void move(int x, int y)
          Called to move the upper left hand corner of the image segment.
protected  void newPixels()
          Called to indicate newPixels are available.
 void run()
          This is the run method used for all threads.
 void setDimensions(int w, int h)
          Called by the image producer to set the image size.
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, byte[] pixels, int off, int scansize)
          Sets the array of pixels from the available GPixmap and fillColor for borders.
 void setPixels(int x, int y, int w, int h, java.awt.image.ColorModel model, int[] pixels, int off, int scansize)
          Sets the array of pixels from the available GPixmap and fillColor for borders.
 
Methods inherited from class java.awt.image.ImageFilter
clone, getFilterInstance, imageComplete, resendTopDownLeftRight, setColorModel, setHints, setProperties
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RGB_MODEL

public static final java.awt.image.ColorModel RGB_MODEL
RGB Color model.


GRAY_MODEL

public static final java.awt.image.ColorModel GRAY_MODEL
Gray Color model.


info

public final DjVuInfo info
The DjVuInfo Codec


page

public final DjVuPage page
The DjVuPage being displayed.


animated

public final boolean animated
True if separate threads may be used.


position

protected final java.awt.Point position
The new position of the upper left corner.


fullHeight

protected final int fullHeight
The full height of the subsampled segment.


fullWidth

protected final int fullWidth
The full width of the subsampled segment.


subsample

protected final int subsample
The current subsample rate.


sx

protected final double sx
Horizontal scale factor.


sy

protected final double sy
Vertical scale factor.

Constructor Detail

DjVuFilter

public DjVuFilter(java.awt.Rectangle bounds,
                  java.awt.Dimension pageSize,
                  DjVuPage page,
                  boolean animated)
Creates a new instance of DjVuFilter

Parameters:
bounds - The bounding rectangle of the desired segment.
pageSize - The stretched page size.
page - The DjVuPage to render.
animated - True if multiple threads should be used to allow progressive rendering and move method calls.
Method Detail

getBounds

public java.awt.Rectangle getBounds()
Return the bounding rectangle of the segment.

Returns:
The rectangle bounding the segment.

setDimensions

public void setDimensions(int w,
                          int h)
Called by the image producer to set the image size. The actual values are ignored, since the producer is always a 1 pixel source.

Specified by:
setDimensions in interface java.awt.image.ImageConsumer
Overrides:
setDimensions in class java.awt.image.ImageFilter
Parameters:
w - ignored
h - ignored

getImage

public java.awt.Image getImage(java.awt.Component parent)
Call to lookup, or create an image with the specified parent.

Parameters:
parent - The component to call createImage on.
Returns:
An Image representation of this object.

getImageProducer

public java.awt.image.ImageProducer getImageProducer()
Called to create an ImageProducer which uses this filter.

Returns:
The ImageProducer for this filter.

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      byte[] pixels,
                      int off,
                      int scansize)
Sets the array of pixels from the available GPixmap and fillColor for borders.

Specified by:
setPixels in interface java.awt.image.ImageConsumer
Overrides:
setPixels in class java.awt.image.ImageFilter
Parameters:
x - (ignored)
y - (ignored)
w - (ignored)
h - (ignored)
model - (ignored)
pixels - (ignored)
off - (ignored)
scansize - (ignored)

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      java.awt.image.ColorModel model,
                      int[] pixels,
                      int off,
                      int scansize)
Sets the array of pixels from the available GPixmap and fillColor for borders.

Specified by:
setPixels in interface java.awt.image.ImageConsumer
Overrides:
setPixels in class java.awt.image.ImageFilter
Parameters:
x - the x-coordinate of the upper-left corner of the region of pixels (ignored)
y - the y-coordinate of the upper-left corner of the region of pixels (ignored)
w - the width of the region of pixels (ignored)
h - the height of the region of pixels (ignored)
model - the color model of the input data (ignored)
pixels - the array of pixels (ignored)
off - the offset into the pixel array (ignored)
scansize - the distance from one row of pixels to the next in the array (ignored)

getSize

public java.awt.Dimension getSize()
Return the scaled page size.

Returns:
The scaled page size.

move

public void move(int x,
                 int y)
Called to move the upper left hand corner of the image segment. If the useThread option is set, this method will return right away, otherwise the method waits until a new pixels are sent to the ImageConsumer.

Parameters:
x - Left to right x coordinate.
y - Top down y coordinate.
Throws:
java.lang.IllegalStateException - if not animated.

run

public void run()
This is the run method used for all threads.

Specified by:
run in interface java.lang.Runnable

newPixels

protected void newPixels()
Called to indicate newPixels are available. If multiple threads are used, the NEWPIXELS_FLAG is set and then this method returns. Otherwise, this method will not return until the pixels are sent to the ImageConsumer.