Package com.twelvemonkeys.image
Class BufferedImageFactory
- java.lang.Object
-
- com.twelvemonkeys.image.BufferedImageFactory
-
public final class BufferedImageFactory extends java.lang.ObjectA faster, lighter and easier way to convert anImageto aBufferedImagethan using aPixelGrabber. Clients may provide progress listeners to monitor conversion progress.Supports source image subsampling and source region extraction. Supports source images with 16 bit
ColorModelandDataBuffer.TYPE_USHORTtransfer type, without converting to 32 bit/TYPE_INT.NOTE: Does not support images with more than one
ColorModelor different types of pixel data. This is not very common.- Version:
- $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/image/BufferedImageFactory.java#1 $
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classBufferedImageFactory.Consumerstatic interfaceBufferedImageFactory.ProgressListenerThis interface allows clients of aBufferedImageFactoryto receive notifications of decoding progress.
-
Field Summary
Fields Modifier and Type Field Description private java.awt.image.BufferedImagebufferedprivate java.awt.image.ColorModelcolorModelprivate BufferedImageFactory.Consumerconsumerprivate ImageConversionExceptionconsumerExceptionprivate booleanfetchingprivate intheightprivate java.util.List<BufferedImageFactory.ProgressListener>listenersprivate intoffsetprivate intpercentageDoneprivate java.awt.image.ImageProducerproducerprivate booleanreadColorModelOnlyprivate intscanSizeprivate java.awt.image.ColorModelsourceColorModelprivate java.lang.ObjectsourcePixelsprivate java.util.Hashtable<?,?>sourcePropertiesprivate intwidthprivate intxprivate intxSubprivate intyprivate intySub
-
Constructor Summary
Constructors Constructor Description BufferedImageFactory(java.awt.Image source)Creates aBufferedImageFactory.BufferedImageFactory(java.awt.image.ImageProducer source)Creates aBufferedImageFactory.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabort()Aborts the image production.voidaddProgressListener(BufferedImageFactory.ProgressListener listener)Adds a progress listener to this factory.private voidcreateBuffered()private voidcreateColorModel()voiddispose()Frees resources used by thisBufferedImageFactory.private voiddoFetch(boolean colorModelOnly)private voidfreeResources()java.awt.image.BufferedImagegetBufferedImage()Returns theBufferedImageextracted from the givenImageSource.java.awt.image.ColorModelgetColorModel()Returns theColorModelextracted from the givenImageSource.private voidprocessProgress(int scanline)voidremoveAllProgressListeners()Removes all progress listeners from this factory.voidremoveProgressListener(BufferedImageFactory.ProgressListener listener)Removes a progress listener from this factory.voidsetSourceRegion(java.awt.Rectangle region)Sets the source region (AOI) for the new image.voidsetSourceSubsampling(int xSubsampling, int ySubsampling)Sets the source subsampling for the new image.private static short[]toShortPixels(int[] inputPixels)Converts an array ofintpixels to an array ofshortpixels.
-
-
-
Field Detail
-
listeners
private java.util.List<BufferedImageFactory.ProgressListener> listeners
-
percentageDone
private int percentageDone
-
producer
private java.awt.image.ImageProducer producer
-
consumerException
private ImageConversionException consumerException
-
fetching
private volatile boolean fetching
-
readColorModelOnly
private boolean readColorModelOnly
-
x
private int x
-
y
private int y
-
width
private int width
-
height
private int height
-
xSub
private int xSub
-
ySub
private int ySub
-
offset
private int offset
-
scanSize
private int scanSize
-
sourceColorModel
private java.awt.image.ColorModel sourceColorModel
-
sourceProperties
private java.util.Hashtable<?,?> sourceProperties
-
sourcePixels
private java.lang.Object sourcePixels
-
buffered
private java.awt.image.BufferedImage buffered
-
colorModel
private java.awt.image.ColorModel colorModel
-
consumer
private final BufferedImageFactory.Consumer consumer
-
-
Constructor Detail
-
BufferedImageFactory
public BufferedImageFactory(java.awt.Image source)
Creates aBufferedImageFactory.- Parameters:
source- the source image- Throws:
java.lang.IllegalArgumentException- ifsource == null
-
BufferedImageFactory
public BufferedImageFactory(java.awt.image.ImageProducer source)
Creates aBufferedImageFactory.- Parameters:
source- the source image producer- Throws:
java.lang.IllegalArgumentException- ifsource == null
-
-
Method Detail
-
getBufferedImage
public java.awt.image.BufferedImage getBufferedImage() throws ImageConversionExceptionReturns theBufferedImageextracted from the givenImageSource. Multiple requests will return the same image.- Returns:
- the
BufferedImage - Throws:
ImageConversionException- if the givenImageSourcecannot be converted for some reason.
-
getColorModel
public java.awt.image.ColorModel getColorModel() throws ImageConversionExceptionReturns theColorModelextracted from the givenImageSource. Multiple requests will return the same model.- Returns:
- the
ColorModel - Throws:
ImageConversionException- if the givenImageSourcecannot be converted for some reason.
-
dispose
public void dispose()
Frees resources used by thisBufferedImageFactory.
-
abort
public void abort()
Aborts the image production.
-
setSourceRegion
public void setSourceRegion(java.awt.Rectangle region)
Sets the source region (AOI) for the new image.- Parameters:
region- the source region
-
setSourceSubsampling
public void setSourceSubsampling(int xSubsampling, int ySubsampling)Sets the source subsampling for the new image.- Parameters:
xSubsampling- horizontal subsampling factorySubsampling- vertical subsampling factor
-
doFetch
private void doFetch(boolean colorModelOnly) throws ImageConversionException- Throws:
ImageConversionException
-
createColorModel
private void createColorModel()
-
createBuffered
private void createBuffered()
-
freeResources
private void freeResources()
-
processProgress
private void processProgress(int scanline)
-
addProgressListener
public void addProgressListener(BufferedImageFactory.ProgressListener listener)
Adds a progress listener to this factory.- Parameters:
listener- the progress listener
-
removeProgressListener
public void removeProgressListener(BufferedImageFactory.ProgressListener listener)
Removes a progress listener from this factory.- Parameters:
listener- the progress listener
-
removeAllProgressListeners
public void removeAllProgressListeners()
Removes all progress listeners from this factory.
-
toShortPixels
private static short[] toShortPixels(int[] inputPixels)
Converts an array ofintpixels to an array ofshortpixels. The conversion is done, by masking out the higher 16 bits of theint.For any given
int, theshortvalue is computed as follows:short value = (short) (intValue & 0x0000ffff);- Parameters:
inputPixels- the pixel data to convert- Returns:
- an array of
shorts, same length asinputPixels
-
-