[cairo] Premultiplied transparency causes streaks in images
Andrea Canciani
ranma42 at gmail.com
Fri Nov 12 01:07:36 PST 2010
On Fri, Nov 12, 2010 at 7:24 AM, Paril <paril at alteredsoftworks.com> wrote:
> Hi there.
>
> 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
> posting here.
Could you provide a small C program reproducing the problem?
(The one using circle.png to generate test.png would be good)
>
> 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:
> http://alteredsoftworks.com/cairo/circle.png
> http://alteredsoftworks.com/cairo/test.png
>
> Does anyone have any experience with this sort of issue that they can tell
> me what the problem is or how to combat it?
If you are accessing the image data directly, you have to handle it as
premultiplied.
In particular from the images you provided, my guess is that test.png was
not generated using cairo png API (which unpremultiplies the data before
storing it in the png file).
Andrea
More information about the cairo
mailing list