home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-20 | 4.8 KB | 159 lines |
- /*
- * @(#)DataBufferByte.java 1.6 98/03/18
- *
- * Copyright 1997 by Sun Microsystems, Inc.,
- * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
- * All rights reserved.
- *
- * This software is the confidential and proprietary information
- * of Sun Microsystems, Inc. ("Confidential Information"). You
- * shall not disclose such Confidential Information and shall use
- * it only in accordance with the terms of the license agreement
- * you entered into with Sun.
- */
-
- /* ****************************************************************
- ******************************************************************
- ******************************************************************
- *** COPYRIGHT (c) Eastman Kodak Company, 1997
- *** As an unpublished work pursuant to Title 17 of the United
- *** States Code. All rights reserved.
- ******************************************************************
- ******************************************************************
- ******************************************************************/
-
- package java.awt.image;
-
- /**
- * This class extends DataBuffer and stores data internally as bytes.
- */
-
- public class DataBufferByte extends DataBuffer
- {
- /** The default data bank. */
- protected byte data[];
-
- /** All data banks */
- protected byte bankdata[][];
-
- /**
- * Construct a byte based DataBuffer with specified size.
- */
- public DataBufferByte(int size) {
- super(BYTE_DATA,size);
- data = new byte[size];
- bankdata = new byte[1][];
- bankdata[0] = data;
- }
-
- /**
- * Construct a byte based DataBuffer with specified number of
- * banks all of which are the specified size.
- */
- public DataBufferByte(int size, int numBanks) {
- super(BYTE_DATA, size, numBanks);
- bankdata = new byte[numBanks][];
- for (int i= 0; i < numBanks; i++) {
- bankdata[i] = new byte[size];
- }
- data = bankdata[0];
- }
-
- /**
- * Construct a byte based DataBuffer with the specified array.
- * Only the first size elements are available for use by
- * this databuffer. dataArray.length must be large enough to
- * hold size elements.
- */
- public DataBufferByte(byte dataArray[], int size) {
- super(BYTE_DATA,size);
- data = dataArray;
- bankdata = new byte[1][];
- bankdata[0] = data;
- }
-
- /**
- * Construct a byte based DataBuffer with the specified array, size,
- * and offset. dataArray.length must be at least as large as
- * offset + size.
- */
- public DataBufferByte(byte dataArray[], int size, int offset){
- super(BYTE_DATA,size,1,offset);
- data = dataArray;
- bankdata = new byte[1][];
- bankdata[0] = data;
- }
-
- /**
- * Construct a byte based DataBuffer with specified arrays.
- * Only the first size elements of each array are available for
- * use by this DataBuffer. The number of banks will be equal to
- * dataArray.length.
- */
- public DataBufferByte(byte dataArray[][], int size) {
- super(BYTE_DATA,size,dataArray.length);
- bankdata = dataArray;
- data = bankdata[0];
- }
-
- /**
- * Construct a byte based DataBuffer with specified arrays/size/offsets.
- * The number of banks is equal to dataArray.length. Each array must
- * be at least as large as size + the corresponding offset. There must
- * be an entry in the offset array for each dataArray entry.
- */
- public DataBufferByte(byte dataArray[][], int size, int offsets[]) {
- super(BYTE_DATA,size,dataArray.length,offsets);
- bankdata = dataArray;
- data = bankdata[0];
- }
-
- /** Return the default (first) byte data array */
- public byte[] getData() {
- return data;
- }
-
- /** Return the data array for the specified bank */
- public byte[] getData(int bank) {
- return bankdata[bank];
- }
-
- /** Return the data array for all banks */
- public byte[][] getBankData() {
- return bankdata;
- }
-
- /**
- * Returns the requested data array element from the first (default) bank
- * as an integer.
- */
- public int getElem(int i) {
- return (int)(data[i+offset]) & 0xff;
- }
-
- /**
- * Returns the requested data array element from the specified bank
- * as an integer.
- */
- public int getElem(int bank, int i) {
- return (int)(bankdata[bank][i+offsets[bank]]) & 0xff;
- }
-
- /**
- * Sets the requested data array element in the first (default) bank
- * from the given integer.
- */
- public void setElem(int i, int val) {
- data[i+offset] = (byte)val;
- }
-
- /**
- * Sets the requested data array element in the specified bank
- * from the given integer.
- */
- public void setElem(int bank, int i, int val) {
- bankdata[bank][i+offsets[bank]] = (byte)val;
- }
- }
-
-