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

For images that include SMask/Mask entries, ignore an SMask defined in the current graphics state (bug 986450) #19269

Merged
merged 1 commit into from
Dec 31, 2024
Merged
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
26 changes: 16 additions & 10 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function addLocallyCachedImageOps(opList, data) {
if (data.objId) {
opList.addDependency(data.objId);
}
opList.addImageOps(data.fn, data.args, data.optionalContent);
opList.addImageOps(data.fn, data.args, data.optionalContent, data.hasMask);

if (data.fn === OPS.paintImageMaskXObject && data.args[0]?.count > 0) {
data.args[0].count++;
Expand Down Expand Up @@ -730,13 +730,9 @@ class PartialEvaluator {
}

const SMALL_IMAGE_DIMENSIONS = 200;
const hasMask = dict.has("SMask") || dict.has("Mask");
// Inlining small images into the queue as RGB data
if (
isInline &&
w + h < SMALL_IMAGE_DIMENSIONS &&
!dict.has("SMask") &&
!dict.has("Mask")
) {
if (isInline && w + h < SMALL_IMAGE_DIMENSIONS && !hasMask) {
try {
const imageObj = new PDFImage({
xref: this.xref,
Expand Down Expand Up @@ -793,7 +789,12 @@ class PartialEvaluator {
// Ensure that the dependency is added before the image is decoded.
operatorList.addDependency(objId);
args = [objId, w, h];
operatorList.addImageOps(OPS.paintImageXObject, args, optionalContent);
operatorList.addImageOps(
OPS.paintImageXObject,
args,
optionalContent,
hasMask
);

if (cacheGlobally) {
if (this.globalImageCache.hasDecodeFailed(imageRef)) {
Expand All @@ -802,6 +803,7 @@ class PartialEvaluator {
fn: OPS.paintImageXObject,
args,
optionalContent,
hasMask,
byteSize: 0, // Data is `null`, since decoding failed previously.
});

Expand All @@ -812,7 +814,7 @@ class PartialEvaluator {
// For large (at least 500x500) or more complex images that we'll cache
// globally, check if the image is still cached locally on the main-thread
// to avoid having to re-parse the image (since that can be slow).
if (w * h > 250000 || dict.has("SMask") || dict.has("Mask")) {
if (w * h > 250000 || hasMask) {
const localLength = await this.handler.sendWithPromise("commonobj", [
objId,
"CopyLocalImage",
Expand All @@ -825,6 +827,7 @@ class PartialEvaluator {
fn: OPS.paintImageXObject,
args,
optionalContent,
hasMask,
byteSize: 0, // Temporary entry, to avoid `setData` returning early.
});
this.globalImageCache.addByteSize(imageRef, localLength);
Expand Down Expand Up @@ -872,6 +875,7 @@ class PartialEvaluator {
fn: OPS.paintImageXObject,
args,
optionalContent,
hasMask,
};
localImageCache.set(cacheKey, imageRef, cacheData);

Expand All @@ -884,6 +888,7 @@ class PartialEvaluator {
fn: OPS.paintImageXObject,
args,
optionalContent,
hasMask,
byteSize: 0, // Temporary entry, note `addByteSize` above.
});
}
Expand Down Expand Up @@ -1814,7 +1819,8 @@ class PartialEvaluator {
operatorList.addImageOps(
globalImage.fn,
globalImage.args,
globalImage.optionalContent
globalImage.optionalContent,
globalImage.hasMask
);

resolveXObject();
Expand Down
9 changes: 8 additions & 1 deletion src/core/operator_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,11 @@ class OperatorList {
}
}

addImageOps(fn, args, optionalContent) {
addImageOps(fn, args, optionalContent, hasMask = false) {
if (hasMask) {
this.addOp(OPS.save);
this.addOp(OPS.setGState, [[["SMask", false]]]);
}
if (optionalContent !== undefined) {
this.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
}
Expand All @@ -646,6 +650,9 @@ class OperatorList {
if (optionalContent !== undefined) {
this.addOp(OPS.endMarkedContent, []);
}
if (hasMask) {
this.addOp(OPS.restore);
}
}

addDependency(dependency) {
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@
!issue5954.pdf
!issue6612.pdf
!alphatrans.pdf
!issue14200.pdf
!pattern_text_embedded_font.pdf
!devicen.pdf
!cmykjpeg.pdf
Expand Down
Binary file added test/pdfs/issue14200.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5255,6 +5255,13 @@
"link": true,
"type": "eq"
},
{
"id": "issue14200",
"file": "pdfs/issue14200.pdf",
"md5": "4dba2cde1c6e65abe53e66eefc97a7f1",
"rounds": 1,
"type": "eq"
},
{
"id": "jbig2_huffman_1",
"file": "pdfs/jbig2_huffman_1.pdf",
Expand Down
Loading