X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=site%2Fswingjs%2Fj2s%2Fswingjs%2FJSImage.js;fp=site%2Fswingjs%2Fj2s%2Fswingjs%2FJSImage.js;h=ebc0cdef1a16bb7a9bdccc3c007f553c0f0b6d8b;hb=4231d40261fef32ce4570a6bbad0d35df44e8baf;hp=0000000000000000000000000000000000000000;hpb=c07eb2c5794833bd0241000d6844d783fe10cb82;p=jalview.git diff --git a/site/swingjs/j2s/swingjs/JSImage.js b/site/swingjs/j2s/swingjs/JSImage.js new file mode 100644 index 0000000..ebc0cde --- /dev/null +++ b/site/swingjs/j2s/swingjs/JSImage.js @@ -0,0 +1,59 @@ +Clazz.declarePackage ("swingjs"); +Clazz.load (["java.awt.image.BufferedImage"], "swingjs.JSImage", ["JU.Base64", "swingjs.api.DOMNode"], function () { +c$ = Clazz.decorateAsClass (function () { +this.typeRequested = 0; +this.pix = null; +this._imgNode = null; +this.width = 0; +this.height = 0; +Clazz.instantialize (this, arguments); +}, swingjs, "JSImage", java.awt.image.BufferedImage); +Clazz.makeConstructor (c$, +function (argb, width, height) { +Clazz.superConstructor (this, swingjs.JSImage, [width, height, 2]); +this.width = width; +this.height = height; +this.pix = argb; +}, "~A,~N,~N"); +Clazz.defineMethod (c$, "toIntARGB", +function (imgData) { +var n = Clazz.doubleToInt (imgData.length / 4); +var iData = Clazz.newIntArray (n, 0); +for (var i = 0, j = 0; i < n; j++) iData[i++] = (imgData[j++] << 16) | (imgData[j++] << 8) | imgData[j++] | 0xFF000000; + +return iData; +}, "~A"); +Clazz.defineMethod (c$, "getDOMImage", +function (b, type) { +var dataurl = "data:image/" + type + ";base64," + JU.Base64.getBase64 (b).toString (); +var me = this; +var img = null; +{ +img = new Image(this.width, this.height); +//img.onLoad = function() { me.setDOMImage(img); }; +img.src = dataurl; +}this.setDOMImage (img); +}, "~A,~S"); +Clazz.defineMethod (c$, "setDOMImage", +function (img) { +var canvas = swingjs.api.DOMNode.createElement ("canvas", "JSImage"); +var w = this.width; +var h = this.height; +this._imgNode = img; +{ +canvas.width = w; +canvas.height = h; +var ctx = canvas.getContext("2d"); +ctx.drawImage(img, 0, 0, w, h); +var data = ctx.getImageData(0, 0, w, h).data; +img._pbuf32 = this.toIntARGB(data); +}}, "swingjs.api.DOMNode"); +Clazz.defineMethod (c$, "getHeight", +function (o) { +return this.height; +}, "java.awt.image.ImageObserver"); +Clazz.defineMethod (c$, "getWidth", +function (o) { +return this.width; +}, "java.awt.image.ImageObserver"); +});