Re: How does semi-transparency work on the anti-aliased canvas?
- From: muppet <scott asofyet org>
- To: zentara <zentara zentara net>
- Cc: gtk-perl-list gnome org
- Subject: Re: How does semi-transparency work on the anti-aliased canvas?
- Date: Wed, 26 Oct 2005 08:58:52 -0400
On Oct 26, 2005, at 7:47 AM, zentara wrote:
I can manipulate the "fill_color_rgba" hex number to
give me a few different semi-transparent ellipses, but
can anyone explain how the hex numbering actually works to
produce the semi-transparent effect?
(Not sure exactly what you want to know, so if i've answered the  
wrong questions, just say so.)
The RGBA numbers are 32-bit values composed of one-byte-per-channel  
for red, green, blue, and alpha (0xrrggbbaa).  The alpha value is the  
"opacity", and this is used to describe how much of the source color  
is blended with the destination color to create the output color  
according to this formula:
   alpha_pct = alpha / 255.0
   destination red' = source red * alpha_pct + dest red * (1.0 -  
alpha_pct)
   destination green' = source green * alpha_pct + dest green * (1.0  
- alpha_pct)
   destination blue' = source blue * alpha_pct + dest blue * (1.0 -  
alpha_pct)
An alpha value of 0xff is 255, which is 100% of the source color,  
which is a traditional "source-copy" operation.  An alpha value of  
25% means the output color is composed of 25% of the source color and  
75% of the color already existing at the destination.  The actual  
color you'll get as a result of the opacity value, therefore, depends  
on what you're blending it with.  On a light background, a lower  
opacity makes the color lighter, on a dark background, a lower  
opacity makes the color darker, over red it gets redder, etc.
This is implemented using client-side blitting of microtiles in  
libart.  To get proper alpha blending, you need full-resolution color  
data, so it must be done on 24-bit RGB values -- dithered colors  
don't work --- so it happens on the client side, using XPutImage to  
transfer the full RGB to the X server.
The canvas demo, is set up, to allow you to choose a normal
(not anti-aliased) example, which does it on the basis of using a  
stiple.
It's alot uglier, but it is always how I thought it was done,  
coming from
Tk.
Stippling is a form of halftoning, which is how you approximate  
colors on a device that can't actually reproduce them.  By having a  
stipple pattern that displays every other dot, you get effectively  
50% of the input color, and the background shows through.  No alpha  
blending occurs --- it's the equivalent of alpha=100%.  And, yes,  
this is uglier than alpha blending, but tends to be much faster, as  
it can be performed on the X server.  The Tk canvas pretty much  
predates widespread use of alpha blending; old hardware had a hard  
time with it, because it requires keeping full-color copies of the  
various components to be blended.
As an aside, cairo does everything in an alpha space, and is much  
more efficient at it than libart.  Part of the big fuss about the new  
compositing-based X servers is that they can do alpha blending on the  
server side.
--
That's it!  It's one thing for a ghost to scare my children, but it's  
another to play my theremin!
  - Homer Simpson
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]