Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / image / DataBufferInt.java
blobc90f95588117946f82be56cd440690096233cf62
1 /* Copyright (C) 2000, 2002 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)
52 public final class DataBufferInt extends DataBuffer
54 private int[] data;
55 private int[][] bankData;
57 /**
58 * Creates a new data buffer with a single data bank containing the
59 * specified number of <code>int</code> elements.
61 * @param size the number of elements in the data bank.
63 public DataBufferInt(int size)
65 super(TYPE_INT, size, 1, 0);
66 bankData = new int[1][];
67 data = new int[size];
68 bankData[0] = data;
71 /**
72 * Creates a new data buffer with the specified number of data banks,
73 * each containing the specified number of <code>int</code> elements.
75 * @param size the number of elements in the data bank.
76 * @param numBanks the number of data banks.
78 public DataBufferInt(int size, int numBanks)
80 super(TYPE_INT, size, numBanks);
81 bankData = new int[numBanks][size];
82 data = bankData[0];
85 /**
86 * Creates a new data buffer backed by the specified data bank.
87 * <p>
88 * Note: there is no exception when <code>dataArray</code> is
89 * <code>null</code>, but in that case an exception will be thrown
90 * later if you attempt to access the data buffer.
92 * @param dataArray the data bank.
93 * @param size the number of elements in the data bank.
95 public DataBufferInt(int[] dataArray, int size)
97 super(TYPE_INT, size, 1, 0);
98 bankData = new int[1][];
99 data = dataArray;
100 bankData[0] = data;
104 * Creates a new data buffer backed by the specified data bank, with
105 * the specified offset to the first element.
106 * <p>
107 * Note: there is no exception when <code>dataArray</code> is
108 * <code>null</code>, but in that case an exception will be thrown
109 * later if you attempt to access the data buffer.
111 * @param dataArray the data bank.
112 * @param size the number of elements in the data bank.
113 * @param offset the offset to the first element in the array.
115 public DataBufferInt(int[] dataArray, int size, int offset)
117 super(TYPE_INT, size, 1, offset);
118 bankData = new int[1][];
119 data = dataArray;
120 bankData[0] = data;
124 * Creates a new data buffer backed by the specified data banks.
126 * @param dataArray the data banks.
127 * @param size the number of elements in the data bank.
129 * @throws NullPointerException if <code>dataArray</code> is
130 * <code>null</code>.
132 public DataBufferInt(int[][] dataArray, int size)
134 super(TYPE_INT, size, dataArray.length);
135 bankData = dataArray;
136 data = bankData[0];
140 * Creates a new data buffer backed by the specified data banks, with
141 * the specified offsets to the first element in each bank.
143 * @param dataArray the data banks.
144 * @param size the number of elements in the data bank.
145 * @param offsets the offsets to the first element in each data bank.
147 * @throws NullPointerException if <code>dataArray</code> is
148 * <code>null</code>.
150 public DataBufferInt(int[][] dataArray, int size, int[] offsets)
152 super(TYPE_INT, size, dataArray.length, offsets);
153 bankData = dataArray;
154 data = bankData[0];
158 * Returns the first data bank.
160 * @return The first data bank.
162 public int[] getData()
164 return data;
168 * Returns a data bank.
170 * @param bank the bank index.
171 * @return A data bank.
173 public int[] getData(int bank)
175 return bankData[bank];
179 * Returns the array underlying this <code>DataBuffer</code>.
181 * @return The data banks.
183 public int[][] getBankData()
185 return bankData;
189 * Returns an element from the first data bank. The <code>offset</code> is
190 * added to the specified index before accessing the underlying data array.
192 * @param i the element index.
193 * @return The element.
195 public int getElem(int i)
197 return data[i+offset];
201 * Returns an element from a particular data bank. The <code>offset</code>
202 * is added to the specified index before accessing the underlying data
203 * array.
205 * @param bank the bank index.
206 * @param i the element index.
207 * @return The element.
209 public int getElem(int bank, int i)
211 // get unsigned int as int
212 return bankData[bank][i+offsets[bank]];
216 * Sets an element in the first data bank. The offset (specified in the
217 * constructor) is added to <code>i</code> before updating the underlying
218 * data array.
220 * @param i the element index.
221 * @param val the new element value.
223 public void setElem(int i, int val)
225 data[i+offset] = val;
229 * Sets an element in a particular data bank. The offset (specified in the
230 * constructor) is added to <code>i</code> before updating the underlying
231 * data array.
233 * @param bank the data bank index.
234 * @param i the element index.
235 * @param val the new element value.
237 public void setElem(int bank, int i, int val)
239 bankData[bank][i+offsets[bank]] = val;