eap.fits
Class ImageDigitizer

java.lang.Object
  extended byeap.fits.ImageDigitizer
All Implemented Interfaces:
ImageProducer, RealImageConsumer

public class ImageDigitizer
extends Object
implements RealImageConsumer, ImageProducer

This class converts a stream of double-valued pixels from a RealImageProducer into a stream of integer pixels. This class implements the Java ImageProducer interface, so it can be used to create a Java Image.

The output image will first be gamma corrected, meaning the pixel values are raised to the power of 1/γ, where γ is set by setGamma(double). Then it is scaled so that the smallest real pixel value corresponds to the smallest ingeger or byte value and the largest real value corresponds to the largest ingeter or byte value.

Since digitization can take time, you can register ChangeListeners to monitor the progress of the digitization.


Constructor Summary
ImageDigitizer(RealImageProducer source, ColorModel color)
          Create an ImageDigitizer using a given color model and which will digitize the data from a given source.
 
Method Summary
 void abortSend()
          abort the image we are sending if we are actually sending an image
 void addChangeListener(ChangeListener l)
          add a change listener to receive change events when significant progress has been made digitizing the image
 void addConsumer(ImageConsumer ic)
          register an integer image consumer.
 byte digitizeToByte(double pixel)
          this is where the actual digitization happens for byte color models
 int digitizeToInt(double pixel)
          this is where the actual digitization happens for int color models
 ColorModel getColorModel()
          get the color model for the digitized pixels
 double getProgress()
          returns the fraction of pixels which have been processed
 void imageComplete(int status)
          pass along the image complete message to the integer image.
 boolean isConsumer(ImageConsumer ic)
          returns true if the given integer consumer is registered.
 void removeChangeListener(ChangeListener l)
          remove a change listener
 void removeConsumer(ImageConsumer ic)
          unregister the given integer consumer.
 void requestTopDownLeftRightResend(ImageConsumer ic)
          passes the request up to the RealImageProducer
 double scalePixel(double pixel)
          return a pixel value scaled so that min -> 0 and max -> 1 and with gamma correction applied.
 void setChangeIncrement(double increment)
          set the interval at which change events are fired in terms of fraction of completion
 void setColorModel(ColorModel color)
          set the color model for the digitized pixels.
 void setDimensions(int width, int height)
          pass this information along to the integer image stream.
 void setGamma(double gamma)
          set the gamma correction factor to used in the digitization.
 void setHints(int hintflags)
          pass this information along to the integer image stream.
 void setImageSource(RealImageProducer source)
          set the RealImageProducer source for the digitizer.
 void setMinMax(double min, double max)
          The RealImageProducer calls this method to indicate the pixel limits.
 void setNaNvalue(byte value)
          set the digitized byte pixel value to use for NaN pixels
 void setNaNvalue(int value)
          set the digitized int pixel value to use for NaN pixels
 void setPixels(int x, int y, int w, int h, double[] pixels, int offset, int scansize)
          the RealImageProducer calls this method to deliver a set of pixels.
 void startProduction(ImageConsumer ic)
          Begin producing pixels for the integer consumers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageDigitizer

public ImageDigitizer(RealImageProducer source,
                      ColorModel color)
Create an ImageDigitizer using a given color model and which will digitize the data from a given source.

Parameters:
source - the source of double valued pixel data.
color - The color model to use in the digitized image.
Method Detail

setImageSource

public void setImageSource(RealImageProducer source)
set the RealImageProducer source for the digitizer. This can be used to change the source after the digitizer has been created.


setNaNvalue

public void setNaNvalue(int value)
set the digitized int pixel value to use for NaN pixels


setNaNvalue

public void setNaNvalue(byte value)
set the digitized byte pixel value to use for NaN pixels


setColorModel

public void setColorModel(ColorModel color)
set the color model for the digitized pixels. This can be used to change the color model after creating the digitizer.


getColorModel

public ColorModel getColorModel()
get the color model for the digitized pixels


setGamma

public void setGamma(double gamma)
set the gamma correction factor to used in the digitization. where digitized is proportional to real^1./gamma


addChangeListener

public void addChangeListener(ChangeListener l)
add a change listener to receive change events when significant progress has been made digitizing the image


removeChangeListener

public void removeChangeListener(ChangeListener l)
remove a change listener


setChangeIncrement

public void setChangeIncrement(double increment)
set the interval at which change events are fired in terms of fraction of completion


getProgress

public double getProgress()
returns the fraction of pixels which have been processed


abortSend

public void abortSend()
abort the image we are sending if we are actually sending an image


imageComplete

public void imageComplete(int status)
pass along the image complete message to the integer image.

Specified by:
imageComplete in interface RealImageConsumer

setDimensions

public void setDimensions(int width,
                          int height)
pass this information along to the integer image stream.

Specified by:
setDimensions in interface RealImageConsumer

setMinMax

public void setMinMax(double min,
                      double max)
The RealImageProducer calls this method to indicate the pixel limits.

Specified by:
setMinMax in interface RealImageConsumer

setHints

public void setHints(int hintflags)
pass this information along to the integer image stream.

Specified by:
setHints in interface RealImageConsumer

setPixels

public void setPixels(int x,
                      int y,
                      int w,
                      int h,
                      double[] pixels,
                      int offset,
                      int scansize)
the RealImageProducer calls this method to deliver a set of pixels. This method scales the pixels and converts them to integers or bytes as appropriate for the color model.

Specified by:
setPixels in interface RealImageConsumer

scalePixel

public double scalePixel(double pixel)
return a pixel value scaled so that min -> 0 and max -> 1 and with gamma correction applied.


digitizeToByte

public byte digitizeToByte(double pixel)
this is where the actual digitization happens for byte color models


digitizeToInt

public int digitizeToInt(double pixel)
this is where the actual digitization happens for int color models


addConsumer

public void addConsumer(ImageConsumer ic)
register an integer image consumer.

Specified by:
addConsumer in interface ImageProducer

isConsumer

public boolean isConsumer(ImageConsumer ic)
returns true if the given integer consumer is registered.

Specified by:
isConsumer in interface ImageProducer

removeConsumer

public void removeConsumer(ImageConsumer ic)
unregister the given integer consumer.

Specified by:
removeConsumer in interface ImageProducer

startProduction

public void startProduction(ImageConsumer ic)
Begin producing pixels for the integer consumers. This just calls RealImageProducer.startProduction(RealImageConsumer).

Specified by:
startProduction in interface ImageProducer

requestTopDownLeftRightResend

public void requestTopDownLeftRightResend(ImageConsumer ic)
passes the request up to the RealImageProducer

Specified by:
requestTopDownLeftRightResend in interface ImageProducer