Skip to content

Paint image masks as stencils in the fill color - #582

Merged
Velli20 merged 1 commit into
mainfrom
image-mask-stencil
Oct 18, 2026
Merged

Velli20 merged 1 commit into
mainfrom
image-mask-stencil

Conversation

@Velli20

@Velli20 Velli20 commented Oct 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Image masks (/ImageMask true) were decoded as opaque grayscale images, so they ignored the current non-stroking color and painted over the page where the mask leaves samples unpainted.
  • Masks now decode to coverage in a new PixelFormat::Alpha8. The canvas paints that coverage in the fill color with the coverage as alpha, for both image XObjects and inline images. Backends still receive RGBA or Gray8 only; Skia maps Alpha8 to its native alpha type.
  • An explicit /Decode array on a mask now yields coverage like the default does, instead of the inverse.
  • A fill pattern under an image mask still paints in the plain fill color.

Test plan

  • cargo conformance render on a 1-bit interpolated image mask drawn with 1 0 0 rg: paints red on a transparent background, matching PDFium. Variants without /Decode (opposite bits painted) and with ca 0.5 (half-transparent red) also checked.
  • cargo test for pdf-image, pdf-resources, pdf-canvas, pdf-document, pdf-renderer and pdf-graphics
  • cargo clippy on the library crates and cargo fmt --check

🤖 Generated with Claude Code

Image masks (/ImageMask true) were decoded as opaque grayscale images,
so they ignored the current non-stroking color and covered the page
where the mask leaves samples unpainted. They now decode to coverage
in a new PixelFormat::Alpha8, which the canvas paints in the fill color
with the coverage as alpha, for both image XObjects and inline images.

An explicit /Decode array on a mask now yields coverage like the
default one does, instead of the inverse.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Velli20
Velli20 merged commit 6c723d8 into main Oct 18, 2026
10 checks passed
@Velli20
Velli20 deleted the image-mask-stencil branch October 18, 2026 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant