org.instantreality.InstantIO
Class Image

java.lang.Object
  extended by org.instantreality.InstantIO.Image

public class Image
extends java.lang.Object

Helper class for exchanging images.

Image is a basic helper class for exchanging image data between different software components. It does not contain any means for working with images, only methods for setting and getting the raw data values. It is not meant to be used directly by software components for image representation. Instead, software components should use their own, appropriate classes for handling images. Only when sending images to an OutSlot, or when receiving images from an InSlot, the internal representation of images should be converted to Image's. This ensures the interoperability between different software components that use different internal representations for images.

The following example demonstrates how to create an RGB Image of 4x3 pixels and send it to an OutSlot:

 OutSlot outSlot = ...;
 Image image = new Image();
 image.setParameters(4, 3, Image.FMT_RGB24);
 byte[] buffer = image.getBuffer();
 buffer[0] = ...; // Red color component of upper left pixel
 buffer[1] = ...; // Green color component of upper left pixel
 buffer[2] = ...; // Blue color component of upper left pixel
 ...
 buffer[33] = ...; // Red color component of lower right pixel
 buffer[34] = ...; // Green color component of lower right pixel
 buffer[35] = ...; // Blue color component of lower right pixel
 outslot.push(image);
 

Receiving images from an InSlot works like this:

 InSlot inSlot = ...;
 Image image = (Image) inSlot.pop();
 int width = image.getWidth();
 int height = image.getHeight();
 int format = image.getFormat();
 System.out.println("Image parameters: " + width + "x" + height + " " + Image.format2string(format));
 byte[] buffer = image.getBuffer();
 if (format == Image.FMT_RGB24)
 {
   int i = 0;
   for (int x = 0; x < width; ++x)
     for (int y = 0; y < height; ++y)
     {
       byte r = buffer[i++];
       byte g = buffer[i++];
       byte b = buffer[i++];
       ...
     }
 }
 else
 {
   ...
 }
 

Author:
Patrick Dähne

Field Summary
static int FMT_BGR232
           
static int FMT_BGR24
           
static int FMT_BGR32
           
static int FMT_BGR555
           
static int FMT_BGR565
           
static int FMT_I420
           
static int FMT_IYU2
           
static int FMT_NONE
          Invalid/unspecified image format.
static int FMT_RGB24
           
static int FMT_RGB32
           
static int FMT_Y1600
           
static int FMT_Y411
           
static int FMT_Y41P
           
static int FMT_Y422
           
static int FMT_Y444
           
static int FMT_Y800
           
static int FMT_YUV411P
           
static int FMT_YUV422P
           
static int FMT_YUV9
           
static int FMT_YUY2
           
static int FMT_YV12
           
static int FMT_YVU9
           
 
Constructor Summary
Image()
          Creates a new Image object.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares the image to another object.
static java.lang.String format2String(int format)
          Converts a Format enumeration value to a human-readable string.
 byte[] getBuffer()
          Returns a pointer to the buffer that holds the image data.
 int getFormat()
          Returns the format of the image data.
 int getHeight()
          Returns the height of the image data in pixels.
 int getSize()
          Returns the size of the data in the buffer in bytes.
 int getWidth()
          Returns the width of the image data in pixels.
 void setParameters(int width, int height, int format)
          This method sets the parameters of the image.
static int string2Format(java.lang.String str)
          Converts a human-readable string to a Format enumeration value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FMT_NONE

public static final int FMT_NONE
Invalid/unspecified image format.

See Also:
Constant Field Values

FMT_BGR232

public static final int FMT_BGR232
See Also:
Constant Field Values

FMT_BGR555

public static final int FMT_BGR555
See Also:
Constant Field Values

FMT_BGR565

public static final int FMT_BGR565
See Also:
Constant Field Values

FMT_BGR24

public static final int FMT_BGR24
See Also:
Constant Field Values

FMT_RGB24

public static final int FMT_RGB24
See Also:
Constant Field Values

FMT_BGR32

public static final int FMT_BGR32
See Also:
Constant Field Values

FMT_RGB32

public static final int FMT_RGB32
See Also:
Constant Field Values

FMT_Y444

public static final int FMT_Y444
See Also:
Constant Field Values

FMT_IYU2

public static final int FMT_IYU2
See Also:
Constant Field Values

FMT_I420

public static final int FMT_I420
See Also:
Constant Field Values

FMT_YVU9

public static final int FMT_YVU9
See Also:
Constant Field Values

FMT_YUV9

public static final int FMT_YUV9
See Also:
Constant Field Values

FMT_Y800

public static final int FMT_Y800
See Also:
Constant Field Values

FMT_Y1600

public static final int FMT_Y1600
See Also:
Constant Field Values

FMT_Y422

public static final int FMT_Y422
See Also:
Constant Field Values

FMT_Y411

public static final int FMT_Y411
See Also:
Constant Field Values

FMT_Y41P

public static final int FMT_Y41P
See Also:
Constant Field Values

FMT_YV12

public static final int FMT_YV12
See Also:
Constant Field Values

FMT_YUY2

public static final int FMT_YUY2
See Also:
Constant Field Values

FMT_YUV422P

public static final int FMT_YUV422P
See Also:
Constant Field Values

FMT_YUV411P

public static final int FMT_YUV411P
See Also:
Constant Field Values
Constructor Detail

Image

public Image()
Creates a new Image object. The image object created by this constructor has a size of 0x0 and an unspecified format.

The following example demonstrates how to create an RGB Image of 4x3 pixels:

 Image image = new Image();
 image.setParameters(4, 3, Image.string2Fromat("RGB24"));
 

Method Detail

setParameters

public final void setParameters(int width,
                                int height,
                                int format)
This method sets the parameters of the image.

The following example demonstrates how to create an RGB Image of 4x3 pixels:

 Image image = new Image();
 image.setParameters(4, 3, Image.string2Fromat("RGB24"));
 

Parameters:
width - The width of the image in pixels
height - The height of the image in pixels
format - The format of the image data

getWidth

public final int getWidth()
Returns the width of the image data in pixels.

The following example prints the width of an Image to the console:

 Image image = ...;
 System.out.println("width = " + image.getWidth());
 

Returns:
The width

getHeight

public final int getHeight()
Returns the height of the image data in pixels.

The following example prints the height of an Image to the console:

 Image image = ...;
 System.out.println("height = " + image.getHeight());
 

Returns:
The height

getFormat

public final int getFormat()
Returns the format of the image data.

The following example prints the format of an Image to the console:

 Image image = ...;
 System.out.println("format = " + Image.format2string(image.getFormat()));
 

Returns:
The format

getBuffer

public final byte[] getBuffer()
Returns a pointer to the buffer that holds the image data. The size of this buffer and its contents depend on the size of the image and its format. You have to call the setParameters method before calling this method.

Returns:
The buffer
See Also:
setParameters(int, int, int)

getSize

public final int getSize()
Returns the size of the data in the buffer in bytes. The size depends on the size of the image as well as its format. You have to call the setParameters method before calling this method. Keep in mind that the size returned by this method may differ from the size of the buffer - the buffer can be larger than the actual image data.

Returns:
The size
See Also:
setParameters(int, int, int)

equals

public final boolean equals(java.lang.Object obj)
Compares the image to another object. The result is true if the object is not null and is an Image object and the pixels of the other Image object are the same as the pixels of this image.

The following example compares two images and prints the result to the console:

 Image image1 = ...;
 Image image2 = ...;
 System.out.println("Images are the same: " + image1.equals(image2));
 

Overrides:
equals in class java.lang.Object
Parameters:
obj - the object to compare the image to
Returns:
true when the images are equal, false otherwise

format2String

public static final java.lang.String format2String(int format)
Converts a Format enumeration value to a human-readable string.

The following example prints the format of an Image to the console:

 Image image = ...;
 System.out.println("format = " + Image.format2string(image.getFormat()));
 

Parameters:
format - The Format enumeration value
Returns:
The human-readable string

string2Format

public static final int string2Format(java.lang.String str)
Converts a human-readable string to a Format enumeration value.

The following example demonstrates how to create an RGB Image of 4x3 pixels:

 Image image = new Image();
 image.setParameters(4, 3, Image.string2Fromat("RGB24"));
 

Parameters:
str - The human-readable string
Returns:
The Format enumeration value