Skip to content

fix: composite JPEG transparency in the source color space - #280

Open
yeagoo wants to merge 4 commits into
VERT-sh:mainfrom
yeagoo:fix/jpeg-transparency
Open

fix: composite JPEG transparency in the source color space#280
yeagoo wants to merge 4 commits into
VERT-sh:mainfrom
yeagoo:fix/jpeg-transparency

Conversation

@yeagoo

@yeagoo yeagoo commented Sep 7, 2026

Copy link
Copy Markdown

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.
  • The defect-focused tests fail against the unchanged upstream conversion function (14 failing tests before this fix).
  • bun run build: passed with a local .env based on .env.example.
  • ESLint and Prettier: changed files pass.
  • 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 cc7b5a54d5e9c797b377db47b9bdfbb561707783 and includes shared test harness commit c69e961, which moves the existing magickConvert function 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.

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