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 () {
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));
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");
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",
43 return this.maskArray[index];
45 Clazz.defineMethod (c$, "getMasks",
47 return this.maskArray.clone ();
49 Clazz.defineMethod (c$, "DecomposeMask",
50 function (mask, idx, componentName) {
52 var count = this.nBits[idx];
53 this.maskArray[idx] = mask;
55 while ((mask & 1) == 0) {
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;
63 this.scaleFactors[idx] = 256.0;
65 this.scaleFactors[idx] = 255.0 / ((1 << count) - 1);
67 Clazz.defineMethod (c$, "equals",
69 if (!(Clazz.instanceOf (obj, java.awt.image.PackedColorModel))) {
71 }if (!Clazz.superCall (this, java.awt.image.PackedColorModel, "equals", [obj])) {
74 var numC = cm.getNumComponents ();
75 if (numC != this.numComponents) {
77 }for (var i = 0; i < numC; i++) {
78 if (this.maskArray[i] != cm.getMask (i)) {
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]);
91 throw new IllegalArgumentException ("Noncontiguous color mask (" + Integer.toHexString (colorMaskArray[i]) + "at index " + i);
94 arr[numColors] = java.awt.image.PackedColorModel.countBits (alphaMask);
95 if (arr[numColors] < 0) {
96 throw new IllegalArgumentException ("Noncontiguous alpha mask (" + Integer.toHexString (alphaMask));
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);
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));
112 arr[3] = java.awt.image.PackedColorModel.countBits (amask);
114 throw new IllegalArgumentException ("Noncontiguous alpha mask (" + Integer.toHexString (amask));
117 c$.countBits = Clazz.defineMethod (c$, "countBits",
121 while ((mask & 1) == 0) {
124 while ((mask & 1) == 1) {