Merge pull request #672 from kkujala/master

Refactor duplicate code in getBlackCode.
This commit is contained in:
vingtetun 2011-10-17 13:27:36 -07:00
commit 2dac9ce451

65
pdf.js
View File

@ -2089,45 +2089,36 @@ var CCITTFaxStream = (function ccittFaxStream() {
return p[1]; return p[1];
} }
} else { } else {
var n; var findBlackCode = function ccittFaxStreamFindBlackCode(start, end,
for (n = 2; n <= 6; ++n) { table, limit) {
code = this.lookBits(n); for (var i = start; i <= end; ++i) {
if (code == EOF) var code = this.lookBits(i);
return 1; if (code == EOF)
if (n < 6) return [true, 1];
code <<= 6 - n; if (i < end)
p = blackTable3[code]; code <<= end - i;
if (p[0] == n) { if (code >= limit) {
this.eatBits(n); var p = table[code - ((limit == -1) ? 0 : limit)];
return p[1]; if (p[0] == i) {
} this.eatBits(i);
} return [true, p[1]];
for (n = 7; n <= 12; ++n) { }
code = this.lookBits(n);
if (code == EOF)
return 1;
if (n < 12)
code <<= 12 - n;
if (code >= 64) {
p = blackTable2[code - 64];
if (p[0] == n) {
this.eatBits(n);
return p[1];
} }
} }
} return [false, 0];
for (n = 10; n <= 13; ++n) { };
code = this.lookBits(n);
if (code == EOF) var result = findBlackCode(2, 6, blackTable3, -1);
return 1; if (result[0])
if (n < 13) return result[1];
code <<= 13 - n;
p = blackTable1[code]; result = findBlackCode(7, 12, blackTable2, 64);
if (p[0] == n) { if (result[0])
this.eatBits(n); return result[1];
return p[1];
} result = findBlackCode(10, 13, blackTable1, -1);
} if (result[0])
return result[1];
} }
warn('bad black code'); warn('bad black code');
this.eatBits(1); this.eatBits(1);