| 1 | /* Copyright (C) 2000, 2002 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., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 18 | 02111-1307 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 | /**
|
|---|
| 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.
|
|---|
| 43 | *
|
|---|
| 44 | * @author Rolf W. Rasmussen <[email protected]>
|
|---|
| 45 | */
|
|---|
| 46 | public abstract class DataBuffer
|
|---|
| 47 | {
|
|---|
| 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;
|
|---|
| 55 |
|
|---|
| 56 | /** The type of the data elements stored in the data buffer. */
|
|---|
| 57 | protected int dataType;
|
|---|
| 58 |
|
|---|
| 59 | /** The number of banks in this buffer. */
|
|---|
| 60 | protected int banks = 1;
|
|---|
| 61 |
|
|---|
| 62 | /** Offset into the default (0'th) bank). */
|
|---|
| 63 | protected int offset; // FIXME: Is offsets[0] always mirrored in offset?
|
|---|
| 64 |
|
|---|
| 65 | /** The size of the banks. */
|
|---|
| 66 | protected int size;
|
|---|
| 67 |
|
|---|
| 68 | /** Offset into each bank. */
|
|---|
| 69 | protected int[] offsets;
|
|---|
| 70 |
|
|---|
| 71 | protected DataBuffer(int dataType, int size)
|
|---|
| 72 | {
|
|---|
| 73 | this.dataType = dataType;
|
|---|
| 74 | this.size = size;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | protected DataBuffer(int dataType, int size, int numBanks) {
|
|---|
| 78 | this(dataType, size);
|
|---|
| 79 | banks = numBanks;
|
|---|
| 80 | offsets = new int[numBanks];
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | protected DataBuffer(int dataType, int size, int numBanks, int offset) {
|
|---|
| 84 | this(dataType, size, numBanks);
|
|---|
| 85 |
|
|---|
| 86 | java.util.Arrays.fill(offsets, offset);
|
|---|
| 87 |
|
|---|
| 88 | this.offset = offset;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) {
|
|---|
| 92 | this(dataType, size);
|
|---|
| 93 | if (numBanks != offsets.length)
|
|---|
| 94 | throw new ArrayIndexOutOfBoundsException();
|
|---|
| 95 |
|
|---|
| 96 | banks = numBanks;
|
|---|
| 97 | this.offsets = offsets;
|
|---|
| 98 |
|
|---|
| 99 | offset = offsets[0];
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | public static int getDataTypeSize(int dataType) {
|
|---|
| 103 | // Maybe this should be a lookup table instead.
|
|---|
| 104 | switch (dataType)
|
|---|
| 105 | {
|
|---|
| 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();
|
|---|
| 118 | }
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | public int getDataType()
|
|---|
| 122 | {
|
|---|
| 123 | return dataType;
|
|---|
| 124 | }
|
|---|
| 125 |
|
|---|
| 126 | public int getSize()
|
|---|
| 127 | {
|
|---|
| 128 | return size;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | public int getOffset()
|
|---|
| 132 | {
|
|---|
| 133 | return offset;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | public int[] getOffsets()
|
|---|
| 137 | {
|
|---|
| 138 | if (offsets == null)
|
|---|
| 139 | {
|
|---|
| 140 | // is this necessary?
|
|---|
| 141 | offsets = new int[1];
|
|---|
| 142 | offsets[0] = offset;
|
|---|
| 143 | }
|
|---|
| 144 | return offsets;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | public int getNumBanks()
|
|---|
| 148 | {
|
|---|
| 149 | return banks;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | public int getElem(int i)
|
|---|
| 153 | {
|
|---|
| 154 | return getElem(0, i);
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | public abstract int getElem(int bank, int i);
|
|---|
| 158 |
|
|---|
| 159 | public void setElem(int i, int val)
|
|---|
| 160 | {
|
|---|
| 161 | setElem(0, i, val);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | public abstract void setElem(int bank, int i, int val);
|
|---|
| 165 |
|
|---|
| 166 | public float getElemFloat(int i)
|
|---|
| 167 | {
|
|---|
| 168 | return getElem(i);
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | public float getElemFloat(int bank, int i)
|
|---|
| 172 | {
|
|---|
| 173 | return getElem(bank, i);
|
|---|
| 174 | }
|
|---|
| 175 |
|
|---|
| 176 | public void setElemFloat(int i, float val)
|
|---|
| 177 | {
|
|---|
| 178 | setElem(i, (int) val);
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | public void setElemFloat(int bank, int i, float val)
|
|---|
| 182 | {
|
|---|
| 183 | setElem(bank, i, (int) val);
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | public double getElemDouble(int i)
|
|---|
| 187 | {
|
|---|
| 188 | return getElem(i);
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | public double getElemDouble(int bank, int i)
|
|---|
| 192 | {
|
|---|
| 193 | return getElem(bank, i);
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | public void setElemDouble(int i, double val)
|
|---|
| 197 | {
|
|---|
| 198 | setElem(i, (int) val);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | public void setElemDouble(int bank, int i, double val)
|
|---|
| 202 | {
|
|---|
| 203 | setElem(bank, i, (int) val);
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|