1 Clazz.declarePackage ("java.awt.image");
2 Clazz.load (["java.awt.image.SampleModel"], "java.awt.image.SinglePixelPackedSampleModel", ["java.lang.ArrayIndexOutOfBoundsException", "$.IllegalArgumentException", "java.util.Arrays", "java.awt.image.DataBufferByte", "$.DataBufferInt", "$.RasterFormatException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
5 this.bitOffsets = null;
8 this.scanlineStride = 0;
9 Clazz.instantialize (this, arguments);
10 }, java.awt.image, "SinglePixelPackedSampleModel", java.awt.image.SampleModel);
11 Clazz.makeConstructor (c$,
12 function (dataType, w, h, bitMasks) {
13 this.construct (dataType, w, h, w, bitMasks);
14 if (dataType != 0 && dataType != 3) {
15 throw new IllegalArgumentException ("Unsupported data type " + dataType);
17 Clazz.makeConstructor (c$,
18 function (dataType, w, h, scanlineStride, bitMasks) {
19 Clazz.superConstructor (this, java.awt.image.SinglePixelPackedSampleModel, [dataType, w, h, bitMasks.length]);
20 if (dataType != 0 && dataType != 3) {
21 throw new IllegalArgumentException ("Unsupported data type " + dataType);
22 }this.dataType = dataType;
23 this.bitMasks = bitMasks.clone ();
24 this.scanlineStride = scanlineStride;
25 this.bitOffsets = Clazz.newIntArray (this.numBands, 0);
26 this.bitSizes = Clazz.newIntArray (this.numBands, 0);
28 for (var i = 0; i < this.numBands; i++) {
34 while ((mask & 1) == 0) {
38 while ((mask & 1) == 1) {
43 throw new IllegalArgumentException ("Mask " + bitMasks[i] + " must be contiguous");
44 }}this.bitOffsets[i] = bitOffset;
45 this.bitSizes[i] = bitSize;
46 if (bitSize > this.maxBitSize) {
47 this.maxBitSize = bitSize;
50 Clazz.overrideMethod (c$, "getNumDataElements",
54 Clazz.defineMethod (c$, "getBufferSize",
56 var size = this.scanlineStride * (this.height - 1) + this.width;
59 Clazz.overrideMethod (c$, "createCompatibleSampleModel",
61 var sampleModel = new java.awt.image.SinglePixelPackedSampleModel (this.dataType, w, h, this.bitMasks);
64 Clazz.overrideMethod (c$, "createDataBuffer",
66 var dataBuffer = null;
67 var size = this.getBufferSize ();
68 switch (this.dataType) {
70 dataBuffer = new java.awt.image.DataBufferByte (size);
73 dataBuffer = new java.awt.image.DataBufferInt (size);
78 Clazz.defineMethod (c$, "getSampleSize",
81 var sampleSize = Clazz.newIntArray (this.numBands, 0);
82 for (var i = 0; i < this.numBands; i++) {
84 mask = this.bitMasks[i] >>> this.bitOffsets[i];
85 while ((mask & 1) != 0) {
92 Clazz.defineMethod (c$, "getSampleSize",
95 var mask = this.bitMasks[band] >>> this.bitOffsets[band];
96 while ((mask & 1) != 0) {
102 Clazz.defineMethod (c$, "getOffset",
104 var offset = y * this.scanlineStride + x;
107 Clazz.defineMethod (c$, "getBitOffsets",
109 return this.bitOffsets.clone ();
111 Clazz.defineMethod (c$, "getBitMasks",
113 return this.bitMasks.clone ();
115 Clazz.defineMethod (c$, "getScanlineStride",
117 return this.scanlineStride;
119 Clazz.overrideMethod (c$, "createSubsetSampleModel",
121 if (bands.length > this.numBands) throw new java.awt.image.RasterFormatException ("There are only " + this.numBands + " bands");
122 var newBitMasks = Clazz.newIntArray (bands.length, 0);
123 for (var i = 0; i < bands.length; i++) newBitMasks[i] = this.bitMasks[bands[i]];
125 return new java.awt.image.SinglePixelPackedSampleModel (this.dataType, this.width, this.height, this.scanlineStride, newBitMasks);
127 Clazz.defineMethod (c$, "getDataElements",
128 function (x, y, obj, data) {
129 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
130 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
131 }var type = this.getTransferType ();
135 if (obj == null) bdata = Clazz.newByteArray (1, 0);
137 bdata[0] = data.getElem (y * this.scanlineStride + x);
142 if (obj == null) idata = Clazz.newIntArray (1, 0);
144 idata[0] = data.getElem (y * this.scanlineStride + x);
149 }, "~N,~N,~O,java.awt.image.DataBuffer");
150 Clazz.defineMethod (c$, "getPixel",
151 function (x, y, iArray, data) {
152 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
153 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
155 if (iArray == null) {
156 pixels = Clazz.newIntArray (this.numBands, 0);
159 }var value = data.getElem (y * this.scanlineStride + x);
160 for (var i = 0; i < this.numBands; i++) {
161 pixels[i] = (value & this.bitMasks[i]) >>> this.bitOffsets[i];
164 }, "~N,~N,~A,java.awt.image.DataBuffer");
165 Clazz.defineMethod (c$, "getPixels",
166 function (x, y, w, h, iArray, data) {
167 if ((x < 0) || (y < 0) || (x + w > this.width) || (y + h > this.height)) {
168 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
170 if (iArray != null) {
173 pixels = Clazz.newIntArray (w * h * this.numBands, 0);
174 }var lineOffset = y * this.scanlineStride + x;
176 for (var i = 0; i < h; i++) {
177 for (var j = 0; j < w; j++) {
178 var value = data.getElem (lineOffset + j);
179 for (var k = 0; k < this.numBands; k++) {
180 pixels[dstOffset++] = ((value & this.bitMasks[k]) >>> this.bitOffsets[k]);
183 lineOffset += this.scanlineStride;
186 }, "~N,~N,~N,~N,~A,java.awt.image.DataBuffer");
187 Clazz.overrideMethod (c$, "getSample",
188 function (x, y, b, data) {
189 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
190 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
191 }var sample = data.getElem (y * this.scanlineStride + x);
192 return ((sample & this.bitMasks[b]) >>> this.bitOffsets[b]);
193 }, "~N,~N,~N,java.awt.image.DataBuffer");
194 Clazz.defineMethod (c$, "getSamples",
195 function (x, y, w, h, b, iArray, data) {
196 if ((x < 0) || (y < 0) || (x + w > this.width) || (y + h > this.height)) {
197 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
199 if (iArray != null) {
202 samples = Clazz.newIntArray (w * h, 0);
203 }var lineOffset = y * this.scanlineStride + x;
205 for (var i = 0; i < h; i++) {
206 for (var j = 0; j < w; j++) {
207 var value = data.getElem (lineOffset + j);
208 samples[dstOffset++] = ((value & this.bitMasks[b]) >>> this.bitOffsets[b]);
210 lineOffset += this.scanlineStride;
213 }, "~N,~N,~N,~N,~N,~A,java.awt.image.DataBuffer");
214 Clazz.defineMethod (c$, "setDataElements",
215 function (x, y, obj, data) {
216 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
217 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
218 }var type = this.getTransferType ();
222 data.setElem (y * this.scanlineStride + x, (barray[0]) & 0xff);
226 data.setElem (y * this.scanlineStride + x, iarray[0]);
229 }, "~N,~N,~O,java.awt.image.DataBuffer");
230 Clazz.defineMethod (c$, "setPixel",
231 function (x, y, iArray, data) {
232 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
233 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
234 }var lineOffset = y * this.scanlineStride + x;
235 var value = data.getElem (lineOffset);
236 for (var i = 0; i < this.numBands; i++) {
237 value &= ~this.bitMasks[i];
238 value |= ((iArray[i] << this.bitOffsets[i]) & this.bitMasks[i]);
240 data.setElem (lineOffset, value);
241 }, "~N,~N,~A,java.awt.image.DataBuffer");
242 Clazz.defineMethod (c$, "setPixels",
243 function (x, y, w, h, iArray, data) {
244 if ((x < 0) || (y < 0) || (x + w > this.width) || (y + h > this.height)) {
245 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
246 }var lineOffset = y * this.scanlineStride + x;
248 for (var i = 0; i < h; i++) {
249 for (var j = 0; j < w; j++) {
250 var value = data.getElem (lineOffset + j);
251 for (var k = 0; k < this.numBands; k++) {
252 value &= ~this.bitMasks[k];
253 var srcValue = iArray[srcOffset++];
254 value |= ((srcValue << this.bitOffsets[k]) & this.bitMasks[k]);
256 data.setElem (lineOffset + j, value);
258 lineOffset += this.scanlineStride;
260 }, "~N,~N,~N,~N,~A,java.awt.image.DataBuffer");
261 Clazz.defineMethod (c$, "setSample",
262 function (x, y, b, s, data) {
263 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
264 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
265 }var value = data.getElem (y * this.scanlineStride + x);
266 value &= ~this.bitMasks[b];
267 value |= (s << this.bitOffsets[b]) & this.bitMasks[b];
268 data.setElem (y * this.scanlineStride + x, value);
269 }, "~N,~N,~N,~N,java.awt.image.DataBuffer");
270 Clazz.defineMethod (c$, "setSamples",
271 function (x, y, w, h, b, iArray, data) {
272 if ((x < 0) || (y < 0) || (x + w > this.width) || (y + h > this.height)) {
273 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
274 }var lineOffset = y * this.scanlineStride + x;
276 for (var i = 0; i < h; i++) {
277 for (var j = 0; j < w; j++) {
278 var value = data.getElem (lineOffset + j);
279 value &= ~this.bitMasks[b];
280 var sample = iArray[srcOffset++];
281 value |= (sample << this.bitOffsets[b]) & this.bitMasks[b];
282 data.setElem (lineOffset + j, value);
284 lineOffset += this.scanlineStride;
286 }, "~N,~N,~N,~N,~N,~A,java.awt.image.DataBuffer");
287 Clazz.overrideMethod (c$, "equals",
289 if ((o == null) || !(Clazz.instanceOf (o, java.awt.image.SinglePixelPackedSampleModel))) {
292 return this.width == that.width && this.height == that.height && this.numBands == that.numBands && this.dataType == that.dataType && java.util.Arrays.equals (this.bitMasks, that.bitMasks) && java.util.Arrays.equals (this.bitOffsets, that.bitOffsets) && java.util.Arrays.equals (this.bitSizes, that.bitSizes) && this.maxBitSize == that.maxBitSize && this.scanlineStride == that.scanlineStride;
294 Clazz.overrideMethod (c$, "hashCode",
301 hash ^= this.numBands;
303 hash ^= this.dataType;
305 for (var i = 0; i < this.bitMasks.length; i++) {
306 hash ^= this.bitMasks[i];
309 for (var i = 0; i < this.bitOffsets.length; i++) {
310 hash ^= this.bitOffsets[i];
313 for (var i = 0; i < this.bitSizes.length; i++) {
314 hash ^= this.bitSizes[i];
317 hash ^= this.maxBitSize;
319 hash ^= this.scanlineStride;