1 Clazz.declarePackage ("java.awt.image");
2 Clazz.load (["java.awt.image.SampleModel"], "java.awt.image.MultiPixelPackedSampleModel", ["java.lang.ArrayIndexOutOfBoundsException", "$.IllegalArgumentException", "java.awt.image.DataBuffer", "$.DataBufferByte", "$.DataBufferInt", "$.RasterFormatException"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.pixelBitStride = 0;
6 this.pixelsPerDataElement = 0;
7 this.dataElementSize = 0;
8 this.dataBitOffset = 0;
9 this.scanlineStride = 0;
10 Clazz.instantialize (this, arguments);
11 }, java.awt.image, "MultiPixelPackedSampleModel", java.awt.image.SampleModel);
12 Clazz.makeConstructor (c$,
13 function (dataType, w, h, numberOfBits) {
14 this.construct (dataType, w, h, numberOfBits, Clazz.doubleToInt ((w * numberOfBits + java.awt.image.DataBuffer.getDataTypeSize (dataType) - 1) / java.awt.image.DataBuffer.getDataTypeSize (dataType)), 0);
15 if (dataType != 0 && dataType != 3) {
16 throw new IllegalArgumentException ("Unsupported data type " + dataType);
18 Clazz.makeConstructor (c$,
19 function (dataType, w, h, numberOfBits, scanlineStride, dataBitOffset) {
20 Clazz.superConstructor (this, java.awt.image.MultiPixelPackedSampleModel, [dataType, w, h, 1]);
21 if (dataType != 0 && dataType != 3) {
22 throw new IllegalArgumentException ("Unsupported data type " + dataType);
23 }this.dataType = dataType;
24 this.pixelBitStride = numberOfBits;
25 this.scanlineStride = scanlineStride;
26 this.dataBitOffset = dataBitOffset;
27 this.dataElementSize = java.awt.image.DataBuffer.getDataTypeSize (dataType);
28 this.pixelsPerDataElement = Clazz.doubleToInt (this.dataElementSize / numberOfBits);
29 if (this.pixelsPerDataElement * numberOfBits != this.dataElementSize) {
30 throw new java.awt.image.RasterFormatException ("MultiPixelPackedSampleModel does not allow pixels to span data element boundaries");
31 }this.bitMask = (1 << numberOfBits) - 1;
32 }, "~N,~N,~N,~N,~N,~N");
33 Clazz.overrideMethod (c$, "createCompatibleSampleModel",
35 var sampleModel = new java.awt.image.MultiPixelPackedSampleModel (this.dataType, w, h, this.pixelBitStride);
38 Clazz.overrideMethod (c$, "createDataBuffer",
40 var dataBuffer = null;
41 var size = this.scanlineStride * this.height;
42 switch (this.dataType) {
44 dataBuffer = new java.awt.image.DataBufferByte (size + Clazz.doubleToInt ((this.dataBitOffset + 7) / 8));
47 dataBuffer = new java.awt.image.DataBufferInt (size + Clazz.doubleToInt ((this.dataBitOffset + 31) / 32));
52 Clazz.overrideMethod (c$, "getNumDataElements",
56 Clazz.defineMethod (c$, "getSampleSize",
58 var sampleSize = Clazz.newIntArray (-1, [this.pixelBitStride]);
61 Clazz.defineMethod (c$, "getSampleSize",
63 return this.pixelBitStride;
65 Clazz.defineMethod (c$, "getOffset",
67 var offset = y * this.scanlineStride;
68 offset += Clazz.doubleToInt ((x * this.pixelBitStride + this.dataBitOffset) / this.dataElementSize);
71 Clazz.defineMethod (c$, "getBitOffset",
73 return (x * this.pixelBitStride + this.dataBitOffset) % this.dataElementSize;
75 Clazz.defineMethod (c$, "getScanlineStride",
77 return this.scanlineStride;
79 Clazz.defineMethod (c$, "getPixelBitStride",
81 return this.pixelBitStride;
83 Clazz.defineMethod (c$, "getDataBitOffset",
85 return this.dataBitOffset;
87 Clazz.overrideMethod (c$, "getTransferType",
91 Clazz.overrideMethod (c$, "createSubsetSampleModel",
94 if (bands.length != 1) throw new java.awt.image.RasterFormatException ("MultiPixelPackedSampleModel has only one band.");
95 }var sm = this.createCompatibleSampleModel (this.width, this.height);
98 Clazz.overrideMethod (c$, "getSample",
99 function (x, y, b, data) {
100 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height) || (b != 0)) {
101 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
102 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;
103 var element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
104 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
105 return (element >> shift) & this.bitMask;
106 }, "~N,~N,~N,java.awt.image.DataBuffer");
107 Clazz.defineMethod (c$, "setSample",
108 function (x, y, b, s, data) {
109 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height) || (b != 0)) {
110 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
111 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;
112 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));
113 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
114 var element = data.getElem (index);
115 element &= ~(this.bitMask << shift);
116 element |= (s & this.bitMask) << shift;
117 data.setElem (index, element);
118 }, "~N,~N,~N,~N,java.awt.image.DataBuffer");
119 Clazz.defineMethod (c$, "getDataElements",
120 function (x, y, obj, data) {
121 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
122 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
123 }var type = this.getTransferType ();
124 var bitnum = this.dataBitOffset + x * this.pixelBitStride;
125 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
130 if (obj == null) bdata = Clazz.newByteArray (1, 0);
132 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
133 bdata[0] = ((element >> shift) & this.bitMask);
138 if (obj == null) idata = Clazz.newIntArray (1, 0);
140 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
141 idata[0] = (element >> shift) & this.bitMask;
146 }, "~N,~N,~O,java.awt.image.DataBuffer");
147 Clazz.defineMethod (c$, "getPixel",
148 function (x, y, iArray, data) {
149 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
150 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
152 if (iArray != null) {
155 pixels = Clazz.newIntArray (this.numBands, 0);
156 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;
157 var element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
158 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
159 pixels[0] = (element >> shift) & this.bitMask;
161 }, "~N,~N,~A,java.awt.image.DataBuffer");
162 Clazz.defineMethod (c$, "setDataElements",
163 function (x, y, obj, data) {
164 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
165 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
166 }var type = this.getTransferType ();
167 var bitnum = this.dataBitOffset + x * this.pixelBitStride;
168 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));
169 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
170 var element = data.getElem (index);
171 element &= ~(this.bitMask << shift);
175 element |= (((barray[0]) & 0xff) & this.bitMask) << shift;
176 data.setElem (index, element);
180 element |= (iarray[0] & this.bitMask) << shift;
181 data.setElem (index, element);
184 }, "~N,~N,~O,java.awt.image.DataBuffer");
185 Clazz.defineMethod (c$, "setPixel",
186 function (x, y, iArray, data) {
187 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {
188 throw new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");
189 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;
190 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));
191 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;
192 var element = data.getElem (index);
193 element &= ~(this.bitMask << shift);
194 element |= (iArray[0] & this.bitMask) << shift;
195 data.setElem (index, element);
196 }, "~N,~N,~A,java.awt.image.DataBuffer");
197 Clazz.overrideMethod (c$, "equals",
199 if ((o == null) || !(Clazz.instanceOf (o, java.awt.image.MultiPixelPackedSampleModel))) {
202 return this.width == that.width && this.height == that.height && this.numBands == that.numBands && this.dataType == that.dataType && this.pixelBitStride == that.pixelBitStride && this.bitMask == that.bitMask && this.pixelsPerDataElement == that.pixelsPerDataElement && this.dataElementSize == that.dataElementSize && this.dataBitOffset == that.dataBitOffset && this.scanlineStride == that.scanlineStride;
204 Clazz.overrideMethod (c$, "hashCode",
211 hash ^= this.numBands;
213 hash ^= this.dataType;
215 hash ^= this.pixelBitStride;
217 hash ^= this.bitMask;
219 hash ^= this.pixelsPerDataElement;
221 hash ^= this.dataElementSize;
223 hash ^= this.dataBitOffset;
225 hash ^= this.scanlineStride;