OSDN Git Service

Start of AWT merge with Classpath:
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / image / DataBufferInt.java
1 /* Copyright (C) 2000, 2002  Free Software Foundation
2
3 This file is part of GNU Classpath.
4
5 GNU Classpath is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
9
10 GNU Classpath is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNU Classpath; see the file COPYING.  If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA.
19
20 As a special exception, if you link this library with other files to
21 produce an executable, this library does not by itself cause the
22 resulting executable to be covered by the GNU General Public License.
23 This exception does not however invalidate any other reasons why the
24 executable file might be covered by the GNU General Public License. */
25
26 package java.awt.image;
27
28 /* This is one of several classes that are nearly identical. Maybe we
29    should have a central template and generate all these files. This
30    is one of the cases where templates or macros would have been
31    useful to have in Java.
32
33    This file has been created using search-replace. My only fear is
34    that these classes will grow out-of-sync as of a result of changes
35    that are not propagated to the other files. As always, mirroring
36    code is a maintenance nightmare.  */
37
38 /**
39  * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
40  */
41 public class DataBufferInt extends DataBuffer
42 {
43   private int[] data;
44   private int[][] bankData;
45   
46   public DataBufferInt(int size)
47   {
48     super(TYPE_INT, size);
49     data = new int[size];
50   }
51
52   public DataBufferInt(int size, int numBanks)
53   {
54     super(TYPE_INT, size, numBanks);
55     bankData = new int[numBanks][size];
56     data = bankData[0];
57   }
58   
59   public DataBufferInt(int[] dataArray, int size)
60   {
61     super(TYPE_INT, size);
62     data = dataArray;
63   }
64     
65   public DataBufferInt(int[] dataArray, int size, int offset)
66   {
67     super(TYPE_INT, size, 1, offset);
68     data = dataArray;
69   }
70   
71   public DataBufferInt(int[][] dataArray, int size)
72   {
73     super(TYPE_INT, size, dataArray.length);
74     bankData = dataArray;
75     data = bankData[0];
76   }
77   
78   public DataBufferInt(int[][] dataArray, int size, int[] offsets)
79   {
80     super(TYPE_INT, size, dataArray.length, offsets);
81     bankData = dataArray;
82     data = bankData[0];
83   }
84
85   public int[] getData()
86   {
87     return data;
88   }
89     
90   public int[] getData(int bank)
91   {
92     return bankData[bank];
93   }
94   
95   public int[][] getBankData()
96   {
97     return bankData;
98   }
99   
100   public int getElem(int i)
101   {
102     return data[i+offset];
103   }
104
105   public int getElem(int bank, int i)
106   {
107     // get unsigned int as int
108     return bankData[bank][i+offsets[bank]];
109   }
110
111   public void setElem(int i, int val)
112   {
113     data[i+offset] = (int) val;
114   }
115   
116   public void setElem(int bank, int i, int val)
117   {
118     bankData[bank][i+offsets[bank]] = (int) val;
119   }
120 }