1 Clazz.declarePackage ("jssun.awt.image");
2 Clazz.load (["jssun.awt.image.SunWritableRaster"], "jssun.awt.image.IntegerComponentRaster", ["java.lang.ArrayIndexOutOfBoundsException", "java.awt.Point", "$.Rectangle", "java.awt.image.DataBufferInt", "$.RasterFormatException", "$.SinglePixelPackedSampleModel"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.dataOffsets = null;
6 this.scanlineStride = 0;
13 Clazz.instantialize (this, arguments);
14 }, jssun.awt.image, "IntegerComponentRaster", jssun.awt.image.SunWritableRaster);
15 Clazz.makeConstructor (c$,
16 function (sampleModel, origin) {
17 Clazz.superConstructor (this, jssun.awt.image.IntegerComponentRaster, []);
18 this.setIntCompRaster (sampleModel, sampleModel.createDataBuffer (), new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
19 }, "java.awt.image.SampleModel,java.awt.Point");
20 Clazz.makeConstructor (c$,
21 function (sampleModel, dataBuffer, origin) {
22 Clazz.superConstructor (this, jssun.awt.image.IntegerComponentRaster, []);
23 this.setIntCompRaster (sampleModel, dataBuffer, new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
24 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Point");
25 Clazz.makeConstructor (c$,
27 Clazz.superConstructor (this, jssun.awt.image.IntegerComponentRaster, []);
29 Clazz.makeConstructor (c$,
30 function (sampleModel, dataBuffer, aRegion, origin, parent) {
31 Clazz.superConstructor (this, jssun.awt.image.IntegerComponentRaster, []);
32 this.setIntCompRaster (sampleModel, dataBuffer, aRegion, origin, parent);
33 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,java.awt.image.Raster");
34 Clazz.defineMethod (c$, "setIntCompRaster",
35 function (sampleModel, dataBuffer, aRegion, origin, parent) {
36 this.setSunRaster (sampleModel, dataBuffer, aRegion, origin, parent);
37 this.maxX = this.minX + this.width;
38 this.maxY = this.minY + this.height;
39 if (!(Clazz.instanceOf (dataBuffer, java.awt.image.DataBufferInt))) {
40 throw new java.awt.image.RasterFormatException ("IntegerComponentRasters must haveinteger DataBuffers");
41 }var dbi = dataBuffer;
42 if (dbi.getNumBanks () != 1) {
43 throw new java.awt.image.RasterFormatException ("DataBuffer for IntegerComponentRasters must only have 1 bank.");
44 }this.data = jssun.awt.image.SunWritableRaster.stealData (dbi, 0);
45 if (Clazz.instanceOf (sampleModel, java.awt.image.SinglePixelPackedSampleModel)) {
46 var sppsm = sampleModel;
47 var boffsets = sppsm.getBitOffsets ();
48 var notByteBoundary = false;
49 for (var i = 1; i < boffsets.length; i++) {
50 if ((boffsets[i] % 8) != 0) {
51 notByteBoundary = true;
53 this.type = (notByteBoundary ? 9 : 10);
54 this.scanlineStride = sppsm.getScanlineStride ();
56 this.dataOffsets = Clazz.newIntArray (1, 0);
57 this.dataOffsets[0] = dbi.getOffset ();
58 this.bandOffset = this.dataOffsets[0];
59 var xOffset = aRegion.x - origin.x;
60 var yOffset = aRegion.y - origin.y;
61 this.dataOffsets[0] += xOffset + yOffset * this.scanlineStride;
62 this.numDataElems = sppsm.getNumDataElements ();
64 throw new java.awt.image.RasterFormatException ("IntegerComponentRasters must have SinglePixelPackedSampleModel");
66 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,java.awt.image.Raster");
67 Clazz.defineMethod (c$, "getDataOffsets",
69 return this.dataOffsets.clone ();
71 Clazz.defineMethod (c$, "getDataOffset",
73 return this.dataOffsets[band];
75 Clazz.defineMethod (c$, "getScanlineStride",
77 return this.scanlineStride;
79 Clazz.defineMethod (c$, "getPixelStride",
81 return this.pixelStride;
83 Clazz.defineMethod (c$, "getDataStorage",
87 Clazz.defineMethod (c$, "getDataElements",
88 function (x, y, obj) {
89 if ((x < this.minX) || (y < this.minY) || (x >= this.maxX) || (y >= this.maxY)) {
90 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
93 outData = Clazz.newIntArray (this.numDataElements, 0);
96 }var off = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
97 for (var band = 0; band < this.numDataElements; band++) {
98 outData[band] = this.data[this.dataOffsets[band] + off];
102 Clazz.defineMethod (c$, "getDataElements",
103 function (x, y, w, h, obj) {
104 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
105 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
107 if (Clazz.instanceOf (obj, Array)) {
110 outData = Clazz.newIntArray (this.numDataElements * w * h, 0);
111 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
116 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
118 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
119 for (var c = 0; c < this.numDataElements; c++) {
120 outData[off++] = this.data[this.dataOffsets[c] + xoff];
125 }, "~N,~N,~N,~N,~O");
126 Clazz.defineMethod (c$, "setDataElements",
127 function (x, y, obj) {
128 if ((x < this.minX) || (y < this.minY) || (x >= this.maxX) || (y >= this.maxY)) {
129 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
131 var off = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
132 for (var i = 0; i < this.numDataElements; i++) {
133 this.data[this.dataOffsets[i] + off] = inData[i];
137 Clazz.overrideMethod (c$, "setDataElementsRaster",
138 function (x, y, inRaster) {
139 var dstOffX = x + inRaster.getMinX ();
140 var dstOffY = y + inRaster.getMinY ();
141 var width = inRaster.getWidth ();
142 var height = inRaster.getHeight ();
143 if ((dstOffX < this.minX) || (dstOffY < this.minY) || (dstOffX + width > this.maxX) || (dstOffY + height > this.maxY)) {
144 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
145 }this.setDataElementsRaster4 (dstOffX, dstOffY, width, height, inRaster);
146 }, "~N,~N,java.awt.image.Raster");
147 Clazz.defineMethod (c$, "setDataElementsRaster4",
148 function (dstX, dstY, width, height, inRaster) {
149 if (width <= 0 || height <= 0) {
151 }var srcOffX = inRaster.getMinX ();
152 var srcOffY = inRaster.getMinY ();
154 if (Clazz.instanceOf (inRaster, jssun.awt.image.IntegerComponentRaster) && (this.pixelStride == 1) && (this.numDataElements == 1)) {
156 if (ict.getNumDataElements () != 1) {
157 throw new ArrayIndexOutOfBoundsException ("Number of bands does not match");
158 }tdata = ict.getDataStorage ();
159 var tss = ict.getScanlineStride ();
160 var toff = ict.getDataOffset (0);
161 var srcOffset = toff;
162 var dstOffset = this.dataOffsets[0] + (dstY - this.minY) * this.scanlineStride + (dstX - this.minX);
163 if (ict.getPixelStride () == this.pixelStride) {
164 width *= this.pixelStride;
165 for (var startY = 0; startY < height; startY++) {
166 System.arraycopy (tdata, srcOffset, this.data, dstOffset, width);
168 dstOffset += this.scanlineStride;
173 for (var startY = 0; startY < height; startY++) {
174 odata = inRaster.getDataElements (srcOffX, srcOffY + startY, width, 1, odata);
175 this.setDataElements (dstX, dstY + startY, width, 1, odata);
177 }, "~N,~N,~N,~N,java.awt.image.Raster");
178 Clazz.defineMethod (c$, "setDataElements",
179 function (x, y, w, h, obj) {
180 if ((x < this.minX) || (y < this.minY) || (x + w > this.maxX) || (y + h > this.maxY)) {
181 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
183 var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
188 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
190 for (xstart = 0; xstart < w; xstart++, xoff += this.pixelStride) {
191 for (var c = 0; c < this.numDataElements; c++) {
192 this.data[this.dataOffsets[c] + xoff] = inData[off++];
197 }, "~N,~N,~N,~N,~O");
198 Clazz.overrideMethod (c$, "createWritableChild",
199 function (x, y, width, height, x0, y0, bandList) {
201 throw new java.awt.image.RasterFormatException ("x lies outside raster");
202 }if (y < this.minY) {
203 throw new java.awt.image.RasterFormatException ("y lies outside raster");
204 }if ((x + width < x) || (x + width > this.minX + this.width)) {
205 throw new java.awt.image.RasterFormatException ("(x + width) is outside raster");
206 }if ((y + height < y) || (y + height > this.minY + this.height)) {
207 throw new java.awt.image.RasterFormatException ("(y + height) is outside raster");
209 if (bandList != null) sm = this.sampleModel.createSubsetSampleModel (bandList);
210 else sm = this.sampleModel;
213 return new jssun.awt.image.IntegerComponentRaster (sm, this.dataBuffer, new java.awt.Rectangle (x0, y0, width, height), new java.awt.Point (this.sampleModelTranslateX + deltaX, this.sampleModelTranslateY + deltaY), this);
214 }, "~N,~N,~N,~N,~N,~N,~A");
215 Clazz.overrideMethod (c$, "createChild",
216 function (x, y, width, height, x0, y0, bandList) {
217 return this.createWritableChild (x, y, width, height, x0, y0, bandList);
218 }, "~N,~N,~N,~N,~N,~N,~A");
219 Clazz.defineMethod (c$, "createCompatibleWritableRaster",
221 if (w <= 0 || h <= 0) {
222 throw new java.awt.image.RasterFormatException ("negative " + ((w <= 0) ? "width" : "height"));
223 }var sm = this.sampleModel.createCompatibleSampleModel (w, h);
224 return new jssun.awt.image.IntegerComponentRaster (sm, new java.awt.Point (0, 0));
226 Clazz.defineMethod (c$, "createCompatibleWritableRaster",
228 return this.createCompatibleWritableRaster (this.width, this.height);
230 Clazz.defineMethod (c$, "verify",
232 if (this.width <= 0 || this.height <= 0 || this.height > (Clazz.doubleToInt (2147483647 / this.width))) {
233 throw new java.awt.image.RasterFormatException ("Invalid raster dimension");
234 }if (this.dataOffsets[0] < 0) {
235 throw new java.awt.image.RasterFormatException ("Data offset (" + this.dataOffsets[0] + ") must be >= 0");
236 }if (this.minX - this.sampleModelTranslateX < 0 || this.minY - this.sampleModelTranslateY < 0) {
237 throw new java.awt.image.RasterFormatException ("Incorrect origin/translate: (" + this.minX + ", " + this.minY + ") / (" + this.sampleModelTranslateX + ", " + this.sampleModelTranslateY + ")");
238 }if (this.scanlineStride < 0 || this.scanlineStride > (Clazz.doubleToInt (2147483647 / this.height))) {
239 throw new java.awt.image.RasterFormatException ("Incorrect scanline stride: " + this.scanlineStride);
240 }if (this.height > 1 || this.minY - this.sampleModelTranslateY > 0) {
241 if (this.scanlineStride > this.data.length) {
242 throw new java.awt.image.RasterFormatException ("Incorrect scanline stride: " + this.scanlineStride);
243 }}var lastScanOffset = (this.height - 1) * this.scanlineStride;
244 if (this.pixelStride < 0 || this.pixelStride > (Clazz.doubleToInt (2147483647 / this.width)) || this.pixelStride > this.data.length) {
245 throw new java.awt.image.RasterFormatException ("Incorrect pixel stride: " + this.pixelStride);
246 }var lastPixelOffset = (this.width - 1) * this.pixelStride;
247 if (lastPixelOffset > (2147483647 - lastScanOffset)) {
248 throw new java.awt.image.RasterFormatException ("Incorrect raster attributes");
249 }lastPixelOffset += lastScanOffset;
252 for (var i = 0; i < this.numDataElements; i++) {
253 if (this.dataOffsets[i] > (2147483647 - lastPixelOffset)) {
254 throw new java.awt.image.RasterFormatException ("Incorrect band offset: " + this.dataOffsets[i]);
255 }index = lastPixelOffset + this.dataOffsets[i];
256 if (index > maxIndex) {
259 if (this.data.length <= maxIndex) {
260 throw new java.awt.image.RasterFormatException ("Data array too small (should be > " + maxIndex + " )");
262 Clazz.overrideMethod (c$, "toString",
264 return String.instantialize ("IntegerComponentRaster: width = " + this.width + " height = " + this.height + " #Bands = " + this.numBands + " #DataElements " + this.numDataElements + " xOff = " + this.sampleModelTranslateX + " yOff = " + this.sampleModelTranslateY + " dataOffset[0] " + this.dataOffsets[0]);
266 Clazz.defineStatics (c$,
268 "TYPE_BYTE_SAMPLES", 1,
269 "TYPE_USHORT_SAMPLES", 2,
270 "TYPE_INT_SAMPLES", 3,
271 "TYPE_BYTE_BANDED_SAMPLES", 4,
272 "TYPE_USHORT_BANDED_SAMPLES", 5,
273 "TYPE_INT_BANDED_SAMPLES", 6,
274 "TYPE_BYTE_PACKED_SAMPLES", 7,
275 "TYPE_USHORT_PACKED_SAMPLES", 8,
276 "TYPE_INT_PACKED_SAMPLES", 9,
277 "TYPE_INT_8BIT_SAMPLES", 10,
278 "TYPE_BYTE_BINARY_SAMPLES", 11);