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

Merge pull request #4406 from nnethercote/fix-and-transfer-masks

Improve image mask handling again
This commit is contained in:
Brendan Dahl 2014-03-10 16:26:22 -07:00
commit 57e896d29e
2 changed files with 25 additions and 17 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.
var length = ((width + 7) >> 3) * height;
var data = new Uint8Array(length);
if (inverseDecode) {
for (var i = 0; i < length; i++) {
data[i] = ~imgArray[i];
}
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;
if (canTransfer) {
data = imgArray;
} else {
for (var i = 0; i < length; i++) {
data[i] = imgArray[i];
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] = ~data[i];
}
}