1 7 8 17 18 package java.awt.image; 19 20 25 26 27 public final class DataBufferUShort extends DataBuffer 28 { 29 30 short data[]; 31 32 33 short bankdata[][]; 34 35 41 public DataBufferUShort(int size) { 42 super(TYPE_USHORT,size); 43 data = new short[size]; 44 bankdata = new short[1][]; 45 bankdata[0] = data; 46 } 47 48 55 public DataBufferUShort(int size, int numBanks) { 56 super(TYPE_USHORT,size,numBanks); 57 bankdata = new short[numBanks][]; 58 for (int i= 0; i < numBanks; i++) { 59 bankdata[i] = new short[size]; 60 } 61 data = bankdata[0]; 62 } 63 64 74 public DataBufferUShort(short dataArray[], int size) { 75 super(TYPE_USHORT,size); 76 if (dataArray == null) { 77 throw new NullPointerException ("dataArray is null"); 78 } 79 data = dataArray; 80 bankdata = new short[1][]; 81 bankdata[0] = data; 82 } 83 84 95 public DataBufferUShort(short dataArray[], int size, int offset) { 96 super(TYPE_USHORT,size,1,offset); 97 if (dataArray == null) { 98 throw new NullPointerException ("dataArray is null"); 99 } 100 if ((size+offset) > dataArray.length) { 101 throw new IllegalArgumentException ("Length of dataArray is less "+ 102 " than size+offset."); 103 } 104 data = dataArray; 105 bankdata = new short[1][]; 106 bankdata[0] = data; 107 } 108 109 118 public DataBufferUShort(short dataArray[][], int size) { 119 super(TYPE_USHORT,size,dataArray.length); 120 if (dataArray == null) { 121 throw new NullPointerException ("dataArray is null"); 122 } 123 for (int i=0; i < dataArray.length; i++) { 124 if (dataArray[i] == null) { 125 throw new NullPointerException ("dataArray["+i+"] is null"); 126 } 127 } 128 129 bankdata = (short[][]) dataArray.clone(); 130 data = bankdata[0]; 131 } 132 133 147 public DataBufferUShort(short dataArray[][], int size, int offsets[]) { 148 super(TYPE_USHORT,size,dataArray.length,offsets); 149 if (dataArray == null) { 150 throw new NullPointerException ("dataArray is null"); 151 } 152 for (int i=0; i < dataArray.length; i++) { 153 if (dataArray[i] == null) { 154 throw new NullPointerException ("dataArray["+i+"] is null"); 155 } 156 if ((size+offsets[i]) > dataArray[i].length) { 157 throw new IllegalArgumentException ("Length of dataArray["+i+ 158 "] is less than size+"+ 159 "offsets["+i+"]."); 160 } 161 162 } 163 bankdata = (short[][]) dataArray.clone(); 164 data = bankdata[0]; 165 } 166 167 172 public short[] getData() { 173 return data; 174 } 175 176 182 public short[] getData(int bank) { 183 return bankdata[bank]; 184 } 185 186 190 public short[][] getBankData() { 191 return (short[][]) bankdata.clone(); 192 } 193 194 202 public int getElem(int i) { 203 return (int)(data[i+offset]&0xffff); 204 } 205 206 215 public int getElem(int bank, int i) { 216 return (int)(bankdata[bank][i+offsets[bank]]&0xffff); 217 } 218 219 228 public void setElem(int i, int val) { 229 data[i+offset] = (short)(val&0xffff); 230 } 231 232 241 public void setElem(int bank, int i, int val) { 242 bankdata[bank][i+offsets[bank]] = (short)(val&0xffff); 243 } 244 } 245 | Popular Tags |