1 /*
2 * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
157 * <p>
158 * Note that {@code DataBuffer} objects created by this constructor
159 * may be incompatible with <a href="#optimizations">performance
160 * optimizations</a> used by some implementations (such as caching
161 * an associated image in video memory).
162 *
163 * @param dataArray The unsigned-short arrays for the <CODE>DataBuffer</CODE>.
164 * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
165 */
166 public DataBufferUShort(short dataArray[][], int size) {
167 super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length);
168 if (dataArray == null) {
169 throw new NullPointerException("dataArray is null");
170 }
171 for (int i=0; i < dataArray.length; i++) {
172 if (dataArray[i] == null) {
173 throw new NullPointerException("dataArray["+i+"] is null");
174 }
175 }
176
177 bankdata = (short[][]) dataArray.clone();
178 data = bankdata[0];
179 }
180
181 /**
182 * Constructs an unsigned-short based <CODE>DataBuffer</CODE> with specified arrays,
183 * size, and offsets.
184 * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must
185 * be at least as large as <CODE>size</CODE> + the corresponding offset. There must
186 * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each
187 * bank, only elements <CODE>offset</CODE> through
188 * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
189 * used by accessors of this <CODE>DataBuffer</CODE>.
190 * <p>
191 * Note that {@code DataBuffer} objects created by this constructor
192 * may be incompatible with <a href="#optimizations">performance
193 * optimizations</a> used by some implementations (such as caching
194 * an associated image in video memory).
195 *
196 * @param dataArray The unsigned-short arrays for the <CODE>DataBuffer</CODE>.
197 * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
198 * @param offsets The offsets into each array.
199 */
200 public DataBufferUShort(short dataArray[][], int size, int offsets[]) {
201 super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length, offsets);
202 if (dataArray == null) {
203 throw new NullPointerException("dataArray is null");
204 }
205 for (int i=0; i < dataArray.length; i++) {
206 if (dataArray[i] == null) {
207 throw new NullPointerException("dataArray["+i+"] is null");
208 }
209 if ((size+offsets[i]) > dataArray[i].length) {
210 throw new IllegalArgumentException("Length of dataArray["+i+
211 "] is less than size+"+
212 "offsets["+i+"].");
213 }
214
215 }
216 bankdata = (short[][]) dataArray.clone();
217 data = bankdata[0];
218 }
219
220 /**
221 * Returns the default (first) unsigned-short data array.
222 * <p>
223 * Note that calling this method may cause this {@code DataBuffer}
224 * object to be incompatible with <a href="#optimizations">performance
225 * optimizations</a> used by some implementations (such as caching
226 * an associated image in video memory).
227 *
228 * @return The first unsigned-short data array.
229 */
230 public short[] getData() {
231 theTrackable.setUntrackable();
232 return data;
233 }
234
235 /**
236 * Returns the data array for the specified bank.
243 * @param bank The bank whose data array you want to get.
244 * @return The data array for the specified bank.
245 */
246 public short[] getData(int bank) {
247 theTrackable.setUntrackable();
248 return bankdata[bank];
249 }
250
251 /**
252 * Returns the data arrays for all banks.
253 * <p>
254 * Note that calling this method may cause this {@code DataBuffer}
255 * object to be incompatible with <a href="#optimizations">performance
256 * optimizations</a> used by some implementations (such as caching
257 * an associated image in video memory).
258 *
259 * @return All of the data arrays.
260 */
261 public short[][] getBankData() {
262 theTrackable.setUntrackable();
263 return (short[][]) bankdata.clone();
264 }
265
266 /**
267 * Returns the requested data array element from the first (default) bank.
268 *
269 * @param i The data array element you want to get.
270 * @return The requested data array element as an integer.
271 * @see #setElem(int, int)
272 * @see #setElem(int, int, int)
273 */
274 public int getElem(int i) {
275 return (int)(data[i+offset]&0xffff);
276 }
277
278 /**
279 * Returns the requested data array element from the specified bank.
280 *
281 * @param bank The bank from which you want to get a data array element.
282 * @param i The data array element you want to get.
283 * @return The requested data array element as an integer.
284 * @see #setElem(int, int)
285 * @see #setElem(int, int, int)
286 */
287 public int getElem(int bank, int i) {
288 return (int)(bankdata[bank][i+offsets[bank]]&0xffff);
289 }
290
291 /**
292 * Sets the requested data array element in the first (default) bank
293 * to the specified value.
294 *
295 * @param i The data array element you want to set.
296 * @param val The integer value to which you want to set the data array element.
297 * @see #getElem(int)
298 * @see #getElem(int, int)
299 */
300 public void setElem(int i, int val) {
301 data[i+offset] = (short)(val&0xffff);
302 theTrackable.markDirty();
303 }
304
305 /**
306 * Sets the requested data array element in the specified bank
307 * from the given integer.
308 * @param bank The bank in which you want to set the data array element.
|
1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
157 * <p>
158 * Note that {@code DataBuffer} objects created by this constructor
159 * may be incompatible with <a href="#optimizations">performance
160 * optimizations</a> used by some implementations (such as caching
161 * an associated image in video memory).
162 *
163 * @param dataArray The unsigned-short arrays for the <CODE>DataBuffer</CODE>.
164 * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
165 */
166 public DataBufferUShort(short dataArray[][], int size) {
167 super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length);
168 if (dataArray == null) {
169 throw new NullPointerException("dataArray is null");
170 }
171 for (int i=0; i < dataArray.length; i++) {
172 if (dataArray[i] == null) {
173 throw new NullPointerException("dataArray["+i+"] is null");
174 }
175 }
176
177 bankdata = dataArray.clone();
178 data = bankdata[0];
179 }
180
181 /**
182 * Constructs an unsigned-short based <CODE>DataBuffer</CODE> with specified arrays,
183 * size, and offsets.
184 * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must
185 * be at least as large as <CODE>size</CODE> + the corresponding offset. There must
186 * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each
187 * bank, only elements <CODE>offset</CODE> through
188 * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
189 * used by accessors of this <CODE>DataBuffer</CODE>.
190 * <p>
191 * Note that {@code DataBuffer} objects created by this constructor
192 * may be incompatible with <a href="#optimizations">performance
193 * optimizations</a> used by some implementations (such as caching
194 * an associated image in video memory).
195 *
196 * @param dataArray The unsigned-short arrays for the <CODE>DataBuffer</CODE>.
197 * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
198 * @param offsets The offsets into each array.
199 */
200 public DataBufferUShort(short dataArray[][], int size, int offsets[]) {
201 super(UNTRACKABLE, TYPE_USHORT, size, dataArray.length, offsets);
202 if (dataArray == null) {
203 throw new NullPointerException("dataArray is null");
204 }
205 for (int i=0; i < dataArray.length; i++) {
206 if (dataArray[i] == null) {
207 throw new NullPointerException("dataArray["+i+"] is null");
208 }
209 if ((size+offsets[i]) > dataArray[i].length) {
210 throw new IllegalArgumentException("Length of dataArray["+i+
211 "] is less than size+"+
212 "offsets["+i+"].");
213 }
214
215 }
216 bankdata = dataArray.clone();
217 data = bankdata[0];
218 }
219
220 /**
221 * Returns the default (first) unsigned-short data array.
222 * <p>
223 * Note that calling this method may cause this {@code DataBuffer}
224 * object to be incompatible with <a href="#optimizations">performance
225 * optimizations</a> used by some implementations (such as caching
226 * an associated image in video memory).
227 *
228 * @return The first unsigned-short data array.
229 */
230 public short[] getData() {
231 theTrackable.setUntrackable();
232 return data;
233 }
234
235 /**
236 * Returns the data array for the specified bank.
243 * @param bank The bank whose data array you want to get.
244 * @return The data array for the specified bank.
245 */
246 public short[] getData(int bank) {
247 theTrackable.setUntrackable();
248 return bankdata[bank];
249 }
250
251 /**
252 * Returns the data arrays for all banks.
253 * <p>
254 * Note that calling this method may cause this {@code DataBuffer}
255 * object to be incompatible with <a href="#optimizations">performance
256 * optimizations</a> used by some implementations (such as caching
257 * an associated image in video memory).
258 *
259 * @return All of the data arrays.
260 */
261 public short[][] getBankData() {
262 theTrackable.setUntrackable();
263 return bankdata.clone();
264 }
265
266 /**
267 * Returns the requested data array element from the first (default) bank.
268 *
269 * @param i The data array element you want to get.
270 * @return The requested data array element as an integer.
271 * @see #setElem(int, int)
272 * @see #setElem(int, int, int)
273 */
274 public int getElem(int i) {
275 return data[i+offset]&0xffff;
276 }
277
278 /**
279 * Returns the requested data array element from the specified bank.
280 *
281 * @param bank The bank from which you want to get a data array element.
282 * @param i The data array element you want to get.
283 * @return The requested data array element as an integer.
284 * @see #setElem(int, int)
285 * @see #setElem(int, int, int)
286 */
287 public int getElem(int bank, int i) {
288 return bankdata[bank][i+offsets[bank]]&0xffff;
289 }
290
291 /**
292 * Sets the requested data array element in the first (default) bank
293 * to the specified value.
294 *
295 * @param i The data array element you want to set.
296 * @param val The integer value to which you want to set the data array element.
297 * @see #getElem(int)
298 * @see #getElem(int, int)
299 */
300 public void setElem(int i, int val) {
301 data[i+offset] = (short)(val&0xffff);
302 theTrackable.markDirty();
303 }
304
305 /**
306 * Sets the requested data array element in the specified bank
307 * from the given integer.
308 * @param bank The bank in which you want to set the data array element.
|