1 Clazz.declarePackage ("jssun.awt.image");
2 Clazz.load (["jssun.awt.image.SunWritableRaster"], "jssun.awt.image.ByteComponentRaster", ["java.lang.ArrayIndexOutOfBoundsException", "java.awt.Point", "$.Rectangle", "java.awt.image.DataBufferByte", "$.RasterFormatException", "$.SinglePixelPackedSampleModel"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.dataOffsets = null;
6 this.scanlineStride = 0;
12 Clazz.instantialize (this, arguments);
13 }, jssun.awt.image, "ByteComponentRaster", jssun.awt.image.SunWritableRaster);
14 Clazz.makeConstructor (c$,
16 Clazz.superConstructor (this, jssun.awt.image.ByteComponentRaster, []);
18 Clazz.makeConstructor (c$,
19 function (sampleModel, origin) {
20 Clazz.superConstructor (this, jssun.awt.image.ByteComponentRaster, []);
21 this.setByteCompRaster (sampleModel, sampleModel.createDataBuffer (), new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
22 }, "java.awt.image.SampleModel,java.awt.Point");
23 Clazz.makeConstructor (c$,
24 function (sampleModel, dataBuffer, origin) {
25 Clazz.superConstructor (this, jssun.awt.image.ByteComponentRaster, []);
26 this.setByteCompRaster (sampleModel, dataBuffer, new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
27 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Point");
28 Clazz.makeConstructor (c$,
29 function (sampleModel, dataBuffer, aRegion, origin, parent) {
30 Clazz.superConstructor (this, jssun.awt.image.ByteComponentRaster, []);
31 this.setByteCompRaster (sampleModel, dataBuffer, aRegion, origin, parent);
32 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,jssun.awt.image.ByteComponentRaster");
33 Clazz.defineMethod (c$, "setByteCompRaster",
34 function (sampleModel, dataBuffer, aRegion, origin, parent) {
35 this.setSunRaster (sampleModel, dataBuffer, aRegion, origin, parent);
36 this.maxX = this.minX + this.width;
37 this.maxY = this.minY + this.height;
38 if (!(Clazz.instanceOf (dataBuffer, java.awt.image.DataBufferByte))) {
39 throw new java.awt.image.RasterFormatException ("ByteComponentRasters must have byte DataBuffers");
40 }var dbb = dataBuffer;
41 this.data = jssun.awt.image.SunWritableRaster.stealData (dbb, 0);
42 if (dbb.getNumBanks () != 1) {
43 throw new java.awt.image.RasterFormatException ("DataBuffer for ByteComponentRasters must only have 1 bank.");
44 }var dbOffset = dbb.getOffset ();
45 if (Clazz.instanceOf (sampleModel, java.awt.image.SinglePixelPackedSampleModel)) {
46 var sppsm = sampleModel;
47 this.scanlineStride = sppsm.getScanlineStride ();
49 this.dataOffsets = Clazz.newIntArray (1, 0);
50 this.dataOffsets[0] = dbOffset;
51 var xOffset = aRegion.x - origin.x;
52 var yOffset = aRegion.y - origin.y;
53 this.dataOffsets[0] += xOffset * this.pixelStride + yOffset * this.scanlineStride;
55 throw new java.awt.image.RasterFormatException ("IntegerComponentRasters must have ComponentSampleModel or SinglePixelPackedSampleModel");
56 }this.bandOffset = this.dataOffsets[0];
58 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,jssun.awt.image.ByteComponentRaster");
59 Clazz.defineMethod (c$, "getDataOffsets",
61 return this.dataOffsets.clone ();
63 Clazz.defineMethod (c$, "getDataOffset",
65 return this.dataOffsets[band];
67 Clazz.defineMethod (c$, "getScanlineStride",
69 return this.scanlineStride;
71 Clazz.defineMethod (c$, "getPixelStride",
73 return this.pixelStride;
75 Clazz.defineMethod (c$, "getDataStorage",
79 Clazz.defineMethod (c$, "getDataElements",
80 function (x, y, obj) {
81 if ((x < this.minX) || (y < this.minY) || (x >= this.maxX) || (y >= this.maxY)) {
82 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
85 outData = Clazz.newByteArray (this.numDataElements, 0);
88 }var off = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
89 for (var band = 0; band < this.numDataElements; band++) {
90 outData[band] = this.data[this.dataOffsets[band] + off];
94 Clazz.defineMethod (c$, "getDataElements",
95 function (x, y, w, h, obj) {
96 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
97 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
100 outData = Clazz.newByteArray (w * h * this.numDataElements, 0);
103 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
108 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
110 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
111 for (var c = 0; c < this.numDataElements; c++) {
112 outData[off++] = this.data[this.dataOffsets[c] + xoff];
117 }, "~N,~N,~N,~N,~O");
118 Clazz.defineMethod (c$, "getByteData",
119 function (x, y, w, h, band, outData) {
120 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
121 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
122 }if (outData == null) {
123 outData = Clazz.newByteArray (this.scanlineStride * h, 0);
124 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride + this.dataOffsets[band];
129 if (this.pixelStride == 1) {
130 if (this.scanlineStride == w) {
131 System.arraycopy (this.data, yoff, outData, 0, w * h);
133 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
134 System.arraycopy (this.data, yoff, outData, off, w);
138 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
140 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
141 outData[off++] = this.data[xoff];
145 }, "~N,~N,~N,~N,~N,~A");
146 Clazz.defineMethod (c$, "getByteData",
147 function (x, y, w, h, outData) {
148 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
149 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
150 }if (outData == null) {
151 outData = Clazz.newByteArray (this.numDataElements * this.scanlineStride * h, 0);
152 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
157 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
159 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
160 for (var c = 0; c < this.numDataElements; c++) {
161 outData[off++] = this.data[this.dataOffsets[c] + xoff];
166 }, "~N,~N,~N,~N,~A");
167 Clazz.defineMethod (c$, "setDataElements",
168 function (x, y, obj) {
169 if ((x < this.minX) || (y < this.minY) || (x >= this.maxX) || (y >= this.maxY)) {
170 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
172 var off = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
173 for (var i = 0; i < this.numDataElements; i++) {
174 this.data[this.dataOffsets[i] + off] = inData[i];
178 Clazz.defineMethod (c$, "setDataElements",
179 function (x, y, inRaster) {
180 var dstOffX = inRaster.getMinX () + x;
181 var dstOffY = inRaster.getMinY () + y;
182 var width = inRaster.getWidth ();
183 var height = inRaster.getHeight ();
184 if ((dstOffX < this.minX) || (dstOffY < this.minY) || (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
185 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
186 }this.setDataElements (dstOffX, dstOffY, width, height, inRaster);
187 }, "~N,~N,java.awt.image.Raster");
188 Clazz.defineMethod (c$, "setDataElements",
189 function (dstX, dstY, width, height, inRaster) {
190 if (width <= 0 || height <= 0) {
192 }var srcOffX = inRaster.getMinX ();
193 var srcOffY = inRaster.getMinY ();
195 if (Clazz.instanceOf (inRaster, jssun.awt.image.ByteComponentRaster)) {
197 var bdata = bct.getDataStorage ();
198 if (this.numDataElements == 1) {
199 var toff = bct.getDataOffset (0);
200 var tss = bct.getScanlineStride ();
201 var srcOffset = toff;
202 var dstOffset = this.dataOffsets[0] + (dstY - this.minY) * this.scanlineStride + (dstX - this.minX);
203 if (this.pixelStride == bct.getPixelStride ()) {
204 width *= this.pixelStride;
205 for (var tmpY = 0; tmpY < height; tmpY++) {
206 System.arraycopy (bdata, srcOffset, this.data, dstOffset, width);
208 dstOffset += this.scanlineStride;
212 }}}for (var startY = 0; startY < height; startY++) {
213 tdata = inRaster.getDataElements (srcOffX, srcOffY + startY, width, 1, tdata);
214 this.setDataElements (dstX, dstY + startY, width, 1, tdata);
216 }, "~N,~N,~N,~N,java.awt.image.Raster");
217 Clazz.defineMethod (c$, "setDataElements",
218 function (x, y, w, h, obj) {
219 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
220 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
222 var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
227 if (this.numDataElements == 1) {
229 var dstOffset = yoff + this.dataOffsets[0];
230 for (ystart = 0; ystart < h; ystart++) {
232 System.arraycopy (inData, srcOffset, this.data, dstOffset, w);
234 dstOffset += this.scanlineStride;
238 }for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
240 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
241 for (var c = 0; c < this.numDataElements; c++) {
242 this.data[this.dataOffsets[c] + xoff] = inData[off++];
247 }, "~N,~N,~N,~N,~O");
248 Clazz.defineMethod (c$, "putByteData",
249 function (x, y, w, h, band, inData) {
250 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
251 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
252 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride + this.dataOffsets[band];
257 if (this.pixelStride == 1) {
258 if (this.scanlineStride == w) {
259 System.arraycopy (inData, 0, this.data, yoff, w * h);
261 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
262 System.arraycopy (inData, off, this.data, yoff, w);
266 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
268 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
269 this.data[xoff] = inData[off++];
273 }, "~N,~N,~N,~N,~N,~A");
274 Clazz.defineMethod (c$, "putByteData",
275 function (x, y, w, h, inData) {
276 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
277 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
278 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
283 if (this.numDataElements == 1) {
284 yoff += this.dataOffsets[0];
285 if (this.pixelStride == 1) {
286 if (this.scanlineStride == w) {
287 System.arraycopy (inData, 0, this.data, yoff, w * h);
289 for (ystart = 0; ystart < h; ystart++) {
290 System.arraycopy (inData, off, this.data, yoff, w);
292 yoff += this.scanlineStride;
295 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
297 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
298 this.data[xoff] = inData[off++];
302 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
304 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
305 for (var c = 0; c < this.numDataElements; c++) {
306 this.data[this.dataOffsets[c] + xoff] = inData[off++];
311 }, "~N,~N,~N,~N,~A");
312 Clazz.overrideMethod (c$, "createChild",
313 function (x, y, width, height, x0, y0, bandList) {
314 var newRaster = this.createWritableChild (x, y, width, height, x0, y0, bandList);
316 }, "~N,~N,~N,~N,~N,~N,~A");
317 Clazz.overrideMethod (c$, "createWritableChild",
318 function (x, y, width, height, x0, y0, bandList) {
320 throw new java.awt.image.RasterFormatException ("x lies outside the raster");
321 }if (y < this.minY) {
322 throw new java.awt.image.RasterFormatException ("y lies outside the raster");
323 }if ((x + width < x) || (x + width > this.minX + this.width)) {
324 throw new java.awt.image.RasterFormatException ("(x + width) is outside of Raster");
325 }if ((y + height < y) || (y + height > this.minY + this.height)) {
326 throw new java.awt.image.RasterFormatException ("(y + height) is outside of Raster");
328 if (bandList != null) sm = this.sampleModel.createSubsetSampleModel (bandList);
329 else sm = this.sampleModel;
332 return new jssun.awt.image.ByteComponentRaster (sm, this.dataBuffer, new java.awt.Rectangle (x0, y0, width, height), new java.awt.Point (this.sampleModelTranslateX + deltaX, this.sampleModelTranslateY + deltaY), this);
333 }, "~N,~N,~N,~N,~N,~N,~A");
334 Clazz.defineMethod (c$, "createCompatibleWritableRaster",
336 if (w <= 0 || h <= 0) {
337 throw new java.awt.image.RasterFormatException ("negative " + ((w <= 0) ? "width" : "height"));
338 }var sm = this.sampleModel.createCompatibleSampleModel (w, h);
339 return new jssun.awt.image.ByteComponentRaster (sm, new java.awt.Point (0, 0));
341 Clazz.defineMethod (c$, "createCompatibleWritableRaster",
343 return this.createCompatibleWritableRaster (this.width, this.height);
345 Clazz.defineMethod (c$, "verify",
347 if (this.width <= 0 || this.height <= 0 || this.height > (Clazz.doubleToInt (2147483647 / this.width))) {
348 throw new java.awt.image.RasterFormatException ("Invalid raster dimension");
349 }for (var i = 0; i < this.dataOffsets.length; i++) {
350 if (this.dataOffsets[i] < 0) {
351 throw new java.awt.image.RasterFormatException ("Data offsets for band " + i + "(" + this.dataOffsets[i] + ") must be >= 0");
353 if (this.minX - this.sampleModelTranslateX < 0 || this.minY - this.sampleModelTranslateY < 0) {
354 throw new java.awt.image.RasterFormatException ("Incorrect origin/translate: (" + this.minX + ", " + this.minY + ") / (" + this.sampleModelTranslateX + ", " + this.sampleModelTranslateY + ")");
355 }if (this.scanlineStride < 0 || this.scanlineStride > (Clazz.doubleToInt (2147483647 / this.height))) {
356 throw new java.awt.image.RasterFormatException ("Incorrect scanline stride: " + this.scanlineStride);
357 }if (this.height > 1 || this.minY - this.sampleModelTranslateY > 0) {
358 if (this.scanlineStride > this.data.length) {
359 throw new java.awt.image.RasterFormatException ("Incorrect scanline stride: " + this.scanlineStride);
360 }}var lastScanOffset = (this.height - 1) * this.scanlineStride;
361 if (this.pixelStride < 0 || this.pixelStride > (Clazz.doubleToInt (2147483647 / this.width)) || this.pixelStride > this.data.length) {
362 throw new java.awt.image.RasterFormatException ("Incorrect pixel stride: " + this.pixelStride);
363 }var lastPixelOffset = (this.width - 1) * this.pixelStride;
364 if (lastPixelOffset > (2147483647 - lastScanOffset)) {
365 throw new java.awt.image.RasterFormatException ("Incorrect raster attributes");
366 }lastPixelOffset += lastScanOffset;
369 for (var i = 0; i < this.numDataElements; i++) {
370 if (this.dataOffsets[i] > (2147483647 - lastPixelOffset)) {
371 throw new java.awt.image.RasterFormatException ("Incorrect band offset: " + this.dataOffsets[i]);
372 }index = lastPixelOffset + this.dataOffsets[i];
373 if (index > maxIndex) {
376 if (this.data.length <= maxIndex) {
377 throw new java.awt.image.RasterFormatException ("Data array too small (should be > " + maxIndex + " )");
379 Clazz.overrideMethod (c$, "toString",
381 return String.instantialize ("ByteComponentRaster: width = " + this.width + " height = " + this.height + " #numDataElements " + this.numDataElements + " dataOff[0] = " + this.dataOffsets[0]);