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