JAL-1807 includes ?j2sdebug flag and DebugJS._(msg)
[jalviewjs.git] / bin / javajs / img / PngEncoder.js
index 8c07dbd..0accd9e 100644 (file)
-Clazz.declarePackage ("javajs.img");\r
-Clazz.load (["javajs.img.CRCEncoder"], "javajs.img.PngEncoder", ["java.io.ByteArrayOutputStream", "java.util.zip.Deflater", "$.DeflaterOutputStream"], function () {\r
-c$ = Clazz.decorateAsClass (function () {\r
-this.encodeAlpha = false;\r
-this.filter = 0;\r
-this.bytesPerPixel = 0;\r
-this.compressionLevel = 0;\r
-this.type = null;\r
-this.transparentColor = null;\r
-this.appData = null;\r
-this.appPrefix = null;\r
-this.comment = null;\r
-this.bytes = null;\r
-this.scanLines = null;\r
-this.byteWidth = 0;\r
-Clazz.instantialize (this, arguments);\r
-}, javajs.img, "PngEncoder", javajs.img.CRCEncoder);\r
-Clazz.overrideMethod (c$, "setParams", \r
-function (params) {\r
-if (this.quality < 0) this.quality = (params.containsKey ("qualityPNG") ? (params.get ("qualityPNG")).intValue () : 2);\r
-if (this.quality > 9) this.quality = 9;\r
-this.encodeAlpha = false;\r
-this.filter = 0;\r
-this.compressionLevel = this.quality;\r
-this.transparentColor = params.get ("transparentColor");\r
-this.comment = params.get ("comment");\r
-this.type = (params.get ("type") + "0000").substring (0, 4);\r
-this.bytes = params.get ("pngImgData");\r
-this.appData = params.get ("pngAppData");\r
-this.appPrefix = params.get ("pngAppPrefix");\r
-}, "java.util.Map");\r
-Clazz.overrideMethod (c$, "generate", \r
-function () {\r
-if (this.bytes == null) {\r
-if (!this.pngEncode ()) {\r
-this.out.cancel ();\r
-return;\r
-}this.bytes = this.getBytes ();\r
-} else {\r
-this.dataLen = this.bytes.length;\r
-}var len = this.dataLen;\r
-if (this.appData != null) {\r
-javajs.img.PngEncoder.setJmolTypeText (this.appPrefix, this.bytes, len, this.appData.length, this.type);\r
-this.out.write (this.bytes, 0, len);\r
-len = (this.bytes = this.appData).length;\r
-}this.out.write (this.bytes, 0, len);\r
-});\r
-Clazz.defineMethod (c$, "pngEncode", \r
-($fz = function () {\r
-var pngIdBytes =  Clazz.newByteArray (-1, [-119, 80, 78, 71, 13, 10, 26, 10]);\r
-this.writeBytes (pngIdBytes);\r
-this.writeHeader ();\r
-this.writeText (javajs.img.PngEncoder.getApplicationText (this.appPrefix, this.type, 0, 0));\r
-this.writeText ("Software\0Jmol " + this.comment);\r
-this.writeText ("Creation Time\0" + this.date);\r
-if (!this.encodeAlpha && this.transparentColor != null) this.writeTransparentColor (this.transparentColor.intValue ());\r
-return this.writeImageData ();\r
-}, $fz.isPrivate = true, $fz));\r
-c$.setJmolTypeText = Clazz.defineMethod (c$, "setJmolTypeText", \r
-($fz = function (prefix, b, nPNG, nState, type) {\r
-var s = "tEXt" + javajs.img.PngEncoder.getApplicationText (prefix, type, nPNG, nState);\r
-var encoder =  new javajs.img.PngEncoder ();\r
-var test = s.substring (0, 4 + prefix.length).getBytes ();\r
-for (var i = test.length; --i >= 0; ) if (b[i + 37] != test[i]) {\r
-System.out.println ("image is not of the right form; appending data, but not adding tEXt tag.");\r
-return;\r
-}\r
-encoder.setData (b, 37);\r
-encoder.writeString (s);\r
-encoder.writeCRC ();\r
-}, $fz.isPrivate = true, $fz), "~S,~A,~N,~N,~S");\r
-c$.getApplicationText = Clazz.defineMethod (c$, "getApplicationText", \r
-($fz = function (prefix, type, nPNG, nState) {\r
-var sPNG = "000000000" + nPNG;\r
-sPNG = sPNG.substring (sPNG.length - 9);\r
-var sState = "000000000" + nState;\r
-sState = sState.substring (sState.length - 9);\r
-return prefix + "\0" + type + (type.equals ("PNG") ? "0" : "") + sPNG + "+" + sState;\r
-}, $fz.isPrivate = true, $fz), "~S,~S,~N,~N");\r
-Clazz.defineMethod (c$, "writeHeader", \r
-($fz = function () {\r
-this.writeInt4 (13);\r
-this.startPos = this.bytePos;\r
-this.writeString ("IHDR");\r
-this.writeInt4 (this.width);\r
-this.writeInt4 (this.height);\r
-this.writeByte (8);\r
-this.writeByte (this.encodeAlpha ? 6 : 2);\r
-this.writeByte (0);\r
-this.writeByte (0);\r
-this.writeByte (0);\r
-this.writeCRC ();\r
-}, $fz.isPrivate = true, $fz));\r
-Clazz.defineMethod (c$, "writeText", \r
-($fz = function (msg) {\r
-this.writeInt4 (msg.length);\r
-this.startPos = this.bytePos;\r
-this.writeString ("tEXt" + msg);\r
-this.writeCRC ();\r
-}, $fz.isPrivate = true, $fz), "~S");\r
-Clazz.defineMethod (c$, "writeTransparentColor", \r
-($fz = function (icolor) {\r
-this.writeInt4 (6);\r
-this.startPos = this.bytePos;\r
-this.writeString ("tRNS");\r
-this.writeInt2 ((icolor >> 16) & 0xFF);\r
-this.writeInt2 ((icolor >> 8) & 0xFF);\r
-this.writeInt2 (icolor & 0xFF);\r
-this.writeCRC ();\r
-}, $fz.isPrivate = true, $fz), "~N");\r
-Clazz.defineMethod (c$, "writeImageData", \r
-($fz = function () {\r
-this.bytesPerPixel = (this.encodeAlpha ? 4 : 3);\r
-this.byteWidth = this.width * this.bytesPerPixel;\r
-var scanWidth = this.byteWidth + 1;\r
-var rowsLeft = this.height;\r
-var nRows;\r
-var scanPos;\r
-var deflater =  new java.util.zip.Deflater (this.compressionLevel);\r
-var outBytes =  new java.io.ByteArrayOutputStream (1024);\r
-var compBytes =  new java.util.zip.DeflaterOutputStream (outBytes, deflater);\r
-var pt = 0;\r
-try {\r
-while (rowsLeft > 0) {\r
-nRows = Math.max (1, Math.min (Clazz.doubleToInt (32767 / scanWidth), rowsLeft));\r
-this.scanLines =  Clazz.newByteArray (scanWidth * nRows, 0);\r
-var nPixels = this.width * nRows;\r
-scanPos = 0;\r
-for (var i = 0; i < nPixels; i++, pt++) {\r
-if (i % this.width == 0) {\r
-this.scanLines[scanPos++] = this.filter;\r
-}this.scanLines[scanPos++] = ((this.pixels[pt] >> 16) & 0xff);\r
-this.scanLines[scanPos++] = ((this.pixels[pt] >> 8) & 0xff);\r
-this.scanLines[scanPos++] = ((this.pixels[pt]) & 0xff);\r
-if (this.encodeAlpha) {\r
-this.scanLines[scanPos++] = ((this.pixels[pt] >> 24) & 0xff);\r
-}}\r
-compBytes.write (this.scanLines, 0, scanPos);\r
-rowsLeft -= nRows;\r
-}\r
-compBytes.close ();\r
-var compressedLines = outBytes.toByteArray ();\r
-this.writeInt4 (compressedLines.length);\r
-this.startPos = this.bytePos;\r
-this.writeString ("IDAT");\r
-this.writeBytes (compressedLines);\r
-this.writeCRC ();\r
-this.writeEnd ();\r
-deflater.finish ();\r
-return true;\r
-} catch (e) {\r
-if (Clazz.exceptionOf (e, java.io.IOException)) {\r
-System.err.println (e.toString ());\r
-return false;\r
-} else {\r
-throw e;\r
-}\r
-}\r
-}, $fz.isPrivate = true, $fz));\r
-Clazz.defineMethod (c$, "writeEnd", \r
-($fz = function () {\r
-this.writeInt4 (0);\r
-this.startPos = this.bytePos;\r
-this.writeString ("IEND");\r
-this.writeCRC ();\r
-}, $fz.isPrivate = true, $fz));\r
-Clazz.defineStatics (c$,\r
-"FILTER_NONE", 0,\r
-"FILTER_SUB", 1,\r
-"FILTER_UP", 2,\r
-"FILTER_LAST", 2,\r
-"PT_FIRST_TAG", 37);\r
-});\r
+Clazz.declarePackage ("javajs.img");
+Clazz.load (["javajs.img.CRCEncoder"], "javajs.img.PngEncoder", ["java.io.ByteArrayOutputStream", "java.util.zip.Deflater", "$.DeflaterOutputStream"], function () {
+c$ = Clazz.decorateAsClass (function () {
+this.encodeAlpha = false;
+this.filter = 0;
+this.bytesPerPixel = 0;
+this.compressionLevel = 0;
+this.type = null;
+this.transparentColor = null;
+this.appData = null;
+this.appPrefix = null;
+this.comment = null;
+this.bytes = null;
+this.scanLines = null;
+this.byteWidth = 0;
+Clazz.instantialize (this, arguments);
+}, javajs.img, "PngEncoder", javajs.img.CRCEncoder);
+Clazz.overrideMethod (c$, "setParams", 
+function (params) {
+if (this.quality < 0) this.quality = (params.containsKey ("qualityPNG") ? (params.get ("qualityPNG")).intValue () : 2);
+if (this.quality > 9) this.quality = 9;
+this.encodeAlpha = false;
+this.filter = 0;
+this.compressionLevel = this.quality;
+this.transparentColor = params.get ("transparentColor");
+this.comment = params.get ("comment");
+this.type = (params.get ("type") + "0000").substring (0, 4);
+this.bytes = params.get ("pngImgData");
+this.appData = params.get ("pngAppData");
+this.appPrefix = params.get ("pngAppPrefix");
+}, "java.util.Map");
+Clazz.overrideMethod (c$, "generate", 
+function () {
+if (this.bytes == null) {
+if (!this.pngEncode ()) {
+this.out.cancel ();
+return;
+}this.bytes = this.getBytes ();
+} else {
+this.dataLen = this.bytes.length;
+}var len = this.dataLen;
+if (this.appData != null) {
+javajs.img.PngEncoder.setJmolTypeText (this.appPrefix, this.bytes, len, this.appData.length, this.type);
+this.out.write (this.bytes, 0, len);
+len = (this.bytes = this.appData).length;
+}this.out.write (this.bytes, 0, len);
+});
+Clazz.defineMethod (c$, "pngEncode", 
+($fz = function () {
+var pngIdBytes =  Clazz.newByteArray (-1, [-119, 80, 78, 71, 13, 10, 26, 10]);
+this.writeBytes (pngIdBytes);
+this.writeHeader ();
+this.writeText (javajs.img.PngEncoder.getApplicationText (this.appPrefix, this.type, 0, 0));
+this.writeText ("Software\0Jmol " + this.comment);
+this.writeText ("Creation Time\0" + this.date);
+if (!this.encodeAlpha && this.transparentColor != null) this.writeTransparentColor (this.transparentColor.intValue ());
+return this.writeImageData ();
+}, $fz.isPrivate = true, $fz));
+c$.setJmolTypeText = Clazz.defineMethod (c$, "setJmolTypeText", 
+($fz = function (prefix, b, nPNG, nState, type) {
+var s = "tEXt" + javajs.img.PngEncoder.getApplicationText (prefix, type, nPNG, nState);
+var encoder =  new javajs.img.PngEncoder ();
+var test = s.substring (0, 4 + prefix.length).getBytes ();
+for (var i = test.length; --i >= 0; ) if (b[i + 37] != test[i]) {
+System.out.println ("image is not of the right form; appending data, but not adding tEXt tag.");
+return;
+}
+encoder.setData (b, 37);
+encoder.writeString (s);
+encoder.writeCRC ();
+}, $fz.isPrivate = true, $fz), "~S,~A,~N,~N,~S");
+c$.getApplicationText = Clazz.defineMethod (c$, "getApplicationText", 
+($fz = function (prefix, type, nPNG, nState) {
+var sPNG = "000000000" + nPNG;
+sPNG = sPNG.substring (sPNG.length - 9);
+var sState = "000000000" + nState;
+sState = sState.substring (sState.length - 9);
+return prefix + "\0" + type + (type.equals ("PNG") ? "0" : "") + sPNG + "+" + sState;
+}, $fz.isPrivate = true, $fz), "~S,~S,~N,~N");
+Clazz.defineMethod (c$, "writeHeader", 
+($fz = function () {
+this.writeInt4 (13);
+this.startPos = this.bytePos;
+this.writeString ("IHDR");
+this.writeInt4 (this.width);
+this.writeInt4 (this.height);
+this.writeByte (8);
+this.writeByte (this.encodeAlpha ? 6 : 2);
+this.writeByte (0);
+this.writeByte (0);
+this.writeByte (0);
+this.writeCRC ();
+}, $fz.isPrivate = true, $fz));
+Clazz.defineMethod (c$, "writeText", 
+($fz = function (msg) {
+this.writeInt4 (msg.length);
+this.startPos = this.bytePos;
+this.writeString ("tEXt" + msg);
+this.writeCRC ();
+}, $fz.isPrivate = true, $fz), "~S");
+Clazz.defineMethod (c$, "writeTransparentColor", 
+($fz = function (icolor) {
+this.writeInt4 (6);
+this.startPos = this.bytePos;
+this.writeString ("tRNS");
+this.writeInt2 ((icolor >> 16) & 0xFF);
+this.writeInt2 ((icolor >> 8) & 0xFF);
+this.writeInt2 (icolor & 0xFF);
+this.writeCRC ();
+}, $fz.isPrivate = true, $fz), "~N");
+Clazz.defineMethod (c$, "writeImageData", 
+($fz = function () {
+this.bytesPerPixel = (this.encodeAlpha ? 4 : 3);
+this.byteWidth = this.width * this.bytesPerPixel;
+var scanWidth = this.byteWidth + 1;
+var rowsLeft = this.height;
+var nRows;
+var scanPos;
+var deflater =  new java.util.zip.Deflater (this.compressionLevel);
+var outBytes =  new java.io.ByteArrayOutputStream (1024);
+var compBytes =  new java.util.zip.DeflaterOutputStream (outBytes, deflater);
+var pt = 0;
+try {
+while (rowsLeft > 0) {
+nRows = Math.max (1, Math.min (Clazz.doubleToInt (32767 / scanWidth), rowsLeft));
+this.scanLines =  Clazz.newByteArray (scanWidth * nRows, 0);
+var nPixels = this.width * nRows;
+scanPos = 0;
+for (var i = 0; i < nPixels; i++, pt++) {
+if (i % this.width == 0) {
+this.scanLines[scanPos++] = this.filter;
+}this.scanLines[scanPos++] = ((this.pixels[pt] >> 16) & 0xff);
+this.scanLines[scanPos++] = ((this.pixels[pt] >> 8) & 0xff);
+this.scanLines[scanPos++] = ((this.pixels[pt]) & 0xff);
+if (this.encodeAlpha) {
+this.scanLines[scanPos++] = ((this.pixels[pt] >> 24) & 0xff);
+}}
+compBytes.write (this.scanLines, 0, scanPos);
+rowsLeft -= nRows;
+}
+compBytes.close ();
+var compressedLines = outBytes.toByteArray ();
+this.writeInt4 (compressedLines.length);
+this.startPos = this.bytePos;
+this.writeString ("IDAT");
+this.writeBytes (compressedLines);
+this.writeCRC ();
+this.writeEnd ();
+deflater.finish ();
+return true;
+} catch (e) {
+if (Clazz.exceptionOf (e, java.io.IOException)) {
+System.err.println (e.toString ());
+return false;
+} else {
+throw e;
+}
+}
+}, $fz.isPrivate = true, $fz));
+Clazz.defineMethod (c$, "writeEnd", 
+($fz = function () {
+this.writeInt4 (0);
+this.startPos = this.bytePos;
+this.writeString ("IEND");
+this.writeCRC ();
+}, $fz.isPrivate = true, $fz));
+Clazz.defineStatics (c$,
+"FILTER_NONE", 0,
+"FILTER_SUB", 1,
+"FILTER_UP", 2,
+"FILTER_LAST", 2,
+"PT_FIRST_TAG", 37);
+});