[Pixman] [cairo] Supersampling - 2nd attempt

Bill Spitzak spitzak at gmail.com
Tue Aug 17 09:56:35 PDT 2010

On 08/17/2010 01:01 AM, Soeren Sandmann wrote:
> Bill Spitzak<spitzak at gmail.com>  writes:
>>   >  I'm not sure what's
>>   >  the difference in quality between those approaches. I could try
>>   >  prototyping both of them.
>> I suspect there is going to be a phasing problem with your approach if
>> the scale is slightly different that 1/integer. At some places the
>> kernel samples line up with the pixel centers and at others it is
>> between them and thus blurring or lowering the contrast. This will
>> probably look like moire patterns.
> This is why we need both interpolation and low-pass filtering. When
> the kernel samples don't line up with the pixel centers, then we apply
> the interpolation filter. For example the bilinear filter. For
> example:
>          X               X               X
>               o  o  o  o  o  o  o  o  o  o  o
>               o  o  o  o  o  o  o  o  o  o  o
>          X    o  o  o  o Xo  o  o  o  o  X  o
>               o  o  o  o  o  o  o  o  o  o  o
> Here, the o's represent transformed destination subpixels and the X's
> represent source pixels. If the image has a
>          pixman_image_set_filter()
> of PIXMAN_FILTER_BILINEAR, then for each of the o's a bilinear
> interpolation will take place, and then all those interpolation
> results will be averaged together (or combined in a higher-quality way
> if we add other resampling filters than box).

This is exactly the problem I am describing. A sample that is 1/2 way 
between pixels A and B will get the value (A+B)/2. A sample that is 
centered on pixel B will get the value B. This will cause moire patterns 
because the first sample is from a blurred image and the second is from 
a sharp image and the output image will vary between these as the phase 
of the samples passes over the image.

Imagine the image is a checkerboard of black and white pixels. The 1/2 
way sample will be .5 while the centered sample will be 1 or 0.

The example image of the house shows this clearly by the aliased 
frequency banding in the gray stripe at the bottom.

> Another, faster, but lower-quality, type of interpolation is NEAREST,
> in which case each o will just take the value of the closest
> X. Depending on the sample rate, this could indeed produce more
> aliasing artifacts.

Actually nearest could improve the moire patterns but it adds a lot of 

Another way to kill the moire patterns is to make all samples a 50/50 
average of two pixels, ie blur the entire image uniformly. This is 
somewhat what mipmapping does.

More information about the Pixman mailing list