|
From: Peter <jun...@dp...> - 2010-09-23 16:14:34
|
On Wednesday 22 September 2010 6:48:12 pm Jim Barry wrote: > On 2010-09-22 23:23, Peter wrote: > > How as AGG designed to handle the situation where you are blending a > > partially transparent color with a fully transparent color? I would > > assume that if it were working with a pixel format that included an > > alpha channel, it would just overwrite the fully transparent color > > with the partially transparent, since a fully transparent color would > > have absolutely zero impact on the final pixel values when blended > > with anything. > > Yes. However... > > > But when using AGG, it appears to blend partially transparent colors > > with fully transparent colors, leading to some very strange results > > where the pixels that you are drawing are actually blended with a > > non-existant color! > > This is because you are using a pixel format (pixfmt_bgra32) that blends > to a premultiplied destination format. In premultiplied space, the RGB > values are scaled by the alpha value, in order to make blending > operations more efficient. > > If any RGB value is larger than the alpha value then the blending > algorithm produces "weird" results such as you are seeing. > > Also, the sample application is not going to do anything with the alpha > channel when drawing to the screen - it just assumes that all pixels are > fully opaque. > > > I'm not sure if I'm describing this correctly, so I've attached a > > patch of lion.cpp example that demonstrates this behaviour that I'm > > talking about. It sets the background color to green but fully > > transparent. Normally, you'd expect the RGB channels to have > > absolutly zero effect when the alpha channel is transparent, but in > > this example, it somehow blends the lion with the green in the > > background even though the background is fully transparent, making > > the lion have a green tint! > > In premultiplied space, there is no such thing as "fully transparent > green". Since the RGB values must not exceed the alpha value, the only > valid fully transparent colour is all-zeros. > > If you really need to work in non-premultiplied space, you can use the > pixfmt_bgra32_plain format. > > - Jim Thank you for your patient and thorough explanation. I obviously have a lot to learn about AGG and even graphics in general. :) The pixel blender used in the pixfmt_bgra32_plain format does exactly what I was wanting it to do. I guess I must have missed that bit of information when I was trying to figure out the library. Since I made this mistake because I didn't understand the library, is there any documentation or source code that would be good for me to get familiar with so I could avoid making another mistake like this in the future? Peter |