JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / image / PackedColorModel.js
1 Clazz.declarePackage ("java.awt.image");\r
2 Clazz.load (["java.awt.image.ColorModel"], "java.awt.image.PackedColorModel", ["java.lang.IllegalArgumentException"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.maskArray = null;\r
5 this.maskOffsets = null;\r
6 this.scaleFactors = null;\r
7 Clazz.instantialize (this, arguments);\r
8 }, java.awt.image, "PackedColorModel", java.awt.image.ColorModel);\r
9 Clazz.makeConstructor (c$, \r
10 function (space, bits, colorMaskArray, alphaMask, isAlphaPremultiplied, trans, transferType) {\r
11 Clazz.superConstructor (this, java.awt.image.PackedColorModel, [bits, java.awt.image.PackedColorModel.createBitsArray (colorMaskArray, alphaMask), space, (alphaMask == 0 ? false : true), isAlphaPremultiplied, trans, transferType]);\r
12 if (bits < 1 || bits > 32) {\r
13 throw  new IllegalArgumentException ("Number of bits must be between 1 and 32.");\r
14 }this.maskArray =  Clazz.newIntArray (this.numComponents, 0);\r
15 this.maskOffsets =  Clazz.newIntArray (this.numComponents, 0);\r
16 this.scaleFactors =  Clazz.newFloatArray (this.numComponents, 0);\r
17 for (var i = 0; i < this.numColorComponents; i++) {\r
18 this.DecomposeMask (colorMaskArray[i], i, space.getName (i));\r
19 }\r
20 if (alphaMask != 0) {\r
21 this.DecomposeMask (alphaMask, this.numColorComponents, "alpha");\r
22 if (this.nBits[this.numComponents - 1] == 1) {\r
23 this.transparency = 2;\r
24 }}}, "java.awt.color.ColorSpace,~N,~A,~N,~B,~N,~N");\r
25 Clazz.makeConstructor (c$, \r
26 function (space, bits, rmask, gmask, bmask, amask, isAlphaPremultiplied, trans, transferType) {\r
27 Clazz.superConstructor (this, java.awt.image.PackedColorModel, [bits, java.awt.image.PackedColorModel.createBitsArray (rmask, gmask, bmask, amask), space, (amask == 0 ? false : true), isAlphaPremultiplied, trans, transferType]);\r
28 if (space.getType () != 5) {\r
29 throw  new IllegalArgumentException ("ColorSpace must be TYPE_RGB.");\r
30 }this.maskArray =  Clazz.newIntArray (this.numComponents, 0);\r
31 this.maskOffsets =  Clazz.newIntArray (this.numComponents, 0);\r
32 this.scaleFactors =  Clazz.newFloatArray (this.numComponents, 0);\r
33 this.DecomposeMask (rmask, 0, "red");\r
34 this.DecomposeMask (gmask, 1, "green");\r
35 this.DecomposeMask (bmask, 2, "blue");\r
36 if (amask != 0) {\r
37 this.DecomposeMask (amask, 3, "alpha");\r
38 if (this.nBits[3] == 1) {\r
39 this.transparency = 2;\r
40 }}}, "java.awt.color.ColorSpace,~N,~N,~N,~N,~N,~B,~N,~N");\r
41 Clazz.defineMethod (c$, "getMask", \r
42 function (index) {\r
43 return this.maskArray[index];\r
44 }, "~N");\r
45 Clazz.defineMethod (c$, "getMasks", \r
46 function () {\r
47 return this.maskArray.clone ();\r
48 });\r
49 Clazz.defineMethod (c$, "DecomposeMask", \r
50  function (mask, idx, componentName) {\r
51 var off = 0;\r
52 var count = this.nBits[idx];\r
53 this.maskArray[idx] = mask;\r
54 if (mask != 0) {\r
55 while ((mask & 1) == 0) {\r
56 mask >>>= 1;\r
57 off++;\r
58 }\r
59 }if (off + count > this.pixel_bits) {\r
60 throw  new IllegalArgumentException (componentName + " mask " + Integer.toHexString (this.maskArray[idx]) + " overflows pixel (expecting " + this.pixel_bits + " bits");\r
61 }this.maskOffsets[idx] = off;\r
62 if (count == 0) {\r
63 this.scaleFactors[idx] = 256.0;\r
64 } else {\r
65 this.scaleFactors[idx] = 255.0 / ((1 << count) - 1);\r
66 }}, "~N,~N,~S");\r
67 Clazz.defineMethod (c$, "equals", \r
68 function (obj) {\r
69 if (!(Clazz.instanceOf (obj, java.awt.image.PackedColorModel))) {\r
70 return false;\r
71 }if (!Clazz.superCall (this, java.awt.image.PackedColorModel, "equals", [obj])) {\r
72 return false;\r
73 }var cm = obj;\r
74 var numC = cm.getNumComponents ();\r
75 if (numC != this.numComponents) {\r
76 return false;\r
77 }for (var i = 0; i < numC; i++) {\r
78 if (this.maskArray[i] != cm.getMask (i)) {\r
79 return false;\r
80 }}\r
81 return true;\r
82 }, "~O");\r
83 c$.createBitsArray = Clazz.defineMethod (c$, "createBitsArray", \r
84  function (colorMaskArray, alphaMask) {\r
85 var numColors = colorMaskArray.length;\r
86 var numAlpha = (alphaMask == 0 ? 0 : 1);\r
87 var arr =  Clazz.newIntArray (numColors + numAlpha, 0);\r
88 for (var i = 0; i < numColors; i++) {\r
89 arr[i] = java.awt.image.PackedColorModel.countBits (colorMaskArray[i]);\r
90 if (arr[i] < 0) {\r
91 throw  new IllegalArgumentException ("Noncontiguous color mask (" + Integer.toHexString (colorMaskArray[i]) + "at index " + i);\r
92 }}\r
93 if (alphaMask != 0) {\r
94 arr[numColors] = java.awt.image.PackedColorModel.countBits (alphaMask);\r
95 if (arr[numColors] < 0) {\r
96 throw  new IllegalArgumentException ("Noncontiguous alpha mask (" + Integer.toHexString (alphaMask));\r
97 }}return arr;\r
98 }, "~A,~N");\r
99 c$.createBitsArray = Clazz.defineMethod (c$, "createBitsArray", \r
100  function (rmask, gmask, bmask, amask) {\r
101 var arr =  Clazz.newIntArray (3 + (amask == 0 ? 0 : 1), 0);\r
102 arr[0] = java.awt.image.PackedColorModel.countBits (rmask);\r
103 arr[1] = java.awt.image.PackedColorModel.countBits (gmask);\r
104 arr[2] = java.awt.image.PackedColorModel.countBits (bmask);\r
105 if (arr[0] < 0) {\r
106 throw  new IllegalArgumentException ("Noncontiguous red mask (" + Integer.toHexString (rmask));\r
107 } else if (arr[1] < 0) {\r
108 throw  new IllegalArgumentException ("Noncontiguous green mask (" + Integer.toHexString (gmask));\r
109 } else if (arr[2] < 0) {\r
110 throw  new IllegalArgumentException ("Noncontiguous blue mask (" + Integer.toHexString (bmask));\r
111 }if (amask != 0) {\r
112 arr[3] = java.awt.image.PackedColorModel.countBits (amask);\r
113 if (arr[3] < 0) {\r
114 throw  new IllegalArgumentException ("Noncontiguous alpha mask (" + Integer.toHexString (amask));\r
115 }}return arr;\r
116 }, "~N,~N,~N,~N");\r
117 c$.countBits = Clazz.defineMethod (c$, "countBits", \r
118  function (mask) {\r
119 var count = 0;\r
120 if (mask != 0) {\r
121 while ((mask & 1) == 0) {\r
122 mask >>>= 1;\r
123 }\r
124 while ((mask & 1) == 1) {\r
125 mask >>>= 1;\r
126 count++;\r
127 }\r
128 }if (mask != 0) {\r
129 return -1;\r
130 }return count;\r
131 }, "~N");\r
132 });\r