Use floating point combiners for all operators that involve divisions

Graphics / Pixman - Søren Sandmann [redhat.com] - 4 January 2014 15:13 EST

Consider a DISJOINT_ATOP operation with the following pixels:

- source: 0xff (8 bits)- source alpha: 0x01 (8 bits)- mask alpha: 0x7b (8 bits)- dest: 0x00 (8 bits)- dest alpha: 0xff (8 bits)

When (src IN mask) is computed in 8 bits, the resulting alpha channel is 0 due to rounding:

floor ((0x01 * 0x7b) / 255.0 + 0.5) = floor (0.9823) = 0

which means that since Render defines any division by zero as infinity, the Fa and Fb for this operator end up as follows:

Fa = max (1 - (1 - 1) / 0, 0) = 0

Fb = min (1, (1 - 0) / 1) = 1

and so since dest is 0x00, the overall result is 0.

However, when computed in full precision, the alpha value no longer rounds to 0, and so Fa ends up being

Fa = max (1 - (1 - 1) / 0.0001, 0) = 1

and so the result is now

s * ma * Fa + d * Fb

= (1.0 * (0x7b / 255.0) * 1) + d * 0

= 0x7b / 255.0

= 0.4823

so the error in this case ends up being 0.48235294, which is clearly not something that can be considered acceptable.

In order to avoid this problem, we need to do all arithmetic in such a way that a multiplication of two tiny numbers can never end up being zero unless one of the input numbers is itself zero.

This patch makes all computations that involve divisions take place in floating point, which is sufficient to fix the test cases

This brings the number of failures in pixel-test down to 14.

15aa37a Use floating point combiners for all operators that involve divisions
pixman/pixman-general.c | 21 ++++++++++++++++++---
test/blitters-test.c | 20 ++++++++++----------
test/thread-test.c | 29 +----------------------------
3 files changed, 29 insertions(+), 41 deletions(-)

Upstream: cgit.freedesktop.org


  • Share