Fix Porter-Duff blend modes with transparent layers - #15721
Conversation
|
✅ All contributors have signed the CLA. Thank you! This PR is ready to be merged. |
|
I have read and agree to the Contributor License Agreement |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📜 Recent review details🧰 Additional context used📓 Path-based instructions (6)**/*📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{py,json}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{py,md,txt,json}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**⚙️ CodeRabbit configuration file
Files:
comfy_extras/**⚙️ CodeRabbit configuration file
Files:
🧠 Learnings (7)📚 Learning: 2026-02-21T14:01:41.482ZApplied to files:
📚 Learning: 2026-07-13T17:26:10.852ZApplied to files:
📚 Learning: 2026-03-04T14:05:31.426ZApplied to files:
📚 Learning: 2026-04-04T13:29:15.653ZApplied to files:
📚 Learning: 2026-05-09T18:40:40.199ZApplied to files:
📚 Learning: 2026-05-20T00:10:14.673ZApplied to files:
📚 Learning: 2026-07-26T18:37:44.213ZApplied to files:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughThe compositing formulas for DARKEN, LIGHTEN, MULTIPLY, and OVERLAY now use corrected alpha-weighted and premultiplied calculations. The changes also correct union-alpha and operand handling. Parameterized tests compare each mode against a tensor-based source-over reference across four source and backdrop alpha combinations. Tests verify both RGB output and transparency masks. Merge Risk: ⚪ Minimal · up to The change corrects transparent-layer blend behavior while preserving the existing interface, with focused tests and passing checks reported; no actionable merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
6b869a0 to
0c351fd
Compare
Problem
PorterDuffImageCompositepremultiplies its color inputs before applying blend modes, but four mode formulas did not account correctly for source-over compositing when either layer was transparent.DARKENandLIGHTENcompared premultiplied colors without weighting them by the opposite alpha.MULTIPLYused only the alpha intersection and dropped both non-overlapping regions.OVERLAYomitted the non-overlapping regions and paired the high-branch alpha factors with the wrong colors.This could make an opaque source disappear on a transparent backdrop, brighten colors unexpectedly, or produce incorrect results for partially transparent layers.
Change
Apply the source-over alpha equation to the affected modes and compute their overlap terms from premultiplied colors. The formulas now follow the W3C Compositing and Blending specification, while preserving the existing node interface and mask convention.
Add parameterized tests that compare all four modes against an independent source-over reference for transparent, partially transparent, and opaque layer combinations.
Tests
pytest -q tests-unit/— 1315 passed, 10 skippedpytest -q tests/execution --skip-timing-checks— 274 passed, 7 skippedruff check .