Add alpha blending
See original GitHub issueWe should have a method for alpha blending. This is required to be able to do contrast calculations properly (see https://github.com/w3c/csswg-drafts/issues/7358 ).
Things to decide:
- Naming: Perhaps
overlay()
orover()
? OroverlayOn()
or juston()
which is more clear as aColor
method, but not so much in the procedural API (SeeoverlayOn(color1, color2)
vscolor1.overlayOn(color2)
). Whatever we come up with should make sense in both APIs, so I’m leaning towardover()
which is also the operator name. - Is there any reason for it to take more than 2 arguments? My understanding is that the operator is associative.
The math seems pretty straightforward. @svgeesus are there any considerations when applying this to other color spaces? What color space do we use for the result? I guess the color space of the color being overlaid?
Issue Analytics
- State:
- Created a year ago
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Compositing Images with Alpha Blending - Apple Developer
Combine two images by using alpha blending to create a single output.
Read more >Transparency
1( α α. Basic Alpha Blending. Solid back color. Transparent front color with opacity α ... But can't insert surface between them later...
Read more >Blending - LearnOpenGL
An alpha value of 0.5 tells us the object's color consist of 50% of its own color and 50% of the colors behind...
Read more >Alpha Blending Using OpenCV (C++ / Python) - LearnOpenCV
In this tutorial – Alpha blending using OpenCV, we will learn how to alpha blend two images and overlay a transparent PNG image...
Read more >Alpha compositing - Wikipedia
In computer graphics, alpha compositing or alpha blending is the process of combining one image with a background to create the appearance of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
EDIT: Just to clarify, clamping αo is specifically related to premultiplication as well, and in my case, I was using it to undo premultiplication on each channel without first clamping it to a realistic 0 - 1 range. Basically, all my issues were related to undoing premultiplication.
As someone that has already gone down this road, if you add support for
source-over
compositing and normal alpha blending, you have everything you need to do the others, you can just swap out different compositing and blend methods. So the key is just to make sure the compositing step and the blend step is generic. I think that is the main point that is being conveyed.Though I had some missteps in the beginning 😅, I can pretty much mimic what browsers are doing now.