1 /* Copyright (C) 2000, 2002, 2003 Free Software Foundation
3 This file is part of GNU Classpath.
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)
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.
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
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
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. */
38 package java
.awt
.image
;
40 import java
.awt
.Point
;
41 import java
.awt
.Rectangle
;
44 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
48 protected SampleModel sampleModel
;
49 protected DataBuffer dataBuffer
;
54 protected int sampleModelTranslateX
;
55 protected int sampleModelTranslateY
;
56 protected int numBands
;
57 protected int numDataElements
;
58 protected Raster parent
;
60 protected Raster(SampleModel sampleModel
, Point origin
)
62 this(sampleModel
, sampleModel
.createDataBuffer(), origin
);
65 protected Raster(SampleModel sampleModel
, DataBuffer dataBuffer
,
68 this(sampleModel
, dataBuffer
,
69 new Rectangle(origin
.x
, origin
.y
,
70 sampleModel
.getWidth(), sampleModel
.getHeight()),
74 protected Raster(SampleModel sampleModel
, DataBuffer dataBuffer
,
76 Point sampleModelTranslate
, Raster parent
)
78 this.sampleModel
= sampleModel
;
79 this.dataBuffer
= dataBuffer
;
80 this.minX
= aRegion
.x
;
81 this.minY
= aRegion
.y
;
82 this.width
= aRegion
.width
;
83 this.height
= aRegion
.height
;
85 // If sampleModelTranslate is null, use (0,0). Methods such as
86 // Raster.createRaster are specified to allow for a null argument.
87 if (sampleModelTranslate
!= null)
89 this.sampleModelTranslateX
= sampleModelTranslate
.x
;
90 this.sampleModelTranslateY
= sampleModelTranslate
.y
;
93 this.numBands
= sampleModel
.getNumBands();
94 this.numDataElements
= sampleModel
.getNumDataElements();
98 public static WritableRaster
createInterleavedRaster(int dataType
,
103 int[] bandOffsets
= new int[bands
];
104 // TODO: Maybe not generate this every time.
105 for (int b
=0; b
<bands
; b
++) bandOffsets
[b
] = b
;
107 int scanlineStride
= bands
*w
;
108 return createInterleavedRaster(dataType
, w
, h
, scanlineStride
, bands
,
109 bandOffsets
, location
);
112 public static WritableRaster
createInterleavedRaster(int dataType
,
119 SampleModel sm
= new ComponentSampleModel(dataType
,
124 return createWritableRaster(sm
, location
);
127 public static WritableRaster
createBandedRaster(int dataType
,
128 int w
, int h
, int bands
,
132 throw new UnsupportedOperationException("not implemented yet");
135 public static WritableRaster
createBandedRaster(int dataType
,
143 throw new UnsupportedOperationException("not implemented yet");
146 public static WritableRaster
createPackedRaster(int dataType
,
151 SampleModel sm
= new SinglePixelPackedSampleModel(dataType
,
154 return createWritableRaster(sm
, location
);
157 public static WritableRaster
158 createInterleavedRaster(DataBuffer dataBuffer
, int w
, int h
,
159 int scanlineStride
, int pixelStride
,
160 int[] bandOffsets
, Point location
)
162 SampleModel sm
= new ComponentSampleModel(dataBuffer
.getDataType(),
167 return createWritableRaster(sm
, dataBuffer
, location
);
171 WritableRaster
createBandedRaster(DataBuffer dataBuffer
,
179 throw new UnsupportedOperationException("not implemented yet");
182 public static WritableRaster
183 createPackedRaster(DataBuffer dataBuffer
,
189 new SinglePixelPackedSampleModel(dataBuffer
.getDataType(),
193 return createWritableRaster(sm
, dataBuffer
, location
);
196 public static Raster
createRaster(SampleModel sm
, DataBuffer db
,
199 return new Raster(sm
, db
, location
);
202 public static WritableRaster
createWritableRaster(SampleModel sm
,
205 return new WritableRaster(sm
, location
);
208 public static WritableRaster
createWritableRaster(SampleModel sm
,
212 return new WritableRaster(sm
, db
, location
);
215 public Raster
getParent()
220 public final int getSampleModelTranslateX()
222 return sampleModelTranslateX
;
225 public final int getSampleModelTranslateY()
227 return sampleModelTranslateY
;
230 public WritableRaster
createCompatibleWritableRaster()
232 return new WritableRaster(getSampleModel(), new Point(minX
, minY
));
235 public WritableRaster
createCompatibleWritableRaster(int w
, int h
)
237 return createCompatibleWritableRaster(minX
, minY
, w
, h
);
240 public WritableRaster
createCompatibleWritableRaster(Rectangle rect
)
242 return createCompatibleWritableRaster(rect
.x
, rect
.y
,
243 rect
.width
, rect
.height
);
246 public WritableRaster
createCompatibleWritableRaster(int x
, int y
,
249 SampleModel sm
= getSampleModel().createCompatibleSampleModel(w
, h
);
250 return new WritableRaster(sm
, sm
.createDataBuffer(),
254 public Raster
createTranslatedChild(int childMinX
, int childMinY
) {
255 int tcx
= sampleModelTranslateX
- minX
+ childMinX
;
256 int tcy
= sampleModelTranslateY
- minY
+ childMinY
;
258 return new Raster(sampleModel
, dataBuffer
,
259 new Rectangle(childMinX
, childMinY
,
265 public Raster
createChild(int parentX
, int parentY
, int width
,
266 int height
, int childMinX
, int childMinY
,
269 /* FIXME: Throw RasterFormatException if child bounds extends
270 beyond the bounds of this raster. */
272 SampleModel sm
= (bandList
== null) ?
274 sampleModel
.createSubsetSampleModel(bandList
);
279 +-------------------------
285 |trans\ /<\-- deltaTrans
287 | /|`| \__ parent [x, y]
294 parent_xy - parent_trans = child_xy - child_trans
296 child_trans = parent_trans + child_xy - parent_xy
299 return new Raster(sm
, dataBuffer
,
300 new Rectangle(childMinX
, childMinY
,
302 new Point(sampleModelTranslateX
+childMinX
-parentX
,
303 sampleModelTranslateY
+childMinY
-parentY
),
307 public Rectangle
getBounds()
309 return new Rectangle(minX
, minY
, width
, height
);
312 public final int getMinX()
317 public final int getMinY()
322 public final int getWidth()
327 public final int getHeight()
332 public final int getNumDataElements()
334 return numDataElements
;
337 public final int getTransferType()
339 return sampleModel
.getTransferType();
342 public DataBuffer
getDataBuffer()
347 public SampleModel
getSampleModel()
352 public Object
getDataElements(int x
, int y
, Object outData
)
354 return sampleModel
.getDataElements(x
-sampleModelTranslateX
,
355 y
-sampleModelTranslateY
,
356 outData
, dataBuffer
);
359 public Object
getDataElements(int x
, int y
, int w
, int h
,
362 return sampleModel
.getDataElements(x
-sampleModelTranslateX
,
363 y
-sampleModelTranslateY
,
364 w
, h
, outData
, dataBuffer
);
367 public int[] getPixel(int x
, int y
, int[] iArray
)
369 return sampleModel
.getPixel(x
-sampleModelTranslateX
,
370 y
-sampleModelTranslateY
,
374 public float[] getPixel(int x
, int y
, float[] fArray
)
376 return sampleModel
.getPixel(x
-sampleModelTranslateX
,
377 y
-sampleModelTranslateY
,
381 public double[] getPixel(int x
, int y
, double[] dArray
)
383 return sampleModel
.getPixel(x
-sampleModelTranslateX
,
384 y
-sampleModelTranslateY
,
388 public int[] getPixels(int x
, int y
, int w
, int h
, int[] iArray
)
390 return sampleModel
.getPixels(x
-sampleModelTranslateX
,
391 y
-sampleModelTranslateY
,
392 w
, h
, iArray
, dataBuffer
);
395 public float[] getPixels(int x
, int y
, int w
, int h
,
398 return sampleModel
.getPixels(x
-sampleModelTranslateX
,
399 y
-sampleModelTranslateY
,
400 w
, h
, fArray
, dataBuffer
);
403 public double[] getPixels(int x
, int y
, int w
, int h
,
406 return sampleModel
.getPixels(x
-sampleModelTranslateX
,
407 y
-sampleModelTranslateY
,
408 w
, h
, dArray
, dataBuffer
);
411 public int getSample(int x
, int y
, int b
)
413 return sampleModel
.getSample(x
-sampleModelTranslateX
,
414 y
-sampleModelTranslateY
,
418 public float getSampleFloat(int x
, int y
, int b
)
420 return sampleModel
.getSampleFloat(x
-sampleModelTranslateX
,
421 y
-sampleModelTranslateY
,
425 public double getSampleDouble(int x
, int y
, int b
)
427 return sampleModel
.getSampleDouble(x
-sampleModelTranslateX
,
428 y
-sampleModelTranslateY
,
432 public int[] getSamples(int x
, int y
, int w
, int h
, int b
,
435 return sampleModel
.getSamples(x
-sampleModelTranslateX
,
436 y
-sampleModelTranslateY
,
437 w
, h
, b
, iArray
, dataBuffer
);
440 public float[] getSamples(int x
, int y
, int w
, int h
, int b
,
443 return sampleModel
.getSamples(x
-sampleModelTranslateX
,
444 y
-sampleModelTranslateY
,
445 w
, h
, b
, fArray
, dataBuffer
);
448 public double[] getSamples(int x
, int y
, int w
, int h
, int b
,
451 return sampleModel
.getSamples(x
-sampleModelTranslateX
,
452 y
-sampleModelTranslateY
,
453 w
, h
, b
, dArray
, dataBuffer
);