[cairo] four-channel alpha and destination alpha

Owen Taylor otaylor at redhat.com
Tue Feb 1 07:25:54 PST 2005


So, I was thinking about whether it was possible to derive a RENDER-
style 4-channel alpha mask from a ClearType image of text drawn
white-on-black. And the obvious question was "how do you compute
the right value for the A channel of the mask". Do you use 0xFF
always? Do you use the max of the other channels? Do you average them?

But then I realized two things:

 - The A channel of the alpha mask is irrelevant when compositing
   to a destination without alpha.

 - You won't get very useful results in any case if the destination
   surface has alpha. Take a simple case ... draw text to an empty ARGB
   surface, then composite that surface OVER a whitebackground. There's
   no result for the ARGB surface that would give the same result as
   compositing the text directly on the background.

Given those two ideas, the choice of using the average of the 
other channels seems the best choice. There are some problems:
 
 - There is some color shifting ... if I draw pure FFFF0000
   red through a ARGB mask onto a ARGB background, the result
   will include pixels like 88AA00000 or AA880000. If I then
   composite that onto a pure red surface, you'll get some
   shadowing around the edges of the text.

 - You get super-luminous pixels like the above mentioned 
   88AA0000. pixman handles that OK, but it's conceivable that
   hardware-accelerated compositing paths would have difficulty.

Still, since correct behavior isn't possible, these issues seem
acceptable and I don't think it's possible to do better.

Anyways, something I hadn't thought through before, so thrown out in
case other people find it useful, or want to correct me.

Regards,
						Owen

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050201/f5d215b8/attachment.pgp


More information about the cairo mailing list