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: public final class DataBufferByte extends DataBuffer {
023:
024: byte data[][];
025:
026: public DataBufferByte(byte dataArrays[][], int size, int offsets[]) {
027: super (TYPE_BYTE, size, dataArrays.length, offsets);
028: data = dataArrays.clone();
029: }
030:
031: public DataBufferByte(byte dataArrays[][], int size) {
032: super (TYPE_BYTE, size, dataArrays.length);
033: data = dataArrays.clone();
034: }
035:
036: public DataBufferByte(byte dataArray[], int size, int offset) {
037: super (TYPE_BYTE, size, 1, offset);
038: data = new byte[1][];
039: data[0] = dataArray;
040: }
041:
042: public DataBufferByte(byte dataArray[], int size) {
043: super (TYPE_BYTE, size);
044: data = new byte[1][];
045: data[0] = dataArray;
046: }
047:
048: public DataBufferByte(int size, int numBanks) {
049: super (TYPE_BYTE, size, numBanks);
050: data = new byte[numBanks][];
051: int i = 0;
052: while (i < numBanks) {
053: data[i++] = new byte[size];
054: }
055: }
056:
057: public DataBufferByte(int size) {
058: super (TYPE_BYTE, size);
059: data = new byte[1][];
060: data[0] = new byte[size];
061: }
062:
063: @Override
064: public void setElem(int bank, int i, int val) {
065: data[bank][offsets[bank] + i] = (byte) val;
066: notifyChanged();
067: }
068:
069: @Override
070: public void setElem(int i, int val) {
071: data[0][offset + i] = (byte) val;
072: notifyChanged();
073: }
074:
075: @Override
076: public int getElem(int bank, int i) {
077: return (data[bank][offsets[bank] + i]) & 0xff;
078: }
079:
080: public byte[] getData(int bank) {
081: notifyTaken();
082: return data[bank];
083: }
084:
085: @Override
086: public int getElem(int i) {
087: return (data[0][offset + i]) & 0xff;
088: }
089:
090: public byte[][] getBankData() {
091: notifyTaken();
092: return data.clone();
093: }
094:
095: public byte[] getData() {
096: notifyTaken();
097: return data[0];
098: }
099:
100: }
|