[cairo] Premultiplied transparency causes streaks in images

Andrea Canciani ranma42 at gmail.com
Fri Nov 12 04:23:53 PST 2010

On Fri, Nov 12, 2010 at 12:54 PM, Paril <paril at alteredsoftworks.com> wrote:
> The black halo isn't black in a colored image, I was talking about in the
> white image, which I understand because of how premultiplication works (1 1
> 1 1 * 1 1 1 0.5 = 0.5 0.5 0.5 0.5); with the different colors it changes
> around, but yes, you are right, it's more like a multicolored halo.
> I get what you mean with the error accumulation, but what else can I do
> here? There's no Cairo function, that I can tell, to use SetSourceColor when
> SetSource on a pattern is used, hence why I do the color stuff manually, and
> I still have to multiply the values to get the bitmap together for Cairo to
> use properly. The _fixed.txt you had attached before seemed to just lighten
> the transparency and make it less visible, but the streaks are still
> definitely there.
> Your explanation of errors makes complete sense to me because when I look at
> it, the streaks barely occur when the color values are 0, 0.5 or 1; any
> value in-between and you can see the streaks on a huge scale, but with those
> three values you see maybe one or two points off the color.
> Cairo only supports integral colors, so there will be rounding errors with
> all of this multiplication... do you have any ideas on what I can do?

Actually cairo supports floating points colors, but the image backend (which
composites images using pixman) restricts you to integers. In theory it would
be possible to use floating point formats (for example on macosx you could
create a cairo-quartz surface that stores color information in floats).

I'm currently working on supporting colorspaces in cairo and pixman
and a side-project
includes extending the supported formats, but right now my code is experimental
(and, at least in some parts, broken) and will anyway take some time
to get it into
the projects, so I guess that relying on cairo support for floating
point compositing
is not an option right now.

I think that (unless you are willing to do the compositing yourself),
you might want to
look at how gimp (or some other open source project) handles this issue.


More information about the cairo mailing list