Merge branch 'pngpredictor' of https://github.com/notmasteryet/pdf.js into predictor

This commit is contained in:
sbarman 2011-06-20 16:02:29 -07:00
commit 72d8bf4fda

22
pdf.js
View File

@ -687,13 +687,13 @@ var PredictorStream = (function() {
this.colors = params.get("Colors") || 1; this.colors = params.get("Colors") || 1;
this.bitsPerComponent = params.get("BitsPerComponent") || 8; this.bitsPerComponent = params.get("BitsPerComponent") || 8;
this.columns = params.get("Columns") || 1; this.columns = params.get("Columns") || 1;
if (this.colors !== 1 || this.bitsPerComponent !== 8) { if (this.bitsPerComponent !== 8) {
error("Multi-color and multi-byte predictors are not supported"); error("Multi-byte predictors are not supported");
} }
if (this.predictor < 10 || this.predictor > 15) { if (this.predictor < 10 || this.predictor > 15) {
error("Unsupported predictor"); error("Unsupported predictor");
} }
this.currentRow = new Uint8Array(this.columns); this.currentRow = new Uint8Array(this.columns * this.colors);
this.pos = 0; this.pos = 0;
this.bufferLength = 0; this.bufferLength = 0;
} }
@ -701,19 +701,33 @@ var PredictorStream = (function() {
constructor.prototype = { constructor.prototype = {
readRow : function() { readRow : function() {
var lastRow = this.currentRow; var lastRow = this.currentRow;
var colors = this.colors;
var predictor = this.stream.getByte(); var predictor = this.stream.getByte();
var currentRow = this.stream.getBytes(this.columns), i; var currentRow = this.stream.getBytes(this.columns * colors), i;
switch (predictor) { switch (predictor) {
default: default:
error("Unsupported predictor"); error("Unsupported predictor");
break; break;
case 0: case 0:
break; break;
case 1:
for (i = colors; i < currentRow.length; ++i) {
currentRow[i] = (currentRow[i - colors] + currentRow[i]) & 0xFF;
}
break;
case 2: case 2:
for (i = 0; i < currentRow.length; ++i) { for (i = 0; i < currentRow.length; ++i) {
currentRow[i] = (lastRow[i] + currentRow[i]) & 0xFF; currentRow[i] = (lastRow[i] + currentRow[i]) & 0xFF;
} }
break; break;
case 3:
for (i = 0; i < color; ++i) {
currentRow[i] = ((lastRow[i] >> 1) + currentRow[i]) & 0xFF;
}
for (; i < currentRow.length; ++i) {
currentRow[i] = (((lastRow[i] + currentRow[i]) >> 1) + currentRow[i]) & 0xFF;
}
break;
} }
this.pos = 0; this.pos = 0;
this.bufferLength = currentRow.length; this.bufferLength = currentRow.length;