[cairo] MIPMAPPING cairo.

Soeren Sandmann sandmann at daimi.au.dk
Tue Nov 4 11:01:31 PST 2008


Here are some high-level comments on the idea of adding mipmaps to

Fred's patch adds three new filters to pixman:

* Simple mipmapping (called NEAREST_MIPMAP_NEAREST in the patch)

Based on the transformation matrix, pick the "closest" mipmap, then
sample using a NEAREST filter in that mipmap.

* Bilinear mipmapping (called LINEAR_MIPMAP_NEAREST in the patch)

This works like simple mipmapping, but the sampling in the mipmap is
done with a BILINEAR filter.

* Trilinear mipmapping (called LINEAR_MIPMAP_LINEAR in the patch)

Based on the transformation matrix, pick the two closest mipmaps, then
sample bilinearly from both mipmaps, then interpolate between those
two samples.

Two things to note: 

(1) None of these filters will produce better *quality* than a simple
    box filter. Their utility is basically improved performance in the
    case where an image needs to be painted at many scaling levels -
    for example in an animated zoom.

(2) The two first filters can be implemented outside of pixman with no
    loss of efficiency. The application would create the mipmap
    pyramid itself as a set of pixman images, and instead of calling
    pixman_image_composite() with the original source image, it would
    call it on one of the mipmaps with the transformation matrix
    adjusted appropriately. Depending on whether the application sets
    a "nearest" or a "bilinear" filter, it would get equivalent
    results to "Simple Mipmap" or "Bilinear Mipmap".

    To implement a TRILINEAR filter, help is needed from inside pixman
    because the sampling would involve two images, not just one. But
    even this could be done much more simply by just adding a new
    PIXMAN_TRILINEAR filter that would take another image and an
    interpolation factor as a parameter.

So I don't think the two first modes make sense to add to pixman as
new filters - at most they could be done as helper/convenience
functions to manage a mipmap pyramid, but before doing that, I'd like
to know that cairo would be interested in using them first.

Support for trilinear filtering could possibly make sense at some
point, but even then, considering that it's only a performance
optimization and that we need something like Jeff's box filtering
anyway, I'd like to see just how much of an improvement it would be. I
suspect a box filter with a fast path specialized for scaling down is
going to be really difficult to beat through the general compositing
path, even with mipmaps.


More information about the cairo mailing list