Working version of predictors

This commit is contained in:
sbarman 2011-06-17 16:06:02 -07:00
parent 2170c2408b
commit 8ce051c579

38
pdf.js
View File

@ -18,6 +18,7 @@ function warn(msg) {
} }
function error(msg) { function error(msg) {
console.trace();
throw new Error(msg); throw new Error(msg);
} }
@ -231,7 +232,7 @@ var FlateStream = (function() {
0x50007, 0x50017, 0x5000f, 0x00000 0x50007, 0x50017, 0x5000f, 0x00000
]), 5]; ]), 5];
function constructor(stream, params) { function constructor(stream) {
this.stream = stream; this.stream = stream;
this.dict = stream.dict; this.dict = stream.dict;
var cmf = stream.getByte(); var cmf = stream.getByte();
@ -510,6 +511,8 @@ var FlateStream = (function() {
var FilterPredictor = (function() { var FilterPredictor = (function() {
function constructor(str, type, width, colors, bits) { function constructor(str, type, width, colors, bits) {
this.str = str; this.str = str;
this.dict = str.dict;
this.type = type; this.type = type;
this.width = width; this.width = width;
this.colors = colors; this.colors = colors;
@ -536,11 +539,17 @@ var FilterPredictor = (function() {
if(!this.getNextLine()) if(!this.getNextLine())
return; return;
} }
return this.prevLine[this.prevIdx]; return this.prevLine[this.prevIdx++];
},
getBytes: function(length) {
var buf = new Uint8Array(length);
for (var i = 0; i < length; ++i)
buf[i] = this.getByte();
return buf;
}, },
getNextLine: function() { getNextLine: function() {
if (this.type >= 10) { if (this.type >= 10) {
var curType = this.str.getRawByte(); var curType = this.str.getByte();
if (!curType) if (!curType)
return; return;
curType += 10; curType += 10;
@ -550,7 +559,7 @@ var FilterPredictor = (function() {
var line = []; var line = [];
for (var i = 0; i < this.rowBytes - this.pixBytes; i++) for (var i = 0; i < this.rowBytes - this.pixBytes; i++)
line.push(this.str.getRawByte()); line.push(this.str.getByte());
var pixBytes = this.pixBytes; var pixBytes = this.pixBytes;
var rowBytes = this.rowBytes; var rowBytes = this.rowBytes;
@ -560,13 +569,14 @@ var FilterPredictor = (function() {
for (var i = 0, ii = pixBytes + 1; i < ii; ++i) for (var i = 0, ii = pixBytes + 1; i < ii; ++i)
upLeftBuf.push(0); upLeftBuf.push(0);
for (var i = pixBytes, ii = rowBybtes; i < ii; ++i) { for (var i = pixBytes, ii = rowBytes; i < ii; ++i) {
for (var j = pixBytes; j > 0; --j) { for (var j = pixBytes; j > 0; --j) {
upLeftBuf[j] = upLeftBuf[j - 1]; upLeftBuf[j] = upLeftBuf[j - 1];
}
upLeftBuf[0] = prevLine[i]; upLeftBuf[0] = prevLine[i];
var c = line[i - pixBytes]; var c = line[i - pixBytes];
if (!c) { if (c == undefined) {
if (i > pixBytes) if (i > pixBytes)
break; break;
return; return;
@ -611,11 +621,10 @@ var FilterPredictor = (function() {
break; break;
} }
} }
}
var bits = this.bits; var bits = this.bits;
var colors = this.colors; var colors = this.colors;
if (curPred === 2) { if (curType === 2) {
if (bits === 1) { if (bits === 1) {
var inbuf = prevLine[pixBytes - 1]; var inbuf = prevLine[pixBytes - 1];
for (var i = pixBytes; i < rowBytes; i+= 8) { for (var i = pixBytes; i < rowBytes; i+= 8) {
@ -656,7 +665,7 @@ var FilterPredictor = (function() {
} }
} }
} }
prevIdx = pixBytes; this.prevIdx = pixBytes;
return true; return true;
} }
}; };
@ -784,7 +793,7 @@ function IsArray(v) {
} }
function IsStream(v) { function IsStream(v) {
return typeof v == "object" && "getChar" in v; return typeof v == "object" && "getByte" in v;
} }
function IsRef(v) { function IsRef(v) {
@ -1294,6 +1303,7 @@ var Parser = (function() {
if (!cols) if (!cols)
cols = 1; cols = 1;
log("Predictor being used");
flateStr = new FilterPredictor(flateStr, predType, cols, flateStr = new FilterPredictor(flateStr, predType, cols,
colors, bpc); colors, bpc);
} }
@ -2529,7 +2539,7 @@ var CanvasGraphics = (function() {
var smask = image.dict.get("SMask"); var smask = image.dict.get("SMask");
smask = xref.fetchIfRef(smask); smask = xref.fetchIfRef(smask);
if (IsStream(smask)) { if (smask) {
if (inline) if (inline)
error("cannot combine smask and inlining"); error("cannot combine smask and inlining");
@ -2559,8 +2569,6 @@ var CanvasGraphics = (function() {
if (maskDecode) if (maskDecode)
TODO("Handle mask decode"); TODO("Handle mask decode");
// handle matte object // handle matte object
} else {
smask = null;
} }
var tmpCanvas = document.createElement("canvas"); var tmpCanvas = document.createElement("canvas");
@ -2573,7 +2581,7 @@ var CanvasGraphics = (function() {
if (bitsPerComponent != 8) if (bitsPerComponent != 8)
error("unhandled number of bits per component"); error("unhandled number of bits per component");
if (smask) { if (false && smask) {
if (maskColorSpace.numComps != 1) if (maskColorSpace.numComps != 1)
error("Incorrect number of components in smask"); error("Incorrect number of components in smask");
@ -2711,6 +2719,8 @@ var ColorSpace = (function() {
case "DeviceGray": case "DeviceGray":
case "G": case "G":
this.numComps = 1; this.numComps = 1;
case "DeviceRGB":
this.numComps = 3;
break; break;
} }
TODO("fill in color space constructor"); TODO("fill in color space constructor");