1 Clazz.declarePackage ("javajs.img");
\r
2 Clazz.load (["javajs.img.ImageEncoder"], "javajs.img.CRCEncoder", ["java.util.zip.CRC32", "javajs.util.AU"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
7 this.pngBytes = null;
\r
11 Clazz.instantialize (this, arguments);
\r
12 }, javajs.img, "CRCEncoder", javajs.img.ImageEncoder);
\r
13 Clazz.prepareFields (c$, function () {
\r
14 this.int2 = Clazz.newByteArray (2, 0);
\r
15 this.int4 = Clazz.newByteArray (4, 0);
\r
17 Clazz.makeConstructor (c$,
\r
19 Clazz.superConstructor (this, javajs.img.CRCEncoder, []);
\r
20 this.pngBytes = Clazz.newByteArray (250, 0);
\r
21 this.crc = new java.util.zip.CRC32 ();
\r
23 Clazz.defineMethod (c$, "setData",
\r
26 this.dataLen = b.length;
\r
27 this.startPos = this.bytePos = pt;
\r
29 Clazz.defineMethod (c$, "getBytes",
\r
31 return (this.dataLen == this.pngBytes.length ? this.pngBytes : javajs.util.AU.arrayCopyByte (this.pngBytes, this.dataLen));
\r
33 Clazz.defineMethod (c$, "writeCRC",
\r
36 this.crc.update (this.pngBytes, this.startPos, this.bytePos - this.startPos);
\r
37 this.writeInt4 (this.crc.getValue ());
\r
39 Clazz.defineMethod (c$, "writeInt2",
\r
41 this.int2[0] = ((n >> 8) & 0xff);
\r
42 this.int2[1] = (n & 0xff);
\r
43 this.writeBytes (this.int2);
\r
45 Clazz.defineMethod (c$, "writeInt4",
\r
47 javajs.img.CRCEncoder.getInt4 (n, this.int4);
\r
48 this.writeBytes (this.int4);
\r
50 c$.getInt4 = Clazz.defineMethod (c$, "getInt4",
\r
51 function (n, int4) {
\r
52 int4[0] = ((n >> 24) & 0xff);
\r
53 int4[1] = ((n >> 16) & 0xff);
\r
54 int4[2] = ((n >> 8) & 0xff);
\r
55 int4[3] = (n & 0xff);
\r
57 Clazz.defineMethod (c$, "writeByte",
\r
59 var temp = Clazz.newByteArray (-1, [b]);
\r
60 this.writeBytes (temp);
\r
62 Clazz.defineMethod (c$, "writeString",
\r
64 this.writeBytes (s.getBytes ());
\r
66 Clazz.defineMethod (c$, "writeBytes",
\r
68 var newPos = this.bytePos + data.length;
\r
69 this.dataLen = Math.max (this.dataLen, newPos);
\r
70 if (newPos > this.pngBytes.length) this.pngBytes = javajs.util.AU.arrayCopyByte (this.pngBytes, newPos + 16);
\r
71 System.arraycopy (data, 0, this.pngBytes, this.bytePos, data.length);
\r
72 this.bytePos = newPos;
\r