1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Improve (local) caching of parsed ColorSpaces (PR 12001 follow-up)

This patch contains the following *notable* improvements:
 - Changes the `ColorSpace.parse` call-sites to, where possible, pass in a reference rather than actual ColorSpace data (necessary for the next point).
 - Adds (local) caching of `ColorSpace`s by `Ref`, when applicable, in addition the caching by name. This (generally) improves `ColorSpace` caching for e.g. the SMask code-paths.
 - Extends the (local) `ColorSpace` caching to also apply when handling Images and Patterns, thus further reducing unneeded re-parsing.
 - Adds a new `ColorSpace.parseAsync` method, almost identical to the existing `ColorSpace.parse` one, but returning a Promise instead (this simplifies some code in the `PartialEvaluator`).
This commit is contained in:
Jonas Jenwald 2020-06-17 18:45:11 +02:00
parent 51e87b9248
commit 19d7976483
5 changed files with 335 additions and 45 deletions

View file

@ -89,6 +89,7 @@ var PDFImage = (function PDFImageClosure() {
mask = null,
isMask = false,
pdfFunctionFactory,
localColorSpaceCache,
}) {
this.image = image;
var dict = image.dict;
@ -159,7 +160,7 @@ var PDFImage = (function PDFImageClosure() {
this.bpc = bitsPerComponent;
if (!this.imageMask) {
var colorSpace = dict.get("ColorSpace", "CS");
let colorSpace = dict.getRaw("ColorSpace") || dict.getRaw("CS");
if (!colorSpace) {
info("JPX images (which do not require color spaces)");
switch (image.numComps) {
@ -184,6 +185,7 @@ var PDFImage = (function PDFImageClosure() {
xref,
resources: isInline ? res : null,
pdfFunctionFactory,
localColorSpaceCache,
});
this.numComps = this.colorSpace.numComps;
}
@ -220,6 +222,7 @@ var PDFImage = (function PDFImageClosure() {
image: smask,
isInline,
pdfFunctionFactory,
localColorSpaceCache,
});
} else if (mask) {
if (isStream(mask)) {
@ -235,6 +238,7 @@ var PDFImage = (function PDFImageClosure() {
isInline,
isMask: true,
pdfFunctionFactory,
localColorSpaceCache,
});
}
} else {
@ -253,6 +257,7 @@ var PDFImage = (function PDFImageClosure() {
image,
isInline = false,
pdfFunctionFactory,
localColorSpaceCache,
}) {
const imageData = image;
let smaskData = null;
@ -279,6 +284,7 @@ var PDFImage = (function PDFImageClosure() {
smask: smaskData,
mask: maskData,
pdfFunctionFactory,
localColorSpaceCache,
});
};