this.black = params.get("BlackIs1") || false;
this.codingLine = new Uint32Array(this.columns + 1);
+ this.refLine = new Uint32Array(this.columns + 2);
+
this.codingLine[0] = this.columns;
this.codingPos = 0;
- this.refLine = new Uint32Array(this.columns + 2);
this.row = 0;
this.nextLine2D = this.encoding < 0;
this.inputBits = 0;
constructor.prototype = Object.create(DecodeStream.prototype);
constructor.prototype.readBlock = function() {
+ var vals = [];
while (!this.eof) {
var c = this.lookChar();
+ vals.push(c);
this.buf = EOF;
this.ensureBuffer(this.bufferLength + 1);
this.buffer[this.bufferLength++] = c;
}
+ var all = "";
+ for (var i = 0; i < vals.length; ++i)
+ all += vals[i] + " \n";
+
+ var text = document.getElementById("text");
+ text.value = all;
};
constructor.prototype.addPixels = function(a1, blackPixels) {
var codingLine = this.codingLine;
if (this.buf != EOF)
return buf;
- this.err = false;
-
if (this.outputBits == 0) {
if (this.eof)
return;
blackPixels ^= 1;
if (codingLine[this.codingPos] < columns) {
++refPos;
- while (refLine[refPos] < codingLine[this.codingPos] &&
+ while (refLine[refPos] <= codingLine[this.codingPos] &&
refLine[refPos] < columns)
refPos += 2;
}
refPos += 2;
}
break;
-
case twoDimVertL1:
this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
blackPixels ^= 1;
break;
default:
warn("bad 2d code");
- addPixels(columns, 0);
+ this.addPixels(columns, 0);
this.err = true;
break;
}
var gotEOL = false;
- if (this.eoblock && this.row == this.rows - 1) {
+ if (!this.eoblock && this.row == this.rows - 1) {
this.eof = true;
} else {
code1 = this.lookBits(12);
if (this.eoblock && gotEOL) {
code1 = this.lookBits(12);
if (code1 == 1) {
- eatBits(12);
+ this.eatBits(12);
if (this.encoding > 0) {
this.lookBits(1);
this.eatBits(1);
for (var i = 0; i < 4; ++i) {
code1 = this.lookBits(12);
if (code1 != 1)
- error("bad rtc code");
+ warning("bad rtc code");
this.eatBits(12);
if (this.encoding > 0) {
this.lookBits(1);
}
this.eof = true;
}
- } else if (this.err && this.eolin) {
+ } else if (this.err && this.eoline) {
var code1;
while (true) {
code1 = this.lookBits(13);
this.eatBits(12);
if (this.encoding > 0) {
this.eatBits(1);
- this.nextLine2 = !(code1 & 1);
+ this.nextLine2D = !(code1 & 1);
}
}
this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
}
} else {
- this.bits = 8;
+ var bits = 8;
this.buf = 0;
do {
- if (this.outputBits > this.bits) {
- this.buf << this.bits;
+ if (this.outputBits > bits) {
+ this.buf <<= bits;
if (!(this.codingPos & 1)) {
- this.buf |= 0xFF >> (8 - this.bits);
+ this.buf |= 0xFF >> (8 - bits);
}
- this.outputBits -= this.bits;
- this.bits = 0;
+ this.outputBits -= bits;
+ bits = 0;
} else {
this.buf <<= this.outputBits;
if (!(this.codingPos & 1)) {
this.buf |= 0xFF >> (8 - this.outputBits);
}
- this.bits -= this.outputBits;
+ bits -= this.outputBits;
this.outputBits = 0;
if (codingLine[this.codingPos] < columns) {
this.codingPos++;
this.outputBits = codingLine[this.codingPos] - codingLine[this.codingPos - 1];
- } else if (this.bits > 0) {
- this.buf <<= this.bits;
- this.bits = 0;
+ } else if (bits > 0) {
+ this.buf <<= bits;
+ bits = 0;
}
}
- } while (this.bits);
+ } while (bits);
}
if (this.black) {
this.buf ^= 0xFF;
var n;
if (this.eoblock) {
code = this.lookBits(12);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if ((code >> 5) == 0)
} else {
for (var n = 1; n <= 9; ++n) {
code = this.lookBits(n);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if (n < 9)
code <<= 9 - n;
p = whiteTable2[code];
if (p[0] == n) {
- this.eatBits(n);
+ this.eatBits(n);
return p[0];
}
}
for (var n = 11; n <= 12; ++n) {
code == this.lookBits(n);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if (n < 12)
code <<= 12 - n;
var code, p, n;
if (this.eoblock) {
code = this.lookBits(13);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if ((code >> 7) == 0)
p = blackTable1[code];
} else {
for (var n = 2; n <= 6; ++n) {
code = this.lookBits(n);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if (n < 6)
code <<= 6 - n;
}
for (var n = 7; n <= 12; ++n) {
code = this.lookBits(n);
- if (typeof code == "undefined")
+ if (code == EOF)
return 1;
if (n < 12)
code <<= 12 - n;
if (numComps != 1)
error("worng numComps");
+ ctx.strokeStyle = "#090";
+ ctx.strokeRect(0 + 1, -h + 1, w / 2, h -2 );
+
var imgArray = image.getBytes((numComps * w * h) >> 3);
var imgIdx = 0;
var imgData = tmpCtx.getImageData(0, 0, w, h);
var pixels = imgData.data;
- var mask = 128;
+ var mask = 1;
var b = 0;
- for (var i = 0, length = imgArray.length*8*4; i < length; i += 4) {
- mask <<= 1;
- if (mask >= 256) {
+ for (var i = 0, length = 4 * w * h; i < length; i += 4) {
+ mask >>= 1;
+ if (mask <= 0) {
b = imgArray[imgIdx++];
- mask = 1;
+ mask = 128;
}
var p = b & mask;