[Pkg-javascript-commits] [pdf.js] 83/210: Optimized JPX's transformComponents

David Prévot taffit at moszumanska.debian.org
Thu Jun 5 14:21:04 UTC 2014


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

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

commit 7067409e00cace2d40712714882b0f2981821b1b
Author: p01 <p01 at opera.com>
Date:   Mon Apr 28 17:24:22 2014 +0200

    Optimized JPX's transformComponents
---
 src/core/jpx.js | 45 ++++++++++++++++++++++-----------------------
 1 file changed, 22 insertions(+), 23 deletions(-)

diff --git a/src/core/jpx.js b/src/core/jpx.js
index 8c2efdd..114c93a 100644
--- a/src/core/jpx.js
+++ b/src/core/jpx.js
@@ -1076,7 +1076,7 @@ var JpxImage = (function JpxImageClosure() {
       };
 
       // Section G.2.2 Inverse multi component transform
-      var shift, offset, max, min;
+      var shift, offset, max, min, maxK;
       var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
       if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
         var fourComponents = componentsCount === 4;
@@ -1090,45 +1090,44 @@ var JpxImage = (function JpxImageClosure() {
         // compute shift and offset only once.
         shift = components[0].precision - 8;
         offset = (128 << shift) + 0.5;
-        max = (127.5 * (1 << shift));
-        min = -max;
+        max = 255 * (1 << shift);
+        maxK = max * 0.5;
+        min = -maxK;
 
         var component0 = tile.components[0];
+        var alpha01 = componentsCount - 3;
+        jj = y0items.length;
         if (!component0.codingStyleParameters.reversibleTransformation) {
           // inverse irreversible multiple component transform
-          for (j = 0, jj = y0items.length; j < jj; ++j) {
-            y0 = y0items[j];
+          for (j = 0; j < jj; j++, pos += alpha01) {
+            y0 = y0items[j] + offset;
             y1 = y1items[j];
             y2 = y2items[j];
             r = y0 + 1.402 * y2;
             g = y0 - 0.34413 * y1 - 0.71414 * y2;
             b = y0 + 1.772 * y1;
-            out[pos++] = r <= min ? 0 : r >= max ? 255 : (r + offset) >> shift;
-            out[pos++] = g <= min ? 0 : g >= max ? 255 : (g + offset) >> shift;
-            out[pos++] = b <= min ? 0 : b >= max ? 255 : (b + offset) >> shift;
-            if (fourComponents) {
-              k = y3items[j];
-              out[pos++] =
-                k <= min ? 0 : k >= max ? 255 : (k + offset) >> shift;
-            }
+            out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
+            out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
+            out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
           }
         } else {
           // inverse reversible multiple component transform
-          for (j = 0, jj = y0items.length; j < jj; ++j) {
-            y0 = y0items[j];
+          for (j = 0; j < jj; j++, pos += alpha01) {
+            y0 = y0items[j] + offset;
             y1 = y1items[j];
             y2 = y2items[j];
             g = y0 - ((y2 + y1) >> 2);
             r = g + y2;
             b = g + y1;
-            out[pos++] = r <= min ? 0 : r >= max ? 255 : (r + offset) >> shift;
-            out[pos++] = g <= min ? 0 : g >= max ? 255 : (g + offset) >> shift;
-            out[pos++] = b <= min ? 0 : b >= max ? 255 : (b + offset) >> shift;
-            if (fourComponents) {
-              k = y3items[j];
-              out[pos++] =
-                k <= min ? 0 : k >= max ? 255 : (k + offset) >> shift;
-            }
+            out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
+            out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
+            out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
+          }
+        }
+        if (fourComponents) {
+          for (j = 0, pos = 3; j < jj; j++, pos += 4) {
+            k = y3items[j];
+            out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
           }
         }
       } else { // no multi-component transform

-- 
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