JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / site / j2s / java / awt / image / BufferedImage.js
1 Clazz.declarePackage ("java.awt.image");\r
2 Clazz.load (["java.awt.Image", "$.Transparency"], "java.awt.image.BufferedImage", ["java.awt.Image", "java.lang.IllegalArgumentException", "$.NullPointerException", "java.util.Hashtable", "java.awt.GraphicsEnvironment", "$.Point", "$.Rectangle", "java.awt.image.ColorModel", "$.DirectColorModel", "$.Raster", "jssun.awt.image.OffScreenImageSource"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.imageType = 0;\r
5 this.colorModel = null;\r
6 this.raster = null;\r
7 this.osis = null;\r
8 this.properties = null;\r
9 this.$isAlphaPremultiplied = false;\r
10 Clazz.instantialize (this, arguments);\r
11 }, java.awt.image, "BufferedImage", java.awt.Image, java.awt.Transparency);\r
12 Clazz.makeConstructor (c$, \r
13 function (width, height, imageType) {\r
14 Clazz.superConstructor (this, java.awt.image.BufferedImage, []);\r
15 switch (imageType) {\r
16 case 1:\r
17 {\r
18 this.colorModel =  new java.awt.image.DirectColorModel (24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x0);\r
19 this.raster = this.colorModel.createCompatibleWritableRaster (width, height);\r
20 }break;\r
21 case 2:\r
22 {\r
23 this.colorModel = java.awt.image.ColorModel.getRGBdefault ();\r
24 this.raster = this.colorModel.createCompatibleWritableRaster (width, height);\r
25 }break;\r
26 default:\r
27 throw  new IllegalArgumentException ("Unknown image type " + imageType);\r
28 }\r
29 this.imageType = imageType;\r
30 }, "~N,~N,~N");\r
31 Clazz.makeConstructor (c$, \r
32 function (cm, raster, isRasterPremultiplied, properties) {\r
33 Clazz.superConstructor (this, java.awt.image.BufferedImage, []);\r
34 if ((raster.minX != 0) || (raster.minY != 0)) {\r
35 throw  new IllegalArgumentException ("Raster " + raster + " has minX or minY not equal to zero: " + raster.minX + " " + raster.minY);\r
36 }this.colorModel = cm;\r
37 this.raster = raster;\r
38 this.properties = properties;\r
39 var cs;\r
40 cs = cm.getColorSpace ();\r
41 }, "java.awt.image.ColorModel,java.awt.image.WritableRaster,~B,java.util.Hashtable");\r
42 Clazz.defineMethod (c$, "getType", \r
43 function () {\r
44 return this.imageType;\r
45 });\r
46 Clazz.defineMethod (c$, "getColorModel", \r
47 function () {\r
48 return this.colorModel;\r
49 });\r
50 Clazz.defineMethod (c$, "getRaster", \r
51 function () {\r
52 return this.raster;\r
53 });\r
54 Clazz.defineMethod (c$, "getRGB", \r
55 function (x, y) {\r
56 return 0;\r
57 }, "~N,~N");\r
58 Clazz.defineMethod (c$, "getRGB", \r
59 function (startX, startY, w, h, rgbArray, offset, scansize) {\r
60 return rgbArray;\r
61 }, "~N,~N,~N,~N,~A,~N,~N");\r
62 Clazz.defineMethod (c$, "setRGB", \r
63 function (x, y, rgb) {\r
64 }, "~N,~N,~N");\r
65 Clazz.defineMethod (c$, "setRGB", \r
66 function (startX, startY, w, h, rgbArray, offset, scansize) {\r
67 }, "~N,~N,~N,~N,~A,~N,~N");\r
68 Clazz.defineMethod (c$, "getWidth", \r
69 function () {\r
70 return this.raster.getWidth ();\r
71 });\r
72 Clazz.defineMethod (c$, "getHeight", \r
73 function () {\r
74 return this.raster.getHeight ();\r
75 });\r
76 Clazz.defineMethod (c$, "getWidth", \r
77 function (observer) {\r
78 return this.raster.getWidth ();\r
79 }, "java.awt.image.ImageObserver");\r
80 Clazz.defineMethod (c$, "getHeight", \r
81 function (observer) {\r
82 return this.raster.getHeight ();\r
83 }, "java.awt.image.ImageObserver");\r
84 Clazz.overrideMethod (c$, "getSource", \r
85 function () {\r
86 if (this.osis == null) {\r
87 if (this.properties == null) {\r
88 this.properties =  new java.util.Hashtable ();\r
89 }this.osis =  new jssun.awt.image.OffScreenImageSource (this, this.properties);\r
90 }return this.osis;\r
91 });\r
92 Clazz.defineMethod (c$, "getProperty", \r
93 function (name, observer) {\r
94 return this.getProperty (name);\r
95 }, "~S,java.awt.image.ImageObserver");\r
96 Clazz.defineMethod (c$, "getProperty", \r
97 function (name) {\r
98 if (name == null) {\r
99 throw  new NullPointerException ("null property name is not allowed");\r
100 }if (this.properties == null) {\r
101 return java.awt.Image.UndefinedProperty;\r
102 }var o = this.properties.get (name);\r
103 if (o == null) {\r
104 o = java.awt.Image.UndefinedProperty;\r
105 }return o;\r
106 }, "~S");\r
107 Clazz.overrideMethod (c$, "getGraphics", \r
108 function () {\r
109 return this.createGraphics ();\r
110 });\r
111 Clazz.defineMethod (c$, "createGraphics", \r
112 function () {\r
113 var env = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment ();\r
114 return env.createGraphics (this);\r
115 });\r
116 Clazz.defineMethod (c$, "getSubimage", \r
117 function (x, y, w, h) {\r
118 return  new java.awt.image.BufferedImage (this.colorModel, this.raster.createWritableChild (x, y, w, h, 0, 0, null), this.colorModel.isAlphaPremultiplied (), this.properties);\r
119 }, "~N,~N,~N,~N");\r
120 Clazz.defineMethod (c$, "isAlphaPremultiplied", \r
121 function () {\r
122 return false;\r
123 });\r
124 Clazz.overrideMethod (c$, "toString", \r
125 function () {\r
126 return  String.instantialize ("BufferedImage@" + Integer.toHexString (this.hashCode ()) + ": type = " + this.imageType + " " + this.colorModel + " " + this.raster);\r
127 });\r
128 Clazz.defineMethod (c$, "getSources", \r
129 function () {\r
130 return null;\r
131 });\r
132 Clazz.defineMethod (c$, "getPropertyNames", \r
133 function () {\r
134 return null;\r
135 });\r
136 Clazz.defineMethod (c$, "getMinX", \r
137 function () {\r
138 return this.raster.getMinX ();\r
139 });\r
140 Clazz.defineMethod (c$, "getMinY", \r
141 function () {\r
142 return this.raster.getMinY ();\r
143 });\r
144 Clazz.defineMethod (c$, "getSampleModel", \r
145 function () {\r
146 return this.raster.getSampleModel ();\r
147 });\r
148 Clazz.defineMethod (c$, "getNumXTiles", \r
149 function () {\r
150 return 1;\r
151 });\r
152 Clazz.defineMethod (c$, "getNumYTiles", \r
153 function () {\r
154 return 1;\r
155 });\r
156 Clazz.defineMethod (c$, "getMinTileX", \r
157 function () {\r
158 return 0;\r
159 });\r
160 Clazz.defineMethod (c$, "getMinTileY", \r
161 function () {\r
162 return 0;\r
163 });\r
164 Clazz.defineMethod (c$, "getTileWidth", \r
165 function () {\r
166 return this.raster.getWidth ();\r
167 });\r
168 Clazz.defineMethod (c$, "getTileHeight", \r
169 function () {\r
170 return this.raster.getHeight ();\r
171 });\r
172 Clazz.defineMethod (c$, "getTileGridXOffset", \r
173 function () {\r
174 return 0;\r
175 });\r
176 Clazz.defineMethod (c$, "getTileGridYOffset", \r
177 function () {\r
178 return 0;\r
179 });\r
180 Clazz.defineMethod (c$, "getTile", \r
181 function (tileX, tileY) {\r
182 return this.raster;\r
183 }, "~N,~N");\r
184 Clazz.defineMethod (c$, "getData", \r
185 function () {\r
186 var width = this.raster.getWidth ();\r
187 var height = this.raster.getHeight ();\r
188 var startX = this.raster.getMinX ();\r
189 var startY = this.raster.getMinY ();\r
190 var wr = java.awt.image.Raster.createWritableRaster (this.raster.getSampleModel (),  new java.awt.Point (this.raster.getSampleModelTranslateX (), this.raster.getSampleModelTranslateY ()));\r
191 var tdata = null;\r
192 for (var i = startY; i < startY + height; i++) {\r
193 tdata = this.raster.getDataElements (startX, i, width, 1, tdata);\r
194 wr.setDataElements (startX, i, width, 1, tdata);\r
195 }\r
196 return wr;\r
197 });\r
198 Clazz.defineMethod (c$, "getData", \r
199 function (rect) {\r
200 var sm = this.raster.getSampleModel ();\r
201 var nsm = sm.createCompatibleSampleModel (rect.width, rect.height);\r
202 var wr = java.awt.image.Raster.createWritableRaster (nsm, rect.getLocation ());\r
203 var width = rect.width;\r
204 var height = rect.height;\r
205 var startX = rect.x;\r
206 var startY = rect.y;\r
207 var tdata = null;\r
208 for (var i = startY; i < startY + height; i++) {\r
209 tdata = this.raster.getDataElements (startX, i, width, 1, tdata);\r
210 wr.setDataElements (startX, i, width, 1, tdata);\r
211 }\r
212 return wr;\r
213 }, "java.awt.Rectangle");\r
214 Clazz.defineMethod (c$, "copyData", \r
215 function (outRaster) {\r
216 if (outRaster == null) {\r
217 return this.getData ();\r
218 }var width = outRaster.getWidth ();\r
219 var height = outRaster.getHeight ();\r
220 var startX = outRaster.getMinX ();\r
221 var startY = outRaster.getMinY ();\r
222 var tdata = null;\r
223 for (var i = startY; i < startY + height; i++) {\r
224 tdata = this.raster.getDataElements (startX, i, width, 1, tdata);\r
225 outRaster.setDataElements (startX, i, width, 1, tdata);\r
226 }\r
227 return outRaster;\r
228 }, "java.awt.image.WritableRaster");\r
229 Clazz.defineMethod (c$, "setData", \r
230 function (r) {\r
231 var width = r.getWidth ();\r
232 var height = r.getHeight ();\r
233 var startX = r.getMinX ();\r
234 var startY = r.getMinY ();\r
235 var tdata = null;\r
236 var rclip =  new java.awt.Rectangle (startX, startY, width, height);\r
237 var bclip =  new java.awt.Rectangle (0, 0, this.raster.width, this.raster.height);\r
238 var intersect = rclip.intersection (bclip);\r
239 if (intersect.isEmpty ()) {\r
240 return;\r
241 }width = intersect.width;\r
242 height = intersect.height;\r
243 startX = intersect.x;\r
244 startY = intersect.y;\r
245 for (var i = startY; i < startY + height; i++) {\r
246 tdata = r.getPixels (startX, i, width, 1, tdata);\r
247 this.raster.setPixels (startX, i, width, 1, tdata);\r
248 }\r
249 }, "java.awt.image.Raster");\r
250 Clazz.overrideMethod (c$, "getTransparency", \r
251 function () {\r
252 return this.colorModel.getTransparency ();\r
253 });\r
254 Clazz.defineStatics (c$,\r
255 "TYPE_CUSTOM", 0,\r
256 "TYPE_INT_RGB", 1,\r
257 "TYPE_INT_ARGB", 2);\r
258 });\r