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

Use a more compact typed array to pass the image mask from the worker to the main thread.

This commit is contained in:
Nicholas Nethercote 2014-01-13 20:08:39 -06:00 committed by Yury Delendik
parent dabafb8444
commit 3f533a1cb0
3 changed files with 44 additions and 22 deletions

View file

@ -209,26 +209,21 @@ var PDFImage = (function PDFImageClosure() {
PDFImage.createMask = function PDFImage_createMask(imgArray, width, height,
inverseDecode) {
var buffer = new Uint8Array(width * height * 4);
var imgArrayPos = 0;
var i, j, mask, buf;
// removing making non-masked pixels transparent
var bufferPos = 3; // alpha component offset
for (i = 0; i < height; i++) {
mask = 0;
for (j = 0; j < width; j++) {
if (!mask) {
buf = imgArray[imgArrayPos++];
mask = 128;
}
if (!(buf & mask) !== inverseDecode) {
buffer[bufferPos] = 255;
}
bufferPos += 4;
mask >>= 1;
// 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];
}
} else {
for (var i = 0; i < length; i++) {
data[i] = imgArray[i];
}
}
return {data: buffer, width: width, height: height};
return {data: data, width: width, height: height};
};
PDFImage.prototype = {