[cairo] Concerns about using filters for downscaling

Søren Sandmann sandmann at cs.au.dk
Tue Mar 25 19:46:49 PDT 2014

Bill Spitzak <spitzak at gmail.com> writes:

> I'm also still mystified by the "two filters" approach. I have no idea
> what you mean by the sampling and reconstruction filter. I have done a
> lot of image processing, and transformations only use *one* filter,
> called the "sampling filter". This filter changes depending on the
> scale and on the fractional portion of the sample point.

Say that we want to transform a source image with a transformation that
is a downscale in one dimension and an upscale in another.

Consider the untransformed source image in the frequency domain. It is
made up of pixels, so its Fourier transform consists of the baseband
replicated to infinity. In order to transform the image, we conceptually
need to do four things:

(a) Get rid of the replicated copies of the baseband. This is
done by lowpass filtering so that only one copy remains.

(b) Transform the image. This will distorts the one remaining baseband
copy so that it becomes bigger in one dimension and smaller in
another. Parts of it will now stick out outside the baseband.

(c) Lowpass filter again to get rid of the bits of baseband copy that
ended up outside the baseband square. Otherwise those bits will cause
aliasing in the next step.

(d) Sample the image; this will once again replicate the baseband to

Step (a) is a reconstruction filter, step (c) is a sampling filter. Both
are necessary. If you leave out step (a) you will get extra copies of
baseband in the final result -- in an extreme form this is what you get
if you upscale an image with insufficient interpolation: tiny dots on a
black background. If you leave out step (c) you get aliasing artefacts,
which is what we all know from current cairo.

Now, when the transform is affine, all the four steps can be combined
into one by convolving the two filters, and this is what pixman does.

You need to read and understand the code in pixman-filter.c and the
bits_image_fetch_pixel_separable_convolution() function in
pixman-bits-image.c. If you are still "mystified" after that, feel free
to ask questions, but I am not going to write any further emails unless
I see evidence that you understand what the pixman code is actually


More information about the cairo mailing list