[Pixman] Better quality downsampling in cairo/pixman
Bill Spitzak
spitzak at gmail.com
Tue Jun 29 12:21:13 PDT 2010
Alexander Shulgin wrote:
> Hi all,
>
> I don't really like to beat the dead horse, but here it goes... :)
>
> (Apparently my first try didn't pass moderation, so I'm retrying now
> with more compact attachment.)
>
> The other day I was using Alt+TAB to switch between windows in my
> brand new Ubuntu desktop and was unpleasantly surprised how window
> thumbnails quality was in striking contrast with the overall eye-candy
> of the desktop (other effects seem to use OpenGL).
>
> 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 problem is the current filtering is incorrect for any scales less
than 1/2. It is not any kind of filtering at all, instead it
interpolates the two pixels nearest the sample point. What interpolation
function it uses is pretty much irrelevant (though it has to be linear
for it to make any sense at all, in that case it is equivalent to a box
filter for scales from 1/2 to infinity).
There was a flurry of work on this at one time but I can't remember
what. The general impression is that for maximum efficiency perhaps
Cairo should do part of the step: it could box-filter the image down to
an intermediate image so that the scaling is in the range 1/2-infinity,
then let unchanged pixmap do the rest. Cairo would then preserve this
scaled image until a different one was requested or the source surface
was changed, because it is likely a similar scale would be needed again.
There was lots of talk about mipmaps but that only saves time if the
image will be drawn many times at many different scales, which seems to
not be Cairo's main use.
There is also some interest in new filtering for zooming in, many users
prefer to see the pixels drawn as antialised squares (like OSX does),
rather than smooth gradents (Linux & Windows). I think that would have
to be addressed in pixman and means the interpolation function is a Z
shape, 0 and 1 at the ends with a linear slope in the middle where the
steepness depends on the scale.
> 2) How comes Gimp's linear is much like cubic? Does it seem to do
> something more than just bilinear interpolation?
"Linear" probably means a box filter, it is poorly named. If you drew
the filter it would be a rectangle 1 output pixel wide and 1 tall. Slide
this across the pixels and (as long as the input pixels are 1/2 or more
wide) it will intersect exactly t of one pixel and 1-t of the next, with
t varying between 0 and 1. This leads to linear interpolation.
"Cubic" may mean a cubic function for interpolation, but this is
equivalent to a triangle-shaped filter, 2 pixels wide at the base. Or it
can mean a cubic-shaped filter. So this term is misleading.
> 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?
I suspect there was some other problem other than the filter selection
in this case. More likely the entire algorithm was altered to one that
applies the filter correctly.
More information about the Pixman
mailing list