001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Igor V. Stolyarov
019: * @version $Revision$
020: */package java.awt.image;
021:
022: import org.apache.harmony.awt.internal.nls.Messages;
023:
024: public final class DataBufferUShort extends DataBuffer {
025:
026: short data[][];
027:
028: public DataBufferUShort(short dataArrays[][], int size,
029: int offsets[]) {
030: super (TYPE_USHORT, size, dataArrays.length, offsets);
031: for (int i = 0; i < dataArrays.length; i++) {
032: if (dataArrays[i].length < offsets[i] + size) {
033: // awt.28d=Length of dataArray[{0}] is less than size + offset[{1}]
034: throw new IllegalArgumentException(Messages.getString(
035: "awt.28D", i, i)); //$NON-NLS-1$
036: }
037: }
038: data = dataArrays.clone();
039: }
040:
041: public DataBufferUShort(short dataArrays[][], int size) {
042: super (TYPE_USHORT, size, dataArrays.length);
043: data = dataArrays.clone();
044: }
045:
046: public DataBufferUShort(short dataArray[], int size, int offset) {
047: super (TYPE_USHORT, size, 1, offset);
048: if (dataArray.length < size + offset) {
049: // awt.28E=Length of dataArray is less than size + offset
050: throw new IllegalArgumentException(Messages
051: .getString("awt.28E")); //$NON-NLS-1$
052: }
053: data = new short[1][];
054: data[0] = dataArray;
055: }
056:
057: public DataBufferUShort(short dataArray[], int size) {
058: super (TYPE_USHORT, size);
059: data = new short[1][];
060: data[0] = dataArray;
061: }
062:
063: public DataBufferUShort(int size, int numBanks) {
064: super (TYPE_USHORT, size, numBanks);
065: data = new short[numBanks][];
066: int i = 0;
067: while (i < numBanks) {
068: data[i++] = new short[size];
069: }
070: }
071:
072: public DataBufferUShort(int size) {
073: super (TYPE_USHORT, size);
074: data = new short[1][];
075: data[0] = new short[size];
076: }
077:
078: @Override
079: public void setElem(int bank, int i, int val) {
080: data[bank][offsets[bank] + i] = (short) val;
081: notifyChanged();
082: }
083:
084: @Override
085: public void setElem(int i, int val) {
086: data[0][offset + i] = (short) val;
087: notifyChanged();
088: }
089:
090: @Override
091: public int getElem(int bank, int i) {
092: return (data[bank][offsets[bank] + i]) & 0xffff;
093: }
094:
095: public short[] getData(int bank) {
096: notifyTaken();
097: return data[bank];
098: }
099:
100: @Override
101: public int getElem(int i) {
102: return (data[0][offset + i]) & 0xffff;
103: }
104:
105: public short[][] getBankData() {
106: notifyTaken();
107: return data.clone();
108: }
109:
110: public short[] getData() {
111: notifyTaken();
112: return data[0];
113: }
114: }
|