# [cairo] Concerns about using filters for downscaling

Owen Taylor otaylor at redhat.com
Fri Mar 21 18:37:05 PDT 2014

```On Fri, 2014-03-21 at 18:33 -0400, Owen Taylor wrote:

> * For some reason, the results of downscaling images don't have
>   left-right symmetry. The result of scaling down:
>
>   000000 000000 000000 000000
>   000000 ffffff ffffff 000000
>   000000 ffffff ffffff 000000
>   000000 000000 000000 000000
>
>   By a factor of two is:
>
>    646464 3c3c3c
>    3c3c3c 242424
>
>   (I'm a bit suspicious about the fact that pixman generates
>   even length filters, and wonder if that has something to do
>   with the asymmetry.)

What's going on here is:

+-------+-------+ Destination image
*       *     Sampling points
+---+---+---+---+ Original image
* * * * * * * *  Subpixel filter points

So each sampling point is between two subpixel filter points, and the
picking one of them the asymmetry. When pixman has N bits of subpixel
filters, it picks the points as:

0.5/2^N, 1.5/2^N ... (2^N-0.5)/2^N

To give an equal distribution in the unit interval. I think that's
actually wrong and they should be at:

0, 1/2^N ... (N-1)/2^N

It shouldn't make a difference when the scale/offset of the filter
is arbitrary, but means that you avoid the half-way-between rounding
for exact integer scale-downs.

With more bits of subpixel precision, the asymmetry decreases - with
cairo modified to use 4 bits instead of 1, the example above is the
more reasonable:

444444 404040
404040 3c3c3c

- Owen

```