[cairo] Cairo gradients and pre-mul data

David Turner dturner at nds.com
Wed Jun 21 00:04:20 PDT 2006


Hello Federico,

Federico Mena Quintero a écrit :
> Since I'm too lazy to figure out the math...
>
> What's the premultiplied equivalent of a non-premult gradient from
> (1, 0, 0, 0) to (1, 1, 1, 0)?  I.e. transparent red to solid white.  On
> the GIMP this gives me a transparent-to-white gradient with a red tinge
> in the middle section.
>
>   
I suppose you mean (1,0,0,0) to (1,1,1,1), with (R,G,B,A) notation, right ?

In one case, you interpolate all channels, THEN perform the ALPHA 
multiplication,
the result:   transparent "color" at the start, 50% transparent *pink* 
at the middle,
and solid white at the end (e.g. Cairo and GIMP)

In the other case, you perform the ALPHA multiplication BEFORE the 
interpolation,
the result: transparent "color" at the start, 50% *gray* at the middle, 
and solid
white at the end (when using pre-multiplied gradient stops)

that's because pre-multipication loses all original color information 
when alpha=0
(which is another way of saying that a fully transparent pixel has no color)

Clearly, using pre-multiplied gradient stops has some problems. I'll add 
that I measured
the performance cost of alpha premultiplication on each pixel, and that 
it is not very
important compared to other gradient computations.

Hope this helps,

- David Turner
- The FreeType Project  (www.freetype.org)


***********************************************************************************
Information contained in this email message is confidential and may be privileged, and is intended only for use of the individual or entity named above. If the reader of this message is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the postmaster at nds.com and destroy the original message.
*********************************************************************************** 



More information about the cairo mailing list