1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 17:48:07 +02:00

Transfer image masks when when possible, instead of copying.

This commit is contained in:
Nicholas Nethercote 2014-03-06 21:27:32 -08:00
parent cb5bb0cec7
commit 00c1cff405
2 changed files with 23 additions and 15 deletions

View file

@ -209,19 +209,25 @@ var PDFImage = (function PDFImageClosure() {
return temp;
};
PDFImage.createMask = function PDFImage_createMask(imgArray, width, height,
inverseDecode) {
// Copy imgArray into a typed array (inverting if necessary) so it can be
// transferred to the main thread.
PDFImage.createMask =
function PDFImage_createMask(imgArray, width, height, canTransfer,
inverseDecode) {
// If imgArray came from a DecodeStream, we're safe to transfer it.
// Otherwise, copy it.
var actualLength = imgArray.byteLength;
var data = new Uint8Array(actualLength);
var data;
if (canTransfer) {
data = imgArray;
} else {
data = new Uint8Array(actualLength);
data.set(imgArray);
}
// Invert if necessary. It's safe to modify the array -- whether it's the
// original or a copy, we're about to transfer it anyway, so nothing else
// in this thread can be relying on its contents.
if (inverseDecode) {
for (var i = 0; i < actualLength; i++) {
data[i] = ~imgArray[i];
}
} else {
for (var i = 0; i < actualLength; i++) {
data[i] = imgArray[i];
data[i] = ~data[i];
}
}