Multi-color predictor; row predictor for sub and average
This commit is contained in:
parent
8edc61bd2f
commit
8d4d0a6752
22
pdf.js
22
pdf.js
@ -522,13 +522,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;
|
||||||
}
|
}
|
||||||
@ -536,19 +536,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;
|
||||||
|
Loading…
Reference in New Issue
Block a user