java.awt.image

Class DataBuffer

Known Direct 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

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.
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.

Constructor Summary

DataBuffer(int dataType, int size)
Creates a new DataBuffer with the specified data type and size.
DataBuffer(int dataType, int size, int numBanks)
Creates a new DataBuffer with the specified data type, size and number of banks.
DataBuffer(int dataType, int size, int numBanks, int offset)
Creates a new DataBuffer with the specified data type, size and number of banks.
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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

TYPE_BYTE

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

TYPE_DOUBLE

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

TYPE_FLOAT

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

TYPE_INT

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

TYPE_SHORT

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

TYPE_UNDEFINED

public static final int TYPE_UNDEFINED
A constant representing an undefined data type.
Field Value:
32

TYPE_USHORT

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

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.

Constructor Details

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 Details

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.

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 <320 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.

Copyright (C) 2000, 2002, 2005 Free Software Foundation This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.