1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Move the colour conversion to jpg.js

Benchmarking shows that this improves performance for the invitation document
from https://github.com/mozilla/pdf.js/issues/3809 by 35%
This commit is contained in:
Thorben Bochenek 2014-03-27 17:08:32 +01:00
parent e7fe45a5c4
commit e8f0700bfa
7 changed files with 243 additions and 190 deletions

View file

@ -502,7 +502,7 @@ var PDFImage = (function PDFImageClosure() {
// Rows start at byte boundary.
var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
var imgArray = this.getImageBytes(originalHeight * rowBytes);
var imgArray;
if (!forceRGBA) {
// If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
@ -522,6 +522,7 @@ var PDFImage = (function PDFImageClosure() {
drawWidth === originalWidth && drawHeight === originalHeight) {
imgData.kind = kind;
imgArray = this.getImageBytes(originalHeight * rowBytes);
// If imgArray came from a DecodeStream, we're safe to transfer it
// (and thus neuter it) because it will constitute the entire
// DecodeStream's data. But if it came from a Stream, we need to
@ -537,6 +538,14 @@ var PDFImage = (function PDFImageClosure() {
return imgData;
}
}
if (this.image instanceof JpegStream) {
imgData.kind = ImageKind.RGB_24BPP;
imgData.data = this.getImageBytes(originalHeight * rowBytes,
drawWidth, drawHeight);
return imgData;
}
imgArray = this.getImageBytes(originalHeight * rowBytes);
// imgArray can be incomplete (e.g. after CCITT fax encoding).
var actualHeight = 0 | (imgArray.length / rowBytes *
drawHeight / originalHeight);
@ -597,7 +606,7 @@ var PDFImage = (function PDFImageClosure() {
length = width * height;
if (this.needsDecode) {
// invert and scale to {0, 255}
for (var i = 0; i < length; ++i) {
for (i = 0; i < length; ++i) {
buffer[i] = (comps[i] - 1) & 255;
}
} else {
@ -620,8 +629,11 @@ var PDFImage = (function PDFImageClosure() {
}
},
getImageBytes: function PDFImage_getImageBytes(length) {
getImageBytes: function PDFImage_getImageBytes(length,
drawWidth, drawHeight) {
this.image.reset();
this.image.drawWidth = drawWidth;
this.image.drawHeight = drawHeight;
return this.image.getBytes(length);
}
};

1039
src/core/jpg.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -873,9 +873,8 @@ var JpegStream = (function JpegStreamClosure() {
jpegImage.colorTransform = this.colorTransform;
}
jpegImage.parse(this.bytes);
var width = jpegImage.width;
var height = jpegImage.height;
var data = jpegImage.getData(width, height);
var data = jpegImage.getData(this.drawWidth, this.drawHeight,
/* forceRGBoutput = */true);
this.buffer = data;
this.bufferLength = data.length;
this.eof = true;
@ -883,6 +882,12 @@ var JpegStream = (function JpegStreamClosure() {
error('JPEG error: ' + e);
}
};
JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
this.ensureBuffer();
return this.buffer;
};
JpegStream.prototype.getIR = function JpegStream_getIR() {
return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
};

View file

@ -49,11 +49,11 @@ var otherFiles = [
'core/stream.js',
'core/worker.js',
'core/arithmetic_decoder.js',
'core/jpg.js',
'core/jpx.js',
'core/jbig2.js',
'core/bidi.js',
'core/murmurhash3.js',
'../external/jpgjs/jpg.js'
'core/murmurhash3.js'
];
function loadInOrder(index, path, files) {