1 Clazz.declarePackage ("java.awt.image");
2 Clazz.load (["java.awt.Transparency", "java.awt.color.ColorSpace"], "java.awt.image.ColorModel", ["java.lang.IllegalArgumentException", "$.NullPointerException", "$.UnsupportedOperationException", "JU.AU"], function () {
3 c$ = Clazz.decorateAsClass (function () {
7 this.supportsAlpha = true;
8 this.$isAlphaPremultiplied = false;
9 this.numComponents = -1;
10 this.numColorComponents = -1;
11 this.colorSpace = null;
12 this.colorSpaceType = 5;
15 this.transferType = 0;
16 Clazz.instantialize (this, arguments);
17 }, java.awt.image, "ColorModel", null, java.awt.Transparency);
18 Clazz.prepareFields (c$, function () {
19 this.colorSpace = java.awt.color.ColorSpace.getInstance (1000);
21 c$.getRGBdefault = Clazz.defineMethod (c$, "getRGBdefault",
23 if (java.awt.image.ColorModel.RGBdefault == null) {
24 java.awt.image.ColorModel.RGBdefault = new java.awt.image.DirectColorModel (32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
25 }return java.awt.image.ColorModel.RGBdefault;
27 Clazz.makeConstructor (c$,
29 this.pixel_bits = bits;
31 throw new IllegalArgumentException ("Number of bits must be > 0");
32 }this.numComponents = 4;
33 this.numColorComponents = 3;
35 this.transferType = java.awt.image.ColorModel.getDefaultTransferType (bits);
37 Clazz.makeConstructor (c$,
38 function (pixel_bits, bits, cspace, hasAlpha, isAlphaPremultiplied, transparency, transferType) {
39 this.colorSpace = cspace;
40 this.colorSpaceType = cspace.getType ();
41 this.numColorComponents = cspace.getNumComponents ();
42 this.numComponents = this.numColorComponents + (hasAlpha ? 1 : 0);
43 this.supportsAlpha = hasAlpha;
44 if (bits.length < this.numComponents) {
45 throw new IllegalArgumentException ("Number of color/alpha components should be " + this.numComponents + " but length of bits array is " + bits.length);
46 }if (transparency < 1 || transparency > 3) {
47 throw new IllegalArgumentException ("Unknown transparency: " + transparency);
48 }if (this.supportsAlpha == false) {
49 this.$isAlphaPremultiplied = false;
50 this.transparency = 1;
52 this.$isAlphaPremultiplied = isAlphaPremultiplied;
53 this.transparency = transparency;
54 }this.nBits = bits.clone ();
55 this.pixel_bits = pixel_bits;
56 if (pixel_bits <= 0) {
57 throw new IllegalArgumentException ("Number of pixel bits must be > 0");
59 for (var i = 0; i < bits.length; i++) {
61 throw new IllegalArgumentException ("Number of bits must be >= 0");
62 }if (this.maxBits < bits[i]) {
63 this.maxBits = bits[i];
65 if (this.maxBits == 0) {
66 throw new IllegalArgumentException ("There must be at least one component with > 0 pixel bits.");
67 }if (cspace !== java.awt.color.ColorSpace.getInstance (1000)) {
69 }this.transferType = transferType;
70 }, "~N,~A,java.awt.color.ColorSpace,~B,~B,~N,~N");
71 Clazz.defineMethod (c$, "hasAlpha",
73 return this.supportsAlpha;
75 Clazz.defineMethod (c$, "isAlphaPremultiplied",
77 return this.$isAlphaPremultiplied;
79 Clazz.defineMethod (c$, "getTransferType",
81 return this.transferType;
83 Clazz.defineMethod (c$, "getPixelSize",
85 return this.pixel_bits;
87 Clazz.defineMethod (c$, "getComponentSize",
88 function (componentIdx) {
89 if (this.nBits == null) {
90 throw new NullPointerException ("Number of bits array is null.");
91 }return this.nBits[componentIdx];
93 Clazz.defineMethod (c$, "getComponentSize",
95 if (this.nBits != null) {
96 return this.nBits.clone ();
99 Clazz.overrideMethod (c$, "getTransparency",
101 return this.transparency;
103 Clazz.defineMethod (c$, "getNumComponents",
105 return this.numComponents;
107 Clazz.defineMethod (c$, "getNumColorComponents",
109 return this.numColorComponents;
111 Clazz.defineMethod (c$, "getRGB",
113 return (this.getAlpha (pixel) << 24) | (this.getRed (pixel) << 16) | (this.getGreen (pixel) << 8) | (this.getBlue (pixel) << 0);
115 Clazz.defineMethod (c$, "getRed",
121 length = idata.length;
123 return this.getRed (pixel);
125 throw new UnsupportedOperationException ("This method is not supported by this color model");
127 Clazz.defineMethod (c$, "getGreen",
133 length = idata.length;
135 return this.getGreen (pixel);
137 throw new UnsupportedOperationException ("This method is not supported by this color model");
139 Clazz.defineMethod (c$, "getBlue",
145 length = idata.length;
147 return this.getBlue (pixel);
149 throw new UnsupportedOperationException ("This method is not supported by this color model");
151 Clazz.defineMethod (c$, "getAlpha",
157 length = idata.length;
159 return this.getAlpha (pixel);
161 throw new UnsupportedOperationException ("This method is not supported by this color model");
163 Clazz.defineMethod (c$, "getRGB",
165 return (this.getAlpha (inData) << 24) | (this.getRed (inData) << 16) | (this.getGreen (inData) << 8) | (this.getBlue (inData) << 0);
167 Clazz.defineMethod (c$, "getDataElements",
168 function (rgb, pixel) {
169 throw new UnsupportedOperationException ("This method is not supported by this color model.");
171 Clazz.defineMethod (c$, "getComponents",
172 function (pixel, components, offset) {
173 throw new UnsupportedOperationException ("This method is not supported by this color model.");
175 Clazz.defineMethod (c$, "getComponents",
176 function (pixel, components, offset) {
177 throw new UnsupportedOperationException ("This method is not supported by this color model.");
179 Clazz.defineMethod (c$, "getUnnormalizedComponents",
180 function (normComponents, normOffset, components, offset) {
181 if (this.colorSpace == null) {
182 throw new UnsupportedOperationException ("This method is not supported by this color model.");
183 }if (this.nBits == null) {
184 throw new UnsupportedOperationException ("This method is not supported. Unable to determine #bits per component.");
185 }if ((normComponents.length - normOffset) < this.numComponents) {
186 throw new IllegalArgumentException ("Incorrect number of components. Expecting " + this.numComponents);
187 }if (components == null) {
188 components = Clazz.newIntArray (offset + this.numComponents, 0);
189 }if (this.supportsAlpha && this.$isAlphaPremultiplied) {
190 var normAlpha = normComponents[normOffset + this.numColorComponents];
191 for (var i = 0; i < this.numColorComponents; i++) {
192 components[offset + i] = Clazz.floatToInt (normComponents[normOffset + i] * ((1 << this.nBits[i]) - 1) * normAlpha + 0.5);
194 components[offset + this.numColorComponents] = Clazz.floatToInt (normAlpha * ((1 << this.nBits[this.numColorComponents]) - 1) + 0.5);
196 for (var i = 0; i < this.numComponents; i++) {
197 components[offset + i] = Clazz.floatToInt (normComponents[normOffset + i] * ((1 << this.nBits[i]) - 1) + 0.5);
201 Clazz.defineMethod (c$, "getNormalizedComponents",
202 function (components, offset, normComponents, normOffset) {
203 if (this.colorSpace == null) {
204 throw new UnsupportedOperationException ("This method is not supported by this color model.");
205 }if (this.nBits == null) {
206 throw new UnsupportedOperationException ("This method is not supported. Unable to determine #bits per component.");
207 }if ((components.length - offset) < this.numComponents) {
208 throw new IllegalArgumentException ("Incorrect number of components. Expecting " + this.numComponents);
209 }if (normComponents == null) {
210 normComponents = Clazz.newFloatArray (this.numComponents + normOffset, 0);
211 }if (this.supportsAlpha && this.$isAlphaPremultiplied) {
212 var normAlpha = components[offset + this.numColorComponents];
213 normAlpha /= ((1 << this.nBits[this.numColorComponents]) - 1);
214 if (normAlpha != 0.0) {
215 for (var i = 0; i < this.numColorComponents; i++) {
216 normComponents[normOffset + i] = (components[offset + i]) / (normAlpha * (((1 << this.nBits[i]) - 1)));
219 for (var i = 0; i < this.numColorComponents; i++) {
220 normComponents[normOffset + i] = 0.0;
222 }normComponents[normOffset + this.numColorComponents] = normAlpha;
224 for (var i = 0; i < this.numComponents; i++) {
225 normComponents[normOffset + i] = (components[offset + i]) / (((1 << this.nBits[i]) - 1));
227 }return normComponents;
229 Clazz.defineMethod (c$, "getDataElement",
230 function (components, offset) {
231 return this.getDataElementInt (components, offset);
233 Clazz.defineMethod (c$, "getDataElementInt",
234 function (components, offset) {
235 throw new UnsupportedOperationException ("This method is not supported by this color model.");
237 Clazz.defineMethod (c$, "getDataElement",
238 function (normComponents, normOffset) {
239 if (JU.AU.isAI (normComponents)) {
240 var ints = normComponents;
241 return this.getDataElementInt (ints, normOffset);
242 }var components = this.getUnnormalizedComponents (normComponents, normOffset, null, 0);
243 return this.getDataElement (components, 0);
245 Clazz.defineMethod (c$, "getDataElements",
246 function (normComponents, normOffset, obj) {
247 var components = this.getUnnormalizedComponents (normComponents, normOffset, null, 0);
248 return this.getDataElements (components, 0, obj);
250 Clazz.defineMethod (c$, "getNormalizedComponents",
251 function (pixel, normComponents, normOffset) {
252 var components = this.getComponents (pixel, null, 0);
253 return this.getNormalizedComponents (components, 0, normComponents, normOffset);
255 Clazz.overrideMethod (c$, "equals",
257 if (!(Clazz.instanceOf (obj, java.awt.image.ColorModel))) {
262 }if (this.supportsAlpha != cm.hasAlpha () || this.$isAlphaPremultiplied != cm.isAlphaPremultiplied () || this.pixel_bits != cm.getPixelSize () || this.transparency != cm.getTransparency () || this.numComponents != cm.getNumComponents ()) {
264 }var nb = cm.getComponentSize ();
265 if ((this.nBits != null) && (nb != null)) {
266 for (var i = 0; i < this.numComponents; i++) {
267 if (this.nBits[i] != nb[i]) {
271 return ((this.nBits == null) && (nb == null));
274 Clazz.overrideMethod (c$, "hashCode",
277 result = (this.supportsAlpha ? 2 : 3) + (this.$isAlphaPremultiplied ? 4 : 5) + this.pixel_bits * 6 + this.transparency * 7 + this.numComponents * 8;
278 if (this.nBits != null) {
279 for (var i = 0; i < this.numComponents; i++) {
280 result = result + this.nBits[i] * (i + 9);
284 Clazz.defineMethod (c$, "getColorSpace",
286 return this.colorSpace;
288 Clazz.defineMethod (c$, "isCompatibleRaster",
290 throw new UnsupportedOperationException ("This method has not been implemented for this ColorModel.");
291 }, "java.awt.image.Raster");
292 Clazz.defineMethod (c$, "createCompatibleWritableRaster",
294 throw new UnsupportedOperationException ("This method is not supported by this color model");
296 Clazz.defineMethod (c$, "createCompatibleSampleModel",
298 throw new UnsupportedOperationException ("This method is not supported by this color model");
300 Clazz.defineMethod (c$, "isCompatibleSampleModel",
302 throw new UnsupportedOperationException ("This method is not supported by this color model");
303 }, "java.awt.image.SampleModel");
304 Clazz.overrideMethod (c$, "finalize",
307 Clazz.defineMethod (c$, "getAlphaRaster",
310 }, "java.awt.image.WritableRaster");
311 Clazz.overrideMethod (c$, "toString",
313 return String.instantialize ("ColorModel: #pixelBits = " + this.pixel_bits + " numComponents = " + this.numComponents + " color space = " + this.colorSpace + " transparency = " + this.transparency + " has alpha = " + this.supportsAlpha + " isAlphaPre = " + this.$isAlphaPremultiplied);
315 c$.getDefaultTransferType = Clazz.defineMethod (c$, "getDefaultTransferType",
316 function (pixel_bits) {
317 if (pixel_bits <= 8) {
321 c$.isLinearRGBspace = Clazz.defineMethod (c$, "isLinearRGBspace",
324 }, "java.awt.color.ColorSpace");
325 c$.isLinearGRAYspace = Clazz.defineMethod (c$, "isLinearGRAYspace",
328 }, "java.awt.color.ColorSpace");
329 Clazz.defineStatics (c$,
336 "lg16Toog8Map", null,
338 "lg16Toog16Map", null);