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 | Linking this library statically or dynamically with other modules is
|
---|
21 | making a combined work based on this library. Thus, the terms and
|
---|
22 | conditions of the GNU General Public License cover the whole
|
---|
23 | combination.
|
---|
24 |
|
---|
25 | As a special exception, the copyright holders of this library give you
|
---|
26 | permission to link this library with independent modules to produce an
|
---|
27 | executable, regardless of the license terms of these independent
|
---|
28 | modules, and to copy and distribute the resulting executable under
|
---|
29 | terms of your choice, provided that you also meet, for each linked
|
---|
30 | independent module, the terms and conditions of the license of that
|
---|
31 | module. An independent module is a module which is not derived from
|
---|
32 | or based on this library. If you modify this library, you may extend
|
---|
33 | this exception to your version of the library, but you are not
|
---|
34 | obligated to do so. If you do not wish to do so, delete this
|
---|
35 | exception statement from your version. */
|
---|
36 |
|
---|
37 | package java.awt.image;
|
---|
38 |
|
---|
39 | import java.awt.*;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
|
---|
43 | */
|
---|
44 | public class Raster
|
---|
45 | {
|
---|
46 | protected SampleModel sampleModel;
|
---|
47 | protected DataBuffer dataBuffer;
|
---|
48 | protected int minX;
|
---|
49 | protected int minY;
|
---|
50 | protected int width;
|
---|
51 | protected int height;
|
---|
52 | protected int sampleModelTranslateX;
|
---|
53 | protected int sampleModelTranslateY;
|
---|
54 | protected int numBands;
|
---|
55 | protected int numDataElements;
|
---|
56 | protected Raster parent;
|
---|
57 |
|
---|
58 | protected Raster(SampleModel sampleModel, Point origin)
|
---|
59 | {
|
---|
60 | this(sampleModel, sampleModel.createDataBuffer(), origin);
|
---|
61 | }
|
---|
62 |
|
---|
63 | protected Raster(SampleModel sampleModel, DataBuffer dataBuffer,
|
---|
64 | Point origin)
|
---|
65 | {
|
---|
66 | this(sampleModel, dataBuffer,
|
---|
67 | new Rectangle(origin.x, origin.y,
|
---|
68 | sampleModel.getWidth(), sampleModel.getHeight()),
|
---|
69 | origin, null);
|
---|
70 | }
|
---|
71 |
|
---|
72 | protected Raster(SampleModel sampleModel, DataBuffer dataBuffer,
|
---|
73 | Rectangle aRegion,
|
---|
74 | Point sampleModelTranslate, Raster parent)
|
---|
75 | {
|
---|
76 | this.sampleModel = sampleModel;
|
---|
77 | this.dataBuffer = dataBuffer;
|
---|
78 | this.minX = aRegion.x;
|
---|
79 | this.minY = aRegion.y;
|
---|
80 | this.width = aRegion.width;
|
---|
81 | this.height = aRegion.height;
|
---|
82 | this.sampleModelTranslateX = sampleModelTranslate.x;
|
---|
83 | this.sampleModelTranslateY = sampleModelTranslate.y;
|
---|
84 | this.numBands = sampleModel.getNumBands();
|
---|
85 | this.numDataElements = sampleModel.getNumDataElements();
|
---|
86 | this.parent = parent;
|
---|
87 | }
|
---|
88 |
|
---|
89 | public static WritableRaster createInterleavedRaster(int dataType,
|
---|
90 | int w, int h,
|
---|
91 | int bands,
|
---|
92 | Point location)
|
---|
93 | {
|
---|
94 | int[] bandOffsets = new int[bands];
|
---|
95 | // TODO: Maybe not generate this every time.
|
---|
96 | for (int b=0; b<bands; b++) bandOffsets[b] = b;
|
---|
97 |
|
---|
98 | int scanlineStride = bands*w;
|
---|
99 | return createInterleavedRaster(dataType, w, h, scanlineStride, bands,
|
---|
100 | bandOffsets, location);
|
---|
101 | }
|
---|
102 |
|
---|
103 | public static WritableRaster createInterleavedRaster(int dataType,
|
---|
104 | int w, int h,
|
---|
105 | int scanlineStride,
|
---|
106 | int pixelStride,
|
---|
107 | int[] bandOffsets,
|
---|
108 | Point location)
|
---|
109 | {
|
---|
110 | SampleModel sm = new ComponentSampleModel(dataType,
|
---|
111 | w, h,
|
---|
112 | pixelStride,
|
---|
113 | scanlineStride,
|
---|
114 | bandOffsets);
|
---|
115 | return createWritableRaster(sm, location);
|
---|
116 | }
|
---|
117 |
|
---|
118 | public static WritableRaster createBandedRaster(int dataType,
|
---|
119 | int w, int h, int bands,
|
---|
120 | Point location)
|
---|
121 | {
|
---|
122 | // FIXME: Implement;
|
---|
123 | throw new UnsupportedOperationException("not implemented yet");
|
---|
124 | }
|
---|
125 |
|
---|
126 | public static WritableRaster createBandedRaster(int dataType,
|
---|
127 | int w, int h,
|
---|
128 | int scanlineStride,
|
---|
129 | int[] bankIndices,
|
---|
130 | int[] bandOffsets,
|
---|
131 | Point location)
|
---|
132 | {
|
---|
133 | // FIXME: Implement;
|
---|
134 | throw new UnsupportedOperationException("not implemented yet");
|
---|
135 | }
|
---|
136 |
|
---|
137 | public static WritableRaster createPackedRaster(int dataType,
|
---|
138 | int w, int h,
|
---|
139 | int[] bandMasks,
|
---|
140 | Point location)
|
---|
141 | {
|
---|
142 | SampleModel sm = new SinglePixelPackedSampleModel(dataType,
|
---|
143 | w, h,
|
---|
144 | bandMasks);
|
---|
145 | return createWritableRaster(sm, location);
|
---|
146 | }
|
---|
147 |
|
---|
148 | public static WritableRaster
|
---|
149 | createInterleavedRaster(DataBuffer dataBuffer, int w, int h,
|
---|
150 | int scanlineStride, int pixelStride,
|
---|
151 | int[] bandOffsets, Point location)
|
---|
152 | {
|
---|
153 | SampleModel sm = new ComponentSampleModel(dataBuffer.getDataType(),
|
---|
154 | w, h,
|
---|
155 | scanlineStride,
|
---|
156 | pixelStride,
|
---|
157 | bandOffsets);
|
---|
158 | return createWritableRaster(sm, dataBuffer, location);
|
---|
159 | }
|
---|
160 |
|
---|
161 | public static
|
---|
162 | WritableRaster createBandedRaster(DataBuffer dataBuffer,
|
---|
163 | int w, int h,
|
---|
164 | int scanlineStride,
|
---|
165 | int[] bankIndices,
|
---|
166 | int[] bandOffsets,
|
---|
167 | Point location)
|
---|
168 | {
|
---|
169 | // FIXME: Implement;
|
---|
170 | throw new UnsupportedOperationException("not implemented yet");
|
---|
171 | }
|
---|
172 |
|
---|
173 | public static WritableRaster
|
---|
174 | createPackedRaster(DataBuffer dataBuffer,
|
---|
175 | int w, int h,
|
---|
176 | int scanlineStride,
|
---|
177 | int[] bandMasks,
|
---|
178 | Point location) {
|
---|
179 | SampleModel sm =
|
---|
180 | new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
|
---|
181 | w, h,
|
---|
182 | scanlineStride,
|
---|
183 | bandMasks);
|
---|
184 | return createWritableRaster(sm, dataBuffer, location);
|
---|
185 | }
|
---|
186 |
|
---|
187 | public static Raster createRaster(SampleModel sm, DataBuffer db,
|
---|
188 | Point location)
|
---|
189 | {
|
---|
190 | return new Raster(sm, db, location);
|
---|
191 | }
|
---|
192 |
|
---|
193 | public static WritableRaster createWritableRaster(SampleModel sm,
|
---|
194 | Point location)
|
---|
195 | {
|
---|
196 | return new WritableRaster(sm, location);
|
---|
197 | }
|
---|
198 |
|
---|
199 | public static WritableRaster createWritableRaster(SampleModel sm,
|
---|
200 | DataBuffer db,
|
---|
201 | Point location)
|
---|
202 | {
|
---|
203 | return new WritableRaster(sm, db, location);
|
---|
204 | }
|
---|
205 |
|
---|
206 | public Raster getParent()
|
---|
207 | {
|
---|
208 | return parent;
|
---|
209 | }
|
---|
210 |
|
---|
211 | public final int getSampleModelTranslateX()
|
---|
212 | {
|
---|
213 | return sampleModelTranslateX;
|
---|
214 | }
|
---|
215 |
|
---|
216 | public final int getSampleModelTranslateY()
|
---|
217 | {
|
---|
218 | return sampleModelTranslateY;
|
---|
219 | }
|
---|
220 |
|
---|
221 | public WritableRaster createCompatibleWritableRaster()
|
---|
222 | {
|
---|
223 | return new WritableRaster(getSampleModel(), new Point(minX, minY));
|
---|
224 | }
|
---|
225 |
|
---|
226 | public WritableRaster createCompatibleWritableRaster(int w, int h)
|
---|
227 | {
|
---|
228 | return createCompatibleWritableRaster(minX, minY, w, h);
|
---|
229 | }
|
---|
230 |
|
---|
231 | public WritableRaster createCompatibleWritableRaster(Rectangle rect)
|
---|
232 | {
|
---|
233 | return createCompatibleWritableRaster(rect.x, rect.y,
|
---|
234 | rect.width, rect.height);
|
---|
235 | }
|
---|
236 |
|
---|
237 | public WritableRaster createCompatibleWritableRaster(int x, int y,
|
---|
238 | int w, int h)
|
---|
239 | {
|
---|
240 | SampleModel sm = getSampleModel().createCompatibleSampleModel(w, h);
|
---|
241 | return new WritableRaster(sm, sm.createDataBuffer(),
|
---|
242 | new Point(x, y));
|
---|
243 | }
|
---|
244 |
|
---|
245 | public Raster createTranslatedChild(int childMinX, int childMinY) {
|
---|
246 | int tcx = sampleModelTranslateX - minX + childMinX;
|
---|
247 | int tcy = sampleModelTranslateY - minY + childMinY;
|
---|
248 |
|
---|
249 | return new Raster(sampleModel, dataBuffer,
|
---|
250 | new Rectangle(childMinX, childMinY,
|
---|
251 | width, height),
|
---|
252 | new Point(tcx, tcy),
|
---|
253 | this);
|
---|
254 | }
|
---|
255 |
|
---|
256 | public Raster createChild(int parentX, int parentY, int width,
|
---|
257 | int height, int childMinX, int childMinY,
|
---|
258 | int[] bandList)
|
---|
259 | {
|
---|
260 | /* FIXME: Throw RasterFormatException if child bounds extends
|
---|
261 | beyond the bounds of this raster. */
|
---|
262 |
|
---|
263 | SampleModel sm = (bandList == null) ?
|
---|
264 | sampleModel :
|
---|
265 | sampleModel.createSubsetSampleModel(bandList);
|
---|
266 |
|
---|
267 | /*
|
---|
268 | data origin
|
---|
269 | /
|
---|
270 | +-------------------------
|
---|
271 | |\. __ parent trans
|
---|
272 | | \`.
|
---|
273 | | \ `. parent origin
|
---|
274 | | \ `. /
|
---|
275 | | /\ +-------- - -
|
---|
276 | |trans\ /<\-- deltaTrans
|
---|
277 | |child +-+-\---- - -
|
---|
278 | | /|`| \__ parent [x, y]
|
---|
279 | |child | |`. \
|
---|
280 | |origin| : `.\
|
---|
281 | | | / `\
|
---|
282 | | : / +
|
---|
283 | | child [x, y]
|
---|
284 |
|
---|
285 | parent_xy - parent_trans = child_xy - child_trans
|
---|
286 |
|
---|
287 | child_trans = parent_trans + child_xy - parent_xy
|
---|
288 | */
|
---|
289 |
|
---|
290 | return new Raster(sm, dataBuffer,
|
---|
291 | new Rectangle(childMinX, childMinY,
|
---|
292 | width, height),
|
---|
293 | new Point(sampleModelTranslateX+childMinX-parentX,
|
---|
294 | sampleModelTranslateY+childMinY-parentY),
|
---|
295 | this);
|
---|
296 | }
|
---|
297 |
|
---|
298 | public Rectangle getBounds()
|
---|
299 | {
|
---|
300 | return new Rectangle(minX, minY, width, height);
|
---|
301 | }
|
---|
302 |
|
---|
303 | public final int getMinX()
|
---|
304 | {
|
---|
305 | return minX;
|
---|
306 | }
|
---|
307 |
|
---|
308 | public final int getMinY()
|
---|
309 | {
|
---|
310 | return minY;
|
---|
311 | }
|
---|
312 |
|
---|
313 | public final int getWidth()
|
---|
314 | {
|
---|
315 | return width;
|
---|
316 | }
|
---|
317 |
|
---|
318 | public final int getHeight()
|
---|
319 | {
|
---|
320 | return height;
|
---|
321 | }
|
---|
322 |
|
---|
323 | public final int getNumDataElements()
|
---|
324 | {
|
---|
325 | return numDataElements;
|
---|
326 | }
|
---|
327 |
|
---|
328 | public final int getTransferType()
|
---|
329 | {
|
---|
330 | return sampleModel.getTransferType();
|
---|
331 | }
|
---|
332 |
|
---|
333 | public DataBuffer getDataBuffer()
|
---|
334 | {
|
---|
335 | return dataBuffer;
|
---|
336 | }
|
---|
337 |
|
---|
338 | public SampleModel getSampleModel()
|
---|
339 | {
|
---|
340 | return sampleModel;
|
---|
341 | }
|
---|
342 |
|
---|
343 | public Object getDataElements(int x, int y, Object outData)
|
---|
344 | {
|
---|
345 | return sampleModel.getDataElements(x-sampleModelTranslateX,
|
---|
346 | y-sampleModelTranslateY,
|
---|
347 | outData, dataBuffer);
|
---|
348 | }
|
---|
349 |
|
---|
350 | public Object getDataElements(int x, int y, int w, int h,
|
---|
351 | Object outData)
|
---|
352 | {
|
---|
353 | return sampleModel.getDataElements(x-sampleModelTranslateX,
|
---|
354 | y-sampleModelTranslateY,
|
---|
355 | w, h, outData, dataBuffer);
|
---|
356 | }
|
---|
357 |
|
---|
358 | public int[] getPixel(int x, int y, int[] iArray)
|
---|
359 | {
|
---|
360 | return sampleModel.getPixel(x-sampleModelTranslateX,
|
---|
361 | y-sampleModelTranslateY,
|
---|
362 | iArray, dataBuffer);
|
---|
363 | }
|
---|
364 |
|
---|
365 | public float[] getPixel(int x, int y, float[] fArray)
|
---|
366 | {
|
---|
367 | return sampleModel.getPixel(x-sampleModelTranslateX,
|
---|
368 | y-sampleModelTranslateY,
|
---|
369 | fArray, dataBuffer);
|
---|
370 | }
|
---|
371 |
|
---|
372 | public double[] getPixel(int x, int y, double[] dArray)
|
---|
373 | {
|
---|
374 | return sampleModel.getPixel(x-sampleModelTranslateX,
|
---|
375 | y-sampleModelTranslateY,
|
---|
376 | dArray, dataBuffer);
|
---|
377 | }
|
---|
378 |
|
---|
379 | public int[] getPixels(int x, int y, int w, int h, int[] iArray)
|
---|
380 | {
|
---|
381 | return sampleModel.getPixels(x-sampleModelTranslateX,
|
---|
382 | y-sampleModelTranslateY,
|
---|
383 | w, h, iArray, dataBuffer);
|
---|
384 | }
|
---|
385 |
|
---|
386 | public float[] getPixels(int x, int y, int w, int h,
|
---|
387 | float[] fArray)
|
---|
388 | {
|
---|
389 | return sampleModel.getPixels(x-sampleModelTranslateX,
|
---|
390 | y-sampleModelTranslateY,
|
---|
391 | w, h, fArray, dataBuffer);
|
---|
392 | }
|
---|
393 |
|
---|
394 | public double[] getPixels(int x, int y, int w, int h,
|
---|
395 | double[] dArray)
|
---|
396 | {
|
---|
397 | return sampleModel.getPixels(x-sampleModelTranslateX,
|
---|
398 | y-sampleModelTranslateY,
|
---|
399 | w, h, dArray, dataBuffer);
|
---|
400 | }
|
---|
401 |
|
---|
402 | public int getSample(int x, int y, int b)
|
---|
403 | {
|
---|
404 | return sampleModel.getSample(x-sampleModelTranslateX,
|
---|
405 | y-sampleModelTranslateY,
|
---|
406 | b, dataBuffer);
|
---|
407 | }
|
---|
408 |
|
---|
409 | public float getSampleFloat(int x, int y, int b)
|
---|
410 | {
|
---|
411 | return sampleModel.getSampleFloat(x-sampleModelTranslateX,
|
---|
412 | y-sampleModelTranslateY,
|
---|
413 | b, dataBuffer);
|
---|
414 | }
|
---|
415 |
|
---|
416 | public double getSampleDouble(int x, int y, int b)
|
---|
417 | {
|
---|
418 | return sampleModel.getSampleDouble(x-sampleModelTranslateX,
|
---|
419 | y-sampleModelTranslateY,
|
---|
420 | b, dataBuffer);
|
---|
421 | }
|
---|
422 |
|
---|
423 | public int[] getSamples(int x, int y, int w, int h, int b,
|
---|
424 | int[] iArray)
|
---|
425 | {
|
---|
426 | return sampleModel.getSamples(x-sampleModelTranslateX,
|
---|
427 | y-sampleModelTranslateY,
|
---|
428 | w, h, b, iArray, dataBuffer);
|
---|
429 | }
|
---|
430 |
|
---|
431 | public float[] getSamples(int x, int y, int w, int h, int b,
|
---|
432 | float[] fArray)
|
---|
433 | {
|
---|
434 | return sampleModel.getSamples(x-sampleModelTranslateX,
|
---|
435 | y-sampleModelTranslateY,
|
---|
436 | w, h, b, fArray, dataBuffer);
|
---|
437 | }
|
---|
438 |
|
---|
439 | public double[] getSamples(int x, int y, int w, int h, int b,
|
---|
440 | double[] dArray)
|
---|
441 | {
|
---|
442 | return sampleModel.getSamples(x-sampleModelTranslateX,
|
---|
443 | y-sampleModelTranslateY,
|
---|
444 | w, h, b, dArray, dataBuffer);
|
---|
445 | }
|
---|
446 | }
|
---|