[cairo] Inefficiency of _cairo_xlib_surface_composite

Bill Spitzak spitzak at d2.com
Thu Jan 27 21:04:30 PST 2005



Jason Dorje Short wrote:

>>> - If the operation is OVER or SRC and there is a mask, but the mask is
>>> only 1-bit (all alpha values either 255 or 0), then XCopyArea can be
>>> used with a monochrome bitmap as a mask.

>> This is wrong if Cairo assumes images are premultiplied. It would only 
>> work if the rgb is 0 where the alpha is 0.
> 
> I don't understand this.

The function for OVER is A+B*(1-a) where A and B are the color and a is 
the alpha. If a is zero, this reduces to A+B which is not equal to B 
unless A==0.

Notice that in non-premultiplied compositing, the result is A*a+B*(1-a) 
which does reduce to just B when a is zero. For this and some other 
reasons I think it may be a good idea to support non-premultiplied images.

>> Second, I really doubt real applications are going to use 1-bit alpha 
>> enough to make it worth detecting this. I would limit the detection to 
>> determining if the alpha is 1 everywhere.
>
> I find that hard to believe.  In my experience, most X applications do 
> use 1-bit alpha.  This is because 0-bit alpha is useless, and >1-bit 
> alpha is unsupported in traditional xlib.  While XRender does support 
> 8-bit alpha, without hardware acceleration it is much slower.

This is true and I had not thought of it this way. I was mostly 
concerned with people porting Windows GDI+ appliations to Cairo, where 
they have no incentive to use 1-bit alpha and thus probably do not use 
it. However if you have an X application you probably have done things 
to force the alpha to 1 bit and thus your translated program will be 
slower unless Cairo can detect this.



More information about the cairo mailing list