[cairo] Premultiplied transparency causes streaks in images
ranma42 at gmail.com
Fri Nov 12 03:44:38 PST 2010
On Fri, Nov 12, 2010 at 11:32 AM, Paril <paril at alteredsoftworks.com> wrote:
> The fixed code you provided outputs a single dot (you forgot the Paint()
> call, but I extrapolated), which appears fine when you look at it at face
> value, but again, if you re-add that loop I had in the first place you see
> the transparency around the corners of the circle creating black streaks.
> This is the problem.
> If you weren't able to see the output, here it is:
If you zoom in http://alteredsoftworks.com/cairo/output.png you will
see that some "incorrect" pixels are more greenish than the expected
color (in particular, the streaks are not just black, confirming that my
explanation of the problem is probably correct).
> Here's a slightly modified version with no y modification. This shows you
> the clear black outline when the brush is continuously drawn in one spot:
Actually if I zoom in I see clearly that there is *no* black outline.
I see these shades: red, dark red, fuchsia, brown, purple, blue, green-blue
(Uhm... I'm not a native English speaker, so I might be misusing the color
names... anyway my point is that I see no black).
> I don't entirely understand your explanation; the only time you can really
> tell that it's happening is when you are drawing a bunch of lines around,
> hence why in the example I drew a capsule shape.
A "simpler" (and much less detailed) explanation is:
Premultiplication amplifies the quantization error of the color components
Compositing multiple times pixels accumulates the error
(so if you want to do it, you need to make sure that the error of the image
you are compositing is small enough)
On Fri, Nov 12, 2010 at 12:31 PM, Paril <paril at alteredsoftworks.com> wrote:
> I expected that the data (as from my understanding with premultiplied alpha)
> would somehow be de-multiplied back into the original white-and-transparent
> one (which apparently.. makes it do less operations? I really don't
> understand the whole concept, and from my googling a lot of people come to
> the same conclusion, probably just due to lack of understanding why
> premultiplication is important). This was not the case, and what Cairo is
> showing ALSO contains the black outline, which leads me to concur that
Does the black outline appear in test.png even if you use cairo functions
to save as png?
> Cairos' usage of the premultiplication is causing the image to draw this
> black halo in the transparent portions of the image.
There is no black halo, the "multicolor" halo is caused by error accumulation.
Premultiplication makes it more evident, but the problem is that you expect
that compositing 100 times a 1% opaque image is the same as compositing
the "same" image at 100% opacity. This assumption doesn't hold if you use
integer components because of quantization errors.
More information about the cairo