com.jme.image
Class Image

java.lang.Object
  extended by com.jme.image.Image
All Implemented Interfaces:
Savable, java.io.Serializable

public class Image
extends java.lang.Object
implements java.io.Serializable, Savable

Image defines a data format for a graphical image. The image is defined by a format, a height and width, and the image data. The width and height must be greater than 0. The data is contained in a byte buffer, and should be packed before creation of the image object.

Version:
$Id: Image.java 4131 2009-03-19 20:15:28Z blaine.dev $
Author:
Mark Powell, Joshua Slack
See Also:
Serialized Form

Nested Class Summary
static class Image.Format
           
 
Field Summary
protected  java.util.ArrayList<java.nio.ByteBuffer> data
           
protected  int depth
           
protected  Image.Format format
           
protected  int height
           
protected  int[] mipMapSizes
           
protected  int width
           
 
Constructor Summary
Image()
          Constructor instantiates a new Image object.
Image(Image.Format format, int width, int height, java.nio.ByteBuffer data)
          Constructor instantiates a new Image object.
Image(Image.Format format, int width, int height, java.nio.ByteBuffer data, int[] mipMapSizes)
          Constructor instantiates a new Image object.
Image(Image.Format format, int width, int height, int depth, java.util.ArrayList<java.nio.ByteBuffer> data)
          Constructor instantiates a new Image object.
Image(Image.Format format, int width, int height, int depth, java.util.ArrayList<java.nio.ByteBuffer> data, int[] mipMapSizes)
          Constructor instantiates a new Image object.
 
Method Summary
 void addData(java.nio.ByteBuffer data)
           
 boolean equals(java.lang.Object other)
           
 java.lang.Class getClassTag()
           
 java.util.ArrayList<java.nio.ByteBuffer> getData()
          getData returns the data for this image.
 java.nio.ByteBuffer getData(int index)
          getData returns the data for this image.
 int getDepth()
          getDepth returns the depth of this image (for 3d images).
static int getEstimatedByteSize(Image.Format format)
           
 Image.Format getFormat()
          getFormat returns the image format for this image.
 int getHeight()
          getHeight returns the height of this image.
 int[] getMipMapSizes()
          Returns the mipmap sizes for this image.
 int getWidth()
          getWidth returns the width of this image.
 boolean hasMipmaps()
          Returns whether the image data contains mipmaps.
 void read(JMEImporter e)
           
 void setData(java.util.ArrayList<java.nio.ByteBuffer> data)
          setData sets the data that makes up the image.
 void setData(java.nio.ByteBuffer data)
          setData sets the data that makes up the image.
 void setData(int index, java.nio.ByteBuffer data)
           
 void setDepth(int depth)
          setDepth sets the depth value of the image.
 void setFormat(Image.Format format)
          setFormat sets the image format for this image.
 void setHeight(int height)
          setHeight sets the height value of the image.
 void setMipMapSizes(int[] mipMapSizes)
          Sets the mipmap sizes stored in this image's data buffer.
 void setWidth(int width)
          setWidth sets the width value of the image.
 void write(JMEExporter e)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

format

protected Image.Format format

width

protected int width

height

protected int height

depth

protected int depth

mipMapSizes

protected int[] mipMapSizes

data

protected transient java.util.ArrayList<java.nio.ByteBuffer> data
Constructor Detail

Image

public Image()
Constructor instantiates a new Image object. All values are undefined.


Image

public Image(Image.Format format,
             int width,
             int height,
             int depth,
             java.util.ArrayList<java.nio.ByteBuffer> data,
             int[] mipMapSizes)
Constructor instantiates a new Image object. The attributes of the image are defined during construction.

Parameters:
format - the data format of the image.
width - the width of the image.
height - the height of the image.
data - the image data.
mipMapSizes - the array of mipmap sizes, or null for no mipmaps.

Image

public Image(Image.Format format,
             int width,
             int height,
             java.nio.ByteBuffer data,
             int[] mipMapSizes)
Constructor instantiates a new Image object. The attributes of the image are defined during construction.

Parameters:
format - the data format of the image.
width - the width of the image.
height - the height of the image.
data - the image data.
mipMapSizes - the array of mipmap sizes, or null for no mipmaps.

Image

public Image(Image.Format format,
             int width,
             int height,
             int depth,
             java.util.ArrayList<java.nio.ByteBuffer> data)
Constructor instantiates a new Image object. The attributes of the image are defined during construction.

Parameters:
type - the data format of the image.
width - the width of the image.
height - the height of the image.
data - the image data.

Image

public Image(Image.Format format,
             int width,
             int height,
             java.nio.ByteBuffer data)
Constructor instantiates a new Image object. The attributes of the image are defined during construction.

Parameters:
type - the data format of the image.
width - the width of the image.
height - the height of the image.
data - the image data.
Method Detail

setData

public void setData(java.util.ArrayList<java.nio.ByteBuffer> data)
setData sets the data that makes up the image. This data is packed into an array of ByteBuffer objects.

Parameters:
data - the data that contains the image information.

setData

public void setData(java.nio.ByteBuffer data)
setData sets the data that makes up the image. This data is packed into a single ByteBuffer.

Parameters:
data - the data that contains the image information.

addData

public void addData(java.nio.ByteBuffer data)

setData

public void setData(int index,
                    java.nio.ByteBuffer data)

setMipMapSizes

public void setMipMapSizes(int[] mipMapSizes)
Sets the mipmap sizes stored in this image's data buffer. Mipmaps are stored sequentially, and the first mipmap is the main image data. To specify no mipmaps, pass null and this will automatically be expanded into a single mipmap of the full

Parameters:
mipMapSizes - the mipmap sizes array, or null for a single image map.

setHeight

public void setHeight(int height)
setHeight sets the height value of the image. It is typically a good idea to try to keep this as a multiple of 2.

Parameters:
height - the height of the image.

setDepth

public void setDepth(int depth)
setDepth sets the depth value of the image. It is typically a good idea to try to keep this as a multiple of 2. This is used for 3d images.

Parameters:
depth - the depth of the image.

setWidth

public void setWidth(int width)
setWidth sets the width value of the image. It is typically a good idea to try to keep this as a multiple of 2.

Parameters:
width - the width of the image.

setFormat

public void setFormat(Image.Format format)
setFormat sets the image format for this image.

Parameters:
format - the image format.
Throws:
java.lang.NullPointerException - if format is null
See Also:
Image.Format

getFormat

public Image.Format getFormat()
getFormat returns the image format for this image.

Returns:
the image format.
See Also:
Image.Format

getWidth

public int getWidth()
getWidth returns the width of this image.

Returns:
the width of this image.

getHeight

public int getHeight()
getHeight returns the height of this image.

Returns:
the height of this image.

getDepth

public int getDepth()
getDepth returns the depth of this image (for 3d images).

Returns:
the depth of this image.

getData

public java.util.ArrayList<java.nio.ByteBuffer> getData()
getData returns the data for this image. If the data is undefined, null will be returned.

Returns:
the data for this image.

getData

public java.nio.ByteBuffer getData(int index)
getData returns the data for this image. If the data is undefined, null will be returned.

Returns:
the data for this image.

hasMipmaps

public boolean hasMipmaps()
Returns whether the image data contains mipmaps.

Returns:
true if the image data contains mipmaps, false if not.

getMipMapSizes

public int[] getMipMapSizes()
Returns the mipmap sizes for this image.

Returns:
the mipmap sizes for this image.

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

write

public void write(JMEExporter e)
           throws java.io.IOException
Specified by:
write in interface Savable
Throws:
java.io.IOException

read

public void read(JMEImporter e)
          throws java.io.IOException
Specified by:
read in interface Savable
Throws:
java.io.IOException

getClassTag

public java.lang.Class getClassTag()
Specified by:
getClassTag in interface Savable

getEstimatedByteSize

public static int getEstimatedByteSize(Image.Format format)
Parameters:
format - image data format
Returns:
an estimate of the size of a texture on the video card of an image in the given format. Mostly this is just a guess and could probably be cleaned up a lot.