mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Improve performances with image masks (bug 857031)
- it's the second part of the fix for https://bugzilla.mozilla.org/show_bug.cgi?id=857031; - some image masks can be used several times but at different positions; - an image need to be pre-process before to be rendered: * rescale it; * use the fill color/pattern. - the two operations above are time consuming so we can cache the generated canvas; - the cache key is based on the current transform matrix (without the translation part) and the current fill color when it isn't a pattern. - the rendering of the pdf in the above bug is really faster than without this patch.
This commit is contained in:
parent
b73a6cc213
commit
f62d961dfe
5 changed files with 151 additions and 29 deletions
|
@ -675,6 +675,7 @@ class PartialEvaluator {
|
|||
width: imgData.width,
|
||||
height: imgData.height,
|
||||
interpolate: imgData.interpolate,
|
||||
count: 1,
|
||||
},
|
||||
];
|
||||
|
||||
|
@ -1676,6 +1677,13 @@ class PartialEvaluator {
|
|||
const localImage = localImageCache.getByName(name);
|
||||
if (localImage) {
|
||||
operatorList.addOp(localImage.fn, localImage.args);
|
||||
if (
|
||||
localImage.fn === OPS.paintImageMaskXObject &&
|
||||
localImage.args[0] &&
|
||||
localImage.args[0].count > 0
|
||||
) {
|
||||
localImage.args[0].count++;
|
||||
}
|
||||
args = null;
|
||||
continue;
|
||||
}
|
||||
|
@ -1692,7 +1700,13 @@ class PartialEvaluator {
|
|||
const localImage = localImageCache.getByRef(xobj);
|
||||
if (localImage) {
|
||||
operatorList.addOp(localImage.fn, localImage.args);
|
||||
|
||||
if (
|
||||
localImage.fn === OPS.paintImageMaskXObject &&
|
||||
localImage.args[0] &&
|
||||
localImage.args[0].count > 0
|
||||
) {
|
||||
localImage.args[0].count++;
|
||||
}
|
||||
resolveXObject();
|
||||
return;
|
||||
}
|
||||
|
@ -1809,6 +1823,13 @@ class PartialEvaluator {
|
|||
const localImage = localImageCache.getByName(cacheKey);
|
||||
if (localImage) {
|
||||
operatorList.addOp(localImage.fn, localImage.args);
|
||||
if (
|
||||
localImage.fn === OPS.paintImageMaskXObject &&
|
||||
localImage.args[0] &&
|
||||
localImage.args[0].count > 0
|
||||
) {
|
||||
localImage.args[0].count++;
|
||||
}
|
||||
args = null;
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -256,6 +256,8 @@ addState(
|
|||
data: maskParams.data,
|
||||
width: maskParams.width,
|
||||
height: maskParams.height,
|
||||
interpolate: maskParams.interpolate,
|
||||
count: maskParams.count,
|
||||
transform: transformArgs,
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue