JAL-1807 test
[jalviewjs.git] / bin / javajs / img / CRCEncoder.js
1 Clazz.declarePackage ("javajs.img");
2 Clazz.load (["javajs.img.ImageEncoder"], "javajs.img.CRCEncoder", ["java.util.zip.CRC32", "javajs.util.AU"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.startPos = 0;
5 this.bytePos = 0;
6 this.crc = null;
7 this.pngBytes = null;
8 this.dataLen = 0;
9 this.int2 = null;
10 this.int4 = null;
11 Clazz.instantialize (this, arguments);
12 }, javajs.img, "CRCEncoder", javajs.img.ImageEncoder);
13 Clazz.prepareFields (c$, function () {
14 this.int2 =  Clazz.newByteArray (2, 0);
15 this.int4 =  Clazz.newByteArray (4, 0);
16 });
17 Clazz.makeConstructor (c$, 
18 function () {
19 Clazz.superConstructor (this, javajs.img.CRCEncoder, []);
20 this.pngBytes =  Clazz.newByteArray (250, 0);
21 this.crc =  new java.util.zip.CRC32 ();
22 });
23 Clazz.defineMethod (c$, "setData", 
24 function (b, pt) {
25 this.pngBytes = b;
26 this.dataLen = b.length;
27 this.startPos = this.bytePos = pt;
28 }, "~A,~N");
29 Clazz.defineMethod (c$, "getBytes", 
30 function () {
31 return (this.dataLen == this.pngBytes.length ? this.pngBytes : javajs.util.AU.arrayCopyByte (this.pngBytes, this.dataLen));
32 });
33 Clazz.defineMethod (c$, "writeCRC", 
34 function () {
35 this.crc.reset ();
36 this.crc.update (this.pngBytes, this.startPos, this.bytePos - this.startPos);
37 this.writeInt4 (this.crc.getValue ());
38 });
39 Clazz.defineMethod (c$, "writeInt2", 
40 function (n) {
41 this.int2[0] = ((n >> 8) & 0xff);
42 this.int2[1] = (n & 0xff);
43 this.writeBytes (this.int2);
44 }, "~N");
45 Clazz.defineMethod (c$, "writeInt4", 
46 function (n) {
47 javajs.img.CRCEncoder.getInt4 (n, this.int4);
48 this.writeBytes (this.int4);
49 }, "~N");
50 c$.getInt4 = Clazz.defineMethod (c$, "getInt4", 
51 function (n, int4) {
52 int4[0] = ((n >> 24) & 0xff);
53 int4[1] = ((n >> 16) & 0xff);
54 int4[2] = ((n >> 8) & 0xff);
55 int4[3] = (n & 0xff);
56 }, "~N,~A");
57 Clazz.defineMethod (c$, "writeByte", 
58 function (b) {
59 var temp =  Clazz.newByteArray (-1, [b]);
60 this.writeBytes (temp);
61 }, "~N");
62 Clazz.defineMethod (c$, "writeString", 
63 function (s) {
64 this.writeBytes (s.getBytes ());
65 }, "~S");
66 Clazz.defineMethod (c$, "writeBytes", 
67 function (data) {
68 var newPos = this.bytePos + data.length;
69 this.dataLen = Math.max (this.dataLen, newPos);
70 if (newPos > this.pngBytes.length) this.pngBytes = javajs.util.AU.arrayCopyByte (this.pngBytes, newPos + 16);
71 System.arraycopy (data, 0, this.pngBytes, this.bytePos, data.length);
72 this.bytePos = newPos;
73 }, "~A");
74 });