001: /*
002: * $RCSfile: DataBufferFloat.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:07 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.awt.image.DataBuffer;
015:
016: /**
017: * An extension of <code>DataBuffer</code> that stores data internally in
018: * <code>float</code> form.
019: *
020: * @see java.awt.image.DataBuffer
021: */
022: public class DataBufferFloat extends DataBuffer {
023:
024: /** The array of data banks. */
025: protected float bankdata[][];
026:
027: /** A reference to the default data bank. */
028: protected float data[];
029:
030: /**
031: * Constructs a <code>float</code>-based <code>DataBuffer</code>
032: * with a specified size.
033: *
034: * @param size The number of elements in the <code>DataBuffer</code>.
035: */
036: public DataBufferFloat(int size) {
037: super (TYPE_FLOAT, size);
038: data = new float[size];
039: bankdata = new float[1][];
040: bankdata[0] = data;
041: }
042:
043: /**
044: * Constructs a <code>float</code>-based <code>DataBuffer</code>
045: * with a specified number of banks, all of which are of a
046: * specified size.
047: *
048: * @param size The number of elements in each bank of the
049: * <code>DataBuffer</code>.
050: * @param numBanks The number of banks in the
051: * <code>DataBuffer</code>.
052: */
053: public DataBufferFloat(int size, int numBanks) {
054: super (TYPE_FLOAT, size, numBanks);
055: bankdata = new float[numBanks][];
056: for (int i = 0; i < numBanks; i++) {
057: bankdata[i] = new float[size];
058: }
059: data = bankdata[0];
060: }
061:
062: /**
063: * Constructs a <code>float</code>-based <code>DataBuffer</code>
064: * with the specified data array. Only the first
065: * <code>size</code> elements are available for use by this
066: * <code>DataBuffer</code>. The array must be large enough to
067: * hold <code>size</code> elements.
068: *
069: * @param dataArray An array of <code>float</code>s to be used as the
070: * first and only bank of this <code>DataBuffer</code>.
071: * @param size The number of elements of the array to be used.
072: */
073: public DataBufferFloat(float dataArray[], int size) {
074: super (TYPE_FLOAT, size);
075: if (dataArray.length < size)
076: throw new RuntimeException(JaiI18N.getString("DataBuffer0"));
077: data = dataArray;
078: bankdata = new float[1][];
079: bankdata[0] = data;
080: }
081:
082: /**
083: * Constructs a <code>float</code>-based <code>DataBuffer</code>
084: * with the specified data array. Only the elements between
085: * <code>offset</code> and <code>offset + size - 1</code> are
086: * available for use by this <code>DataBuffer</code>. The array
087: * must be large enough to hold <code>offset + size</code>
088: * elements.
089: *
090: * @param dataArray An array of <code>float</code>s to be used as the
091: * first and only bank of this <code>DataBuffer</code>.
092: * @param size The number of elements of the array to be used.
093: * @param offset The offset of the first element of the array
094: * that will be used.
095: */
096: public DataBufferFloat(float dataArray[], int size, int offset) {
097: super (TYPE_FLOAT, size, 1, offset);
098: if (dataArray.length < size)
099: throw new RuntimeException(JaiI18N.getString("DataBuffer1"));
100: data = dataArray;
101: bankdata = new float[1][];
102: bankdata[0] = data;
103: }
104:
105: /**
106: * Constructs a <code>float</code>-based <code>DataBuffer</code>
107: * with the specified data arrays. Only the first
108: * <code>size</code> elements of each array are available for use
109: * by this <code>DataBuffer</code>. The number of banks will be
110: * equal to <code>dataArray.length</code>.
111: *
112: * @param dataArray An array of arrays of <code>float</code>s to be
113: * used as the banks of this <code>DataBuffer</code>.
114: * @param size The number of elements of each array to be used.
115: */
116: public DataBufferFloat(float dataArray[][], int size) {
117: super (TYPE_FLOAT, size, dataArray.length);
118: bankdata = dataArray;
119: data = bankdata[0];
120: }
121:
122: /**
123: * Constructs a <code>float</code>-based <code>DataBuffer</code>
124: * with the specified data arrays, size, and per-bank offsets.
125: * The number of banks is equal to <code>dataArray.length</code>.
126: * Each array must be at least as large as <code>size</code> plus the
127: * corresponding offset. There must be an entry in the offsets
128: * array for each data array.
129: *
130: * @param dataArray An array of arrays of <code>float</code>s to be
131: * used as the banks of this <code>DataBuffer</code>.
132: * @param size The number of elements of each array to be used.
133: * @param offsets An array of integer offsets, one for each bank.
134: */
135: public DataBufferFloat(float dataArray[][], int size, int offsets[]) {
136: super (TYPE_FLOAT, size, dataArray.length, offsets);
137: bankdata = dataArray;
138: data = bankdata[0];
139: }
140:
141: /** Returns the <code>float</code> data array of the default(first) bank. */
142: public float[] getData() {
143: return data;
144: }
145:
146: /** Returns the data array for the specified bank. */
147: public float[] getData(int bank) {
148: return bankdata[bank];
149: }
150:
151: /** Returns the data array for all banks. */
152: public float[][] getBankData() {
153: return bankdata;
154: }
155:
156: /**
157: * Returns the requested data array element from the first
158: * (default) bank rounded off as an <code>int</code>.
159: *
160: * @param i The desired data array element.
161: *
162: * @return The data entry as an <code>int</code>.
163: */
164: public int getElem(int i) {
165: return Math.round(data[i + offset]);
166: }
167:
168: /**
169: * Returns the requested data array element from the specified
170: * bank rounded off as an <code>int</code>.
171: *
172: * @param bank The bank number.
173: * @param i The desired data array element.
174: *
175: * @return The data entry as an <code>int</code>.
176: */
177: public int getElem(int bank, int i) {
178: return Math.round(bankdata[bank][i + offsets[bank]]);
179: }
180:
181: /**
182: * Sets the requested data array element in the first (default)
183: * bank to the given <code>int</code>.
184: *
185: * @param i The desired data array element.
186: * @param val The value to be set.
187: */
188: public void setElem(int i, int val) {
189: data[i + offset] = (float) val;
190: }
191:
192: /**
193: * Sets the requested data array element in the specified bank to
194: * the given <code>int</code>.
195: *
196: * @param bank The bank number.
197: * @param i The desired data array element.
198: * @param val The value to be set.
199: */
200: public void setElem(int bank, int i, int val) {
201: bankdata[bank][i + offsets[bank]] = (float) val;
202: }
203:
204: /**
205: * Returns the requested data array element from the first
206: * (default) bank as a <code>float</code>.
207: *
208: * @param i The desired data array element.
209: *
210: * @return The data entry as a <code>float</code>.
211: */
212: public float getElemFloat(int i) {
213: return data[i + offset];
214: }
215:
216: /**
217: * Returns the requested data array element from the specified
218: * bank as a <code>float</code>.
219: *
220: * @param bank The bank number.
221: * @param i The desired data array element.
222: *
223: * @return The data entry as a <code>float</code>.
224: */
225: public float getElemFloat(int bank, int i) {
226: return bankdata[bank][i + offsets[bank]];
227: }
228:
229: /**
230: * Sets the requested data array element in the first (default)
231: * bank to the given <code>float</code>.
232: *
233: * @param i The desired data array element.
234: * @param val The value to be set.
235: */
236: public void setElemFloat(int i, float val) {
237: data[i + offset] = val;
238: }
239:
240: /**
241: * Sets the requested data array element in the specified bank to
242: * the given <code>float</code>.
243: *
244: * @param bank The bank number.
245: * @param i The desired data array element.
246: * @param val The value to be set.
247: */
248: public void setElemFloat(int bank, int i, float val) {
249: bankdata[bank][i + offsets[bank]] = val;
250: }
251:
252: /**
253: * Returns the requested data array element from the first
254: * (default) bank as a <code>double</code>.
255: *
256: * @param i The desired data array element.
257: *
258: * @return The data entry as a <code>double</code>.
259: */
260: public double getElemDouble(int i) {
261: return (double) data[i + offset];
262: }
263:
264: /**
265: * Returns the requested data array element from the specified
266: * bank as a <code>double</code>.
267: *
268: * @param bank The bank number.
269: * @param i The desired data array element.
270: *
271: * @return The data entry as a <code>double</code>.
272: */
273: public double getElemDouble(int bank, int i) {
274: return (double) bankdata[bank][i + offsets[bank]];
275: }
276:
277: /**
278: * Sets the requested data array element in the first (default)
279: * bank to the given <code>double</code>.
280: *
281: * @param i The desired data array element.
282: * @param val The value to be set.
283: */
284: public void setElemDouble(int i, double val) {
285: data[i + offset] = (float) val;
286: }
287:
288: /**
289: * Sets the requested data array element in the specified bank to
290: * the given <code>double</code>.
291: *
292: * @param bank The bank number.
293: * @param i The desired data array element.
294: * @param val The value to be set.
295: */
296: public void setElemDouble(int bank, int i, double val) {
297: bankdata[bank][i + offsets[bank]] = (float) val;
298: }
299: }
|