utils.c: Set DEVIATION to 0.0128
authorSøren Sandmann Pedersen <ssp@redhat.com>
Mon, 30 Sep 2013 23:22:20 +0000 (19:22 -0400)
committerSøren Sandmann <ssp@redhat.com>
Sat, 4 Jan 2014 21:13:27 +0000 (16:13 -0500)
commit94244b0c401f797835567a8bd165beef8f0dd820
tree7a2fc496dd64c65af60675ceabcf50524c88e228
parent15aa37adeca79a22b393ff451e6d29f484c3b0ef
utils.c: Set DEVIATION to 0.0128

Consider a HARD_LIGHT operation with the following pixels:

- source:           15      (6 bits)
- source alpha:     255     (8 bits)
- mask alpha:       223     (8 bits)
- dest              255     (8 bits)
- dest alpha:       0       (8 bits)

Since 2 times the source is less than source alpha, the first branch
of the hard light blend mode is taken:

        (1 - sa) * d + (1 - da) * s + 2 * s * d

Since da is 0 and d is 1, this degenerates to:

        (1 - sa) + 3 * s

Taking (src IN mask) into account along with the fact that sa is 1,
this becomes:

        (1 - ma) + 3 * s * ma

      = (1 - 223/255.0) + 3 * (15/63.0) * (223/255.0)

      = 0.7501400560224089

When computed with the source converted by bit replication to eight
bits, and additionally with the (src IN mask) part rounded to eight
bits, we get:

        ma = 223/255.0

        s * ma = (60 / 255.0) * (223/255.0) which rounds to 52 / 255

and the result is

        (1 - ma) + 3 * s * ma

      = (1 - 223/255.0) + 3 * 52/255.0

      = 0.7372549019607844

so now we have an error of 0.012885.

Without making changes to the way pixman does integer
rounding/arithmetic, this error must then be considered
acceptable. Due to conservative computations in the test suite we can
however get away with 0.0128 as the acceptable deviation.

This fixes the remaining failures in pixel-test.
test/utils.c