Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / image / DataBufferUShort.java
blob7466d8579564e15935ed369920cbee003d823011
1 /* DataBufferUShort.java --
2 Copyright (C) 2000, 2002, 2004 Free Software Foundation
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.awt.image;
40 /* This is one of several classes that are nearly identical. Maybe we
41 should have a central template and generate all these files. This
42 is one of the cases where templates or macros would have been
43 useful to have in Java.
45 This file has been created using search-replace. My only fear is
46 that these classes will grow out-of-sync as of a result of changes
47 that are not propagated to the other files. As always, mirroring
48 code is a maintenance nightmare. */
50 /**
51 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
53 public final class DataBufferUShort extends DataBuffer
55 private short[] data;
56 private short[][] bankData;
58 /**
59 * Creates a new data buffer with a single data bank containing the
60 * specified number of <code>short</code> elements.
62 * @param size the number of elements in the data bank.
64 public DataBufferUShort(int size)
66 super(TYPE_USHORT, size, 1, 0);
67 bankData = new short[1][];
68 data = new short[size];
69 bankData[0] = data;
72 /**
73 * Creates a new data buffer with the specified number of data banks,
74 * each containing the specified number of <code>short</code> elements.
76 * @param size the number of elements in the data bank.
77 * @param numBanks the number of data banks.
79 public DataBufferUShort(int size, int numBanks)
81 super(TYPE_USHORT, size, numBanks);
82 bankData = new short[numBanks][size];
83 data = bankData[0];
86 /**
87 * Creates a new data buffer backed by the specified data bank.
89 * @param dataArray the data bank.
90 * @param size the number of elements in the data bank.
92 * @throws NullPointerException if dataArray is null
94 public DataBufferUShort(short[] dataArray, int size)
96 super(TYPE_USHORT, size, 1, 0);
97 if (dataArray == null)
98 throw new NullPointerException();
99 bankData = new short[1][];
100 data = dataArray;
101 bankData[0] = data;
105 * Creates a new data buffer backed by the specified data bank, with
106 * the specified offset to the first element.
108 * @param dataArray the data bank.
109 * @param size the number of elements in the data bank.
110 * @param offset the offset to the first element in the array.
112 * @throws NullPointerException if dataArray is null
114 public DataBufferUShort(short[] dataArray, int size, int offset)
116 super(TYPE_USHORT, size, 1, offset);
117 if (dataArray == null)
118 throw new NullPointerException();
119 bankData = new short[1][];
120 data = dataArray;
121 bankData[0] = data;
125 * Creates a new data buffer backed by the specified data banks.
127 * @param dataArray the data banks.
128 * @param size the number of elements in the data bank.
130 * @throws NullPointerException if <code>dataArray</code> is
131 * <code>null</code>.
133 public DataBufferUShort(short[][] dataArray, int size)
135 super(TYPE_USHORT, size, dataArray.length);
136 bankData = dataArray;
137 data = bankData[0];
141 * Creates a new data buffer backed by the specified data banks, with
142 * the specified offsets to the first element in each bank.
144 * @param dataArray the data banks.
145 * @param size the number of elements in the data bank.
146 * @param offsets the offsets to the first element in each data bank.
148 * @throws NullPointerException if <code>dataArray</code> is
149 * <code>null</code>.
151 public DataBufferUShort(short[][] dataArray, int size, int[] offsets)
153 super(TYPE_USHORT, size, dataArray.length, offsets);
154 bankData = dataArray;
155 data = bankData[0];
159 * Returns the first data bank.
161 * @return The first data bank.
163 public short[] getData()
165 return data;
169 * Returns a data bank.
171 * @param bank the bank index.
172 * @return A data bank.
174 public short[] getData(int bank)
176 return bankData[bank];
180 * Returns the array underlying this <code>DataBuffer</code>.
182 * @return The data banks.
184 public short[][] getBankData()
186 return bankData;
190 * Returns an element from the first data bank. The offset (specified in
191 * the constructor) is added to <code>i</code> before accessing the
192 * underlying data array.
194 * @param i the element index.
195 * @return The element.
197 public int getElem(int i)
199 return data[i+offset] & 0xffff; // get unsigned short as int
203 * Returns an element from a particular data bank. The offset (specified in
204 * the constructor) is added to <code>i</code> before accessing the
205 * underlying data array.
207 * @param bank the bank index.
208 * @param i the element index.
209 * @return The element.
211 public int getElem(int bank, int i)
213 // get unsigned short as int
214 return bankData[bank][i+offsets[bank]] & 0xffff;
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] = (short) 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]] = (short) val;