openpdf-renderer: honor /SMask soft masks on Image XObjects - #1604
Open
andreasrosdalw wants to merge 2 commits into
Open
openpdf-renderer: honor /SMask soft masks on Image XObjects#1604andreasrosdalw wants to merge 2 commits into
andreasrosdalw wants to merge 2 commits into
Conversation
Image XObjects with a /SMask entry (PDF §11.6.5.3) -- the mechanism behind transparent-background PNGs (logos, product photos, ...) embedded in a PDF -- previously rendered fully opaque, since decodeImage()/renderImage() never looked at /SMask. Decode the soft mask as an 8-bit DeviceGray alpha channel (supporting the same JPEG/JPX/Flate/uncompressed encodings as the base image raster path, with nearest-neighbor resampling when the mask's own dimensions differ from the base image's) and composite it onto the decoded image before drawing. Update the README to document the new capability.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 7 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1604, LibrePDF#1605, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1605, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1604, and LibrePDF#1606, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
andreasrosdalw
added a commit
to andreasrosdalw/OpenPDF
that referenced
this pull request
Jul 28, 2026
Consolidated into LibrePDF#1607 along with the README updates for LibrePDF#1603, LibrePDF#1604, and LibrePDF#1605, so these four independent PRs (all based on master) don't each carry their own overlapping README.md diff and risk merge conflicts with each other depending on merge order.
This was referenced Jul 28, 2026
|
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.



Summary
OpenPdfCorePageRenderer.decodeImage()/renderImage()never looked at an Image XObject's/SMaskentry (PDF §11.6.5.3 soft mask), so images were always painted fully opaque./SMaskis exactly how a transparent-background PNG (a logo, a product photo, a watermark, ...) ends up embedded in a PDF, so this was a real, common visual bug: such images rendered as a solid opaque rectangle instead of blending into the page.applySoftMask/compositeSoftMaskresolve the (possibly indirect)/SMaskstream, decode it as an 8-bit DeviceGray alpha channel viareadSoftMaskGray(supporting JPEG/JPX viaImageIO, Flate-decoded, and uncompressed encodings — the same set already supported for base image rasters), and composite it onto the decoded base image, producing aTYPE_INT_ARGBresult. The soft mask's own/Width//Heightneed not match the base image (legal per spec) — handled with nearest-neighbor resampling./Mask(stencil / color-key masking) is not yet handled.openpdf-renderer/README.md's XObject-coverage section to document the new capability.