[Pixman] Better quality downsampling in cairo/pixman
sandmann at daimi.au.dk
Wed Jun 30 08:57:32 PDT 2010
> I don't really like to beat the dead horse, but here it goes... :)
The horse is far from dead. We really do need better image scaling, so
thanks for looking into it.
> Not sure if cairo is the case here, but the simple test I made shows
> that the best filter it have in the toolbox is bilinear
> (cairo-best.png). Gimp beats cairo with it's left hand, when it comes
> to downsampling (see gimp-cubic.png). And even gimp-linear.png seems
> to be much better than cairo's best attempt!
> I'm willing to take my time improving cairo's downsampling
> capabilities, if experienced people out there are willing to help me
> by answering my naive questions and pointing in the right direction.
> So my current questions are:
> 1) How hard would it be to add new cairo (or does it belong to
> pixman?) filter, say bicubic interpolation?
The place to add new filters is in pixman. Here are two old mails on
Simply adding a bicubic interpolation filter is relatively
straight-forward. All you have to do it write a new
bits_image_fetch_pixel_bicubic() in pixman-bits-image.c.
However, while a bicubic interpolation is better than bilinear and
would make upscaling look better, it wouldn't have that much effect on
downscaling. For downscaling, the basic problem is that we are
ignoring way too many source pixels, and not so much the quality of
the filter function itself.
The suggestion in the two mails above is therefore to add another
filtering stage where the transformed image is resampled using a
configurable filter kernel with a configurable sampling rate.
A first implementation could just offer a box filter. With resampling,
even a relatively poor filter like that would produce vastly better
results than what we have now while not being too complicated to
implement. There is a bit more detail in the second of the mails.
> 3) I know from past experience that even bicubic can be faulty when it
> comes to downsampling by a factor of over 1/4. I have solved this
> issue by using Lanczos (SinC) filter once. Should we consider using
> this filter too?
What you were seeing was likely just the issue that the bicubic filter
was run on too few sources pixels. If you use a bicubic filter with
But even with proper resampling, I think it might make sense to have
high-quality filters such as Lanczos available. A gaussian filter
would also be interesting since gaussian blur is a pretty useful
More information about the Pixman