[Pkg-javascript-commits] [pdf.js] 26/141: Prescales shading pattern packed data indices

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 22:40:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 1e8d70af9819d9b285e15fea8d50456c8275137e
Author: Yury Delendik <ydelendik at mozilla.com>
Date:   Thu Feb 13 08:20:00 2014 -0600

    Prescales shading pattern packed data indices
---
 src/core/pattern.js           | 61 +++++++++++++++++++++++++------------------
 src/display/pattern_helper.js | 25 +++++++++---------
 2 files changed, 48 insertions(+), 38 deletions(-)

diff --git a/src/core/pattern.js b/src/core/pattern.js
index 137eaef..a59c766 100644
--- a/src/core/pattern.js
+++ b/src/core/pattern.js
@@ -670,6 +670,38 @@ Shadings.Mesh = (function MeshClosure() {
     mesh.bounds = [minX, minY, maxX, maxY];
   }
 
+  function packData(mesh) {
+    var i, ii, j, jj;
+
+    var coords = mesh.coords;
+    var coordsPacked = new Float32Array(coords.length * 2);
+    for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
+      var xy = coords[i];
+      coordsPacked[j++] = xy[0];
+      coordsPacked[j++] = xy[1];
+    }
+    mesh.coords = coordsPacked;
+
+    var colors = mesh.colors;
+    var colorsPacked = new Uint8Array(colors.length * 3);
+    for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
+      var c = colors[i];
+      colorsPacked[j++] = c[0];
+      colorsPacked[j++] = c[1];
+      colorsPacked[j++] = c[2];
+    }
+    mesh.colors = colorsPacked;
+
+    var figures = mesh.figures;
+    for (i = 0, ii = figures.length; i < ii; i++) {
+      var figure = figures[i], ps = figure.coords, cs = figure.colors;
+      for (j = 0, jj = ps.length; j < jj; j++) {
+        ps[j] *= 2;
+        cs[j] *= 3;
+      }
+    }
+  }
+
   function Mesh(stream, matrix, xref, res) {
     assert(isStream(stream), 'Mesh data is not a stream');
     var dict = stream.dict;
@@ -757,35 +789,14 @@ Shadings.Mesh = (function MeshClosure() {
     }
     // calculate bounds
     updateBounds(this);
+
+    packData(this);
   }
 
   Mesh.prototype = {
     getIR: function Mesh_getIR() {
-      var type = this.shadingType;
-      var i, ii, j;
-      var coords = this.coords;
-      var coordsPacked = new Float32Array(coords.length * 2);
-      for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
-        var xy = coords[i];
-        coordsPacked[j++] = xy[0];
-        coordsPacked[j++] = xy[1];
-      }
-      var colors = this.colors;
-      var colorsPacked = new Uint8Array(colors.length * 3);
-      for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
-        var c = colors[i];
-        colorsPacked[j++] = c[0];
-        colorsPacked[j++] = c[1];
-        colorsPacked[j++] = c[2];
-      }
-      var figures = this.figures;
-      var bbox = this.bbox;
-      var bounds = this.bounds;
-      var matrix = this.matrix;
-      var background = this.background;
-
-      return ['Mesh', type, coordsPacked, colorsPacked, figures, bounds,
-        matrix, bbox, background];
+      return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
+        this.bounds, this.matrix, this.bbox, this.background];
     }
   };
 
diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js
index bf07808..3e9038a 100644
--- a/src/display/pattern_helper.js
+++ b/src/display/pattern_helper.js
@@ -55,28 +55,27 @@ var createMeshCanvas = (function createMeshCanvasClosure() {
     var coords = context.coords, colors = context.colors;
     var bytes = data.data, rowSize = data.width * 4;
     var tmp;
-    if (coords[p1 * 2 + 1] > coords[p2 * 2 + 1]) {
+    if (coords[p1 + 1] > coords[p2 + 1]) {
       tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
     }
-    if (coords[p2 * 2 + 1] > coords[p3 * 2 + 1]) {
+    if (coords[p2 + 1] > coords[p3 + 1]) {
       tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
     }
-    if (coords[p1 * 2 + 1] > coords[p2 * 2 + 1]) {
+    if (coords[p1 + 1] > coords[p2 + 1]) {
       tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
     }
-    var x1 = (coords[p1 * 2] + context.offsetX) * context.scaleX;
-    var y1 = (coords[p1 * 2 + 1] + context.offsetY) * context.scaleY;
-    var x2 = (coords[p2 * 2] + context.offsetX) * context.scaleX;
-    var y2 = (coords[p2 * 2 + 1] + context.offsetY) * context.scaleY;
-    var x3 = (coords[p3 * 2] + context.offsetX) * context.scaleX;
-    var y3 = (coords[p3 * 2 + 1] + context.offsetY) * context.scaleY;
+    var x1 = (coords[p1] + context.offsetX) * context.scaleX;
+    var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
+    var x2 = (coords[p2] + context.offsetX) * context.scaleX;
+    var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
+    var x3 = (coords[p3] + context.offsetX) * context.scaleX;
+    var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
     if (y1 >= y3) {
       return;
     }
-    var c1i = c1 * 3, c2i = c2 * 3, c3i = c3 * 3;
-    var c1r = colors[c1i], c1g = colors[c1i + 1], c1b = colors[c1i + 2];
-    var c2r = colors[c2i], c2g = colors[c2i + 1], c2b = colors[c2i + 2];
-    var c3r = colors[c3i], c3g = colors[c3i + 1], c3b = colors[c3i + 2];
+    var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
+    var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
+    var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
 
     var minY = Math.round(y1), maxY = Math.round(y3);
     var xa, car, cag, cab;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list