[Pkg-javascript-commits] [pdf.js] 39/141: Use Stream instead of byte array access
David Prévot
taffit at moszumanska.debian.org
Sat Apr 19 22:40:28 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 2982de8f33f1b785ff82c3dc46d12968286f3703
Author: fkaelberer <o_0_o at gmx.de>
Date: Sun Apr 6 12:08:04 2014 +0200
Use Stream instead of byte array access
---
src/core/image.js | 24 +++++++++++++-----------
src/core/jpx.js | 24 +++++++++++++-----------
2 files changed, 26 insertions(+), 22 deletions(-)
diff --git a/src/core/image.js b/src/core/image.js
index 17ea6b6..edc8443 100644
--- a/src/core/image.js
+++ b/src/core/image.js
@@ -52,17 +52,19 @@ var PDFImage = (function PDFImageClosure() {
function PDFImage(xref, res, image, inline, smask, mask, isMask) {
this.image = image;
var dict = image.dict;
- if (dict.get('Filter').name === 'JPXDecode') {
- info('get image params from JPX stream');
- var jpxImage = new JpxImage();
- var data = image.stream.bytes;
- jpxImage.parseImageProperties(data, 0, data.length);
- image.bitsPerComponent = jpxImage.bitsPerComponent;
- image.numComps = jpxImage.componentsCount;
- }
- if (dict.get('Filter').name === 'JBIG2Decode') {
- image.bitsPerComponent = 1;
- image.numComps = 1;
+ if (dict.has('Filter')) {
+ var filter = dict.get('Filter').name;
+ if (filter === 'JPXDecode') {
+ info('get image params from JPX stream');
+ var jpxImage = new JpxImage();
+ jpxImage.parseImageProperties(image.stream);
+ image.stream.reset();
+ image.bitsPerComponent = jpxImage.bitsPerComponent;
+ image.numComps = jpxImage.componentsCount;
+ } else if (filter === 'JBIG2Decode') {
+ image.bitsPerComponent = 1;
+ image.numComps = 1;
+ }
}
// TODO cache rendered images?
diff --git a/src/core/jpx.js b/src/core/jpx.js
index de8cc90..8f484f1 100644
--- a/src/core/jpx.js
+++ b/src/core/jpx.js
@@ -98,19 +98,22 @@ var JpxImage = (function JpxImageClosure() {
}
}
},
- parseImageProperties: function JpxImage_parseImageProperties(data, start,
- end) {
+ parseImageProperties: function JpxImage_parseImageProperties(stream) {
try {
- var position = start;
- while (position + 40 < end) {
- var code = readUint16(data, position);
+ var newByte = stream.getByte();
+ while (newByte >= 0) {
+ var oldByte = newByte;
+ newByte = stream.getByte();
+ var code = (oldByte << 8) | newByte;
// Image and tile size (SIZ)
if (code == 0xFF51) {
- var Xsiz = readUint32(data, position + 6);
- var Ysiz = readUint32(data, position + 10);
- var XOsiz = readUint32(data, position + 14);
- var YOsiz = readUint32(data, position + 18);
- var Csiz = readUint16(data, position + 38);
+ stream.skip(4);
+ var Xsiz = stream.getUint32(); // Byte 4
+ var Ysiz = stream.getUint32(); // Byte 8
+ var XOsiz = stream.getUint32(); // Byte 12
+ var YOsiz = stream.getUint32(); // Byte 16
+ stream.skip(16);
+ var Csiz = stream.getUint16(); // Byte 36
this.width = Xsiz - XOsiz;
this.height = Ysiz - YOsiz;
this.componentsCount = Csiz;
@@ -118,7 +121,6 @@ var JpxImage = (function JpxImageClosure() {
this.bitsPerComponent = 8;
return;
}
- position += 1;
}
throw 'No size marker found in JPX stream';
} catch (e) {
--
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