[cairo] Downing scaling images

Bill Spitzak spitzak at gmail.com
Tue Dec 14 22:38:08 PST 2010


Tim Corio wrote:
> gdk_pixbuf_scale (...) did a much better job of scaling than cairo_scale
> (...).  Here's a draft of a routine to do that scaling.  It's not very
> pretty but it works.

Searching on the web found code (attached is my copy of it) that gtk 
"hyper" generates a variable-sized sampling filter depending on the 
scale and offset. This is very similar to the code we use to generate 
filters.

The filter shape is a trapezoid:

         ___________
       _/           \_

The slanted ends are always 1 source pixel wide. The horizontal portion 
is 1/scale-1 pixels wide, or zero if the scale is greater than 1 (then 
it is a triangle). The actual samples are 1-unit wide integrals under this.

There is a fractional positioning (they call it "subsamples") which are 
chosen by where the center of the destination pixel lands in a source 
pixel, and they calculate all the fractional positions for a given 
filter size at the same time. So there are N rows of the table (they use 
16 but my code has it set to 3).

To figure out what row to use, take the projection of the center of the 
destination pixel into the source and subtract .5/scale+1. Take floor() 
of the answer and this is the pixel index for the first sample. Take the 
fractional part of this to figure out what row of the table to use, zero
for the first entry.

We have had better luck with filters that are not computed as integrals, 
but instead directly as smooth functions where the value is the function 
at the pixel center.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: hyperfilter.c
Type: text/x-csrc
Size: 2055 bytes
Desc: not available
URL: <http://lists.cairographics.org/archives/cairo/attachments/20101214/66bc1954/attachment.c>


More information about the cairo mailing list