From 604e8977e9432dbae55ba375c01ed0bed7c25932 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Tue, 18 Jun 2024 17:01:30 +0200 Subject: [PATCH] Add a helper function for handling locally cached image data (PR 18269 follow-up) This avoids having to duplicate the same exact code multiple times. --- src/core/evaluator.js | 40 +++++++++------------------------------- 1 file changed, 9 insertions(+), 31 deletions(-) diff --git a/src/core/evaluator.js b/src/core/evaluator.js index c7dc72f4edd65..41595b4a36b0f 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -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++; } @@ -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; } @@ -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; } @@ -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; }