Package com.twelvemonkeys.image
Class BufferedImageFactory
java.lang.Object
com.twelvemonkeys.image.BufferedImageFactory
A faster, lighter and easier way to convert an
Image
to a
BufferedImage
than using a PixelGrabber
.
Clients may provide progress listeners to monitor conversion progress.
Supports source image subsampling and source region extraction.
Supports source images with 16 bit ColorModel
and
DataBuffer.TYPE_USHORT
transfer type, without converting to
32 bit/TYPE_INT.
NOTE: Does not support images with more than one ColorModel
or
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 ClassesModifier and TypeClassDescriptionprivate class
static interface
This interface allows clients of aBufferedImageFactory
to receive notifications of decoding progress. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BufferedImage
private ColorModel
private final BufferedImageFactory.Consumer
private ImageConversionException
private boolean
private int
private int
private int
private ImageProducer
private boolean
private int
private ColorModel
private Object
private Hashtable
<?, ?> private int
private int
private int
private int
private int
-
Constructor Summary
ConstructorsConstructorDescriptionBufferedImageFactory
(Image source) Creates aBufferedImageFactory
.BufferedImageFactory
(ImageProducer source) Creates aBufferedImageFactory
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
abort()
Aborts the image production.void
Adds a progress listener to this factory.private void
private void
void
dispose()
Frees resources used by thisBufferedImageFactory
.private void
doFetch
(boolean colorModelOnly) private void
Returns theBufferedImage
extracted from the givenImageSource
.Returns theColorModel
extracted from the givenImageSource
.private void
processProgress
(int scanline) void
Removes all progress listeners from this factory.void
Removes a progress listener from this factory.void
setSourceRegion
(Rectangle region) Sets the source region (AOI) for the new image.void
setSourceSubsampling
(int xSubsampling, int ySubsampling) Sets the source subsampling for the new image.private static short[]
toShortPixels
(int[] inputPixels) Converts an array ofint
pixels to an array ofshort
pixels.
-
Field Details
-
listeners
-
percentageDone
private int percentageDone -
producer
-
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
-
sourceProperties
-
sourcePixels
-
buffered
-
colorModel
-
consumer
-
-
Constructor Details
-
BufferedImageFactory
Creates aBufferedImageFactory
.- Parameters:
source
- the source image- Throws:
IllegalArgumentException
- ifsource == null
-
BufferedImageFactory
Creates aBufferedImageFactory
.- Parameters:
source
- the source image producer- Throws:
IllegalArgumentException
- ifsource == null
-
-
Method Details
-
getBufferedImage
Returns theBufferedImage
extracted from the givenImageSource
. Multiple requests will return the same image.- Returns:
- the
BufferedImage
- Throws:
ImageConversionException
- if the givenImageSource
cannot be converted for some reason.
-
getColorModel
Returns theColorModel
extracted from the givenImageSource
. Multiple requests will return the same model.- Returns:
- the
ColorModel
- Throws:
ImageConversionException
- if the givenImageSource
cannot be converted for some reason.
-
dispose
public void dispose()Frees resources used by thisBufferedImageFactory
. -
abort
public void abort()Aborts the image production. -
setSourceRegion
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
- Throws:
ImageConversionException
-
createColorModel
private void createColorModel() -
createBuffered
private void createBuffered() -
freeResources
private void freeResources() -
processProgress
private void processProgress(int scanline) -
addProgressListener
Adds a progress listener to this factory.- Parameters:
listener
- the progress listener
-
removeProgressListener
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 ofint
pixels to an array ofshort
pixels. The conversion is done, by masking out the higher 16 bits of theint
.For any given
int
, theshort
value is computed as follows:short value = (short) (intValue & 0x0000ffff);
- Parameters:
inputPixels
- the pixel data to convert- Returns:
- an array of
short
s, same length asinputPixels
-