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