Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / image / Raster.js
1 Clazz.declarePackage ("java.awt.image");
2 Clazz.load (["java.awt.image.MultiPixelPackedSampleModel", "$.SinglePixelPackedSampleModel"], "java.awt.image.Raster", ["java.lang.IllegalArgumentException", "$.NullPointerException", "java.awt.Point", "$.Rectangle", "java.awt.image.DataBuffer", "$.DataBufferByte", "$.DataBufferInt", "$.RasterFormatException", "swingjs.api.Interface"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.sampleModel = null;
5 this.dataBuffer = null;
6 this.minX = 0;
7 this.minY = 0;
8 this.width = 0;
9 this.height = 0;
10 this.sampleModelTranslateX = 0;
11 this.sampleModelTranslateY = 0;
12 this.numBands = 0;
13 this.numDataElements = 0;
14 this.parent = null;
15 Clazz.instantialize (this, arguments);
16 }, java.awt.image, "Raster");
17 c$.createPackedRaster = Clazz.defineMethod (c$, "createPackedRaster", 
18 function (dataType, w, h, bandMasks, location) {
19 var d;
20 switch (dataType) {
21 case 0:
22 d =  new java.awt.image.DataBufferByte (w * h);
23 break;
24 case 3:
25 d =  new java.awt.image.DataBufferInt (w * h);
26 break;
27 default:
28 throw  new IllegalArgumentException ("Unsupported data type " + dataType);
29 }
30 return java.awt.image.Raster.createPackedRaster (d, w, h, w, bandMasks, location);
31 }, "~N,~N,~N,~A,java.awt.Point");
32 c$.createPackedRaster = Clazz.defineMethod (c$, "createPackedRaster", 
33 function (dataType, w, h, bands, bitsPerBand, location) {
34 var d;
35 if (bands <= 0) {
36 throw  new IllegalArgumentException ("Number of bands (" + bands + ") must be greater than 0");
37 }if (bitsPerBand <= 0) {
38 throw  new IllegalArgumentException ("Bits per band (" + bitsPerBand + ") must be greater than 0");
39 }if (bands != 1) {
40 var masks =  Clazz.newIntArray (bands, 0);
41 var mask = (1 << bitsPerBand) - 1;
42 var shift = (bands - 1) * bitsPerBand;
43 if (shift + bitsPerBand > java.awt.image.DataBuffer.getDataTypeSize (dataType)) {
44 throw  new IllegalArgumentException ("bitsPerBand(" + bitsPerBand + ") * bands is " + " greater than data type " + "size.");
45 }switch (dataType) {
46 case 0:
47 case 3:
48 break;
49 default:
50 throw  new IllegalArgumentException ("Unsupported data type " + dataType);
51 }
52 for (var i = 0; i < bands; i++) {
53 masks[i] = mask << shift;
54 shift = shift - bitsPerBand;
55 }
56 return java.awt.image.Raster.createPackedRaster (dataType, w, h, masks, location);
57 } else {
58 var fw = w;
59 switch (dataType) {
60 case 0:
61 d =  new java.awt.image.DataBufferByte (Clazz.doubleToInt (Math.ceil (fw / (Clazz.doubleToInt (8 / bitsPerBand)))) * h);
62 break;
63 case 3:
64 d =  new java.awt.image.DataBufferInt (Clazz.doubleToInt (Math.ceil (fw / (Clazz.doubleToInt (32 / bitsPerBand)))) * h);
65 break;
66 default:
67 throw  new IllegalArgumentException ("Unsupported data type " + dataType);
68 }
69 return java.awt.image.Raster.createPackedRaster (d, w, h, bitsPerBand, location);
70 }}, "~N,~N,~N,~N,~N,java.awt.Point");
71 c$.createPackedRaster = Clazz.defineMethod (c$, "createPackedRaster", 
72 function (dataBuffer, w, h, scanlineStride, bandMasks, location) {
73 if (dataBuffer == null) {
74 throw  new NullPointerException ("DataBuffer cannot be null");
75 }if (location == null) {
76 location =  new java.awt.Point (0, 0);
77 }var dataType = dataBuffer.getDataType ();
78 var sppsm =  new java.awt.image.SinglePixelPackedSampleModel (dataType, w, h, scanlineStride, bandMasks);
79 switch (dataType) {
80 case 0:
81 case 3:
82 break;
83 default:
84 throw  new IllegalArgumentException ("Unsupported data type " + dataType);
85 }
86 var r = swingjs.api.Interface.getInstance ("jssun.awt.image." + (dataType == 0 ? "Byte" : "Integer") + "InterleavedRaster", true);
87 r.setParams (sppsm, dataBuffer, location);
88 return r;
89 }, "java.awt.image.DataBuffer,~N,~N,~N,~A,java.awt.Point");
90 c$.createPackedRaster = Clazz.defineMethod (c$, "createPackedRaster", 
91 function (dataBuffer, w, h, bitsPerPixel, location) {
92 if (dataBuffer == null) {
93 throw  new NullPointerException ("DataBuffer cannot be null");
94 }if (location == null) {
95 location =  new java.awt.Point (0, 0);
96 }var dataType = dataBuffer.getDataType ();
97 if (dataType != 0 && dataType != 3) {
98 throw  new IllegalArgumentException ("Unsupported data type " + dataType);
99 }if (dataBuffer.getNumBanks () != 1) {
100 throw  new java.awt.image.RasterFormatException ("DataBuffer for packed Rasters must only have 1 bank.");
101 }var mppsm =  new java.awt.image.MultiPixelPackedSampleModel (dataType, w, h, bitsPerPixel);
102 if (dataType == 0 && (bitsPerPixel == 1 || bitsPerPixel == 2 || bitsPerPixel == 4)) {
103 return  new jssun.awt.image.BytePackedRaster (mppsm, dataBuffer, location);
104 } else {
105 return  new jssun.awt.image.SunWritableRaster (mppsm, dataBuffer, location);
106 }}, "java.awt.image.DataBuffer,~N,~N,~N,java.awt.Point");
107 c$.createRaster = Clazz.defineMethod (c$, "createRaster", 
108 function (sm, db, location) {
109 if ((sm == null) || (db == null)) {
110 throw  new NullPointerException ("SampleModel and DataBuffer cannot be null");
111 }if (location == null) {
112 location =  new java.awt.Point (0, 0);
113 }var dataType = sm.getDataType ();
114 if (Clazz.instanceOf (sm, java.awt.image.MultiPixelPackedSampleModel) && dataType == 0 && sm.getSampleSize (0) < 8) {
115 return  new jssun.awt.image.BytePackedRaster (sm, db, location);
116 }return  new java.awt.image.Raster (sm, db, location);
117 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Point");
118 c$.createWritableRaster = Clazz.defineMethod (c$, "createWritableRaster", 
119 function (sm, location) {
120 if (location == null) {
121 location =  new java.awt.Point (0, 0);
122 }return java.awt.image.Raster.createWritableRaster (sm, sm.createDataBuffer (), location);
123 }, "java.awt.image.SampleModel,java.awt.Point");
124 c$.createWritableRaster = Clazz.defineMethod (c$, "createWritableRaster", 
125 function (sm, db, location) {
126 if ((sm == null) || (db == null)) {
127 throw  new NullPointerException ("SampleModel and DataBuffer cannot be null");
128 }if (location == null) {
129 location =  new java.awt.Point (0, 0);
130 }var dataType = sm.getDataType ();
131 if (Clazz.instanceOf (sm, java.awt.image.MultiPixelPackedSampleModel) && dataType == 0 && sm.getSampleSize (0) < 8) {
132 return  new jssun.awt.image.BytePackedRaster (sm, db, location);
133 }return  new jssun.awt.image.SunWritableRaster (sm, db, location);
134 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Point");
135 Clazz.makeConstructor (c$, 
136 function (sampleModel, origin) {
137 this.setRaster (sampleModel, sampleModel.createDataBuffer (),  new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
138 }, "java.awt.image.SampleModel,java.awt.Point");
139 Clazz.makeConstructor (c$, 
140 function (sampleModel, dataBuffer, origin) {
141 this.setRaster (sampleModel, dataBuffer,  new java.awt.Rectangle (origin.x, origin.y, sampleModel.getWidth (), sampleModel.getHeight ()), origin, null);
142 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Point");
143 Clazz.makeConstructor (c$, 
144 function () {
145 });
146 Clazz.makeConstructor (c$, 
147 function (sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent) {
148 this.setRaster (sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent);
149 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,java.awt.image.Raster");
150 Clazz.defineMethod (c$, "setRaster", 
151 function (sampleModel, dataBuffer, aRegion, sampleModelTranslate, parent) {
152 if ((sampleModel == null) || (dataBuffer == null) || (aRegion == null) || (sampleModelTranslate == null)) {
153 throw  new NullPointerException ("SampleModel, dataBuffer, aRegion and sampleModelTranslate cannot be null");
154 }this.sampleModel = sampleModel;
155 this.dataBuffer = dataBuffer;
156 this.minX = aRegion.x;
157 this.minY = aRegion.y;
158 this.width = aRegion.width;
159 this.height = aRegion.height;
160 if (this.width <= 0 || this.height <= 0) {
161 throw  new java.awt.image.RasterFormatException ("negative or zero " + ((this.width <= 0) ? "width" : "height"));
162 }if ((this.minX + this.width) < this.minX) {
163 throw  new java.awt.image.RasterFormatException ("overflow condition for X coordinates of Raster");
164 }if ((this.minY + this.height) < this.minY) {
165 throw  new java.awt.image.RasterFormatException ("overflow condition for Y coordinates of Raster");
166 }this.sampleModelTranslateX = sampleModelTranslate.x;
167 this.sampleModelTranslateY = sampleModelTranslate.y;
168 this.numBands = sampleModel.getNumBands ();
169 this.numDataElements = sampleModel.getNumDataElements ();
170 this.parent = parent;
171 }, "java.awt.image.SampleModel,java.awt.image.DataBuffer,java.awt.Rectangle,java.awt.Point,java.awt.image.Raster");
172 Clazz.defineMethod (c$, "getParent", 
173 function () {
174 return this.parent;
175 });
176 Clazz.defineMethod (c$, "getSampleModelTranslateX", 
177 function () {
178 return this.sampleModelTranslateX;
179 });
180 Clazz.defineMethod (c$, "getSampleModelTranslateY", 
181 function () {
182 return this.sampleModelTranslateY;
183 });
184 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
185 function () {
186 return  new jssun.awt.image.SunWritableRaster (this.sampleModel,  new java.awt.Point (0, 0));
187 });
188 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
189 function (w, h) {
190 if (w <= 0 || h <= 0) {
191 throw  new java.awt.image.RasterFormatException ("negative " + ((w <= 0) ? "width" : "height"));
192 }var sm = this.sampleModel.createCompatibleSampleModel (w, h);
193 return  new jssun.awt.image.SunWritableRaster (sm,  new java.awt.Point (0, 0));
194 }, "~N,~N");
195 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
196 function (rect) {
197 if (rect == null) {
198 throw  new NullPointerException ("Rect cannot be null");
199 }return this.createCompatibleWritableRaster (rect.x, rect.y, rect.width, rect.height);
200 }, "java.awt.Rectangle");
201 Clazz.defineMethod (c$, "createCompatibleWritableRaster", 
202 function (x, y, w, h) {
203 var ret = this.createCompatibleWritableRaster (w, h);
204 return ret.createWritableChild (0, 0, w, h, x, y, null);
205 }, "~N,~N,~N,~N");
206 Clazz.defineMethod (c$, "createTranslatedChild", 
207 function (childMinX, childMinY) {
208 return this.createChild (this.minX, this.minY, this.width, this.height, childMinX, childMinY, null);
209 }, "~N,~N");
210 Clazz.defineMethod (c$, "createChild", 
211 function (parentX, parentY, width, height, childMinX, childMinY, bandList) {
212 if (parentX < this.minX) {
213 throw  new java.awt.image.RasterFormatException ("parentX lies outside raster");
214 }if (parentY < this.minY) {
215 throw  new java.awt.image.RasterFormatException ("parentY lies outside raster");
216 }if ((parentX + width < parentX) || (parentX + width > this.width + this.minX)) {
217 throw  new java.awt.image.RasterFormatException ("(parentX + width) is outside raster");
218 }if ((parentY + height < parentY) || (parentY + height > this.height + this.minY)) {
219 throw  new java.awt.image.RasterFormatException ("(parentY + height) is outside raster");
220 }var subSampleModel;
221 if (bandList == null) {
222 subSampleModel = this.sampleModel;
223 } else {
224 subSampleModel = this.sampleModel.createSubsetSampleModel (bandList);
225 }var deltaX = childMinX - parentX;
226 var deltaY = childMinY - parentY;
227 return  new java.awt.image.Raster (subSampleModel, this.getDataBuffer (),  new java.awt.Rectangle (childMinX, childMinY, width, height),  new java.awt.Point (this.sampleModelTranslateX + deltaX, this.sampleModelTranslateY + deltaY), this);
228 }, "~N,~N,~N,~N,~N,~N,~A");
229 Clazz.defineMethod (c$, "getBounds", 
230 function () {
231 return  new java.awt.Rectangle (this.minX, this.minY, this.width, this.height);
232 });
233 Clazz.defineMethod (c$, "getMinX", 
234 function () {
235 return this.minX;
236 });
237 Clazz.defineMethod (c$, "getMinY", 
238 function () {
239 return this.minY;
240 });
241 Clazz.defineMethod (c$, "getWidth", 
242 function () {
243 return this.width;
244 });
245 Clazz.defineMethod (c$, "getHeight", 
246 function () {
247 return this.height;
248 });
249 Clazz.defineMethod (c$, "getNumBands", 
250 function () {
251 return this.numBands;
252 });
253 Clazz.defineMethod (c$, "getNumDataElements", 
254 function () {
255 return this.sampleModel.getNumDataElements ();
256 });
257 Clazz.defineMethod (c$, "getTransferType", 
258 function () {
259 return this.sampleModel.getTransferType ();
260 });
261 Clazz.defineMethod (c$, "getDataBuffer", 
262 function () {
263 return this.dataBuffer;
264 });
265 Clazz.defineMethod (c$, "getSampleModel", 
266 function () {
267 return this.sampleModel;
268 });
269 Clazz.defineMethod (c$, "getDataElements", 
270 function (x, y, outData) {
271 return this.sampleModel.getDataElements (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, outData, this.dataBuffer);
272 }, "~N,~N,~O");
273 Clazz.defineMethod (c$, "getDataElements", 
274 function (x, y, w, h, outData) {
275 return this.sampleModel.getDataElements (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, outData, this.dataBuffer);
276 }, "~N,~N,~N,~N,~O");
277 Clazz.defineMethod (c$, "getPixel", 
278 function (x, y, iArray) {
279 return this.sampleModel.getPixel (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, iArray, this.dataBuffer);
280 }, "~N,~N,~A");
281 Clazz.defineMethod (c$, "getPixel", 
282 function (x, y, fArray) {
283 return this.sampleModel.getPixel (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, fArray, this.dataBuffer);
284 }, "~N,~N,~A");
285 Clazz.defineMethod (c$, "getPixel", 
286 function (x, y, dArray) {
287 return this.sampleModel.getPixel (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, dArray, this.dataBuffer);
288 }, "~N,~N,~A");
289 Clazz.defineMethod (c$, "getPixels", 
290 function (x, y, w, h, iArray) {
291 return this.sampleModel.getPixels (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, iArray, this.dataBuffer);
292 }, "~N,~N,~N,~N,~A");
293 Clazz.defineMethod (c$, "getPixels", 
294 function (x, y, w, h, fArray) {
295 return this.sampleModel.getPixels (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, fArray, this.dataBuffer);
296 }, "~N,~N,~N,~N,~A");
297 Clazz.defineMethod (c$, "getPixels", 
298 function (x, y, w, h, dArray) {
299 return this.sampleModel.getPixels (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, dArray, this.dataBuffer);
300 }, "~N,~N,~N,~N,~A");
301 Clazz.defineMethod (c$, "getSample", 
302 function (x, y, b) {
303 return this.sampleModel.getSample (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, b, this.dataBuffer);
304 }, "~N,~N,~N");
305 Clazz.defineMethod (c$, "getSampleFloat", 
306 function (x, y, b) {
307 return this.sampleModel.getSampleFloat (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, b, this.dataBuffer);
308 }, "~N,~N,~N");
309 Clazz.defineMethod (c$, "getSampleDouble", 
310 function (x, y, b) {
311 return this.sampleModel.getSampleDouble (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, b, this.dataBuffer);
312 }, "~N,~N,~N");
313 Clazz.defineMethod (c$, "getSamples", 
314 function (x, y, w, h, b, iArray) {
315 return this.sampleModel.getSamples (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, b, iArray, this.dataBuffer);
316 }, "~N,~N,~N,~N,~N,~A");
317 Clazz.defineMethod (c$, "getSamples", 
318 function (x, y, w, h, b, fArray) {
319 return this.sampleModel.getSamples (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, b, fArray, this.dataBuffer);
320 }, "~N,~N,~N,~N,~N,~A");
321 Clazz.defineMethod (c$, "getSamples", 
322 function (x, y, w, h, b, dArray) {
323 return this.sampleModel.getSamples (x - this.sampleModelTranslateX, y - this.sampleModelTranslateY, w, h, b, dArray, this.dataBuffer);
324 }, "~N,~N,~N,~N,~N,~A");
325 });