diff options
Diffstat (limited to 'libjava/java/awt/image/DataBuffer.java')
-rw-r--r-- | libjava/java/awt/image/DataBuffer.java | 231 |
1 files changed, 231 insertions, 0 deletions
diff --git a/libjava/java/awt/image/DataBuffer.java b/libjava/java/awt/image/DataBuffer.java index 967e1a26c9c..b921953ec28 100644 --- a/libjava/java/awt/image/DataBuffer.java +++ b/libjava/java/awt/image/DataBuffer.java @@ -45,12 +45,45 @@ package java.awt.image; */ public abstract class DataBuffer { + /** + * A constant representng a data type that uses <code>byte</code> primitives + * as the storage unit. + */ public static final int TYPE_BYTE = 0; + + /** + * A constant representng a data type that uses <code>short</code> + * primitives as the storage unit. + */ public static final int TYPE_USHORT = 1; + + /** + * A constant representng a data type that uses <code>short</code> + * primitives as the storage unit. + */ public static final int TYPE_SHORT = 2; + + /** + * A constant representng a data type that uses <code>int</code> + * primitives as the storage unit. + */ public static final int TYPE_INT = 3; + + /** + * A constant representng a data type that uses <code>float</code> + * primitives as the storage unit. + */ public static final int TYPE_FLOAT = 4; + + /** + * A constant representng a data type that uses <code>double</code> + * primitives as the storage unit. + */ public static final int TYPE_DOUBLE = 5; + + /** + * A constant representng an undefined data type. + */ public static final int TYPE_UNDEFINED = 32; /** The type of the data elements stored in the data buffer. */ @@ -68,18 +101,57 @@ public abstract class DataBuffer /** Offset into each bank. */ protected int[] offsets; + /** + * Creates a new <code>DataBuffer</code> with the specified data type and + * size. The <code>dataType</code> 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}. + * <p> + * The physical (array-based) storage is allocated by a subclass. + * + * @param dataType the data type. + * @param size the number of elements in the buffer. + */ protected DataBuffer(int dataType, int size) { this.dataType = dataType; this.size = size; } + /** + * Creates a new <code>DataBuffer</code> with the specified data type, + * size and number of banks. The <code>dataType</code> 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}. + * <p> + * The physical (array-based) storage is allocated by a subclass. + * + * @param dataType the data type. + * @param size the number of elements in the buffer. + * @param numBanks the number of data banks. + */ protected DataBuffer(int dataType, int size, int numBanks) { this(dataType, size); banks = numBanks; offsets = new int[numBanks]; } + /** + * Creates a new <code>DataBuffer</code> with the specified data type, + * size and number of banks. An offset (which applies to all banks) is + * also specified. The <code>dataType</code> 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}. + * <p> + * The physical (array-based) storage is allocated by a subclass. + * + * @param dataType the data type. + * @param size the number of elements in the buffer. + * @param numBanks the number of data banks. + * @param offset the offset to the first element for all banks. + */ protected DataBuffer(int dataType, int size, int numBanks, int offset) { this(dataType, size, numBanks); @@ -88,6 +160,24 @@ public abstract class DataBuffer this.offset = offset; } + /** + * Creates a new <code>DataBuffer</code> with the specified data type, + * size and number of banks. An offset (which applies to all banks) is + * also specified. The <code>dataType</code> 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}. + * <p> + * The physical (array-based) storage is allocated by a subclass. + * + * @param dataType the data type. + * @param size the number of elements in the buffer. + * @param numBanks the number of data banks. + * @param offsets the offsets to the first element for all banks. + * + * @throws ArrayIndexOutOfBoundsException if + * <code>numBanks != offsets.length</code>. + */ protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) { this(dataType, size); if (numBanks != offsets.length) @@ -99,6 +189,17 @@ public abstract class DataBuffer offset = offsets[0]; } + /** + * 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}. + * + * @param dataType the data type. + * @return The number of bits for the specified data type. + * @throws IllegalArgumentException if <code>dataType < 0</code> or + * <code>dataType > TYPE_DOUBLE</code>. + */ public static int getDataTypeSize(int dataType) { // Maybe this should be a lookup table instead. switch (dataType) @@ -118,21 +219,45 @@ public abstract class DataBuffer } } + /** + * 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}. + * + * @return The type. + */ public int getDataType() { return dataType; } + /** + * Returns the size of the data buffer. + * + * @return The size. + */ public int getSize() { return size; } + /** + * Returns the element offset for the first data bank. + * + * @return The element offset. + */ public int getOffset() { return offset; } + /** + * Returns the offsets for all the data banks used by this + * <code>DataBuffer</code>. + * + * @return The offsets. + */ public int[] getOffsets() { if (offsets == null) @@ -144,60 +269,166 @@ public abstract class DataBuffer return offsets; } + /** + * Returns the number of data banks for this <code>DataBuffer</code>. + * @return The number of data banks. + */ public int getNumBanks() { return banks; } + /** + * Returns an element from the first data bank. The offset (specified in + * the constructor) is added to <code>i</code> before accessing the + * underlying data array. + * + * @param i the element index. + * @return The element. + */ public int getElem(int i) { return getElem(0, i); } + /** + * Returns an element from a particular data bank. The offset (specified in + * the constructor) is added to <code>i</code> before accessing the + * underlying data array. + * + * @param bank the bank index. + * @param i the element index. + * @return The element. + */ public abstract int getElem(int bank, int i); + /** + * Sets an element in the first data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param i the element index. + * @param val the new element value. + */ public void setElem(int i, int val) { setElem(0, i, val); } + /** + * Sets an element in a particular data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param bank the data bank index. + * @param i the element index. + * @param val the new element value. + */ public abstract void setElem(int bank, int i, int val); + /** + * Returns an element from the first data bank, converted to a + * <code>float</code>. The offset (specified in the constructor) is added + * to <code>i</code> before accessing the underlying data array. + * + * @param i the element index. + * @return The element. + */ public float getElemFloat(int i) { return getElem(i); } + /** + * Returns an element from a particular data bank, converted to a + * <code>float</code>. The offset (specified in the constructor) is + * added to <code>i</code> before accessing the underlying data array. + * + * @param bank the bank index. + * @param i the element index. + * @return The element. + */ public float getElemFloat(int bank, int i) { return getElem(bank, i); } + /** + * Sets an element in the first data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param i the element index. + * @param val the new element value. + */ public void setElemFloat(int i, float val) { setElem(i, (int) val); } + /** + * Sets an element in a particular data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param bank the data bank index. + * @param i the element index. + * @param val the new element value. + */ public void setElemFloat(int bank, int i, float val) { setElem(bank, i, (int) val); } + /** + * Returns an element from the first data bank, converted to a + * <code>double</code>. The offset (specified in the constructor) is added + * to <code>i</code> before accessing the underlying data array. + * + * @param i the element index. + * @return The element. + */ public double getElemDouble(int i) { return getElem(i); } + /** + * Returns an element from a particular data bank, converted to a + * <code>double</code>. The offset (specified in the constructor) is + * added to <code>i</code> before accessing the underlying data array. + * + * @param bank the bank index. + * @param i the element index. + * @return The element. + */ public double getElemDouble(int bank, int i) { return getElem(bank, i); } + /** + * Sets an element in the first data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param i the element index. + * @param val the new element value. + */ public void setElemDouble(int i, double val) { setElem(i, (int) val); } + /** + * Sets an element in a particular data bank. The offset (specified in the + * constructor) is added to <code>i</code> before updating the underlying + * data array. + * + * @param bank the data bank index. + * @param i the element index. + * @param val the new element value. + */ public void setElemDouble(int bank, int i, double val) { setElem(bank, i, (int) val); |