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 class
GraphicsImage.FormatMode
GraphicsImage format mode:static class
GraphicsImage.Type
GraphicsImage format mode:
-
Field Summary
Fields Modifier and Type Field Description private static float
fInv255
Converting from 0-255 range to 0-1 range.protected float[]
m_afData
Image float data.protected int[]
m_aiBound
Image extents.protected byte[]
m_aucData
Image byte data.protected boolean
m_bUpdateBuffer
protected GraphicsImage.FormatMode
m_eFormat
Image format mode.private static GraphicsImage.FormatMode
m_eFormatModeStatic
Initializes format mode static enum:protected GraphicsImage.Type
m_eType
Image format mode.private static GraphicsImage.Type
m_eTypeStatic
Initializes format mode static enum:protected int
m_iDimension
Image number of dimensions.protected int
m_iQuantity
Image size.protected java.nio.Buffer
m_kBuffer
private static java.util.HashMap<java.lang.Integer,GraphicsImage.FormatMode>
ms_pkFormatModeMap
For a lookup of the renderer constant type from its string name.private static java.util.HashMap<java.lang.Integer,GraphicsImage.Type>
ms_pkTypeMap
For a lookup of the renderer constant type from its string name.private static long
serialVersionUID
-
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 void
CopyRGBA(ColorRGBA[] akCImage)
Copy to an already existing image of ColorRGBA values.ColorRGBA[]
CreateRGBA()
Create an image of ColorRGBA values.void
dispose()
delete memoryint
GetBound(int i)
Get the image extent in the given dimension.int
GetBytesPerPixel()
Get the number of bytes per pixel in the image.static int
GetBytesPerPixel(GraphicsImage.FormatMode eFormat)
Get the number of bytes per pixel for the given format enum.byte[]
GetData()
Get the image data.java.nio.Buffer
GetDataBuffer()
Get the imag data in Buffer format.int
GetDimension()
Get the dimension of this image (1D, 2D, 3D).int
GetDiskUsed(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.FormatMode
GetFormat()
Return image format.java.lang.String
GetFormatName()
Return image format name.static java.lang.String
GetFormatName(GraphicsImage.FormatMode eFormat)
Return image format name for the input enum.int
GetQuantity()
Get the image size.GraphicsImage.Type
GetType()
Get the image size.void
InitDataBuffer()
Allocate the data array based on the image type.boolean
IsCubeImage()
Return true if this is a cube image.boolean
IsDepthImage()
Return true if this is a depth image.static GraphicsImage
Load(java.lang.String acImageName, java.lang.String rkDirectory)
Streaming support.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.private static java.io.ByteArrayInputStream
LoadFile(java.lang.String acFilename)
Opens an input stream from the input filename.static GraphicsImage
LoadImage(java.lang.String acImageName, java.lang.String rkDirectory, java.lang.String kExtension)
void
Save(Stream rkStream)
Write this object and all it's children to the Stream.StringTree
SaveStrings(java.lang.String acTitle)
Write this object into a StringTree for the scene-graph visualization.void
SetData(byte[] aucData, int iSize)
Set the image data for 1D image.void
SetData(byte[] aucData, int iXSize, int iYSize)
Set the image data for 2D image.void
SetData(byte[] aucData, int iXSize, int iYSize, int iZSize)
Set the image data for 3D image.void
SetData(float[] afData, int iXSize, int iYSize)
Set the image data for 2D image.void
SetData(java.nio.Buffer kBuffer, int iZ)
void
SetData(java.nio.ByteBuffer kBuffer, int iZ)
void
SetFloatData(float[] afData, int iSize)
Set the image data for 1D image.void
SetFloatData(float[] afData, int iXSize, int iYSize)
Set the image data for 2D image.void
SetFloatData(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:
dispose
in 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:
GetDiskUsed
in interfaceStreamInterface
- Overrides:
GetDiskUsed
in 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:
Load
in interfaceStreamInterface
- Overrides:
Load
in 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:
Save
in interfaceStreamInterface
- Overrides:
Save
in 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:
SaveStrings
in interfaceStreamInterface
- Overrides:
SaveStrings
in 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.
-
-