Skip to content
Merged
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: 15 additions & 25 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,16 @@ class PartialEvaluator {
}
}

#createTransferMap(fn) {
const transferFn = this._pdfFunctionFactory.create(fn),
tmp = new Float32Array(1);
return Uint8Array.from({ length: 256 }, (_, i) => {
tmp[0] = i / 255;
transferFn(tmp, 0, tmp, 0);
return (tmp[0] * 255) | 0;
});
}

handleSMask(
smask,
resources,
Expand All @@ -904,15 +914,7 @@ class PartialEvaluator {
// we will build a map of integer values in range 0..255 to be fast.
const transferObj = smask.get("TR");
if (isPDFFunction(transferObj)) {
const transferFn = this._pdfFunctionFactory.create(transferObj);
const transferMap = new Uint8Array(256);
const tmp = new Float32Array(1);
for (let i = 0; i < 256; i++) {
tmp[0] = i / 255;
transferFn(tmp, 0, tmp, 0);
transferMap[i] = (tmp[0] * 255) | 0;
}
smaskOptions.transferMap = transferMap;
smaskOptions.transferMap = this.#createTransferMap(transferObj);
}

return this.buildFormXObject(
Expand All @@ -930,12 +932,9 @@ class PartialEvaluator {
handleTransferFunction(tr) {
let transferArray;
if (Array.isArray(tr)) {
transferArray = tr;
if (tr.length > 1 && tr.every(map => map === tr[0])) {
// All entries in the array are the same, so we can just use one of
// them.
transferArray = [tr[0]];
}
// If all entries in the array are the same, we can just use one of them.
transferArray =
tr.length > 1 && tr.every(map => map === tr[0]) ? [tr[0]] : tr;
} else if (isPDFFunction(tr)) {
transferArray = [tr];
} else {
Expand All @@ -955,16 +954,7 @@ class PartialEvaluator {
} else if (!isPDFFunction(transferObj)) {
return null; // Not a valid transfer function object.
}

const transferFn = this._pdfFunctionFactory.create(transferObj);
const transferMap = new Uint8Array(256),
tmp = new Float32Array(1);
for (let j = 0; j < 256; j++) {
tmp[0] = j / 255;
transferFn(tmp, 0, tmp, 0);
transferMap[j] = (tmp[0] * 255) | 0;
}
transferMaps.push(transferMap);
transferMaps.push(this.#createTransferMap(transferObj));
numEffectfulFns++;
}

Expand Down