Conversation
The Indexed4 branch of PngImageImporter never advanced offsetAlpha, so every palette alpha was written to index 0 of the alpha mask and the rest of the mask stayed zero. The /SMask therefore made the whole image fully transparent. Fixes empira#392.
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.
Fixes #392.
Cause
PngImageImporterbuilds the alpha mask for an indexed PNG with atRNSchunk by looking up each pixel's palette alpha. In theIndexed4branch,offsetAlphawas never incremented. Every pixel's alpha went toalphaMask[0], and the rest of the mask stayed0.PdfImagethen wrote that mask as the image's/SMask, so the image was fully transparent in every viewer. It was embedded and referenced from the page, but you could not see it.The
Indexed1andIndexed8branches do advance their offset. Only 4-bit palette images were affected. That is why converting the same image to RGBA fixed it.Fix
Increment
offsetAlphaafter each pixel's alpha is written, for both pixels of the nibble pair.Test
ImageTests.Indexed4_PNG_with_transparency_has_same_alpha_mask_as_RGBA_PNG(Core only). The test embeds the two sample images from the issue: the 4-bit indexed PNG and its RGBA conversion. It checks that the decoded/SMaskof the indexed image is not all zero and is byte-for-byte equal to the RGBA image's mask.Checked against the issue's samples (96×36, alphas 0/255/55/199/121):
/SMaskNote: I verified this with a small harness that references
PdfSharp.csproj. I did not run the new test insidePdfSharp.Tests, because building that project needs the downloaded assets and I did not have them locally.