KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)DataBufferDouble.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>double</code> form.
13  *
14  * @see DataBuffer
15  * @since 1.4
16  */

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

32     public DataBufferDouble(int size) {
33         super(TYPE_DOUBLE, size);
34         data = new double[size];
35         bankdata = new double[1][];
36         bankdata[0] = data;
37     }
38
39     /**
40      * Constructs a <code>double</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 <code>DataBuffer</code>.
47      */

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

319     public void setElemDouble(int bank, int i, double val) {
320         bankdata[bank][i+offsets[bank]] = val;
321     }
322 }
323
Popular Tags