e824ff92064abda862ee675f60ee53b41734167e
[jalviewjs.git] / site / swingjs / j2s / jssun / awt / image / IntegerComponentRaster.js
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 () {
4 this.bandOffset = 0;
5 this.dataOffsets = null;
6 this.scanlineStride = 0;
7 this.pixelStride = 0;
8 this.data = null;
9 this.numDataElems = 0;
10 this.type = 0;
11 this.maxX = 0;
12 this.maxY = 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$, 
26 function () {
27 Clazz.superConstructor (this, jssun.awt.image.IntegerComponentRaster, []);
28 });
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;
52 }}
53 this.type = (notByteBoundary ? 9 : 10);
54 this.scanlineStride = sppsm.getScanlineStride ();
55 this.pixelStride = 1;
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 ();
63 } else {
64 throw  new java.awt.image.RasterFormatException ("IntegerComponentRasters must have SinglePixelPackedSampleModel");
65 }this.verify ();
66 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,java.awt.image.Raster");
67 Clazz.defineMethod (c$, "getDataOffsets", 
68 function () {
69 return this.dataOffsets.clone ();
70 });
71 Clazz.defineMethod (c$, "getDataOffset", 
72 function (band) {
73 return this.dataOffsets[band];
74 }, "~N");
75 Clazz.defineMethod (c$, "getScanlineStride", 
76 function () {
77 return this.scanlineStride;
78 });
79 Clazz.defineMethod (c$, "getPixelStride", 
80 function () {
81 return this.pixelStride;
82 });
83 Clazz.defineMethod (c$, "getDataStorage", 
84 function () {
85 return this.data;
86 });
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!");
91 }var outData;
92 if (obj == null) {
93 outData =  Clazz.newIntArray (this.numDataElements, 0);
94 } else {
95 outData = obj;
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];
99 }
100 return outData;
101 }, "~N,~N,~O");
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!");
106 }var outData;
107 if (Clazz.instanceOf (obj, Array)) {
108 outData = obj;
109 } else {
110 outData =  Clazz.newIntArray (this.numDataElements * w * h, 0);
111 }var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
112 var xoff;
113 var off = 0;
114 var xstart;
115 var ystart;
116 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
117 xoff = yoff;
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];
121 }
122 }
123 }
124 return outData;
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!");
130 }var inData = obj;
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];
134 }
135 this.markDirty ();
136 }, "~N,~N,~O");
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) {
150 return;
151 }var srcOffX = inRaster.getMinX ();
152 var srcOffY = inRaster.getMinY ();
153 var tdata = null;
154 if (Clazz.instanceOf (inRaster, jssun.awt.image.IntegerComponentRaster) && (this.pixelStride == 1) && (this.numDataElements == 1)) {
155 var ict = inRaster;
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);
167 srcOffset += tss;
168 dstOffset += this.scanlineStride;
169 }
170 this.markDirty ();
171 return;
172 }}var odata = null;
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);
176 }
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!");
182 }var inData = obj;
183 var yoff = (y - this.minY) * this.scanlineStride + (x - this.minX) * this.pixelStride;
184 var xoff;
185 var off = 0;
186 var xstart;
187 var ystart;
188 for (ystart = 0; ystart < h; ystart++, yoff += this.scanlineStride) {
189 xoff = yoff;
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++];
193 }
194 }
195 }
196 this.markDirty ();
197 }, "~N,~N,~N,~N,~O");
198 Clazz.overrideMethod (c$, "createWritableChild", 
199 function (x, y, width, height, x0, y0, bandList) {
200 if (x < this.minX) {
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");
208 }var sm;
209 if (bandList != null) sm = this.sampleModel.createSubsetSampleModel (bandList);
210  else sm = this.sampleModel;
211 var deltaX = x0 - x;
212 var deltaY = y0 - y;
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", 
220 function (w, h) {
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));
225 }, "~N,~N");
226 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
227 function () {
228 return this.createCompatibleWritableRaster (this.width, this.height);
229 });
230 Clazz.defineMethod (c$, "verify", 
231 function () {
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;
250 var index;
251 var maxIndex = 0;
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) {
257 maxIndex = index;
258 }}
259 if (this.data.length <= maxIndex) {
260 throw  new java.awt.image.RasterFormatException ("Data array too small (should be > " + maxIndex + " )");
261 }});
262 Clazz.overrideMethod (c$, "toString", 
263 function () {
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]);
265 });
266 Clazz.defineStatics (c$,
267 "TYPE_CUSTOM", 0,
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);
279 });