java.awt.image

Class DataBuffer

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 intbanks
The number of banks in this buffer.
protected intdataType
The type of the data elements stored in the data buffer.
protected intoffset
Offset into the default (0'th) bank).
protected int[]offsets
Offset into each bank.
protected intsize
The size of the banks.
static intTYPE_BYTE
A constant representing a data type that uses byte primitives as the storage unit.
static intTYPE_DOUBLE
A constant representing a data type that uses double primitives as the storage unit.
static intTYPE_FLOAT
A constant representing a data type that uses float primitives as the storage unit.
static intTYPE_INT
A constant representing a data type that uses int primitives as the storage unit.
static intTYPE_SHORT
A constant representing a data type that uses short primitives as the storage unit.
static intTYPE_UNDEFINED
A constant representing an undefined data type.
static intTYPE_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
intgetDataType()
Returns the type of the data elements in the data buffer.
static intgetDataTypeSize(int dataType)
Returns the size (number of bits) of the specified data type.
intgetElem(int i)
Returns an element from the first data bank.
abstract intgetElem(int bank, int i)
Returns an element from a particular data bank.
doublegetElemDouble(int i)
Returns an element from the first data bank, converted to a double.
doublegetElemDouble(int bank, int i)
Returns an element from a particular data bank, converted to a double.
floatgetElemFloat(int i)
Returns an element from the first data bank, converted to a float.
floatgetElemFloat(int bank, int i)
Returns an element from a particular data bank, converted to a float.
intgetNumBanks()
Returns the number of data banks for this DataBuffer.
intgetOffset()
Returns the element offset for the first data bank.
int[]getOffsets()
Returns the offsets for all the data banks used by this DataBuffer.
intgetSize()
Returns the size of the data buffer.
voidsetElem(int i, int val)
Sets an element in the first data bank.
abstract voidsetElem(int bank, int i, int val)
Sets an element in a particular data bank.
voidsetElemDouble(int i, double val)
Sets an element in the first data bank.
voidsetElemDouble(int bank, int i, double val)
Sets an element in a particular data bank.
voidsetElemFloat(int i, float val)
Sets an element in the first data bank.
voidsetElemFloat(int bank, int i, float val)
Sets an element in a particular data bank.

Field Detail

banks

protected int banks
The number of banks in this buffer.

dataType

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

offset

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

offsets

protected int[] offsets
Offset into each bank.

size

protected int size
The size of the banks.

TYPE_BYTE

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

TYPE_DOUBLE

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

TYPE_FLOAT

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

TYPE_INT

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

TYPE_SHORT

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

TYPE_UNDEFINED

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

TYPE_USHORT

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

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 {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #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 {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #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 {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #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 {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #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

getDataType

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

Returns: The type.

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 {@link #TYPE_BYTE}, {@link #TYPE_SHORT}, {@link #TYPE_USHORT}, {@link #TYPE_INT}, {@link #TYPE_FLOAT} and {@link #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.

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.

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.

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.

getNumBanks

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

Returns: The number of data banks.

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.

getSize

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

Returns: The size.

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.

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.

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.