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 / DataBufferInt.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  4.7 KB  |  160 lines

  1. /*
  2.  * @(#)DataBufferInt.java    1.8 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 ints.
  29.  */
  30.  
  31. public class DataBufferInt extends DataBuffer
  32. {
  33.     /** The default data bank. */
  34.     int data[];
  35.  
  36.     /** All data banks */
  37.     int bankdata[][];
  38.  
  39.     /**
  40.      * Construct an int based DataBuffer with specified size
  41.      */
  42.     public DataBufferInt(int size) {
  43.         super(INT_DATA,size);
  44.         data = new int[size];
  45.         bankdata = new int[1][];
  46.         bankdata[0] = data;
  47.     }
  48.   
  49.     /**
  50.      * Construct an int based DataBuffer with specified number of
  51.      * banks all of which are the specified size.
  52.      */
  53.     public DataBufferInt(int size, int numBanks) {
  54.         super(INT_DATA,size,numBanks);
  55.         bankdata = new int[numBanks][];
  56.         for (int i= 0; i < numBanks; i++) {
  57.             bankdata[i] = new int[size];
  58.         }
  59.         data = bankdata[0];
  60.     }
  61.  
  62.     /**
  63.      * Construct an int based DataBuffer with 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 DataBufferInt(int dataArray[], int size) {
  69.         super(INT_DATA,size);
  70.         data = dataArray;
  71.         bankdata = new int[1][];
  72.         bankdata[0] = data;
  73.     }
  74.  
  75.     /**
  76.      * Construct an int based DataBuffer with specified array, size,
  77.      * and offset.  dataArray.length must be at least as large as
  78.      * offset + size.
  79.      */
  80.     public DataBufferInt(int dataArray[], int size, int offset) {
  81.         super(INT_DATA,size,1,offset);
  82.         data = dataArray;
  83.         bankdata = new int[1][];
  84.         bankdata[0] = data;
  85.     }
  86.  
  87.     /**
  88.      * Construct an int based DataBuffer with specified array.
  89.      * Only the first size elements are available for use by
  90.      * this databuffer.  dataArray.length must be large enough to
  91.      * hold size elements.
  92.      */
  93.     public DataBufferInt(int dataArray[][], int size) {
  94.         super(INT_DATA,dataArray.length,size);
  95.         bankdata = dataArray;
  96.         data = bankdata[0];
  97.     }
  98.  
  99.     /**
  100.      * Construct an int 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 DataBufferInt(int dataArray[][], int size, int offsets[]) {
  106.         super(INT_DATA,size,dataArray.length,offsets);
  107.         bankdata = dataArray;
  108.         data = bankdata[0];
  109.     }
  110.  
  111.     /**
  112.      * Return the default (first) int data array int DataBuffer
  113.      */
  114.     public int[] getData() {
  115.         return data;
  116.     }
  117.  
  118.     /** Return the data array for the specified bank */
  119.     public int[] getData(int bank) {
  120.         return bankdata[bank];
  121.     }
  122.  
  123.     /** Return the data array for all banks */
  124.     public int[][] getBankData() {
  125.         return bankdata;
  126.     }
  127.      
  128.     /**
  129.      * Returns the requested data array element from the first (default) bank
  130.      * as an integer.
  131.      */
  132.     public int getElem(int i) {
  133.         return data[i+offset];
  134.     }
  135.  
  136.     /**
  137.      * Returns the requested data array element from the specified bank
  138.      * as an integer.
  139.      */
  140.     public int getElem(int bank, int i) {
  141.         return bankdata[bank][i+offsets[bank]];
  142.     }
  143.  
  144.     /**
  145.      * Sets the requested data array element in the first (default) bank 
  146.      * from the given integer.
  147.      */
  148.     public void setElem(int i, int val) {
  149.         data[i+offset] = val;
  150.     }
  151.  
  152.     /**
  153.      * Sets the requested data array element in the specified bank 
  154.      * from the given integer.
  155.      */
  156.     public void setElem(int bank, int i, int val) {
  157.         bankdata[bank][i+offsets[bank]] = (int)val;
  158.     }
  159. }
  160.