]> git.parisson.com Git - pdf.js.git/commitdiff
Just use imageData directly on Gecko
authorJulian Viereck <julian.viereck@gmail.com>
Wed, 14 Sep 2011 17:08:10 +0000 (10:08 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 20:17:09 +0000 (13:17 -0700)
pdf.js
worker.js

diff --git a/pdf.js b/pdf.js
index 23dd910aaac48102ae1615a7688b963e4e76589c..141d1087638af8c12fed996889f411b2db08b843 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -6,6 +6,11 @@
 var ERRORS = 0, WARNINGS = 1, TODOS = 5;
 var verbosity = WARNINGS;
 
+var isGecko = false;
+if (typeof navigator !== 'undefined') {
+  isGecko = navigator.userAgent.indexOf("Gecko/") !== -1;
+}
+
 function log(msg) {
   if (console && console.log)
     console.log(msg);
@@ -5469,19 +5474,26 @@ var CanvasGraphics = (function() {
       // scale the image to the unit square
       ctx.scale(1 / w, -1 / h);
 
-
       var tmpCanvas = new this.ScratchCanvas(w, h);
       var tmpCtx = tmpCanvas.getContext('2d');
-      var tmpImgData = tmpCtx.getImageData(0, 0, w, h);
+      var tmpImgData;
+      
+      // Gecko doesn't care too much of the shape of imgData, but other browser
+      // do.
+      if (isGecko) {
+        tmpImgData = imgData;
+      } else {
+        tmpImgData = tmpCtx.getImageData(0, 0, w, h);
 
-      // Copy over the imageData.
-      var tmpImgDataPixels = tmpImgData.data;
-      var len = tmpImgDataPixels.length;
+        // Copy over the imageData.
+        var tmpImgDataPixels = tmpImgData.data;
+        var len = tmpImgDataPixels.length;
 
-      // TODO: There got to be a better way to copy an ImageData array
-      // then coping over all the bytes one by one :/
-      while (len--) 
-        tmpImgDataPixels[len] = imgData.data[len];
+        // TODO: There got to be a better way to copy an ImageData array
+        // then coping over all the bytes one by one :/
+        while (len--) 
+          tmpImgDataPixels[len] = imgData.data[len];
+      }
 
       tmpCtx.putImageData(tmpImgData, 0, 0);
       ctx.drawImage(tmpCanvas, 0, -h);
index a1bbf85a621de0db5347ded9da7ffac7ef07ab5c..b463261602cfad01f09ed398addec8101dbd4021 100644 (file)
--- a/worker.js
+++ b/worker.js
@@ -85,7 +85,7 @@ var Objects = {
   get: function(objId) {
     var obj = Objects[objId];
     if (!obj || !obj.isResolved) {
-      throw "Requesting object that isn't resolved yet";
+      throw "Requesting object that isn't resolved yet " + objId;
     }
     return obj.data;
   }
@@ -162,7 +162,7 @@ var WorkerPDFDoc = (function() {
     
     this.pageCache = [];
     
-    var useWorker = false;
+    var useWorker = true;
     
     if (useWorker) {
       var worker = new Worker("../worker/boot_processor.js");