[cairo] Cairo gradients and pre-mul data

Bill Spitzak spitzak at d2.com
Wed Jun 21 14:50:57 PDT 2006


If I understand this right, Cairo's implementation of a gradient is 
equivalent to producing an image that is a linear interpolation between 
the supplied rgba values, then premultiplying that image by multiplying 
all the rgb values by the a values, and using this result as the source 
image.

My feeling is that this is wrong. The gradient result will be different 
than if a user tried to replicated it by making their own linearly 
interpolated image and then use that as the source image. Probably a 
more serious problem is that it is not possible to get a premultiplied 
gradient without inventing a lot more color stops. Since I suspect all 
gradients in other software other than SVG is premultiplied, this could 
be a problem for emulation.

I think whether the source is premultiplied or not can instead be 
considered part of the compositing step and is not part of the source 
image. This would allow both types of gradients, and also both types of 
images, to be used as the source. There are several ways to do this:

1. In Cairo right now, you can use OVER to get premultiplied, or use the 
same image as the source and mask and use COPY to get non-premultiplied. 
  I have already done this to support non-premultiplied images. The 
biggest problem here is that you can't use the mask for something else, 
and that operations other than OVER are not supported. Personally I 
don't see these as big problems, though it does make an exact SVG 
emulation impossible.

2. You could add another piece to the graphics state that says whether 
the source is premultiplied or not. If not, this would alter all the 
compositing math by replacing any occurance of A with A*a. It is not 
clear how hard this is.

2a. If you want, the above flag could be considered part of the source 
object. You can turn it on/off on a surface or gradient and it stays 
with it.

2b. The opposite alternative is to add enough extra compositing 
operators so that all useful non-premultiplied versions of the existing 
operators are provided.

3. You could add an operation that premultiplies a source, replacing 
it's contents, or that creates a new source that is the premultiplied 
version.

jose_ogp at juno.com wrote:

> 	I understand the desire to have support for the SVG spec, 
> but there are aspects there that are less then satisfactory (and 
> they are not strictly necessary in order to obtain things like 
> fading-out-to-a-color), and it may be wise to keep such in mind. 


More information about the cairo mailing list