[Pixman] [PATCH v14 12/22] pixman-filter: fix subsample_bits == 0

Bill Spitzak spitzak at gmail.com
Mon Apr 11 18:43:36 UTC 2016

Okay the actual bug is that the gnuplot output is wrong for
subsample_bits==0. It apparently is correct for other values of
subsampling. I will try to get an updated version posted soon.

But I very much agree with Owen (and you?) that the current behavior is
incorrect and should be fixed exactly as stated. The current version
produces different images from fallbacks to impulse, bilinear, or
integer-sized box filters, when the filter math says the fallback should
produce an identical result. Scaling down by an integer produces a slightly
blurry and offset result, when a perfect result could be achieved at the
same speed. Increasing the subsamples moves the existing samples, thus may
increase artifacts, rather than always reducing them. All of this is not a
good situation.

I feel this can be fixed. It is already correct for subsample_bits==0.
Since both the filter generator and filtering code would be changed in the
same version, only programs that generate their own filters would actually
be incompatible. And as you point out the error is very tiny for large
numbers of subsamples, and Cairo is already using an excessively large
number of subsamples (likely because I was trying to remove the difference
between identity filters and nearest filtering, and did not realize this
was the underlying problem).

On Sun, Apr 10, 2016 at 10:01 PM, Søren Sandmann <soren.sandmann at gmail.com>

> It does look like there is something really wrong. I compared and (except
>> for the subsample_bits==0 case) my version produces the same output as the
>> current git head.
>> I think your intention is that there is a sample at offset=0 whether the
>> filter width is even or odd. However (except when subsample_bits==0) the
>> filter generator makes a symmetric filter for even sizes, with two equal
>> samples around the maximum center value. If a sample was at offset==0 then
>> it would be unique and larger than all the other samples.
> The root of this confusion is probably that when subsample_bits = k, the
> subpixel positions used are:
>     0.5 / 2^k, 1.5 / 2^k, ..., (2^k-0.5)/2^k
> For example, for subsample_bits = 2:
>     0.125, 0.375, 0.625, 0.875
> and for subsample_bits = 0:
>     0.5
> That is, they are regularly spaced, but centered within the pixel. When
> there is an even number of them, this means there will not be a filter
> position at 0.5, and therefore no sample at offset 0. And the only case
> where number of subpixel locations is odd, is when subsample_bits = 0.
> I'm pretty sure that the existing code gets the filter generation right
> for these subpixel positions.
> [ You can argue that it would be better to use the sampling positions
>     0, 0.25, 0.5, 0.75
> for subsample_bits = 2, as Owen did here:
>     https://lists.cairographics.org/archives/cairo/2014-March/025105.html
> and I agree that that would have been better. ]
> Søren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pixman/attachments/20160411/01d7f101/attachment.html>

More information about the Pixman mailing list