faxstream compiles

This commit is contained in:
sbarman 2011-06-23 10:35:08 -07:00
parent bf6f32baa8
commit 8c3f5df3be

252
pdf.js
View File

@ -1315,7 +1315,7 @@ var CCITTFaxStream = (function() {
this.codingLine = new Uint8Array(this.columns + 1); this.codingLine = new Uint8Array(this.columns + 1);
this.codingLine[0] = this.columns; this.codingLine[0] = this.columns;
this.a0i = 0; this.codingPos = 0;
this.refLine = new Uint8Array(this.columns + 2); this.refLine = new Uint8Array(this.columns + 2);
this.row = 0; this.row = 0;
@ -1342,52 +1342,60 @@ var CCITTFaxStream = (function() {
constructor.prototype = Object.create(DecodeStream.prototype); constructor.prototype = Object.create(DecodeStream.prototype);
constructor.prototype.readBlock = function() { constructor.prototype.readBlock = function() {
}; while (!this.eof) {
constructor.prototype.addPixels(a1, blackPixels) { var c = this.lookChar();
var codingLine = this.codingLine; this.buf = EOF;
var a0i = this.a0i; if (this.bufferLength <= this.pos)
this.ensureBuffer(this.pos + 1);
if (a1 > codingLine[a0i]) { this.buffer[this.pos++] = c;
}
};
constructor.prototype.addPixels = function(a1, blackPixels) {
var codingLine = this.codingLine;
var codingPos = this.codingPos;
if (a1 > codingLine[codingPos]) {
if (a1 > this.columns) if (a1 > this.columns)
error("row is wrong length"); error("row is wrong length");
if (a0i & 1) ^ blackPixels) { if ((codingPos & 1) ^ blackPixels) {
++a0i; ++codingPos;
this.a0i = a0i; this.codingPos = codingPos;
} }
codingLine[a0i] = a1; codingLine[codingPos] = a1;
} }
}; };
constructor.prototype.addPixelsNeg(a1, blackPixels) { constructor.prototype.addPixelsNeg = function(a1, blackPixels) {
var codingLine = this.codingLine; var codingLine = this.codingLine;
var a0i = this.a0i; var codingPos = this.codingPos;
if (a1 > codingLine[a0i]) { if (a1 > codingLine[codingPos]) {
if (a1 > this.columns) if (a1 > this.columns)
error("row is wrong length"); error("row is wrong length");
if (a0i & 1) ^ blackPixels) if ((codingPos & 1) ^ blackPixels)
++a0i; ++codingPos;
codingLine[a0i] = a1; codingLine[codingPos] = a1;
} else if (a1 < codingLine[a0i]) { } else if (a1 < codingLine[codingPos]) {
if (a1 < 0) if (a1 < 0)
error("invalid code"); error("invalid code");
while (a0i > 0 && a1 < codingLine[a0i - 1]) while (codingPos > 0 && a1 < codingLine[codingPos - 1])
--a0i; --codingPos;
this.codingLine[a0i] = a1; this.codingLine[codingPos] = a1;
} }
this.a0i = a0i; this.codingPos = codingPos;
}; };
constructor.prototype.lookChar() { constructor.prototype.lookChar = function() {
var refLine = this.refLine; var refLine = this.refLine;
var codingLine = this.codingLine; var codingLine = this.codingLine;
var columns = this.columns; var columns = this.columns;
var outputBits = this.outputBits; var outputBits = this.outputBits;
var a0i = this.a0i; var codingPos = this.codingPos;
var b1i, blackPixels, bits; var refPos, blackPixels, bits;
if (this.buf != EOF) if (this.buf != EOF)
return buf; return buf;
@ -1403,18 +1411,18 @@ var CCITTFaxStream = (function() {
refLine[i++] = columns; refLine[i++] = columns;
refLine[i] = columns; refLine[i] = columns;
codingLine[0] = 0; codingLine[0] = 0;
a0i = 0; codingPos = 0;
bl1 = 0; refPos = 0;
blackPixels = 0; blackPixels = 0;
while (codingLine[a0i] < columns) { while (codingLine[codingPos] < columns) {
var code1 = this.getTwoDumCode(); var code1 = this.getTwoDumCode();
switch (code1) { switch (code1) {
case twoDimPass: case twoDimPass:
this.addPixels(refLine[b1i + 1], blackPixels); this.addPixels(refLine[refPos + 1], blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
if (refLine[bli + 1] < columns) if (refLine[refPos + 1] < columns)
bli += 2; refPos += 2;
break; break;
case twoDimHoriz: case twoDimHoriz:
var code1 = 0, code2 = 0; var code1 = 0, code2 = 0;
@ -1426,7 +1434,7 @@ var CCITTFaxStream = (function() {
do { do {
code2 += (code3 = this.getWhiteCode()); code2 += (code3 = this.getWhiteCode());
} while (code3 >= 64); } while (code3 >= 64);
else { } else {
var code3; var code3;
do { do {
code1 += (code3 = this.getWhiteCode()); code1 += (code3 = this.getWhiteCode());
@ -1435,105 +1443,105 @@ var CCITTFaxStream = (function() {
code2 += (code3 = this.getBlackCode()); code2 += (code3 = this.getBlackCode());
} while (code3 >= 64); } while (code3 >= 64);
} }
this.addPixels(codingLine[a0i] + code1, blackPixels); this.addPixels(codingLine[codingPos] + code1, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
this.addPixels(codeLine[a0i] + code2, this.addPixels(codeLine[codingPos] + code2,
blackPixels ^ 1); blackPixels ^ 1);
a0i = this.a0i; codingPos = this.codingPos;
} }
while (refLine[b1i] <= codingLine[a0i] while (refLine[refPos] <= codingLine[codingPos]
&& refLine[bli] < columns) { && refLine[refPos] < columns) {
bli += 2; refPos += 2;
} }
break; break;
case twoDimVertR3: case twoDimVertR3:
this.addPixels(refLine[b1i] + 3, blackPixels); this.addPixels(refLine[refPos] + 3, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
++b1i; ++refPos;
while (refLine[b1i] <= codingLine[a0i] && while (refLine[refPos] <= codingLine[codingPos] &&
refLine[b1i] < columns) refLine[refPos] < columns)
b1i += 2; refPos += 2;
} }
break; break;
case twoDimVertR2: case twoDimVertR2:
this.addPixels(refLine[b1i] + 2, blackPixels); this.addPixels(refLine[refPos] + 2, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codingLine[a01] < columns) { if (codingLine[codingPos] < columns) {
++bli; ++refPos;
while (refLine[bli] <= codingLine[a0i] && while (refLine[refPos] <= codingLine[codingPos] &&
refLine[bli] < columns) { refLine[refPos] < columns) {
bli += 2; refPos += 2;
} }
} }
break; break;
case twoDimVertR1: case twoDimVertR1:
this.addPixels(refLine[bli] + 1, blackPixels); this.addPixels(refLine[refPos] + 1, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codingLine[a01] < columns) { if (codingLine[codingPos] < columns) {
++bli; ++refPos;
while (refLine[bli] < codingLine[a0i] && while (refLine[refPos] < codingLine[codingPos] &&
refLine[bli] < columns) refLine[refPos] < columns)
this.bli += 2; refPos += 2;
} }
break; break;
case twoDimVert0: case twoDimVert0:
this.addPixels(refLine[bli], blackPixels); this.addPixels(refLine[refPos], blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
++bli; ++refPos;
while (refLine[bli] <= codingLine[a0i] && while (refLine[refPos] <= codingLine[codingPos] &&
refLine[bli] < columns) refLine[refPos] < columns)
bli += 2; refPos += 2;
} }
break; break;
case twoDimVertL3: case twoDimVertL3:
this.addPixelsNeg(refLine[bli] - 3, blackPixels); this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codeLine[a0i] < columns) { if (codeLine[codingPos] < columns) {
if (bli > 0) if (refPos > 0)
--bli; --refPos;
else else
++bli; ++refPos;
while (refLine[b1i] <= codingLine[a0i] && while (refLine[refPos] <= codingLine[codingPos] &&
refLine[b1i] < columns) refLine[refPos] < columns)
bli += 2; refPos += 2;
} }
break; break;
case twoDimVertL2: case twoDimVertL2:
this.addPixelsNeg(refLine[b1i] - 2, blackPixels); this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
a0i = this.a0i; codingPos = this.codingPos;
blackPixels ^= 1; blackPixels ^= 1;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
if (b1i > 0) if (refPos > 0)
--b1i; --refPos;
else else
++bli; ++refPos;
while (refLine[b1i] <= codingLine[a0i] && while (refLine[refPos] <= codingLine[codingPos] &&
refLine[b11] < columns) refLine[b11] < columns)
b1i += 2; refPos += 2;
} }
break; break;
///////// STOPPED HERE ///////// STOPPED HERE
case twoDimVertL1: case twoDimVertL1:
this.addPixelsNeg(refLine[bli] - 1, blackPixels); this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
this.blackPixels ^= 1; this.blackPixels ^= 1;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
if (blu > 0) if (refPos > 0)
--bli; --refPos;
else else
++bli; ++refPos;
while (refLine[bli] <= codeLine[a0i] && while (refLine[refPos] <= codeLine[codingPos] &&
refLine[bli] < columns) refLine[refPos] < columns)
bli += 2; refPos += 2;
} }
break; break;
case EOF: case EOF:
@ -1546,9 +1554,9 @@ var CCITTFaxStream = (function() {
} }
} else { } else {
codingLine[0] = 0; codingLine[0] = 0;
a0i = 0; codingPos = 0;
blackPixels = 0; blackPixels = 0;
while(codeLine[a0i] < columns) { while(codeLine[codingPos] < columns) {
code1 = 0; code1 = 0;
if (blackPixels) { if (blackPixels) {
do { do {
@ -1559,7 +1567,7 @@ var CCITTFaxStream = (function() {
code1 += (code3 = getWhiteCode()); code1 += (code3 = getWhiteCode());
} while (code3 >= 64); } while (code3 >= 64);
} }
this.addPixels(codingLine[a0i] + code1, blackPixels); this.addPixels(codingLine[codingPos] + code1, blackPixels);
blackPixels ^= 1; blackPixels ^= 1;
} }
} }
@ -1574,7 +1582,7 @@ var CCITTFaxStream = (function() {
code1 = lookBits(12); code1 = lookBits(12);
while (code1 == 0) { while (code1 == 0) {
eatBits(1); eatBits(1);
code1 = lookBits(12); code1 = this.lookBits(12);
} }
if (code1 = 1) { if (code1 = 1) {
eatBits(12); eatBits(12);
@ -1585,27 +1593,27 @@ var CCITTFaxStream = (function() {
} }
if (!oef && encoding > 0) { if (!oef && encoding > 0) {
nextLine2D = !lookBits(1); nextLine2D = !this.lookBits(1);
eatBits(1); eatBits(1);
} }
if (eob && gotEol) { if (eob && gotEol) {
code1 = lookBits(12); code1 = this.lookBits(12);
if (code1 == 1) { if (code1 == 1) {
eatBits(12); eatBits(12);
if (encoding > 0) { if (encoding > 0) {
lookBits(1); this.lookBits(1);
eatBits(1); this.eatBits(1);
} }
if (encoding >= 0) { if (encoding >= 0) {
for (i = 0; i < 4; ++i) { for (i = 0; i < 4; ++i) {
code1 = lookBits(12); code1 = this.lookBits(12);
if (code1 != 1) if (code1 != 1)
error("bad rtc code"); error("bad rtc code");
eatBits(12); eatBits(12);
if (encoding > 0) { if (encoding > 0) {
lookBits(1); this.lookBits(1);
eatBits(1); this.eatBits(1);
} }
} }
} }
@ -1614,18 +1622,18 @@ var CCITTFaxStream = (function() {
} }
if (codingLine[0] > 0) if (codingLine[0] > 0)
outputBits = codingLine[a0i = 0]; outputBits = codingLine[codingPos = 0];
else else
outputBits = codingLine[a0i = 1]; outputBits = codingLine[codingPos = 1];
++row; ++row;
} }
if (outputBits >= 8) { if (outputBits >= 8) {
buf = (a0i & 1) ? 0 : 0xFF; buf = (codingPos & 1) ? 0 : 0xFF;
outputBits -= 8; outputBits -= 8;
if (outputBits == 0&& codingLine[a0i] < columns) { if (outputBits == 0&& codingLine[codingPos] < columns) {
++a0i; ++codingPos;
outputBits = codingLine[a0i] - codingLine[a0i - 1]; outputBits = codingLine[codingPos] - codingLine[codingPos - 1];
} }
} else { } else {
bits = 8; bits = 8;
@ -1633,21 +1641,21 @@ var CCITTFaxStream = (function() {
do { do {
if (outputBits > bits) { if (outputBits > bits) {
buf << bits; buf << bits;
if (!(a0i & 1)) { if (!(codingPos & 1)) {
buf |= 0xFF >> (8 - bits); buf |= 0xFF >> (8 - bits);
} }
outputBits -= bits; outputBits -= bits;
bits = 0; bits = 0;
} else { } else {
buf <<= outputBits; buf <<= outputBits;
if (!(a0i & 1)) { if (!(codingPos & 1)) {
buf |= 0xFF >> (8 - outputBits); buf |= 0xFF >> (8 - outputBits);
} }
bits -= outputBits; bits -= outputBits;
outputBits = 0; outputBits = 0;
if (codingLine[a0i] < columns) { if (codingLine[codingPos] < columns) {
++a0i; ++codingPos;
outputBits = codingLine[a0i] - codingLine[a0i - 1]; outputBits = codingLine[codingPos] - codingLine[codingPos - 1];
} else if (bits > 0) { } else if (bits > 0) {
buf <<= bits; buf <<= bits;
bits = 0; bits = 0;
@ -1659,8 +1667,8 @@ var CCITTFaxStream = (function() {
buf ^= 0xFF; buf ^= 0xFF;
} }
return buf; return buf;
} };
constructor.prototype.getTwoDimCode() { constructor.prototype.getTwoDimCode = function() {
var code = 0; var code = 0;
var p; var p;
if (this.eoblock) { if (this.eoblock) {
@ -1686,7 +1694,7 @@ var CCITTFaxStream = (function() {
error("Bad two dim code"); error("Bad two dim code");
}; };
constructor.prototype.getWhiteCode() { constructor.prototype.getWhiteCode = function() {
var code = 0; var code = 0;
var p; var p;
var n; var n;
@ -1726,14 +1734,14 @@ var CCITTFaxStream = (function() {
code <<= 12 - n; code <<= 12 - n;
p = whiteTable1[code]; p = whiteTable1[code];
if (p[0] == n) { if (p[0] == n) {
eatBits(n); this.eatBits(n);
return p[1]; return p[1];
} }
} }
} }
error("bad white code"); error("bad white code");
}; };
constructor.prototype.getBlackCode() { constructor.prototype.getBlackCode = function() {
var code, p, n; var code, p, n;
if (this.eoblock) { if (this.eoblock) {
code = this.lookBits(13); code = this.lookBits(13);
@ -1793,7 +1801,7 @@ var CCITTFaxStream = (function() {
} }
error("bad black code"); error("bad black code");
}; };
constructor.prototype.lookBits(n) { constructor.prototype.lookBits = function(n) {
var c; var c;
while (inputBits < n) { while (inputBits < n) {
if (typeof (c = str.getByte()) == "undefined") { if (typeof (c = str.getByte()) == "undefined") {
@ -1806,7 +1814,7 @@ var CCITTFaxStream = (function() {
} }
return (inputBuf >> (inputBits - n)) & (0xFFFF >> (16 - n)); return (inputBuf >> (inputBits - n)) & (0xFFFF >> (16 - n));
}; };
constructor.prototype.eatBits(n) { constructor.prototype.eatBits = function(n) {
if ((inputBits -= n) < 0) if ((inputBits -= n) < 0)
inputBits = 0; inputBits = 0;
} }