[cairo] Compositing strategies and pre-multiplied alpha

Mauricio Piacentini mauricio at tabuleiro.com
Wed Sep 21 15:10:07 PDT 2005

>>The big question is: am I right to assume that doing the above (caching
>>the data as bitmaps with pre-multiplied alpha) will automatically reduce
>>the quality of antialiasing? The effect would probably not be noticeable
>>on a black background, but if I composite one cached bitmap on top of
>>another I will have a drop in antialiasing quality, wouldn't I? Or is
>>this not important as long as I move my sprites in whole pixel
>>increments (subpixel is obviously not possible in a scenario like this.)
> No idea, but I think the pre-multiplied alpha calculations are
> cleaner and more precise than nomal ones, so I wouldn't be
> surprised if it was the other way around.  I may be completely
> wrong.

Thanks for the input, I am building a prototype to test these ideas. Let 
me just clarify what I was trying to say before concerning "reduced 
quality", this is probably not the best way to put it.
As far as I understand it pre-multiplied assumes a black background, 
values on actual pixels are faded to match the alpha. My rationale was 
to compare two scenarios:

a) Get a red background
b) Render shape directly, antialias would be calculated to red


a) Get a red background
b) Composite a pre-multiplied image (rendered over a black background) 
over it.

The second scenario (in my twisted mind) would produce worse antialias, 
since colors would already be altered by the precompositing to black.

But now thinking about it I can see that maybe the results would be the 
same, namely red + a given transparency since black would not skew the 
results... doh. Maybe this makes a difference only if you need to 
process the image further, like trying to increase brightness, as some 
color information (resolution) in the pre-multiplied pixels would be 
lost. But quality would actually be the same for the common scenario of 
simply compositing the layers.

I will experiment with this a bit more in a prototype.


More information about the cairo mailing list