home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / image / DataBufferByte.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.8 KB  |  159 lines

  1. /*
  2.  * @(#)DataBufferByte.java    1.6 98/03/18
  3.  *
  4.  * Copyright 1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /* ****************************************************************
  16.  ******************************************************************
  17.  ******************************************************************
  18.  *** COPYRIGHT (c) Eastman Kodak Company, 1997
  19.  *** As  an unpublished  work pursuant to Title 17 of the United
  20.  *** States Code.  All rights reserved.
  21.  ******************************************************************
  22.  ******************************************************************
  23.  ******************************************************************/
  24.  
  25. package java.awt.image;
  26.  
  27. /**
  28.  * This class extends DataBuffer and stores data internally as bytes.
  29.  */
  30.  
  31. public class DataBufferByte extends DataBuffer
  32. {
  33.     /** The default data bank. */
  34.     protected byte data[];
  35.  
  36.     /** All data banks */
  37.     protected byte bankdata[][];
  38.  
  39.     /**
  40.      * Construct a byte based DataBuffer with specified size.
  41.      */
  42.     public DataBufferByte(int size) {
  43.       super(BYTE_DATA,size);
  44.       data = new byte[size];
  45.       bankdata = new byte[1][];
  46.       bankdata[0] = data;
  47.     }
  48.   
  49.     /**
  50.      * Construct a byte based DataBuffer with specified number of
  51.      * banks all of which are the specified size.
  52.      */
  53.     public DataBufferByte(int size, int numBanks) {
  54.         super(BYTE_DATA, size, numBanks);
  55.         bankdata = new byte[numBanks][];
  56.         for (int i= 0; i < numBanks; i++) {
  57.             bankdata[i] = new byte[size];
  58.         }
  59.         data = bankdata[0];
  60.     }
  61.  
  62.     /**
  63.      * Construct a byte based DataBuffer with the specified array.
  64.      * Only the first size elements are available for use by
  65.      * this databuffer.  dataArray.length must be large enough to
  66.      * hold size elements.
  67.      */
  68.     public DataBufferByte(byte dataArray[], int size) {
  69.         super(BYTE_DATA,size);
  70.         data = dataArray;
  71.         bankdata = new byte[1][];
  72.         bankdata[0] = data;
  73.     }
  74.  
  75.     /**
  76.      * Construct a byte based DataBuffer with the specified array, size,
  77.      * and offset.  dataArray.length must be at least as large as
  78.      * offset + size.
  79.      */
  80.     public DataBufferByte(byte dataArray[], int size, int offset){
  81.         super(BYTE_DATA,size,1,offset);
  82.         data = dataArray;
  83.         bankdata = new byte[1][];
  84.         bankdata[0] = data;
  85.     }
  86.  
  87.     /**
  88.      * Construct a byte based DataBuffer with specified arrays.
  89.      * Only the first size elements of each array are available for
  90.      * use by this DataBuffer.  The number of banks will be equal to 
  91.      * dataArray.length.
  92.      */
  93.     public DataBufferByte(byte dataArray[][], int size) {
  94.         super(BYTE_DATA,size,dataArray.length);
  95.         bankdata = dataArray;
  96.         data = bankdata[0];
  97.     }
  98.  
  99.     /**
  100.      * Construct a byte based DataBuffer with specified arrays/size/offsets.
  101.      * The number of banks is equal to dataArray.length.  Each array must
  102.      * be at least as large as size + the corresponding offset.   There must
  103.      * be an entry in the offset array for each dataArray entry.
  104.      */
  105.     public DataBufferByte(byte dataArray[][], int size, int offsets[]) {
  106.         super(BYTE_DATA,size,dataArray.length,offsets);
  107.         bankdata = dataArray;
  108.         data = bankdata[0];
  109.     }
  110.  
  111.     /** Return the default (first) byte data array */
  112.     public byte[] getData() {
  113.         return data;
  114.     }
  115.  
  116.     /** Return the data array for the specified bank */
  117.     public byte[] getData(int bank) {
  118.         return bankdata[bank];
  119.     }
  120.  
  121.     /** Return the data array for all banks */
  122.     public byte[][] getBankData() {
  123.        return bankdata;
  124.     }
  125.  
  126.     /**
  127.      * Returns the requested data array element from the first (default) bank
  128.      * as an integer.
  129.      */
  130.     public int getElem(int i) {
  131.         return (int)(data[i+offset]) & 0xff;
  132.     }
  133.  
  134.     /**
  135.      * Returns the requested data array element from the specified bank
  136.      * as an integer.
  137.      */
  138.     public int getElem(int bank, int i) {
  139.         return (int)(bankdata[bank][i+offsets[bank]]) & 0xff;
  140.     }
  141.  
  142.     /**
  143.      * Sets the requested data array element in the first (default) bank 
  144.      * from the given integer.
  145.      */
  146.     public void setElem(int i, int val) {
  147.         data[i+offset] = (byte)val;
  148.     }
  149.  
  150.     /**
  151.      * Sets the requested data array element in the specified bank 
  152.      * from the given integer.
  153.      */
  154.     public void setElem(int bank, int i, int val) {
  155.         bankdata[bank][i+offsets[bank]] = (byte)val;
  156.     }
  157. }
  158.  
  159.