fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libjava / java / awt / image / Raster.java
blobff6033a6a036b147629f9affb0a667caa301c7c3
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)
8 any later version.
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
18 02111-1307 USA.
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.
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;
43 /**
44 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
46 public class Raster
48 protected SampleModel sampleModel;
49 protected DataBuffer dataBuffer;
50 protected int minX;
51 protected int minY;
52 protected int width;
53 protected int height;
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,
66 Point origin)
68 this(sampleModel, dataBuffer,
69 new Rectangle(origin.x, origin.y,
70 sampleModel.getWidth(), sampleModel.getHeight()),
71 origin, null);
74 protected Raster(SampleModel sampleModel, DataBuffer dataBuffer,
75 Rectangle aRegion,
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();
95 this.parent = parent;
98 public static WritableRaster createInterleavedRaster(int dataType,
99 int w, int h,
100 int bands,
101 Point location)
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,
113 int w, int h,
114 int scanlineStride,
115 int pixelStride,
116 int[] bandOffsets,
117 Point location)
119 SampleModel sm = new ComponentSampleModel(dataType,
120 w, h,
121 pixelStride,
122 scanlineStride,
123 bandOffsets);
124 return createWritableRaster(sm, location);
127 public static WritableRaster createBandedRaster(int dataType,
128 int w, int h, int bands,
129 Point location)
131 // FIXME: Implement;
132 throw new UnsupportedOperationException("not implemented yet");
135 public static WritableRaster createBandedRaster(int dataType,
136 int w, int h,
137 int scanlineStride,
138 int[] bankIndices,
139 int[] bandOffsets,
140 Point location)
142 // FIXME: Implement;
143 throw new UnsupportedOperationException("not implemented yet");
146 public static WritableRaster createPackedRaster(int dataType,
147 int w, int h,
148 int[] bandMasks,
149 Point location)
151 SampleModel sm = new SinglePixelPackedSampleModel(dataType,
152 w, h,
153 bandMasks);
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(),
163 w, h,
164 scanlineStride,
165 pixelStride,
166 bandOffsets);
167 return createWritableRaster(sm, dataBuffer, location);
170 public static
171 WritableRaster createBandedRaster(DataBuffer dataBuffer,
172 int w, int h,
173 int scanlineStride,
174 int[] bankIndices,
175 int[] bandOffsets,
176 Point location)
178 // FIXME: Implement;
179 throw new UnsupportedOperationException("not implemented yet");
182 public static WritableRaster
183 createPackedRaster(DataBuffer dataBuffer,
184 int w, int h,
185 int scanlineStride,
186 int[] bandMasks,
187 Point location) {
188 SampleModel sm =
189 new SinglePixelPackedSampleModel(dataBuffer.getDataType(),
190 w, h,
191 scanlineStride,
192 bandMasks);
193 return createWritableRaster(sm, dataBuffer, location);
196 public static Raster createRaster(SampleModel sm, DataBuffer db,
197 Point location)
199 return new Raster(sm, db, location);
202 public static WritableRaster createWritableRaster(SampleModel sm,
203 Point location)
205 return new WritableRaster(sm, location);
208 public static WritableRaster createWritableRaster(SampleModel sm,
209 DataBuffer db,
210 Point location)
212 return new WritableRaster(sm, db, location);
215 public Raster getParent()
217 return parent;
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,
247 int w, int h)
249 SampleModel sm = getSampleModel().createCompatibleSampleModel(w, h);
250 return new WritableRaster(sm, sm.createDataBuffer(),
251 new Point(x, y));
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,
260 width, height),
261 new Point(tcx, tcy),
262 this);
265 public Raster createChild(int parentX, int parentY, int width,
266 int height, int childMinX, int childMinY,
267 int[] bandList)
269 /* FIXME: Throw RasterFormatException if child bounds extends
270 beyond the bounds of this raster. */
272 SampleModel sm = (bandList == null) ?
273 sampleModel :
274 sampleModel.createSubsetSampleModel(bandList);
277 data origin
279 +-------------------------
280 |\. __ parent trans
281 | \`.
282 | \ `. parent origin
283 | \ `. /
284 | /\ +-------- - -
285 |trans\ /<\-- deltaTrans
286 |child +-+-\---- - -
287 | /|`| \__ parent [x, y]
288 |child | |`. \
289 |origin| : `.\
290 | | / `\
291 | : / +
292 | child [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,
301 width, height),
302 new Point(sampleModelTranslateX+childMinX-parentX,
303 sampleModelTranslateY+childMinY-parentY),
304 this);
307 public Rectangle getBounds()
309 return new Rectangle(minX, minY, width, height);
312 public final int getMinX()
314 return minX;
317 public final int getMinY()
319 return minY;
322 public final int getWidth()
324 return width;
327 public final int getHeight()
329 return height;
332 public final int getNumDataElements()
334 return numDataElements;
337 public final int getTransferType()
339 return sampleModel.getTransferType();
342 public DataBuffer getDataBuffer()
344 return dataBuffer;
347 public SampleModel getSampleModel()
349 return sampleModel;
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,
360 Object outData)
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,
371 iArray, dataBuffer);
374 public float[] getPixel(int x, int y, float[] fArray)
376 return sampleModel.getPixel(x-sampleModelTranslateX,
377 y-sampleModelTranslateY,
378 fArray, dataBuffer);
381 public double[] getPixel(int x, int y, double[] dArray)
383 return sampleModel.getPixel(x-sampleModelTranslateX,
384 y-sampleModelTranslateY,
385 dArray, dataBuffer);
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,
396 float[] fArray)
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,
404 double[] dArray)
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,
415 b, dataBuffer);
418 public float getSampleFloat(int x, int y, int b)
420 return sampleModel.getSampleFloat(x-sampleModelTranslateX,
421 y-sampleModelTranslateY,
422 b, dataBuffer);
425 public double getSampleDouble(int x, int y, int b)
427 return sampleModel.getSampleDouble(x-sampleModelTranslateX,
428 y-sampleModelTranslateY,
429 b, dataBuffer);
432 public int[] getSamples(int x, int y, int w, int h, int b,
433 int[] iArray)
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,
441 float[] fArray)
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,
449 double[] dArray)
451 return sampleModel.getSamples(x-sampleModelTranslateX,
452 y-sampleModelTranslateY,
453 w, h, b, dArray, dataBuffer);