]> git.parisson.com Git - pdf.js.git/commitdiff
Cleaning up FaxStream
authorsbarman <sbarman@L3CWZ5T.(none)>
Thu, 23 Jun 2011 01:56:33 +0000 (18:56 -0700)
committersbarman <sbarman@L3CWZ5T.(none)>
Thu, 23 Jun 2011 01:56:33 +0000 (18:56 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 8cb1d07d1278f2558459397f3c24601b439828f6..a43dcf559682e793f909e4bdbfd35aeaa1cbbc48 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -839,7 +839,7 @@ var Ascii85Stream = (function() {
     return constructor;
 })();
 
-var CcittFaxStream = (function() {
+var CCITTFaxStream = (function() {
 
     const ccittEOL = -2;
     const twoDimPass = 0;
@@ -1284,12 +1284,15 @@ var CcittFaxStream = (function() {
 
         this.codingLine = new Uint8Array(this.columns + 1);
         this.codingLine[0] = this.columns;
+        this.a0i = 0;
+
         this.refLine = new Uint8Array(this.columns + 2);
         this.row = 0;
         this.nextLine2D = this.encoding < 0;
         this.inputBits = 0;
-        this.a0i = 0;
+        this.inputBuf;
         this.outputBits = 0;
+        this.buf = EOF;
 
         var code1;
         while ((code1 = this.lookBits(12)) == 0) {
@@ -1310,57 +1313,81 @@ var CcittFaxStream = (function() {
     constructor.prototype.readBlock = function() {
     };
     constructor.prototype.addPixels(a1, blackPixels) {
-        if (a1 > this.codingLine[this.a01]) {
+        var codingLine = this.codingLine;
+        var a0i = this.a0i;
+
+        if (a1 > codingLine[a0i]) {
             if (a1 > this.columns)
                 error("row is wrong length");
-            if (this.a0i & 1) ^ this.blackPixels)
-                this.a0i++;
+            if (a0i & 1) ^ blackPixels) {
+                ++a0i;
+                this.a0i = a0i;
+            }
 
-            this.codingLine[this.a0i] = a1;
+            codingLine[a0i] = a1;
+        }
     };
     constructor.prototype.addPixelsNeg(a1, blackPixels) {
-        if (a1 > this.codingLine[this.a01]) {
+        var codingLine = this.codingLine;
+        var a0i = this.a0i;
+
+        if (a1 > codingLine[a0i]) {
             if (a1 > this.columns)
                 error("row is wrong length");
-            if (this.a0i & 1) ^ this.blackPixels)
-                this.a0i++;
+            if (a0i & 1) ^ blackPixels)
+                ++a0i;
 
-            this.codingLine[this.a0i] = a1;
-        } else if (at < this.codingLine[this.a0i]) {
+            codingLine[a0i] = a1;
+        } else if (a1 < codingLine[a0i]) {
             if (a1 < 0)
                 error("invalid code");
-            while (this.a0i > 0 && a1 < this.codingLine[this.a0i -i])
-                this.a0i--;
-            this.codingLine[this.a0i] = a1;
+            while (a0i > 0 && a1 < codingLine[a0i - 1])
+                --a0i;
+            this.codingLine[a0i] = a1;
         }
+
+        this.a0i = a0i;
     };
-    constructor.prototype.lookChar(a1, blackPixels) {
+    constructor.prototype.lookChar() {
         var refLine = this.refLine;
         var codingLine = this.codingLine;
         var columns = this.columns;
 
-        if (this.outputBits == 0) {
+        var outputBits = this.outputBits;
+        var a0i = this.a0i;
+
+        var b1i, blackPixels, bits;
+
+        if (this.buf != EOF)
+            return buf;
+
+        if (outputBits == 0) {
+            if (this.eof)
+                return;
+
             if (this.nextLine2D) {
                 for (var i = 0; codingLine[i] < columns; ++i)
-                    refLine[i] = codeLine[i];
+                    refLine[i] = codingLine[i];
+
                 refLine[i++] = columns;
                 refLine[i] = columns;
                 codingLine[0] = 0;
-                this.a0i = 0;
-                this.bl1 = 0;
-                this.blackPixels = 0;
+                a0i = 0;
+                bl1 = 0;
+                blackPixels = 0;
 
-                while (codingLine[this.a0i] < columns) {
+                while (codingLine[a0i] < columns) {
                     var code1 = this.getTwoDumCode();
                     switch (code1) {
                     case twoDimPass:
-                        this.addPixels(refLine[this.bli + 1], this.blackPixels);
-                        if (refLine[this.bli + 1] < columns)
-                            this.bli += 2;
+                        this.addPixels(refLine[b1i + 1], blackPixels);
+                        a0i = this.a0i;
+                        if (refLine[bli + 1] < columns)
+                            bli += 2;
                         break;
                     case twoDimHoriz:
                         var code1 = 0, code2 = 0;
-                        if (this.blackPixels) {
+                        if (blackPixels) {
                             var code3;
                             do {
                                 code1 += (code3 = this.getBlackCode());
@@ -1371,75 +1398,99 @@ var CcittFaxStream = (function() {
                         else {
                             var code3;
                             do {
-                                code1 += (code3 = getWhiteCode());
+                                code1 += (code3 = this.getWhiteCode());
                             } while (code3 >= 64);
-                            this.addPixels(codeLine[this.a0i + code1, this.blackPixels);
-                            if (codeLine[a0i] < columns) {
-                                addPixels(codeLine[a0i] + code2, this.blackPixels ^ 1);
-                            }
-                            while (refLine[this.bli] <= codingLine[a0i] 
-                                    && refLine[this.bli] < columns) {
-                                this.bli += 2;
-                            }
+                            do {
+                                code2 += (code3 = this.getBlackCode());
+                            } while (code3 >= 64);
+                        }
+                        this.addPixels(codingLine[a0i] + code1, blackPixels);
+                        a0i = this.a0i;
+                        if (codingLine[a0i] < columns) {
+                            this.addPixels(codeLine[a0i] + code2,
+                                    blackPixels ^ 1);
+                            a0i = this.a0i;
+                        }
+                        while (refLine[b1i] <= codingLine[a0i] 
+                                && refLine[bli] < columns) {
+                            bli += 2;
+                        }    
+                        break;
+                    case twoDimVertR3:
+                        this.addPixels(refLine[b1i] + 3, blackPixels);
+                        a0i = this.a0i;
+                        blackPixels ^= 1;
+                        if (codingLine[a0i] < columns) {
+                            ++b1i;
+                            while (refLine[b1i] <= codingLine[a0i] &&
+                                    refLine[b1i] < columns)
+                                b1i += 2;
                         }
                         break;
                     case twoDimVertR2:
-                        this.addPixels(this.refLine[this.bli], blackPixels);
+                        this.addPixels(refLine[b1i] + 2, blackPixels);
+                        a0i = this.a0i;
                         blackPixels ^= 1;
-                        if (codeLine[this.a01] < columns) {
-                            this.bli++;
-                            while (refLine[this.bli] <= codeLine[this.a0i] &&
+                        if (codingLine[a01] < columns) {
+                            ++bli;
+                            while (refLine[bli] <= codingLine[a0i] &&
                                     refLine[bli] < columns) {
-                                this.bli += 2;
+                                bli += 2;
                             }
                         }
                         break;
                     case twoDimVertR1:
-                        this.addPixels(refLine[this.bli] + 1, blackPixels);
-                        this.blackPixels ^= 1;
-                        if (codeLine[this.a01] < columns) {
-                            this.bli++;
-                            while (refLine[this.bli] < codingLine[this.a0i] &&
-                                    refLine[this.bli] < columns)
+                        this.addPixels(refLine[bli] + 1, blackPixels);
+                        a0i = this.a0i;
+                        blackPixels ^= 1;
+                        if (codingLine[a01] < columns) {
+                            ++bli;
+                            while (refLine[bli] < codingLine[a0i] &&
+                                    refLine[bli] < columns)
                                 this.bli += 2;
                         }
                         break;
                     case twoDimVert0:
-                        this.addPixels(refLine[this.bli], blackPixels);
-                        this.blackPixels ^= 1;
-                        if (codingLine[this.a0i] < columns) {
-                            this.bli++;
-                            while (refLine[this.bli] <= codingLine[a0i] &&
-                                    refLine[this.bli] < columns)
-                                this.bli += 2;
+                        this.addPixels(refLine[bli], blackPixels);
+                        a0i = this.a0i;
+                        blackPixels ^= 1;
+                        if (codingLine[a0i] < columns) {
+                            ++bli;
+                            while (refLine[bli] <= codingLine[a0i] &&
+                                    refLine[bli] < columns)
+                                bli += 2;
                         }
                         break;
                     case twoDimVertL3:
-                        this.addPixelsNeg(refLine[this.bli] - 3, blackPixels);
-                        this.blackPixels ^= 1;
+                        this.addPixelsNeg(refLine[bli] - 3, blackPixels);
+                        a0i = this.a0i;
+                        blackPixels ^= 1;
                         if (codeLine[a0i] < columns) {
                             if (bli > 0)
                                 --bli;
                             else
                                 ++bli;
-                            while (refLine[bli] <= codingLine[a0i] &&
-                                    refLine[bli] < columns)
+                            while (refLine[b1i] <= codingLine[a0i] &&
+                                    refLine[b1i] < columns)
                                 bli += 2;
                         }
                         break;
                     case twoDimVertL2:
-                        this.addPixelsNeg(refLine[bli] - 2, blackPixels);
+                        this.addPixelsNeg(refLine[b1i] - 2, blackPixels);
+                        a0i = this.a0i;
                         blackPixels ^= 1;
                         if (codingLine[a0i] < columns) {
-                            if (bli > 0)
-                                --bli;
+                            if (b1i > 0)
+                                --b1i;
                             else
                                 ++bli;
-                            while (refLine[bli] <= codingLine[a0i] &&
-                                    refLine[bl1] < columns)
-                                bli += 2;
+                            while (refLine[b1i] <= codingLine[a0i] &&
+                                    refLine[b11] < columns)
+                                b1i += 2;
                         }
                         break;
+
+///////// STOPPED HERE
                     case twoDimVertL1:
                         this.addPixelsNeg(refLine[bli] - 1, blackPixels);
                         this.blackPixels ^= 1;