[Pixman] [PATCH 1/4] Change conditions for setting FAST_PATH_SAMPLES_COVER_CLIP flags

Søren Sandmann soren.sandmann at gmail.com
Mon Sep 14 11:52:18 PDT 2015


Ben Avison <bavison at riscosopen.org> writes:

> It's an odd omission that it doesn't talk about BILINEAR filtering,
> though. However, having briefly read through the text, even though some
> of it goes over my head a bit, I'd say it's describing from a strictly
> mathematical point of view. Discussion of exactly which pixels get loaded
> from memory in order to reach this mathematical outcome feels outside the
> scope of that document to me.

My take on the question is that conceptually the BILINEAR filter works
by loading four pixels surrounding the sample locations, and then
convolving them with a 2 x 2 matrix where the entries are determined by
the fractional part of the sample position. The question then is: How do
you determine the North-West pixel? And the answer is that you round
down. The other three pixels are then found by adding 1 to one or both
of the North-West pixel's coordinates. The CONVOLUTION filter works this way
too, except the matrix may be bigger than 2x2 and is given explicitly
rather than implicitly.

It is important to note that a pixman image is not undefined outside its
borders because the repeat mode always says what happens if you ask for
such a sample.

Now, of course, if the sample position is exactly on top of a pixel,
some of the weights in the matrix will be zero and so a possible
optimization is to eliminate those memory references. But I think this
should be considered an optimization and not the specification.

> Here's a draft section for BILINEAR filtering, comments welcome:
>
> ---- 8< -----
>
> -- BILINEAR filtering:
>
> The BILINEAR filter calculates the linear interpolation between (i.e. a
> weighted mean of) the two closest pixels to the given position - one
> found by rounding down, one by rounding up.
>
>      round_up(x) = ceil(x - o) + o
>      round_down(x) = floor(x - o) + o
>
> The weight factor applied to each of these is given by
>
>      1 - abs(round(x) - x)
>
> except in the case where two to rounding functions amount to the same
  ^^^^^^
I really don't like to have a exceptions in the specifications for
filters. Instead, I'd just say that the first pixel is found by rounding
down, the second by adding 1 to the first pixel. The weights are
given by 1 - (x - x0) and (x1 - x).

> pixel - which only occurs if the given position aligns precisely with one
> pixel. In that case, that one pixel value is used directly.
>
> A common simplification, to avoid having to treat this case differently,
> is to define one (and only one) of the two round functions such that when
> the given positions aligns with a pixel, abs(round(x) - x) = 1, and hence
> the corresponding weight factor is 0. Either of the following pairs of
> definitions satisfy this requirement:

When described as a above, this simplification is simply a description
of how BILINEAR works in all cases.

I think this is my basic concern: In my mind BILINEAR_COVER_CLIP says
"if[1] the filter is BILINEAR, then all pixels required for the
operation (regardless of weight) are inside the borders of the source
image". This is useful information for the implementations because it
means they can elide the border-checking logic.

A separate possibility is a flag that says "all pixels whose weights are
non-zero are inside the borders of the source image". Is this useful
information? It might be, and if so, it could be conveyed through some
new flag, though I'd echo Siarhei's comment about whether this is
something that happens in practice.


Søren


[1] A subtle, but mostly irrelevant for this discussion, point is that
the flag can be set even if the filter in question is not actually
BILINEAR.


More information about the Pixman mailing list