Skip to content

Commit

Permalink
Add a helper function for handling locally cached image data (PR 1826…
Browse files Browse the repository at this point in the history
…9 follow-up)

This avoid having to duplicate the same exact code multiple times.
  • Loading branch information
Snuffleupagus committed Jun 18, 2024
1 parent 4c04158 commit 992e630
Showing 1 changed file with 9 additions and 31 deletions.
40 changes: 9 additions & 31 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ function normalizeBlendMode(value, parsingArray = false) {
return "source-over";
}

function incrementCachedImageMaskCount(data) {
function addLocallyCachedImageOps(opList, data) {
if (data.objId) {
opList.addDependency(data.objId);
}
opList.addImageOps(data.fn, data.args, data.optionalContent);

if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
data.args[0].count++;
}
Expand Down Expand Up @@ -1785,16 +1790,7 @@ class PartialEvaluator {
if (isValidName) {
const localImage = localImageCache.getByName(name);
if (localImage) {
if (localImage.objId) {
operatorList.addDependency(localImage.objId);
}
operatorList.addImageOps(
localImage.fn,
localImage.args,
localImage.optionalContent
);

incrementCachedImageMaskCount(localImage);
addLocallyCachedImageOps(operatorList, localImage);
args = null;
continue;
}
Expand All @@ -1812,16 +1808,7 @@ class PartialEvaluator {
localImageCache.getByRef(xobj) ||
self._regionalImageCache.getByRef(xobj);
if (localImage) {
if (localImage.objId) {
operatorList.addDependency(localImage.objId);
}
operatorList.addImageOps(
localImage.fn,
localImage.args,
localImage.optionalContent
);

incrementCachedImageMaskCount(localImage);
addLocallyCachedImageOps(operatorList, localImage);
resolveXObject();
return;
}
Expand Down Expand Up @@ -1936,16 +1923,7 @@ class PartialEvaluator {
if (cacheKey) {
const localImage = localImageCache.getByName(cacheKey);
if (localImage) {
if (localImage.objId) {
operatorList.addDependency(localImage.objId);
}
operatorList.addImageOps(
localImage.fn,
localImage.args,
localImage.optionalContent
);

incrementCachedImageMaskCount(localImage);
addLocallyCachedImageOps(operatorList, localImage);
args = null;
continue;
}
Expand Down

0 comments on commit 992e630

Please sign in to comment.