Working version of predictors
This commit is contained in:
parent
2170c2408b
commit
8ce051c579
38
pdf.js
38
pdf.js
@ -18,6 +18,7 @@ function warn(msg) {
|
||||
}
|
||||
|
||||
function error(msg) {
|
||||
console.trace();
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
@ -231,7 +232,7 @@ var FlateStream = (function() {
|
||||
0x50007, 0x50017, 0x5000f, 0x00000
|
||||
]), 5];
|
||||
|
||||
function constructor(stream, params) {
|
||||
function constructor(stream) {
|
||||
this.stream = stream;
|
||||
this.dict = stream.dict;
|
||||
var cmf = stream.getByte();
|
||||
@ -510,6 +511,8 @@ var FlateStream = (function() {
|
||||
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;
|
||||
@ -536,11 +539,17 @@ var FilterPredictor = (function() {
|
||||
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;
|
||||
@ -550,7 +559,7 @@ var FilterPredictor = (function() {
|
||||
|
||||
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;
|
||||
@ -560,13 +569,14 @@ var FilterPredictor = (function() {
|
||||
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];
|
||||
|
||||
var c = line[i - pixBytes];
|
||||
if (!c) {
|
||||
if (c == undefined) {
|
||||
if (i > pixBytes)
|
||||
break;
|
||||
return;
|
||||
@ -611,11 +621,10 @@ var FilterPredictor = (function() {
|
||||
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) {
|
||||
@ -656,7 +665,7 @@ var FilterPredictor = (function() {
|
||||
}
|
||||
}
|
||||
}
|
||||
prevIdx = pixBytes;
|
||||
this.prevIdx = pixBytes;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@ -784,7 +793,7 @@ function IsArray(v) {
|
||||
}
|
||||
|
||||
function IsStream(v) {
|
||||
return typeof v == "object" && "getChar" in v;
|
||||
return typeof v == "object" && "getByte" in v;
|
||||
}
|
||||
|
||||
function IsRef(v) {
|
||||
@ -1294,6 +1303,7 @@ var Parser = (function() {
|
||||
if (!cols)
|
||||
cols = 1;
|
||||
|
||||
log("Predictor being used");
|
||||
flateStr = new FilterPredictor(flateStr, predType, cols,
|
||||
colors, bpc);
|
||||
}
|
||||
@ -2529,7 +2539,7 @@ var CanvasGraphics = (function() {
|
||||
var smask = image.dict.get("SMask");
|
||||
smask = xref.fetchIfRef(smask);
|
||||
|
||||
if (IsStream(smask)) {
|
||||
if (smask) {
|
||||
if (inline)
|
||||
error("cannot combine smask and inlining");
|
||||
|
||||
@ -2559,8 +2569,6 @@ var CanvasGraphics = (function() {
|
||||
if (maskDecode)
|
||||
TODO("Handle mask decode");
|
||||
// handle matte object
|
||||
} else {
|
||||
smask = null;
|
||||
}
|
||||
|
||||
var tmpCanvas = document.createElement("canvas");
|
||||
@ -2573,7 +2581,7 @@ var CanvasGraphics = (function() {
|
||||
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");
|
||||
|
||||
@ -2711,6 +2719,8 @@ var ColorSpace = (function() {
|
||||
case "DeviceGray":
|
||||
case "G":
|
||||
this.numComps = 1;
|
||||
case "DeviceRGB":
|
||||
this.numComps = 3;
|
||||
break;
|
||||
}
|
||||
TODO("fill in color space constructor");
|
||||
|
Loading…
x
Reference in New Issue
Block a user