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) {
|
_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;
|
const transfers = imgData ? [imgData.bitmap || imgData.data.buffer] : null;
|
||||||
|
|
||||||
if (this.parsingType3Font || cacheGlobally) {
|
if (this.parsingType3Font || cacheGlobally) {
|
||||||
@ -690,6 +696,10 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
const objId = `mask_${this.idFactory.createObjId()}`;
|
const objId = `mask_${this.idFactory.createObjId()}`;
|
||||||
operatorList.addDependency(objId);
|
operatorList.addDependency(objId);
|
||||||
|
|
||||||
|
imgData.dataLen = imgData.bitmap
|
||||||
|
? imgData.width * imgData.height * 4
|
||||||
|
: imgData.data.length;
|
||||||
this._sendImgData(objId, imgData);
|
this._sendImgData(objId, imgData);
|
||||||
|
|
||||||
args = [
|
args = [
|
||||||
@ -790,12 +800,12 @@ class PartialEvaluator {
|
|||||||
/* isOffscreenCanvasSupported = */ this.options
|
/* isOffscreenCanvasSupported = */ this.options
|
||||||
.isOffscreenCanvasSupported
|
.isOffscreenCanvasSupported
|
||||||
);
|
);
|
||||||
|
imgData.dataLen = imgData.bitmap
|
||||||
|
? imgData.width * imgData.height * 4
|
||||||
|
: imgData.data.length;
|
||||||
|
|
||||||
if (cacheKey && imageRef && cacheGlobally) {
|
if (cacheKey && imageRef && cacheGlobally) {
|
||||||
const length = imgData.bitmap
|
this.globalImageCache.addByteSize(imageRef, imgData.dataLen);
|
||||||
? imgData.width * imgData.height * 4
|
|
||||||
: imgData.data.length;
|
|
||||||
this.globalImageCache.addByteSize(imageRef, length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._sendImgData(objId, imgData, cacheGlobally);
|
return this._sendImgData(objId, imgData, cacheGlobally);
|
||||||
|
@ -2781,18 +2781,8 @@ class WorkerTransport {
|
|||||||
pageProxy.objs.resolve(id, imageData);
|
pageProxy.objs.resolve(id, imageData);
|
||||||
|
|
||||||
// Heuristic that will allow us not to store large data.
|
// Heuristic that will allow us not to store large data.
|
||||||
if (imageData) {
|
if (imageData?.dataLen > MAX_IMAGE_SIZE_TO_CACHE) {
|
||||||
let length;
|
pageProxy._maybeCleanupAfterRender = true;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "Pattern":
|
case "Pattern":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user