[cairo] Premultiplied transparency causes streaks in images
paril at alteredsoftworks.com
Thu Nov 11 22:24:13 PST 2010
I'm writing a small app kind of like Paint, and using images as brushes;
these images are transparent PNGs with white as the brush color, and the
color is multiplied in the code to the color selected in a color picker,
with transparency being applied in PaintWithAlpha.
This problem is generic to cairo and not the API I'm using, hence why I'm
Because cairo pre-multiplies the colors, it is obvious to expect that any
transparency would be multiplied into black; this makes sense to me,
however, with my understanding of pre-multiplied alpha, it is un-multiplied
by the rendering API so that it renders alpha properly. This appears not to
be the case, as all of my images render with an ugly black outline which
destroys alpha blending and creates "streaks" across the program.
Here is the image being used as a brush, and the image that is outputted by
Cairo after loading:
Does anyone have any experience with this sort of issue that they can tell
me what the problem is or how to combat it?
The streaking is barely visible when any combination of color values
containing 128, 255 or 0 are used; however, if you review the drawn data,
the color does in fact vary by usually 1 or 2 points in certain spots, in
around where the brushes were drawn.
Here's a screenshot of a canvas being manipulated by a scaled-up brush (5x
the size of circle.png); you can see the streaks on the background green
strokes, as well as a constant blue circle being drawn in the center to
highlight the issue.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cairo