3 ms·
Premultiplied alpha exists to solve one problem: multiplying by the alpha channel is common to almost all of the Porter-Duff compositing operations, and compute
by mistercow 14y ago
Premultiplied alpha exists to solve one problem: multiplying by the alpha channel is common to almost all of the Porter-Duff compositing operations, and computers used to be slow, so premul came about as a way of speeding up drawing operations. Instead of multiplying each time, you simply multiplied the alpha channels in advance.
Unfortunately, this causes a ton of problems when you're doing anything with transparent images outside the realm of Porter-Duff, since the process is not fully reversible. In addition, it has tainted the way that developers think about alpha channels, so that they erroneously act like there is only One True Clear Color, which is how we ended up with issues like the one described in TFA in the first place.
Premul is not the solution. Premul is the original problem.
- ziedaniel1 14y agoI'm no graphics expert, but I'm pretty sure premul is not just an optimization technique -- it's a fundamentally different approach at alpha blending, and it makes some new things possible and some behavior more correct. See http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premultiplied-alpha.aspx http://blogs.msdn.com/b/shawnhar/archive/2009/11/06/premulti... . Sure, if you don't need the extra features premul provides (like the built-in ability for additive blending), then you can do some clever computations like IE apparently does to get the same result, but it's much simpler just to do things with premul.
- jixcode 14y agoI do not know why premultiplied alpha was invented in the first place but it does exactly solve the problem stated in the article. From the wikipedia article on "Alpha compositing": "Premultiplied alpha has some practical advantages over normal alpha blending because premultiplied alpha blending is associative and linear interpolation gives better results". I'd go even farther and say that linear interpolation of nonpremultiplied alpha gives incorrect results. Since antialiasing results in pixels that are a linear interpolation of the foreground and background color this is exactly what causes this problem and would be solve by premultiplied alpha. While unrelated to this problem, associativity of blending is a very usefull property for any graphics system since you can draw primitives into a temporary image and then draw that temporary image onto the target image and get the same results as you would get when drawing into the target image directly. I do not know any problem of the unspecified ton of problems you mentiond, but these two properties are so useful that I would not want to work with any system that does not use (or at least support) premultiplied alpha.