Premultiplied colors and alpha=0
sandmann at daimi.au.dk
Wed Aug 13 12:46:41 PDT 2008
Generally to recover the "real" pixel from a premultiplied one, you
have to divide by the alpha channel, but this leads to a problem when
the alpha channel is 0. How should a render implementation treat such
Suppose it is compositing a source pixel with alpha 0 and color
channels non-zero OVER some destination pixel. There are at least two
reasonable things an implementation can do:
1. "The alpha channel is 0, so the source is transparent, so you just
get the destination"
2. "I'll do arithmetic as usual, so I'll just add the source color
channels onto the destination"
Pixman does both in various places. Is one more correct than the
The advantage of (1) is that you can avoid a bunch of memory reads for
images that are mostly transparent. The advantage of (2) is that
special-casing alpha=0 is unnecessary.
We could say that the results are simply unspecified, but clearly (0,
0, 0, 0) needs to be treated as transparent. Fortunately both (1) and
(2) do that. Since (1) is just a performance optimization and since
it's easy enough to check all the channels instead of just the alpha
channel, maybe (2) should be considered correct.
The alternative is to leave it unspecified.
More information about the xorg