JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / image / MultiPixelPackedSampleModel.js
1 Clazz.declarePackage ("java.awt.image");\r
2 Clazz.load (["java.awt.image.SampleModel"], "java.awt.image.MultiPixelPackedSampleModel", ["java.lang.ArrayIndexOutOfBoundsException", "$.IllegalArgumentException", "java.awt.image.DataBuffer", "$.DataBufferByte", "$.DataBufferInt", "$.RasterFormatException"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.pixelBitStride = 0;\r
5 this.bitMask = 0;\r
6 this.pixelsPerDataElement = 0;\r
7 this.dataElementSize = 0;\r
8 this.dataBitOffset = 0;\r
9 this.scanlineStride = 0;\r
10 Clazz.instantialize (this, arguments);\r
11 }, java.awt.image, "MultiPixelPackedSampleModel", java.awt.image.SampleModel);\r
12 Clazz.makeConstructor (c$, \r
13 function (dataType, w, h, numberOfBits) {\r
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);\r
15 if (dataType != 0 && dataType != 3) {\r
16 throw  new IllegalArgumentException ("Unsupported data type " + dataType);\r
17 }}, "~N,~N,~N,~N");\r
18 Clazz.makeConstructor (c$, \r
19 function (dataType, w, h, numberOfBits, scanlineStride, dataBitOffset) {\r
20 Clazz.superConstructor (this, java.awt.image.MultiPixelPackedSampleModel, [dataType, w, h, 1]);\r
21 if (dataType != 0 && dataType != 3) {\r
22 throw  new IllegalArgumentException ("Unsupported data type " + dataType);\r
23 }this.dataType = dataType;\r
24 this.pixelBitStride = numberOfBits;\r
25 this.scanlineStride = scanlineStride;\r
26 this.dataBitOffset = dataBitOffset;\r
27 this.dataElementSize = java.awt.image.DataBuffer.getDataTypeSize (dataType);\r
28 this.pixelsPerDataElement = Clazz.doubleToInt (this.dataElementSize / numberOfBits);\r
29 if (this.pixelsPerDataElement * numberOfBits != this.dataElementSize) {\r
30 throw  new java.awt.image.RasterFormatException ("MultiPixelPackedSampleModel does not allow pixels to span data element boundaries");\r
31 }this.bitMask = (1 << numberOfBits) - 1;\r
32 }, "~N,~N,~N,~N,~N,~N");\r
33 Clazz.overrideMethod (c$, "createCompatibleSampleModel", \r
34 function (w, h) {\r
35 var sampleModel =  new java.awt.image.MultiPixelPackedSampleModel (this.dataType, w, h, this.pixelBitStride);\r
36 return sampleModel;\r
37 }, "~N,~N");\r
38 Clazz.overrideMethod (c$, "createDataBuffer", \r
39 function () {\r
40 var dataBuffer = null;\r
41 var size = this.scanlineStride * this.height;\r
42 switch (this.dataType) {\r
43 case 0:\r
44 dataBuffer =  new java.awt.image.DataBufferByte (size + Clazz.doubleToInt ((this.dataBitOffset + 7) / 8));\r
45 break;\r
46 case 3:\r
47 dataBuffer =  new java.awt.image.DataBufferInt (size + Clazz.doubleToInt ((this.dataBitOffset + 31) / 32));\r
48 break;\r
49 }\r
50 return dataBuffer;\r
51 });\r
52 Clazz.overrideMethod (c$, "getNumDataElements", \r
53 function () {\r
54 return 1;\r
55 });\r
56 Clazz.defineMethod (c$, "getSampleSize", \r
57 function () {\r
58 var sampleSize =  Clazz.newIntArray (-1, [this.pixelBitStride]);\r
59 return sampleSize;\r
60 });\r
61 Clazz.defineMethod (c$, "getSampleSize", \r
62 function (band) {\r
63 return this.pixelBitStride;\r
64 }, "~N");\r
65 Clazz.defineMethod (c$, "getOffset", \r
66 function (x, y) {\r
67 var offset = y * this.scanlineStride;\r
68 offset += Clazz.doubleToInt ((x * this.pixelBitStride + this.dataBitOffset) / this.dataElementSize);\r
69 return offset;\r
70 }, "~N,~N");\r
71 Clazz.defineMethod (c$, "getBitOffset", \r
72 function (x) {\r
73 return (x * this.pixelBitStride + this.dataBitOffset) % this.dataElementSize;\r
74 }, "~N");\r
75 Clazz.defineMethod (c$, "getScanlineStride", \r
76 function () {\r
77 return this.scanlineStride;\r
78 });\r
79 Clazz.defineMethod (c$, "getPixelBitStride", \r
80 function () {\r
81 return this.pixelBitStride;\r
82 });\r
83 Clazz.defineMethod (c$, "getDataBitOffset", \r
84 function () {\r
85 return this.dataBitOffset;\r
86 });\r
87 Clazz.overrideMethod (c$, "getTransferType", \r
88 function () {\r
89 return 3;\r
90 });\r
91 Clazz.overrideMethod (c$, "createSubsetSampleModel", \r
92 function (bands) {\r
93 if (bands != null) {\r
94 if (bands.length != 1) throw  new java.awt.image.RasterFormatException ("MultiPixelPackedSampleModel has only one band.");\r
95 }var sm = this.createCompatibleSampleModel (this.width, this.height);\r
96 return sm;\r
97 }, "~A");\r
98 Clazz.overrideMethod (c$, "getSample", \r
99 function (x, y, b, data) {\r
100 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height) || (b != 0)) {\r
101 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
102 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
103 var element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));\r
104 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
105 return (element >> shift) & this.bitMask;\r
106 }, "~N,~N,~N,java.awt.image.DataBuffer");\r
107 Clazz.defineMethod (c$, "setSample", \r
108 function (x, y, b, s, data) {\r
109 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height) || (b != 0)) {\r
110 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
111 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
112 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));\r
113 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
114 var element = data.getElem (index);\r
115 element &= ~(this.bitMask << shift);\r
116 element |= (s & this.bitMask) << shift;\r
117 data.setElem (index, element);\r
118 }, "~N,~N,~N,~N,java.awt.image.DataBuffer");\r
119 Clazz.defineMethod (c$, "getDataElements", \r
120 function (x, y, obj, data) {\r
121 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {\r
122 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
123 }var type = this.getTransferType ();\r
124 var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
125 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
126 var element = 0;\r
127 switch (type) {\r
128 case 0:\r
129 var bdata;\r
130 if (obj == null) bdata =  Clazz.newByteArray (1, 0);\r
131  else bdata = obj;\r
132 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));\r
133 bdata[0] = ((element >> shift) & this.bitMask);\r
134 obj = bdata;\r
135 break;\r
136 case 3:\r
137 var idata;\r
138 if (obj == null) idata =  Clazz.newIntArray (1, 0);\r
139  else idata = obj;\r
140 element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));\r
141 idata[0] = (element >> shift) & this.bitMask;\r
142 obj = idata;\r
143 break;\r
144 }\r
145 return obj;\r
146 }, "~N,~N,~O,java.awt.image.DataBuffer");\r
147 Clazz.defineMethod (c$, "getPixel", \r
148 function (x, y, iArray, data) {\r
149 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {\r
150 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
151 }var pixels;\r
152 if (iArray != null) {\r
153 pixels = iArray;\r
154 } else {\r
155 pixels =  Clazz.newIntArray (this.numBands, 0);\r
156 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
157 var element = data.getElem (y * this.scanlineStride + Clazz.doubleToInt (bitnum / this.dataElementSize));\r
158 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
159 pixels[0] = (element >> shift) & this.bitMask;\r
160 return pixels;\r
161 }, "~N,~N,~A,java.awt.image.DataBuffer");\r
162 Clazz.defineMethod (c$, "setDataElements", \r
163 function (x, y, obj, data) {\r
164 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {\r
165 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
166 }var type = this.getTransferType ();\r
167 var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
168 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));\r
169 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
170 var element = data.getElem (index);\r
171 element &= ~(this.bitMask << shift);\r
172 switch (type) {\r
173 case 0:\r
174 var barray = obj;\r
175 element |= (((barray[0]) & 0xff) & this.bitMask) << shift;\r
176 data.setElem (index, element);\r
177 break;\r
178 case 3:\r
179 var iarray = obj;\r
180 element |= (iarray[0] & this.bitMask) << shift;\r
181 data.setElem (index, element);\r
182 break;\r
183 }\r
184 }, "~N,~N,~O,java.awt.image.DataBuffer");\r
185 Clazz.defineMethod (c$, "setPixel", \r
186 function (x, y, iArray, data) {\r
187 if ((x < 0) || (y < 0) || (x >= this.width) || (y >= this.height)) {\r
188 throw  new ArrayIndexOutOfBoundsException ("Coordinate out of bounds!");\r
189 }var bitnum = this.dataBitOffset + x * this.pixelBitStride;\r
190 var index = y * this.scanlineStride + (Clazz.doubleToInt (bitnum / this.dataElementSize));\r
191 var shift = this.dataElementSize - (bitnum & (this.dataElementSize - 1)) - this.pixelBitStride;\r
192 var element = data.getElem (index);\r
193 element &= ~(this.bitMask << shift);\r
194 element |= (iArray[0] & this.bitMask) << shift;\r
195 data.setElem (index, element);\r
196 }, "~N,~N,~A,java.awt.image.DataBuffer");\r
197 Clazz.overrideMethod (c$, "equals", \r
198 function (o) {\r
199 if ((o == null) || !(Clazz.instanceOf (o, java.awt.image.MultiPixelPackedSampleModel))) {\r
200 return false;\r
201 }var that = o;\r
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;\r
203 }, "~O");\r
204 Clazz.overrideMethod (c$, "hashCode", \r
205 function () {\r
206 var hash = 0;\r
207 hash = this.width;\r
208 hash <<= 8;\r
209 hash ^= this.height;\r
210 hash <<= 8;\r
211 hash ^= this.numBands;\r
212 hash <<= 8;\r
213 hash ^= this.dataType;\r
214 hash <<= 8;\r
215 hash ^= this.pixelBitStride;\r
216 hash <<= 8;\r
217 hash ^= this.bitMask;\r
218 hash <<= 8;\r
219 hash ^= this.pixelsPerDataElement;\r
220 hash <<= 8;\r
221 hash ^= this.dataElementSize;\r
222 hash <<= 8;\r
223 hash ^= this.dataBitOffset;\r
224 hash <<= 8;\r
225 hash ^= this.scanlineStride;\r
226 return hash;\r
227 });\r
228 });\r