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