fix: composite JPEG transparency in the source color space - #280
Open
yeagoo wants to merge 4 commits into
Open
Conversation
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.
JPEG has no alpha channel. Dropping alpha can expose hidden RGB values: a fully transparent red pixel becomes opaque red, and a partially transparent edge loses its intended compositing.
Composite alpha onto white before writing JPEG and its JPG/JPE/JFIF aliases. Derive the matte by converting a single white pixel into the source color space; raw RGB white channel values would otherwise create black CMYK or orange Lab backgrounds. Dispose this temporary image in
finally. A 50%-transparent red region becomes light red while an opaque region stays red.White is an explicit default background choice and needs maintainer agreement. This branch adds no background-color UI; a configurable background can be considered separately.
Validation
Synthetic fully transparent, half-transparent and opaque bands are checked through JPEG/JPG/JPE/JFIF output. Color assertions allow a two-level JPEG quantization tolerance. Source alpha is preserved until the explicit compositing operation. Additional tests cover CMYK transparency through all four aliases with both metadata settings, Lab transparency, and opaque CMYK.
bun run test: 20 passed, including five shared behavior tests.bun run build: passed with a local.envbased on.env.example.bun run check: the same 7 pre-existing missing Node type errors as upstream; no additional errors. Full-repository lint has existing failures outside this change; changed files pass.Patch structure
This branch is based on upstream
cc7b5a54d5e9c797b377db47b9bdfbb561707783and includes shared test harness commitc69e961, which moves the existingmagickConvertfunction unchanged into a utility imported by the worker. Tests invoke that exact production function with the installed WASM. No new package dependency is introduced.Each repair branch can be reviewed independently. After the shared harness lands, the remaining branches will need rebasing onto upstream main to resolve overlapping edits in
magick-convert.ts.Shares the behavior-preserving test harness with #275.