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)
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
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
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. */
52 * @author <a href="mailto:rolfwr@ii.uib.no">Rolf W. Rasmussen</a>
53 * @author <a href="mailto:brawer@dandelis.ch">Sascha Brawer</a>
55 public final class DataBufferDouble
58 private double[] data;
59 private double[][] bankData;
62 * Creates a new data buffer with a single data bank containing the
63 * specified number of <code>double</code> elements.
65 * @param size the number of elements in the data bank.
67 public DataBufferDouble(int size)
69 super(TYPE_DOUBLE, size, 1, 0);
70 bankData = new double[1][];
71 data = new double[size];
76 * Creates a new data buffer with the specified number of data banks,
77 * each containing the specified number of <code>double</code> elements.
79 * @param size the number of elements in the data bank.
80 * @param numBanks the number of data banks.
82 public DataBufferDouble(int size, int numBanks)
84 super(TYPE_DOUBLE, size, numBanks);
85 bankData = new double[numBanks][size];
90 * Creates a new data buffer backed by the specified data bank.
92 * Note: there is no exception when <code>dataArray</code> is
93 * <code>null</code>, but in that case an exception will be thrown
94 * later if you attempt to access the data buffer.
96 * @param dataArray the data bank.
97 * @param size the number of elements in the data bank.
99 public DataBufferDouble(double[] dataArray, int size)
101 super(TYPE_DOUBLE, size, 1, 0);
102 bankData = new double[1][];
108 * Creates a new data buffer backed by the specified data bank, with
109 * the specified offset to the first element.
111 * Note: there is no exception when <code>dataArray</code> is
112 * <code>null</code>, but in that case an exception will be thrown
113 * later if you attempt to access the data buffer.
115 * @param dataArray the data bank.
116 * @param size the number of elements in the data bank.
117 * @param offset the offset to the first element in the array.
119 public DataBufferDouble(double[] dataArray, int size, int offset)
121 super(TYPE_DOUBLE, size, 1, offset);
122 bankData = new double[1][];
128 * Creates a new data buffer backed by the specified data banks.
130 * @param dataArray the data banks.
131 * @param size the number of elements in the data bank.
133 * @throws NullPointerException if <code>dataArray</code> is
136 public DataBufferDouble(double[][] dataArray, int size)
138 super(TYPE_DOUBLE, size, dataArray.length);
139 bankData = dataArray;
144 * Creates a new data buffer backed by the specified data banks, with
145 * the specified offsets to the first element in each bank.
147 * @param dataArray the data banks.
148 * @param size the number of elements in the data bank.
149 * @param offsets the offsets to the first element in each data bank.
151 * @throws NullPointerException if <code>dataArray</code> is
154 public DataBufferDouble(double[][] dataArray, int size, int[] offsets)
156 super(TYPE_DOUBLE, size, dataArray.length, offsets);
157 bankData = dataArray;
162 * Returns the first data bank.
164 * @return The first data bank.
166 public double[] getData()
172 * Returns a data bank.
174 * @param bank the bank index.
175 * @return A data bank.
177 public double[] getData(int bank)
179 return bankData[bank];
183 * Returns the array underlying this <code>DataBuffer</code>.
185 * @return The data banks.
187 public double[][] getBankData()
193 * Returns an element from the first data bank. The offset (specified in
194 * the constructor) is added to <code>i</code> before accessing the
195 * underlying data array.
197 * @param i the element index.
198 * @return The element.
200 public int getElem(int i)
202 return (int) data[i+offset];
206 * Returns an element from a particular data bank. The offset (specified in
207 * the constructor) is added to <code>i</code> before accessing the
208 * underlying data array.
210 * @param bank the bank index.
211 * @param i the element index.
212 * @return The element.
214 public int getElem(int bank, int i)
216 return (int) bankData[bank][i+offsets[bank]];
220 * Sets an element in the first data bank. The offset (specified in the
221 * constructor) is added to <code>i</code> before updating the underlying
224 * @param i the element index.
225 * @param val the new element value.
227 public void setElem(int i, int val)
229 data[i+offset] = (double) val;
233 * Sets an element in a particular data bank. The offset (specified in the
234 * constructor) is added to <code>i</code> before updating the underlying
237 * @param bank the data bank index.
238 * @param i the element index.
239 * @param val the new element value.
241 public void setElem(int bank, int i, int val)
243 bankData[bank][i+offsets[bank]] = (double) val;
246 public float getElemFloat(int i)
248 return (float) data[i+offset];
251 public float getElemFloat(int bank, int i)
253 return (float) bankData[bank][i+offsets[bank]];
256 public void setElemFloat(int i, float val)
258 data[i+offset] = val;
261 public void setElemFloat(int bank, int i, float val)
263 bankData[bank][i+offsets[bank]] = val;
266 public double getElemDouble(int i)
268 return data[i + offset];
271 public double getElemDouble(int bank, int i)
273 return bankData[bank][i + offsets[bank]];
276 public void setElemDouble(int i, double val)
278 data[i + offset] = val;
281 public void setElemDouble(int bank, int i, double val)
283 bankData[bank][i + offsets[bank]] = val;