Use Stream instead of byte array access

This commit is contained in:
fkaelberer 2014-04-06 12:08:04 +02:00
parent 1ccc8a64b7
commit 2982de8f33
2 changed files with 26 additions and 22 deletions

View File

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

View File

@ -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) {