]> git.parisson.com Git - pdf.js.git/commitdiff
Merge branch 'master' into streamrewrite2
authorsbarman <sbarman@L3CWZ5T.(none)>
Mon, 20 Jun 2011 21:02:54 +0000 (14:02 -0700)
committersbarman <sbarman@L3CWZ5T.(none)>
Mon, 20 Jun 2011 21:02:54 +0000 (14:02 -0700)
Conflicts:
pdf.js

1  2 
pdf.js

diff --cc pdf.js
index b12dc9d0807fea931541407a6b95c9e8e46591a8,7436b9a43c87e1de76a55aa9071a5c7d02c5ecae..4fd3fedce9092de5a36daef6f73f4dc234e3bd71
--- 1/pdf.js
--- 2/pdf.js
+++ b/pdf.js
@@@ -232,12 -233,10 +233,12 @@@ var FlateStream = (function() 
      ]), 5];
  
      function constructor(stream) {
 -        this.stream = stream;
 +        var bytes = stream.getBytes();
-         var bytesIdx = 0;
++        var bytesPos = 0;
 +
          this.dict = stream.dict;
-         var cmf = bytes[bytesIdx++];
-         var flg = bytes[bytesIdx++];
 -        var cmf = stream.getByte();
 -        var flg = stream.getByte();
++        var cmf = bytes[bytesPos++];
++        var flg = bytes[bytesPos++];
          if (cmf == -1 || flg == -1)
              error("Invalid header in flate stream");
          if ((cmf & 0x0f) != 0x08)
              error("Bad FCHECK in flate stream");
          if (flg & 0x20)
              error("FDICT bit set in flate stream");
-         this.bytesIdx = bytesIdx;
 +
 +        this.bytes = bytes;
++        this.bytesPos = bytesPos;
          this.eof = false;
          this.codeSize = 0;
          this.codeBuf = 0;
  
      constructor.prototype = {
          getBits: function(bits) {
 -            var stream = this.stream;
              var codeSize = this.codeSize;
              var codeBuf = this.codeBuf;
-             var bytesIdx = this.bytesIdx;
 +            var bytes = this.bytes;
++            var bytesPos = this.bytesPos;
 +
              var b;
              while (codeSize < bits) {
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad encoding in flate stream");
                  codeBuf |= b << codeSize;
                  codeSize += 8;
              b = codeBuf & ((1 << bits) - 1);
              this.codeBuf = codeBuf >> bits;
              this.codeSize = codeSize -= bits;
-             this.bytesIdx = bytesIdx;
++            this.bytesPos = bytesPos;
              return b;
          },
          getCode: function(table) {
              var maxLen = table[1];
              var codeSize = this.codeSize;
              var codeBuf = this.codeBuf;
 -            var stream = this.stream;
 +            var bytes = this.bytes;
-             var bytesIdx = this.bytesIdx;
++            var bytesPos = this.bytesPos;
 +
              while (codeSize < maxLen) {
                  var b;
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad encoding in flate stream");
                  codeBuf |= (b << codeSize);
                  codeSize += 8;
                  error("Bad encoding in flate stream");
              this.codeBuf = (codeBuf >> codeLen);
              this.codeSize = (codeSize - codeLen);
-             this.bytesIdx = bytesIdx;
++            this.bytesPos = bytesPos;
              return codeVal;
          },
          ensureBuffer: function(requested) {
              return [codes, maxLen];
          },
          readBlock: function() {
 -            var stream = this.stream;
+             function repeat(stream, array, len, offset, what) {
+                 var repeat = stream.getBits(len) + offset;
+                 while (repeat-- > 0)
+                     array[i++] = what;
+             }
-             var bytesIdx = this.bytesIdx;
 +            var bytes = this.bytes;
++            var bytesPos = this.bytesPos;
  
              // read block header
              var hdr = this.getBits(3);
  
              var b;
              if (hdr == 0) { // uncompressed block
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad block header in flate stream");
                  var blockLen = b;
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad block header in flate stream");
                  blockLen |= (b << 8);
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad block header in flate stream");
                  var check = b;
-                 if ((b = bytes[bytesIdx++]) == undefined)
 -                if ((b = stream.getByte()) == -1)
++                if ((b = bytes[bytesPos++]) == undefined)
                      error("Bad block header in flate stream");
                  check |= (b << 8);
                  if (check != (~this.blockLen & 0xffff))
                  var buffer = this.ensureBuffer(bufferLength + blockLen);
                  this.bufferLength = bufferLength + blockLen;
                  for (var n = bufferLength; n < blockLen; ++n) {
-                     if ((b = bytes[bytesIdx++]) == undefined) {
 -                    if ((b = stream.getByte()) == -1) {
++                    if ((b = bytes[bytesPos++]) == undefined) {
                          this.eof = true;
                          break;
                      }