Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a temporary function-cache in AlternateCS.prototype.getRgbBuffer #19428

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 31 additions & 9 deletions src/core/colorspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,24 +636,46 @@ class AlternateCS extends ColorSpace {
: new Uint8ClampedArray(baseNumComps * count);
const numComps = this.numComps;

const tintCache = new Map();
// Use an integer cache-key when possible, since that's a lot faster than
// string concatenation.
const int32Key =
numComps <= 3 &&
(src instanceof Uint8Array || src instanceof Uint8ClampedArray);

const scaled = new Float32Array(numComps);
const tinted = new Float32Array(baseNumComps);
let i, j;
let i, j, key, val;

for (i = 0; i < count; i++) {
key = int32Key ? 0 : "";

for (j = 0; j < numComps; j++) {
scaled[j] = src[srcOffset++] * scale;
val = src[srcOffset++];
scaled[j] = val * scale;

key += int32Key ? val << (8 * j) : val + "_";
}
tintFn(scaled, 0, tinted, 0);
if (usesZeroToOneRange) {
for (j = 0; j < baseNumComps; j++) {
baseBuf[pos++] = tinted[j] * 255;
}
} else {
base.getRgbItem(tinted, 0, baseBuf, pos);

const cached = tintCache.get(key);
if (cached) {
baseBuf.set(cached, pos);
pos += baseNumComps;
} else {
tintFn(scaled, 0, tinted, 0);

if (usesZeroToOneRange) {
for (j = 0; j < baseNumComps; j++) {
baseBuf[pos++] = tinted[j] * 255;
}
} else {
base.getRgbItem(tinted, 0, baseBuf, pos);
pos += baseNumComps;
}
tintCache.set(key, baseBuf.subarray(pos - baseNumComps, pos).slice());
}
}
tintCache.clear();

if (!isPassthrough) {
base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
Expand Down
3 changes: 1 addition & 2 deletions src/core/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,11 @@ class PDFFunction {
// seen in our tests.
const MAX_CACHE_SIZE = 2048 * 4;
let cache_available = MAX_CACHE_SIZE;
const tmpBuf = new Float32Array(numInputs);
const input = new Float32Array(numInputs);

return function constructPostScriptFn(src, srcOffset, dest, destOffset) {
let i, value;
let key = "";
const input = tmpBuf;
for (i = 0; i < numInputs; i++) {
value = src[srcOffset + i];
input[i] = value;
Expand Down
2 changes: 1 addition & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function getDocument(src = {}) {
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
? src.maxImageSize
: -1;
const isEvalSupported = src.isEvalSupported !== false;
const isEvalSupported = false; // src.isEvalSupported !== false;
const isOffscreenCanvasSupported =
typeof src.isOffscreenCanvasSupported === "boolean"
? src.isOffscreenCanvasSupported
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/pr5134.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://web.archive.org/web/20140211020222/http://www.coachusa.com/CoachUsaAssets/files/97/route45.pdf
9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,15 @@
"lastPage": 1,
"type": "eq"
},
{
"id": "pr5134",
"file": "pdfs/pr5134.pdf",
"md5": "6a701a163472e071a2519348b55cbac1",
"rounds": 1,
"link": true,
"firstPage": 2,
"type": "eq"
},
{
"id": "issue5599",
"file": "pdfs/issue5599.pdf",
Expand Down