OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [java/] [awt/] [image/] [DataBufferDouble.java] - Blame information for rev 771

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 771 jeremybenn
/* Copyright (C) 2004, 2005  Free Software Foundation
2
 
3
This file is part of GNU Classpath.
4
 
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.
9
 
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.
14
 
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., 51 Franklin Street, Fifth Floor, Boston, MA
18
02110-1301 USA.
19
 
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.
24
 
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. */
36
 
37
package java.awt.image;
38
 
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.
43
 
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.  */
48
 
49
/**
50
 * A {@link DataBuffer} that uses an array of <code>double</code> primitives
51
 * to represent each of its banks.
52
 *
53
 * @since 1.4
54
 *
55
 * @author Rolf W. Rasmussen (rolfwr@ii.uib.no)
56
 * @author Sascha Brawer (brawer@dandelis.ch)
57
 */
58
public final class DataBufferDouble
59
  extends DataBuffer
60
{
61
  private double[] data;
62
  private double[][] bankData;
63
 
64
  /**
65
   * Creates a new data buffer with a single data bank containing the
66
   * specified number of <code>double</code> elements.
67
   *
68
   * @param size the number of elements in the data bank.
69
   */
70
  public DataBufferDouble(int size)
71
  {
72
    super(TYPE_DOUBLE, size, 1, 0);
73
    bankData = new double[1][];
74
    data = new double[size];
75
    bankData[0] = data;
76
  }
77
 
78
  /**
79
   * Creates a new data buffer with the specified number of data banks,
80
   * each containing the specified number of <code>double</code> elements.
81
   *
82
   * @param size the number of elements in the data bank.
83
   * @param numBanks the number of data banks.
84
   */
85
  public DataBufferDouble(int size, int numBanks)
86
  {
87
    super(TYPE_DOUBLE, size, numBanks);
88
    bankData = new double[numBanks][size];
89
    data = bankData[0];
90
  }
91
 
92
  /**
93
   * Creates a new data buffer backed by the specified data bank.
94
   * <p>
95
   * Note: there is no exception when <code>dataArray</code> is
96
   * <code>null</code>, but in that case an exception will be thrown
97
   * later if you attempt to access the data buffer.
98
   *
99
   * @param dataArray the data bank.
100
   * @param size the number of elements in the data bank.
101
   */
102
  public DataBufferDouble(double[] dataArray, int size)
103
  {
104
    super(TYPE_DOUBLE, size, 1, 0);
105
    bankData = new double[1][];
106
    data = dataArray;
107
    bankData[0] = data;
108
  }
109
 
110
  /**
111
   * Creates a new data buffer backed by the specified data bank, with
112
   * the specified offset to the first element.
113
   * <p>
114
   * Note: there is no exception when <code>dataArray</code> is
115
   * <code>null</code>, but in that case an exception will be thrown
116
   * later if you attempt to access the data buffer.
117
   *
118
   * @param dataArray the data bank.
119
   * @param size the number of elements in the data bank.
120
   * @param offset the offset to the first element in the array.
121
   */
122
  public DataBufferDouble(double[] dataArray, int size, int offset)
123
  {
124
    super(TYPE_DOUBLE, size, 1, offset);
125
    bankData = new double[1][];
126
    data = dataArray;
127
    bankData[0] = data;
128
  }
129
 
130
  /**
131
   * Creates a new data buffer backed by the specified data banks.
132
   *
133
   * @param dataArray the data banks.
134
   * @param size the number of elements in the data bank.
135
   *
136
   * @throws NullPointerException if <code>dataArray</code> is
137
   *         <code>null</code>.
138
   */
139
  public DataBufferDouble(double[][] dataArray, int size)
140
  {
141
    super(TYPE_DOUBLE, size, dataArray.length);
142
    bankData = dataArray;
143
    data = bankData[0];
144
  }
145
 
146
  /**
147
   * Creates a new data buffer backed by the specified data banks, with
148
   * the specified offsets to the first element in each bank.
149
   *
150
   * @param dataArray the data banks.
151
   * @param size the number of elements in the data bank.
152
   * @param offsets the offsets to the first element in each data bank.
153
   *
154
   * @throws NullPointerException if <code>dataArray</code> is
155
   *         <code>null</code>.
156
   */
157
  public DataBufferDouble(double[][] dataArray, int size, int[] offsets)
158
  {
159
    super(TYPE_DOUBLE, size, dataArray.length, offsets);
160
    bankData = dataArray;
161
    data = bankData[0];
162
  }
163
 
164
  /**
165
   * Returns the first data bank.
166
   *
167
   * @return The first data bank.
168
   */
169
  public double[] getData()
170
  {
171
    return data;
172
  }
173
 
174
  /**
175
   * Returns a data bank.
176
   *
177
   * @param bank the bank index.
178
   * @return A data bank.
179
   */
180
  public double[] getData(int bank)
181
  {
182
    return bankData[bank];
183
  }
184
 
185
  /**
186
   * Returns the array underlying this <code>DataBuffer</code>.
187
   *
188
   * @return The data banks.
189
   */
190
  public double[][] getBankData()
191
  {
192
    return bankData;
193
  }
194
 
195
  /**
196
   * Returns an element from the first data bank.  The offset (specified in
197
   * the constructor) is added to <code>i</code> before accessing the
198
   * underlying data array.
199
   *
200
   * @param i the element index.
201
   * @return The element.
202
   */
203
  public int getElem(int i)
204
  {
205
    return (int) data[i+offset];
206
  }
207
 
208
  /**
209
   * Returns an element from a particular data bank.  The offset (specified in
210
   * the constructor) is added to <code>i</code> before accessing the
211
   * underlying data array.
212
   *
213
   * @param bank the bank index.
214
   * @param i the element index.
215
   * @return The element.
216
   */
217
  public int getElem(int bank, int i)
218
  {
219
    return (int) bankData[bank][i+offsets[bank]];
220
  }
221
 
222
  /**
223
   * Sets an element in the first data bank.  The offset (specified in the
224
   * constructor) is added to <code>i</code> before updating the underlying
225
   * data array.
226
   *
227
   * @param i the element index.
228
   * @param val the new element value.
229
   */
230
  public void setElem(int i, int val)
231
  {
232
    data[i+offset] = val;
233
  }
234
 
235
  /**
236
   * Sets an element in a particular data bank.  The offset (specified in the
237
   * constructor) is added to <code>i</code> before updating the underlying
238
   * data array.
239
   *
240
   * @param bank the data bank index.
241
   * @param i the element index.
242
   * @param val the new element value.
243
   */
244
  public void setElem(int bank, int i, int val)
245
  {
246
    bankData[bank][i+offsets[bank]] = val;
247
  }
248
 
249
  public float getElemFloat(int i)
250
  {
251
    return (float) data[i+offset];
252
  }
253
 
254
  public float getElemFloat(int bank, int i)
255
  {
256
    return (float) bankData[bank][i+offsets[bank]];
257
  }
258
 
259
  public void setElemFloat(int i, float val)
260
  {
261
    data[i+offset] = val;
262
  }
263
 
264
  public void setElemFloat(int bank, int i, float val)
265
  {
266
    bankData[bank][i+offsets[bank]] = val;
267
  }
268
 
269
  public double getElemDouble(int i)
270
  {
271
    return data[i + offset];
272
  }
273
 
274
  public double getElemDouble(int bank, int i)
275
  {
276
    return bankData[bank][i + offsets[bank]];
277
  }
278
 
279
  public void setElemDouble(int i, double val)
280
  {
281
    data[i + offset] = val;
282
  }
283
 
284
  public void setElemDouble(int bank, int i, double val)
285
  {
286
    bankData[bank][i + offsets[bank]] = val;
287
  }
288
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.