Repository navigation
Combine image soft masks of a different size at the larger resolution - #560
Merged
Merged
Conversation
Conformance readsNo document reads differently from the base commit any more. 840 documents of the PDFium corpus read as on |
An /SMask may have different dimensions from its image, since both map onto the unit square. The decoder paired mask and image pixels one to one, so a low-resolution color image kept its own size and took its alpha from the first few mask samples. Images that carry glyph shapes in a full-resolution mask over a 2x2 single-color image rendered fully transparent, leaving pages without their text. Combine the two at the larger width and the larger height, capped at 4M pixels unless the image alone is larger, by dividing both axes by the smallest whole factor that fits; a mask can be far finer than the area it is drawn on. Build the result in one pass: each output pixel takes its color from the image pixel it falls in and its coverage from a 2x2 grid of mask samples over the area it covers, so the work follows the output size rather than the mask's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Velli20
force-pushed
the
resample-mismatched-soft-masks
branch
from
October 11, 2026 12:27
6bf820c to
eed107a
Compare
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
An image's
/SMaskmay have different dimensions from the image itself, since both map onto the unit square. The decoder paired mask and image pixels one to one. A low-resolution color image therefore kept its own size and took its alpha from only the first few mask samples.Some producers draw each line of text as a 2×2 single-color image whose full-resolution soft mask holds the glyph shapes. Those lines rendered fully transparent, so the page appeared to have no text.
When the sizes differ, the decoder now:
When the sizes already match, nothing changes.
Changes
pdf-image/src/raster.rs:resample_nearestscales a Gray8 or RGBA image to a target size. It tolerates short decoder buffers and returns a resource-limit error if the size overflows or allocation fails.pdf-image/src/image_decoder.rs:apply_resized_soft_maskhandles mismatched sizes. The existing assembly code moved intorender_ready_image.pdf-image/src/error.rs:PdfImageError::RasterwrapsImageRasterError.Test plan
cargo conformance renderon an affected document: text lines that were missing now render in their colors.cargo test -p pdf-image -p pdf-graphics -p pdf-resources -p pdf-canvas,cargo clippy --all --workspace,cargo fmt --check.🤖 Generated with Claude Code