Repository navigation
Fix color key mask for greyscale and RGB PNGs - #1865
1AbdullahButt wants to merge 2 commits into
Conversation
The tRNS chunk of a greyscale or truecolour PNG holds one 2-byte sample per color component. The /Mask array needs one min/max pair per component, at the image's bit depth. Greyscale images got a mask built from only the high byte png-js keeps, so 8-bit and lower images used the wrong key. Read the samples straight from the tRNS chunk and build the mask from them for both color types. Fixes foliojs#1864 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| }); | ||
| } | ||
|
|
||
| // For greyscale and truecolour images, the tRNS chunk holds one 2-byte |
There was a problem hiding this comment.
Please create a PR in https://github.com/foliojs/png.js to fix the transparency property
There was a problem hiding this comment.
Try to use an existing png file instead of a synthetic one
The existing PngSuite fixtures already cover both cases: the 4-bit greyscale fixture has the key 0x000f (was masked as 0) and the 16-bit RGB fixture has one sample per channel (was 12 mask values). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Switched the tests to the existing fixtures (d16f4e0). The PngSuite 4-bit grey ( Opened foliojs/png.js#113 to read |
|
No. I will release a new pngjs and update dependency |
What kind of change does this PR introduce?
Bug fix. Fixes #1864.
The
tRNSchunk of a greyscale or truecolour PNG holds one 2-byte sample per color component. The PDF/Maskcolor key needs one min/max pair per component, using the image's bit depth.tRNS0x000fgot[0, 0]instead of[15, 15].The fix reads the samples straight from the
tRNSchunk (PNGImage#colorKey) and builds the mask from them for both color types. Indexed and alpha-channel images are unchanged.Tests
tests/unit/png.spec.jsusing small PNGs built in the test: 8-bit grey with grey (128) transparent, and 8-bit RGB with red transparent.png.spec.jshad 4 failures before the fix and all 18 tests pass after it.png,image,document,pdfa1andpdfa2specs all pass: 69 tests.tests/unitrun to finish in my container (it timed out on setup), so CI is the check for the rest.eslintandprettier --checkpass.Checklist:
This change was written with Claude Code (an AI coding assistant).
🤖 Generated with Claude Code