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