Working version of predictors
This commit is contained in:
parent
ce09870e2b
commit
3da5245abf
154
pdf.js
154
pdf.js
@ -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,62 +569,62 @@ 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;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
switch (curType) {
|
|
||||||
case 11:
|
|
||||||
prevLine[i] = prevLine[i - pixBytes] + c;
|
|
||||||
break;
|
break;
|
||||||
case 12:
|
return;
|
||||||
prevLine[i] = prevLine[i] + c;
|
}
|
||||||
break;
|
switch (curType) {
|
||||||
case 13:
|
case 11:
|
||||||
prevLine[i] = ((prevLine[i - pixBytes]
|
prevLine[i] = prevLine[i - pixBytes] + c;
|
||||||
+ prevLine[i]) >> 1) + c;
|
break;
|
||||||
break;
|
case 12:
|
||||||
case 14:
|
prevLine[i] = prevLine[i] + c;
|
||||||
var left = prevLine[i - pixBytes];
|
break;
|
||||||
var up = prevLine[i];
|
case 13:
|
||||||
var upLeft = upLeftBuf[pixBytes];
|
prevLine[i] = ((prevLine[i - pixBytes]
|
||||||
var p = left + up - upLeft;
|
+ 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;
|
var pa = p - left;
|
||||||
if (pa < 0)
|
if (pa < 0)
|
||||||
pa = -pa;
|
pa = -pa;
|
||||||
var pb = p - up;
|
var pb = p - up;
|
||||||
if (pb < 0)
|
if (pb < 0)
|
||||||
pb = -pb;
|
pb = -pb;
|
||||||
var pc = p - upLeft;
|
var pc = p - upLeft;
|
||||||
if (pc < 0)
|
if (pc < 0)
|
||||||
pc = -pc;
|
pc = -pc;
|
||||||
|
|
||||||
if (pa <= pb && pa <= pc)
|
if (pa <= pb && pa <= pc)
|
||||||
prevLine[i] = left + c;
|
prevLine[i] = left + c;
|
||||||
else if (pb <= pc)
|
else if (pb <= pc)
|
||||||
prevLine[i] = up + c;
|
prevLine[i] = up + c;
|
||||||
else
|
else
|
||||||
prevLine[i] = upLeft + c;
|
prevLine[i] = upLeft + c;
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
default:
|
default:
|
||||||
prevLine[i] = c;
|
prevLine[i] = c;
|
||||||
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -680,9 +689,9 @@ var Name = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return constructor;
|
return constructor;
|
||||||
@ -694,9 +703,9 @@ var Cmd = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
toString: function() {
|
toString: function() {
|
||||||
return this.cmd;
|
return this.cmd;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return constructor;
|
return constructor;
|
||||||
@ -709,18 +718,18 @@ var Dict = (function() {
|
|||||||
|
|
||||||
constructor.prototype = {
|
constructor.prototype = {
|
||||||
get: function(key) {
|
get: function(key) {
|
||||||
return this.map[key];
|
return this.map[key];
|
||||||
},
|
},
|
||||||
get2: function(key1, key2) {
|
get2: function(key1, key2) {
|
||||||
return this.get(key1) || this.get(key2);
|
return this.get(key1) || this.get(key2);
|
||||||
},
|
},
|
||||||
has: function(key) {
|
has: function(key) {
|
||||||
return key in this.map;
|
return key in this.map;
|
||||||
},
|
},
|
||||||
set: function(key, value) {
|
set: function(key, value) {
|
||||||
this.map[key] = value;
|
this.map[key] = value;
|
||||||
},
|
},
|
||||||
forEach: function(aCallback) {
|
forEach: function(aCallback) {
|
||||||
for (var key in this.map)
|
for (var key in this.map)
|
||||||
aCallback(key, this.map[key]);
|
aCallback(key, this.map[key]);
|
||||||
},
|
},
|
||||||
@ -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");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user