2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / image / DataBuffer.java
blob967e1a26c9cef6c0453a8bf8cc025de6cbddbe6d
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 /**
40 * Class that manages arrays of data elements. A data buffer consists
41 * of one or more banks. A bank is a continuous region of data
42 * elements.
44 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
46 public abstract class DataBuffer
48 public static final int TYPE_BYTE = 0;
49 public static final int TYPE_USHORT = 1;
50 public static final int TYPE_SHORT = 2;
51 public static final int TYPE_INT = 3;
52 public static final int TYPE_FLOAT = 4;
53 public static final int TYPE_DOUBLE = 5;
54 public static final int TYPE_UNDEFINED = 32;
56 /** The type of the data elements stored in the data buffer. */
57 protected int dataType;
59 /** The number of banks in this buffer. */
60 protected int banks = 1;
62 /** Offset into the default (0'th) bank). */
63 protected int offset; // FIXME: Is offsets[0] always mirrored in offset?
65 /** The size of the banks. */
66 protected int size;
68 /** Offset into each bank. */
69 protected int[] offsets;
71 protected DataBuffer(int dataType, int size)
73 this.dataType = dataType;
74 this.size = size;
77 protected DataBuffer(int dataType, int size, int numBanks) {
78 this(dataType, size);
79 banks = numBanks;
80 offsets = new int[numBanks];
83 protected DataBuffer(int dataType, int size, int numBanks, int offset) {
84 this(dataType, size, numBanks);
86 java.util.Arrays.fill(offsets, offset);
88 this.offset = offset;
91 protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
92 this(dataType, size);
93 if (numBanks != offsets.length)
94 throw new ArrayIndexOutOfBoundsException();
96 banks = numBanks;
97 this.offsets = offsets;
99 offset = offsets[0];
102 public static int getDataTypeSize(int dataType) {
103 // Maybe this should be a lookup table instead.
104 switch (dataType)
106 case TYPE_BYTE:
107 return 8;
108 case TYPE_USHORT:
109 case TYPE_SHORT:
110 return 16;
111 case TYPE_INT:
112 case TYPE_FLOAT:
113 return 32;
114 case TYPE_DOUBLE:
115 return 64;
116 default:
117 throw new IllegalArgumentException();
121 public int getDataType()
123 return dataType;
126 public int getSize()
128 return size;
131 public int getOffset()
133 return offset;
136 public int[] getOffsets()
138 if (offsets == null)
140 // is this necessary?
141 offsets = new int[1];
142 offsets[0] = offset;
144 return offsets;
147 public int getNumBanks()
149 return banks;
152 public int getElem(int i)
154 return getElem(0, i);
157 public abstract int getElem(int bank, int i);
159 public void setElem(int i, int val)
161 setElem(0, i, val);
164 public abstract void setElem(int bank, int i, int val);
166 public float getElemFloat(int i)
168 return getElem(i);
171 public float getElemFloat(int bank, int i)
173 return getElem(bank, i);
176 public void setElemFloat(int i, float val)
178 setElem(i, (int) val);
181 public void setElemFloat(int bank, int i, float val)
183 setElem(bank, i, (int) val);
186 public double getElemDouble(int i)
188 return getElem(i);
191 public double getElemDouble(int bank, int i)
193 return getElem(bank, i);
196 public void setElemDouble(int i, double val)
198 setElem(i, (int) val);
201 public void setElemDouble(int bank, int i, double val)
203 setElem(bank, i, (int) val);