Class EventOutSFImage
- Direct Known Subclasses:
EventOutSFImageWrapper
Images are represented as arrays of integers as per the VRML IS specification Section 5.5 SFImage. Pixel values are between 0 and 256 and represented as integers to maintain consistency with java's ImageConsumer interface and PixelGrabber class.
- Version:
- 1.0 30 April 1998
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract int
Get the number of colour components in the image.abstract int
Get the height of the image.abstract int[]
Get the image pixel value in the given eventOut.abstract void
getPixels
(int[] pixels) Write the pixel values to the given array.abstract int
getWidth()
Get the width of the image.Methods inherited from class vrml.eai.field.EventOut
addVrmlEventListener, getUserData, removeVrmlEventListener, setUserData
-
Constructor Details
-
EventOutSFImage
protected EventOutSFImage()Construct an instance of this class. Calls the superclass constructor with the field type set to SFImage.
-
-
Method Details
-
getWidth
public abstract int getWidth()Get the width of the image.- Returns:
- The width of the image in pixels
-
getHeight
public abstract int getHeight()Get the height of the image.- Returns:
- The height of the image in pixels
-
getComponents
public abstract int getComponents()Get the number of colour components in the image. The value will always be between 1 and 4 indicating the number of components of the colour specification to be read from the image pixel data.- Returns:
- The number of components
-
getPixels
public abstract int[] getPixels()Get the image pixel value in the given eventOut.The number of items in the pixels array will be
width * height
. If there are less items than this an ArrayIndexOutOfBoundsException will be generated. The integer values are represented according to the number of components.1 Component Images
The integer has the intensity value stored in the lowest byte and can be obtained:intensity = pixel[i] &0xFF;
2 Component Images
The integer has the intensity value stored in the lowest byte and the transparency in the top byte:intensity = pixel[i] &0xFF; alpha = (pixel[i] >> 24) &0xFF00;
Note that this is different to the VRML representation of the image which would store the values in the text file asalpha = pixel[i] >> 8) &0xFF
. The reason for the difference is to maintain as much compatibility with the java image model as possible. Java does not contain a separate intensity only image model, instead it sets all three colour components to the same value. This way, the user of SFImages can take a full colour image and turn it to black + white by just setting each of the bytes to the same value as the lowest byte.3 Component Images
The three colour components are stored in the integer array as follows:red = (pixel[i] >> 16) &0xFF; green = (pixel[i] >> 8) &0xFF; blue = (pixel[i] ) &0xFF;
4 Component Images
The integer has the value stored in the array as follows:alpha = (pixel >> 24) &0xff; red = (pixel >> 16) &0xff; green = (pixel >> 8) &0xff; blue = (pixel ) &0xff;
The width and height values must be greater than or equal to zero. The number of components is between 1 and 4. Any value outside of these bounds will generate an IllegalArgumentException.
- Returns:
- The array of pixel values as specified above.
-
getPixels
public abstract void getPixels(int[] pixels) Write the pixel values to the given array. Returns values in the same format as that used by the no argument version of this method. The length of the array must be at least width * height elements.- Parameters:
pixels
- The array to write pixels to.- Throws:
ArrayIndexOutOfBoundsException
- The provided array was too small
-