1 Clazz.declarePackage ("java.awt.image");
2 Clazz.load (["java.awt.image.PackedColorModel"], "java.awt.image.DirectColorModel", ["java.lang.ClassCastException", "$.IllegalArgumentException", "$.UnsupportedOperationException", "java.awt.color.ColorSpace", "java.awt.image.ColorModel", "$.Raster"], function () {
3 c$ = Clazz.decorateAsClass (function () {
8 this.is_LinearRGB = false;
9 this.lRGBprecision = 0;
10 this.tosRGB8LUT = null;
11 this.fromsRGB8LUT8 = null;
12 this.fromsRGB8LUT16 = null;
13 Clazz.instantialize (this, arguments);
14 }, java.awt.image, "DirectColorModel", java.awt.image.PackedColorModel);
15 Clazz.makeConstructor (c$,
16 function (bits, rmask, gmask, bmask) {
17 this.construct (bits, rmask, gmask, bmask, 0);
19 Clazz.makeConstructor (c$,
20 function (bits, rmask, gmask, bmask, amask) {
21 Clazz.superConstructor (this, java.awt.image.DirectColorModel, [java.awt.color.ColorSpace.getInstance (1000), bits, rmask, gmask, bmask, amask, false, amask == 0 ? 1 : 3, java.awt.image.ColorModel.getDefaultTransferType (bits)]);
23 Clazz.makeConstructor (c$,
24 function (space, bits, rmask, gmask, bmask, amask, isAlphaPremultiplied, transferType) {
25 Clazz.superConstructor (this, java.awt.image.DirectColorModel, [space, bits, rmask, gmask, bmask, amask, isAlphaPremultiplied, amask == 0 ? 1 : 3, transferType]);
26 }, "java.awt.color.ColorSpace,~N,~N,~N,~N,~N,~B,~N");
27 Clazz.defineMethod (c$, "getRedMask",
29 return this.maskArray[0];
31 Clazz.defineMethod (c$, "getGreenMask",
33 return this.maskArray[1];
35 Clazz.defineMethod (c$, "getBlueMask",
37 return this.maskArray[2];
39 Clazz.defineMethod (c$, "getAlphaMask",
41 if (this.supportsAlpha) {
42 return this.maskArray[3];
46 Clazz.defineMethod (c$, "getDefaultRGBComponents",
48 var components = this.getComponents (pixel, null, 0);
49 var norm = this.getNormalizedComponents (components, 0, null, 0);
50 return this.colorSpace.toRGB (norm);
52 Clazz.defineMethod (c$, "getsRGBComponentFromsRGB",
53 function (pixel, idx) {
54 var c = ((pixel & this.maskArray[idx]) >>> this.maskOffsets[idx]);
55 if (this.$isAlphaPremultiplied) {
56 var a = ((pixel & this.maskArray[3]) >>> this.maskOffsets[3]);
57 c = (a == 0) ? 0 : Clazz.floatToInt (((c * this.scaleFactors[idx]) * 255.0 / (a * this.scaleFactors[3])) + 0.5);
58 } else if (this.scaleFactors[idx] != 1.0) {
59 c = Clazz.floatToInt ((c * this.scaleFactors[idx]) + 0.5);
62 Clazz.defineMethod (c$, "getsRGBComponentFromLinearRGB",
63 function (pixel, idx) {
64 var c = ((pixel & this.maskArray[idx]) >>> this.maskOffsets[idx]);
65 if (this.$isAlphaPremultiplied) {
66 var factor = ((1 << this.lRGBprecision) - 1);
67 var a = ((pixel & this.maskArray[3]) >>> this.maskOffsets[3]);
68 c = (a == 0) ? 0 : Clazz.floatToInt (((c * this.scaleFactors[idx]) * factor / (a * this.scaleFactors[3])) + 0.5);
69 } else if (this.nBits[idx] != this.lRGBprecision) {
70 if (this.lRGBprecision == 16) {
71 c = Clazz.floatToInt ((c * this.scaleFactors[idx] * 257.0) + 0.5);
73 c = Clazz.floatToInt ((c * this.scaleFactors[idx]) + 0.5);
74 }}return this.tosRGB8LUT[c] & 0xff;
76 Clazz.defineMethod (c$, "getRed",
79 return this.getsRGBComponentFromsRGB (pixel, 0);
80 } else if (this.is_LinearRGB) {
81 return this.getsRGBComponentFromLinearRGB (pixel, 0);
82 }var rgb = this.getDefaultRGBComponents (pixel);
83 return Clazz.floatToInt (rgb[0] * 255.0 + 0.5);
85 Clazz.defineMethod (c$, "getGreen",
88 return this.getsRGBComponentFromsRGB (pixel, 1);
89 } else if (this.is_LinearRGB) {
90 return this.getsRGBComponentFromLinearRGB (pixel, 1);
91 }var rgb = this.getDefaultRGBComponents (pixel);
92 return Clazz.floatToInt (rgb[1] * 255.0 + 0.5);
94 Clazz.defineMethod (c$, "getBlue",
97 return this.getsRGBComponentFromsRGB (pixel, 2);
98 } else if (this.is_LinearRGB) {
99 return this.getsRGBComponentFromLinearRGB (pixel, 2);
100 }var rgb = this.getDefaultRGBComponents (pixel);
101 return Clazz.floatToInt (rgb[2] * 255.0 + 0.5);
103 Clazz.defineMethod (c$, "getAlpha",
105 if (!this.supportsAlpha) return 255;
106 var a = ((pixel & this.maskArray[3]) >>> this.maskOffsets[3]);
107 if (this.scaleFactors[3] != 1.0) {
108 a = Clazz.floatToInt (a * this.scaleFactors[3] + 0.5);
111 Clazz.defineMethod (c$, "getRGB",
113 if (this.is_sRGB || this.is_LinearRGB) {
114 return (this.getAlpha (pixel) << 24) | (this.getRed (pixel) << 16) | (this.getGreen (pixel) << 8) | (this.getBlue (pixel) << 0);
115 }var rgb = this.getDefaultRGBComponents (pixel);
116 return (this.getAlpha (pixel) << 24) | ((Clazz.floatToInt (rgb[0] * 255.0 + 0.5)) << 16) | ((Clazz.floatToInt (rgb[1] * 255.0 + 0.5)) << 8) | ((Clazz.floatToInt (rgb[2] * 255.0 + 0.5)) << 0);
118 Clazz.defineMethod (c$, "getRed",
121 switch (this.transferType) {
124 pixel = bdata[0] & 0xff;
131 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
133 return this.getRed (pixel);
135 Clazz.defineMethod (c$, "getGreen",
138 switch (this.transferType) {
141 pixel = bdata[0] & 0xff;
148 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
150 return this.getGreen (pixel);
152 Clazz.defineMethod (c$, "getBlue",
155 switch (this.transferType) {
158 pixel = bdata[0] & 0xff;
165 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
167 return this.getBlue (pixel);
169 Clazz.defineMethod (c$, "getAlpha",
172 switch (this.transferType) {
175 pixel = bdata[0] & 0xff;
182 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
184 return this.getAlpha (pixel);
186 Clazz.defineMethod (c$, "getRGB",
189 switch (this.transferType) {
192 pixel = bdata[0] & 0xff;
199 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
201 return this.getRGB (pixel);
203 Clazz.defineMethod (c$, "getDataElements",
204 function (rgb, pixel) {
206 if (this.transferType == 3 && pixel != null) {
210 intpixel = Clazz.newIntArray (1, 0);
211 }var defaultCM = java.awt.image.ColorModel.getRGBdefault ();
212 if (this === defaultCM || this.equals (defaultCM)) {
219 red = (rgb >> 16) & 0xff;
220 grn = (rgb >> 8) & 0xff;
222 if (this.is_sRGB || this.is_LinearRGB) {
225 if (this.is_LinearRGB) {
226 if (this.lRGBprecision == 8) {
227 red = this.fromsRGB8LUT8[red] & 0xff;
228 grn = this.fromsRGB8LUT8[grn] & 0xff;
229 blu = this.fromsRGB8LUT8[blu] & 0xff;
231 factor = 0.003921569;
233 red = this.fromsRGB8LUT16[red] & 0xffff;
234 grn = this.fromsRGB8LUT16[grn] & 0xffff;
235 blu = this.fromsRGB8LUT16[blu] & 0xffff;
237 factor = 1.5259022E-5;
240 factor = 0.003921569;
241 }if (this.supportsAlpha) {
242 alp = (rgb >> 24) & 0xff;
243 if (this.$isAlphaPremultiplied) {
244 factor *= (alp * (0.003921569));
246 }if (this.nBits[3] != 8) {
247 alp = Clazz.floatToInt ((alp * (0.003921569) * ((1 << this.nBits[3]) - 1)) + 0.5);
248 if (alp > ((1 << this.nBits[3]) - 1)) {
249 alp = (1 << this.nBits[3]) - 1;
250 }}intpixel[0] = alp << this.maskOffsets[3];
251 }if (this.nBits[0] != precision) {
252 red = Clazz.floatToInt ((red * factor * ((1 << this.nBits[0]) - 1)) + 0.5);
253 }if (this.nBits[1] != precision) {
254 grn = Clazz.floatToInt ((grn * factor * ((1 << this.nBits[1]) - 1)) + 0.5);
255 }if (this.nBits[2] != precision) {
256 blu = Clazz.floatToInt ((blu * factor * ((1 << this.nBits[2]) - 1)) + 0.5);
258 var norm = Clazz.newFloatArray (3, 0);
259 var factor = 0.003921569;
260 norm[0] = red * factor;
261 norm[1] = grn * factor;
262 norm[2] = blu * factor;
263 norm = this.colorSpace.fromRGB (norm);
264 if (this.supportsAlpha) {
265 alp = (rgb >> 24) & 0xff;
266 if (this.$isAlphaPremultiplied) {
268 for (var i = 0; i < 3; i++) {
271 }if (this.nBits[3] != 8) {
272 alp = Clazz.floatToInt ((alp * (0.003921569) * ((1 << this.nBits[3]) - 1)) + 0.5);
273 if (alp > ((1 << this.nBits[3]) - 1)) {
274 alp = (1 << this.nBits[3]) - 1;
275 }}intpixel[0] = alp << this.maskOffsets[3];
276 }red = Clazz.floatToInt ((norm[0] * ((1 << this.nBits[0]) - 1)) + 0.5);
277 grn = Clazz.floatToInt ((norm[1] * ((1 << this.nBits[1]) - 1)) + 0.5);
278 blu = Clazz.floatToInt ((norm[2] * ((1 << this.nBits[2]) - 1)) + 0.5);
279 }if (this.maxBits > 23) {
280 if (red > ((1 << this.nBits[0]) - 1)) {
281 red = (1 << this.nBits[0]) - 1;
282 }if (grn > ((1 << this.nBits[1]) - 1)) {
283 grn = (1 << this.nBits[1]) - 1;
284 }if (blu > ((1 << this.nBits[2]) - 1)) {
285 blu = (1 << this.nBits[2]) - 1;
286 }}intpixel[0] |= (red << this.maskOffsets[0]) | (grn << this.maskOffsets[1]) | (blu << this.maskOffsets[2]);
287 switch (this.transferType) {
292 bdata = Clazz.newByteArray (1, 0);
295 }bdata[0] = (0xff & intpixel[0]);
300 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
302 Clazz.defineMethod (c$, "getComponents",
303 function (pixel, components, offset) {
304 if (components == null) {
305 components = Clazz.newIntArray (offset + this.numComponents, 0);
306 }for (var i = 0; i < this.numComponents; i++) {
307 components[offset + i] = (pixel & this.maskArray[i]) >>> this.maskOffsets[i];
311 Clazz.defineMethod (c$, "getComponents",
312 function (pixel, components, offset) {
314 switch (this.transferType) {
317 intpixel = bdata[0] & 0xff;
324 throw new UnsupportedOperationException ("This method has not been " + "implemented for transferType " + this.transferType);
326 return this.getComponents (intpixel, components, offset);
328 Clazz.overrideMethod (c$, "createCompatibleWritableRaster",
330 if ((w <= 0) || (h <= 0)) {
331 throw new IllegalArgumentException ("Width (" + w + ") and height (" + h + ") cannot be <= 0");
333 if (this.supportsAlpha) {
334 bandmasks = Clazz.newIntArray (4, 0);
335 bandmasks[3] = this.alpha_mask;
337 bandmasks = Clazz.newIntArray (3, 0);
338 }bandmasks[0] = this.red_mask;
339 bandmasks[1] = this.green_mask;
340 bandmasks[2] = this.blue_mask;
341 if (this.pixel_bits > 8) {
342 return java.awt.image.Raster.createPackedRaster (3, w, h, bandmasks, null);
344 return java.awt.image.Raster.createPackedRaster (0, w, h, bandmasks, null);
346 Clazz.defineMethod (c$, "getDataElement",
347 function (components, offset) {
349 for (var i = 0; i < this.numComponents; i++) {
350 pixel |= ((components[offset + i] << this.maskOffsets[i]) & this.maskArray[i]);
354 Clazz.defineMethod (c$, "getDataElements",
355 function (components, offset, obj) {
357 for (var i = 0; i < this.numComponents; i++) {
358 pixel |= ((components[offset + i] << this.maskOffsets[i]) & this.maskArray[i]);
360 switch (this.transferType) {
362 if (Clazz.instanceOf (obj, Array)) {
364 bdata[0] = (pixel & 0xff);
367 var bdata = Clazz.newByteArray (-1, [(pixel & 0xff)]);
370 if (Clazz.instanceOf (obj, Array)) {
375 var idata = Clazz.newIntArray (-1, [pixel]);
378 throw new ClassCastException ("This method has not been " + "implemented for transferType " + this.transferType);
381 Clazz.overrideMethod (c$, "toString",
383 return String.instantialize ("DirectColorModel: rmask=" + Integer.toHexString (this.red_mask) + " gmask=" + Integer.toHexString (this.green_mask) + " bmask=" + Integer.toHexString (this.blue_mask) + " amask=" + Integer.toHexString (this.alpha_mask));