Convolution filter: round color values instead of truncating
authorSøren Sandmann Pedersen <ssp@redhat.com>
Wed, 21 Nov 2012 04:28:43 +0000 (23:28 -0500)
committerSøren Sandmann Pedersen <ssp@redhat.com>
Thu, 22 Nov 2012 06:06:29 +0000 (01:06 -0500)
commit74319e9d39f5d7f85cb75fcb91343f298b0e62e2
tree757df6a7991c983e5fdc13e53339bd04cb59debe
parentf0816ddaf4e61d9295de5b1cbe51f956db7fbd16
Convolution filter: round color values instead of truncating

The pixel computed by the convolution filter should be rounded off,
not truncated. As a simple example consider a convolution matrix
consisting of five times 0x3333. If all five all five input pixels are
0xff, then the result of truncating will be

    (5 * 0x3333 * 255) >> 16 = 254

But the real value of the computation is (5 * 0x3333 / 65536.0) * 254
= 254.9961, so the error is almost 1. If the user isn't very careful
about normalizing the convolution kernel so that it sums to one in
fixed point, such error might cause solid images to change color, or
opaque images to become translucent.

The fix is simply to round instead of truncate.
pixman/pixman-bits-image.c