Repository navigation
fix(pdf): keep the soft mask of a JPEG image - #1201
Merged
Merged
Conversation
A JPEG passes through to the browser undecoded, so its /SMask or stencil /Mask was dropped, and the transparent pixels showed the colour the JPEG holds there, often black. Keep the alpha apart as an RGBA png and mask the image with it in the SVG, so the browser composites what a JPEG cannot hold. Refs #1188 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5yx1nDeVcNX3BxqK1WpJz
andiwand
force-pushed
the
fix/pdf-jpeg-soft-mask
branch
from
October 10, 2026 09:45
879a59f to
9a017e9
Compare
andiwand
added a commit
that referenced
this pull request
Oct 10, 2026
The output now masks a JPEG image with its soft mask (#1201), and extracts Adobe small capitals as letters (#1200). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S5yx1nDeVcNX3BxqK1WpJz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #1188, refs opendocument-app/OpenDocument.droid#703
A user reports that a transparent image in a PDF shows with a black background. The report has no sample file, but one cause reproduces on current main:
encode_imagepasses aDCTDecodeJPEG through to the browser undecoded and drops its/SMaskor stencil/Mask. Producers often store a transparent image as a JPEG with a separate soft mask, and the JPEG holds black under the transparent pixels.The common case already works: LibreOffice writes a transparent PNG as Flate with an
/SMask, and odr renders that correctly.Before and after
A probe PDF draws a red rectangle, then a JPEG of a blue circle on black with a Flate
/SMaskthat is opaque only inside the circle.Change
encode_imagekeeps the JPEG as it is, and writes its alpha plane as an RGBA png (EncodedImage::alpha_png).XObject::image_alphaandImageElement::alpha_maskcarry it to the renderer.<mask mask-type="alpha">in the image's own unit square, one for each mask on a page (MaskRegistry::register_image_mask), and the<image>references it. The browser composites. No JPEG decoder is needed. The alpha soft masks of the graphics state already usemask-type="alpha", so this needs no browser support that the pdf view did not need before.Limits
/Maskon a JPEG still needs the decoded samples, so it stays unsupported.Verification
PdfFile.a_jpeg_keeps_its_soft_mask: a JPEG with an/SMaskgets one mask, and a JPEG without one gets none, in both text modes. Without the change, the test fails.The report has no sample, and OpenDocument.droid 4.21.0 still uses core 7.4.0. So I suggest closing #1188 only when the reporter confirms the fix, or sends a file.
Reference output
PDF pages with JPEG images that have soft masks will change. I will update the reference output after this PR and #1200 have landed.