Use Stream instead of byte array access
This commit is contained in:
parent
1ccc8a64b7
commit
2982de8f33
@ -52,17 +52,19 @@ var PDFImage = (function PDFImageClosure() {
|
|||||||
function PDFImage(xref, res, image, inline, smask, mask, isMask) {
|
function PDFImage(xref, res, image, inline, smask, mask, isMask) {
|
||||||
this.image = image;
|
this.image = image;
|
||||||
var dict = image.dict;
|
var dict = image.dict;
|
||||||
if (dict.get('Filter').name === 'JPXDecode') {
|
if (dict.has('Filter')) {
|
||||||
info('get image params from JPX stream');
|
var filter = dict.get('Filter').name;
|
||||||
var jpxImage = new JpxImage();
|
if (filter === 'JPXDecode') {
|
||||||
var data = image.stream.bytes;
|
info('get image params from JPX stream');
|
||||||
jpxImage.parseImageProperties(data, 0, data.length);
|
var jpxImage = new JpxImage();
|
||||||
image.bitsPerComponent = jpxImage.bitsPerComponent;
|
jpxImage.parseImageProperties(image.stream);
|
||||||
image.numComps = jpxImage.componentsCount;
|
image.stream.reset();
|
||||||
}
|
image.bitsPerComponent = jpxImage.bitsPerComponent;
|
||||||
if (dict.get('Filter').name === 'JBIG2Decode') {
|
image.numComps = jpxImage.componentsCount;
|
||||||
image.bitsPerComponent = 1;
|
} else if (filter === 'JBIG2Decode') {
|
||||||
image.numComps = 1;
|
image.bitsPerComponent = 1;
|
||||||
|
image.numComps = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// TODO cache rendered images?
|
// TODO cache rendered images?
|
||||||
|
|
||||||
|
@ -98,19 +98,22 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
parseImageProperties: function JpxImage_parseImageProperties(data, start,
|
parseImageProperties: function JpxImage_parseImageProperties(stream) {
|
||||||
end) {
|
|
||||||
try {
|
try {
|
||||||
var position = start;
|
var newByte = stream.getByte();
|
||||||
while (position + 40 < end) {
|
while (newByte >= 0) {
|
||||||
var code = readUint16(data, position);
|
var oldByte = newByte;
|
||||||
|
newByte = stream.getByte();
|
||||||
|
var code = (oldByte << 8) | newByte;
|
||||||
// Image and tile size (SIZ)
|
// Image and tile size (SIZ)
|
||||||
if (code == 0xFF51) {
|
if (code == 0xFF51) {
|
||||||
var Xsiz = readUint32(data, position + 6);
|
stream.skip(4);
|
||||||
var Ysiz = readUint32(data, position + 10);
|
var Xsiz = stream.getUint32(); // Byte 4
|
||||||
var XOsiz = readUint32(data, position + 14);
|
var Ysiz = stream.getUint32(); // Byte 8
|
||||||
var YOsiz = readUint32(data, position + 18);
|
var XOsiz = stream.getUint32(); // Byte 12
|
||||||
var Csiz = readUint16(data, position + 38);
|
var YOsiz = stream.getUint32(); // Byte 16
|
||||||
|
stream.skip(16);
|
||||||
|
var Csiz = stream.getUint16(); // Byte 36
|
||||||
this.width = Xsiz - XOsiz;
|
this.width = Xsiz - XOsiz;
|
||||||
this.height = Ysiz - YOsiz;
|
this.height = Ysiz - YOsiz;
|
||||||
this.componentsCount = Csiz;
|
this.componentsCount = Csiz;
|
||||||
@ -118,7 +121,6 @@ var JpxImage = (function JpxImageClosure() {
|
|||||||
this.bitsPerComponent = 8;
|
this.bitsPerComponent = 8;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
position += 1;
|
|
||||||
}
|
}
|
||||||
throw 'No size marker found in JPX stream';
|
throw 'No size marker found in JPX stream';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user