KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > image > DataBufferInt


1 /*
2  * @(#)DataBufferInt.java 1.20 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /* ****************************************************************
9  ******************************************************************
10  ******************************************************************
11  *** COPYRIGHT (c) Eastman Kodak Company, 1997
12  *** As an unpublished work pursuant to Title 17 of the United
13  *** States Code. All rights reserved.
14  ******************************************************************
15  ******************************************************************
16  ******************************************************************/

17
18 package java.awt.image;
19
20 /**
21  * This class extends <CODE>DataBuffer</CODE> and stores data internally
22  * as integers.
23  */

24
25 public final class DataBufferInt extends DataBuffer JavaDoc
26 {
27     /** The default data bank. */
28     int data[];
29
30     /** All data banks */
31     int bankdata[][];
32
33     /**
34      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank
35      * and the specified size.
36      *
37      * @param size The size of the <CODE>DataBuffer</CODE>.
38      */

39     public DataBufferInt(int size) {
40         super(TYPE_INT,size);
41         data = new int[size];
42         bankdata = new int[1][];
43         bankdata[0] = data;
44     }
45
46     /**
47      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified number of
48      * banks, all of which are the specified size.
49      *
50      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
51      * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>.
52      */

53     public DataBufferInt(int size, int numBanks) {
54         super(TYPE_INT,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      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
64      * specified array.
65      * Only the first <CODE>size</CODE> elements should be used by accessors of
66      * this <CODE>DataBuffer</CODE>. <CODE>dataArray</CODE> must be large enough to
67      * hold <CODE>size</CODE> elements.
68      *
69      * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
70      * @param size The size of the <CODE>DataBuffer</CODE> bank.
71      */

72     public DataBufferInt(int dataArray[], int size) {
73         super(TYPE_INT,size);
74         data = dataArray;
75         bankdata = new int[1][];
76         bankdata[0] = data;
77     }
78
79     /**
80      * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
81      * specified array, size, and offset. <CODE>dataArray</CODE> must have at least
82      * <CODE>offset</CODE> + <CODE>size</CODE> elements. Only elements <CODE>offset</CODE>
83      * through <CODE>offset</CODE> + <CODE>size</CODE> - 1
84      * should be used by accessors of this <CODE>DataBuffer</CODE>.
85      *
86      * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
87      * @param size The size of the <CODE>DataBuffer</CODE> bank.
88      * @param offset The offset into the <CODE>dataArray</CODE>.
89      */

90     public DataBufferInt(int dataArray[], int size, int offset) {
91         super(TYPE_INT,size,1,offset);
92         data = dataArray;
93         bankdata = new int[1][];
94         bankdata[0] = data;
95     }
96
97     /**
98      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays.
99      * The number of banks will be equal to <CODE>dataArray.length</CODE>.
100      * Only the first <CODE>size</CODE> elements of each array should be used by
101      * accessors of this <CODE>DataBuffer</CODE>.
102      *
103      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
104      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
105      */

106     public DataBufferInt(int dataArray[][], int size) {
107         super(TYPE_INT, size, dataArray.length);
108         bankdata = (int [][]) dataArray.clone();
109         data = bankdata[0];
110     }
111
112     /**
113      * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays, size,
114      * and offsets.
115      * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must
116      * be at least as large as <CODE>size</CODE> + the corresponding offset. There must
117      * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each
118      * bank, only elements <CODE>offset</CODE> through
119      * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
120      * used by accessors of this <CODE>DataBuffer</CODE>.
121      *
122      * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
123      * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
124      * @param offsets The offsets into each array.
125      */

126     public DataBufferInt(int dataArray[][], int size, int offsets[]) {
127         super(TYPE_INT,size,dataArray.length,offsets);
128         bankdata = (int [][]) dataArray.clone();
129         data = bankdata[0];
130     }
131
132     /**
133      * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
134      *
135      * @return The first integer data array.
136      */

137     public int[] getData() {
138         return data;
139     }
140
141     /**
142      * Returns the data array for the specified bank.
143      *
144      * @param bank The bank whose data array you want to get.
145      * @return The data array for the specified bank.
146      */

147     public int[] getData(int bank) {
148         return bankdata[bank];
149     }
150
151     /**
152      * Returns the data arrays for all banks.
153      * @return All of the data arrays.
154      */

155     public int[][] getBankData() {
156         return (int [][]) bankdata.clone();
157     }
158
159     /**
160      * Returns the requested data array element from the first (default) bank.
161      *
162      * @param i The data array element you want to get.
163      * @return The requested data array element as an integer.
164      * @see #setElem(int, int)
165      * @see #setElem(int, int, int)
166      */

167     public int getElem(int i) {
168         return data[i+offset];
169     }
170
171     /**
172      * Returns the requested data array element from the specified bank.
173      *
174      * @param bank The bank from which you want to get a data array element.
175      * @param i The data array element you want to get.
176      * @return The requested data array element as an integer.
177      * @see #setElem(int, int)
178      * @see #setElem(int, int, int)
179      */

180     public int getElem(int bank, int i) {
181         return bankdata[bank][i+offsets[bank]];
182     }
183
184     /**
185      * Sets the requested data array element in the first (default) bank
186      * to the specified value.
187      *
188      * @param i The data array element you want to set.
189      * @param val The integer value to which you want to set the data array element.
190      * @see #getElem(int)
191      * @see #getElem(int, int)
192      */

193     public void setElem(int i, int val) {
194         data[i+offset] = val;
195     }
196
197     /**
198      * Sets the requested data array element in the specified bank
199      * to the integer value <CODE>i</CODE>.
200      * @param bank The bank in which you want to set the data array element.
201      * @param i The data array element you want to set.
202      * @param val The integer value to which you want to set the specified data array element.
203      * @see #getElem(int)
204      * @see #getElem(int, int)
205      */

206     public void setElem(int bank, int i, int val) {
207         bankdata[bank][i+offsets[bank]] = (int)val;
208     }
209 }
210
211
Popular Tags