[cairo] pixman box filtering code prototype

Soeren Sandmann sandmann at daimi.au.dk
Thu Nov 6 17:54:27 PST 2008


Hi Jeff,

[Replying out of order]

> > And another update. This version is pretty much feature complete and I
> > gave it a basic run through with firefox. (there's still a rounding
> > problem...).
> > 
> > I've also done some quick performance tests compared to the current
> > bilinear downscaling:
> > scale:.8 speed: 2x faster
> > scale:.4 speed: a little faster
> > scale:.2 speed: slower
> > 
> > The speed gains currently come at a cost. The image quality when scaling
> > between 1. and .5 is lower than the current filtering because we use a
> > combination of two integer box sizes which causes some blockiness. It's
> > possible to fix this by using a non-integer box-filter but that will
> > probably have a performance impact.

I wrote some code to do this - it is available in the "area" branch
here:

        git://freedesktop.org/~sandmann/pixman

Basically the idea is to first reconstruct a continuous image
bilinearly, then do a regular grid sampling in that
reconstruction. Currently it uses a 3x3 grid per destination pixels,
but this should be computed dynamically.

There are several appealing things about this filter:

- For upscaling with a box size of 1, it degenerates automatically to
  bilinear filtering.

- It works well for all affine transformations, not just scaling.

- It could be made to work well for perspective transformations by
  adjusting the shape of the sample grid dynamically.

- It is easy to define what it does.

- It gets results as good as GdkPixbuf

I didn't try to make the code fast at all, only to get it to work, so
in the current form it is too slow to be practical. There are several
possibilities for optimization though, and I don't think it is
*inherently* impractical.

In particular, the bilinear special-casing that I'm going to write
about in the other thread is likely to make a big difference, but
there is also some really dumb stuff going on in the area filter
itself, such as doing two matrix multiplications per subpixel row.

> > > Here's an update. It should be basically correct at this time (although
> > > it doesn't filter masks yet...). It still needs cleanup and
> > > optimization.

The thing that bothers me about this approach, is that it makes
pixman's filters not really behave as advertised. "Integer box
filtering, followed by whatever you actually asked for", is not the
same as "what you actually asked for".

If we do need something like this, could it be done by adding a new
"integer box" filter, then having cairo do the two step operation? As
Bill said, it seems like that would be equivalent, and it would have
the advantage of pixman filters behaving in a well-defined way.

I only looked briefly at the patch, so I could be missing something here.


Soren


More information about the cairo mailing list