[cairo] Concerns about using filters for downscaling

Bill Spitzak spitzak at gmail.com
Mon Mar 24 19:51:04 PDT 2014


The current default filter in Cairo for any scale less than .5 is 
unacceptable and must not be the default. This is a bug in current Cairo 
that has to be fixed. Therefore Cairo should change the default to 
"GOOD" and "GOOD" must do something other than bilinear for scales less 
than .5.

My recommendation:

NEAREST - Always use the pixel who's center is nearest the sample point. 
  This is the only mode that will produce output pixels that have values 
equal to some input pixel, which is important if the data is not a 
continuous value but something like object id's.

BILINEAR - Linearly interpolate the 4 nearest pixels from their centers 
to the sample point. This setting is needed to replicate old Cairo. THIS 
SHOULD NOT BE THE DEFAULT VALUE!!!

GOOD - For any scale >= 1 it is the same as BILINEAR. It may also use 
BILINEAR for scales greater than .5 though the quality starts to 
deteriorate. Below that it MUST switch to something that uses more than 
4 input pixels per output pixel! Some possibilities:

  * Box filter: multiply the pixels by the intersection of them with a 
scale-sized rectangle, then divide by the area of this rectangle.

  * Mipmap: entire image is scaled to the power of 2 nearest the scale 
and then BILINEAR sampling is done from that. As opposed to what is 
usually called mipmaps, I think a single one can be calculated, it is 
thrown away if a different power of 2 is requested. This is faster for 
single calculations and allows the scale in each direction to be different.

BEST - May be the same as GOOD. Or it may do something that produces 
higher quality:

  * Move the cutoff from BILINEAR from .5 to 1 (or maybe .99)

  * Replace mipmap with box filter

  * Replace box filter with a more complex filter

  * Do trilinear interpolation of 2 mipmaps.

  * Replace the BILINEAR for scales > 1 with some better filtering to 
preserve edges.


More information about the cairo mailing list