Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / java / awt / image / WritableRaster.java
blobde3648af5f349df9daf4d65c758148b1a21b2866
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 WritableRaster extends Raster
48 protected WritableRaster(SampleModel sampleModel, Point origin)
50 this(sampleModel, sampleModel.createDataBuffer(), origin);
53 protected WritableRaster(SampleModel sampleModel,
54 DataBuffer dataBuffer, Point origin)
56 this(sampleModel, dataBuffer,
57 new Rectangle(origin != null ? origin.x : 0,
58 origin != null ? origin.y : 0,
59 sampleModel.getWidth(), sampleModel.getHeight()),
60 origin,
61 null);
64 protected WritableRaster(SampleModel sampleModel,
65 DataBuffer dataBuffer,
66 Rectangle aRegion,
67 Point sampleModelTranslate,
68 WritableRaster parent)
70 super(sampleModel, dataBuffer, aRegion, sampleModelTranslate,
71 parent);
74 public WritableRaster getWritableParent()
76 return (WritableRaster) getParent();
79 public WritableRaster createWritableTranslatedChild(int childMinX,
80 int childMinY)
82 // This mirrors the code from the super class
83 int tcx = sampleModelTranslateX - minX + childMinX;
84 int tcy = sampleModelTranslateY - minY + childMinY;
86 return new WritableRaster(sampleModel, dataBuffer,
87 new Rectangle(childMinX, childMinY,
88 width, height),
89 new Point(tcx, tcy),
90 this);
93 public WritableRaster createWritableChild(int parentX,
94 int parentY,
95 int w, int h,
96 int childMinX,
97 int childMinY,
98 int[] bandList)
100 // This mirrors the code from the super class
102 // FIXME: Throw RasterFormatException if child bounds extends
103 // beyond the bounds of this raster.
105 SampleModel sm = (bandList == null) ?
106 sampleModel :
107 sampleModel.createSubsetSampleModel(bandList);
109 return new
110 WritableRaster(sm, dataBuffer,
111 new Rectangle(childMinX, childMinY,
112 w, h),
113 new Point(sampleModelTranslateX+childMinX-parentX,
114 sampleModelTranslateY+childMinY-parentY),
115 this);
118 public void setDataElements(int x, int y, Object inData)
120 sampleModel.setDataElements(x-sampleModelTranslateX,
121 y-sampleModelTranslateY,
122 inData, dataBuffer);
125 public void setDataElements(int x, int y, Raster inRaster)
127 Object dataElements = getDataElements(0, 0,
128 inRaster.getWidth(),
129 inRaster.getHeight(),
130 null);
131 setDataElements(x, y, dataElements);
134 public void setDataElements(int x, int y, int w, int h,
135 Object inData)
137 sampleModel.setDataElements(x-sampleModelTranslateX,
138 y-sampleModelTranslateY,
139 w, h, inData, dataBuffer);
142 public void setRect(Raster srcRaster)
144 setRect(0, 0, srcRaster);
147 public void setRect(int dx, int dy, Raster srcRaster)
149 Rectangle targetUnclipped = new Rectangle(srcRaster.getMinX()+dx,
150 srcRaster.getMinY()+dy,
151 srcRaster.getWidth(),
152 srcRaster.getHeight());
154 Rectangle target = getBounds().intersection(targetUnclipped);
156 if (target.isEmpty()) return;
158 int sx = target.x - dx;
159 int sy = target.y - dy;
161 // FIXME: Do tests on rasters and use get/set data instead.
163 /* The JDK documentation seems to imply this implementation.
164 (the trucation of higher bits), but an implementation using
165 get/setDataElements would be more efficient. None of the
166 implementations would do anything sensible when the sample
167 models don't match.
169 But this is probably not the place to consider such
170 optimizations.*/
172 int[] pixels = srcRaster.getPixels(sx, sy,
173 target.width, target.height,
174 (int[]) null);
176 setPixels(target.x, target.y, target.width, target.height, pixels);
179 public void setPixel(int x, int y, int[] iArray)
181 sampleModel.setPixel(x-sampleModelTranslateX,
182 y-sampleModelTranslateY,
183 iArray, dataBuffer);
186 public void setPixel(int x, int y, float[] fArray)
188 sampleModel.setPixel(x-sampleModelTranslateX,
189 y-sampleModelTranslateY,
190 fArray, dataBuffer);
193 public void setPixel(int x, int y, double[] dArray)
195 sampleModel.setPixel(x-sampleModelTranslateX,
196 y-sampleModelTranslateY,
197 dArray, dataBuffer);
200 public void setPixels(int x, int y, int w, int h, int[] iArray)
202 sampleModel.setPixels(x-sampleModelTranslateX,
203 y-sampleModelTranslateY,
204 w, h, iArray, dataBuffer);
207 public void setPixels(int x, int y, int w, int h, float[] fArray)
209 sampleModel.setPixels(x-sampleModelTranslateX,
210 y-sampleModelTranslateY,
211 w, h, fArray, dataBuffer);
214 public void setPixels(int x, int y, int w, int h, double[] dArray)
216 sampleModel.setPixels(x-sampleModelTranslateX,
217 y-sampleModelTranslateY,
218 w, h, dArray, dataBuffer);
221 public void setSample(int x, int y, int b, int s)
223 sampleModel.setSample(x-sampleModelTranslateX,
224 y-sampleModelTranslateY,
225 b, s, dataBuffer);
228 public void setSample(int x, int y, int b, float s)
230 sampleModel.setSample(x-sampleModelTranslateX,
231 y-sampleModelTranslateY,
232 b, s, dataBuffer);
235 public void setSample(int x, int y, int b, double s)
237 sampleModel.setSample(x-sampleModelTranslateX,
238 y-sampleModelTranslateY,
239 b, s, dataBuffer);
242 public void setSamples(int x, int y, int w, int h, int b,
243 int[] iArray)
245 sampleModel.setSamples(x-sampleModelTranslateX,
246 y-sampleModelTranslateY,
247 w, h, b, iArray, dataBuffer);
250 public void setSamples(int x, int y, int w, int h, int b,
251 float[] fArray)
253 sampleModel.setSamples(x-sampleModelTranslateX,
254 y-sampleModelTranslateY,
255 w, h, b, fArray, dataBuffer);
258 public void setSamples(int x, int y, int w, int h, int b,
259 double[] dArray)
261 sampleModel.setSamples(x-sampleModelTranslateX,
262 y-sampleModelTranslateY,
263 w, h, b, dArray, dataBuffer);