Merge branch 'master' of https://source.jalview.org/git/jalviewjs.git
[jalviewjs.git] / site / j2s / java / awt / image / MultiPixelPackedSampleModel.js
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;
5 this.bitMask = 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);
17 }}, "~N,~N,~N,~N");
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", 
34 function (w, h) {
35 var sampleModel =  new java.awt.image.MultiPixelPackedSampleModel (this.dataType, w, h, this.pixelBitStride);
36 return sampleModel;
37 }, "~N,~N");
38 Clazz.overrideMethod (c$, "createDataBuffer", 
39 function () {
40 var dataBuffer = null;
41 var size = this.scanlineStride * this.height;
42 switch (this.dataType) {
43 case 0:
44 dataBuffer =  new java.awt.image.DataBufferByte (size + Clazz.doubleToInt ((this.dataBitOffset + 7) / 8));
45 break;
46 case 3:
47 dataBuffer =  new java.awt.image.DataBufferInt (size + Clazz.doubleToInt ((this.dataBitOffset + 31) / 32));
48 break;
49 }
50 return dataBuffer;
51 });
52 Clazz.overrideMethod (c$, "getNumDataElements", 
53 function () {
54 return 1;
55 });
56 Clazz.defineMethod (c$, "getSampleSize", 
57 function () {
58 var sampleSize =  Clazz.newIntArray (-1, [this.pixelBitStride]);
59 return sampleSize;
60 });
61 Clazz.defineMethod (c$, "getSampleSize", 
62 function (band) {
63 return this.pixelBitStride;
64 }, "~N");
65 Clazz.defineMethod (c$, "getOffset", 
66 function (x, y) {
67 var offset = y * this.scanlineStride;
68 offset += Clazz.doubleToInt ((x * this.pixelBitStride + this.dataBitOffset) / this.dataElementSize);
69 return offset;
70 }, "~N,~N");
71 Clazz.defineMethod (c$, "getBitOffset", 
72 function (x) {
73 return (x * this.pixelBitStride + this.dataBitOffset) % this.dataElementSize;
74 }, "~N");
75 Clazz.defineMethod (c$, "getScanlineStride", 
76 function () {
77 return this.scanlineStride;
78 });
79 Clazz.defineMethod (c$, "getPixelBitStride", 
80 function () {
81 return this.pixelBitStride;
82 });
83 Clazz.defineMethod (c$, "getDataBitOffset", 
84 function () {
85 return this.dataBitOffset;
86 });
87 Clazz.overrideMethod (c$, "getTransferType", 
88 function () {
89 return 3;
90 });
91 Clazz.overrideMethod (c$, "createSubsetSampleModel", 
92 function (bands) {
93 if (bands != null) {
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);
96 return sm;
97 }, "~A");
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;
126 var element = 0;
127 switch (type) {
128 case 0:
129 var bdata;
130 if (obj == null) bdata =  Clazz.newByteArray (1, 0);
131  else bdata = obj;
132 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
133 bdata[0] = ((element >> shift) & this.bitMask);
134 obj = bdata;
135 break;
136 case 3:
137 var idata;
138 if (obj == null) idata =  Clazz.newIntArray (1, 0);
139  else idata = obj;
140 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));
141 idata[0] = (element >> shift) & this.bitMask;
142 obj = idata;
143 break;
144 }
145 return obj;
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!");
151 }var pixels;
152 if (iArray != null) {
153 pixels = iArray;
154 } else {
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;
160 return pixels;
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);
172 switch (type) {
173 case 0:
174 var barray = obj;
175 element |= (((barray[0]) & 0xff) & this.bitMask) << shift;
176 data.setElem (index, element);
177 break;
178 case 3:
179 var iarray = obj;
180 element |= (iarray[0] & this.bitMask) << shift;
181 data.setElem (index, element);
182 break;
183 }
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", 
198 function (o) {
199 if ((o == null) || !(Clazz.instanceOf (o, java.awt.image.MultiPixelPackedSampleModel))) {
200 return false;
201 }var that = o;
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;
203 }, "~O");
204 Clazz.overrideMethod (c$, "hashCode", 
205 function () {
206 var hash = 0;
207 hash = this.width;
208 hash <<= 8;
209 hash ^= this.height;
210 hash <<= 8;
211 hash ^= this.numBands;
212 hash <<= 8;
213 hash ^= this.dataType;
214 hash <<= 8;
215 hash ^= this.pixelBitStride;
216 hash <<= 8;
217 hash ^= this.bitMask;
218 hash <<= 8;
219 hash ^= this.pixelsPerDataElement;
220 hash <<= 8;
221 hash ^= this.dataElementSize;
222 hash <<= 8;
223 hash ^= this.dataBitOffset;
224 hash <<= 8;
225 hash ^= this.scanlineStride;
226 return hash;
227 });
228 });