Package WildMagic.LibGraphics.Rendering
Class GraphicsImage
- java.lang.Object
-
- WildMagic.LibGraphics.ObjectSystem.GraphicsObject
-
- WildMagic.LibGraphics.Rendering.GraphicsImage
-
- All Implemented Interfaces:
java.io.Serializable,StreamInterface
public class GraphicsImage extends GraphicsObject implements StreamInterface, java.io.Serializable
The color image data is stored so that the red channel is in low memory, the green channel is next, the blue channel after that, and the alpha channel in high memory. For example, the first pixel has the following layout. IT_RGB888: r = aucData[0]; g = aucData[1]; b = aucData[2]; IT_RGBA8888: r = aucData[0]; g = aucData[1]; b = aucData[2]; a = aucData[3]; Depth image data is always 'float' with values in [0,1]. The specification of 16, 24, or 32 is for setting up the hardware with the correct size depth buffer. Data read into a depth image from the depth buffer will be converted to [0,1] if necessary. Construction and destruction. GraphicsImage accepts responsibility for deleting the input array. The acImageName field is used as a unique identifier for the image for purposes of sharing. The caller of the constructor may provided a name. If not, the constructor generates a unique name "imageN.wmif" where N is the Object::m_uiID field. A global map of images is maintained for sharing purposes. NOTE: GraphicsImage dimensions must be a power of two. Assert statements are placed in the constructors to trap when the dimensions are not power of two.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGraphicsImage.FormatModeGraphicsImage format mode:static classGraphicsImage.TypeGraphicsImage format mode:
-
Field Summary
Fields Modifier and Type Field Description private static floatfInv255Converting from 0-255 range to 0-1 range.protected float[]m_afDataImage float data.protected int[]m_aiBoundImage extents.protected byte[]m_aucDataImage byte data.protected booleanm_bUpdateBufferprotected GraphicsImage.FormatModem_eFormatImage format mode.private static GraphicsImage.FormatModem_eFormatModeStaticInitializes format mode static enum:protected GraphicsImage.Typem_eTypeImage format mode.private static GraphicsImage.Typem_eTypeStaticInitializes format mode static enum:protected intm_iDimensionImage number of dimensions.protected intm_iQuantityImage size.protected java.nio.Bufferm_kBufferprivate static java.util.HashMap<java.lang.Integer,GraphicsImage.FormatMode>ms_pkFormatModeMapFor a lookup of the renderer constant type from its string name.private static java.util.HashMap<java.lang.Integer,GraphicsImage.Type>ms_pkTypeMapFor a lookup of the renderer constant type from its string name.private static longserialVersionUID
-
Constructor Summary
Constructors Constructor Description GraphicsImage()Default constructor.GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, byte[] aucData, java.lang.String acImageName)Construct a 1D image (byte)GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, float[] afData, java.lang.String acImageName)Construct a 1D image (float)GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, byte[] aucData, java.lang.String acImageName)Construct a 2D image (byte)GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, float[] afData, java.lang.String acImageName)Construct a 2D image (float)GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, int iBound2, byte[] aucData, java.lang.String acImageName)Construct a 3D image (byte)GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, int iBound2, float[] afData, java.lang.String acImageName)Construct a 3D image (float)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidCopyRGBA(ColorRGBA[] akCImage)Copy to an already existing image of ColorRGBA values.ColorRGBA[]CreateRGBA()Create an image of ColorRGBA values.voiddispose()delete memoryintGetBound(int i)Get the image extent in the given dimension.intGetBytesPerPixel()Get the number of bytes per pixel in the image.static intGetBytesPerPixel(GraphicsImage.FormatMode eFormat)Get the number of bytes per pixel for the given format enum.byte[]GetData()Get the image data.java.nio.BufferGetDataBuffer()Get the imag data in Buffer format.intGetDimension()Get the dimension of this image (1D, 2D, 3D).intGetDiskUsed(StreamVersion rkVersion)Returns the size of this object and it's children on disk for the current StreamVersion parameter.float[]GetFloatData()Get image float data.GraphicsImage.FormatModeGetFormat()Return image format.java.lang.StringGetFormatName()Return image format name.static java.lang.StringGetFormatName(GraphicsImage.FormatMode eFormat)Return image format name for the input enum.intGetQuantity()Get the image size.GraphicsImage.TypeGetType()Get the image size.voidInitDataBuffer()Allocate the data array based on the image type.booleanIsCubeImage()Return true if this is a cube image.booleanIsDepthImage()Return true if this is a depth image.static GraphicsImageLoad(java.lang.String acImageName, java.lang.String rkDirectory)Streaming support.voidLoad(Stream rkStream, Stream.Link pkLink)Loads this object from the input parameter rkStream, using the input Stream.Link to store the IDs of children objects of this object for linking after all objects are loaded from the Stream.private static java.io.ByteArrayInputStreamLoadFile(java.lang.String acFilename)Opens an input stream from the input filename.static GraphicsImageLoadImage(java.lang.String acImageName, java.lang.String rkDirectory, java.lang.String kExtension)voidSave(Stream rkStream)Write this object and all it's children to the Stream.StringTreeSaveStrings(java.lang.String acTitle)Write this object into a StringTree for the scene-graph visualization.voidSetData(byte[] aucData, int iSize)Set the image data for 1D image.voidSetData(byte[] aucData, int iXSize, int iYSize)Set the image data for 2D image.voidSetData(byte[] aucData, int iXSize, int iYSize, int iZSize)Set the image data for 3D image.voidSetData(float[] afData, int iXSize, int iYSize)Set the image data for 2D image.voidSetData(java.nio.Buffer kBuffer, int iZ)voidSetData(java.nio.ByteBuffer kBuffer, int iZ)voidSetFloatData(float[] afData, int iSize)Set the image data for 1D image.voidSetFloatData(float[] afData, int iXSize, int iYSize)Set the image data for 2D image.voidSetFloatData(float[] afData, int iXSize, int iYSize, int iZSize)Set the image data for 3D image.-
Methods inherited from class WildMagic.LibGraphics.ObjectSystem.GraphicsObject
GetAllObjectsByName, GetID, GetName, GetNextID, GetObjectByID, GetObjectByIDBase, GetObjectByName, GetObjectByNameBase, Link, Register, SetName
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface WildMagic.LibGraphics.ObjectSystem.StreamInterface
Link, Register
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
ms_pkFormatModeMap
private static java.util.HashMap<java.lang.Integer,GraphicsImage.FormatMode> ms_pkFormatModeMap
For a lookup of the renderer constant type from its string name.
-
ms_pkTypeMap
private static java.util.HashMap<java.lang.Integer,GraphicsImage.Type> ms_pkTypeMap
For a lookup of the renderer constant type from its string name.
-
m_eFormatModeStatic
private static GraphicsImage.FormatMode m_eFormatModeStatic
Initializes format mode static enum:
-
m_eTypeStatic
private static GraphicsImage.Type m_eTypeStatic
Initializes format mode static enum:
-
fInv255
private static final float fInv255
Converting from 0-255 range to 0-1 range.- See Also:
- Constant Field Values
-
m_eFormat
protected GraphicsImage.FormatMode m_eFormat
Image format mode.
-
m_eType
protected GraphicsImage.Type m_eType
Image format mode.
-
m_iDimension
protected int m_iDimension
Image number of dimensions.
-
m_aiBound
protected int[] m_aiBound
Image extents.
-
m_iQuantity
protected int m_iQuantity
Image size.
-
m_aucData
protected byte[] m_aucData
Image byte data.
-
m_afData
protected float[] m_afData
Image float data.
-
m_kBuffer
protected java.nio.Buffer m_kBuffer
-
m_bUpdateBuffer
protected boolean m_bUpdateBuffer
-
-
Constructor Detail
-
GraphicsImage
public GraphicsImage()
Default constructor.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, byte[] aucData, java.lang.String acImageName)
Construct a 1D image (byte)- Parameters:
eFormat- image formatiBound0- size of image.aucData- image data.acImageName- image name.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, float[] afData, java.lang.String acImageName)
Construct a 1D image (float)- Parameters:
eFormat- image formatiBound0- size of image.afData- image data.acImageName- image name.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, byte[] aucData, java.lang.String acImageName)
Construct a 2D image (byte)- Parameters:
eFormat- image formatiBound0- image dimension 1.iBound1- image dimension 2.aucData- image data.acImageName- image name.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, float[] afData, java.lang.String acImageName)
Construct a 2D image (float)- Parameters:
eFormat- image formatiBound0- image dimension 1.iBound1- image dimension 2.afData- image data.acImageName- image name.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, int iBound2, byte[] aucData, java.lang.String acImageName)
Construct a 3D image (byte)- Parameters:
eFormat- image formatiBound0- image dimension 1.iBound1- image dimension 2.iBound2- image dimension 3.aucData- image data.acImageName- image name.
-
GraphicsImage
public GraphicsImage(GraphicsImage.FormatMode eFormat, int iBound0, int iBound1, int iBound2, float[] afData, java.lang.String acImageName)
Construct a 3D image (float)- Parameters:
eFormat- image formatiBound0- image dimension 1.iBound1- image dimension 2.iBound2- image dimension 3.afData- image data.acImageName- image name.
-
-
Method Detail
-
GetBytesPerPixel
public static final int GetBytesPerPixel(GraphicsImage.FormatMode eFormat)
Get the number of bytes per pixel for the given format enum.- Parameters:
eFormat- format type.- Returns:
- the number of bytes per pixel for the given format enum.
-
GetFormatName
public static java.lang.String GetFormatName(GraphicsImage.FormatMode eFormat)
Return image format name for the input enum.- Parameters:
eFormat- format enum.- Returns:
- image format name.
-
Load
public static GraphicsImage Load(java.lang.String acImageName, java.lang.String rkDirectory)
Streaming support. The sharing system is automatically invoked by these calls. In Load, if an image corresponding to the filename is already in memory, then that image is returned (i.e. shared). Otherwise, a new image is created and returned. The filename is used as the image name.- Parameters:
acImageName- image namerkDirectory- directory where the image is located.- Returns:
- new GraphicsImage or null if it cannot be loaded.
-
LoadFile
private static java.io.ByteArrayInputStream LoadFile(java.lang.String acFilename)
Opens an input stream from the input filename.- Parameters:
acFilename- image file name.- Returns:
- an input stream for reading the file.
-
LoadImage
public static GraphicsImage LoadImage(java.lang.String acImageName, java.lang.String rkDirectory, java.lang.String kExtension)
-
CopyRGBA
public void CopyRGBA(ColorRGBA[] akCImage)
Copy to an already existing image of ColorRGBA values.- Parameters:
akCImage- The input array must have the correct dimensions as the GraphicsImage itself.
-
CreateRGBA
public ColorRGBA[] CreateRGBA()
Create an image of ColorRGBA values.- Returns:
- an image of the same width and height for these formats. The returned image is dynamically allocated; the caller is responsible for deleting it.
-
dispose
public void dispose()
delete memory- Overrides:
disposein classGraphicsObject
-
GetBound
public int GetBound(int i)
Get the image extent in the given dimension.- Parameters:
i- dimension.- Returns:
- the image extent in the given dimension.
-
GetBytesPerPixel
public final int GetBytesPerPixel()
Get the number of bytes per pixel in the image.- Returns:
- the number of bytes per pixel in the image.
-
GetData
public final byte[] GetData()
Get the image data.- Returns:
- the image data.
-
GetDataBuffer
public java.nio.Buffer GetDataBuffer()
Get the imag data in Buffer format.- Returns:
- the imag data in Buffer format.
-
GetDimension
public final int GetDimension()
Get the dimension of this image (1D, 2D, 3D).- Returns:
- the dimension of this image (1D, 2D, 3D).
-
GetDiskUsed
public int GetDiskUsed(StreamVersion rkVersion)
Returns the size of this object and it's children on disk for the current StreamVersion parameter.- Specified by:
GetDiskUsedin interfaceStreamInterface- Overrides:
GetDiskUsedin classGraphicsObject- Parameters:
rkVersion- the current version of the Stream file being created.- Returns:
- the size of this object on disk.
-
GetFloatData
public float[] GetFloatData()
Get image float data.- Returns:
- image float data.
-
GetFormat
public final GraphicsImage.FormatMode GetFormat()
Return image format.- Returns:
- image format.
-
GetFormatName
public final java.lang.String GetFormatName()
Return image format name.- Returns:
- image format name.
-
GetQuantity
public final int GetQuantity()
Get the image size.- Returns:
- the image size.
-
GetType
public final GraphicsImage.Type GetType()
Get the image size.- Returns:
- the image size.
-
InitDataBuffer
public void InitDataBuffer()
Allocate the data array based on the image type.
-
IsCubeImage
public final boolean IsCubeImage()
Return true if this is a cube image.- Returns:
- true if this is a cube image.
-
IsDepthImage
public final boolean IsDepthImage()
Return true if this is a depth image.- Returns:
- true if this is a depth image.
-
Load
public void Load(Stream rkStream, Stream.Link pkLink)
Loads this object from the input parameter rkStream, using the input Stream.Link to store the IDs of children objects of this object for linking after all objects are loaded from the Stream.- Specified by:
Loadin interfaceStreamInterface- Overrides:
Loadin classGraphicsObject- Parameters:
rkStream- the Stream from which this object is being read.pkLink- the Link class for storing the IDs of this object's children objects.
-
Save
public void Save(Stream rkStream)
Write this object and all it's children to the Stream.- Specified by:
Savein interfaceStreamInterface- Overrides:
Savein classGraphicsObject- Parameters:
rkStream- the Stream where the child objects are stored.
-
SaveStrings
public StringTree SaveStrings(java.lang.String acTitle)
Write this object into a StringTree for the scene-graph visualization.- Specified by:
SaveStringsin interfaceStreamInterface- Overrides:
SaveStringsin classGraphicsObject- Parameters:
acTitle- the header for this object in the StringTree.- Returns:
- StringTree containing a String-based representation of this object and it's children.
-
SetData
public void SetData(java.nio.Buffer kBuffer, int iZ)
-
SetData
public void SetData(byte[] aucData, int iSize)Set the image data for 1D image.- Parameters:
aucData- new image data.iSize- new image size.
-
SetData
public void SetData(byte[] aucData, int iXSize, int iYSize)Set the image data for 2D image.- Parameters:
aucData- new image data.iXSize- new image x-size.iYSize- new image y-size.
-
SetData
public void SetData(byte[] aucData, int iXSize, int iYSize, int iZSize)Set the image data for 3D image.- Parameters:
aucData- new image data.iXSize- new image x-size.iYSize- new image y-size.iZSize- new image z-size.
-
SetData
public void SetData(java.nio.ByteBuffer kBuffer, int iZ)
-
SetData
public void SetData(float[] afData, int iXSize, int iYSize)Set the image data for 2D image.- Parameters:
afData- new image data.iXSize- new image x-size.iYSize- new image y-size.
-
SetFloatData
public void SetFloatData(float[] afData, int iSize)Set the image data for 1D image.- Parameters:
afData- new image data.iSize- new image size.
-
SetFloatData
public void SetFloatData(float[] afData, int iXSize, int iYSize)Set the image data for 2D image.- Parameters:
afData- new image data.iXSize- new image x-size.iYSize- new image y-size.
-
SetFloatData
public void SetFloatData(float[] afData, int iXSize, int iYSize, int iZSize)Set the image data for 3D image.- Parameters:
afData- new image data.iXSize- new image x-size.iYSize- new image y-size.iZSize- new image z-size.
-
-