[cairo] Does cairo respect the alpha component of a color ?

Carl Worth cworth at east.isi.edu
Mon Sep 13 10:34:33 PDT 2004

On Mon, 13 Sep 2004 05:51:24 -0600, "Ravindra Kumar" wrote:
> I had a simple question about the way cairo
> deals with the alpha component. So far, I
> have seen that cairo does not care about
> alpha values lying in between 0 and 1. It just
> behaves as alpha on/off. Is it the intended
> behavior or I have hit some bug ?

That's definitely not intended behavior. What use of alpha are you
referring to? Alpha values that are passed directly to a function call
such as cairo_set_alpha are definitely floating-point values in the
range [0..1] with 1.0 being totally opaque.

We have lots of examples showing this working, such as:


Another place where alpha values show up, (and perhaps where you are
having the problem), is within image data. In this case, it's important
to point out that cairo expects image data to be provided with
pre-multiplied alpha. That is, the RGB color channels should already
have the alpha value multiplied into them, (so that no color component
exceeds the value of the alpha component of the same pixel).

If you weren't providing pre-multiplied color values in your image data,
then that would probably cause a result like what you described.

Let us know if that doesn't cover it.


PS. Keith might point out that the compositing algebra doesn't actually
prevent pre-multiplied color component values that exceed alpha.
"Super-luminescent colors" is I think what he called them. They might be
good for some interesting effects.

More information about the cairo mailing list