f31d19b6e492fb4fc4c0c9e579caf8415626fa42
[jalviewjs.git] / site / j2s / jssun / awt / image / ByteComponentRaster.js
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 () {
4 this.bandOffset = 0;
5 this.dataOffsets = null;
6 this.scanlineStride = 0;
7 this.pixelStride = 0;
8 this.data = null;
9 this.type = 0;
10 this.maxX = 0;
11 this.maxY = 0;
12 Clazz.instantialize (this, arguments);
13 }, jssun.awt.image, "ByteComponentRaster", jssun.awt.image.SunWritableRaster);
14 Clazz.makeConstructor (c$, 
15 function () {
16 Clazz.superConstructor (this, jssun.awt.image.ByteComponentRaster, []);
17 });
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 ();
48 this.pixelStride = 1;
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;
54 } else {
55 throw  new java.awt.image.RasterFormatException ("IntegerComponentRasters must have ComponentSampleModel or SinglePixelPackedSampleModel");
56 }this.bandOffset = this.dataOffsets[0];
57 this.verify ();
58 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,jssun.awt.image.ByteComponentRaster");
59 Clazz.defineMethod (c$, "getDataOffsets", 
60 function () {
61 return this.dataOffsets.clone ();
62 });
63 Clazz.defineMethod (c$, "getDataOffset", 
64 function (band) {
65 return this.dataOffsets[band];
66 }, "~N");
67 Clazz.defineMethod (c$, "getScanlineStride", 
68 function () {
69 return this.scanlineStride;
70 });
71 Clazz.defineMethod (c$, "getPixelStride", 
72 function () {
73 return this.pixelStride;
74 });
75 Clazz.defineMethod (c$, "getDataStorage", 
76 function () {
77 return this.data;
78 });
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!");
83 }var outData;
84 if (obj == null) {
85 outData =  Clazz.newByteArray (this.numDataElements, 0);
86 } else {
87 outData = obj;
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];
91 }
92 return outData;
93 }, "~N,~N,~O");
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!");
98 }var outData;
99 if (obj == null) {
100 outData =  Clazz.newByteArray (w * h * this.numDataElements, 0);
101 } else {
102 outData = obj;
103 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
104 var xoff;
105 var off = 0;
106 var xstart;
107 var ystart;
108 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
109 xoff = yoff;
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];
113 }
114 }
115 }
116 return outData;
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];
125 var xoff;
126 var off = 0;
127 var xstart;
128 var ystart;
129 if (this.pixelStride == 1) {
130 if (this.scanlineStride == w) {
131 System.arraycopy (this.data, yoff, outData, 0, w * h);
132 } else {
133 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
134 System.arraycopy (this.data, yoff, outData, off, w);
135 off += w;
136 }
137 }} else {
138 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
139 xoff = yoff;
140 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
141 outData[off++] = this.data[xoff];
142 }
143 }
144 }return outData;
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;
153 var xoff;
154 var off = 0;
155 var xstart;
156 var ystart;
157 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
158 xoff = yoff;
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];
162 }
163 }
164 }
165 return outData;
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!");
171 }var inData = obj;
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];
175 }
176 this.markDirty ();
177 }, "~N,~N,~O");
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) {
191 return;
192 }var srcOffX = inRaster.getMinX ();
193 var srcOffY = inRaster.getMinY ();
194 var tdata = null;
195 if (Clazz.instanceOf (inRaster, jssun.awt.image.ByteComponentRaster)) {
196 var bct = inRaster;
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);
207 srcOffset += tss;
208 dstOffset += this.scanlineStride;
209 }
210 this.markDirty ();
211 return;
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);
215 }
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!");
221 }var inData = obj;
222 var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
223 var xoff;
224 var off = 0;
225 var xstart;
226 var ystart;
227 if (this.numDataElements == 1) {
228 var srcOffset = 0;
229 var dstOffset = yoff + this.dataOffsets[0];
230 for (ystart = 0; ystart < h; ystart++) {
231 xoff = yoff;
232 System.arraycopy (inData, srcOffset, this.data, dstOffset, w);
233 srcOffset += w;
234 dstOffset += this.scanlineStride;
235 }
236 this.markDirty ();
237 return;
238 }for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
239 xoff = yoff;
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++];
243 }
244 }
245 }
246 this.markDirty ();
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];
253 var xoff;
254 var off = 0;
255 var xstart;
256 var ystart;
257 if (this.pixelStride == 1) {
258 if (this.scanlineStride == w) {
259 System.arraycopy (inData, 0, this.data, yoff, w * h);
260 } else {
261 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
262 System.arraycopy (inData, off, this.data, yoff, w);
263 off += w;
264 }
265 }} else {
266 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
267 xoff = yoff;
268 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
269 this.data[xoff] = inData[off++];
270 }
271 }
272 }this.markDirty ();
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;
279 var xoff;
280 var off = 0;
281 var xstart;
282 var ystart;
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);
288 } else {
289 for (ystart = 0; ystart < h; ystart++) {
290 System.arraycopy (inData, off, this.data, yoff, w);
291 off += w;
292 yoff += this.scanlineStride;
293 }
294 }} else {
295 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
296 xoff = yoff;
297 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
298 this.data[xoff] = inData[off++];
299 }
300 }
301 }} else {
302 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
303 xoff = yoff;
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++];
307 }
308 }
309 }
310 }this.markDirty ();
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);
315 return newRaster;
316 }, "~N,~N,~N,~N,~N,~N,~A");
317 Clazz.overrideMethod (c$, "createWritableChild", 
318 function (x, y, width, height, x0, y0, bandList) {
319 if (x < this.minX) {
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");
327 }var sm;
328 if (bandList != null) sm = this.sampleModel.createSubsetSampleModel (bandList);
329  else sm = this.sampleModel;
330 var deltaX = x0 - x;
331 var deltaY = y0 - y;
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", 
335 function (w, h) {
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));
340 }, "~N,~N");
341 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
342 function () {
343 return this.createCompatibleWritableRaster (this.width, this.height);
344 });
345 Clazz.defineMethod (c$, "verify", 
346 function () {
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");
352 }}
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;
367 var index;
368 var maxIndex = 0;
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) {
374 maxIndex = index;
375 }}
376 if (this.data.length <= maxIndex) {
377 throw  new java.awt.image.RasterFormatException ("Data array too small (should be > " + maxIndex + " )");
378 }});
379 Clazz.overrideMethod (c$, "toString", 
380 function () {
381 return  String.instantialize ("ByteComponentRaster: width = " + this.width + " height = " + this.height + " #numDataElements " + this.numDataElements + " dataOff[0] = " + this.dataOffsets[0]);
382 });
383 });