Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / image / DataBufferFloat.java
blob6b47e2be00595c9db394dcb6200021a826422624
1 /* Copyright (C) 2004 Free Software Foundation
3 This file is part of GNU Classpath.
5 GNU Classpath is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 GNU Classpath is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Classpath; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA.
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version. */
37 package java.awt.image;
39 /* This is one of several classes that are nearly identical. Maybe we
40 should have a central template and generate all these files. This
41 is one of the cases where templates or macros would have been
42 useful to have in Java.
44 This file has been created using search-replace. My only fear is
45 that these classes will grow out-of-sync as of a result of changes
46 that are not propagated to the other files. As always, mirroring
47 code is a maintenance nightmare. */
49 /**
50 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
51 * @author Sascha Brawer (brawer@dandelis.ch)
53 public final class DataBufferFloat
54 extends DataBuffer
56 private float[] data;
57 private float[][] bankData;
59 /**
60 * Creates a new data buffer with a single data bank containing the
61 * specified number of <code>float</code> elements.
63 * @param size the number of elements in the data bank.
65 public DataBufferFloat(int size)
67 super(TYPE_FLOAT, size, 1, 0);
68 bankData = new float[1][];
69 data = new float[size];
70 bankData[0] = data;
73 /**
74 * Creates a new data buffer with the specified number of data banks,
75 * each containing the specified number of <code>float</code> elements.
77 * @param size the number of elements in the data bank.
78 * @param numBanks the number of data banks.
80 public DataBufferFloat(int size, int numBanks)
82 super(TYPE_FLOAT, size, numBanks);
83 bankData = new float[numBanks][size];
84 data = bankData[0];
87 /**
88 * Creates a new data buffer backed by the specified data bank.
89 * <p>
90 * Note: there is no exception when <code>dataArray</code> is
91 * <code>null</code>, but in that case an exception will be thrown
92 * later if you attempt to access the data buffer.
94 * @param dataArray the data bank.
95 * @param size the number of elements in the data bank.
97 public DataBufferFloat(float[] dataArray, int size)
99 super(TYPE_FLOAT, size, 1, 0);
100 bankData = new float[1][];
101 data = dataArray;
102 bankData[0] = data;
106 * Creates a new data buffer backed by the specified data bank, with
107 * the specified offset to the first element.
108 * <p>
109 * Note: there is no exception when <code>dataArray</code> is
110 * <code>null</code>, but in that case an exception will be thrown
111 * later if you attempt to access the data buffer.
113 * @param dataArray the data bank.
114 * @param size the number of elements in the data bank.
115 * @param offset the offset to the first element in the array.
117 public DataBufferFloat(float[] dataArray, int size, int offset)
119 super(TYPE_FLOAT, size, 1, offset);
120 bankData = new float[1][];
121 data = dataArray;
122 bankData[0] = data;
126 * Creates a new data buffer backed by the specified data banks.
128 * @param dataArray the data banks.
129 * @param size the number of elements in the data bank.
131 * @throws NullPointerException if <code>dataArray</code> is
132 * <code>null</code>.
134 public DataBufferFloat(float[][] dataArray, int size)
136 super(TYPE_FLOAT, size, dataArray.length);
137 bankData = dataArray;
138 data = bankData[0];
142 * Creates a new data buffer backed by the specified data banks, with
143 * the specified offsets to the first element in each bank.
145 * @param dataArray the data banks.
146 * @param size the number of elements in the data bank.
147 * @param offsets the offsets to the first element in each data bank.
149 * @throws NullPointerException if <code>dataArray</code> is
150 * <code>null</code>.
152 public DataBufferFloat(float[][] dataArray, int size, int[] offsets)
154 super(TYPE_FLOAT, size, dataArray.length, offsets);
155 bankData = dataArray;
156 data = bankData[0];
160 * Returns the first data bank.
162 * @return The first data bank.
164 public float[] getData()
166 return data;
170 * Returns a data bank.
172 * @param bank the bank index.
173 * @return A data bank.
175 public float[] getData(int bank)
177 return bankData[bank];
181 * Returns the array underlying this <code>DataBuffer</code>.
183 * @return The data banks.
185 public float[][] getBankData()
187 return bankData;
191 * Returns an element from the first data bank. The offset (specified in
192 * the constructor) is added to <code>i</code> before accessing the
193 * underlying data array.
195 * @param i the element index.
196 * @return The element.
198 public int getElem(int i)
200 return (int) data[i+offset];
204 * Returns an element from a particular data bank. The offset (specified in
205 * the constructor) is added to <code>i</code> before accessing the
206 * underlying data array.
208 * @param bank the bank index.
209 * @param i the element index.
210 * @return The element.
212 public int getElem(int bank, int i)
214 return (int) bankData[bank][i+offsets[bank]];
218 * Sets an element in the first data bank. The offset (specified in the
219 * constructor) is added to <code>i</code> before updating the underlying
220 * data array.
222 * @param i the element index.
223 * @param val the new element value.
225 public void setElem(int i, int val)
227 data[i+offset] = (float) val;
231 * Sets an element in a particular data bank. The offset (specified in the
232 * constructor) is added to <code>i</code> before updating the underlying
233 * data array.
235 * @param bank the data bank index.
236 * @param i the element index.
237 * @param val the new element value.
239 public void setElem(int bank, int i, int val)
241 bankData[bank][i+offsets[bank]] = (float) val;
244 public float getElemFloat(int i)
246 return data[i+offset];
249 public float getElemFloat(int bank, int i)
251 return bankData[bank][i+offsets[bank]];
254 public void setElemFloat(int i, float val)
256 data[i+offset] = val;
259 public void setElemFloat(int bank, int i, float val)
261 bankData[bank][i+offsets[bank]] = val;
264 public double getElemDouble(int i)
266 return getElemFloat(i);
269 public double getElemDouble(int bank, int i)
271 return getElemFloat(bank, i);
274 public void setElemDouble(int i, double val)
276 setElemFloat(i, (float) val);
279 public void setElemDouble(int bank, int i, double val)
281 setElemFloat(bank, i, (float) val);