[cairo] High Quality ImagePattern Scaling

Bill Spitzak spitzak at thefoundry.co.uk
Thu Aug 28 12:39:40 PDT 2008


Vladimir Vukicevic wrote:

> We actually talked about solving this at the Cairo summit yesterday,  
> and should hopefully have it fixed in a day or so -- there will be a  
> high-quality mipmapping option, as well as a less memory intensive  
> option.

Did you consider the idea I posted where it picks the next larger 
integer down-scale and produces that image, and then uses the current 
interpolation for it?

Creating a mipmap is expensive and it works poorly if the horizontal and 
vertical scales are different or if they are not near powers of 2. It 
only wins if you expect to draw the same image at many scales, such as 
when it is a texture map for a 3D object that moves in Z. Since Cairo 
does not do perspective transforms it cannot do this use case.

If instead this integer-scaled single version was cached using the code 
you plan to use for caching the mipmap, it would speed up the most 
common case (drawing the same image with the same scale over and over), 
produce better scaling, and the cache would be created much faster and 
use less memory than the mipmap.

Some more detail:

 From the transform, figure out a scale of x=1/A,y=1/B where A and B are 
integers. If the transform has no rotation, these are 
max(1,ceil(1/fabs(xscale))) and max(1,ceil(1/fabs(yscale))).

Getting A and B when there are rotations is more complicated :-)

If A==B==1 then ignore the cache and use the image. Otherwise see if 
this is the A,B used by the current cached image, if not, throw away the 
cached image and create a new one with this scale. This is really fast 
as each pixel is just the average of a non-overlapping rectangle of 
source pixels.

Divide the transform by this scaling to get the transform from the 
scaled image to the final, and use this to run the existing XRender 
transform.

-- 
Bill Spitzak, Senior Software Engineer
The Foundry, 618 Hampton Drive, Venice, CA, 90291, USA
Tel: +1 310 399-4555 * Fax: +1 310 450-4516 * Web: www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027


More information about the cairo mailing list