Use, and re-name, the addLocallyCachedImageOps helper for global images too

This avoids having to "manually" set the image operators for globally cached images.
This commit is contained in:
Jonas Jenwald 2025-03-31 10:49:47 +02:00
parent e0e59eaf01
commit 213830f44f

View File

@ -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++;
} }
} }
@ -1769,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;
} }
@ -1783,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;
} }
@ -1897,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;
} }