KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > image > DataBufferFloat


1 /*
2  * @(#)DataBufferFloat.java 1.6 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.awt.image;
9
10 /**
11  * This class extends <code>DataBuffer</code> and stores data internally
12  * in <code>float</code> form.
13  *
14  * @see DataBuffer
15  * @since 1.4
16  */

17
18 public final class DataBufferFloat extends DataBuffer JavaDoc {
19
20     /** The array of data banks. */
21     float bankdata[][];
22
23     /** A reference to the default data bank. */
24     float data[];
25
26     /**
27      * Constructs a <code>float</code>-based <code>DataBuffer</code>
28      * with a specified size.
29      *
30      * @param size The number of elements in the DataBuffer.
31      */

32     public DataBufferFloat(int size) {
33         super(TYPE_FLOAT, size);
34         data = new float[size];
35         bankdata = new float[1][];
36         bankdata[0] = data;
37     }
38
39     /**
40      * Constructs a <code>float</code>-based <code>DataBuffer</code>
41      * with a specified number of banks, all of which are of a
42      * specified size.
43      *
44      * @param size The number of elements in each bank of the
45      * <code>DataBuffer</code>.
46      * @param numBanks The number of banks in the
47      * <code>DataBuffer</code>.
48      */

49     public DataBufferFloat(int size, int numBanks) {
50         super(TYPE_FLOAT, size, numBanks);
51         bankdata = new float[numBanks][];
52         for (int i= 0; i < numBanks; i++) {
53             bankdata[i] = new float[size];
54         }
55         data = bankdata[0];
56     }
57
58     /**
59      * Constructs a <code>float</code>-based <code>DataBuffer</code>
60      * with the specified data array. Only the first
61      * <code>size</code> elements are available for use by this
62      * <code>DataBuffer</code>. The array must be large enough to
63      * hold <code>size</code> elements.
64      *
65      * @param dataArray An array of <code>float</code>s to be used as the
66      * first and only bank of this <code>DataBuffer</code>.
67      * @param size The number of elements of the array to be used.
68      */

69     public DataBufferFloat(float dataArray[], int size) {
70         super(TYPE_FLOAT, size);
71         data = dataArray;
72         bankdata = new float[1][];
73         bankdata[0] = data;
74     }
75
76     /**
77      * Constructs a <code>float</code>-based <code>DataBuffer</code>
78      * with the specified data array. Only the elements between
79      * <code>offset</code> and <code>offset + size - 1</code> are
80      * available for use by this <code>DataBuffer</code>. The array
81      * must be large enough to hold <code>offset + size</code>
82      * elements.
83      *
84      * @param dataArray An array of <code>float</code>s to be used as the
85      * first and only bank of this <code>DataBuffer</code>.
86      * @param size The number of elements of the array to be used.
87      * @param offset The offset of the first element of the array
88      * that will be used.
89      */

90     public DataBufferFloat(float dataArray[], int size, int offset) {
91         super(TYPE_FLOAT, size, 1, offset);
92         data = dataArray;
93         bankdata = new float[1][];
94         bankdata[0] = data;
95     }
96
97     /**
98      * Constructs a <code>float</code>-based <code>DataBuffer</code>
99      * with the specified data arrays. Only the first
100      * <code>size</code> elements of each array are available for use
101      * by this <code>DataBuffer</code>. The number of banks will be
102      * equal to <code>dataArray.length</code>.
103      *
104      * @param dataArray An array of arrays of <code>float</code>s to be
105      * used as the banks of this <code>DataBuffer</code>.
106      * @param size The number of elements of each array to be used.
107      */

108     public DataBufferFloat(float dataArray[][], int size) {
109         super(TYPE_FLOAT, size, dataArray.length);
110         bankdata = (float[][]) dataArray.clone();
111         data = bankdata[0];
112     }
113
114     /**
115      * Constructs a <code>float</code>-based <code>DataBuffer</code>
116      * with the specified data arrays, size, and per-bank offsets.
117      * The number of banks is equal to <code>dataArray.length</code>.
118      * Each array must be at least as large as <code>size</code> plus the
119      * corresponding offset. There must be an entry in the offsets
120      * array for each data array.
121      *
122      * @param dataArray An array of arrays of <code>float</code>s to be
123      * used as the banks of this <code>DataBuffer</code>.
124      * @param size The number of elements of each array to be used.
125      * @param offsets An array of integer offsets, one for each bank.
126      */

127     public DataBufferFloat(float dataArray[][], int size, int offsets[]) {
128         super(TYPE_FLOAT, size,dataArray.length, offsets);
129         bankdata = (float[][]) dataArray.clone();
130         data = bankdata[0];
131     }
132
133     /**
134      * Returns the default (first) <code>float</code> data array.
135      * @return the first float data array.
136      */

137     public float[] getData() {
138         return data;
139     }
140
141     /**
142      * Returns the data array for the specified bank.
143      * @param bank the data array
144      * @return the data array specified by <code>bank</code>.
145      */

146     public float[] getData(int bank) {
147         return bankdata[bank];
148     }
149
150     /**
151      * Returns the data array for all banks.
152      * @return all data arrays for this data buffer.
153      */

154     public float[][] getBankData() {
155         return (float[][]) bankdata.clone();
156     }
157     
158     /**
159      * Returns the requested data array element from the first
160      * (default) bank as an <code>int</code>.
161      *
162      * @param i The desired data array element.
163      *
164      * @return The data entry as an <code>int</code>.
165      * @see #setElem(int, int)
166      * @see #setElem(int, int, int)
167      */

168     public int getElem(int i) {
169         return (int)(data[i+offset]);
170     }
171
172     /**
173      * Returns the requested data array element from the specified
174      * bank as an <code>int</code>.
175      *
176      * @param bank The bank number.
177      * @param i The desired data array element.
178      *
179      * @return The data entry as an <code>int</code>.
180      * @see #setElem(int, int)
181      * @see #setElem(int, int, int)
182      */

183     public int getElem(int bank, int i) {
184         return (int)(bankdata[bank][i+offsets[bank]]);
185     }
186
187     /**
188      * Sets the requested data array element in the first (default)
189      * bank to the given <code>int</code>.
190      *
191      * @param i The desired data array element.
192      * @param val The value to be set.
193      * @see #getElem(int)
194      * @see #getElem(int, int)
195      */

196     public void setElem(int i, int val) {
197         data[i+offset] = (float)val;
198     }
199
200     /**
201      * Sets the requested data array element in the specified bank to
202      * the given <code>int</code>.
203      *
204      * @param bank The bank number.
205      * @param i The desired data array element.
206      * @param val The value to be set.
207      * @see #getElem(int)
208      * @see #getElem(int, int)
209      */

210     public void setElem(int bank, int i, int val) {
211         bankdata[bank][i+offsets[bank]] = (float)val;
212     }
213
214     /**
215      * Returns the requested data array element from the first
216      * (default) bank as a <code>float</code>.
217      *
218      * @param i The desired data array element.
219      *
220      * @return The data entry as a <code>float</code>.
221      * @see #setElemFloat(int, float)
222      * @see #setElemFloat(int, int, float)
223      */

224     public float getElemFloat(int i) {
225         return data[i+offset];
226     }
227  
228     /**
229      * Returns the requested data array element from the specified
230      * bank as a <code>float</code>.
231      *
232      * @param bank The bank number.
233      * @param i The desired data array element.
234      *
235      * @return The data entry as a <code>float</code>.
236      * @see #setElemFloat(int, float)
237      * @see #setElemFloat(int, int, float)
238      */

239     public float getElemFloat(int bank, int i) {
240         return bankdata[bank][i+offsets[bank]];
241     }
242  
243     /**
244      * Sets the requested data array element in the first (default)
245      * bank to the given <code>float</code>.
246      *
247      * @param i The desired data array element.
248      * @param val The value to be set.
249      * @see #getElemFloat(int)
250      * @see #getElemFloat(int, int)
251      */

252     public void setElemFloat(int i, float val) {
253         data[i+offset] = val;
254     }
255  
256     /**
257      * Sets the requested data array element in the specified bank to
258      * the given <code>float</code>.
259      *
260      * @param bank The bank number.
261      * @param i The desired data array element.
262      * @param val The value to be set.
263      * @see #getElemFloat(int)
264      * @see #getElemFloat(int, int)
265      */

266     public void setElemFloat(int bank, int i, float val) {
267         bankdata[bank][i+offsets[bank]] = val;
268     }
269
270     /**
271      * Returns the requested data array element from the first
272      * (default) bank as a <code>double</code>.
273      *
274      * @param i The desired data array element.
275      *
276      * @return The data entry as a <code>double</code>.
277      * @see #setElemDouble(int, double)
278      * @see #setElemDouble(int, int, double)
279      */

280     public double getElemDouble(int i) {
281         return (double)data[i+offset];
282     }
283  
284     /**
285      * Returns the requested data array element from the specified
286      * bank as a <code>double</code>.
287      *
288      * @param bank The bank number.
289      * @param i The desired data array element.
290      *
291      * @return The data entry as a <code>double</code>.
292      * @see #setElemDouble(int, double)
293      * @see #setElemDouble(int, int, double)
294      */

295     public double getElemDouble(int bank, int i) {
296         return (double)bankdata[bank][i+offsets[bank]];
297     }
298  
299     /**
300      * Sets the requested data array element in the first (default)
301      * bank to the given <code>double</code>.
302      *
303      * @param i The desired data array element.
304      * @param val The value to be set.
305      * @see #getElemDouble(int)
306      * @see #getElemDouble(int, int)
307      */

308     public void setElemDouble(int i, double val) {
309         data[i+offset] = (float)val;
310     }
311  
312     /**
313      * Sets the requested data array element in the specified bank to
314      * the given <code>double</code>.
315      *
316      * @param bank The bank number.
317      * @param i The desired data array element.
318      * @param val The value to be set.
319      * @see #getElemDouble(int)
320      * @see #getElemDouble(int, int)
321      */

322     public void setElemDouble(int bank, int i, double val) {
323         bankdata[bank][i+offsets[bank]] = (float)val;
324     }
325 }
326
Popular Tags