[cairo] antialias for images?

BJörn Lindqvist bjourne at gmail.com
Mon Oct 15 14:15:57 PDT 2007


On 10/15/07, Peter Goetz <peter.gtz2 at gmail.com> wrote:
> As you already supposed I started with a high resolution source image.
> I also change the order of rotation and scale. With no success.
> Even if I don't rotate at all and just scale the image down, I get a
> non-antialiased result.
> Any suggestions? Thanks again for help!

What you want is not anti alias for images. Anti alias is just for
putting points on non-integer coordinates. What you are looking for is
a better point sampling filter. If you scale down an image that is 100
pixels wide to 10 pixels, then you pick only one out of ten pixels
from the original image. The first result pixel is picked from among
the ten first pixels in the input, the second from those in position
10-20, the third from 20-30 and so on.

Let's say that your original is a 100x100 image of a black and white
checkerboard and each square is 5x5 pixels. If you scale that down to
a 10x10 image, then it may happen that Cairo only picks white pixels
for an entire row. It will looks really ugly and appear like the black
squares have disappeared. This is what happens with your image, Cairo
picks the wrong pixels.

The solution to your problem is to use interpolation. Then for each
resulting pixel, the mean of all contributing pixels are taken. So in
the example, instead of choosing one out of ten pixels for the result,
you sum all the ten pixels, then divide them by ten and use that as
the result. This process produces much better images because the risk
of "picking the wrong pixel" is reduced. It's like when doing a
census, if you just ask one person then that persons opinion might not
be representative of what everyone think. If you want a more accurate
result you need to answer many more persons. But that's more time

In short, Cairo doesn't do high quality filtering at the moment like
you require, if you need that then you need to use another image
library. Maybe this feature will be added in the future.

mvh Björn

More information about the cairo mailing list