source: trunk/gcc/libjava/java/awt/image/WritableRaster.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.5 KB
Line 
1/* Copyright (C) 2000, 2002 Free Software Foundation
2
3This file is part of GNU Classpath.
4
5GNU Classpath is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2, or (at your option)
8any later version.
9
10GNU Classpath is distributed in the hope that it will be useful, but
11WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GNU Classpath; see the file COPYING. If not, write to the
17Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1802111-1307 USA.
19
20Linking this library statically or dynamically with other modules is
21making a combined work based on this library. Thus, the terms and
22conditions of the GNU General Public License cover the whole
23combination.
24
25As a special exception, the copyright holders of this library give you
26permission to link this library with independent modules to produce an
27executable, regardless of the license terms of these independent
28modules, and to copy and distribute the resulting executable under
29terms of your choice, provided that you also meet, for each linked
30independent module, the terms and conditions of the license of that
31module. An independent module is a module which is not derived from
32or based on this library. If you modify this library, you may extend
33this exception to your version of the library, but you are not
34obligated to do so. If you do not wish to do so, delete this
35exception statement from your version. */
36
37package java.awt.image;
38
39import java.awt.*;
40
41/**
42 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
43 */
44public class WritableRaster extends Raster
45{
46 protected WritableRaster(SampleModel sampleModel, Point origin)
47 {
48 this(sampleModel, sampleModel.createDataBuffer(), origin);
49 }
50
51 protected WritableRaster(SampleModel sampleModel,
52 DataBuffer dataBuffer, Point origin)
53 {
54 this(sampleModel, dataBuffer,
55 new Rectangle(origin.x, origin.y,
56 sampleModel.getWidth(), sampleModel.getHeight()),
57 origin,
58 null);
59 }
60
61 protected WritableRaster(SampleModel sampleModel,
62 DataBuffer dataBuffer,
63 Rectangle aRegion,
64 Point sampleModelTranslate,
65 WritableRaster parent)
66 {
67 super(sampleModel, dataBuffer, aRegion, sampleModelTranslate,
68 parent);
69 }
70
71 public WritableRaster getWritableParent()
72 {
73 return (WritableRaster) getParent();
74 }
75
76 public WritableRaster createWritableTranslatedChild(int childMinX,
77 int childMinY)
78 {
79 // This mirrors the code from the super class
80 int tcx = sampleModelTranslateX - minX + childMinX;
81 int tcy = sampleModelTranslateY - minY + childMinY;
82
83 return new WritableRaster(sampleModel, dataBuffer,
84 new Rectangle(childMinX, childMinY,
85 width, height),
86 new Point(tcx, tcy),
87 this);
88 }
89
90 public WritableRaster createWritableChild(int parentX,
91 int parentY,
92 int w, int h,
93 int childMinX,
94 int childMinY,
95 int[] bandList)
96 {
97 // This mirrors the code from the super class
98
99 // FIXME: Throw RasterFormatException if child bounds extends
100 // beyond the bounds of this raster.
101
102 SampleModel sm = (bandList == null) ?
103 sampleModel :
104 sampleModel.createSubsetSampleModel(bandList);
105
106 return new
107 WritableRaster(sm, dataBuffer,
108 new Rectangle(childMinX, childMinY,
109 w, h),
110 new Point(sampleModelTranslateX+childMinX-parentX,
111 sampleModelTranslateY+childMinY-parentY),
112 this);
113 }
114
115 public void setDataElements(int x, int y, Object inData)
116 {
117 sampleModel.setDataElements(x-sampleModelTranslateX,
118 y-sampleModelTranslateY,
119 inData, dataBuffer);
120 }
121
122 public void setDataElements(int x, int y, Raster inRaster)
123 {
124 Object dataElements = getDataElements(0, 0,
125 inRaster.getWidth(),
126 inRaster.getHeight(),
127 null);
128 setDataElements(x, y, dataElements);
129 }
130
131 public void setDataElements(int x, int y, int w, int h,
132 Object inData)
133 {
134 sampleModel.setDataElements(x-sampleModelTranslateX,
135 y-sampleModelTranslateY,
136 w, h, inData, dataBuffer);
137 }
138
139 public void setRect(Raster srcRaster)
140 {
141 setRect(srcRaster, 0, 0);
142 }
143
144 public void setRect(Raster srcRaster, int dx, int dy)
145 {
146 Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX()+dx,
147 srcRaster.getMinY()+dy,
148 srcRaster.getWidth(),
149 srcRaster.getHeight());
150
151 Rectangle target = getBounds().intersection(targetUnclipped);
152
153 if (target.isEmpty()) return;
154
155 int sx = target.x - dx;
156 int sy = target.y - dy;
157
158 // FIXME: Do tests on rasters and use get/set data instead.
159
160 /* The JDK documentation seems to imply this implementation.
161 (the trucation of higher bits), but an implementation using
162 get/setDataElements would be more efficient. None of the
163 implementations would do anything sensible when the sample
164 models don't match.
165
166 But this is probably not the place to consider such
167 optimizations.*/
168
169 int[] pixels = srcRaster.getPixels(sx, sy,
170 target.width, target.height,
171 (int[]) null);
172
173 setPixels(target.x, target.y, target.width, target.height, pixels);
174 }
175
176 public void setPixel(int x, int y, int[] iArray)
177 {
178 sampleModel.setPixel(x-sampleModelTranslateX,
179 y-sampleModelTranslateY,
180 iArray, dataBuffer);
181 }
182
183 public void setPixel(int x, int y, float[] fArray)
184 {
185 sampleModel.setPixel(x-sampleModelTranslateX,
186 y-sampleModelTranslateY,
187 fArray, dataBuffer);
188 }
189
190 public void setPixel(int x, int y, double[] dArray)
191 {
192 sampleModel.setPixel(x-sampleModelTranslateX,
193 y-sampleModelTranslateY,
194 dArray, dataBuffer);
195 }
196
197 public void setPixels(int x, int y, int w, int h, int[] iArray)
198 {
199 sampleModel.setPixels(x-sampleModelTranslateX,
200 y-sampleModelTranslateY,
201 w, h, iArray, dataBuffer);
202 }
203
204 public void setPixels(int x, int y, int w, int h, float[] fArray)
205 {
206 sampleModel.setPixels(x-sampleModelTranslateX,
207 y-sampleModelTranslateY,
208 w, h, fArray, dataBuffer);
209 }
210
211 public void setPixels(int x, int y, int w, int h, double[] dArray)
212 {
213 sampleModel.setPixels(x-sampleModelTranslateX,
214 y-sampleModelTranslateY,
215 w, h, dArray, dataBuffer);
216 }
217
218 public void setSample(int x, int y, int b, int s)
219 {
220 sampleModel.setSample(x-sampleModelTranslateX,
221 y-sampleModelTranslateY,
222 b, s, dataBuffer);
223 }
224
225 public void setSample(int x, int y, int b, float s)
226 {
227 sampleModel.setSample(x-sampleModelTranslateX,
228 y-sampleModelTranslateY,
229 b, s, dataBuffer);
230 }
231
232 public void setSample(int x, int y, int b, double s)
233 {
234 sampleModel.setSample(x-sampleModelTranslateX,
235 y-sampleModelTranslateY,
236 b, s, dataBuffer);
237 }
238
239 public void setSamples(int x, int y, int w, int h, int b,
240 int[] iArray)
241 {
242 sampleModel.setSamples(x-sampleModelTranslateX,
243 y-sampleModelTranslateY,
244 w, h, b, iArray, dataBuffer);
245 }
246
247 public void setSamples(int x, int y, int w, int h, int b,
248 float[] fArray)
249 {
250 sampleModel.setSamples(x-sampleModelTranslateX,
251 y-sampleModelTranslateY,
252 w, h, b, fArray, dataBuffer);
253 }
254
255 public void setSamples(int x, int y, int w, int h, int b,
256 double[] dArray)
257 {
258 sampleModel.setSamples(x-sampleModelTranslateX,
259 y-sampleModelTranslateY,
260 w, h, b, dArray, dataBuffer);
261 }
262}
Note: See TracBrowser for help on using the repository browser.