Merge pull request #19746 from Snuffleupagus/evaluator-img-cache-tweaks
Reduce some code duplication when handling globally cached images
This commit is contained in:
commit
b33522a208
@ -180,14 +180,17 @@ function normalizeBlendMode(value, parsingArray = false) {
|
|||||||
return "source-over";
|
return "source-over";
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLocallyCachedImageOps(opList, data) {
|
function addCachedImageOps(
|
||||||
if (data.objId) {
|
opList,
|
||||||
opList.addDependency(data.objId);
|
{ objId, fn, args, optionalContent, hasMask }
|
||||||
|
) {
|
||||||
|
if (objId) {
|
||||||
|
opList.addDependency(objId);
|
||||||
}
|
}
|
||||||
opList.addImageOps(data.fn, data.args, data.optionalContent, data.hasMask);
|
opList.addImageOps(fn, args, optionalContent, hasMask);
|
||||||
|
|
||||||
if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
|
if (fn === OPS.paintImageMaskXObject && args[0]?.count > 0) {
|
||||||
data.args[0].count++;
|
args[0].count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -742,7 +745,8 @@ class PartialEvaluator {
|
|||||||
// If there is no imageMask, create the PDFImage and a lot
|
// If there is no imageMask, create the PDFImage and a lot
|
||||||
// of image processing can be done here.
|
// of image processing can be done here.
|
||||||
let objId = `img_${this.idFactory.createObjId()}`,
|
let objId = `img_${this.idFactory.createObjId()}`,
|
||||||
cacheGlobally = false;
|
cacheGlobally = false,
|
||||||
|
globalCacheData = null;
|
||||||
|
|
||||||
if (this.parsingType3Font) {
|
if (this.parsingType3Font) {
|
||||||
objId = `${this.idFactory.getDocId()}_type3_${objId}`;
|
objId = `${this.idFactory.getDocId()}_type3_${objId}`;
|
||||||
@ -767,15 +771,17 @@ class PartialEvaluator {
|
|||||||
operatorList.addImageOps(fn, args, optionalContent, hasMask);
|
operatorList.addImageOps(fn, args, optionalContent, hasMask);
|
||||||
|
|
||||||
if (cacheGlobally) {
|
if (cacheGlobally) {
|
||||||
|
globalCacheData = {
|
||||||
|
objId,
|
||||||
|
fn,
|
||||||
|
args,
|
||||||
|
optionalContent,
|
||||||
|
hasMask,
|
||||||
|
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
|
||||||
|
};
|
||||||
|
|
||||||
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
|
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
|
||||||
this.globalImageCache.setData(imageRef, {
|
this.globalImageCache.setData(imageRef, globalCacheData);
|
||||||
objId,
|
|
||||||
fn,
|
|
||||||
args,
|
|
||||||
optionalContent,
|
|
||||||
hasMask,
|
|
||||||
byteSize: 0, // Data is `null`, since decoding failed previously.
|
|
||||||
});
|
|
||||||
|
|
||||||
this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
|
this._sendImgData(objId, /* imgData = */ null, cacheGlobally);
|
||||||
return;
|
return;
|
||||||
@ -792,14 +798,7 @@ class PartialEvaluator {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
if (localLength) {
|
if (localLength) {
|
||||||
this.globalImageCache.setData(imageRef, {
|
this.globalImageCache.setData(imageRef, globalCacheData);
|
||||||
objId,
|
|
||||||
fn,
|
|
||||||
args,
|
|
||||||
optionalContent,
|
|
||||||
hasMask,
|
|
||||||
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
|
|
||||||
});
|
|
||||||
this.globalImageCache.addByteSize(imageRef, localLength);
|
this.globalImageCache.addByteSize(imageRef, localLength);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -848,14 +847,8 @@ class PartialEvaluator {
|
|||||||
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
||||||
|
|
||||||
if (cacheGlobally) {
|
if (cacheGlobally) {
|
||||||
this.globalImageCache.setData(imageRef, {
|
assert(globalCacheData, "The global cache-data must be available.");
|
||||||
objId,
|
this.globalImageCache.setData(imageRef, globalCacheData);
|
||||||
fn,
|
|
||||||
args,
|
|
||||||
optionalContent,
|
|
||||||
hasMask,
|
|
||||||
byteSize: 0, // Temporary entry, note `addByteSize` above.
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1779,7 +1772,7 @@ class PartialEvaluator {
|
|||||||
if (isValidName) {
|
if (isValidName) {
|
||||||
const localImage = localImageCache.getByName(name);
|
const localImage = localImageCache.getByName(name);
|
||||||
if (localImage) {
|
if (localImage) {
|
||||||
addLocallyCachedImageOps(operatorList, localImage);
|
addCachedImageOps(operatorList, localImage);
|
||||||
args = null;
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1793,28 +1786,12 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
let xobj = xobjs.getRaw(name);
|
let xobj = xobjs.getRaw(name);
|
||||||
if (xobj instanceof Ref) {
|
if (xobj instanceof Ref) {
|
||||||
const localImage =
|
const cachedImage =
|
||||||
localImageCache.getByRef(xobj) ||
|
localImageCache.getByRef(xobj) ||
|
||||||
self._regionalImageCache.getByRef(xobj);
|
self._regionalImageCache.getByRef(xobj) ||
|
||||||
if (localImage) {
|
self.globalImageCache.getData(xobj, self.pageIndex);
|
||||||
addLocallyCachedImageOps(operatorList, localImage);
|
if (cachedImage) {
|
||||||
resolveXObject();
|
addCachedImageOps(operatorList, cachedImage);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const globalImage = self.globalImageCache.getData(
|
|
||||||
xobj,
|
|
||||||
self.pageIndex
|
|
||||||
);
|
|
||||||
if (globalImage) {
|
|
||||||
operatorList.addDependency(globalImage.objId);
|
|
||||||
operatorList.addImageOps(
|
|
||||||
globalImage.fn,
|
|
||||||
globalImage.args,
|
|
||||||
globalImage.optionalContent,
|
|
||||||
globalImage.hasMask
|
|
||||||
);
|
|
||||||
|
|
||||||
resolveXObject();
|
resolveXObject();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1907,7 +1884,7 @@ class PartialEvaluator {
|
|||||||
if (cacheKey) {
|
if (cacheKey) {
|
||||||
const localImage = localImageCache.getByName(cacheKey);
|
const localImage = localImageCache.getByName(cacheKey);
|
||||||
if (localImage) {
|
if (localImage) {
|
||||||
addLocallyCachedImageOps(operatorList, localImage);
|
addCachedImageOps(operatorList, localImage);
|
||||||
args = null;
|
args = null;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user