[cairo] [Fwd: CAIRO_OPERATOR_SOURCE issue]

Owen Taylor otaylor at redhat.com
Sun May 9 13:50:00 PDT 2010


On Sun, 2010-05-09 at 21:42 +0200, Oscar Lazzarino wrote:
> On Sat, May 8, 2010 at 3:15 PM, Jonathan Morton
> <jonathan.morton at movial.com> wrote:
> >
> > Yes, Cairo uses premultiplied alpha throughout.  Presumably
> > cairo_set_source_rgba() is correcting the colour channels of the given
> > colour so that they are limited by the alpha channel.
> >
> 
> If so, what is the correct way to use Cairo with OpenGL to draw on
> screen (with glDrawPixels) or to generate textures (with glTexImage2D
> and friends) since OpenGL assumes non-premultiplied alpha? Is there a
> fast way to un-premultiply?

The best way to do it is to set up your GL drawing to assume
premultiplied textures. See:

 http://bugzilla.openedhand.com/show_bug.cgi?id=1406

To quote myself:

===
In fact, GL is really agnostic about what's in a texture; a texture is
just a
quadruple of R,G,B,A values. Depending on how you've set up your blending,
these could be premultiplied values, unpremultiplied values or something
entirely different. In particular:

 glBlendFunc(GL_SRC_ALPHA, G_ONE_MINUS_SRC_ALPHA)

  What clutter uses currently. Blend an non-premultiplied
  source over a destination without alpha. Not correct
  if the destination has alpha.

 glBlendFuncSeparate(GL_SRC_ALPHA, G_ONE_MINUS_SRC_ALPHA,
                     GL_ONE, G_ONE_MINUS_SRC_ALPHA)

  Blend an non-premultiplied source over a destination with
  premultiplied alpha.

 glBlendFunc(GL_ONE, G_ONE_MINUS_SRC_ALPHA)

  Blend an premultiplied source over a destination with
  premultiplied alpha.

There is no way to render to a destination with non-premultiplied alpha. So in
that sense, the native way that GL handles alpha is *premultiplied*.
===

- Owen




More information about the cairo mailing list