mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Improve (local) caching of parsed ColorSpace
s (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:
parent
51e87b9248
commit
19d7976483
5 changed files with 335 additions and 45 deletions
|
@ -57,7 +57,8 @@ var Pattern = (function PatternClosure() {
|
|||
xref,
|
||||
res,
|
||||
handler,
|
||||
pdfFunctionFactory
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
var dict = isStream(shading) ? shading.dict : shading;
|
||||
var type = dict.get("ShadingType");
|
||||
|
@ -72,7 +73,8 @@ var Pattern = (function PatternClosure() {
|
|||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
);
|
||||
case ShadingType.FREE_FORM_MESH:
|
||||
case ShadingType.LATTICE_FORM_MESH:
|
||||
|
@ -83,7 +85,8 @@ var Pattern = (function PatternClosure() {
|
|||
matrix,
|
||||
xref,
|
||||
res,
|
||||
pdfFunctionFactory
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
);
|
||||
default:
|
||||
throw new FormatError("Unsupported ShadingType: " + type);
|
||||
|
@ -111,16 +114,24 @@ Shadings.SMALL_NUMBER = 1e-6;
|
|||
// Radial and axial shading have very similar implementations
|
||||
// If needed, the implementations can be broken into two classes
|
||||
Shadings.RadialAxial = (function RadialAxialClosure() {
|
||||
function RadialAxial(dict, matrix, xref, resources, pdfFunctionFactory) {
|
||||
function RadialAxial(
|
||||
dict,
|
||||
matrix,
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
this.matrix = matrix;
|
||||
this.coordsArr = dict.getArray("Coords");
|
||||
this.shadingType = dict.get("ShadingType");
|
||||
this.type = "Pattern";
|
||||
const cs = ColorSpace.parse({
|
||||
cs: dict.get("ColorSpace", "CS"),
|
||||
cs: dict.getRaw("ColorSpace") || dict.getRaw("CS"),
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
this.cs = cs;
|
||||
const bbox = dict.getArray("BBox");
|
||||
|
@ -834,7 +845,14 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
}
|
||||
}
|
||||
|
||||
function Mesh(stream, matrix, xref, resources, pdfFunctionFactory) {
|
||||
function Mesh(
|
||||
stream,
|
||||
matrix,
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache
|
||||
) {
|
||||
if (!isStream(stream)) {
|
||||
throw new FormatError("Mesh data is not a stream");
|
||||
}
|
||||
|
@ -849,10 +867,11 @@ Shadings.Mesh = (function MeshClosure() {
|
|||
this.bbox = null;
|
||||
}
|
||||
const cs = ColorSpace.parse({
|
||||
cs: dict.get("ColorSpace", "CS"),
|
||||
cs: dict.getRaw("ColorSpace") || dict.getRaw("CS"),
|
||||
xref,
|
||||
resources,
|
||||
pdfFunctionFactory,
|
||||
localColorSpaceCache,
|
||||
});
|
||||
this.cs = cs;
|
||||
this.background = dict.has("Background")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue