net.sourceforge.jiu.gui.awt

Class BufferedRGB24Image

Implemented Interfaces:
ByteChannelImage, IntegerImage, PixelImage, RGB24Image, RGBImage, RGBIndex, RGBIntegerImage

public class BufferedRGB24Image
extends java.lang.Object
implements RGB24Image

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
 
Author:
Marco Schmidt
Since:
0.10.0

Field Summary

private static int
BLUE_SHIFT
private static int
GREEN_SHIFT
private int
HEIGHT
private static int
RED_SHIFT
private static int[]
RGB_CLEAR
Masks for the three RGB channels.
private static int[]
RGB_SHIFT
private int
WIDTH
private BufferedImage
image

Fields inherited from interface net.sourceforge.jiu.data.RGBIndex

INDEX_BLUE, INDEX_GREEN, INDEX_RED

Constructor Summary

BufferedRGB24Image(BufferedImage bufferedImage)
Creates a new BufferedRGB24Image object, storing the argument BufferedImage object internally.

Method Summary

void
clear(byte newValue)
Sets all the RGB samples in this image to the argument, keeping the alpha value.
void
clear(int newValue)
void
clear(int channelIndex, byte newValue)
void
clear(int channelIndex, int newValue)
PixelImage
createCompatibleImage(int width, int height)
PixelImage
createCopy()
long
getAllocatedMemory()
int
getBitsPerPixel()
byte
getByteSample(int x, int y)
byte
getByteSample(int channelIndex, int x, int y)
void
getByteSamples(int x, int y, int w, int h, byte[] dest, int destOffset)
void
getByteSamples(int channelIndex, int x, int y, int w, int h, byte[] dest, int destOffset)
int
getHeight()
Class
getImageType()
int
getMaxSample(int channel)
int
getNumChannels()
int
getSample(int x, int y)
int
getSample(int channelIndex, int x, int y)
void
getSamples(int channelIndex, int x, int y, int w, int h, int[] dest, int destOffs)
void
getSamples(int x, int y, int w, int h, int[] dest, int destOffs)
int
getWidth()
void
putByteSample(int x, int y, byte newValue)
void
putByteSample(int channelIndex, int x, int y, byte newValue)
void
putByteSamples(int x, int y, int w, int h, byte[] src, int srcOffset)
void
putByteSamples(int channelIndex, int x, int y, int w, int h, byte[] src, int srcOffset)
void
putSample(int x, int y, int newValue)
void
putSample(int channelIndex, int x, int y, int newValue)
void
putSamples(int channelIndex, int x, int y, int w, int h, int[] src, int srcOffset)

Field Details

BLUE_SHIFT

private static final int BLUE_SHIFT
Field Value:
0

GREEN_SHIFT

private static final int GREEN_SHIFT
Field Value:
8

HEIGHT

private final int HEIGHT

RED_SHIFT

private static final int RED_SHIFT
Field Value:
16

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

Constructor Details

BufferedRGB24Image

public BufferedRGB24Image(BufferedImage bufferedImage)
Creates a new BufferedRGB24Image object, storing the argument BufferedImage object internally. All image data access will be delegated to that BufferedImage object's methods.
Parameters:
bufferedImage - the underlying BufferedImage object for this BufferedRGB24Image object

Method Details

clear

public void clear(byte newValue)
Sets all the RGB samples in this image to the argument, keeping the alpha value.
Specified by:
clear in interface ByteChannelImage
Parameters:
newValue - all samples in the image will be set to this value

clear

public void clear(int newValue)
Specified by:
clear in interface IntegerImage

clear

public void clear(int channelIndex,
                  byte newValue)
Specified by:
clear in interface ByteChannelImage

clear

public void clear(int channelIndex,
                  int newValue)
Specified by:
clear in interface IntegerImage

createCompatibleImage

public PixelImage createCompatibleImage(int width,
                                        int height)
Specified by:
createCompatibleImage in interface PixelImage

createCopy

public PixelImage createCopy()
Specified by:
createCopy in interface PixelImage

getAllocatedMemory

public long getAllocatedMemory()
Specified by:
getAllocatedMemory in interface PixelImage

getBitsPerPixel

public int getBitsPerPixel()
Specified by:
getBitsPerPixel in interface PixelImage

getByteSample

public byte getByteSample(int x,
                          int y)
Specified by:
getByteSample in interface ByteChannelImage

getByteSample

public byte getByteSample(int channelIndex,
                          int x,
                          int y)
Specified by:
getByteSample in interface ByteChannelImage

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)
Specified by:
getByteSamples in interface ByteChannelImage

getHeight

public int getHeight()
Specified by:
getHeight in interface PixelImage

getImageType

public Class getImageType()
Specified by:
getImageType in interface PixelImage

getMaxSample

public int getMaxSample(int channel)
Specified by:
getMaxSample in interface IntegerImage

getNumChannels

public int getNumChannels()
Specified by:
getNumChannels in interface PixelImage

getSample

public int getSample(int x,
                     int y)
Specified by:
getSample in interface IntegerImage

getSample

public int getSample(int channelIndex,
                     int x,
                     int y)
Specified by:
getSample in interface IntegerImage

getSamples

public void getSamples(int channelIndex,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] dest,
                       int destOffs)
Specified by:
getSamples in interface IntegerImage

getSamples

public void getSamples(int x,
                       int y,
                       int w,
                       int h,
                       int[] dest,
                       int destOffs)

getWidth

public int getWidth()
Specified by:
getWidth in interface PixelImage

putByteSample

public void putByteSample(int x,
                          int y,
                          byte newValue)
Specified by:
putByteSample in interface ByteChannelImage

putByteSample

public void putByteSample(int channelIndex,
                          int x,
                          int y,
                          byte newValue)
Specified by:
putByteSample in interface ByteChannelImage

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)
Specified by:
putByteSamples in interface ByteChannelImage

putSample

public void putSample(int x,
                      int y,
                      int newValue)
Specified by:
putSample in interface IntegerImage

putSample

public void putSample(int channelIndex,
                      int x,
                      int y,
                      int newValue)
Specified by:
putSample in interface IntegerImage

putSamples

public void putSamples(int channelIndex,
                       int x,
                       int y,
                       int w,
                       int h,
                       int[] src,
                       int srcOffset)
Specified by:
putSamples in interface IntegerImage