[Pkg-javascript-commits] [pdf.js] 16/207: Adds color components decoding to the JPEG
David Prévot
taffit at moszumanska.debian.org
Mon Jul 28 15:36:24 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 6235e3a61cd3fd91cda5b9fecf3ac2581a82bc86
Author: Yury Delendik <ydelendik at mozilla.com>
Date: Tue Jun 3 08:51:57 2014 -0500
Adds color components decoding to the JPEG
---
src/core/jpg.js | 15 ++++++++++++---
src/core/stream.js | 22 ++++++++++++++++++++--
2 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/core/jpg.js b/src/core/jpg.js
index cb61a23..1b043a0 100644
--- a/src/core/jpg.js
+++ b/src/core/jpg.js
@@ -811,7 +811,7 @@ var JpegImage = (function jpegImage() {
var scaleX = this.width / width, scaleY = this.height / height;
var component, componentScaleX, componentScaleY, blocksPerScanline;
- var x, y, i, j;
+ var x, y, i, j, k;
var index;
var offset = 0;
var output;
@@ -843,6 +843,17 @@ var JpegImage = (function jpegImage() {
}
}
}
+
+ // decodeTransform will contains pairs of multiplier (-256..256) and
+ // additive
+ var transform = this.decodeTransform;
+ if (transform) {
+ for (i = 0; i < dataLength;) {
+ for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
+ data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
+ }
+ }
+ }
return data;
},
@@ -852,8 +863,6 @@ var JpegImage = (function jpegImage() {
return true;
} else if (this.numComponents == 3) {
return true;
- } else if (typeof this.colorTransform !== 'undefined') {
- return !!this.colorTransform;
} else {
return false;
}
diff --git a/src/core/stream.js b/src/core/stream.js
index f2996a6..669cab1 100644
--- a/src/core/stream.js
+++ b/src/core/stream.js
@@ -878,9 +878,27 @@ var JpegStream = (function JpegStreamClosure() {
}
try {
var jpegImage = new JpegImage();
- if (this.colorTransform != -1) {
- jpegImage.colorTransform = this.colorTransform;
+
+ // checking if values needs to be transformed before conversion
+ if (this.dict && isArray(this.dict.get('Decode'))) {
+ var decodeArr = this.dict.get('Decode');
+ var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
+ var decodeArrLength = decodeArr.length;
+ var transform = new Int32Array(decodeArrLength);
+ var transformNeeded = false;
+ var maxValue = (1 << bitsPerComponent) - 1;
+ for (var i = 0; i < decodeArrLength; i += 2) {
+ transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
+ transform[i + 1] = (decodeArr[i] * maxValue) | 0;
+ if (transform[i] !== 256 || transform[i + 1] !== 0) {
+ transformNeeded = true;
+ }
+ }
+ if (transformNeeded) {
+ jpegImage.decodeTransform = transform;
+ }
}
+
jpegImage.parse(this.bytes);
var data = jpegImage.getData(this.drawWidth, this.drawHeight,
/* forceRGBoutput = */true);
--
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