}
function error(msg) {
+ console.trace();
throw new Error(msg);
}
0x50007, 0x50017, 0x5000f, 0x00000
]), 5];
- function constructor(stream, params) {
+ function constructor(stream) {
this.stream = stream;
this.dict = stream.dict;
var cmf = stream.getByte();
var FilterPredictor = (function() {
function constructor(str, type, width, colors, bits) {
this.str = str;
+ this.dict = str.dict;
+
this.type = type;
this.width = width;
this.colors = colors;
if(!this.getNextLine())
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() {
if (this.type >= 10) {
- var curType = this.str.getRawByte();
+ var curType = this.str.getByte();
if (!curType)
return;
curType += 10;
var line = [];
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 rowBytes = this.rowBytes;
for (var i = 0, ii = pixBytes + 1; i < ii; ++i)
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) {
upLeftBuf[j] = upLeftBuf[j - 1];
- upLeftBuf[0] = prevLine[i];
+ }
+ upLeftBuf[0] = prevLine[i];
- var c = line[i - pixBytes];
- if (!c) {
- if (i > pixBytes)
- break;
- return;
- }
- switch (curType) {
- case 11:
- prevLine[i] = prevLine[i - pixBytes] + c;
- break;
- case 12:
- prevLine[i] = prevLine[i] + c;
- break;
- case 13:
- prevLine[i] = ((prevLine[i - pixBytes]
- + prevLine[i]) >> 1) + c;
+ var c = line[i - pixBytes];
+ if (c == undefined) {
+ if (i > pixBytes)
break;
- case 14:
- var left = prevLine[i - pixBytes];
- var up = prevLine[i];
- var upLeft = upLeftBuf[pixBytes];
- var p = left + up - upLeft;
-
- var pa = p - left;
- if (pa < 0)
- pa = -pa;
- var pb = p - up;
- if (pb < 0)
+ return;
+ }
+ switch (curType) {
+ case 11:
+ prevLine[i] = prevLine[i - pixBytes] + c;
+ break;
+ case 12:
+ prevLine[i] = prevLine[i] + c;
+ break;
+ case 13:
+ prevLine[i] = ((prevLine[i - pixBytes]
+ + prevLine[i]) >> 1) + c;
+ break;
+ case 14:
+ var left = prevLine[i - pixBytes];
+ var up = prevLine[i];
+ var upLeft = upLeftBuf[pixBytes];
+ var p = left + up - upLeft;
+
+ var pa = p - left;
+ if (pa < 0)
+ pa = -pa;
+ var pb = p - up;
+ if (pb < 0)
pb = -pb;
- var pc = p - upLeft;
- if (pc < 0)
- pc = -pc;
-
- if (pa <= pb && pa <= pc)
- prevLine[i] = left + c;
- else if (pb <= pc)
- prevLine[i] = up + c;
- else
- prevLine[i] = upLeft + c;
- break;
- case 10:
- default:
- prevLine[i] = c;
- break;
- }
+ var pc = p - upLeft;
+ if (pc < 0)
+ pc = -pc;
+
+ if (pa <= pb && pa <= pc)
+ prevLine[i] = left + c;
+ else if (pb <= pc)
+ prevLine[i] = up + c;
+ else
+ prevLine[i] = upLeft + c;
+ break;
+ case 10:
+ default:
+ prevLine[i] = c;
+ break;
}
}
var bits = this.bits;
var colors = this.colors;
- if (curPred === 2) {
+ if (curType === 2) {
if (bits === 1) {
var inbuf = prevLine[pixBytes - 1];
for (var i = pixBytes; i < rowBytes; i+= 8) {
}
}
}
- prevIdx = pixBytes;
+ this.prevIdx = pixBytes;
return true;
}
};
}
constructor.prototype = {
- toString: function() {
- return this.name;
- }
+ toString: function() {
+ return this.name;
+ }
};
return constructor;
}
constructor.prototype = {
- toString: function() {
- return this.cmd;
- }
+ toString: function() {
+ return this.cmd;
+ }
};
return constructor;
constructor.prototype = {
get: function(key) {
- return this.map[key];
- },
- get2: function(key1, key2) {
- return this.get(key1) || this.get(key2);
- },
- has: function(key) {
- return key in this.map;
- },
- set: function(key, value) {
- this.map[key] = value;
- },
- forEach: function(aCallback) {
+ return this.map[key];
+ },
+ get2: function(key1, key2) {
+ return this.get(key1) || this.get(key2);
+ },
+ has: function(key) {
+ return key in this.map;
+ },
+ set: function(key, value) {
+ this.map[key] = value;
+ },
+ forEach: function(aCallback) {
for (var key in this.map)
aCallback(key, this.map[key]);
},
}
function IsStream(v) {
- return typeof v == "object" && "getChar" in v;
+ return typeof v == "object" && "getByte" in v;
}
function IsRef(v) {
if (!cols)
cols = 1;
+ log("Predictor being used");
flateStr = new FilterPredictor(flateStr, predType, cols,
colors, bpc);
}
var smask = image.dict.get("SMask");
smask = xref.fetchIfRef(smask);
- if (IsStream(smask)) {
+ if (smask) {
if (inline)
error("cannot combine smask and inlining");
if (maskDecode)
TODO("Handle mask decode");
// handle matte object
- } else {
- smask = null;
}
var tmpCanvas = document.createElement("canvas");
if (bitsPerComponent != 8)
error("unhandled number of bits per component");
- if (smask) {
+ if (false && smask) {
if (maskColorSpace.numComps != 1)
error("Incorrect number of components in smask");
case "DeviceGray":
case "G":
this.numComps = 1;
+ case "DeviceRGB":
+ this.numComps = 3;
break;
}
TODO("fill in color space constructor");