mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 17:55:37 +02:00
Merge pull request #16268 from Snuffleupagus/RegionalImageCache
Attempt to also cache images at the "page"-level (issue 16263)
This commit is contained in:
commit
3a36a9d337
5 changed files with 63 additions and 9 deletions
|
@ -59,6 +59,7 @@ import {
|
|||
LocalGStateCache,
|
||||
LocalImageCache,
|
||||
LocalTilingPatternCache,
|
||||
RegionalImageCache,
|
||||
} from "./image_utils.js";
|
||||
import { NullStream, Stream } from "./stream.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
|
@ -229,6 +230,7 @@ class PartialEvaluator {
|
|||
this.options = options || DefaultPartialEvaluatorOptions;
|
||||
this.parsingType3Font = false;
|
||||
|
||||
this._regionalImageCache = new RegionalImageCache();
|
||||
this._fetchBuiltInCMapBound = this.fetchBuiltInCMap.bind(this);
|
||||
ImageResizer.setMaxArea(this.options.canvasMaxAreaInBytes);
|
||||
}
|
||||
|
@ -635,11 +637,20 @@ class PartialEvaluator {
|
|||
);
|
||||
|
||||
if (cacheKey) {
|
||||
localImageCache.set(cacheKey, imageRef, {
|
||||
const cacheData = {
|
||||
fn: OPS.paintImageMaskXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
});
|
||||
};
|
||||
localImageCache.set(cacheKey, imageRef, cacheData);
|
||||
|
||||
if (imageRef) {
|
||||
this._regionalImageCache.set(
|
||||
/* name = */ null,
|
||||
imageRef,
|
||||
cacheData
|
||||
);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -664,11 +675,20 @@ class PartialEvaluator {
|
|||
);
|
||||
|
||||
if (cacheKey) {
|
||||
localImageCache.set(cacheKey, imageRef, {
|
||||
const cacheData = {
|
||||
fn: OPS.paintSolidColorImageMask,
|
||||
args: [],
|
||||
optionalContent,
|
||||
});
|
||||
};
|
||||
localImageCache.set(cacheKey, imageRef, cacheData);
|
||||
|
||||
if (imageRef) {
|
||||
this._regionalImageCache.set(
|
||||
/* name = */ null,
|
||||
imageRef,
|
||||
cacheData
|
||||
);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -693,11 +713,16 @@ class PartialEvaluator {
|
|||
);
|
||||
|
||||
if (cacheKey) {
|
||||
localImageCache.set(cacheKey, imageRef, {
|
||||
const cacheData = {
|
||||
fn: OPS.paintImageMaskXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
});
|
||||
};
|
||||
localImageCache.set(cacheKey, imageRef, cacheData);
|
||||
|
||||
if (imageRef) {
|
||||
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -790,13 +815,16 @@ class PartialEvaluator {
|
|||
operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
|
||||
|
||||
if (cacheKey) {
|
||||
localImageCache.set(cacheKey, imageRef, {
|
||||
const cacheData = {
|
||||
fn: OPS.paintImageXObject,
|
||||
args,
|
||||
optionalContent,
|
||||
});
|
||||
};
|
||||
localImageCache.set(cacheKey, imageRef, cacheData);
|
||||
|
||||
if (imageRef) {
|
||||
this._regionalImageCache.set(/* name = */ null, imageRef, cacheData);
|
||||
|
||||
assert(!isInline, "Cannot cache an inline image globally.");
|
||||
this.globalImageCache.addPageIndex(imageRef, this.pageIndex);
|
||||
|
||||
|
@ -1723,7 +1751,9 @@ class PartialEvaluator {
|
|||
|
||||
let xobj = xobjs.getRaw(name);
|
||||
if (xobj instanceof Ref) {
|
||||
const localImage = localImageCache.getByRef(xobj);
|
||||
const localImage =
|
||||
localImageCache.getByRef(xobj) ||
|
||||
self._regionalImageCache.getByRef(xobj);
|
||||
if (localImage) {
|
||||
operatorList.addImageOps(
|
||||
localImage.fn,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue