[cairo] Operator optimization based on source or dest opacity

Soeren Sandmann sandmann at daimi.au.dk
Sat Mar 1 06:29:51 PST 2008


Hi Antoine,

> >If the convolution has negative coefficients, then the alpha channel
> >of the pixel would get something subtracted from it.
> 
> A convolution is a weighed average of the pixels under the 
> convolution kernel, with the kernel defining the weights. Whether 
> they're negative or positive, you'll be averaging 1s together. I 
> don't see anyway we could end up with a non-1 alpha value.

Only if the weights sum to 1, right?

Unfortunately, the render spec doesn't say exactly how convolution
filters should work, so the best we have to work with is the code. And
I don't see anything in the code that prevents the user from setting,
say, all the weights to 0.

> >Suppose we have an image with REPEAT_NONE, a NEAREST filter, and this
> >affine transformation:
> >
> >     [ 1  0 -10 ]
> >     [ 0  1 -10 ]
> >     [ 0  0   1 ]
> >
> >When we fetch (0, 0, 1), we get the source pixel at (-10, -10, 1),
> >which will be 0 since we have REPEAT_NONE. But the if statement in
> >your patch will claim that the image is opaque, as far as I can tell.
> 
> There might be cairo-independant considerations to take into account 
> which I've ignored, but as far as my cairo tests have shown, we're 
> sending the correct xSrc and ySrc down to 
> PIXMAN_COMPOSITE_RECT_GENERAL so that we always sample inside the 
> source and don't waste time sampling inexistant source pixels.

We can't rely on what cairo happens to do or not do. Even if cairo
were the only user of pixman, that would still be a recipe for
disaster.

Pixman is (more or less) an implementation of the X Render extension,
whose specification is here:

    http://gitweb.freedesktop.org/?p=xorg/proto/renderproto.git;a=blob_plain;h=af158b500590a37c0ffe0c0a1a147e489dfd4345;f=renderproto.txt

It is certainly legal to use X Render to composite with images that
are partially transparent, including where this transparency is the
result of a transformation.

So we will need to make sure that the image is completely opaque
before applying this optimization.

The alternative would be to have pixman_image_is_opaque take x, y,
width, height parameters and make it a check for whether that
sub-image is opaque. The compositing routine could then first check
whether all the rectangles were opaque, but I think this would be way
too complicated for way too little gain.


Soren


More information about the cairo mailing list