|
From: Jim B. <ji...@ch...> - 2010-09-23 02:17:59
|
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 |