FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / awt / image / WritableRaster.java
blob887ee8fa1cd90b702e5918660f403948dc8fdb96
1 /* Copyright (C) 2000, 2002 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. */
37 package java.awt.image;
39 import java.awt.*;
41 /**
42 * @author Rolf W. Rasmussen <rolfwr@ii.uib.no>
44 public class WritableRaster extends Raster
46 protected WritableRaster(SampleModel sampleModel, Point origin)
48 this(sampleModel, sampleModel.createDataBuffer(), origin);
51 protected WritableRaster(SampleModel sampleModel,
52 DataBuffer dataBuffer, Point origin)
54 this(sampleModel, dataBuffer,
55 new Rectangle(origin.x, origin.y,
56 sampleModel.getWidth(), sampleModel.getHeight()),
57 origin,
58 null);
61 protected WritableRaster(SampleModel sampleModel,
62 DataBuffer dataBuffer,
63 Rectangle aRegion,
64 Point sampleModelTranslate,
65 WritableRaster parent)
67 super(sampleModel, dataBuffer, aRegion, sampleModelTranslate,
68 parent);
71 public WritableRaster getWritableParent()
73 return (WritableRaster) getParent();
76 public WritableRaster createWritableTranslatedChild(int childMinX,
77 int childMinY)
79 // This mirrors the code from the super class
80 int tcx = sampleModelTranslateX - minX + childMinX;
81 int tcy = sampleModelTranslateY - minY + childMinY;
83 return new WritableRaster(sampleModel, dataBuffer,
84 new Rectangle(childMinX, childMinY,
85 width, height),
86 new Point(tcx, tcy),
87 this);
90 public WritableRaster createWritableChild(int parentX,
91 int parentY,
92 int w, int h,
93 int childMinX,
94 int childMinY,
95 int[] bandList)
97 // This mirrors the code from the super class
99 // FIXME: Throw RasterFormatException if child bounds extends
100 // beyond the bounds of this raster.
102 SampleModel sm = (bandList == null) ?
103 sampleModel :
104 sampleModel.createSubsetSampleModel(bandList);
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);
115 public void setDataElements(int x, int y, Object inData)
117 sampleModel.setDataElements(x-sampleModelTranslateX,
118 y-sampleModelTranslateY,
119 inData, dataBuffer);
122 public void setDataElements(int x, int y, Raster inRaster)
124 Object dataElements = getDataElements(0, 0,
125 inRaster.getWidth(),
126 inRaster.getHeight(),
127 null);
128 setDataElements(x, y, dataElements);
131 public void setDataElements(int x, int y, int w, int h,
132 Object inData)
134 sampleModel.setDataElements(x-sampleModelTranslateX,
135 y-sampleModelTranslateY,
136 w, h, inData, dataBuffer);
139 public void setRect(Raster srcRaster)
141 setRect(srcRaster, 0, 0);
144 public void setRect(Raster srcRaster, int dx, int dy)
146 Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX()+dx,
147 srcRaster.getMinY()+dy,
148 srcRaster.getWidth(),
149 srcRaster.getHeight());
151 Rectangle target = getBounds().intersection(targetUnclipped);
153 if (target.isEmpty()) return;
155 int sx = target.x - dx;
156 int sy = target.y - dy;
158 // FIXME: Do tests on rasters and use get/set data instead.
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.
166 But this is probably not the place to consider such
167 optimizations.*/
169 int[] pixels = srcRaster.getPixels(sx, sy,
170 target.width, target.height,
171 (int[]) null);
173 setPixels(target.x, target.y, target.width, target.height, pixels);
176 public void setPixel(int x, int y, int[] iArray)
178 sampleModel.setPixel(x-sampleModelTranslateX,
179 y-sampleModelTranslateY,
180 iArray, dataBuffer);
183 public void setPixel(int x, int y, float[] fArray)
185 sampleModel.setPixel(x-sampleModelTranslateX,
186 y-sampleModelTranslateY,
187 fArray, dataBuffer);
190 public void setPixel(int x, int y, double[] dArray)
192 sampleModel.setPixel(x-sampleModelTranslateX,
193 y-sampleModelTranslateY,
194 dArray, dataBuffer);
197 public void setPixels(int x, int y, int w, int h, int[] iArray)
199 sampleModel.setPixels(x-sampleModelTranslateX,
200 y-sampleModelTranslateY,
201 w, h, iArray, dataBuffer);
204 public void setPixels(int x, int y, int w, int h, float[] fArray)
206 sampleModel.setPixels(x-sampleModelTranslateX,
207 y-sampleModelTranslateY,
208 w, h, fArray, dataBuffer);
211 public void setPixels(int x, int y, int w, int h, double[] dArray)
213 sampleModel.setPixels(x-sampleModelTranslateX,
214 y-sampleModelTranslateY,
215 w, h, dArray, dataBuffer);
218 public void setSample(int x, int y, int b, int s)
220 sampleModel.setSample(x-sampleModelTranslateX,
221 y-sampleModelTranslateY,
222 b, s, dataBuffer);
225 public void setSample(int x, int y, int b, float s)
227 sampleModel.setSample(x-sampleModelTranslateX,
228 y-sampleModelTranslateY,
229 b, s, dataBuffer);
232 public void setSample(int x, int y, int b, double s)
234 sampleModel.setSample(x-sampleModelTranslateX,
235 y-sampleModelTranslateY,
236 b, s, dataBuffer);
239 public void setSamples(int x, int y, int w, int h, int b,
240 int[] iArray)
242 sampleModel.setSamples(x-sampleModelTranslateX,
243 y-sampleModelTranslateY,
244 w, h, b, iArray, dataBuffer);
247 public void setSamples(int x, int y, int w, int h, int b,
248 float[] fArray)
250 sampleModel.setSamples(x-sampleModelTranslateX,
251 y-sampleModelTranslateY,
252 w, h, b, fArray, dataBuffer);
255 public void setSamples(int x, int y, int w, int h, int b,
256 double[] dArray)
258 sampleModel.setSamples(x-sampleModelTranslateX,
259 y-sampleModelTranslateY,
260 w, h, b, dArray, dataBuffer);