A bridge class to use
java.awt.image.BufferedImage objects (class defined
in the standard runtime library, package
java.awt.image) as
RGB24Image objects within JIU.
This class encapsulates a single
java.awt.image.BufferedImage object.
It enables reusing existing BufferedImage objects as input or
output of JIU operations,
removing the necessity for the conversion step from
java.awt.Image
to
net.sourceforge.jiu.data.PixelImage (or vice versa)
and thus reducing memory consumption.
The name of this class is a combination of BufferedImage (the class of the object
that is encapsulated) and RGB24Image (the JIU image data interface).
Internally, this class uses
java.awt.image.BufferedImage's getRGB and
setRGB methods to access image data.
This approach is slower than working directly on the BufferedImage's data
buffers.
However, using getRGB and setRGB, this class will work with all types of BufferedImage objects.
Note that while the abstract
java.awt.Image class existed from the very
beginning (version 1.0) of the Java runtime library,
java.awt.image.BufferedImage
has not been added until version 1.2.
Usage example
This code snippet demonstrates to how combine functionality from Java's runtime
library with JIU by using this class.
Requires Java 1.4 or higher.
Obviously, BufferedRGB24Image objects can only be used with operations that
work on classes implementing RGB24Image.
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import net.sourceforge.jiu.color.Invert;
import net.sourceforge.jiu.data.PixelImage;
import net.sourceforge.jiu.gui.awt.BufferedRGB24Image;
...
BufferedImage bufferedImage = ImageIO.read(new File("image.jpg"));
BufferedRGB24Image image = new BufferedRGB24Image(bufferedImage);
Invert invert = new Invert();
invert.setInputImage(image);
invert.process();
PixelImage outputImage = invert.getOutputImage();
If you can be sure that an image object can be input and output
image at the same time (as is the case with some operations), you
can even work with only one BufferedRGB24Image object.
Invert is one of these operations, so the following would work:
Invert invert = new Invert();
invert.setInputImage(image);
invert.setOutputImage(image);
invert.process();
// image now is inverted
BLUE_SHIFT
private static final int BLUE_SHIFT
GREEN_SHIFT
private static final int GREEN_SHIFT
HEIGHT
private final int HEIGHT
RED_SHIFT
private static final int RED_SHIFT
RGB_CLEAR
private static final int[] RGB_CLEAR
Masks for the three RGB channels.
RGB_CLEAR[i] is an int with all bits on, except for those occupied by the channel i.
RGB_CLEAR[i] can thus be used to bitwise AND an ARGB value so that the sample for channel i will be cleared.
RGB_SHIFT
private static final int[] RGB_SHIFT
WIDTH
private final int WIDTH
image
private final BufferedImage image
clear
public void clear(byte newValue)
Sets all the RGB samples in this image to the argument, keeping
the alpha value.
- clear in interface ByteChannelImage
newValue - all samples in the image will be set to this value
clear
public void clear(int channelIndex,
int newValue)- clear in interface IntegerImage
getByteSamples
public void getByteSamples(int x,
int y,
int w,
int h,
byte[] dest,
int destOffset)
getByteSamples
public void getByteSamples(int channelIndex,
int x,
int y,
int w,
int h,
byte[] dest,
int destOffset)- getByteSamples in interface ByteChannelImage
getSamples
public void getSamples(int channelIndex,
int x,
int y,
int w,
int h,
int[] dest,
int destOffs)- getSamples in interface IntegerImage
getSamples
public void getSamples(int x,
int y,
int w,
int h,
int[] dest,
int destOffs)
putByteSamples
public void putByteSamples(int x,
int y,
int w,
int h,
byte[] src,
int srcOffset)
putByteSamples
public void putByteSamples(int channelIndex,
int x,
int y,
int w,
int h,
byte[] src,
int srcOffset)- putByteSamples in interface ByteChannelImage
putSample
public void putSample(int channelIndex,
int x,
int y,
int newValue)- putSample in interface IntegerImage
putSamples
public void putSamples(int channelIndex,
int x,
int y,
int w,
int h,
int[] src,
int srcOffset)- putSamples in interface IntegerImage