mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +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:
parent
e7fe45a5c4
commit
e8f0700bfa
7 changed files with 243 additions and 190 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue