[cairo] downscaling capabilities

Frédéric Plourde frederic.plourde at polymtl.ca
Sat Apr 19 10:23:11 PDT 2008


By the way,

Does anybody know what was the first intented uses for filtering modes 
CAIRO_FILTER_BILINEAR,
CAIRO_FILTER_GOOD and CAIRO_FILTER_BEST ??

down to pixman, all three are considered equal to the same bilinear 
sampling technique, so we're not making any smart use of them.
I would suggest, since we're turning ourselves toward sampling issues, 
that we make use of these "GOOD" and "BEST" modes in a more clever way.

For example :

    CAIRO_FILTER_BILINEAR : our current bilinear filter
    CAIRO_FILTER_GOOD :       true downscaling to nearest mipmap level + 
bilinear filtering
    CAIRO_FILTER_BEST :         trilinear filtering.

thanx
-fred-



Owen Taylor a écrit :
> On Sat, 2008-04-19 at 09:35 -0400, Frédéric Plourde wrote:
>   
>> Thanks Bill for that "state of the art" about resampling techniques ;-)
>>
>>    Just to answer your last question and to be sure we understand each 
>> other, .. no, no... I was not thinking about MipMaping at all. I don't 
>> think it's well suited to cairo/pixman neither.
>>
>> I said that I was going to implement a simple low-pass filter (surely 
>> gaussian) in space-domain... it means : a convolution kernel (just like 
>> your "box filtering" that you mentionned). I just used another term to 
>> refer to it.
>>
>> However, the important thing is to adaptively adapt the size of that 
>> gaussian convolution kernel to the scaling factor...
>> let's keep in touch 'bout that.
>>     
>
> I'm going to directly disagree here and suggest that for
> CAIRO_FILTER_GOOD, the right algorithm is:
>
>  - Scale down by factors of 2 repeatedly until you are less than 2 times
>    the target scale factor
>  - Bilinearly sample from the result
>
> There are certainly disadvantages to this to this approach:
>
>  - Works worse with non-uniform scales (that contract more in one
>    direction than others)
>  - Produces discontinuities at powers of two (this is why people use
>    trilinear filtering)
>  - Produces noticeable aliasing just above powers of two (another
>    reason to use trilinear filtering)
>
> It's not good filtering in any sense. But:
>
>  - It has a cost that's O(num pixels in source), which is hard to do
>    with convolution techniques. (Not going to say impossible, but
>    hard, and especially hard for anything but a pure scale.)
>  - It's easy to make fast in C and optimize with mmx/sse/etc.
>  - It has good memory locality for the scale-down phase
>  - It is easy to apply to transforms that aren't pure scales
>
> There are certainly all sorts of better things you can do .. use better
> ways of scaling down the image, use better sampling from the scaled
> down image; there may be some interesting things to do with non-uniform
> / random sampling that would allow doing better than O(number of pixels
> in source), but but given the constraints of real-time software
> rendering (and CAIRO_FILTER_GOOD should be shooting for real-time) I'm
> not sure that they are feasible. What we should worry about in the
> short term is improving the worst case appearance (cairo does a really
> bad job here) and keeping the worst case performance within bounds
> (gdk-pixbuf does a really bad job with that.)
>
> - Owen
>
>
>   



More information about the cairo mailing list