]> git.parisson.com Git - pdf.js.git/commitdiff
Multi-color predictor; row predictor for sub and average
authornotmasteryet <async.processingjs@yahoo.com>
Mon, 20 Jun 2011 04:23:21 +0000 (23:23 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Mon, 20 Jun 2011 04:23:21 +0000 (23:23 -0500)
pdf.js

diff --git a/pdf.js b/pdf.js
index a051e57f3e687bc656f39aa9b3f53ebe34368ed3..f22d7c70defcab80cbd1d29cf7486ae4b7a98d77 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -522,13 +522,13 @@ var PredictorStream = (function() {
         this.colors = params.get("Colors") || 1;
         this.bitsPerComponent = params.get("BitsPerComponent") || 8;
         this.columns = params.get("Columns") || 1;
-        if (this.colors !== 1 || this.bitsPerComponent !== 8) {
-            error("Multi-color and multi-byte predictors are not supported");
+        if (this.bitsPerComponent !== 8) {
+            error("Multi-byte predictors are not supported");
         }
         if (this.predictor < 10 || this.predictor > 15) {
             error("Unsupported predictor");
         }
-        this.currentRow = new Uint8Array(this.columns);
+        this.currentRow = new Uint8Array(this.columns * this.colors);
         this.pos = 0;
         this.bufferLength = 0;
     }
@@ -536,19 +536,33 @@ var PredictorStream = (function() {
     constructor.prototype = {
         readRow : function() {
             var lastRow = this.currentRow;
+            var colors = this.colors;
             var predictor = this.stream.getByte();
-            var currentRow = this.stream.getBytes(this.columns), i;
+            var currentRow = this.stream.getBytes(this.columns * colors), i;
             switch (predictor) {
             default:
                 error("Unsupported predictor");
                 break;
             case 0:
                 break;
+            case 1:
+                for (i = colors; i < currentRow.length; ++i) {
+                  currentRow[i] = (currentRow[i - colors] + currentRow[i]) & 0xFF;
+                }
+                break;
             case 2:
                 for (i = 0; i < currentRow.length; ++i) {
                   currentRow[i] = (lastRow[i] + currentRow[i]) & 0xFF;
                 }
                 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.bufferLength = currentRow.length;