author | tvaleev |
Thu, 04 Oct 2018 12:40:55 -0700 | |
changeset 52248 | 2e330da7cbf4 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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 |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.awt.image; |
|
27 |
||
28 |
import static sun.java2d.StateTrackable.State.*; |
|
29 |
||
30 |
/** |
|
35667 | 31 |
* This class extends {@code DataBuffer} and stores data internally |
32 |
* in {@code float} form. |
|
2 | 33 |
* <p> |
45025 | 34 |
* <a id="optimizations"> |
2 | 35 |
* Note that some implementations may function more efficiently |
36 |
* if they can maintain control over how the data for an image is |
|
37 |
* stored. |
|
38 |
* For example, optimizations such as caching an image in video |
|
39 |
* memory require that the implementation track all modifications |
|
40 |
* to that data. |
|
41 |
* Other implementations may operate better if they can store the |
|
42 |
* data in locations other than a Java array. |
|
43 |
* To maintain optimum compatibility with various optimizations |
|
44 |
* it is best to avoid constructors and methods which expose the |
|
45 |
* underlying storage as a Java array as noted below in the |
|
46 |
* documentation for those methods. |
|
47 |
* </a> |
|
48 |
* |
|
49 |
* @since 1.4 |
|
50 |
*/ |
|
51 |
||
52 |
public final class DataBufferFloat extends DataBuffer { |
|
53 |
||
54 |
/** The array of data banks. */ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
55 |
float[][] bankdata; |
2 | 56 |
|
57 |
/** A reference to the default data bank. */ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
58 |
float[] data; |
2 | 59 |
|
60 |
/** |
|
35667 | 61 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 62 |
* with a specified size. |
63 |
* |
|
64 |
* @param size The number of elements in the DataBuffer. |
|
65 |
*/ |
|
66 |
public DataBufferFloat(int size) { |
|
67 |
super(STABLE, TYPE_FLOAT, size); |
|
68 |
data = new float[size]; |
|
69 |
bankdata = new float[1][]; |
|
70 |
bankdata[0] = data; |
|
71 |
} |
|
72 |
||
73 |
/** |
|
35667 | 74 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 75 |
* with a specified number of banks, all of which are of a |
76 |
* specified size. |
|
77 |
* |
|
78 |
* @param size The number of elements in each bank of the |
|
35667 | 79 |
* {@code DataBuffer}. |
2 | 80 |
* @param numBanks The number of banks in the |
35667 | 81 |
* {@code DataBuffer}. |
2 | 82 |
*/ |
83 |
public DataBufferFloat(int size, int numBanks) { |
|
84 |
super(STABLE, TYPE_FLOAT, size, numBanks); |
|
85 |
bankdata = new float[numBanks][]; |
|
86 |
for (int i= 0; i < numBanks; i++) { |
|
87 |
bankdata[i] = new float[size]; |
|
88 |
} |
|
89 |
data = bankdata[0]; |
|
90 |
} |
|
91 |
||
92 |
/** |
|
35667 | 93 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 94 |
* with the specified data array. Only the first |
35667 | 95 |
* {@code size} elements are available for use by this |
96 |
* {@code DataBuffer}. The array must be large enough to |
|
97 |
* hold {@code size} elements. |
|
2 | 98 |
* <p> |
99 |
* Note that {@code DataBuffer} objects created by this constructor |
|
100 |
* may be incompatible with <a href="#optimizations">performance |
|
101 |
* optimizations</a> used by some implementations (such as caching |
|
102 |
* an associated image in video memory). |
|
103 |
* |
|
35667 | 104 |
* @param dataArray An array of {@code float}s to be used as the |
105 |
* first and only bank of this {@code DataBuffer}. |
|
2 | 106 |
* @param size The number of elements of the array to be used. |
107 |
*/ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
108 |
public DataBufferFloat(float[] dataArray, int size) { |
2 | 109 |
super(UNTRACKABLE, TYPE_FLOAT, size); |
110 |
data = dataArray; |
|
111 |
bankdata = new float[1][]; |
|
112 |
bankdata[0] = data; |
|
113 |
} |
|
114 |
||
115 |
/** |
|
35667 | 116 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 117 |
* with the specified data array. Only the elements between |
35667 | 118 |
* {@code offset} and {@code offset + size - 1} are |
119 |
* available for use by this {@code DataBuffer}. The array |
|
120 |
* must be large enough to hold {@code offset + size} |
|
2 | 121 |
* elements. |
122 |
* <p> |
|
123 |
* Note that {@code DataBuffer} objects created by this constructor |
|
124 |
* may be incompatible with <a href="#optimizations">performance |
|
125 |
* optimizations</a> used by some implementations (such as caching |
|
126 |
* an associated image in video memory). |
|
127 |
* |
|
35667 | 128 |
* @param dataArray An array of {@code float}s to be used as the |
129 |
* first and only bank of this {@code DataBuffer}. |
|
2 | 130 |
* @param size The number of elements of the array to be used. |
131 |
* @param offset The offset of the first element of the array |
|
132 |
* that will be used. |
|
133 |
*/ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
134 |
public DataBufferFloat(float[] dataArray, int size, int offset) { |
2 | 135 |
super(UNTRACKABLE, TYPE_FLOAT, size, 1, offset); |
136 |
data = dataArray; |
|
137 |
bankdata = new float[1][]; |
|
138 |
bankdata[0] = data; |
|
139 |
} |
|
140 |
||
141 |
/** |
|
35667 | 142 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 143 |
* with the specified data arrays. Only the first |
35667 | 144 |
* {@code size} elements of each array are available for use |
145 |
* by this {@code DataBuffer}. The number of banks will be |
|
146 |
* equal to {@code dataArray.length}. |
|
2 | 147 |
* <p> |
148 |
* Note that {@code DataBuffer} objects created by this constructor |
|
149 |
* may be incompatible with <a href="#optimizations">performance |
|
150 |
* optimizations</a> used by some implementations (such as caching |
|
151 |
* an associated image in video memory). |
|
152 |
* |
|
35667 | 153 |
* @param dataArray An array of arrays of {@code float}s to be |
154 |
* used as the banks of this {@code DataBuffer}. |
|
2 | 155 |
* @param size The number of elements of each array to be used. |
156 |
*/ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
157 |
public DataBufferFloat(float[][] dataArray, int size) { |
2 | 158 |
super(UNTRACKABLE, TYPE_FLOAT, size, dataArray.length); |
22584 | 159 |
bankdata = dataArray.clone(); |
2 | 160 |
data = bankdata[0]; |
161 |
} |
|
162 |
||
163 |
/** |
|
35667 | 164 |
* Constructs a {@code float}-based {@code DataBuffer} |
2 | 165 |
* with the specified data arrays, size, and per-bank offsets. |
35667 | 166 |
* The number of banks is equal to {@code dataArray.length}. |
167 |
* Each array must be at least as large as {@code size} plus the |
|
2 | 168 |
* corresponding offset. There must be an entry in the offsets |
169 |
* array for each data array. |
|
170 |
* <p> |
|
171 |
* Note that {@code DataBuffer} objects created by this constructor |
|
172 |
* may be incompatible with <a href="#optimizations">performance |
|
173 |
* optimizations</a> used by some implementations (such as caching |
|
174 |
* an associated image in video memory). |
|
175 |
* |
|
35667 | 176 |
* @param dataArray An array of arrays of {@code float}s to be |
177 |
* used as the banks of this {@code DataBuffer}. |
|
2 | 178 |
* @param size The number of elements of each array to be used. |
179 |
* @param offsets An array of integer offsets, one for each bank. |
|
180 |
*/ |
|
52248
2e330da7cbf4
8211300: Convert C-style array declarations in JDK client code
tvaleev
parents:
47216
diff
changeset
|
181 |
public DataBufferFloat(float[][] dataArray, int size, int[] offsets) { |
2 | 182 |
super(UNTRACKABLE, TYPE_FLOAT, size,dataArray.length, offsets); |
22584 | 183 |
bankdata = dataArray.clone(); |
2 | 184 |
data = bankdata[0]; |
185 |
} |
|
186 |
||
187 |
/** |
|
35667 | 188 |
* Returns the default (first) {@code float} data array. |
2 | 189 |
* <p> |
190 |
* Note that calling this method may cause this {@code DataBuffer} |
|
191 |
* object to be incompatible with <a href="#optimizations">performance |
|
192 |
* optimizations</a> used by some implementations (such as caching |
|
193 |
* an associated image in video memory). |
|
194 |
* |
|
195 |
* @return the first float data array. |
|
196 |
*/ |
|
197 |
public float[] getData() { |
|
198 |
theTrackable.setUntrackable(); |
|
199 |
return data; |
|
200 |
} |
|
201 |
||
202 |
/** |
|
203 |
* Returns the data array for the specified bank. |
|
204 |
* <p> |
|
205 |
* Note that calling this method may cause this {@code DataBuffer} |
|
206 |
* object to be incompatible with <a href="#optimizations">performance |
|
207 |
* optimizations</a> used by some implementations (such as caching |
|
208 |
* an associated image in video memory). |
|
209 |
* |
|
210 |
* @param bank the data array |
|
35667 | 211 |
* @return the data array specified by {@code bank}. |
2 | 212 |
*/ |
213 |
public float[] getData(int bank) { |
|
214 |
theTrackable.setUntrackable(); |
|
215 |
return bankdata[bank]; |
|
216 |
} |
|
217 |
||
218 |
/** |
|
219 |
* Returns the data array for all banks. |
|
220 |
* <p> |
|
221 |
* Note that calling this method may cause this {@code DataBuffer} |
|
222 |
* object to be incompatible with <a href="#optimizations">performance |
|
223 |
* optimizations</a> used by some implementations (such as caching |
|
224 |
* an associated image in video memory). |
|
225 |
* |
|
226 |
* @return all data arrays for this data buffer. |
|
227 |
*/ |
|
228 |
public float[][] getBankData() { |
|
229 |
theTrackable.setUntrackable(); |
|
22584 | 230 |
return bankdata.clone(); |
2 | 231 |
} |
232 |
||
233 |
/** |
|
234 |
* Returns the requested data array element from the first |
|
35667 | 235 |
* (default) bank as an {@code int}. |
2 | 236 |
* |
237 |
* @param i The desired data array element. |
|
238 |
* |
|
35667 | 239 |
* @return The data entry as an {@code int}. |
2 | 240 |
* @see #setElem(int, int) |
241 |
* @see #setElem(int, int, int) |
|
242 |
*/ |
|
243 |
public int getElem(int i) { |
|
244 |
return (int)(data[i+offset]); |
|
245 |
} |
|
246 |
||
247 |
/** |
|
248 |
* Returns the requested data array element from the specified |
|
35667 | 249 |
* bank as an {@code int}. |
2 | 250 |
* |
251 |
* @param bank The bank number. |
|
252 |
* @param i The desired data array element. |
|
253 |
* |
|
35667 | 254 |
* @return The data entry as an {@code int}. |
2 | 255 |
* @see #setElem(int, int) |
256 |
* @see #setElem(int, int, int) |
|
257 |
*/ |
|
258 |
public int getElem(int bank, int i) { |
|
259 |
return (int)(bankdata[bank][i+offsets[bank]]); |
|
260 |
} |
|
261 |
||
262 |
/** |
|
263 |
* Sets the requested data array element in the first (default) |
|
35667 | 264 |
* bank to the given {@code int}. |
2 | 265 |
* |
266 |
* @param i The desired data array element. |
|
267 |
* @param val The value to be set. |
|
268 |
* @see #getElem(int) |
|
269 |
* @see #getElem(int, int) |
|
270 |
*/ |
|
271 |
public void setElem(int i, int val) { |
|
272 |
data[i+offset] = (float)val; |
|
273 |
theTrackable.markDirty(); |
|
274 |
} |
|
275 |
||
276 |
/** |
|
277 |
* Sets the requested data array element in the specified bank to |
|
35667 | 278 |
* the given {@code int}. |
2 | 279 |
* |
280 |
* @param bank The bank number. |
|
281 |
* @param i The desired data array element. |
|
282 |
* @param val The value to be set. |
|
283 |
* @see #getElem(int) |
|
284 |
* @see #getElem(int, int) |
|
285 |
*/ |
|
286 |
public void setElem(int bank, int i, int val) { |
|
287 |
bankdata[bank][i+offsets[bank]] = (float)val; |
|
288 |
theTrackable.markDirty(); |
|
289 |
} |
|
290 |
||
291 |
/** |
|
292 |
* Returns the requested data array element from the first |
|
35667 | 293 |
* (default) bank as a {@code float}. |
2 | 294 |
* |
295 |
* @param i The desired data array element. |
|
296 |
* |
|
35667 | 297 |
* @return The data entry as a {@code float}. |
2 | 298 |
* @see #setElemFloat(int, float) |
299 |
* @see #setElemFloat(int, int, float) |
|
300 |
*/ |
|
301 |
public float getElemFloat(int i) { |
|
302 |
return data[i+offset]; |
|
303 |
} |
|
304 |
||
305 |
/** |
|
306 |
* Returns the requested data array element from the specified |
|
35667 | 307 |
* bank as a {@code float}. |
2 | 308 |
* |
309 |
* @param bank The bank number. |
|
310 |
* @param i The desired data array element. |
|
311 |
* |
|
35667 | 312 |
* @return The data entry as a {@code float}. |
2 | 313 |
* @see #setElemFloat(int, float) |
314 |
* @see #setElemFloat(int, int, float) |
|
315 |
*/ |
|
316 |
public float getElemFloat(int bank, int i) { |
|
317 |
return bankdata[bank][i+offsets[bank]]; |
|
318 |
} |
|
319 |
||
320 |
/** |
|
321 |
* Sets the requested data array element in the first (default) |
|
35667 | 322 |
* bank to the given {@code float}. |
2 | 323 |
* |
324 |
* @param i The desired data array element. |
|
325 |
* @param val The value to be set. |
|
326 |
* @see #getElemFloat(int) |
|
327 |
* @see #getElemFloat(int, int) |
|
328 |
*/ |
|
329 |
public void setElemFloat(int i, float val) { |
|
330 |
data[i+offset] = val; |
|
331 |
theTrackable.markDirty(); |
|
332 |
} |
|
333 |
||
334 |
/** |
|
335 |
* Sets the requested data array element in the specified bank to |
|
35667 | 336 |
* the given {@code float}. |
2 | 337 |
* |
338 |
* @param bank The bank number. |
|
339 |
* @param i The desired data array element. |
|
340 |
* @param val The value to be set. |
|
341 |
* @see #getElemFloat(int) |
|
342 |
* @see #getElemFloat(int, int) |
|
343 |
*/ |
|
344 |
public void setElemFloat(int bank, int i, float val) { |
|
345 |
bankdata[bank][i+offsets[bank]] = val; |
|
346 |
theTrackable.markDirty(); |
|
347 |
} |
|
348 |
||
349 |
/** |
|
350 |
* Returns the requested data array element from the first |
|
35667 | 351 |
* (default) bank as a {@code double}. |
2 | 352 |
* |
353 |
* @param i The desired data array element. |
|
354 |
* |
|
35667 | 355 |
* @return The data entry as a {@code double}. |
2 | 356 |
* @see #setElemDouble(int, double) |
357 |
* @see #setElemDouble(int, int, double) |
|
358 |
*/ |
|
359 |
public double getElemDouble(int i) { |
|
360 |
return (double)data[i+offset]; |
|
361 |
} |
|
362 |
||
363 |
/** |
|
364 |
* Returns the requested data array element from the specified |
|
35667 | 365 |
* bank as a {@code double}. |
2 | 366 |
* |
367 |
* @param bank The bank number. |
|
368 |
* @param i The desired data array element. |
|
369 |
* |
|
35667 | 370 |
* @return The data entry as a {@code double}. |
2 | 371 |
* @see #setElemDouble(int, double) |
372 |
* @see #setElemDouble(int, int, double) |
|
373 |
*/ |
|
374 |
public double getElemDouble(int bank, int i) { |
|
375 |
return (double)bankdata[bank][i+offsets[bank]]; |
|
376 |
} |
|
377 |
||
378 |
/** |
|
379 |
* Sets the requested data array element in the first (default) |
|
35667 | 380 |
* bank to the given {@code double}. |
2 | 381 |
* |
382 |
* @param i The desired data array element. |
|
383 |
* @param val The value to be set. |
|
384 |
* @see #getElemDouble(int) |
|
385 |
* @see #getElemDouble(int, int) |
|
386 |
*/ |
|
387 |
public void setElemDouble(int i, double val) { |
|
388 |
data[i+offset] = (float)val; |
|
389 |
theTrackable.markDirty(); |
|
390 |
} |
|
391 |
||
392 |
/** |
|
393 |
* Sets the requested data array element in the specified bank to |
|
35667 | 394 |
* the given {@code double}. |
2 | 395 |
* |
396 |
* @param bank The bank number. |
|
397 |
* @param i The desired data array element. |
|
398 |
* @param val The value to be set. |
|
399 |
* @see #getElemDouble(int) |
|
400 |
* @see #getElemDouble(int, int) |
|
401 |
*/ |
|
402 |
public void setElemDouble(int bank, int i, double val) { |
|
403 |
bankdata[bank][i+offsets[bank]] = (float)val; |
|
404 |
theTrackable.markDirty(); |
|
405 |
} |
|
406 |
} |