java.awt.image
Class DataBuffer

java.lang.Object
  extended by java.awt.image.DataBuffer
Direct Known Subclasses:
DataBufferByte, DataBufferDouble, DataBufferFloat, DataBufferInt, DataBufferShort, DataBufferUShort

public abstract class DataBuffer
extends Object

Class that manages arrays of data elements. A data buffer consists of one or more banks. A bank is a continuous region of data elements.


Field Summary
protected  int banks
          The number of banks in this buffer.
protected  int dataType
          The type of the data elements stored in the data buffer.
protected  int offset
          Offset into the default (0'th) bank).
protected  int[] offsets
          Offset into each bank.
protected  int size
          The size of the banks.
static int TYPE_BYTE
          A constant representing a data type that uses byte primitives as the storage unit.
static int TYPE_DOUBLE
          A constant representing a data type that uses double primitives as the storage unit.
static int TYPE_FLOAT
          A constant representing a data type that uses float primitives as the storage unit.
static int TYPE_INT
          A constant representing a data type that uses int primitives as the storage unit.
static int TYPE_SHORT
          A constant representing a data type that uses short primitives as the storage unit.
static int TYPE_UNDEFINED
          A constant representing an undefined data type.
static int TYPE_USHORT
          A constant representing a data type that uses short primitives as the storage unit.
 
Constructor Summary
protected DataBuffer(int dataType, int size)
          Creates a new DataBuffer with the specified data type and size.
protected DataBuffer(int dataType, int size, int numBanks)
          Creates a new DataBuffer with the specified data type, size and number of banks.
protected DataBuffer(int dataType, int size, int numBanks, int offset)
          Creates a new DataBuffer with the specified data type, size and number of banks.
protected DataBuffer(int dataType, int size, int numBanks, int[] offsets)
          Creates a new DataBuffer with the specified data type, size and number of banks.
 
Method Summary
 int getDataType()
          Returns the type of the data elements in the data buffer.
static int getDataTypeSize(int dataType)
          Returns the size (number of bits) of the specified data type.
 int getElem(int i)
          Returns an element from the first data bank.
abstract  int getElem(int bank, int i)
          Returns an element from a particular data bank.
 double getElemDouble(int i)
          Returns an element from the first data bank, converted to a double.
 double getElemDouble(int bank, int i)
          Returns an element from a particular data bank, converted to a double.
 float getElemFloat(int i)
          Returns an element from the first data bank, converted to a float.
 float getElemFloat(int bank, int i)
          Returns an element from a particular data bank, converted to a float.
 int getNumBanks()
          Returns the number of data banks for this DataBuffer.
 int getOffset()
          Returns the element offset for the first data bank.
 int[] getOffsets()
          Returns the offsets for all the data banks used by this DataBuffer.
 int getSize()
          Returns the size of the data buffer.
 void setElem(int i, int val)
          Sets an element in the first data bank.
abstract  void setElem(int bank, int i, int val)
          Sets an element in a particular data bank.
 void setElemDouble(int i, double val)
          Sets an element in the first data bank.
 void setElemDouble(int bank, int i, double val)
          Sets an element in a particular data bank.
 void setElemFloat(int i, float val)
          Sets an element in the first data bank.
 void setElemFloat(int bank, int i, float val)
          Sets an element in a particular data bank.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE_BYTE

public static final int TYPE_BYTE
A constant representing a data type that uses byte primitives as the storage unit.

See Also:
Constant Field Values

TYPE_USHORT

public static final int TYPE_USHORT
A constant representing a data type that uses short primitives as the storage unit.

See Also:
Constant Field Values

TYPE_SHORT

public static final int TYPE_SHORT
A constant representing a data type that uses short primitives as the storage unit.

See Also:
Constant Field Values

TYPE_INT

public static final int TYPE_INT
A constant representing a data type that uses int primitives as the storage unit.

See Also:
Constant Field Values

TYPE_FLOAT

public static final int TYPE_FLOAT
A constant representing a data type that uses float primitives as the storage unit.

See Also:
Constant Field Values

TYPE_DOUBLE

public static final int TYPE_DOUBLE
A constant representing a data type that uses double primitives as the storage unit.

See Also:
Constant Field Values

TYPE_UNDEFINED

public static final int TYPE_UNDEFINED
A constant representing an undefined data type.

See Also:
Constant Field Values

dataType

protected int dataType
The type of the data elements stored in the data buffer.


banks

protected int banks
The number of banks in this buffer.


offset

protected int offset
Offset into the default (0'th) bank).


size

protected int size
The size of the banks.


offsets

protected int[] offsets
Offset into each bank.

Constructor Detail

DataBuffer

protected DataBuffer(int dataType,
                     int size)
Creates a new DataBuffer with the specified data type and size. The dataType should be one of the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

The physical (array-based) storage is allocated by a subclass.

Parameters:
dataType - the data type.
size - the number of elements in the buffer.

DataBuffer

protected DataBuffer(int dataType,
                     int size,
                     int numBanks)
Creates a new DataBuffer with the specified data type, size and number of banks. The dataType should be one of the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

The physical (array-based) storage is allocated by a subclass.

Parameters:
dataType - the data type.
size - the number of elements in the buffer.
numBanks - the number of data banks.

DataBuffer

protected DataBuffer(int dataType,
                     int size,
                     int numBanks,
                     int offset)
Creates a new DataBuffer with the specified data type, size and number of banks. An offset (which applies to all banks) is also specified. The dataType should be one of the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

The physical (array-based) storage is allocated by a subclass.

Parameters:
dataType - the data type.
size - the number of elements in the buffer.
numBanks - the number of data banks.
offset - the offset to the first element for all banks.

DataBuffer

protected DataBuffer(int dataType,
                     int size,
                     int numBanks,
                     int[] offsets)
Creates a new DataBuffer with the specified data type, size and number of banks. An offset (which applies to all banks) is also specified. The dataType should be one of the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

The physical (array-based) storage is allocated by a subclass.

Parameters:
dataType - the data type.
size - the number of elements in the buffer.
numBanks - the number of data banks.
offsets - the offsets to the first element for all banks.
Throws:
ArrayIndexOutOfBoundsException - if numBanks != offsets.length.
Method Detail

getDataTypeSize

public static int getDataTypeSize(int dataType)
Returns the size (number of bits) of the specified data type. Valid types are defined by the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

Parameters:
dataType - the data type.
Returns:
The number of bits for the specified data type.
Throws:
IllegalArgumentException - if dataType < 0 or dataType > TYPE_DOUBLE.

getDataType

public int getDataType()
Returns the type of the data elements in the data buffer. Valid types are defined by the constants TYPE_BYTE, TYPE_SHORT, TYPE_USHORT, TYPE_INT, TYPE_FLOAT and TYPE_DOUBLE.

Returns:
The type.

getSize

public int getSize()
Returns the size of the data buffer.

Returns:
The size.

getOffset

public int getOffset()
Returns the element offset for the first data bank.

Returns:
The element offset.

getOffsets

public int[] getOffsets()
Returns the offsets for all the data banks used by this DataBuffer.

Returns:
The offsets.

getNumBanks

public int getNumBanks()
Returns the number of data banks for this DataBuffer.

Returns:
The number of data banks.

getElem

public int getElem(int i)
Returns an element from the first data bank. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
i - the element index.
Returns:
The element.

getElem

public abstract int getElem(int bank,
                            int i)
Returns an element from a particular data bank. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
bank - the bank index.
i - the element index.
Returns:
The element.

setElem

public void setElem(int i,
                    int val)
Sets an element in the first data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
i - the element index.
val - the new element value.

setElem

public abstract void setElem(int bank,
                             int i,
                             int val)
Sets an element in a particular data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
bank - the data bank index.
i - the element index.
val - the new element value.

getElemFloat

public float getElemFloat(int i)
Returns an element from the first data bank, converted to a float. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
i - the element index.
Returns:
The element.

getElemFloat

public float getElemFloat(int bank,
                          int i)
Returns an element from a particular data bank, converted to a float. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
bank - the bank index.
i - the element index.
Returns:
The element.

setElemFloat

public void setElemFloat(int i,
                         float val)
Sets an element in the first data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
i - the element index.
val - the new element value.

setElemFloat

public void setElemFloat(int bank,
                         int i,
                         float val)
Sets an element in a particular data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
bank - the data bank index.
i - the element index.
val - the new element value.

getElemDouble

public double getElemDouble(int i)
Returns an element from the first data bank, converted to a double. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
i - the element index.
Returns:
The element.

getElemDouble

public double getElemDouble(int bank,
                            int i)
Returns an element from a particular data bank, converted to a double. The offset (specified in the constructor) is added to i before accessing the underlying data array.

Parameters:
bank - the bank index.
i - the element index.
Returns:
The element.

setElemDouble

public void setElemDouble(int i,
                          double val)
Sets an element in the first data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
i - the element index.
val - the new element value.

setElemDouble

public void setElemDouble(int bank,
                          int i,
                          double val)
Sets an element in a particular data bank. The offset (specified in the constructor) is added to i before updating the underlying data array.

Parameters:
bank - the data bank index.
i - the element index.
val - the new element value.