Compute the length of the final image-bitmap/data on the worker-thread
Currently this is done in the API, but moving it into the worker-thread will simplify upcoming changes.
This commit is contained in:
parent
b09f238436
commit
e547b198a3
@ -546,6 +546,12 @@ class PartialEvaluator {
|
||||
}
|
||||
|
||||
_sendImgData(objId, imgData, cacheGlobally = false) {
|
||||
if (
|
||||
(typeof PDFJSDev === "undefined" || PDFJSDev.test("TESTING")) &&
|
||||
imgData
|
||||
) {
|
||||
assert(Number.isInteger(imgData.dataLen), "Expected dataLen to be set.");
|
||||
}
|
||||
const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
|
||||
|
||||
if (this.parsingType3Font || cacheGlobally) {
|
||||
@ -690,6 +696,10 @@ class PartialEvaluator {
|
||||
|
||||
const objId = `mask_${this.idFactory.createObjId()}`;
|
||||
operatorList.addDependency(objId);
|
||||
|
||||
imgData.dataLen = imgData.bitmap
|
||||
? imgData.width * imgData.height * 4
|
||||
: imgData.data.length;
|
||||
this._sendImgData(objId, imgData);
|
||||
|
||||
args = [
|
||||
@ -790,12 +800,12 @@ class PartialEvaluator {
|
||||
/* isOffscreenCanvasSupported = */ this.options
|
||||
.isOffscreenCanvasSupported
|
||||
);
|
||||
imgData.dataLen = imgData.bitmap
|
||||
? imgData.width * imgData.height * 4
|
||||
: imgData.data.length;
|
||||
|
||||
if (cacheKey && imageRef && cacheGlobally) {
|
||||
const length = imgData.bitmap
|
||||
? imgData.width * imgData.height * 4
|
||||
: imgData.data.length;
|
||||
this.globalImageCache.addByteSize(imageRef, length);
|
||||
this.globalImageCache.addByteSize(imageRef, imgData.dataLen);
|
||||
}
|
||||
|
||||
return this._sendImgData(objId, imgData, cacheGlobally);
|
||||
|
@ -2781,18 +2781,8 @@ class WorkerTransport {
|
||||
pageProxy.objs.resolve(id, imageData);
|
||||
|
||||
// Heuristic that will allow us not to store large data.
|
||||
if (imageData) {
|
||||
let length;
|
||||
if (imageData.bitmap) {
|
||||
const { width, height } = imageData;
|
||||
length = width * height * 4;
|
||||
} else {
|
||||
length = imageData.data?.length || 0;
|
||||
}
|
||||
|
||||
if (length > MAX_IMAGE_SIZE_TO_CACHE) {
|
||||
pageProxy._maybeCleanupAfterRender = true;
|
||||
}
|
||||
if (imageData?.dataLen > MAX_IMAGE_SIZE_TO_CACHE) {
|
||||
pageProxy._maybeCleanupAfterRender = true;
|
||||
}
|
||||
break;
|
||||
case "Pattern":
|
||||
|
Loading…
x
Reference in New Issue
Block a user