mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Add (basic) support for transfer functions to Images (issue 6931, bug 1149713)
This is *similar* to the existing transfer function support for SMasks, but extended to simple image data. Please note that the extra amount of data now being sent to the worker-thread, for affected /ExtGState entries, is limited to *at most* 4 `Uint8Array`s each with a length of 256 elements. Refer to https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf#G9.1658137 for additional details.
This commit is contained in:
parent
9d3e046a4f
commit
1058f16605
5 changed files with 143 additions and 6 deletions
|
@ -668,6 +668,51 @@ class PartialEvaluator {
|
|||
);
|
||||
}
|
||||
|
||||
handleTransferFunction(tr) {
|
||||
let transferArray;
|
||||
if (Array.isArray(tr)) {
|
||||
transferArray = tr;
|
||||
} else if (isPDFFunction(tr)) {
|
||||
transferArray = [tr];
|
||||
} else {
|
||||
return null; // Not a valid transfer function entry.
|
||||
}
|
||||
|
||||
const transferMaps = [];
|
||||
let numFns = 0,
|
||||
numEffectfulFns = 0;
|
||||
for (const entry of transferArray) {
|
||||
const transferObj = this.xref.fetchIfRef(entry);
|
||||
numFns++;
|
||||
|
||||
if (isName(transferObj, "Identity")) {
|
||||
transferMaps.push(null);
|
||||
continue;
|
||||
} 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);
|
||||
numEffectfulFns++;
|
||||
}
|
||||
|
||||
if (!(numFns === 1 || numFns === 4)) {
|
||||
return null; // Only 1 or 4 functions are supported, by the specification.
|
||||
}
|
||||
if (numEffectfulFns === 0) {
|
||||
return null; // Only /Identity transfer functions found, which are no-ops.
|
||||
}
|
||||
return transferMaps;
|
||||
}
|
||||
|
||||
handleTilingType(
|
||||
fn,
|
||||
args,
|
||||
|
@ -887,7 +932,10 @@ class PartialEvaluator {
|
|||
} else {
|
||||
warn("Unsupported SMask type");
|
||||
}
|
||||
|
||||
break;
|
||||
case "TR":
|
||||
const transferMaps = this.handleTransferFunction(value);
|
||||
gStateObj.push([key, transferMaps]);
|
||||
break;
|
||||
// Only generate info log messages for the following since
|
||||
// they are unlikely to have a big impact on the rendering.
|
||||
|
@ -898,7 +946,6 @@ class PartialEvaluator {
|
|||
case "BG2":
|
||||
case "UCR":
|
||||
case "UCR2":
|
||||
case "TR":
|
||||
case "TR2":
|
||||
case "HT":
|
||||
case "SM":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue